PostgreSQL Source Code  git master
ecpglib.h File Reference
#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 true   ((bool) 1)
 
#define false   ((bool) 0)
 
#define SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

Typedefs

typedef unsigned char bool
 

Functions

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

Macro Definition Documentation

◆ false

#define false   ((bool) 0)

Definition at line 40 of file ecpglib.h.

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 72 of file ecpglib.h.

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 73 of file ecpglib.h.

◆ true

#define true   ((bool) 1)

Definition at line 36 of file ecpglib.h.

Typedef Documentation

◆ bool

typedef unsigned char bool

Definition at line 32 of file ecpglib.h.

Function Documentation

◆ ECPGallocate_desc()

bool ECPGallocate_desc ( int  line,
const char *  name 
)

Definition at line 797 of file descriptor.c.

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

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 271 of file connect.c.

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 
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  if (dbname == NULL && connection_name == NULL)
321  connection_name = "DEFAULT";
322 
323 #if ENABLE_THREAD_SAFETY
324  ecpg_pthreads_init();
325 #endif
326 
327  /* check if the identifier is unique */
328  if (ecpg_get_connection(connection_name))
329  {
330  ecpg_free(dbname);
331  ecpg_log("ECPGconnect: connection identifier %s is already in use\n",
332  connection_name);
333  return false;
334  }
335 
336  if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
337  {
338  ecpg_free(dbname);
339  return false;
340  }
341 
342  if (dbname != NULL)
343  {
344  /* get the detail information from dbname */
345  if (strncmp(dbname, "tcp:", 4) == 0 || strncmp(dbname, "unix:", 5) == 0)
346  {
347  int offset = 0;
348 
349  /*
350  * only allow protocols tcp and unix
351  */
352  if (strncmp(dbname, "tcp:", 4) == 0)
353  offset = 4;
354  else if (strncmp(dbname, "unix:", 5) == 0)
355  offset = 5;
356 
357  if (strncmp(dbname + offset, "postgresql://", strlen("postgresql://")) == 0)
358  {
359 
360  /*------
361  * new style:
362  * <tcp|unix>:postgresql://server[:port][/db-name][?options]
363  *------
364  */
365  offset += strlen("postgresql://");
366 
367  tmp = strrchr(dbname + offset, '?');
368  if (tmp != NULL) /* options given */
369  {
370  options = ecpg_strdup(tmp + 1, lineno);
371  *tmp = '\0';
372  }
373 
374  tmp = last_dir_separator(dbname + offset);
375  if (tmp != NULL) /* database name given */
376  {
377  if (tmp[1] != '\0') /* non-empty database name */
378  {
379  realname = ecpg_strdup(tmp + 1, lineno);
380  connect_params++;
381  }
382  *tmp = '\0';
383  }
384 
385  tmp = strrchr(dbname + offset, ':');
386  if (tmp != NULL) /* port number given */
387  {
388  *tmp = '\0';
389  port = ecpg_strdup(tmp + 1, lineno);
390  connect_params++;
391  }
392 
393  if (strncmp(dbname, "unix:", 5) == 0)
394  {
395  /*
396  * The alternative of using "127.0.0.1" here is deprecated
397  * and undocumented; we'll keep it for backward
398  * compatibility's sake, but not extend it to allow IPv6.
399  */
400  if (strcmp(dbname + offset, "localhost") != 0 &&
401  strcmp(dbname + offset, "127.0.0.1") != 0)
402  {
403  ecpg_log("ECPGconnect: non-localhost access via sockets on line %d\n", lineno);
405  if (host)
406  ecpg_free(host);
407  if (port)
408  ecpg_free(port);
409  if (options)
411  if (realname)
412  ecpg_free(realname);
413  if (dbname)
414  ecpg_free(dbname);
415  free(this);
416  return false;
417  }
418  }
419  else
420  {
421  if (*(dbname + offset) != '\0')
422  {
423  host = ecpg_strdup(dbname + offset, lineno);
424  connect_params++;
425  }
426  }
427  }
428  }
429  else
430  {
431  /* old style: dbname[@server][:port] */
432  tmp = strrchr(dbname, ':');
433  if (tmp != NULL) /* port number given */
434  {
435  port = ecpg_strdup(tmp + 1, lineno);
436  connect_params++;
437  *tmp = '\0';
438  }
439 
440  tmp = strrchr(dbname, '@');
441  if (tmp != NULL) /* host name given */
442  {
443  host = ecpg_strdup(tmp + 1, lineno);
444  connect_params++;
445  *tmp = '\0';
446  }
447 
448  if (strlen(dbname) > 0)
449  {
450  realname = ecpg_strdup(dbname, lineno);
451  connect_params++;
452  }
453  else
454  realname = NULL;
455  }
456  }
457  else
458  realname = NULL;
459 
460  /*
461  * Count options for the allocation done below (this may produce an
462  * overestimate, it's ok).
463  */
464  if (options)
465  for (i = 0; options[i]; i++)
466  if (options[i] == '=')
467  connect_params++;
468 
469  if (user && strlen(user) > 0)
470  connect_params++;
471  if (passwd && strlen(passwd) > 0)
472  connect_params++;
473 
474  /*
475  * Allocate enough space for all connection parameters. These allocations
476  * are done before manipulating the list of connections to ease the error
477  * handling on failure.
478  */
479  conn_keywords = (const char **) ecpg_alloc((connect_params + 1) * sizeof(char *), lineno);
480  conn_values = (const char **) ecpg_alloc(connect_params * sizeof(char *), lineno);
481  if (conn_keywords == NULL || conn_values == NULL)
482  {
483  if (host)
484  ecpg_free(host);
485  if (port)
486  ecpg_free(port);
487  if (options)
489  if (realname)
490  ecpg_free(realname);
491  if (dbname)
492  ecpg_free(dbname);
493  if (conn_keywords)
494  ecpg_free(conn_keywords);
495  if (conn_values)
496  ecpg_free(conn_values);
497  free(this);
498  return false;
499  }
500 
501  /* add connection to our list */
502 #ifdef ENABLE_THREAD_SAFETY
503  pthread_mutex_lock(&connections_mutex);
504 #endif
505  if (connection_name != NULL)
506  this->name = ecpg_strdup(connection_name, lineno);
507  else
508  this->name = ecpg_strdup(realname, lineno);
509 
510  this->cache_head = NULL;
511  this->prep_stmts = NULL;
512 
513  if (all_connections == NULL)
514  this->next = NULL;
515  else
516  this->next = all_connections;
517 
518  all_connections = this;
519 #ifdef ENABLE_THREAD_SAFETY
520  pthread_setspecific(actual_connection_key, all_connections);
521 #endif
523 
524  ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s %s%s\n",
525  realname ? realname : "<DEFAULT>",
526  host ? host : "<DEFAULT>",
527  port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
528  options ? "with options " : "", options ? options : "",
529  (user && strlen(user) > 0) ? "for user " : "", user ? user : "");
530 
531  i = 0;
532  if (realname)
533  {
534  conn_keywords[i] = "dbname";
535  conn_values[i] = realname;
536  i++;
537  }
538  if (host)
539  {
540  conn_keywords[i] = "host";
541  conn_values[i] = host;
542  i++;
543  }
544  if (port)
545  {
546  conn_keywords[i] = "port";
547  conn_values[i] = port;
548  i++;
549  }
550  if (user && strlen(user) > 0)
551  {
552  conn_keywords[i] = "user";
553  conn_values[i] = user;
554  i++;
555  }
556  if (passwd && strlen(passwd) > 0)
557  {
558  conn_keywords[i] = "password";
559  conn_values[i] = passwd;
560  i++;
561  }
562  if (options)
563  {
564  char *str;
565 
566  /*
567  * The options string contains "keyword=value" pairs separated by
568  * '&'s. We must break this up into keywords and values to pass to
569  * libpq (it's okay to scribble on the options string). We ignore
570  * spaces just before each keyword or value.
571  */
572  for (str = options; *str;)
573  {
574  int e,
575  a;
576  char *token1,
577  *token2;
578 
579  /* Skip spaces before keyword */
580  for (token1 = str; *token1 == ' '; token1++)
581  /* skip */ ;
582  /* Find end of keyword */
583  for (e = 0; token1[e] && token1[e] != '='; e++)
584  /* skip */ ;
585  if (token1[e]) /* found "=" */
586  {
587  token1[e] = '\0';
588  /* Skip spaces before value */
589  for (token2 = token1 + e + 1; *token2 == ' '; token2++)
590  /* skip */ ;
591  /* Find end of value */
592  for (a = 0; token2[a] && token2[a] != '&'; a++)
593  /* skip */ ;
594  if (token2[a]) /* found "&" => another option follows */
595  {
596  token2[a] = '\0';
597  str = token2 + a + 1;
598  }
599  else
600  str = token2 + a;
601 
602  conn_keywords[i] = token1;
603  conn_values[i] = token2;
604  i++;
605  }
606  else
607  {
608  /* Bogus options syntax ... ignore trailing garbage */
609  str = token1 + e;
610  }
611  }
612  }
613 
614  Assert(i <= connect_params);
615  conn_keywords[i] = NULL; /* terminator */
616 
617  this->connection = PQconnectdbParams(conn_keywords, conn_values, 0);
618 
619  if (host)
620  ecpg_free(host);
621  if (port)
622  ecpg_free(port);
623  if (options)
625  if (dbname)
626  ecpg_free(dbname);
627  ecpg_free(conn_values);
628  ecpg_free(conn_keywords);
629 
630  if (PQstatus(this->connection) == CONNECTION_BAD)
631  {
632  const char *errmsg = PQerrorMessage(this->connection);
633  const char *db = realname ? realname : ecpg_gettext("<DEFAULT>");
634 
635  /* PQerrorMessage's result already has a trailing newline */
636  ecpg_log("ECPGconnect: %s", errmsg);
637 
638  ecpg_finish(this);
639 #ifdef ENABLE_THREAD_SAFETY
640  pthread_mutex_unlock(&connections_mutex);
641 #endif
642 
644  if (realname)
645  ecpg_free(realname);
646 
647  return false;
648  }
649 
650  if (realname)
651  ecpg_free(realname);
652 
653 #ifdef ENABLE_THREAD_SAFETY
654  pthread_mutex_unlock(&connections_mutex);
655 #endif
656 
657  this->autocommit = autocommit;
658 
659  PQsetNoticeReceiver(this->connection, &ECPGnoticeReceiver, (void *) this);
660 
661  return true;
662 }
static int32 next
Definition: blutils.c:219
static void ecpg_finish(struct connection *act)
Definition: connect.c:113
static struct connection * all_connections
Definition: connect.c:19
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
static void ECPGnoticeReceiver(void *arg, const PGresult *result)
Definition: connect.c:219
static struct connection * actual_connection
Definition: connect.c:18
bool autocommit
Definition: ecpg.c:15
enum COMPAT_MODE compat
Definition: ecpg.c:25
#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:158
#define INFORMIX_MODE(X)
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
bool ecpg_internal_regression_mode
Definition: misc.c:29
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
int errmsg(const char *fmt,...)
Definition: elog.c:904
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
Definition: fe-connect.c:658
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6908
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6855
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
Definition: fe-connect.c:7059
#define free(a)
Definition: header.h:65
int a
Definition: isn.c:69
int i
Definition: isn.c:73
@ CONNECTION_BAD
Definition: libpq-fe.h:61
Assert(fmt[strlen(fmt) - 1] !='\n')
static char * user
Definition: pg_regress.c:95
static int port
Definition: pg_regress.c:92
char * last_dir_separator(const char *filename)
Definition: path.c:139
char * c
e
Definition: preproc-init.c:82
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
char * dbname
Definition: streamutil.c:51
struct ECPGtype_information_cache * cache_head
struct prepared_statement * prep_stmts

