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

Go to the source code of this file.

Macros

#define SQLCODE   sqlca.sqlcode
 
#define SQLSTATE   sqlca.sqlstate
 

Functions

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

Macro Definition Documentation

◆ SQLCODE

#define SQLCODE   sqlca.sqlcode

Definition at line 48 of file ecpglib.h.

◆ SQLSTATE

#define SQLSTATE   sqlca.sqlstate

Definition at line 49 of file ecpglib.h.

Function Documentation

◆ ecpg_pthreads_init()

void ecpg_pthreads_init ( void  )

Definition at line 30 of file connect.c.

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

References actual_connection_key_once, and ecpg_actual_connection_init().

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

◆ ECPGallocate_desc()

bool ECPGallocate_desc ( int  line,
const char *  name 
)

Definition at line 800 of file descriptor.c.

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

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

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

◆ ECPGconnect()

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

Definition at line 260 of file connect.c.

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

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

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

◆ ECPGdeallocate()

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

Definition at line 347 of file prepare.c.

348{
349 struct connection *con;
350 struct prepared_statement *this,
351 *prev;
352
353 con = ecpg_get_connection(connection_name);
354 if (!ecpg_init(con, connection_name, lineno))
355 return false;
356
357 this = ecpg_find_prepared_statement(name, con, &prev);
358 if (this)
359 return deallocate_one(lineno, c, con, prev, this);
360
361 /* prepared statement is not found */
362 if (INFORMIX_MODE(c))
363 return true;
365 return false;
366}
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:73
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:292
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:271

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

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

◆ ECPGdeallocate_all()

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

Definition at line 382 of file prepare.c.

383{
384 return ecpg_deallocate_all_conn(lineno, compat,
385 ecpg_get_connection(connection_name));
386}
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
Definition: prepare.c:369

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

757{
758 struct descriptor *desc;
759 struct descriptor *prev;
760 struct sqlca_t *sqlca = ECPGget_sqlca();
761
762 if (sqlca == NULL)
763 {
766 return false;
767 }
768
770 for (desc = get_descriptors(), prev = NULL; desc; prev = desc, desc = desc->next)
771 {
772 if (strcmp(name, desc->name) == 0)
773 {
774 if (prev)
775 prev->next = desc->next;
776 else
777 set_descriptors(desc->next);
778 descriptor_free(desc);
779 return true;
780 }
781 }
783 return false;
784}
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static void descriptor_free(struct descriptor *desc)
Definition: descriptor.c:736
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
struct descriptor * next

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

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

◆ ECPGdebug()

void ECPGdebug ( int  n,
FILE *  dbgs 
)

Definition at line 204 of file misc.c.

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

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

◆ ECPGdescribe()

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

Definition at line 855 of file descriptor.c.

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

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

Referenced by execute_test(), and main().

◆ ECPGdisconnect()

bool ECPGdisconnect ( int  lineno,
const char *  connection_name 
)

Definition at line 693 of file connect.c.

694{
695 struct sqlca_t *sqlca = ECPGget_sqlca();
696 struct connection *con;
697
698 if (sqlca == NULL)
699 {
702 return false;
703 }
704
706
707 if (strcmp(connection_name, "ALL") == 0)
708 {
710 for (con = all_connections; con;)
711 {
712 struct connection *f = con;
713
714 con = con->next;
715 ecpg_finish(f);
716 }
717 }
718 else
719 {
720 con = ecpg_get_connection_nr(connection_name);
721
722 if (!ecpg_init(con, connection_name, lineno))
723 {
725 return false;
726 }
727 else
728 ecpg_finish(con);
729 }
730
732
733 return true;
734}
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
struct connection * next

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

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

◆ ECPGdo()

bool ECPGdo ( const int  lineno,
const int  compat,
const int  force_indicator,
const char *  connection_name,
const bool  questionmarks,
const int  st,
const char *  query,
  ... 
)

Definition at line 2293 of file execute.c.

2294{
2295 va_list args;
2296 bool ret;
2297
2298 va_start(args, query);
2299 ret = ecpg_do(lineno, compat, force_indicator, connection_name,
2300 questionmarks, st, query, args);
2301 va_end(args);
2302
2303 return ret;
2304}
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:2259

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

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

◆ ECPGdo_descriptor()

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

Definition at line 2308 of file execute.c.

