PostgreSQL Source Code  git master
ecpglib.h File Reference
#include <stdbool.h>
#include <string.h>
#include "ecpg_config.h"
#include "ecpgtype.h"
#include "libpq-fe.h"
#include "sqlca.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 SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

Functions

void ECPGdebug (int n, FILE *dbgs)
 
bool ECPGstatus (int lineno, const char *connection_name)
 
bool ECPGsetcommit (int lineno, const char *mode, const char *connection_name)
 
bool ECPGsetconn (int lineno, const char *connection_name)
 
bool ECPGconnect (int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
 
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,...)
 
bool ECPGtrans (int lineno, const char *connection_name, const char *transaction)
 
bool ECPGdisconnect (int lineno, const char *connection_name)
 
bool ECPGprepare (int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
 
bool ECPGdeallocate (int lineno, int c, const char *connection_name, const char *name)
 
bool ECPGdeallocate_all (int lineno, int compat, const char *connection_name)
 
char * ECPGprepared_statement (const char *connection_name, const char *name, int lineno)
 
PGconnECPGget_PGconn (const char *connection_name)
 
PGTransactionStatusType ECPGtransactionStatus (const char *connection_name)
 
void sqlprint (void)
 
bool ECPGdo_descriptor (int line, const char *connection, const char *descriptor, const char *query)
 
bool ECPGdeallocate_desc (int line, const char *name)
 
bool ECPGallocate_desc (int line, const char *name)
 
bool ECPGget_desc_header (int lineno, const char *desc_name, int *count)
 
bool ECPGget_desc (int lineno, const char *desc_name, int index,...)
 
bool ECPGset_desc_header (int lineno, const char *desc_name, int count)
 
bool ECPGset_desc (int lineno, const char *desc_name, int index,...)
 
void ECPGset_noind_null (enum ECPGttype type, void *ptr)
 
bool ECPGis_noind_null (enum ECPGttype type, const void *ptr)
 
bool ECPGdescribe (int line, int compat, bool input, const char *connection_name, const char *stmt_name,...)
 
void ECPGset_var (int number, void *pointer, int lineno)
 
void * ECPGget_var (int number)
 
void ECPGfree_auto_mem (void)
 
void ecpg_pthreads_init (void)
 

Macro Definition Documentation

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 48 of file ecpglib.h.

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 49 of file ecpglib.h.

Function Documentation

◆ ecpg_pthreads_init()

void ecpg_pthreads_init ( void  )

Definition at line 30 of file connect.c.

31 {
33 }
static pthread_once_t actual_connection_key_once
Definition: connect.c:19
static void ecpg_actual_connection_init(void)
Definition: connect.c:24

References actual_connection_key_once, and ecpg_actual_connection_init().

Referenced by ecpg_do_prologue(), ecpg_get_connection(), ecpg_get_connection_nr(), and ECPGconnect().

◆ ECPGallocate_desc()

bool ECPGallocate_desc ( int  line,
const char *  name 
)

Definition at line 792 of file descriptor.c.

793 {
794  struct descriptor *new;
795  struct sqlca_t *sqlca = ECPGget_sqlca();
796 
797  if (sqlca == NULL)
798  {
801  return false;
802  }
803 
805  new = (struct descriptor *) ecpg_alloc(sizeof(struct descriptor), line);
806  if (!new)
807  return false;
808  new->next = get_descriptors();
809  new->name = ecpg_alloc(strlen(name) + 1, line);
810  if (!new->name)
811  {
812  ecpg_free(new);
813  return false;
814  }
815  new->count = -1;
816  new->items = NULL;
817  new->result = PQmakeEmptyPGresult(NULL, 0);
818  if (!new->result)
819  {
820  ecpg_free(new->name);
821  ecpg_free(new);
823  return false;
824  }
825  strcpy(new->name, name);
826  set_descriptors(new);
827  return true;
828 }
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
static struct descriptor * get_descriptors(void)
Definition: descriptor.c:40
static void set_descriptors(struct descriptor *value)
Definition: descriptor.c:47
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_free(void *ptr)
Definition: memory.c:13
PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
Definition: fe-exec.c:159
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20
const char * name

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

Referenced by execute_test(), fn(), and main().

◆ ECPGconnect()

bool ECPGconnect ( int  lineno,
int  c,
const char *  name,
const char *  user,
const char *  passwd,
const char *  connection_name,
int  autocommit 
)

Definition at line 255 of file connect.c.

256 {
257  struct sqlca_t *sqlca = ECPGget_sqlca();
258  enum COMPAT_MODE compat = c;
259  struct connection *this;
260  int i,
261  connect_params = 0;
262  char *dbname = name ? ecpg_strdup(name, lineno) : NULL,
263  *host = NULL,
264  *tmp,
265  *port = NULL,
266  *realname = NULL,
267  *options = NULL;
268  const char **conn_keywords;
269  const char **conn_values;
270 
271  if (sqlca == NULL)
272  {
275  ecpg_free(dbname);
276  return false;
277  }
278 
280 
281  /*
282  * clear auto_mem structure because some error handling functions might
283  * access it
284  */
286 
287  if (INFORMIX_MODE(compat))
288  {
289  char *envname;
290 
291  /*
292  * Informix uses an environment variable DBPATH that overrides the
293  * connection parameters given here. We do the same with PG_DBPATH as
294  * the syntax is different.
295  */
296  envname = getenv("PG_DBPATH");
297  if (envname)
298  {
299  ecpg_free(dbname);
300  dbname = ecpg_strdup(envname, lineno);
301  }
302  }
303 
304  if (dbname == NULL && connection_name == NULL)
305  connection_name = "DEFAULT";
306 
308 
309  /* check if the identifier is unique */
310  if (ecpg_get_connection(connection_name))
311  {
312  ecpg_free(dbname);
313  ecpg_log("ECPGconnect: connection identifier %s is already in use\n",
314  connection_name);
315  return false;
316  }
317 
318  if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
319  {
320  ecpg_free(dbname);
321  return false;
322  }
323 
324  if (dbname != NULL)
325  {
326  /* get the detail information from dbname */
327  if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0)
328  {
329  int offset = 0;
330 
331  /*
332  * only allow protocols tcp and unix
333  */
334  if (strncmp(dbname, "tcp:", 4) == 0)
335  offset = 4;
336  else if (strncmp(dbname, "unix:", 5) == 0)
337  offset = 5;
338 
339  if (strncmp(dbname + offset, "postgresql://", strlen("postgresql://")) == 0)
340  {
341 
342  /*------
343  * new style:
344  * <tcp|unix>:postgresql://server[:port][/db-name][?options]
345  *------
346  */
347  offset += strlen("postgresql://");
348 
349  tmp = strrchr(dbname + offset, '?');
350  if (tmp != NULL) /* options given */
351  {
352  options = ecpg_strdup(tmp + 1, lineno);
353  *tmp = '\0';
354  }
355 
356  tmp = last_dir_separator(dbname + offset);
357  if (tmp != NULL) /* database name given */
358  {
359  if (tmp[1] != '\0') /* non-empty database name */
360  {
361  realname = ecpg_strdup(tmp + 1, lineno);
362  connect_params++;
363  }
364  *tmp = '\0';
365  }
366 
367  tmp = strrchr(dbname + offset, ':');
368  if (tmp != NULL) /* port number given */
369  {
370  *tmp = '\0';
371  port = ecpg_strdup(tmp + 1, lineno);
372  connect_params++;
373  }
374 
375  if (strncmp(dbname, "unix:", 5) == 0)
376  {
377  /*
378  * The alternative of using "127.0.0.1" here is deprecated
379  * and undocumented; we'll keep it for backward
380  * compatibility's sake, but not extend it to allow IPv6.
381  */
382  if (strcmp(dbname + offset, "localhost") != 0 &&
383  strcmp(dbname + offset, "127.0.0.1") != 0)
384  {
385  ecpg_log("ECPGconnect: non-localhost access via sockets on line %d\n", lineno);
387  if (host)
388  ecpg_free(host);
389  if (port)
390  ecpg_free(port);
391  if (options)
393  if (realname)
394  ecpg_free(realname);
395  if (dbname)
396  ecpg_free(dbname);
397  free(this);
398  return false;
399  }
400  }
401  else
402  {
403  if (*(dbname + offset) != '\0')
404  {
405  host = ecpg_strdup(dbname + offset, lineno);
406  connect_params++;
407  }
408  }
409  }
410  }
411  else
412  {
413  /* old style: dbname[@server][:port] */
414  tmp = strrchr(dbname, ':');
415  if (tmp != NULL) /* port number given */
416  {
417  port = ecpg_strdup(tmp + 1, lineno);
418  connect_params++;
419  *tmp = '\0';
420  }
421 
422  tmp = strrchr(dbname, '@');
423  if (tmp != NULL) /* host name given */
424  {
425  host = ecpg_strdup(tmp + 1, lineno);
426  connect_params++;
427  *tmp = '\0';
428  }
429 
430  if (strlen(dbname) > 0)
431  {
432  realname = ecpg_strdup(dbname, lineno);
433  connect_params++;
434  }
435  else
436  realname = NULL;
437  }
438  }
439  else
440  realname = NULL;
441 
442  /*
443  * Count options for the allocation done below (this may produce an
444  * overestimate, it's ok).
445  */
446  if (options)
447  for (i = 0; options[i]; i++)
448  if (options[i] == '=')
449  connect_params++;
450 
451  if (user && strlen(user) > 0)
452  connect_params++;
453  if (passwd && strlen(passwd) > 0)
454  connect_params++;
455 
456  /*
457  * Allocate enough space for all connection parameters. These allocations
458  * are done before manipulating the list of connections to ease the error
459  * handling on failure.
460  */
461  conn_keywords = (const char **) ecpg_alloc((connect_params + 1) * sizeof(char *), lineno);
462  conn_values = (const char **) ecpg_alloc(connect_params * sizeof(char *), lineno);
463  if (conn_keywords == NULL || conn_values == NULL)
464  {
465  if (host)
466  ecpg_free(host);
467  if (port)
468  ecpg_free(port);
469  if (options)
471  if (realname)
472  ecpg_free(realname);
473  if (dbname)
474  ecpg_free(dbname);
475  if (conn_keywords)
476  ecpg_free(conn_keywords);
477  if (conn_values)
478  ecpg_free(conn_values);
479  free(this);
480  return false;
481  }
482 
483  /* add connection to our list */
485 
486  /*
487  * ... but first, make certain we have created ecpg_clocale. Rely on
488  * holding connections_mutex to ensure this is done by only one thread.
489  */
490 #ifdef HAVE_USELOCALE
491  if (!ecpg_clocale)
492  {
493  ecpg_clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
494  if (!ecpg_clocale)
495  {
499  if (host)
500  ecpg_free(host);
501  if (port)
502  ecpg_free(port);
503  if (options)
505  if (realname)
506  ecpg_free(realname);
507  if (dbname)
508  ecpg_free(dbname);
509  if (conn_keywords)
510  ecpg_free(conn_keywords);
511  if (conn_values)
512  ecpg_free(conn_values);
513  free(this);
514  return false;
515  }
516  }
517 #endif
518 
519  if (connection_name != NULL)
520  this->name = ecpg_strdup(connection_name, lineno);
521  else
522  this->name = ecpg_strdup(realname, lineno);
523 
524  this->cache_head = NULL;
525  this->prep_stmts = NULL;
526 
527  if (all_connections == NULL)
528  this->next = NULL;
529  else
530  this->next = all_connections;
531 
532  all_connections = this;
535 
536  ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s %s%s\n",
537  realname ? realname : "<DEFAULT>",
538  host ? host : "<DEFAULT>",
539  port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
540  options ? "with options " : "", options ? options : "",
541  (user && strlen(user) > 0) ? "for user " : "", user ? user : "");
542 
543  i = 0;
544  if (realname)
545  {
546  conn_keywords[i] = "dbname";
547  conn_values[i] = realname;
548  i++;
549  }
550  if (host)
551  {
552  conn_keywords[i] = "host";
553  conn_values[i] = host;
554  i++;
555  }
556  if (port)
557  {
558  conn_keywords[i] = "port";
559  conn_values[i] = port;
560  i++;
561  }
562  if (user && strlen(user) > 0)
563  {
564  conn_keywords[i] = "user";
565  conn_values[i] = user;
566  i++;
567  }
568  if (passwd && strlen(passwd) > 0)
569  {
570  conn_keywords[i] = "password";
571  conn_values[i] = passwd;
572  i++;
573  }
574  if (options)
575  {
576  char *str;
577 
578  /*
579  * The options string contains "keyword=value" pairs separated by
580  * '&'s. We must break this up into keywords and values to pass to
581  * libpq (it's okay to scribble on the options string). We ignore
582  * spaces just before each keyword or value. (The preprocessor used
583  * to add spaces around '&'s, making it necessary to ignore spaces
584  * before keywords here. While it no longer does that, we still must
585  * skip spaces to support code compiled with older preprocessors.)
586  */
587  for (str = options; *str;)
588  {
589  int e,
590  a;
591  char *token1,
592  *token2;
593 
594  /* Skip spaces before keyword */
595  for (token1 = str; *token1 == ' '; token1++)
596  /* skip */ ;
597  /* Find end of keyword */
598  for (e = 0; token1[e] && token1[e] != '='; e++)
599  /* skip */ ;
600  if (token1[e]) /* found "=" */
601  {
602  token1[e] = '\0';
603  /* Skip spaces before value */
604  for (token2 = token1 + e + 1; *token2 == ' '; token2++)
605  /* skip */ ;
606  /* Find end of value */
607  for (a = 0; token2[a] && token2[a] != '&'; a++)
608  /* skip */ ;
609  if (token2[a]) /* found "&" => another option follows */
610  {
611  token2[a] = '\0';
612  str = token2 + a + 1;
613  }
614  else
615  str = token2 + a;
616 
617  conn_keywords[i] = token1;
618  conn_values[i] = token2;
619  i++;
620  }
621  else
622  {
623  /* Bogus options syntax ... ignore trailing garbage */
624  str = token1 + e;
625  }
626  }
627  }
628 
629  Assert(i <= connect_params);
630  conn_keywords[i] = NULL; /* terminator */
631 
632  this->connection = PQconnectdbParams(conn_keywords, conn_values, 0);
633 
634  if (host)
635  ecpg_free(host);
636  if (port)
637  ecpg_free(port);
638  if (options)
640  if (dbname)
641  ecpg_free(dbname);
642  ecpg_free(conn_values);
643  ecpg_free(conn_keywords);
644 
645  if (PQstatus(this->connection) == CONNECTION_BAD)
646  {
647  const char *errmsg = PQerrorMessage(this->connection);
648  const char *db = realname ? realname : ecpg_gettext("<DEFAULT>");
649 
650  /* PQerrorMessage's result already has a trailing newline */
651  ecpg_log("ECPGconnect: %s", errmsg);
652 
653  ecpg_finish(this);
655 
657  if (realname)
658  ecpg_free(realname);
659 
660  return false;
661  }
662 
663  if (realname)
664  ecpg_free(realname);
665 
667 
668  this->autocommit = autocommit;
669 
671 
672  return true;
673 }
static int32 next
Definition: blutils.c:219
#define Assert(condition)
Definition: c.h:837
static void ecpg_finish(struct connection *act)
Definition: connect.c:103
static pthread_mutex_t connections_mutex
Definition: connect.c:17
void ecpg_pthreads_init(void)
Definition: connect.c:30
static pthread_key_t actual_connection_key
Definition: connect.c:18
static struct connection * all_connections
Definition: connect.c:21
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:71
static void ECPGnoticeReceiver(void *arg, const PGresult *result)
Definition: connect.c:203
static struct connection * actual_connection
Definition: connect.c:20
bool autocommit
Definition: ecpg.c:15
enum COMPAT_MODE compat
Definition: ecpg.c:26
#define ECPG_CONNECT
Definition: ecpgerrno.h:51
#define ecpg_gettext(x)
COMPAT_MODE
void ecpg_log(const char *format,...) pg_attribute_printf(1
void ecpg_clear_auto_mem(void)
Definition: memory.c:151
#define INFORMIX_MODE(X)
char * ecpg_strdup(const char *string, int lineno)
Definition: memory.c:47
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
bool ecpg_internal_regression_mode
Definition: misc.c:29
int errmsg(const char *fmt,...)
Definition: elog.c:1070
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:690
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7200
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:7137
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
Definition: fe-connect.c:7362
const char * str
#define free(a)
Definition: header.h:65
int a
Definition: isn.c:68
int i
Definition: isn.c:72
@ CONNECTION_BAD
Definition: libpq-fe.h:82
static char * user
Definition: pg_regress.c:119
static int port
Definition: pg_regress.c:115
char * last_dir_separator(const char *filename)
Definition: path.c:140
char * c
e
Definition: preproc-init.c:82
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:60
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:42
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
char * dbname
Definition: streamutil.c:50
struct ECPGtype_information_cache * cache_head
struct prepared_statement * prep_stmts
#define locale_t
Definition: win32_port.h:442

References a, actual_connection, actual_connection_key, all_connections, Assert, autocommit, connection::cache_head, compat, CONNECTION_BAD, connections_mutex, 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_pthreads_init(), 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(), locale_t, name, next, port, PQconnectdbParams(), PQerrorMessage(), PQsetNoticeReceiver(), PQstatus(), connection::prep_stmts, pthread_mutex_lock(), pthread_mutex_unlock(), pthread_setspecific(), sqlca, str, and user.

Referenced by fn(), main(), test(), and test_thread().

◆ ECPGdeallocate()

bool ECPGdeallocate ( int  lineno,
int  c,
const char *  connection_name,
const char *  name 
)

Definition at line 315 of file prepare.c.

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 }
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:73
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
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
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239

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