References a, actual_connection, all_connections, Assert(), autocommit, connection::cache_head, compat, CONNECTION_BAD, dbname, ecpg_alloc(), ecpg_clear_auto_mem(), ECPG_CONNECT, ecpg_finish(), ecpg_free(), ecpg_get_connection(), ecpg_gettext, ecpg_init_sqlca(), ecpg_internal_regression_mode, ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, ecpg_strdup(), ECPGget_sqlca(), ECPGnoticeReceiver(), errmsg(), free, i, INFORMIX_MODE, last_dir_separator(), name, 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().

◆ 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 *, const char *, const int)
Definition: misc.c:104
#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(), 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 750 of file descriptor.c.

751 {
752  struct descriptor *desc;
753  struct descriptor *prev;
754  struct sqlca_t *sqlca = ECPGget_sqlca();
755 
756  if (sqlca == NULL)
757  {
760  return false;
761  }
762 
764  for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
765  {
766  if (strcmp(name, desc->name) == 0)
767  {
768  if (prev)
769  prev->next = desc->next;
770  else
771  set_descriptors(desc->next);
772  descriptor_free(desc);
773  return true;
774  }
775  }
777  return false;
778 }
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:730
#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 241 of file misc.c.

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

References 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 852 of file descriptor.c.

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

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, name, PQclear(), PQdescribePrepared(), res, descriptor::result, generate_unaccent_rules::type, va_end(), and va_start().

