PostgreSQL Source Code  git master
ecpglib.h File Reference
#include "libpq-fe.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 ecpg_gettext(x)   (x)
 
#define bool   char
 
#define true   ((bool) 1)
 
#define false   ((bool) 0)
 
#define TRUE   1
 
#define FALSE   0
 
#define SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

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 *)
 
char * ECPGerrmsg (void)
 
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

◆ bool

#define bool   char

Definition at line 23 of file ecpglib.h.

◆ ecpg_gettext

#define ecpg_gettext (   x)    (x)

◆ false

#define false   ((bool) 0)

Definition at line 30 of file ecpglib.h.

◆ FALSE

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 69 of file ecpglib.h.

Referenced by sql_check().

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 70 of file ecpglib.h.

◆ true

#define true   ((bool) 1)

Definition at line 27 of file ecpglib.h.

◆ TRUE

Function Documentation

◆ ECPGallocate_desc()

bool ECPGallocate_desc ( int  ,
const char *   
)

Definition at line 760 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().

761 {
762  struct descriptor *new;
763  struct sqlca_t *sqlca = ECPGget_sqlca();
764 
765  if (sqlca == NULL)
766  {
769  return false;
770  }
771 
772  ecpg_init_sqlca(sqlca);
773  new = (struct descriptor *) ecpg_alloc(sizeof(struct descriptor), line);
774  if (!new)
775  return false;
776  new->next = get_descriptors();
777  new->name = ecpg_alloc(strlen(name) + 1, line);
778  if (!new->name)
779  {
780  ecpg_free(new);
781  return false;
782  }
783  new->count = -1;
784  new->items = NULL;
785  new->result = PQmakeEmptyPGresult(NULL, 0);
786  if (!new->result)
787  {
788  ecpg_free(new->name);
789  ecpg_free(new);
791  return false;
792  }
793  strcpy(new->name, name);
794  set_descriptors(new);
795  return true;
796 }
void ecpg_free(void *)
Definition: memory.c:13
#define sqlca
Definition: sqlca.h:59
#define set_descriptors(value)
Definition: descriptor.c:57
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:222
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
Definition: sqlca.h:19
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
Definition: fe-exec.c:142
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
const char * name
Definition: encode.c:521
#define get_descriptors()
Definition: descriptor.c:56

