PostgreSQL Source Code  git master
ecpglib.h File Reference
#include "libpq-fe.h"
#include "ecpg_config.h"
#include "ecpgtype.h"
#include "sqlca.h"
#include <string.h>
Include dependency graph for ecpglib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define true   ((bool) 1)
 
#define false   ((bool) 0)
 
#define SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

Typedefs

typedef unsigned char bool
 

Functions

void ECPGdebug (int, FILE *)
 
bool ECPGstatus (int, const char *)
 
bool ECPGsetcommit (int, const char *, const char *)
 
bool ECPGsetconn (int, const char *)
 
bool ECPGconnect (int, int, const char *, const char *, const char *, const char *, int)
 
bool ECPGdo (const int, const int, const int, const char *, const bool, const int, const char *,...)
 
bool ECPGtrans (int, const char *, const char *)
 
bool ECPGdisconnect (int, const char *)
 
bool ECPGprepare (int, const char *, const bool, const char *, const char *)
 
bool ECPGdeallocate (int, int, const char *, const char *)
 
bool ECPGdeallocate_all (int, int, const char *)
 
char * ECPGprepared_statement (const char *, const char *, int)
 
PGconnECPGget_PGconn (const char *)
 
PGTransactionStatusType ECPGtransactionStatus (const char *)
 
void sqlprint (void)
 
bool ECPGdo_descriptor (int, const char *, const char *, const char *)
 
bool ECPGdeallocate_desc (int, const char *)
 
bool ECPGallocate_desc (int, const char *)
 
bool ECPGget_desc_header (int, const char *, int *)
 
bool ECPGget_desc (int, const char *, int,...)
 
bool ECPGset_desc_header (int, const char *, int)
 
bool ECPGset_desc (int, const char *, int,...)
 
void ECPGset_noind_null (enum ECPGttype, void *)
 
bool ECPGis_noind_null (enum ECPGttype, const void *)
 
bool ECPGdescribe (int, int, bool, const char *, const char *,...)
 
void ECPGset_var (int, void *, int)
 
void * ECPGget_var (int number)
 
void ECPGfree_auto_mem (void)
 

Macro Definition Documentation

◆ false

#define false   ((bool) 0)

Definition at line 39 of file ecpglib.h.

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 71 of file ecpglib.h.

Referenced by sql_check().

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 72 of file ecpglib.h.

◆ true

#define true   ((bool) 1)

Definition at line 35 of file ecpglib.h.

Typedef Documentation

◆ bool

typedef unsigned char bool

Definition at line 31 of file ecpglib.h.

Function Documentation

◆ ECPGallocate_desc()

bool ECPGallocate_desc ( int  ,
const char *   
)

Definition at line 797 of file descriptor.c.

References ecpg_alloc(), ecpg_free(), ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGget_sqlca(), get_descriptors, PQmakeEmptyPGresult(), set_descriptors, and sqlca.

Referenced by fn(), and main().