Referenced by execute_test(), fn(), and main().

◆ ECPGdeallocate_all()

bool ECPGdeallocate_all ( int  lineno,
int  compat,
const char *  connection_name 
)

Definition at line 350 of file prepare.c.

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

References compat, ecpg_deallocate_all_conn(), and ecpg_get_connection().

Referenced by main().

◆ ECPGdeallocate_desc()

bool ECPGdeallocate_desc ( int  line,
const char *  name 
)

Definition at line 748 of file descriptor.c.

749 {
750  struct descriptor *desc;
751  struct descriptor *prev;
752  struct sqlca_t *sqlca = ECPGget_sqlca();
753 
754  if (sqlca == NULL)
755  {
758  return false;
759  }
760 
762  for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
763  {
764  if (strcmp(name, desc->name) == 0)
765  {
766  if (prev)
767  prev->next = desc->next;
768  else
769  set_descriptors(desc->next);
770  descriptor_free(desc);
771  return true;
772  }
773  }
775  return false;
776 }
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:728
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
struct descriptor * next

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(), name, descriptor::name, descriptor::next, set_descriptors(), and sqlca.

Referenced by execute_test(), fn(), and main().

◆ ECPGdebug()

void ECPGdebug ( int  n,
FILE *  dbgs 
)

Definition at line 204 of file misc.c.