◆ 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, 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  if (options)
518  for (i = 0; options[i]; i++)
519  /* count options */
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  /* options look like this "option1 = value1 option2 = value2 ... */
587  /* we have to break up the string into single options */
588  for (str = options; *str;)
589  {
590  int e,
591  a;
592  char *token1,
593  *token2;
594 
595  for (token1 = str; *token1 && *token1 == ' '; token1++);
596  for (e = 0; token1[e] && token1[e] != '='; e++);
597  if (token1[e]) /* found "=" */
598  {
599  token1[e] = '\0';
600  for (token2 = token1 + e + 1; *token2 && *token2 == ' '; token2++);
601  for (a = 0; token2[a] && token2[a] != '&'; a++);
602  if (token2[a]) /* found "&" => another option follows */
603  {
604  token2[a] = '\0';
605  str = token2 + a + 1;
606  }
607  else
608  str = token2 + a;
609 
610  conn_keywords[i] = token1;
611  conn_values[i] = token2;
612  i++;
613  }
614  else
615  /* the parser should not be able to create this invalid option */
616  str = token1 + e;
617  }
618 
619  }
620  conn_keywords[i] = NULL; /* terminator */
621 
622  this->connection = PQconnectdbParams(conn_keywords, conn_values, 0);
623 
624  if (host)
625  ecpg_free(host);
626  if (port)
627  ecpg_free(port);
628  if (options)
629  ecpg_free(options);
630  if (dbname)
631  ecpg_free(dbname);
632  ecpg_free(conn_values);
633  ecpg_free(conn_keywords);
634 
635  if (PQstatus(this->connection) == CONNECTION_BAD)
636  {
637  const char *errmsg = PQerrorMessage(this->connection);
638  const char *db = realname ? realname : ecpg_gettext("<DEFAULT>");
639 
640  ecpg_log("ECPGconnect: could not open database: %s\n", errmsg);
641 
642  ecpg_finish(this);
643 #ifdef ENABLE_THREAD_SAFETY
644  pthread_mutex_unlock(&connections_mutex);
645 #endif
646 
648  if (realname)
649  ecpg_free(realname);
650 
651  return false;
652  }
653 
654  if (realname)
655  ecpg_free(realname);
656 
657 #ifdef ENABLE_THREAD_SAFETY
658  pthread_mutex_unlock(&connections_mutex);
659 #endif
660 
661  this->autocommit = autocommit;
662 
663  PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this);
664 
665  return true;
666 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6116
static void ecpg_finish(struct connection *act)
Definition: connect.c:113
#define ECPG_CONNECT
Definition: ecpgerrno.h:51
static int32 next
Definition: blutils.c:211
void ecpg_free(void *)
Definition: memory.c:13
#define INFORMIX_MODE(X)
Definition: extern.h:23
#define sqlca
Definition: sqlca.h:59
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:222
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:536
void ecpg_log(const char *format,...) pg_attribute_printf(1
#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:142
struct ECPGtype_information_cache * cache_head
Definition: extern.h:85
Definition: sqlca.h:19
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
char * c
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
enum COMPAT_MODE compat
Definition: ecpg.c:25
static int port
Definition: pg_regress.c:90
bool ecpg_internal_regression_mode
Definition: misc.c:30
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
#define ecpg_gettext(x)
Definition: ecpglib.h:18
char * last_dir_separator(const char *filename)
Definition: path.c:138
#define free(a)
Definition: header.h:65
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
bool autocommit
Definition: ecpg.c:15
char * dbname
Definition: streamutil.c:51
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
static char * user
Definition: pg_regress.c:93
int errmsg(const char *fmt,...)
Definition: elog.c:797
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
static struct connection * actual_connection
Definition: connect.c:18
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
Definition: extern.h:206
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
int i
COMPAT_MODE
Definition: extern.h:16
static void ECPGnoticeReceiver(void *arg, const PGresult *result)
Definition: connect.c:219
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6063
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
Definition: fe-connect.c:6275
struct prepared_statement * prep_stmts
Definition: extern.h:86

◆ ECPGdeallocate()

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

Definition at line 253 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().

254 {
255  struct connection *con;
256  struct prepared_statement *this,
257  *prev;
258 
259  con = ecpg_get_connection(connection_name);
260 
261  if (!ecpg_init(con, connection_name, lineno))
262  return false;
263 
264  this = ecpg_find_prepared_statement(name, con, &prev);
265  if (this)
266  return deallocate_one(lineno, c, con, prev, this);
267 
268  /* prepared statement is not found */
269  if (INFORMIX_MODE(c))
270  return true;
272  return false;
273 }
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
#define INFORMIX_MODE(X)
Definition: extern.h:23
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:201
char * c
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
Definition: extern.h:213
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:182
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGdeallocate_all()

bool ECPGdeallocate_all ( int  ,
int  ,
const char *   
)

Definition at line 289 of file prepare.c.

References ecpg_deallocate_all_conn(), and ecpg_get_connection().

Referenced by main().

290 {
291  return ecpg_deallocate_all_conn(lineno, compat, ecpg_get_connection(connection_name));
292 }
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
Definition: prepare.c:276
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 713 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().

714 {
715  struct descriptor *desc;
716  struct descriptor *prev;
717  struct sqlca_t *sqlca = ECPGget_sqlca();
718 
719  if (sqlca == NULL)
720  {
723  return false;
724  }
725 
726  ecpg_init_sqlca(sqlca);
727  for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
728  {
729  if (strcmp(name, desc->name) == 0)
730  {
731  if (prev)
732  prev->next = desc->next;
733  else
734  set_descriptors(desc->next);
735  descriptor_free(desc);
736  return true;
737  }
738  }
740  return false;
741 }
#define sqlca
Definition: sqlca.h:59
#define set_descriptors(value)
Definition: descriptor.c:57
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:222
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
Definition: extern.h:214
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct descriptor * next
Definition: extern.h:95
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
Definition: sqlca.h:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:693
const char * name
Definition: encode.c:521
#define get_descriptors()
Definition: descriptor.c:56

◆ ECPGdebug()

void ECPGdebug ( int  ,
FILE *   
)

Definition at line 243 of file misc.c.

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

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

◆ ECPGdescribe()

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

Definition at line 815 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().

816 {
817  bool ret = false;
818  struct connection *con;
819  struct prepared_statement *prep;
820  PGresult *res;
821  va_list args;
822 
823  /* DESCRIBE INPUT is not yet supported */
824  if (input)
825  {
827  return ret;
828  }
829 
830  con = ecpg_get_connection(connection_name);
831  if (!con)
832  {
834  connection_name ? connection_name : ecpg_gettext("NULL"));
835  return ret;
836  }
837  prep = ecpg_find_prepared_statement(stmt_name, con, NULL);
838  if (!prep)
839  {
841  return ret;
842  }
843 
844  va_start(args, stmt_name);
845 
846  for (;;)
847  {
848  enum ECPGttype type;
849  void *ptr;
850 
851  /* variable type */
852  type = va_arg(args, enum ECPGttype);
853 
854  if (type == ECPGt_EORT)
855  break;
856 
857  /* rest of variable parameters */
858  ptr = va_arg(args, void *);
859  (void) va_arg(args, long); /* skip args */
860  (void) va_arg(args, long);
861  (void) va_arg(args, long);
862 
863  /* variable indicator */
864  (void) va_arg(args, enum ECPGttype);
865  (void) va_arg(args, void *); /* skip args */
866  (void) va_arg(args, long);
867  (void) va_arg(args, long);
868  (void) va_arg(args, long);
869 
870  switch (type)
871  {
872  case ECPGt_descriptor:
873  {
874  char *name = ptr;
875  struct descriptor *desc = ecpg_find_desc(line, name);
876 
877  if (desc == NULL)
878  break;
879 
880  res = PQdescribePrepared(con->connection, stmt_name);
881  if (!ecpg_check_PQresult(res, line, con->connection, compat))
882  break;
883 
884  if (desc->result != NULL)
885  PQclear(desc->result);
886 
887  desc->result = res;
888  ret = true;
889  break;
890  }
891  case ECPGt_sqlda:
892  {
893  if (INFORMIX_MODE(compat))
894  {
895  struct sqlda_compat **_sqlda = ptr;
896  struct sqlda_compat *sqlda;
897 
898  res = PQdescribePrepared(con->connection, stmt_name);
899  if (!ecpg_check_PQresult(res, line, con->connection, compat))
900  break;
901 
902  sqlda = ecpg_build_compat_sqlda(line, res, -1, compat);
903  if (sqlda)
904  {
905  struct sqlda_compat *sqlda_old = *_sqlda;
906  struct sqlda_compat *sqlda_old1;
907 
908  while (sqlda_old)
909  {
910  sqlda_old1 = sqlda_old->desc_next;
911  free(sqlda_old);
912  sqlda_old = sqlda_old1;
913  }
914 
915  *_sqlda = sqlda;
916  ret = true;
917  }
918 
919  PQclear(res);
920  }
921  else
922  {
923  struct sqlda_struct **_sqlda = ptr;
924  struct sqlda_struct *sqlda;
925 
926  res = PQdescribePrepared(con->connection, stmt_name);
927  if (!ecpg_check_PQresult(res, line, con->connection, compat))
928  break;
929 
930  sqlda = ecpg_build_native_sqlda(line, res, -1, compat);
931  if (sqlda)
932  {
933  struct sqlda_struct *sqlda_old = *_sqlda;
934  struct sqlda_struct *sqlda_old1;
935 
936  while (sqlda_old)
937  {
938  sqlda_old1 = sqlda_old->desc_next;
939  free(sqlda_old);
940  sqlda_old = sqlda_old1;
941  }
942 
943  *_sqlda = sqlda;
944  ret = true;
945  }
946 
947  PQclear(res);
948  }
949  break;
950  }
951  default:
952  /* nothing else may come */
953  ;
954  }
955  }
956 
957  va_end(args);
958 
959  return ret;
960 }
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
Definition: fe-exec.c:2114
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:221
struct sqlda_struct * desc_next
Definition: sqlda-native.h:39
#define INFORMIX_MODE(X)
Definition: extern.h:23
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
Definition: type.h:102
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
Definition: extern.h:207
struct sqlda_compat * desc_next
Definition: sqlda-compat.h:43
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:800
PGresult * result
Definition: extern.h:94
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
enum COMPAT_MODE compat
Definition: ecpg.c:25
struct prepared_statement * ecpg_find_prepared_statement(const char *, struct connection *, struct prepared_statement **)
Definition: prepare.c:182
struct sqlda_compat * ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:203
#define ecpg_gettext(x)
Definition: ecpglib.h:18
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:410
void PQclear(PGresult *res)
Definition: fe-exec.c:671
#define free(a)
Definition: header.h:65
PGconn * connection
Definition: extern.h:83
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
Definition: extern.h:213
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:283
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 669 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().