Referenced by execute_test(), and main().

◆ ECPGdisconnect()

bool ECPGdisconnect ( int  lineno,
const char *  connection_name 
)

Definition at line 665 of file connect.c.

666 {
667  struct sqlca_t *sqlca = ECPGget_sqlca();
668  struct connection *con;
669 
670  if (sqlca == NULL)
671  {
674  return false;
675  }
676 
677 #ifdef ENABLE_THREAD_SAFETY
678  pthread_mutex_lock(&connections_mutex);
679 #endif
680 
681  if (strcmp(connection_name, "ALL") == 0)
682  {
684  for (con = all_connections; con;)
685  {
686  struct connection *f = con;
687 
688  con = con->next;
689  ecpg_finish(f);
690  }
691  }
692  else
693  {
694  con = ecpg_get_connection_nr(connection_name);
695 
696  if (!ecpg_init(con, connection_name, lineno))
697  {
698 #ifdef ENABLE_THREAD_SAFETY
699  pthread_mutex_unlock(&connections_mutex);
700 #endif
701  return false;
702  }
703  else
704  ecpg_finish(con);
705  }
706 
707 #ifdef ENABLE_THREAD_SAFETY
708  pthread_mutex_unlock(&connections_mutex);
709 #endif
710 
711  return true;
712 }
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
struct connection * next

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