205 {
206  /* Interlock against concurrent executions of ECPGdebug() */
208 
209  /* Prevent ecpg_log() from printing while we change settings */
211 
212  if (n > 100)
213  {
215  simple_debug = n - 100;
216  }
217  else
218  simple_debug = n;
219 
220  debugstream = dbgs;
221 
222  /* We must release debug_mutex before invoking ecpg_log() ... */
224 
225  /* ... but keep holding debug_init_mutex to avoid racy printout */
226  ecpg_log("ECPGdebug: set to %d\n", simple_debug);
227 
229 }
static pthread_mutex_t debug_init_mutex
Definition: misc.c:62
static pthread_mutex_t debug_mutex
Definition: misc.c:61
void ecpg_log(const char *format,...)
Definition: misc.c:232
static FILE * debugstream
Definition: misc.c:64
static volatile int simple_debug
Definition: misc.c:63
bool ecpg_internal_regression_mode
Definition: misc.c:29

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

◆ ECPGdescribe()

bool ECPGdescribe ( int  line,
int  compat,
bool  input,
const char *  connection_name,
const char *  stmt_name,
  ... 
)

Definition at line 847 of file descriptor.c.

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

References generate_unaccent_rules::args, compat, connection::connection, sqlda_compat::desc_next, sqlda_struct::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, input, name, PQclear(), PQdescribePrepared(), res, descriptor::result, type, va_end(), and va_start().