670 {
671  struct sqlca_t *sqlca = ECPGget_sqlca();
672  struct connection *con;
673 
674  if (sqlca == NULL)
675  {
678  return false;
679  }
680 
681 #ifdef ENABLE_THREAD_SAFETY
682  pthread_mutex_lock(&connections_mutex);
683 #endif
684 
685  if (strcmp(connection_name, "ALL") == 0)
686  {
687  ecpg_init_sqlca(sqlca);
688  for (con = all_connections; con;)
689  {
690  struct connection *f = con;
691 
692  con = con->next;
693  ecpg_finish(f);
694  }
695  }
696  else
697  {
698  con = ecpg_get_connection_nr(connection_name);
699 
700  if (!ecpg_init(con, connection_name, lineno))
701  {
702 #ifdef ENABLE_THREAD_SAFETY
703  pthread_mutex_unlock(&connections_mutex);
704 #endif
705  return false;
706  }
707  else
708  ecpg_finish(con);
709  }
710 
711 #ifdef ENABLE_THREAD_SAFETY
712  pthread_mutex_unlock(&connections_mutex);
713 #endif
714 
715  return true;
716 }
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
static void ecpg_finish(struct connection *act)
Definition: connect.c:113
#define sqlca
Definition: sqlca.h:59
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:222
#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:142
Definition: sqlca.h:19
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
struct connection * next
Definition: extern.h:87
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36

