PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ecpglib.h File Reference
#include "libpq-fe.h"
#include "ecpgtype.h"
#include "sqlca.h"
#include <string.h>
Include dependency graph for ecpglib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ecpg_gettext(x)   (x)
 
#define bool   char
 
#define true   ((bool) 1)
 
#define false   ((bool) 0)
 
#define TRUE   1
 
#define FALSE   0
 
#define SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

Functions

void ECPGdebug (int, FILE *)
 
bool ECPGstatus (int, const char *)
 
bool ECPGsetcommit (int, const char *, const char *)
 
bool ECPGsetconn (int, const char *)
 
bool ECPGconnect (int, int, const char *, const char *, const char *, const char *, int)
 
bool ECPGdo (const int, const int, const int, const char *, const bool, const int, const char *,...)
 
bool ECPGtrans (int, const char *, const char *)
 
bool ECPGdisconnect (int, const char *)
 
bool ECPGprepare (int, const char *, const bool, const char *, const char *)
 
bool ECPGdeallocate (int, int, const char *, const char *)
 
bool ECPGdeallocate_all (int, int, const char *)
 
char * ECPGprepared_statement (const char *, const char *, int)
 
PGconnECPGget_PGconn (const char *)
 
PGTransactionStatusType ECPGtransactionStatus (const char *)
 
char * ECPGerrmsg (void)
 
void sqlprint (void)
 
bool ECPGdo_descriptor (int, const char *, const char *, const char *)
 
bool ECPGdeallocate_desc (int, const char *)
 
bool ECPGallocate_desc (int, const char *)
 
bool ECPGget_desc_header (int, const char *, int *)
 
bool ECPGget_desc (int, const char *, int,...)
 
bool ECPGset_desc_header (int, const char *, int)
 
bool ECPGset_desc (int, const char *, int,...)
 
void ECPGset_noind_null (enum ECPGttype, void *)
 
bool ECPGis_noind_null (enum ECPGttype, 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

#define bool   char

Definition at line 23 of file ecpglib.h.

#define ecpg_gettext (   x)    (x)
#define false   ((bool) 0)

Definition at line 30 of file ecpglib.h.

#define FALSE   0

Definition at line 39 of file ecpglib.h.

#define SQLCODE   sqlca.sqlcode

Definition at line 69 of file ecpglib.h.

Referenced by sql_check().

#define SQLSTATE   sqlca.sqlstate

Definition at line 70 of file ecpglib.h.

#define true   ((bool) 1)

Definition at line 27 of file ecpglib.h.

#define TRUE   1

Definition at line 35 of file ecpglib.h.

Function Documentation

bool ECPGallocate_desc ( int  ,
const char *   
)

Definition at line 759 of file descriptor.c.

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

Referenced by fn(), and main().

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

Definition at line 271 of file connect.c.

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

Referenced by main(), and test().

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

Definition at line 253 of file prepare.c.

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

Referenced by main().

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

Definition at line 289 of file prepare.c.

References ecpg_deallocate_all_conn(), and ecpg_get_connection().

Referenced by main().

290 {
291  return ecpg_deallocate_all_conn(lineno, compat, ecpg_get_connection(connection_name));
292 }
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
Definition: prepare.c:276
enum COMPAT_MODE compat
Definition: ecpg.c:25
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool ECPGdeallocate_desc ( int  ,
const char *   
)

Definition at line 712 of file descriptor.c.

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

Referenced by fn(), and main().

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

Definition at line 243 of file misc.c.

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

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

Definition at line 814 of file descriptor.c.

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

Referenced by main().

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

Definition at line 669 of file connect.c.

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

Referenced by main(), and test().

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

Definition at line 2030 of file execute.c.

References generate_unaccent_rules::args, and ecpg_do().

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

2031 {
2032  va_list args;
2033  bool ret;
2034 
2035  va_start(args, query);
2036  ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2037  questionmarks, st, query, args);
2038  va_end(args);
2039 
2040  return ret;
2041 }
bool questionmarks
Definition: ecpg.c:19
enum COMPAT_MODE compat
Definition: ecpg.c:25
bool force_indicator
Definition: ecpg.c:18
bool ecpg_do(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query, va_list args)
Definition: execute.c:1996
bool ECPGdo_descriptor ( int  ,
const char *  ,
const char *  ,
const char *   
)

Definition at line 2045 of file execute.c.

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

2047 {
2048  return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2049  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2050  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2051 }
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:2030
#define NULL
Definition: c.h:229
char* ECPGerrmsg ( void  )
void ECPGfree_auto_mem ( void  )

Definition at line 138 of file memory.c.

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

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

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

Definition at line 245 of file descriptor.c.

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

Referenced by main().

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

Definition at line 91 of file descriptor.c.

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

Referenced by main().

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

Definition at line 719 of file connect.c.

References connection::connection, ecpg_get_connection(), and NULL.

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

Definition at line 568 of file misc.c.

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

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

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

Definition at line 388 of file misc.c.

References _check(), ECPGgeneric_varchar::arr, 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, NUMERIC_NULL, and sign.

Referenced by ecpg_store_input(), and risnull().

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

Definition at line 161 of file prepare.c.

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

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

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

Definition at line 306 of file prepare.c.

References ecpg_get_connection(), and ecpg_prepared().

Referenced by main(), and test().

307 {
308  (void) lineno; /* keep the compiler quiet */
309  return ecpg_prepared(name, ecpg_get_connection(connection_name));
310 }
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:295
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool ECPGset_desc ( int  ,
const char *  ,
int  ,
  ... 
)

Definition at line 567 of file descriptor.c.

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

Referenced by main().

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

Definition at line 556 of file descriptor.c.

References descriptor::count, ecpg_find_desc(), and NULL.

Referenced by main().

557 {
558  struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
559 
560  if (desc == NULL)
561  return false;
562  desc->count = count;
563  return true;
564 }
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:799
int count
Definition: extern.h:95
#define NULL
Definition: c.h:229
void ECPGset_noind_null ( enum  ECPGttype,
void *   
)

Definition at line 320 of file misc.c.

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

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

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

Definition at line 524 of file misc.c.

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

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

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

Definition at line 165 of file connect.c.

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

Referenced by main().

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

Definition at line 202 of file connect.c.

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

Referenced by main().

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

Definition at line 165 of file misc.c.

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

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

Definition at line 199 of file misc.c.

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

Referenced by main(), and sql_check().

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

Definition at line 183 of file misc.c.

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

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

Definition at line 336 of file error.c.

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

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

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