Referenced by execute_test(), and main().

◆ ECPGdisconnect()

bool ECPGdisconnect ( int  lineno,
const char *  connection_name 
)

Definition at line 676 of file connect.c.

677 {
678  struct sqlca_t *sqlca = ECPGget_sqlca();
679  struct connection *con;
680 
681  if (sqlca == NULL)
682  {
685  return false;
686  }
687 
689 
690  if (strcmp(connection_name, "ALL") == 0)
691  {
693  for (con = all_connections; con;)
694  {
695  struct connection *f = con;
696 
697  con = con->next;
698  ecpg_finish(f);
699  }
700  }
701  else
702  {
703  con = ecpg_get_connection_nr(connection_name);
704 
705  if (!ecpg_init(con, connection_name, lineno))
706  {
708  return false;
709  }
710  else
711  ecpg_finish(con);
712  }
713 
715 
716  return true;
717 }
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
struct connection * next

References all_connections, connections_mutex, 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 fn(), main(), test(), and test_thread().

◆ ECPGdo()

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 at line 2275 of file execute.c.

2276 {
2277  va_list args;
2278  bool ret;
2279 
2280  va_start(args, query);
2281  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2282  questionmarks, st, query, args);
2283  va_end(args);
2284 
2285  return ret;
2286 }
bool force_indicator
Definition: ecpg.c:18
bool questionmarks
Definition: ecpg.c:19
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:2241

References generate_unaccent_rules::args, compat, ecpg_do(), force_indicator, statement::lineno, questionmarks, va_end(), and va_start().

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

◆ ECPGdo_descriptor()

bool ECPGdo_descriptor ( int  line,
const char *  connection,
const char *  descriptor,
const char *  query 
)

Definition at line 2290 of file execute.c.

2292 {
2293  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2294  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2295  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2296 }
@ ECPG_COMPAT_PGSQL
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
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:2275

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

◆ ECPGfree_auto_mem()

void ECPGfree_auto_mem ( void  )

Definition at line 131 of file memory.c.

132 {
133  struct auto_mem *am = get_auto_allocs();
134 
135  /* free all memory we have allocated for the user */
136  if (am)
137  {
138  do
139  {
140  struct auto_mem *act = am;
141 
142  am = am->next;
143  ecpg_free(act->pointer);
144  ecpg_free(act);
145  } while (am);
146  set_auto_allocs(NULL);
147  }
148 }
static struct auto_mem * get_auto_allocs(void)
Definition: memory.c:88
void ecpg_free(void *ptr)
Definition: memory.c:13
static void set_auto_allocs(struct auto_mem *am)
Definition: memory.c:95
void * pointer
Definition: memory.c:67
struct auto_mem * next
Definition: memory.c:68

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

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

◆ ECPGget_desc()

bool ECPGget_desc ( int  lineno,
const char *  desc_name,
int  index,
  ... 
)

Definition at line 234 of file descriptor.c.