◆ ECPGdo()

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

Definition at line 2037 of file execute.c.

References generate_unaccent_rules::args, and ecpg_do().

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

2038 {
2039  va_list args;
2040  bool ret;
2041 
2042  va_start(args, query);
2043  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2044  questionmarks, st, query, args);
2045  va_end(args);
2046 
2047  return ret;
2048 }
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:2003

◆ ECPGdo_descriptor()

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

Definition at line 2052 of file execute.c.

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

2054 {
2055  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2056  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2057  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2058 }
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:2037

◆ ECPGerrmsg()

char* ECPGerrmsg ( void  )

◆ 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 246 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, 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().

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

◆ ECPGget_desc_header()

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

Definition at line 92 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().

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

◆ ECPGget_PGconn()

PGconn* ECPGget_PGconn ( const char *  )

Definition at line 719 of file connect.c.

References connection::connection, and ecpg_get_connection().

720 {
721  struct connection *con;
722 
723  con = ecpg_get_connection(connection_name);
724  if (con == NULL)
725  return NULL;
726 
727  return con->connection;
728 }
PGconn * connection
Definition: extern.h:83
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGget_var()

void* ECPGget_var ( int  number)

Definition at line 568 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().

569 {
570  struct var_list *ptr;
571 
572  for (ptr = ivlist; ptr != NULL && ptr->number != number; ptr = ptr->next);
573  return (ptr) ? ptr->pointer : NULL;
574 }
struct var_list * next
Definition: extern.h:133
void * pointer
Definition: extern.h:132
int number
Definition: extern.h:131
struct var_list * ivlist
Definition: misc.c:521