798 {
799  struct descriptor *new;
800  struct sqlca_t *sqlca = ECPGget_sqlca();
801 
802  if (sqlca == NULL)
803  {
806  return false;
807  }
808 
809  ecpg_init_sqlca(sqlca);
810  new = (struct descriptor *) ecpg_alloc(sizeof(struct descriptor), line);
811  if (!new)
812  return false;
813  new->next = get_descriptors();
814  new->name = ecpg_alloc(strlen(name) + 1, line);
815  if (!new->name)
816  {
817  ecpg_free(new);
818  return false;
819  }
820  new->count = -1;
821  new->items = NULL;
822  new->result = PQmakeEmptyPGresult(NULL, 0);
823  if (!new->result)
824  {
825  ecpg_free(new->name);
826  ecpg_free(new);
828  return false;
829  }
830  strcpy(new->name, name);
831  set_descriptors(new);
832  return true;
833 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define sqlca
Definition: sqlca.h:59
#define set_descriptors(value)
Definition: descriptor.c:56
void ecpg_free(void *)
Definition: memory.c:13
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
Definition: fe-exec.c:141
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
const char * name
Definition: encode.c:521
#define get_descriptors()
Definition: descriptor.c:55

◆ ECPGconnect()

bool ECPGconnect ( int  ,
int  ,
const char *  ,
const char *  ,
const char *  ,
const char *  ,
int   
)

Definition at line 271 of file connect.c.

References all_connections, Assert, autocommit, connection::cache_head, compat, CONNECTION_BAD, dbname, ecpg_alloc(), ecpg_clear_auto_mem(), ECPG_CONNECT, ecpg_finish(), ecpg_free(), ecpg_get_connection(), ecpg_gettext, ecpg_init_sqlca(), ecpg_internal_regression_mode, ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, ecpg_strdup(), ECPGget_sqlca(), ECPGnoticeReceiver(), errmsg(), free, i, INFORMIX_MODE, last_dir_separator(), next, port, PQconnectdbParams(), PQerrorMessage(), PQsetNoticeReceiver(), PQstatus(), connection::prep_stmts, pthread_mutex_lock(), pthread_mutex_unlock(), pthread_setspecific(), sqlca, generate_unaccent_rules::str, and user.

Referenced by main(), and test().

272 {
273  struct sqlca_t *sqlca = ECPGget_sqlca();
274  enum COMPAT_MODE compat = c;
275  struct connection *this;
276  int i,
277  connect_params = 0;
278  char *dbname = name ? ecpg_strdup(name, lineno) : NULL,
279  *host = NULL,
280  *tmp,
281  *port = NULL,
282  *realname = NULL,
283  *options = NULL;
284  const char **conn_keywords;
285  const char **conn_values;
286 
287  if (sqlca == NULL)
288  {
291  ecpg_free(dbname);
292  return false;
293  }
294 
295  ecpg_init_sqlca(sqlca);
296 
297  /*
298  * clear auto_mem structure because some error handling functions might
299  * access it
300  */
302 
303  if (INFORMIX_MODE(compat))
304  {
305  char *envname;
306 
307  /*
308  * Informix uses an environment variable DBPATH that overrides the
309  * connection parameters given here. We do the same with PG_DBPATH as
310  * the syntax is different.
311  */
312  envname = getenv("PG_DBPATH");
313  if (envname)
314  {
315  ecpg_free(dbname);
316  dbname = ecpg_strdup(envname, lineno);
317  }
318 
319  }
320 
321  if (dbname == NULL && connection_name == NULL)
322  connection_name = "DEFAULT";
323 
324 #if ENABLE_THREAD_SAFETY
325  ecpg_pthreads_init();
326 #endif
327 
328  /* check if the identifier is unique */
329  if (ecpg_get_connection(connection_name))
330  {
331  ecpg_free(dbname);
332  ecpg_log("ECPGconnect: connection identifier %s is already in use\n",
333  connection_name);
334  return false;
335  }
336 
337  if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
338  {
339  ecpg_free(dbname);
340  return false;
341  }
342 
343  if (dbname != NULL)
344  {
345  /* get the detail information from dbname */
346  if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0)
347  {
348  int offset = 0;
349 
350  /*
351  * only allow protocols tcp and unix
352  */
353  if (strncmp(dbname, "tcp:", 4) == 0)
354  offset = 4;
355  else if (strncmp(dbname, "unix:", 5) == 0)
356  offset = 5;
357 
358  if (strncmp(dbname + offset, "postgresql://", strlen("postgresql://")) == 0)
359  {
360 
361  /*------
362  * new style:
363  * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
364  * [/db-name][?options]
365  *------
366  */
367  offset += strlen("postgresql://");
368 
369  tmp = strrchr(dbname + offset, '?');
370  if (tmp != NULL) /* options given */
371  {
372  options = ecpg_strdup(tmp + 1, lineno);
373  *tmp = '\0';
374  }
375 
376  tmp = last_dir_separator(dbname + offset);
377  if (tmp != NULL) /* database name given */
378  {
379  if (tmp[1] != '\0') /* non-empty database name */
380  {
381  realname = ecpg_strdup(tmp + 1, lineno);
382  connect_params++;
383  }
384  *tmp = '\0';
385  }
386 
387  tmp = strrchr(dbname + offset, ':');
388  if (tmp != NULL) /* port number or Unix socket path given */
389  {
390  char *tmp2;
391 
392  *tmp = '\0';
393  if ((tmp2 = strchr(tmp + 1, ':')) != NULL)
394  {
395  *tmp2 = '\0';
396  host = ecpg_strdup(tmp + 1, lineno);
397  connect_params++;
398  if (strncmp(dbname, "unix:", 5) != 0)
399  {
400  ecpg_log("ECPGconnect: socketname %s given for TCP connection on line %d\n", host, lineno);
402  if (host)
403  ecpg_free(host);
404 
405  /*
406  * port not set yet if (port) ecpg_free(port);
407  */
408  if (options)
410  if (realname)
411  ecpg_free(realname);
412  if (dbname)
413  ecpg_free(dbname);
414  free(this);
415  return false;
416  }
417  }
418  else
419  {
420  port = ecpg_strdup(tmp + 1, lineno);
421  connect_params++;
422  }
423  }
424 
425  if (strncmp(dbname, "unix:", 5) == 0)
426  {
427  if (strcmp(dbname + offset, "localhost") != 0 && strcmp(dbname + offset, "127.0.0.1") != 0)
428  {
429  ecpg_log("ECPGconnect: non-localhost access via sockets on line %d\n", lineno);
431  if (host)
432  ecpg_free(host);
433  if (port)
434  ecpg_free(port);
435  if (options)
437  if (realname)
438  ecpg_free(realname);
439  if (dbname)
440  ecpg_free(dbname);
441  free(this);
442  return false;
443  }
444  }
445  else
446  {
447  if (*(dbname + offset) != '\0')
448  {
449  host = ecpg_strdup(dbname + offset, lineno);
450  connect_params++;
451  }
452  }
453 
454  }
455  }
456  else
457  {
458  /* old style: dbname[@server][:port] */
459  tmp = strrchr(dbname, ':');
460  if (tmp != NULL) /* port number given */
461  {
462  port = ecpg_strdup(tmp + 1, lineno);
463  connect_params++;
464  *tmp = '\0';
465  }
466 
467  tmp = strrchr(dbname, '@');
468  if (tmp != NULL) /* host name given */
469  {
470  host = ecpg_strdup(tmp + 1, lineno);
471  connect_params++;
472  *tmp = '\0';
473  }
474 
475  if (strlen(dbname) > 0)
476  {
477  realname = ecpg_strdup(dbname, lineno);
478  connect_params++;
479  }
480  else
481  realname = NULL;
482  }
483  }
484  else
485  realname = NULL;
486 
487  /* add connection to our list */
488 #ifdef ENABLE_THREAD_SAFETY
489  pthread_mutex_lock(&connections_mutex);
490 #endif
491  if (connection_name != NULL)
492  this->name = ecpg_strdup(connection_name, lineno);
493  else
494  this->name = ecpg_strdup(realname, lineno);
495 
496  this->cache_head = NULL;
497  this->prep_stmts = NULL;
498 
499  if (all_connections == NULL)
500  this->next = NULL;
501  else
502  this->next = all_connections;
503 
504  all_connections = this;
505 #ifdef ENABLE_THREAD_SAFETY
506  pthread_setspecific(actual_connection_key, all_connections);
507 #endif
509 
510  ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s %s%s\n",
511  realname ? realname : "<DEFAULT>",
512  host ? host : "<DEFAULT>",
513  port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
514  options ? "with options " : "", options ? options : "",
515  (user && strlen(user) > 0) ? "for user " : "", user ? user : "");
516 
517  /* count options (this may produce an overestimate, it's ok) */
518  if (options)
519  for (i = 0; options[i]; i++)
520  if (options[i] == '=')
521  connect_params++;
522 
523  if (user && strlen(user) > 0)
524  connect_params++;
525  if (passwd && strlen(passwd) > 0)
526  connect_params++;
527 
528  /* allocate enough space for all connection parameters */
529  conn_keywords = (const char **) ecpg_alloc((connect_params + 1) * sizeof(char *), lineno);
530  conn_values = (const char **) ecpg_alloc(connect_params * sizeof(char *), lineno);
531  if (conn_keywords == NULL || conn_values == NULL)
532  {
533  if (host)
534  ecpg_free(host);
535  if (port)
536  ecpg_free(port);
537  if (options)
538  ecpg_free(options);
539  if (realname)
540  ecpg_free(realname);
541  if (dbname)
542  ecpg_free(dbname);
543  if (conn_keywords)
544  ecpg_free(conn_keywords);
545  if (conn_values)
546  ecpg_free(conn_values);
547  free(this);
548  return false;
549  }
550 
551  i = 0;
552  if (realname)
553  {
554  conn_keywords[i] = "dbname";
555  conn_values[i] = realname;
556  i++;
557  }
558  if (host)
559  {
560  conn_keywords[i] = "host";
561  conn_values[i] = host;
562  i++;
563  }
564  if (port)
565  {
566  conn_keywords[i] = "port";
567  conn_values[i] = port;
568  i++;
569  }
570  if (user && strlen(user) > 0)
571  {
572  conn_keywords[i] = "user";
573  conn_values[i] = user;
574  i++;
575  }
576  if (passwd && strlen(passwd) > 0)
577  {
578  conn_keywords[i] = "password";
579  conn_values[i] = passwd;
580  i++;
581  }
582  if (options)
583  {
584  char *str;
585 
586  /*
587  * The options string contains "keyword=value" pairs separated by
588  * '&'s. We must break this up into keywords and values to pass to
589  * libpq (it's okay to scribble on the options string). We ignore
590  * spaces just before each keyword or value.
591  */
592  for (str = options; *str;)
593  {
594  int e,
595  a;
596  char *token1,
597  *token2;
598 
599  /* Skip spaces before keyword */
600  for (token1 = str; *token1 == ' '; token1++)
601  /* skip */ ;
602  /* Find end of keyword */
603  for (e = 0; token1[e] && token1[e] != '='; e++)
604  /* skip */ ;
605  if (token1[e]) /* found "=" */
606  {
607  token1[e] = '\0';
608  /* Skip spaces before value */
609  for (token2 = token1 + e + 1; *token2 == ' '; token2++)
610  /* skip */ ;
611  /* Find end of value */
612  for (a = 0; token2[a] && token2[a] != '&'; a++)
613  /* skip */ ;
614  if (token2[a]) /* found "&" => another option follows */
615  {
616  token2[a] = '\0';
617  str = token2 + a + 1;
618  }
619  else
620  str = token2 + a;
621 
622  conn_keywords[i] = token1;
623  conn_values[i] = token2;
624  i++;
625  }
626  else
627  {
628  /* Bogus options syntax ... ignore trailing garbage */
629  str = token1 + e;
630  }
631  }
632  }
633 
634  Assert(i <= connect_params);
635  conn_keywords[i] = NULL; /* terminator */
636 
637  this->connection = PQconnectdbParams(conn_keywords, conn_values, 0);
638 
639  if (host)
640  ecpg_free(host);
641  if (port)
642  ecpg_free(port);
643  if (options)
644  ecpg_free(options);
645  if (dbname)
646  ecpg_free(dbname);
647  ecpg_free(conn_values);
648  ecpg_free(conn_keywords);
649 
650  if (PQstatus(this->connection) == CONNECTION_BAD)
651  {
652  const char *errmsg = PQerrorMessage(this->connection);
653  const char *db = realname ? realname : ecpg_gettext("<DEFAULT>");
654 
655  ecpg_log("ECPGconnect: could not open database: %s\n", errmsg);
656 
657  ecpg_finish(this);
658 #ifdef ENABLE_THREAD_SAFETY
659  pthread_mutex_unlock(&connections_mutex);
660 #endif
661 
663  if (realname)
664  ecpg_free(realname);
665 
666  return false;
667  }
668 
669  if (realname)
670  ecpg_free(realname);
671 
672 #ifdef ENABLE_THREAD_SAFETY
673  pthread_mutex_unlock(&connections_mutex);
674 #endif
675 
676  this->autocommit = autocommit;
677 
678  PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this);
679 
680  return true;
681 }
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6617
COMPAT_MODE
static void ecpg_finish(struct connection *act)
Definition: connect.c:113
#define ECPG_CONNECT
Definition: ecpgerrno.h:51
static int32 next
Definition: blutils.c:213
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define sqlca
Definition: sqlca.h:59
void ecpg_free(void *)
Definition: memory.c:13
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
#define INFORMIX_MODE(X)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:620
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ecpg_gettext(x)
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
static struct connection * all_connections
Definition: connect.c:19
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
struct ECPGtype_information_cache * cache_head
Definition: sqlca.h:19
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
char * c
bool ecpg_internal_regression_mode
Definition: misc.c:29
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
static int port
Definition: pg_regress.c:91
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
char * last_dir_separator(const char *filename)
Definition: path.c:138
#define free(a)
Definition: header.h:65
#define Assert(condition)
Definition: c.h:733
bool autocommit
Definition: ecpg.c:15
char * dbname
Definition: streamutil.c:50
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
static char * user
Definition: pg_regress.c:94
int errmsg(const char *fmt,...)
Definition: elog.c:822
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
static struct connection * actual_connection
Definition: connect.c:18
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
int i
static void ECPGnoticeReceiver(void *arg, const PGresult *result)
Definition: connect.c:219
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6564
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
Definition: fe-connect.c:6776
struct prepared_statement * prep_stmts