235 {
236  va_list args;
237  PGresult *ECPGresult;
238  enum ECPGdtype type;
239  int ntuples,
240  act_tuple;
241  struct variable data_var;
242  struct sqlca_t *sqlca = ECPGget_sqlca();
243 
244  if (sqlca == NULL)
245  {
248  return false;
249  }
250 
251  va_start(args, index);
253  ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
254  if (!ECPGresult)
255  {
256  va_end(args);
257  return false;
258  }
259 
260  ntuples = PQntuples(ECPGresult);
261 
262  if (index < 1 || index > PQnfields(ECPGresult))
263  {
265  va_end(args);
266  return false;
267  }
268 
269  ecpg_log("ECPGget_desc: reading items for tuple %d\n", index);
270  --index;
271 
272  type = va_arg(args, enum ECPGdtype);
273 
274  memset(&data_var, 0, sizeof data_var);
275  data_var.type = ECPGt_EORT;
276  data_var.ind_type = ECPGt_NO_INDICATOR;
277 
278  while (type != ECPGd_EODT)
279  {
280  char type_str[20];
281  long varcharsize;
282  long offset;
283  long arrsize;
284  enum ECPGttype vartype;
285  void *var;
286 
287  vartype = va_arg(args, enum ECPGttype);
288  var = va_arg(args, void *);
289  varcharsize = va_arg(args, long);
290  arrsize = va_arg(args, long);
291  offset = va_arg(args, long);
292 
293  switch (type)
294  {
295  case (ECPGd_indicator):
297  data_var.ind_type = vartype;
298  data_var.ind_pointer = var;
299  data_var.ind_varcharsize = varcharsize;
300  data_var.ind_arrsize = arrsize;
301  data_var.ind_offset = offset;
302  if (data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0)
303  data_var.ind_value = *((void **) (data_var.ind_pointer));
304  else
305  data_var.ind_value = data_var.ind_pointer;
306  break;
307 
308  case ECPGd_data:
310  data_var.type = vartype;
311  data_var.pointer = var;
312  data_var.varcharsize = varcharsize;
313  data_var.arrsize = arrsize;
314  data_var.offset = offset;
315  if (data_var.arrsize == 0 || data_var.varcharsize == 0)
316  data_var.value = *((void **) (data_var.pointer));
317  else
318  data_var.value = data_var.pointer;
319  break;
320 
321  case ECPGd_name:
322  if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize))
323  {
324  va_end(args);
325  return false;
326  }
327 
328  ecpg_log("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index));
329  break;
330 
331  case ECPGd_nullable:
332  if (!get_int_item(lineno, var, vartype, 1))
333  {
334  va_end(args);
335  return false;
336  }
337 
338  break;
339 
340  case ECPGd_key_member:
341  if (!get_int_item(lineno, var, vartype, 0))
342  {
343  va_end(args);
344  return false;
345  }
346 
347  break;
348 
349  case ECPGd_scale:
350  if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
351  {
352  va_end(args);
353  return false;
354  }
355 
356  ecpg_log("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff);
357  break;
358 
359  case ECPGd_precision:
360  if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
361  {
362  va_end(args);
363  return false;
364  }
365 
366  ecpg_log("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16);
367  break;
368 
369  case ECPGd_octet:
370  if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
371  {
372  va_end(args);
373  return false;
374  }
375 
376  ecpg_log("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index));
377  break;
378 
379  case ECPGd_length:
380  if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
381  {
382  va_end(args);
383  return false;
384  }
385 
386  ecpg_log("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ);
387  break;
388 
389  case ECPGd_type:
390  if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type(PQftype(ECPGresult, index))))
391  {
392  va_end(args);
393  return false;
394  }
395 
396  ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type(PQftype(ECPGresult, index)));
397  break;
398 
399  case ECPGd_di_code:
400  if (!get_int_item(lineno, var, vartype, ecpg_dynamic_type_DDT(PQftype(ECPGresult, index))))
401  {
402  va_end(args);
403  return false;
404  }
405 
406  ecpg_log("ECPGget_desc: TYPE = %d\n", ecpg_dynamic_type_DDT(PQftype(ECPGresult, index)));
407  break;
408 
409  case ECPGd_cardinality:
410  if (!get_int_item(lineno, var, vartype, PQntuples(ECPGresult)))
411  {
412  va_end(args);
413  return false;
414  }
415 
416  ecpg_log("ECPGget_desc: CARDINALITY = %d\n", PQntuples(ECPGresult));
417  break;
418 
419  case ECPGd_ret_length:
420  case ECPGd_ret_octet:
421 
423 
424  /*
425  * this is like ECPGstore_result
426  */
427  if (arrsize > 0 && ntuples > arrsize)
428  {
429  ecpg_log("ECPGget_desc on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
430  lineno, ntuples, arrsize);
432  va_end(args);
433  return false;
434  }
435  /* allocate storage if needed */
436  if (arrsize == 0 && *(void **) var == NULL)
437  {
438  void *mem = ecpg_auto_alloc(offset * ntuples, lineno);
439 
440  if (!mem)
441  {
442  va_end(args);
443  return false;
444  }
445  *(void **) var = mem;
446  var = mem;
447  }
448 
449  for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
450  {
451  if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, act_tuple, index)))
452  {
453  va_end(args);
454  return false;
455  }
456  var = (char *) var + offset;
457  ecpg_log("ECPGget_desc: RETURNED[%d] = %d\n", act_tuple, PQgetlength(ECPGresult, act_tuple, index));
458  }
459  break;
460 
461  default:
462  snprintf(type_str, sizeof(type_str), "%d", type);
464  va_end(args);
465  return false;
466  }
467 
468  type = va_arg(args, enum ECPGdtype);
469  }
470 
471  if (data_var.type != ECPGt_EORT)
472  {
473  struct statement stmt;
474 
475  memset(&stmt, 0, sizeof stmt);
476  stmt.lineno = lineno;
477 
478  /* Make sure we do NOT honor the locale for numeric input */
479  /* since the database gives the standard decimal point */
480  /* (see comments in execute.c) */
481 #ifdef HAVE_USELOCALE
482 
483  /*
484  * To get here, the above PQnfields() test must have found nonzero
485  * fields. One needs a connection to create such a descriptor. (EXEC
486  * SQL SET DESCRIPTOR can populate the descriptor's "items", but it
487  * can't change the descriptor's PQnfields().) Any successful
488  * connection initializes ecpg_clocale.
489  */
490  Assert(ecpg_clocale);
491  stmt.oldlocale = uselocale(ecpg_clocale);
492 #else
493 #ifdef WIN32
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 #else
508  if (stmt.oldlocale)
509  {
510  setlocale(LC_NUMERIC, stmt.oldlocale);
511  ecpg_free(stmt.oldlocale);
512  }
513 #ifdef WIN32
514  if (stmt.oldthreadlocale != -1)
515  _configthreadlocale(stmt.oldthreadlocale);
516 #endif
517 #endif
518  }
519  else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
520 
521  /*
522  * ind_type != NO_INDICATOR should always have ind_pointer != NULL but
523  * since this might be changed manually in the .c file let's play it
524  * safe
525  */
526  {
527  /*
528  * this is like ECPGstore_result but since we don't have a data
529  * variable at hand, we can't call it
530  */
531  if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
532  {
533  ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %ld\n",
534  lineno, ntuples, data_var.ind_arrsize);
536  va_end(args);
537  return false;
538  }
539 
540  /* allocate storage if needed */
541  if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
542  {
543  void *mem = ecpg_auto_alloc(data_var.ind_offset * ntuples, lineno);
544 
545  if (!mem)
546  {
547  va_end(args);
548  return false;
549  }
550  *(void **) data_var.ind_pointer = mem;
551  data_var.ind_value = mem;
552  }
553 
554  for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
555  {
556  if (!get_int_item(lineno, data_var.ind_value, data_var.ind_type, -PQgetisnull(ECPGresult, act_tuple, index)))
557  {
558  va_end(args);
559  return false;
560  }
561  data_var.ind_value = (char *) data_var.ind_value + data_var.ind_offset;
562  ecpg_log("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
563  }
564  }
565  sqlca->sqlerrd[2] = ntuples;
566  va_end(args);
567  return true;
568 }
#define VARHDRSZ
Definition: c.h:671
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
#define ECPG_INVALID_DESCRIPTOR_INDEX
Definition: ecpgerrno.h:43
#define ECPG_TOO_MANY_MATCHES
Definition: ecpgerrno.h:21
static bool get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int varcharsize)
Definition: descriptor.c:194
#define RETURN_IF_NO_DATA
Definition: descriptor.c:226
static PGresult * ecpg_result_by_descriptor(int line, const char *name)
Definition: descriptor.c:54
static bool get_int_item(int lineno, void *var, enum ECPGttype vartype, int value)
Definition: descriptor.c:108
static unsigned int ecpg_dynamic_type_DDT(Oid type)
Definition: descriptor.c:64
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:303
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:101
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION
#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX
int ecpg_dynamic_type(Oid type)
Definition: typename.c:73
ECPGdtype
Definition: ecpgtype.h:72
@ ECPGd_scale
Definition: ecpgtype.h:86
@ ECPGd_precision
Definition: ecpgtype.h:83
@ ECPGd_length
Definition: ecpgtype.h:79
@ ECPGd_nullable
Definition: ecpgtype.h:81
@ ECPGd_type
Definition: ecpgtype.h:87
@ ECPGd_cardinality
Definition: ecpgtype.h:89
@ ECPGd_indicator
Definition: ecpgtype.h:77
@ ECPGd_ret_length
Definition: ecpgtype.h:84
@ ECPGd_di_code
Definition: ecpgtype.h:75
@ ECPGd_name
Definition: ecpgtype.h:80
@ ECPGd_key_member
Definition: ecpgtype.h:78
@ ECPGd_EODT
Definition: ecpgtype.h:88
@ ECPGd_octet
Definition: ecpgtype.h:82
@ ECPGd_ret_octet
Definition: ecpgtype.h:85
@ ECPGd_data
Definition: ecpgtype.h:74
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3887
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3719
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3567
int PQfmod(const PGresult *res, int field_num)
Definition: fe-exec.c:3741
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3489
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3730
#define stmt
Definition: indent_codes.h:59
#define snprintf
Definition: port.h:238
Definition: type.h:96
#define setlocale(a, b)
Definition: win32_port.h:485

