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 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)
 

Macro Definition Documentation

◆ false

#define false   ((bool) 0)

Definition at line 40 of file ecpglib.h.

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 76 of file ecpglib.h.

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 77 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 802 of file descriptor.c.

803 {
804  struct descriptor *new;
805  struct sqlca_t *sqlca = ECPGget_sqlca();
806 
807  if (sqlca == NULL)
808  {
811  return false;
812  }
813 
815  new = (struct descriptor *) ecpg_alloc(sizeof(struct descriptor), line);
816  if (!new)
817  return false;
818  new->next = get_descriptors();
819  new->name = ecpg_alloc(strlen(name) + 1, line);
820  if (!new->name)
821  {
822  ecpg_free(new);
823  return false;
824  }
825  new->count = -1;
826  new->items = NULL;
827  new->result = PQmakeEmptyPGresult(NULL, 0);
828  if (!new->result)
829  {
830  ecpg_free(new->name);
831  ecpg_free(new);
833  return false;
834  }
835  strcpy(new->name, name);
836  set_descriptors(new);
837  return true;
838 }
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
#define set_descriptors(value)
Definition: descriptor.c:56
#define get_descriptors()
Definition: descriptor.c:55
#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:98
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
const char * name
Definition: encode.c:571
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 277 of file connect.c.

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

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(), locale_t, 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 *con, const char *connection_name, const int lineno)
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 755 of file descriptor.c.

756 {
757  struct descriptor *desc;
758  struct descriptor *prev;
759  struct sqlca_t *sqlca = ECPGget_sqlca();
760 
761  if (sqlca == NULL)
762  {
765  return false;
766  }
767 
769  for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
770  {
771  if (strcmp(name, desc->name) == 0)
772  {
773  if (prev)
774  prev->next = desc->next;
775  else
776  set_descriptors(desc->next);
777  descriptor_free(desc);
778  return true;
779  }
780  }
782  return false;
783 }
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:735
#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 857 of file descriptor.c.

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

708 {
709  struct sqlca_t *sqlca = ECPGget_sqlca();
710  struct connection *con;
711 
712  if (sqlca == NULL)
713  {
716  return false;
717  }
718 
719 #ifdef ENABLE_THREAD_SAFETY
720  pthread_mutex_lock(&connections_mutex);
721 #endif
722 
723  if (strcmp(connection_name, "ALL") == 0)
724  {
726  for (con = all_connections; con;)
727  {
728  struct connection *f = con;
729 
730  con = con->next;
731  ecpg_finish(f);
732  }
733  }
734  else
735  {
736  con = ecpg_get_connection_nr(connection_name);
737 
738  if (!ecpg_init(con, connection_name, lineno))
739  {
740 #ifdef ENABLE_THREAD_SAFETY
741  pthread_mutex_unlock(&connections_mutex);
742 #endif
743  return false;
744  }
745  else
746  ecpg_finish(con);
747  }
748 
749 #ifdef ENABLE_THREAD_SAFETY
750  pthread_mutex_unlock(&connections_mutex);
751 #endif
752 
753  return true;
754 }
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:40
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 2279 of file execute.c.

2280 {
2281  va_list args;
2282  bool ret;
2283 
2284  va_start(args, query);
2285  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2286  questionmarks, st, query, args);
2287  va_end(args);
2288 
2289  return ret;
2290 }
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:2245

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