◆ ECPGdeallocate()

bool ECPGdeallocate ( int  ,
int  ,
const char *  ,
const char *   
)

Definition at line 315 of file prepare.c.

References deallocate_one(), ecpg_find_prepared_statement(), ecpg_get_connection(), ecpg_init(), ECPG_INVALID_STMT, ecpg_raise(), ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, and INFORMIX_MODE.

Referenced by main().

316 {
317  struct connection *con;
318  struct prepared_statement *this,
319  *prev;
320 
321  con = ecpg_get_connection(connection_name);
322  if (!ecpg_init(con, connection_name, lineno))
323  return false;
324 
325  this = ecpg_find_prepared_statement(name, con, &prev);
326  if (this)
327  return deallocate_one(lineno, c, con, prev, this);
328 
329  /* prepared statement is not found */
330  if (INFORMIX_MODE(c))
331  return true;
333  return false;
334 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
#define INFORMIX_MODE(X)
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:260
char * c
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104

◆ ECPGdeallocate_all()

bool ECPGdeallocate_all ( int  ,
int  ,
const char *   
)

Definition at line 350 of file prepare.c.

References ecpg_deallocate_all_conn(), and ecpg_get_connection().

Referenced by main().

351 {
352  return ecpg_deallocate_all_conn(lineno, compat,
353  ecpg_get_connection(connection_name));
354 }
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
Definition: prepare.c:337
enum COMPAT_MODE compat
Definition: ecpg.c:25
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGdeallocate_desc()

bool ECPGdeallocate_desc ( int  ,
const char *   
)

Definition at line 750 of file descriptor.c.

References descriptor_free(), ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, ECPG_UNKNOWN_DESCRIPTOR, ECPGget_sqlca(), get_descriptors, sort-test::list, descriptor::next, next, set_descriptors, and sqlca.

Referenced by fn(), and main().

751 {
752  struct descriptor *desc;
753  struct descriptor *prev;
754  struct sqlca_t *sqlca = ECPGget_sqlca();
755 
756  if (sqlca == NULL)
757  {
760  return false;
761  }
762 
763  ecpg_init_sqlca(sqlca);
764  for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
765  {
766  if (strcmp(name, desc->name) == 0)
767  {
768  if (prev)
769  prev->next = desc->next;
770  else
771  set_descriptors(desc->next);
772  descriptor_free(desc);
773  return true;
774  }
775  }
777  return false;
778 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define sqlca
Definition: sqlca.h:59
#define set_descriptors(value)
Definition: descriptor.c:56
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct descriptor * next
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:730
const char * name
Definition: encode.c:521
#define get_descriptors()
Definition: descriptor.c:55

◆ ECPGdebug()

void ECPGdebug ( int  ,
FILE *   
)

Definition at line 242 of file misc.c.

References debugstream, ecpg_internal_regression_mode, ecpg_log(), pthread_mutex_lock(), pthread_mutex_unlock(), and simple_debug.

243 {
244 #ifdef ENABLE_THREAD_SAFETY
245  pthread_mutex_lock(&debug_init_mutex);
246 #endif
247 
248  if (n > 100)
249  {
251  simple_debug = n - 100;
252  }
253  else
254  simple_debug = n;
255 
256  debugstream = dbgs;
257 
258  ecpg_log("ECPGdebug: set to %d\n", simple_debug);
259 
260 #ifdef ENABLE_THREAD_SAFETY
261  pthread_mutex_unlock(&debug_init_mutex);
262 #endif
263 }
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
static int simple_debug
Definition: misc.c:94
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
static FILE * debugstream
Definition: misc.c:95
void ecpg_log(const char *format,...)
Definition: misc.c:266
bool ecpg_internal_regression_mode
Definition: misc.c:29

◆ ECPGdescribe()

bool ECPGdescribe ( int  ,
int  ,
bool  ,
const char *  ,
const char *  ,
  ... 
)

Definition at line 852 of file descriptor.c.

References generate_unaccent_rules::args, connection::connection, sqlda_struct::desc_next, sqlda_compat::desc_next, ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), ecpg_check_PQresult(), ecpg_find_desc(), ecpg_find_prepared_statement(), ecpg_get_connection(), ecpg_gettext, ECPG_INVALID_STMT, ECPG_NO_CONN, ecpg_raise(), ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, ECPG_UNSUPPORTED, ECPGt_descriptor, ECPGt_EORT, ECPGt_sqlda, free, INFORMIX_MODE, name, PQclear(), PQdescribePrepared(), descriptor::result, and generate_unaccent_rules::type.

Referenced by main().

853 {
854  bool ret = false;
855  struct connection *con;
856  struct prepared_statement *prep;
857  PGresult *res;
858  va_list args;
859 
860  /* DESCRIBE INPUT is not yet supported */
861  if (input)
862  {
864  return ret;
865  }
866 
867  con = ecpg_get_connection(connection_name);
868  if (!con)
869  {
871  connection_name ? connection_name : ecpg_gettext("NULL"));
872  return ret;
873  }
874  prep = ecpg_find_prepared_statement(stmt_name, con, NULL);
875  if (!prep)
876  {
878  return ret;
879  }
880 
881  va_start(args, stmt_name);
882 
883  for (;;)
884  {
885  enum ECPGttype type;
886  void *ptr;
887 
888  /* variable type */
889  type = va_arg(args, enum ECPGttype);
890 
891  if (type == ECPGt_EORT)
892  break;
893 
894  /* rest of variable parameters */
895  ptr = va_arg(args, void *);
896  (void) va_arg(args, long); /* skip args */
897  (void) va_arg(args, long);
898  (void) va_arg(args, long);
899 
900  /* variable indicator */
901  (void) va_arg(args, enum ECPGttype);
902  (void) va_arg(args, void *); /* skip args */
903  (void) va_arg(args, long);
904  (void) va_arg(args, long);
905  (void) va_arg(args, long);
906 
907  switch (type)
908  {
909  case ECPGt_descriptor:
910  {
911  char *name = ptr;
912  struct descriptor *desc = ecpg_find_desc(line, name);
913 
914  if (desc == NULL)
915  break;
916 
917  res = PQdescribePrepared(con->connection, stmt_name);
918  if (!ecpg_check_PQresult(res, line, con->connection, compat))
919  break;
920 
921  if (desc->result != NULL)
922  PQclear(desc->result);
923 
924  desc->result = res;
925  ret = true;
926  break;
927  }
928  case ECPGt_sqlda:
929  {
930  if (INFORMIX_MODE(compat))
931  {
932  struct sqlda_compat **_sqlda = ptr;
933  struct sqlda_compat *sqlda;
934 
935  res = PQdescribePrepared(con->connection, stmt_name);
936  if (!ecpg_check_PQresult(res, line, con->connection, compat))
937  break;
938 
939  sqlda = ecpg_build_compat_sqlda(line, res, -1, compat);
940  if (sqlda)
941  {
942  struct sqlda_compat *sqlda_old = *_sqlda;
943  struct sqlda_compat *sqlda_old1;
944 
945  while (sqlda_old)
946  {
947  sqlda_old1 = sqlda_old->desc_next;
948  free(sqlda_old);
949  sqlda_old = sqlda_old1;
950  }
951 
952  *_sqlda = sqlda;
953  ret = true;
954  }
955 
956  PQclear(res);
957  }
958  else
959  {
960  struct sqlda_struct **_sqlda = ptr;
961  struct sqlda_struct *sqlda;
962 
963  res = PQdescribePrepared(con->connection, stmt_name);
964  if (!ecpg_check_PQresult(res, line, con->connection, compat))
965  break;
966 
967  sqlda = ecpg_build_native_sqlda(line, res, -1, compat);
968  if (sqlda)
969  {
970  struct sqlda_struct *sqlda_old = *_sqlda;
971  struct sqlda_struct *sqlda_old1;
972 
973  while (sqlda_old)
974  {
975  sqlda_old1 = sqlda_old->desc_next;
976  free(sqlda_old);
977  sqlda_old = sqlda_old1;
978  }
979 
980  *_sqlda = sqlda;
981  ret = true;
982  }
983 
984  PQclear(res);
985  }
986  break;
987  }
988  default:
989  /* nothing else may come */
990  ;
991  }
992  }
993 
994  va_end(args);
995 
996  return ret;
997 }
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
Definition: fe-exec.c:2156
struct sqlda_struct * desc_next
Definition: sqlda-native.h:39
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
Definition: type.h:102
#define INFORMIX_MODE(X)
#define ecpg_gettext(x)
struct sqlda_compat * desc_next
Definition: sqlda-compat.h:43
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:837
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:412
PGresult * result
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
struct sqlda_compat * ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:205
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
struct prepared_statement * ecpg_find_prepared_statement(const char *, struct connection *, struct prepared_statement **)
Definition: prepare.c:239
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define free(a)
Definition: header.h:65
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36
ECPGttype
Definition: ecpgtype.h:41