◆ 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 2286 of file execute.c.

2287 {
2288  va_list args;
2289  bool ret;
2290 
2291  va_start(args, query);
2292  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2293  questionmarks, st, query, args);
2294  va_end(args);
2295 
2296  return ret;
2297 }
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:2252

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(), get_record1(), main(), open_cur1(), openit(), and test().

◆ ECPGdo_descriptor()

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

Definition at line 2301 of file execute.c.

2303 {
2304  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2305  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2306  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2307 }
@ 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:2286

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 138 of file memory.c.

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 }
#define set_auto_allocs(am)
Definition: memory.c:104
#define get_auto_allocs()
Definition: memory.c:103
void ecpg_free(void *ptr)
Definition: memory.c:13
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 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 241 of file descriptor.c.

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

References generate_unaccent_rules::args, variable::arrsize, statement::connection, ecpg_auto_alloc(), ecpg_dynamic_type(), ecpg_dynamic_type_DDT(), ecpg_free(), ecpg_get_connection(), ecpg_init_sqlca(), ECPG_INVALID_DESCRIPTOR_INDEX, ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_result_by_descriptor(), ECPG_SQLSTATE_CARDINALITY_VIOLATION, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX, ecpg_store_result(), ecpg_strdup(), ECPG_TOO_MANY_MATCHES, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_EODT, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGget_sqlca(), ECPGt_EORT, ECPGt_NO_INDICATOR, get_char_item(), get_int_item(), variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, statement::lineno, locale_t, variable::offset, statement::oldlocale, variable::pointer, PQfmod(), PQfname(), PQfsize(), PQftype(), PQgetisnull(), PQgetlength(), PQnfields(), PQntuples(), RETURN_IF_NO_DATA, setlocale, snprintf, sqlca, generate_unaccent_rules::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 91 of file descriptor.c.

92 {
93  PGresult *ECPGresult;
94  struct sqlca_t *sqlca = ECPGget_sqlca();
95 
96  if (sqlca == NULL)
97  {
100  return false;
101  }
102 
104  ECPGresult = ecpg_result_by_descriptor(lineno, desc_name);
105  if (!ECPGresult)
106  return false;
107 
108  *count = PQnfields(ECPGresult);
109  sqlca->sqlerrd[2] = 1;
110  ecpg_log("ECPGget_desc_header: found %d attributes\n", *count);
111  return true;
112 }

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 715 of file connect.c.

716 {
717  struct connection *con;
718 
719  con = ecpg_get_connection(connection_name);
720  if (con == NULL)
721  return NULL;
722 
723  return con->connection;
724 }

References connection::connection, and ecpg_get_connection().

◆ ECPGget_var()

void* ECPGget_var ( int  number)

Definition at line 587 of file misc.c.

588 {
589  struct var_list *ptr;
590 
591  for (ptr = ivlist; ptr != NULL && ptr->number != number; ptr = ptr->next);
592  return (ptr) ? ptr->pointer : NULL;
593 }
struct var_list * ivlist
Definition: misc.c:529
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,
const void *  ptr 
)

Definition at line 387 of file misc.c.

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

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

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

References descriptor::count, and ecpg_find_desc().