References generate_unaccent_rules::args, variable::arrsize, Assert, 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, variable::pointer, PQfmod(), PQfname(), PQfsize(), PQftype(), PQgetisnull(), PQgetlength(), PQnfields(), PQntuples(), RETURN_IF_NO_DATA, setlocale, snprintf, sqlca, stmt, type, variable::type, va_end(), va_start(), variable::value, variable::varcharsize, and VARHDRSZ.

Referenced by execute_test(), and main().

◆ ECPGget_desc_header()

bool ECPGget_desc_header ( int  lineno,
const char *  desc_name,
int *  count 
)

Definition at line 84 of file descriptor.c.

85 {
86  PGresult *ECPGresult;
87  struct sqlca_t *sqlca = ECPGget_sqlca();
88 
89  if (sqlca == NULL)
90  {
93  return false;
94  }
95 
97  ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
98  if (!ECPGresult)
99  return false;
100 
101  *count = PQnfields(ECPGresult);
102  sqlca->sqlerrd[2] = 1;
103  ecpg_log("ECPGget_desc_header: found %d attributes\n", *count);
104  return true;
105 }

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(), and sqlca.

Referenced by execute_test(), and main().

◆ ECPGget_PGconn()

PGconn* ECPGget_PGconn ( const char *  connection_name)

Definition at line 720 of file connect.c.

721 {
722  struct connection *con;
723 
724  con = ecpg_get_connection(connection_name);
725  if (con == NULL)
726  return NULL;
727 
728  return con->connection;
729 }

References connection::connection, and ecpg_get_connection().

◆ ECPGget_var()

void* ECPGget_var ( int  number)

Definition at line 593 of file misc.c.

594 {
595  struct var_list *ptr;
596 
597  for (ptr = ivlist; ptr != NULL && ptr->number != number; ptr = ptr->next);
598  return (ptr) ? ptr->pointer : NULL;
599 }
struct var_list * ivlist
Definition: misc.c:535
struct var_list * next
void * pointer

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

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

◆ ECPGis_noind_null()

bool ECPGis_noind_null ( enum ECPGttype  type,
const void *  ptr 
)

Definition at line 361 of file misc.c.