2296 {
2297  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2298  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2299  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2300 }
@ 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:2279

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 
490  /*
491  * To get here, the above PQnfields() test must have found nonzero
492  * fields. One needs a connection to create such a descriptor. (EXEC
493  * SQL SET DESCRIPTOR can populate the descriptor's "items", but it
494  * can't change the descriptor's PQnfields().) Any successful
495  * connection initializes ecpg_clocale.
496  */
497  Assert(ecpg_clocale);
498  stmt.oldlocale = uselocale(ecpg_clocale);
499 #else
500 #ifdef HAVE__CONFIGTHREADLOCALE
501  stmt.oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
502 #endif
503  stmt.oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
504  setlocale(LC_NUMERIC, "C");
505 #endif
506 
507  /* desperate try to guess something sensible */
508  stmt.connection = ecpg_get_connection(NULL);
509  ecpg_store_result(ECPGresult, index, &stmt, &data_var);
510 
511 #ifdef HAVE_USELOCALE
512  if (stmt.oldlocale != (locale_t) 0)
513  uselocale(stmt.oldlocale);
514 #else
515  if (stmt.oldlocale)
516  {
517  setlocale(LC_NUMERIC, stmt.oldlocale);
518  ecpg_free(stmt.oldlocale);
519  }
520 #ifdef HAVE__CONFIGTHREADLOCALE
521  if (stmt.oldthreadlocale != -1)
522  (void) _configthreadlocale(stmt.oldthreadlocale);
523 #endif
524 #endif
525  }
526  else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
527 
528  /*
529  * ind_type != NO_INDICATOR should always have ind_pointer != NULL but
530  * since this might be changed manually in the .c file let's play it
531  * safe
532  */
533  {
534  /*
535  * this is like ECPGstore_result but since we don't have a data
536  * variable at hand, we can't call it
537  */
538  if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
539  {
540  ecpg_log("ECPGget_desc on line %d: incorrect number of matches (indicator); %d don't fit into array of %ld\n",
541  lineno, ntuples, data_var.ind_arrsize);
543  va_end(args);
544  return false;
545  }
546 
547  /* allocate storage if needed */
548  if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
549  {
550  void *mem = (void *) ecpg_auto_alloc(data_var.ind_offset * ntuples, lineno);
551 
552  if (!mem)
553  {
554  va_end(args);
555  return false;
556  }
557  *(void **) data_var.ind_pointer = mem;
558  data_var.ind_value = mem;
559  }
560 
561  for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
562  {
563  if (!get_int_item(lineno, data_var.ind_value, data_var.ind_type, -PQgetisnull(ECPGresult, act_tuple, index)))
564  {
565  va_end(args);
566  return false;
567  }
568  data_var.ind_value = (char *) data_var.ind_value + data_var.ind_offset;
569  ecpg_log("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
570  }
571  }
572  sqlca->sqlerrd[2] = ntuples;
573  va_end(args);
574  return true;
575 }
#define VARHDRSZ
Definition: c.h:676
#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:303
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:108
#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:3720
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3552
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3314
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:3400
int PQfmod(const PGresult *res, int field_num)
Definition: fe-exec.c:3574
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3734
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3322
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3563
#define stmt
Definition: indent_codes.h:59
#define snprintf
Definition: port.h:238
Definition: type.h:95
#define setlocale(a, b)
Definition: win32_port.h:471

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

758 {
759  struct connection *con;
760 
761  con = ecpg_get_connection(connection_name);
762  if (con == NULL)
763  return NULL;
764 
765  return con->connection;
766 }

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  type,
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 612 of file descriptor.c.

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

581 {
582  struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
583 
584  if (desc == NULL)
585  return false;
586  desc->count = count;
587  return true;
588 }

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 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  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::@148 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 171 of file connect.c.

172 {
173  struct connection *con = ecpg_get_connection(connection_name);
174  PGresult *results;
175 
176  if (!ecpg_init(con, connection_name, lineno))
177  return false;
178 
179  ecpg_log("ECPGsetcommit on line %d: action \"%s\"; connection \"%s\"\n", lineno, mode, con->name);
180 
181  if (con->autocommit && strncmp(mode, "off", strlen("off")) == 0)
182  {
184  {
185  results = PQexec(con->connection, "begin transaction");
186  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
187  return false;
188  PQclear(results);
189  }
190  con->autocommit = false;
191  }
192  else if (!con->autocommit && strncmp(mode, "on", strlen("on")) == 0)
193  {
195  {
196  results = PQexec(con->connection, "commit");
197  if (!ecpg_check_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
198  return false;
199  PQclear(results);
200  }
201  con->autocommit = true;
202  }
203 
204  return true;
205 }
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6975
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2229
@ 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 208 of file connect.c.

209 {
210  struct connection *con = ecpg_get_connection(connection_name);
211 
212  if (!ecpg_init(con, connection_name, lineno))
213  return false;
214 
215 #ifdef ENABLE_THREAD_SAFETY
216  pthread_setspecific(actual_connection_key, con);
217 #else
218  actual_connection = con;
219 #endif
220  return true;
221 }

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