Referenced by main().

◆ ECPGset_noind_null()

void ECPGset_noind_null ( enum  ECPGttype,
void *  ptr 
)

Definition at line 318 of file misc.c.

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

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 generate_unaccent_rules::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 532 of file misc.c.

533 {
534  struct var_list *ptr;
535 
536  struct sqlca_t *sqlca = ECPGget_sqlca();
537 
538  if (sqlca == NULL)
539  {
542  return;
543  }
544 
546 
547  for (ptr = ivlist; ptr != NULL; ptr = ptr->next)
548  {
549  if (ptr->number == number)
550  {
551  /* already known => just change pointer value */
552  ptr->pointer = pointer;
553  return;
554  }
555  }
556 
557  /* a new one has to be added */
558  ptr = (struct var_list *) calloc(1L, sizeof(struct var_list));
559  if (!ptr)
560  {
561  struct sqlca_t *sqlca = ECPGget_sqlca();
562 
563  if (sqlca == NULL)
564  {
567  return;
568  }
569 
571  strncpy(sqlca->sqlstate, "YE001", sizeof(sqlca->sqlstate));
572  snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);
574  /* free all memory we have allocated for the user */
576  }
577  else
578  {
579  ptr->number = number;
580  ptr->pointer = pointer;
581  ptr->next = ivlist;
582  ivlist = ptr;
583  }
584 }
#define calloc(a, b)
Definition: header.h:55
static struct sqlca_t sqlca
Definition: misc.c:62
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
void ECPGfree_auto_mem(void)
Definition: memory.c:138
struct sqlca_t::@154 sqlerrm
char sqlstate[5]
Definition: sqlca.h:53
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
long sqlcode
Definition: sqlca.h:23
int sqlerrml
Definition: sqlca.h:26

References calloc, ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGfree_auto_mem(), ECPGget_sqlca(), ivlist, var_list::next, var_list::number, var_list::pointer, snprintf, sqlca, 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().

◆ ECPGsetcommit()

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

Definition at line 165 of file connect.c.

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 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6863
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2273
@ PQTRANS_IDLE
Definition: libpq-fe.h:118
static PgChecksumMode mode
Definition: pg_checksums.c:65

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 main().

◆ ECPGsetconn()

bool ECPGsetconn ( int  lineno,
const char *  connection_name 
)

Definition at line 202 of file connect.c.

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 }

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

Referenced by main().

◆ ECPGstatus()

bool ECPGstatus ( int  lineno,
const char *  connection_name 
)

Definition at line 164 of file misc.c.

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

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 197 of file misc.c.

198 {
199  PGresult *res;
200  struct connection *con = ecpg_get_connection(connection_name);
201 
202  if (!ecpg_init(con, connection_name, lineno))
203  return false;
204 
205  ecpg_log("ECPGtrans on line %d: action \"%s\"; connection \"%s\"\n", lineno, transaction, con ? con->name : "null");
206 
207  /* if we have no connection we just simulate the command */
208  if (con && con->connection)
209  {
210  /*
211  * If we got a transaction command but have no open transaction, we
212  * have to start one, unless we are in autocommit, where the
213  * developers have to take care themselves. However, if the command is
214  * a begin statement, we just execute it once. And if the command is
215  * commit or rollback prepared, we don't execute it.
216  */
218  !con->autocommit &&
219  strncmp(transaction, "begin", 5) != 0 &&
220  strncmp(transaction, "start", 5) != 0 &&
221  strncmp(transaction, "commit prepared", 15) != 0 &&
222  strncmp(transaction, "rollback prepared", 17) != 0)
223  {
224  res = PQexec(con->connection, "begin transaction");
226  return false;
227  PQclear(res);
228  }
229 
230  res = PQexec(con->connection, transaction);
232  return false;
233  PQclear(res);
234  }
235 
236  return true;
237 }

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

◆ ECPGtransactionStatus()

PGTransactionStatusType ECPGtransactionStatus ( const char *  connection_name)

Definition at line 182 of file misc.c.

183 {
184  const struct connection *con;
185 
186  con = ecpg_get_connection(connection_name);
187  if (con == NULL)
188  {
189  /* transaction status is unknown */
190  return PQTRANS_UNKNOWN;
191  }
192 
193  return PQtransactionStatus(con->connection);
194 }
@ PQTRANS_UNKNOWN
Definition: libpq-fe.h:122

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

◆ sqlprint()

void sqlprint ( void  )

Definition at line 335 of file error.c.

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

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

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