362 {
363  switch (type)
364  {
365  case ECPGt_char:
366  case ECPGt_unsigned_char:
367  case ECPGt_string:
368  if (*((const char *) ptr) == '\0')
369  return true;
370  break;
371  case ECPGt_short:
373  if (*((const short int *) ptr) == SHRT_MIN)
374  return true;
375  break;
376  case ECPGt_int:
377  case ECPGt_unsigned_int:
378  if (*((const int *) ptr) == INT_MIN)
379  return true;
380  break;
381  case ECPGt_long:
382  case ECPGt_unsigned_long:
383  case ECPGt_date:
384  if (*((const long *) ptr) == LONG_MIN)
385  return true;
386  break;
387  case ECPGt_long_long:
389  if (*((const long long *) ptr) == LONG_LONG_MIN)
390  return true;
391  break;
392  case ECPGt_float:
393  return _check(ptr, sizeof(float));
394  break;
395  case ECPGt_double:
396  return _check(ptr, sizeof(double));
397  break;
398  case ECPGt_varchar:
399  if (*(((const struct ECPGgeneric_varchar *) ptr)->arr) == 0x00)
400  return true;
401  break;
402  case ECPGt_bytea:
403  if (((const struct ECPGgeneric_bytea *) ptr)->len == 0)
404  return true;
405  break;
406  case ECPGt_decimal:
407  if (((const decimal *) ptr)->sign == NUMERIC_NULL)
408  return true;
409  break;
410  case ECPGt_numeric:
411  if (((const numeric *) ptr)->sign == NUMERIC_NULL)
412  return true;
413  break;
414  case ECPGt_interval:
415  return _check(ptr, sizeof(interval));
416  break;
417  case ECPGt_timestamp:
418  return _check(ptr, sizeof(timestamp));
419  break;
420  default:
421  break;
422  }
423 
424  return false;
425 }
@ ECPGt_float
Definition: ecpgtype.h:47
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_decimal
Definition: ecpgtype.h:51
@ ECPGt_bytea
Definition: ecpgtype.h:67
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ ECPGt_varchar
Definition: ecpgtype.h:48
@ ECPGt_timestamp
Definition: ecpgtype.h:54
@ ECPGt_unsigned_short
Definition: ecpgtype.h:43
@ ECPGt_int
Definition: ecpgtype.h:44
@ ECPGt_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_double
Definition: ecpgtype.h:47
@ ECPGt_date
Definition: ecpgtype.h:53
@ ECPGt_interval
Definition: ecpgtype.h:55
@ ECPGt_unsigned_long
Definition: ecpgtype.h:44
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
@ ECPGt_char
Definition: ecpgtype.h:43
@ ECPGt_string
Definition: ecpgtype.h:65
char sign
Definition: informix.c:693
static bool _check(const unsigned char *ptr, int length)
Definition: misc.c:351
#define LONG_LONG_MIN
Definition: misc.c:25
const void size_t len
#define NUMERIC_NULL
int64 timestamp

References _check(), ECPGgeneric_bytea::arr, 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, len, LONG_LONG_MIN, NUMERIC_NULL, sign, and type.

Referenced by ecpg_store_input(), and risnull().

◆ ECPGprepare()

bool ECPGprepare ( int  lineno,
const char *  connection_name,
const bool  questionmarks,
const char *  name,
const char *  variable 
)

Definition at line 217 of file prepare.c.

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 prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:159

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

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

◆ ECPGprepared_statement()

char* ECPGprepared_statement ( const char *  connection_name,
const char *  name,
int  lineno 
)

Definition at line 368 of file prepare.c.

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

References ecpg_get_connection(), ecpg_prepared(), and name.

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

◆ ECPGset_desc()

bool ECPGset_desc ( int  lineno,
const char *  desc_name,
int  index,
  ... 
)

Definition at line 605 of file descriptor.c.

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

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, va_end(), va_start(), variable::value, and variable::varcharsize.

Referenced by main().

◆ ECPGset_desc_header()

bool ECPGset_desc_header ( int  lineno,
const char *  desc_name,
int  count 
)

Definition at line 573 of file descriptor.c.

574 {
575  struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
576 
577  if (desc == NULL)
578  return false;
579  desc->count = count;
580  return true;
581 }

References descriptor::count, and ecpg_find_desc().

Referenced by main().

◆ ECPGset_noind_null()

void ECPGset_noind_null ( enum ECPGttype  type,
void *  ptr 
)

Definition at line 292 of file misc.c.

293 {
294  switch (type)
295  {
296  case ECPGt_char:
297  case ECPGt_unsigned_char:
298  case ECPGt_string:
299  *((char *) ptr) = '\0';
300  break;
301  case ECPGt_short:
303  *((short int *) ptr) = SHRT_MIN;
304  break;
305  case ECPGt_int:
306  case ECPGt_unsigned_int:
307  *((int *) ptr) = INT_MIN;
308  break;
309  case ECPGt_long:
310  case ECPGt_unsigned_long:
311  case ECPGt_date:
312  *((long *) ptr) = LONG_MIN;
313  break;
314  case ECPGt_long_long:
316  *((long long *) ptr) = LONG_LONG_MIN;
317  break;
318  case ECPGt_float:
319  memset((char *) ptr, 0xff, sizeof(float));
320  break;
321  case ECPGt_double:
322  memset((char *) ptr, 0xff, sizeof(double));
323  break;
324  case ECPGt_varchar:
325  *(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00;
326  ((struct ECPGgeneric_varchar *) ptr)->len = 0;
327  break;
328  case ECPGt_bytea:
329  ((struct ECPGgeneric_bytea *) ptr)->len = 0;
330  break;
331  case ECPGt_decimal:
332  memset((char *) ptr, 0, sizeof(decimal));
333  ((decimal *) ptr)->sign = NUMERIC_NULL;
334  break;
335  case ECPGt_numeric:
336  memset((char *) ptr, 0, sizeof(numeric));
337  ((numeric *) ptr)->sign = NUMERIC_NULL;
338  break;
339  case ECPGt_interval:
340  memset((char *) ptr, 0xff, sizeof(interval));
341  break;
342  case ECPGt_timestamp:
343  memset((char *) ptr, 0xff, sizeof(timestamp));
344  break;
345  default:
346  break;
347  }
348 }

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

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

◆ ECPGset_var()

void ECPGset_var ( int  number,
void *  pointer,
int  lineno 
)

Definition at line 538 of file misc.c.

539 {
540  struct var_list *ptr;
541 
542  struct sqlca_t *sqlca = ECPGget_sqlca();
543 
544  if (sqlca == NULL)
545  {
548  return;
549  }
550 
552 
553  for (ptr = ivlist; ptr != NULL; ptr = ptr->next)
554  {
555  if (ptr->number == number)
556  {
557  /* already known => just change pointer value */
558  ptr->pointer = pointer;
559  return;
560  }
561  }
562 
563  /* a new one has to be added */
564  ptr = (struct var_list *) calloc(1L, sizeof(struct var_list));
565  if (!ptr)
566  {
567  sqlca = ECPGget_sqlca();
568 
569  if (sqlca == NULL)
570  {
573  return;
574  }
575 
576  sqlca->sqlcode = ECPG_OUT_OF_MEMORY;
577  strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
578  snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);
579  sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
580  /* free all memory we have allocated for the user */
582  }
583  else
584  {
585  ptr->number = number;
586  ptr->pointer = pointer;
587  ptr->next = ivlist;
588  ivlist = ptr;
589  }
590 }
#define calloc(a, b)
Definition: header.h:55
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
void ECPGfree_auto_mem(void)
Definition: memory.c:131

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, and sqlca.

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