◆ ECPGis_noind_null()

bool ECPGis_noind_null ( enum  ECPGttype,
const void *   
)

Definition at line 388 of file misc.c.

References _check(), ECPGgeneric_varchar::arr, dgettext, ecpg_gettext, 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, FALSE, fn(), 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 #ifdef HAVE_LONG_LONG_INT
415  case ECPGt_long_long:
417  if (*((const long long *) ptr) == LONG_LONG_MIN)
418  return true;
419  break;
420 #endif /* HAVE_LONG_LONG_INT */
421  case ECPGt_float:
422  return _check(ptr, sizeof(float));
423  break;
424  case ECPGt_double:
425  return _check(ptr, sizeof(double));
426  break;
427  case ECPGt_varchar:
428  if (*(((const struct ECPGgeneric_varchar *) ptr)->arr) == 0x00)
429  return true;
430  break;
431  case ECPGt_decimal:
432  if (((const decimal *) ptr)->sign == NUMERIC_NULL)
433  return true;
434  break;
435  case ECPGt_numeric:
436  if (((const numeric *) ptr)->sign == NUMERIC_NULL)
437  return true;
438  break;
439  case ECPGt_interval:
440  return _check(ptr, sizeof(interval));
441  break;
442  case ECPGt_timestamp:
443  return _check(ptr, sizeof(timestamp));
444  break;
445  default:
446  break;
447  }
448 
449  return false;
450 }
int64 timestamp
#define NUMERIC_NULL
static bool _check(const unsigned char *ptr, int length)
Definition: misc.c:378
char sign
Definition: informix.c:693

◆ ECPGprepare()

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

Definition at line 161 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().

162 {
163  struct connection *con;
164  struct prepared_statement *this,
165  *prev;
166 
167  (void) questionmarks; /* quiet the compiler */
168  con = ecpg_get_connection(connection_name);
169 
170  if (!ecpg_init(con, connection_name, lineno))
171  return false;
172 
173  /* check if we already have prepared this statement */
174  this = ecpg_find_prepared_statement(name, con, &prev);
175  if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
176  return false;
177 
178  return prepare_common(lineno, con, name, variable);
179 }
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:201
bool questionmarks
Definition: ecpg.c:19
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:103
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:182
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74

◆ ECPGprepared_statement()

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

Definition at line 306 of file prepare.c.

References ecpg_get_connection(), and ecpg_prepared().

Referenced by main(), and test().

307 {
308  (void) lineno; /* keep the compiler quiet */
309  return ecpg_prepared(name, ecpg_get_connection(connection_name));
310 }
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:295
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 568 of file descriptor.c.

References generate_unaccent_rules::args, variable::arrsize, descriptor::count, descriptor_item::data, 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_int_item(), snprintf(), descriptor_item::type, variable::type, variable::value, and variable::varcharsize.

Referenced by main().