◆ ECPGdisconnect()

bool ECPGdisconnect ( int  ,
const char *   
)

Definition at line 684 of file connect.c.

References ecpg_finish(), ecpg_get_connection_nr(), ecpg_init(), ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGget_sqlca(), connection::next, pthread_mutex_lock(), pthread_mutex_unlock(), and sqlca.

Referenced by main(), and test().

685 {
686  struct sqlca_t *sqlca = ECPGget_sqlca();
687  struct connection *con;
688 
689  if (sqlca == NULL)
690  {
693  return false;
694  }
695 
696 #ifdef ENABLE_THREAD_SAFETY
697  pthread_mutex_lock(&connections_mutex);
698 #endif
699 
700  if (strcmp(connection_name, "ALL") == 0)
701  {
702  ecpg_init_sqlca(sqlca);
703  for (con = all_connections; con;)
704  {
705  struct connection *f = con;
706 
707  con = con->next;
708  ecpg_finish(f);
709  }
710  }
711  else
712  {
713  con = ecpg_get_connection_nr(connection_name);
714 
715  if (!ecpg_init(con, connection_name, lineno))
716  {
717 #ifdef ENABLE_THREAD_SAFETY
718  pthread_mutex_unlock(&connections_mutex);
719 #endif
720  return false;
721  }
722  else
723  ecpg_finish(con);
724  }
725 
726 #ifdef ENABLE_THREAD_SAFETY
727  pthread_mutex_unlock(&connections_mutex);
728 #endif
729 
730  return true;
731 }
static void ecpg_finish(struct connection *act)
Definition: connect.c:113
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define sqlca
Definition: sqlca.h:59
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
static struct connection * all_connections
Definition: connect.c:19
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
struct connection * next
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104

◆ ECPGdo()

bool ECPGdo ( const int  ,
const int  ,
const int  ,
const char *  ,
const bool  ,
const int  ,
const char *  ,
  ... 
)

Definition at line 2276 of file execute.c.

References generate_unaccent_rules::args, and ecpg_do().

Referenced by check_result_of_insert(), close_cur1(), ECPGdo_descriptor(), get_record1(), main(), open_cur1(), openit(), and test().

2277 {
2278  va_list args;
2279  bool ret;
2280 
2281  va_start(args, query);
2282  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2283  questionmarks, st, query, args);
2284  va_end(args);
2285 
2286  return ret;
2287 }
bool questionmarks
Definition: ecpg.c:19
enum COMPAT_MODE compat
Definition: ecpg.c:25
bool force_indicator
Definition: ecpg.c:18
bool ecpg_do(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query, va_list args)
Definition: execute.c:2242

◆ ECPGdo_descriptor()

bool ECPGdo_descriptor ( int  ,
const char *  ,
const char *  ,
const char *   
)

Definition at line 2291 of file execute.c.

References ECPG_COMPAT_PGSQL, ECPGdo(), ECPGt_descriptor, ECPGt_EOIT, ECPGt_EORT, and ECPGt_NO_INDICATOR.

2293 {
2294  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2295  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2296  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2297 }
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2276

◆ ECPGfree_auto_mem()

void ECPGfree_auto_mem ( void  )

Definition at line 138 of file memory.c.

References ecpg_free(), get_auto_allocs, auto_mem::next, auto_mem::pointer, and set_auto_allocs.

Referenced by ecpg_raise(), ecpg_raise_backend(), ECPGset_var(), and main().

139 {
140  struct auto_mem *am = get_auto_allocs();
141 
142  /* free all memory we have allocated for the user */
143  if (am)
144  {
145  do
146  {
147  struct auto_mem *act = am;
148 
149  am = am->next;
150  ecpg_free(act->pointer);
151  ecpg_free(act);
152  } while (am);
153  set_auto_allocs(NULL);
154  }
155 }
void * pointer
Definition: memory.c:67
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
void ecpg_free(void *ptr)
Definition: memory.c:13
struct auto_mem * next
Definition: memory.c:68

◆ ECPGget_desc()

bool ECPGget_desc ( int  ,
const char *  ,
int  ,
  ... 
)

Definition at line 241 of file descriptor.c.

References generate_unaccent_rules::args, variable::arrsize, statement::connection, ecpg_auto_alloc(), ecpg_dynamic_type(), ecpg_dynamic_type_DDT(), ecpg_free(), ecpg_get_connection(), ecpg_init_sqlca(), ECPG_INVALID_DESCRIPTOR_INDEX, ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_result_by_descriptor(), ECPG_SQLSTATE_CARDINALITY_VIOLATION, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX, ecpg_store_result(), ecpg_strdup(), ECPG_TOO_MANY_MATCHES, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_EODT, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGget_sqlca(), ECPGt_EORT, ECPGt_NO_INDICATOR, get_char_item(), get_int_item(), variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, statement::lineno, locale_t, variable::offset, statement::oldlocale, variable::pointer, PQfmod(), PQfname(), PQfsize(), PQftype(), PQgetisnull(), PQgetlength(), PQnfields(), PQntuples(), RETURN_IF_NO_DATA, setlocale, snprintf, sqlca, sqlca_t::sqlerrd, variable::type, generate_unaccent_rules::type, variable::value, variable::varcharsize, and VARHDRSZ.

Referenced by main().