2310{
2311 return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, query, ECPGt_EOIT,
2312 ECPGt_descriptor, descriptor, 0L, 0L, 0L,
2313 ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
2314}
@ 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:2293

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

141{
142 struct auto_mem *am = get_auto_allocs();
143
144 /* free all memory we have allocated for the user */
145 if (am)
146 {
147 do
148 {
149 struct auto_mem *act = am;
150
151 am = am->next;
152 ecpg_free(act->pointer);
153 ecpg_free(act);
154 } while (am);
155 set_auto_allocs(NULL);
156 }
157}
static struct auto_mem * get_auto_allocs(void)
Definition: memory.c:97
void ecpg_free(void *ptr)
Definition: memory.c:13
static void set_auto_allocs(struct auto_mem *am)
Definition: memory.c:104
void * pointer
Definition: memory.c:76
struct auto_mem * next
Definition: memory.c:77

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

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

◆ ECPGget_desc()

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

Definition at line 234 of file descriptor.c.

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

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

Referenced by execute_test(), and main().

◆ ECPGget_desc_header()

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

Definition at line 84 of file descriptor.c.

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

References ecpg_init_sqlca(), ecpg_log(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_result_by_descriptor(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGget_sqlca(), PQnfields, and sqlca.

Referenced by execute_test(), and main().

◆ ECPGget_PGconn()

PGconn * ECPGget_PGconn ( const char *  connection_name)

Definition at line 737 of file connect.c.

738{
739 struct connection *con;
740
741 con = ecpg_get_connection(connection_name);
742 if (con == NULL)
743 return NULL;
744
745 return con->connection;
746}

References connection::connection, and ecpg_get_connection().

◆ ECPGget_var()

void * ECPGget_var ( int  number)

Definition at line 593 of file misc.c.

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

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

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

◆ ECPGis_noind_null()

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

Definition at line 361 of file misc.c.

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

References _check(), ECPGgeneric_bytea::arr, ECPGt_bytea, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGt_varchar, len, LONG_LONG_MIN, NUMERIC_NULL, sign, and type.

Referenced by ecpg_store_input(), and risnull().

◆ ECPGprepare()

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

Definition at line 249 of file prepare.c.

251{
252 struct connection *con;
253 struct prepared_statement *this,
254 *prev;
255
256 (void) questionmarks; /* quiet the compiler */
257
258 con = ecpg_get_connection(connection_name);
259 if (!ecpg_init(con, connection_name, lineno))
260 return false;
261
262 /* check if we already have prepared this statement */
263 this = ecpg_find_prepared_statement(name, con, &prev);
264 if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
265 return false;
266
267 return prepare_common(lineno, con, name, variable);
268}
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:172

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

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

◆ ECPGprepared_statement()

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

Definition at line 400 of file prepare.c.

401{
402 (void) lineno; /* keep the compiler quiet */
403
404 return ecpg_prepared(name, ecpg_get_connection(connection_name));
405}
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:389

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

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

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

References descriptor::count, and ecpg_find_desc().

Referenced by main().

◆ ECPGset_noind_null()

void ECPGset_noind_null ( enum ECPGttype  type,
void *  ptr 
)

Definition at line 292 of file misc.c.

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

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

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

◆ ECPGset_var()

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

Definition at line 538 of file misc.c.

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

References calloc, ecpg_init_sqlca(), ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGfree_auto_mem(), ECPGget_sqlca(), ivlist, var_list::next, var_list::number, var_list::pointer, snprintf, and sqlca.

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

◆ ECPGsetcommit()

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

Definition at line 158 of file connect.c.

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

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

Referenced by fn(), and main().

◆ ECPGsetconn()

bool ECPGsetconn ( int  lineno,
const char *  connection_name 
)

Definition at line 195 of file connect.c.

196{
197 struct connection *con = ecpg_get_connection(connection_name);
198
199 if (!ecpg_init(con, connection_name, lineno))
200 return false;
201
203 return true;
204}

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

Referenced by main().

◆ ECPGstatus()

bool ECPGstatus ( int  lineno,
const char *  connection_name 
)

Definition at line 127 of file misc.c.

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

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

◆ ECPGtrans()

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

Definition at line 160 of file misc.c.

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

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

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

◆ ECPGtransactionStatus()

PGTransactionStatusType ECPGtransactionStatus ( const char *  connection_name)

Definition at line 145 of file misc.c.

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

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(file, fmt, msg)
Definition: cubescan.l:21

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

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