569 {
570  va_list args;
571  struct descriptor *desc;
572  struct descriptor_item *desc_item;
573  struct variable *var;
574 
575  desc = ecpg_find_desc(lineno, desc_name);
576  if (desc == NULL)
577  return false;
578 
579  for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
580  {
581  if (desc_item->num == index)
582  break;
583  }
584 
585  if (desc_item == NULL)
586  {
587  desc_item = (struct descriptor_item *) ecpg_alloc(sizeof(*desc_item), lineno);
588  if (!desc_item)
589  return false;
590  desc_item->num = index;
591  if (desc->count < index)
592  desc->count = index;
593  desc_item->next = desc->items;
594  desc->items = desc_item;
595  }
596 
597  if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
598  return false;
599 
600  va_start(args, index);
601 
602  for (;;)
603  {
604  enum ECPGdtype itemtype;
605  char *tobeinserted = NULL;
606 
607  itemtype = va_arg(args, enum ECPGdtype);
608 
609  if (itemtype == ECPGd_EODT)
610  break;
611 
612  var->type = va_arg(args, enum ECPGttype);
613  var->pointer = va_arg(args, char *);
614 
615  var->varcharsize = va_arg(args, long);
616  var->arrsize = va_arg(args, long);
617  var->offset = va_arg(args, long);
618 
619  if (var->arrsize == 0 || var->varcharsize == 0)
620  var->value = *((char **) (var->pointer));
621  else
622  var->value = var->pointer;
623 
624  /*
625  * negative values are used to indicate an array without given bounds
626  */
627  /* reset to zero for us */
628  if (var->arrsize < 0)
629  var->arrsize = 0;
630  if (var->varcharsize < 0)
631  var->varcharsize = 0;
632 
633  var->next = NULL;
634 
635  switch (itemtype)
636  {
637  case ECPGd_data:
638  {
639  if (!ecpg_store_input(lineno, true, var, &tobeinserted, false))
640  {
641  ecpg_free(var);
642  va_end(args);
643  return false;
644  }
645 
646  ecpg_free(desc_item->data); /* free() takes care of a
647  * potential NULL value */
648  desc_item->data = (char *) tobeinserted;
649  tobeinserted = NULL;
650  break;
651  }
652 
653  case ECPGd_indicator:
654  set_int_item(lineno, &desc_item->indicator, var->pointer, var->type);
655  break;
656 
657  case ECPGd_length:
658  set_int_item(lineno, &desc_item->length, var->pointer, var->type);
659  break;
660 
661  case ECPGd_precision:
662  set_int_item(lineno, &desc_item->precision, var->pointer, var->type);
663  break;
664 
665  case ECPGd_scale:
666  set_int_item(lineno, &desc_item->scale, var->pointer, var->type);
667  break;
668 
669  case ECPGd_type:
670  set_int_item(lineno, &desc_item->type, var->pointer, var->type);
671  break;
672 
673  default:
674  {
675  char type_str[20];
676 
677  snprintf(type_str, sizeof(type_str), "%d", itemtype);
679  ecpg_free(var);
680  va_end(args);
681  return false;
682  }
683  }
684  }
685  ecpg_free(var);
686  va_end(args);
687 
688  return true;
689 }
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:221
static bool set_int_item(int lineno, int *target, const void *var, enum ECPGttype vartype)
Definition: descriptor.c:161
void ecpg_free(void *)
Definition: memory.c:13
char * data
Definition: extern.h:103
void * pointer
Definition: extern.h:116
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
enum ECPGttype type
Definition: extern.h:114
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
struct variable * next
Definition: extern.h:126
Definition: type.h:89
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:800
void * value
Definition: extern.h:115
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
int count
Definition: extern.h:96
long offset
Definition: extern.h:119
ECPGdtype
Definition: ecpgtype.h:70
struct descriptor_item * items
Definition: extern.h:97
struct descriptor_item * next
Definition: extern.h:109
long arrsize
Definition: extern.h:118
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
Definition: execute.c:494
long varcharsize
Definition: extern.h:117
ECPGttype
Definition: ecpgtype.h:41

◆ ECPGset_desc_header()

bool ECPGset_desc_header ( int  ,
const char *  ,
int   
)

Definition at line 557 of file descriptor.c.

References descriptor::count, and ecpg_find_desc().

Referenced by main().

558 {
559  struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
560 
561  if (desc == NULL)
562  return false;
563  desc->count = count;
564  return true;
565 }
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:800
int count
Definition: extern.h:96

◆ ECPGset_noind_null()

void ECPGset_noind_null ( enum  ECPGttype,
void *   
)

Definition at line 320 of file misc.c.

References 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, and NUMERIC_NULL.

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