242 {
243  va_list args;
244  PGresult *ECPGresult;
245  enum ECPGdtype type;
246  int ntuples,
247  act_tuple;
248  struct variable data_var;
249  struct sqlca_t *sqlca = ECPGget_sqlca();
250 
251  if (sqlca == NULL)
252  {
255  return false;
256  }
257 
258  va_start(args, index);
259  ecpg_init_sqlca(sqlca);
260  ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
261  if (!ECPGresult)
262  {
263  va_end(args);
264  return false;
265  }
266 
267  ntuples = PQntuples(ECPGresult);
268 
269  if (index < 1 || index > PQnfields(ECPGresult))
270  {
272  va_end(args);
273  return false;
274  }
275 
276  ecpg_log("ECPGget_desc: reading items for tuple %d\n", index);
277  --index;
278 
279  type = va_arg(args, enum ECPGdtype);
280 
281  memset(&data_var, 0, sizeof data_var);
282  data_var.type = ECPGt_EORT;
283  data_var.ind_type = ECPGt_NO_INDICATOR;
284 
285  while (type != ECPGd_EODT)
286  {
287  char type_str[20];
288  long varcharsize;
289  long offset;
290  long arrsize;
291  enum ECPGttype vartype;
292  void *var;
293 
294  vartype = va_arg(args, enum ECPGttype);
295  var = va_arg(args, void *);
296  varcharsize = va_arg(args, long);
297  arrsize = va_arg(args, long);
298  offset = va_arg(args, long);
299 
300  switch (type)
301  {
302  case (ECPGd_indicator):
304  data_var.ind_type = vartype;
305  data_var.ind_pointer = var;
306  data_var.ind_varcharsize = varcharsize;
307  data_var.ind_arrsize = arrsize;
308  data_var.ind_offset = offset;
309  if (data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0)
310  data_var.ind_value = *((void **) (data_var.ind_pointer));
311  else
312  data_var.ind_value = data_var.ind_pointer;
313  break;
314 
315  case ECPGd_data:
317  data_var.type = vartype;
318  data_var.pointer = var;
319  data_var.varcharsize = varcharsize;
320  data_var.arrsize = arrsize;
321  data_var.offset = offset;
322  if (data_var.arrsize == 0 || data_var.varcharsize == 0)
323  data_var.value = *((void **) (data_var.pointer));
324  else
325  data_var.value = data_var.pointer;
326  break;
327 
328  case ECPGd_name:
329  if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize))
330  {
331  va_end(args);
332  return false;
333  }
334 
335  ecpg_log("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index));
336  break;
337 
338  case ECPGd_nullable:
339  if (!get_int_item(lineno, var, vartype, 1))
340  {
341  va_end(args);
342  return false;
343  }
344 
345  break;
346 
347  case ECPGd_key_member:
348  if (!get_int_item(lineno, var, vartype, 0))
349  {
350  va_end(args);
351  return false;
352  }
353 
354  break;
355 
356  case ECPGd_scale:
357  if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
358  {
359  va_end(args);
360  return false;
361  }
362 
363  ecpg_log("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff);
364  break;
365 
366  case ECPGd_precision:
367  if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
368  {
369  va_end(args);
370  return false;
371  }
372 
373  ecpg_log("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16);
374  break;
375 
376  case ECPGd_octet:
377  if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
378  {
379  va_end(args);
380  return false;
381  }
382 
383  ecpg_log("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index));
384  break;
385 
386  case ECPGd_length:
387  if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
388  {
389  va_end(args);
390  return false;
391  }
392 
393  ecpg_log("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ);
394  break;
395 
396  case ECPGd_type:
397  if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type(PQftype(ECPGresult, index))))
398  {
399  va_end(args);
400  return false;
401  }
402 
403  ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type(PQftype(ECPGresult, index)));
404  break;
405 
406  case ECPGd_di_code:
407  if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type_DDT(PQftype(ECPGresult, index))))
408  {
409  va_end(args);
410  return false;
411  }
412 
413  ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type_DDT(PQftype(ECPGresult, index)));
414  break;
415 
416  case ECPGd_cardinality:
417  if (!get_int_item(lineno, var, vartype, PQntuples(ECPGresult)))
418  {
419  va_end(args);
420  return false;
421  }
422 
423  ecpg_log("ECPGget_desc: CARDINALITY = %d\n", PQntuples(ECPGresult));
424  break;
425 
426  case ECPGd_ret_length:
427  case ECPGd_ret_octet:
428 
430 
431  /*
432  * this is like ECPGstore_result
433  */
434  if (arrsize > 0 && ntuples > arrsize)
435  {
436  ecpg_log("ECPGget_desc on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
437  lineno, ntuples, arrsize);
439  va_end(args);
440  return false;
441  }
442  /* allocate storage if needed */
443  if (arrsize == 0 && *(void **) var == NULL)
444  {
445  void *mem = (void *) ecpg_auto_alloc(offset * ntuples, lineno);
446 
447  if (!mem)
448  {
449  va_end(args);
450  return false;
451  }
452  *(void **) var = mem;
453  var = mem;
454  }
455 
456  for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
457  {
458  if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, act_tuple, index)))
459  {
460  va_end(args);
461  return false;
462  }
463  var = (char *) var + offset;
464  ecpg_log("ECPGget_desc: RETURNED[%d] = %d\n", act_tuple, PQgetlength(ECPGresult, act_tuple, index));
465  }
466  break;
467 
468  default:
469  snprintf(type_str, sizeof(type_str), "%d", type);
471  va_end(args);
472  return false;
473  }
474 
475  type = va_arg(args, enum ECPGdtype);
476  }
477 
478  if (data_var.type != ECPGt_EORT)
479  {
480  struct statement stmt;
481 
482  memset(&stmt, 0, sizeof stmt);
483  stmt.lineno = lineno;
484 
485  /* Make sure we do NOT honor the locale for numeric input */
486  /* since the database gives the standard decimal point */
487  /* (see comments in execute.c) */
488 #ifdef HAVE_USELOCALE
489  stmt.clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
490  if (stmt.clocale != (locale_t) 0)
491  stmt.oldlocale = uselocale(stmt.clocale);
492 #else
493 #ifdef HAVE__CONFIGTHREADLOCALE
494  stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
495 #endif
496  stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
497  setlocale(LC_NUMERIC, "C");
498 #endif
499 
500  /* desperate try to guess something sensible */
501  stmt.connection = ecpg_get_connection(NULL);
502  ecpg_store_result(ECPGresult, index, &stmt, &data_var);
503 
504 #ifdef HAVE_USELOCALE
505  if (stmt.oldlocale != (locale_t) 0)
506  uselocale(stmt.oldlocale);
507  if (stmt.clocale)
508  freelocale(stmt.clocale);
509 #else
510  if (stmt.oldlocale)
511  {
512  setlocale(LC_NUMERIC, stmt.oldlocale);
513  ecpg_free(stmt.oldlocale);
514  }
515 #ifdef HAVE__CONFIGTHREADLOCALE
516  if (stmt.oldthreadlocale != -1)
517  (void) _configthreadlocale(stmt.oldthreadlocale);
518 #endif
519 #endif
520  }
521  else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
522 
523  /*
524  * ind_type != NO_INDICATOR should always have ind_pointer != NULL but
525  * since this might be changed manually in the .c file let's play it
526  * safe
527  */
528  {
529  /*
530  * this is like ECPGstore_result but since we don't have a data
531  * variable at hand, we can't call it
532  */
533  if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
534  {
535  ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %ld\n",
536  lineno, ntuples, data_var.ind_arrsize);
538  va_end(args);
539  return false;
540  }
541 
542  /* allocate storage if needed */
543  if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
544  {
545  void *mem = (void *) ecpg_auto_alloc(data_var.ind_offset * ntuples, lineno);
546 
547  if (!mem)
548  {
549  va_end(args);
550  return false;
551  }
552  *(void **) data_var.ind_pointer = mem;
553  data_var.ind_value = mem;
554  }
555 
556  for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
557  {
558  if (!get_int_item(lineno, data_var.ind_value, data_var.ind_type, -PQgetisnull(ECPGresult, act_tuple, index)))
559  {
560  va_end(args);
561  return false;
562  }
563  data_var.ind_value = (char *) data_var.ind_value + data_var.ind_offset;
564  ecpg_log("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
565  }
566  }
567  sqlca->sqlerrd[2] = ntuples;
568  va_end(args);
569  return true;
570 }
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3174
static bool get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int varcharsize)
Definition: descriptor.c:201
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
#define setlocale(a, b)
Definition: win32_port.h:408
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3018
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2855
static bool get_int_item(int lineno, void *var, enum ECPGttype vartype, int value)
Definition: descriptor.c:115
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
int ecpg_dynamic_type(Oid)
Definition: typename.c:73
#define sqlca
Definition: sqlca.h:59
#define VARHDRSZ
Definition: c.h:556
void ecpg_free(void *)
Definition: memory.c:13
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
#define ECPG_INVALID_DESCRIPTOR_INDEX
Definition: ecpgerrno.h:43
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: type.h:89
#define ECPG_TOO_MANY_MATCHES
Definition: ecpgerrno.h:21
char * ecpg_auto_alloc(long, int)
Definition: memory.c:108
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
static PGresult * ecpg_result_by_descriptor(int line, const char *name)
Definition: descriptor.c:61
Definition: sqlca.h:19
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3007
#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX
long sqlerrd[6]
Definition: sqlca.h:30
#define locale_t
Definition: win32_port.h:363
void ecpg_log(const char *format,...) pg_attribute_printf(1
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
ECPGdtype
Definition: ecpgtype.h:71
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:306
int PQfmod(const PGresult *res, int field_num)
Definition: fe-exec.c:3029
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
static unsigned int ecpg_dynamic_type_DDT(Oid type)
Definition: descriptor.c:71
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
#define RETURN_IF_NO_DATA
Definition: descriptor.c:233
#define snprintf
Definition: port.h:192
ECPGttype
Definition: ecpgtype.h:41

◆ ECPGget_desc_header()

bool ECPGget_desc_header ( int  ,
const char *  ,
int *   
)

Definition at line 91 of file descriptor.c.

References ecpg_init_sqlca(), ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_result_by_descriptor(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGget_sqlca(), PQnfields(), sqlca, and sqlca_t::sqlerrd.

Referenced by main().

92 {
93  PGresult *ECPGresult;
94  struct sqlca_t *sqlca = ECPGget_sqlca();
95 
96  if (sqlca == NULL)
97  {
100  return false;
101  }
102 
103  ecpg_init_sqlca(sqlca);
104  ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
105  if (!ECPGresult)
106  return false;
107 
108  *count = PQnfields(ECPGresult);
109  sqlca->sqlerrd[2] = 1;
110  ecpg_log("ECPGget_desc_header: found %d attributes\n", *count);
111  return true;
112 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define sqlca
Definition: sqlca.h:59
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
static PGresult * ecpg_result_by_descriptor(int line, const char *name)
Definition: descriptor.c:61
Definition: sqlca.h:19
long sqlerrd[6]
Definition: sqlca.h:30
void ecpg_log(const char *format,...) pg_attribute_printf(1
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98

◆ ECPGget_PGconn()

PGconn* ECPGget_PGconn ( const char *  )

Definition at line 734 of file connect.c.

References connection::connection, and ecpg_get_connection().

735 {
736  struct connection *con;
737 
738  con = ecpg_get_connection(connection_name);
739  if (con == NULL)
740  return NULL;
741 
742  return con->connection;
743 }
PGconn * connection
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGget_var()

void* ECPGget_var ( int  number)

Definition at line 581 of file misc.c.

References var_list::next, var_list::number, and var_list::pointer.

Referenced by ECPG_informix_get_var(), get_record1(), open_cur1(), and openit().

582 {
583  struct var_list *ptr;
584 
585  for (ptr = ivlist; ptr != NULL && ptr->number != number; ptr = ptr->next);
586  return (ptr) ? ptr->pointer : NULL;
587 }
struct var_list * next
void * pointer
struct var_list * ivlist
Definition: misc.c:523

◆ ECPGis_noind_null()

bool ECPGis_noind_null ( enum  ECPGttype,
const void *   
)

Definition at line 388 of file misc.c.

References _check(), ECPGgeneric_bytea::arr, dgettext, ecpg_gettext, ECPGt_bytea, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGt_varchar, fn(), ECPGgeneric_bytea::len, LONG_LONG_MIN, NUMERIC_NULL, PG_TEXTDOMAIN, pthread_mutex_lock(), pthread_mutex_unlock(), and sign.

Referenced by ecpg_store_input(), and risnull().

389 {
390  switch (type)
391  {
392  case ECPGt_char:
393  case ECPGt_unsigned_char:
394  case ECPGt_string:
395  if (*((const char *) ptr) == '\0')
396  return true;
397  break;
398  case ECPGt_short:
400  if (*((const short int *) ptr) == SHRT_MIN)
401  return true;
402  break;
403  case ECPGt_int:
404  case ECPGt_unsigned_int:
405  if (*((const int *) ptr) == INT_MIN)
406  return true;
407  break;
408  case ECPGt_long:
409  case ECPGt_unsigned_long:
410  case ECPGt_date:
411  if (*((const long *) ptr) == LONG_MIN)
412  return true;
413  break;
414  case ECPGt_long_long:
416  if (*((const long long *) ptr) == LONG_LONG_MIN)
417  return true;
418  break;
419  case ECPGt_float:
420  return _check(ptr, sizeof(float));
421  break;
422  case ECPGt_double:
423  return _check(ptr, sizeof(double));
424  break;
425  case ECPGt_varchar:
426  if (*(((const struct ECPGgeneric_varchar *) ptr)->arr) == 0x00)
427  return true;
428  break;
429  case ECPGt_bytea:
430  if (((const struct ECPGgeneric_bytea *) ptr)->len == 0)
431  return true;
432  break;
433  case ECPGt_decimal:
434  if (((const decimal *) ptr)->sign == NUMERIC_NULL)
435  return true;
436  break;
437  case ECPGt_numeric:
438  if (((const numeric *) ptr)->sign == NUMERIC_NULL)
439  return true;
440  break;
441  case ECPGt_interval:
442  return _check(ptr, sizeof(interval));
443  break;
444  case ECPGt_timestamp:
445  return _check(ptr, sizeof(timestamp));
446  break;
447  default:
448  break;
449  }
450 
451  return false;
452 }
#define LONG_LONG_MIN
Definition: misc.c:25
int64 timestamp
#define NUMERIC_NULL
static bool _check(const unsigned char *ptr, int length)
Definition: misc.c:378
char sign
Definition: informix.c:688

◆ ECPGprepare()

bool ECPGprepare ( int  ,
const char *  ,
const bool  ,
const char *  ,
const char *   
)

Definition at line 217 of file prepare.c.

References deallocate_one(), ECPG_COMPAT_PGSQL, ecpg_find_prepared_statement(), ecpg_get_connection(), ecpg_init(), and prepare_common().

Referenced by ecpg_auto_prepare(), main(), and test().

219 {
220  struct connection *con;
221  struct prepared_statement *this,
222  *prev;
223 
224  (void) questionmarks; /* quiet the compiler */
225 
226  con = ecpg_get_connection(connection_name);
227  if (!ecpg_init(con, connection_name, lineno))
228  return false;
229 
230  /* check if we already have prepared this statement */
231  this = ecpg_find_prepared_statement(name, con, &prev);
232  if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
233  return false;
234 
235  return prepare_common(lineno, con, name, variable);
236 }
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:260
bool questionmarks
Definition: ecpg.c:19
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:159
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104

◆ ECPGprepared_statement()

char* ECPGprepared_statement ( const char *  ,
const char *  ,
int   
)

Definition at line 368 of file prepare.c.

References ecpg_get_connection(), and ecpg_prepared().

Referenced by main(), and test().

369 {
370  (void) lineno; /* keep the compiler quiet */
371 
372  return ecpg_prepared(name, ecpg_get_connection(connection_name));
373 }
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:357
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGset_desc()

bool ECPGset_desc ( int  ,
const char *  ,
int  ,
  ... 
)

Definition at line 607 of file descriptor.c.

References generate_unaccent_rules::args, variable::arrsize, descriptor::count, ecpg_alloc(), ecpg_find_desc(), ecpg_free(), ecpg_raise(), ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ecpg_store_input(), ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPGd_data, ECPGd_EODT, ECPGd_indicator, ECPGd_length, ECPGd_precision, ECPGd_scale, ECPGd_type, descriptor_item::indicator, descriptor::items, descriptor_item::length, descriptor_item::next, variable::next, descriptor_item::num, variable::offset, variable::pointer, descriptor_item::precision, descriptor_item::scale, set_desc_attr(), set_int_item(), snprintf, descriptor_item::type, variable::type, variable::value, and variable::varcharsize.

Referenced by main().

608 {
609  va_list args;
610  struct descriptor *desc;
611  struct descriptor_item *desc_item;
612  struct variable *var;
613 
614  desc = ecpg_find_desc(lineno, desc_name);
615  if (desc == NULL)
616  return false;
617 
618  for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
619  {
620  if (desc_item->num == index)
621  break;
622  }
623 
624  if (desc_item == NULL)
625  {
626  desc_item = (struct descriptor_item *) ecpg_alloc(sizeof(*desc_item), lineno);
627  if (!desc_item)
628  return false;
629  desc_item->num = index;
630  if (desc->count < index)
631  desc->count = index;
632  desc_item->next = desc->items;
633  desc->items = desc_item;
634  }
635 
636  if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
637  return false;
638 
639  va_start(args, index);
640 
641  for (;;)
642  {
643  enum ECPGdtype itemtype;
644  char *tobeinserted = NULL;
645 
646  itemtype = va_arg(args, enum ECPGdtype);
647 
648  if (itemtype == ECPGd_EODT)
649  break;
650 
651  var->type = va_arg(args, enum ECPGttype);
652  var->pointer = va_arg(args, char *);
653 
654  var->varcharsize = va_arg(args, long);
655  var->arrsize = va_arg(args, long);
656  var->offset = va_arg(args, long);
657 
658  if (var->arrsize == 0 || var->varcharsize == 0)
659  var->value = *((char **) (var->pointer));
660  else
661  var->value = var->pointer;
662 
663  /*
664  * negative values are used to indicate an array without given bounds
665  */
666  /* reset to zero for us */
667  if (var->arrsize < 0)
668  var->arrsize = 0;
669  if (var->varcharsize < 0)
670  var->varcharsize = 0;
671 
672  var->next = NULL;
673 
674  switch (itemtype)
675  {
676  case ECPGd_data:
677  {
678  if (!ecpg_store_input(lineno, true, var, &tobeinserted, false))
679  {
680  ecpg_free(var);
681  va_end(args);
682  return false;
683  }
684 
685  set_desc_attr(desc_item, var, tobeinserted);
686  tobeinserted = NULL;
687  break;
688  }
689 
690  case ECPGd_indicator:
691  set_int_item(lineno, &desc_item->indicator, var->pointer, var->type);
692  break;
693 
694  case ECPGd_length:
695  set_int_item(lineno, &desc_item->length, var->pointer, var->type);
696  break;
697 
698  case ECPGd_precision:
699  set_int_item(lineno, &desc_item->precision, var->pointer, var->type);
700  break;
701 
702  case ECPGd_scale:
703  set_int_item(lineno, &desc_item->scale, var->pointer, var->type);
704  break;
705 
706  case ECPGd_type:
707  set_int_item(lineno, &desc_item->type, var->pointer, var->type);
708  break;
709 
710  default:
711  {
712  char type_str[20];
713 
714  snprintf(type_str, sizeof(type_str), "%d", itemtype);
716  ecpg_free(var);
717  va_end(args);
718  return false;
719  }
720  }
721  }
722  ecpg_free(var);
723  va_end(args);
724 
725  return true;
726 }
bool ecpg_store_input(const int, const bool, const struct variable *, char **, bool)
Definition: execute.c:509
static bool set_int_item(int lineno, int *target, const void *var, enum ECPGttype vartype)
Definition: descriptor.c:158
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_free(void *)
Definition: memory.c:13
void * pointer
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
enum ECPGttype type
struct variable * next
Definition: type.h:89
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:837
void * value
char * ecpg_alloc(long, int)
Definition: memory.c:19
ECPGdtype
Definition: ecpgtype.h:71
struct descriptor_item * items
struct descriptor_item * next
static void set_desc_attr(struct descriptor_item *desc_item, struct variable *var, char *tobeinserted)
Definition: descriptor.c:586
#define snprintf
Definition: port.h:192
long varcharsize
ECPGttype
Definition: ecpgtype.h:41

◆ ECPGset_desc_header()

bool ECPGset_desc_header ( int  ,
const char *  ,
int   
)

Definition at line 575 of file descriptor.c.

References descriptor::count, and ecpg_find_desc().

Referenced by main().

576 {
577  struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
578 
579  if (desc == NULL)
580  return false;
581  desc->count = count;
582  return true;
583 }
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:837

◆ ECPGset_noind_null()

void ECPGset_noind_null ( enum  ECPGttype,
void *   
)

Definition at line 319 of file misc.c.

References ECPGt_bytea, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGt_varchar, LONG_LONG_MIN, and NUMERIC_NULL.

Referenced by ecpg_get_data(), ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), and rsetnull().

320 {
321  switch (type)
322  {
323  case ECPGt_char:
324  case ECPGt_unsigned_char:
325  case ECPGt_string:
326  *((char *) ptr) = '\0';
327  break;
328  case ECPGt_short:
330  *((short int *) ptr) = SHRT_MIN;
331  break;
332  case ECPGt_int:
333  case ECPGt_unsigned_int:
334  *((int *) ptr) = INT_MIN;
335  break;
336  case ECPGt_long:
337  case ECPGt_unsigned_long:
338  case ECPGt_date:
339  *((long *) ptr) = LONG_MIN;
340  break;
341  case ECPGt_long_long:
343  *((long long *) ptr) = LONG_LONG_MIN;
344  break;
345  case ECPGt_float:
346  memset((char *) ptr, 0xff, sizeof(float));
347  break;
348  case ECPGt_double:
349  memset((char *) ptr, 0xff, sizeof(double));
350  break;
351  case ECPGt_varchar:
352  *(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
353  ((struct ECPGgeneric_varchar *) ptr)->len = 0;
354  break;
355  case ECPGt_bytea:
356  ((struct ECPGgeneric_bytea *) ptr)->len = 0;
357  break;
358  case ECPGt_decimal:
359  memset((char *) ptr, 0, sizeof(decimal));
360  ((decimal *) ptr)->sign = NUMERIC_NULL;
361  break;
362  case ECPGt_numeric:
363  memset((char *) ptr, 0, sizeof(numeric));
364  ((numeric *) ptr)->sign = NUMERIC_NULL;
365  break;
366  case ECPGt_interval:
367  memset((char *) ptr, 0xff, sizeof(interval));
368  break;
369  case ECPGt_timestamp:
370  memset((char *) ptr, 0xff, sizeof(timestamp));
371  break;
372  default:
373  break;
374  }
375 }
#define LONG_LONG_MIN
Definition: misc.c:25
int64 timestamp
#define NUMERIC_NULL

◆ ECPGset_var()

void ECPGset_var ( int  ,
void *  ,
int   
)

Definition at line 526 of file misc.c.

References calloc, ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGfree_auto_mem(), ECPGget_sqlca(), ivlist, var_list::next, var_list::number, var_list::pointer, snprintf, sqlca_t::sqlcode, sqlca_t::sqlerrm, sqlca_t::sqlerrmc, sqlca_t::sqlerrml, and sqlca_t::sqlstate.

Referenced by ECPG_informix_set_var(), get_var1(), and main().

527 {
528  struct var_list *ptr;
529 
530  struct sqlca_t *sqlca = ECPGget_sqlca();
531 
532  if (sqlca == NULL)
533  {
536  return;
537  }
538 
539  ecpg_init_sqlca(sqlca);
540 
541  for (ptr = ivlist; ptr != NULL; ptr = ptr->next)
542  {
543  if (ptr->number == number)
544  {
545  /* already known => just change pointer value */
546  ptr->pointer = pointer;
547  return;
548  }
549  }
550 
551  /* a new one has to be added */
552  ptr = (struct var_list *) calloc(1L, sizeof(struct var_list));
553  if (!ptr)
554  {
555  struct sqlca_t *sqlca = ECPGget_sqlca();
556 
557  if (sqlca == NULL)
558  {
561  return;
562  }
563 
564  sqlca->sqlcode = ECPG_OUT_OF_MEMORY;
565  strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
566  snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);
567  sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
568  /* free all memory we have allocated for the user */
570  }
571  else
572  {
573  ptr->number = number;
574  ptr->pointer = pointer;
575  ptr->next = ivlist;
576  ivlist = ptr;
577  }
578 }
#define calloc(a, b)
Definition: header.h:55
struct var_list * next
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ECPGfree_auto_mem(void)
Definition: memory.c:138
void * pointer
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
int sqlerrml
Definition: sqlca.h:26
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
char sqlstate[5]
Definition: sqlca.h:53
long sqlcode
Definition: sqlca.h:23
static struct sqlca_t sqlca
Definition: misc.c:62
struct sqlca_t::@148 sqlerrm
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
#define snprintf
Definition: port.h:192
struct var_list * ivlist
Definition: misc.c:523

◆ ECPGsetcommit()

bool ECPGsetcommit ( int  ,
const char *  ,
const char *   
)

Definition at line 165 of file connect.c.

References connection::autocommit, connection::connection, ecpg_check_PQresult(), ECPG_COMPAT_PGSQL, ecpg_get_connection(), ecpg_init(), ecpg_log(), connection::name, PQclear(), PQexec(), PQTRANS_IDLE, and PQtransactionStatus().

Referenced by main().

166 {
167  struct connection *con = ecpg_get_connection(connection_name);
168  PGresult *results;
169 
170  if (!ecpg_init(con, connection_name, lineno))
171  return false;
172 
173  ecpg_log("ECPGsetcommit on line %d: action \"%s\"; connection \"%s\"\n", lineno, mode, con->name);
174 
175  if (con->autocommit && strncmp(mode, "off", strlen("off")) == 0)
176  {
178  {
179  results = PQexec(con->connection, "begin transaction");
180  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
181  return false;
182  PQclear(results);
183  }
184  con->autocommit = false;
185  }
186  else if (!con->autocommit && strncmp(mode, "on", strlen("on")) == 0)
187  {
189  {
190  results = PQexec(con->connection, "commit");
191  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
192  return false;
193  PQclear(results);
194  }
195  con->autocommit = true;
196  }
197 
198  return true;
199 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
void ecpg_log(const char *format,...) pg_attribute_printf(1
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6572
void PQclear(PGresult *res)
Definition: fe-exec.c:694
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1939
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104

◆ ECPGsetconn()

bool ECPGsetconn ( int  ,
const char *   
)

Definition at line 202 of file connect.c.

References ecpg_get_connection(), ecpg_init(), and pthread_setspecific().

Referenced by main().

203 {
204  struct connection *con = ecpg_get_connection(connection_name);
205 
206  if (!ecpg_init(con, connection_name, lineno))
207  return false;
208 
209 #ifdef ENABLE_THREAD_SAFETY
210  pthread_setspecific(actual_connection_key, con);
211 #else
212  actual_connection = con;
213 #endif
214  return true;
215 }
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
static struct connection * actual_connection
Definition: connect.c:18
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:104

◆ ECPGstatus()

bool ECPGstatus ( int  ,
const char *   
)

Definition at line 164 of file misc.c.

References connection::connection, ecpg_get_connection(), ecpg_init(), ECPG_NOT_CONN, ecpg_raise(), ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, and connection::name.

165 {
166  struct connection *con = ecpg_get_connection(connection_name);
167 
168  if (!ecpg_init(con, connection_name, lineno))
169  return false;
170 
171  /* are we connected? */
172  if (con->connection == NULL)
173  {
175  return false;
176  }
177 
178  return true;
179 }
#define ECPG_NOT_CONN
Definition: ecpgerrno.h:37
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
PGconn * connection
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:104
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGtrans()

bool ECPGtrans ( int  ,
const char *  ,
const char *   
)

Definition at line 198 of file misc.c.

References connection::autocommit, connection::connection, ecpg_check_PQresult(), ECPG_COMPAT_PGSQL, ecpg_get_connection(), ecpg_init(), ecpg_log(), connection::name, PQclear(), PQexec(), PQTRANS_IDLE, and PQtransactionStatus().

Referenced by main(), and sql_check().

199 {
200  PGresult *res;
201  struct connection *con = ecpg_get_connection(connection_name);
202 
203  if (!ecpg_init(con, connection_name, lineno))
204  return false;
205 
206  ecpg_log("ECPGtrans on line %d: action \"%s\"; connection \"%s\"\n", lineno, transaction, con ? con->name : "null");
207 
208  /* if we have no connection we just simulate the command */
209  if (con && con->connection)
210  {
211  /*
212  * If we got a transaction command but have no open transaction, we
213  * have to start one, unless we are in autocommit, where the
214  * developers have to take care themselves. However, if the command is
215  * a begin statement, we just execute it once. And if the command is
216  * commit or rollback prepared, we don't execute it.
217  */
219  !con->autocommit &&
220  strncmp(transaction, "begin", 5) != 0 &&
221  strncmp(transaction, "start", 5) != 0 &&
222  strncmp(transaction, "commit prepared", 15) != 0 &&
223  strncmp(transaction, "rollback prepared", 17) != 0)
224  {
225  res = PQexec(con->connection, "begin transaction");
226  if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
227  return false;
228  PQclear(res);
229  }
230 
231  res = PQexec(con->connection, transaction);
232  if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
233  return false;
234  PQclear(res);
235  }
236 
237  return true;
238 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6572
void ecpg_log(const char *format,...)
Definition: misc.c:266
void PQclear(PGresult *res)
Definition: fe-exec.c:694
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:104
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1939

◆ ECPGtransactionStatus()

PGTransactionStatusType ECPGtransactionStatus ( const char *  )

Definition at line 182 of file misc.c.

References connection::connection, ecpg_get_connection(), PQTRANS_UNKNOWN, and PQtransactionStatus().

183 {
184  const struct connection *con;
185 
186  con = ecpg_get_connection(connection_name);
187  if (con == NULL)
188  {
189  /* transaction status is unknown */
190  return PQTRANS_UNKNOWN;
191  }
192 
193  return PQtransactionStatus(con->connection);
194 
195 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6572
PGconn * connection
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ sqlprint()

void sqlprint ( void  )

Definition at line 336 of file error.c.

References ecpg_gettext, ecpg_log(), ECPGget_sqlca(), fprintf, sqlca, sqlca_t::sqlerrm, sqlca_t::sqlerrmc, and sqlca_t::sqlerrml.

Referenced by check_result_of_insert(), fn(), main(), print(), print2(), and test().

337 {
338  struct sqlca_t *sqlca = ECPGget_sqlca();
339 
340  if (sqlca == NULL)
341  {
342  ecpg_log("out of memory");
343  return;
344  }
345 
346  sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml] = '\0';
347  fprintf(stderr, ecpg_gettext("SQL error: %s\n"), sqlca->sqlerrm.sqlerrmc);
348 }
#define sqlca
Definition: sqlca.h:59
int sqlerrml
Definition: sqlca.h:26
#define fprintf
Definition: port.h:196
#define ecpg_gettext(x)
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct sqlca_t::@148 sqlerrm
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27