◆ ECPGsetcommit()

bool ECPGsetcommit ( int  lineno,
const char *  mode,
const char *  connection_name 
)

Definition at line 153 of file connect.c.

154 {
155  struct connection *con = ecpg_get_connection(connection_name);
156  PGresult *results;
157 
158  if (!ecpg_init(con, connection_name, lineno))
159  return false;
160 
161  ecpg_log("ECPGsetcommit on line %d: action \"%s\"; connection \"%s\"\n", lineno, mode, con->name);
162 
163  if (con->autocommit && strncmp(mode, "off", strlen("off")) == 0)
164  {
166  {
167  results = PQexec(con->connection, "begin transaction");
168  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
169  return false;
170  PQclear(results);
171  }
172  con->autocommit = false;
173  }
174  else if (!con->autocommit && strncmp(mode, "on", strlen("on")) == 0)
175  {
177  {
178  results = PQexec(con->connection, "commit");
179  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
180  return false;
181  PQclear(results);
182  }
183  con->autocommit = true;
184  }
185 
186  return true;
187 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:7145
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2262
@ PQTRANS_IDLE
Definition: libpq-fe.h:142
static PgChecksumMode mode
Definition: pg_checksums.c:55

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

Referenced by fn(), and main().

◆ ECPGsetconn()

bool ECPGsetconn ( int  lineno,
const char *  connection_name 
)

Definition at line 190 of file connect.c.

191 {
192  struct connection *con = ecpg_get_connection(connection_name);
193 
194  if (!ecpg_init(con, connection_name, lineno))
195  return false;
196 
198  return true;
199 }

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

Referenced by main().

◆ ECPGstatus()

bool ECPGstatus ( int  lineno,
const char *  connection_name 
)

Definition at line 127 of file misc.c.

128 {
129  struct connection *con = ecpg_get_connection(connection_name);
130 
131  if (!ecpg_init(con, connection_name, lineno))
132  return false;
133 
134  /* are we connected? */
135  if (con->connection == NULL)
136  {
138  return false;
139  }
140 
141  return true;
142 }
#define ECPG_NOT_CONN
Definition: ecpgerrno.h:37
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:73

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

◆ ECPGtrans()

bool ECPGtrans ( int  lineno,
const char *  connection_name,
const char *  transaction 
)

Definition at line 160 of file misc.c.

161 {
162  PGresult *res;
163  struct connection *con = ecpg_get_connection(connection_name);
164 
165  if (!ecpg_init(con, connection_name, lineno))
166  return false;
167 
168  ecpg_log("ECPGtrans on line %d: action \"%s\"; connection \"%s\"\n", lineno, transaction, con ? con->name : "null");
169 
170  /* if we have no connection we just simulate the command */
171  if (con && con->connection)
172  {
173  /*
174  * If we got a transaction command but have no open transaction, we
175  * have to start one, unless we are in autocommit, where the
176  * developers have to take care themselves. However, if the command is
177  * a begin statement, we just execute it once. And if the command is
178  * commit or rollback prepared, we don't execute it.
179  */
181  !con->autocommit &&
182  strncmp(transaction, "begin", 5) != 0 &&
183  strncmp(transaction, "start", 5) != 0 &&
184  strncmp(transaction, "commit prepared", 15) != 0 &&
185  strncmp(transaction, "rollback prepared", 17) != 0)
186  {
187  res = PQexec(con->connection, "begin transaction");
189  return false;
190  PQclear(res);
191  }
192 
193  res = PQexec(con->connection, transaction);
195  return false;
196  PQclear(res);
197  }
198 
199  return true;
200 }

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

Referenced by commitTable(), main(), sql_check(), and test_thread().

◆ ECPGtransactionStatus()

PGTransactionStatusType ECPGtransactionStatus ( const char *  connection_name)

Definition at line 145 of file misc.c.

146 {
147  const struct connection *con;
148 
149  con = ecpg_get_connection(connection_name);
150  if (con == NULL)
151  {
152  /* transaction status is unknown */
153  return PQTRANS_UNKNOWN;
154  }
155 
156  return PQtransactionStatus(con->connection);
157 }
@ PQTRANS_UNKNOWN
Definition: libpq-fe.h:146

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

◆ sqlprint()

void sqlprint ( void  )

Definition at line 334 of file error.c.

335 {
336  struct sqlca_t *sqlca = ECPGget_sqlca();
337 
338  if (sqlca == NULL)
339  {
340  ecpg_log("out of memory");
341  return;
342  }
343 
344  sqlca->sqlerrm.sqlerrmc[sqlca->sqlerrm.sqlerrml] = '\0';
345  fprintf(stderr, ecpg_gettext("SQL error: %s\n"), sqlca->sqlerrm.sqlerrmc);
346 }
#define fprintf
Definition: port.h:242

References ecpg_gettext, ecpg_log(), ECPGget_sqlca(), fprintf, and sqlca.

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