321 {
322  switch (type)
323  {
324  case ECPGt_char:
325  case ECPGt_unsigned_char:
326  case ECPGt_string:
327  *((char *) ptr) = '\0';
328  break;
329  case ECPGt_short:
331  *((short int *) ptr) = SHRT_MIN;
332  break;
333  case ECPGt_int:
334  case ECPGt_unsigned_int:
335  *((int *) ptr) = INT_MIN;
336  break;
337  case ECPGt_long:
338  case ECPGt_unsigned_long:
339  case ECPGt_date:
340  *((long *) ptr) = LONG_MIN;
341  break;
342 #ifdef HAVE_LONG_LONG_INT
343  case ECPGt_long_long:
345  *((long long *) ptr) = LONG_LONG_MIN;
346  break;
347 #endif /* HAVE_LONG_LONG_INT */
348  case ECPGt_float:
349  memset((char *) ptr, 0xff, sizeof(float));
350  break;
351  case ECPGt_double:
352  memset((char *) ptr, 0xff, sizeof(double));
353  break;
354  case ECPGt_varchar:
355  *(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
356  ((struct ECPGgeneric_varchar *) 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 }
int64 timestamp
#define NUMERIC_NULL

◆ ECPGset_var()

void ECPGset_var ( int  ,
void *  ,
int   
)

Definition at line 524 of file misc.c.

References calloc, 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().

525 {
526  struct var_list *ptr;
527 
528  for (ptr = ivlist; ptr != NULL; ptr = ptr->next)
529  {
530  if (ptr->number == number)
531  {
532  /* already known => just change pointer value */
533  ptr->pointer = pointer;
534  return;
535  }
536  }
537 
538  /* a new one has to be added */
539  ptr = (struct var_list *) calloc(1L, sizeof(struct var_list));
540  if (!ptr)
541  {
542  struct sqlca_t *sqlca = ECPGget_sqlca();
543 
544  if (sqlca == NULL)
545  {
548  return;
549  }
550 
551  sqlca->sqlcode = ECPG_OUT_OF_MEMORY;
552  strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
553  snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);
554  sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
555  /* free all memory we have allocated for the user */
557  }
558  else
559  {
560  ptr->number = number;
561  ptr->pointer = pointer;
562  ptr->next = ivlist;
563  ivlist = ptr;
564  }
565 }
#define calloc(a, b)
Definition: header.h:55
struct var_list * next
Definition: extern.h:133
struct sqlca_t::@134 sqlerrm
void ECPGfree_auto_mem(void)
Definition: memory.c:138
void * pointer
Definition: extern.h:132
int sqlerrml
Definition: sqlca.h:26
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:222
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
Definition: sqlca.h:19
int number
Definition: extern.h:131
char sqlstate[5]
Definition: sqlca.h:53
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
long sqlcode
Definition: sqlca.h:23
static struct sqlca_t sqlca
Definition: misc.c:63
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
struct var_list * ivlist
Definition: misc.c:521

◆ 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 }
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
char * name
Definition: extern.h:82
bool autocommit
Definition: extern.h:84
void ecpg_log(const char *format,...) pg_attribute_printf(1
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6071
void PQclear(PGresult *res)
Definition: fe-exec.c:671
PGconn * connection
Definition: extern.h:83
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:283
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1897

◆ 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 }
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
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

◆ ECPGstatus()

bool ECPGstatus ( int  ,
const char *   
)

Definition at line 165 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.

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

◆ ECPGtrans()

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

Definition at line 199 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().

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

◆ ECPGtransactionStatus()

PGTransactionStatusType ECPGtransactionStatus ( const char *  )

Definition at line 183 of file misc.c.

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

184 {
185  const struct connection *con;
186 
187  con = ecpg_get_connection(connection_name);
188  if (con == NULL)
189  {
190  /* transaction status is unknown */
191  return PQTRANS_UNKNOWN;
192  }
193 
194  return PQtransactionStatus(con->connection);
195 
196 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6071
PGconn * connection
Definition: extern.h:83
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(), sqlca, sqlca_t::sqlerrm, sqlca_t::sqlerrmc, and sqlca_t::sqlerrml.

Referenced by 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 }
struct sqlca_t::@134 sqlerrm
#define sqlca
Definition: sqlca.h:59
int sqlerrml
Definition: sqlca.h:26
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
Definition: sqlca.h:19
#define ecpg_gettext(x)
Definition: ecpglib.h:18
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27