PostgreSQL Source Code git master
ecpglib_extern.h File Reference
#include "ecpg_config.h"
#include "ecpgtype.h"
#include "libpq-fe.h"
#include "sqlca.h"
#include "sqlda-compat.h"
#include "sqlda-native.h"
#include <limits.h>
Include dependency graph for ecpglib_extern.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ECPGgeneric_varchar
 
struct  ECPGgeneric_bytea
 
struct  ECPGtype_information_cache
 
struct  statement
 
struct  prepared_statement
 
struct  connection
 
struct  descriptor
 
struct  descriptor_item
 
struct  variable
 
struct  var_list
 

Macros

#define INFORMIX_MODE(X)   ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
 
#define ORACLE_MODE(X)   ((X) == ECPG_COMPAT_ORACLE)
 
#define ECPG_IS_ARRAY(X)   ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
 
#define ecpg_gettext(x)   (x)
 
#define ECPG_SQLSTATE_NO_DATA   "02000"
 
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS   "07001"
 
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS   "07002"
 
#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION   "07006"
 
#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX   "07009"
 
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION   "08001"
 
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST   "08003"
 
#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN   "08007"
 
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION   "21000"
 
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER   "22002"
 
#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION   "25001"
 
#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION   "25P01"
 
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME   "26000"
 
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME   "33000"
 
#define ECPG_SQLSTATE_INVALID_CURSOR_NAME   "34000"
 
#define ECPG_SQLSTATE_SYNTAX_ERROR   "42601"
 
#define ECPG_SQLSTATE_DATATYPE_MISMATCH   "42804"
 
#define ECPG_SQLSTATE_DUPLICATE_CURSOR   "42P03"
 
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR   "YE000"
 
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY   "YE001"
 

Enumerations

enum  COMPAT_MODE {
  ECPG_COMPAT_PGSQL = 0 , ECPG_COMPAT_INFORMIX , ECPG_COMPAT_INFORMIX_SE , ECPG_COMPAT_ORACLE ,
  ECPG_COMPAT_PGSQL = 0 , ECPG_COMPAT_INFORMIX , ECPG_COMPAT_INFORMIX_SE , ECPG_COMPAT_ORACLE
}
 
enum  ARRAY_TYPE {
  ECPG_ARRAY_ERROR , ECPG_ARRAY_NOT_SET , ECPG_ARRAY_ARRAY , ECPG_ARRAY_VECTOR ,
  ECPG_ARRAY_NONE
}
 

Functions

bool ecpg_add_mem (void *ptr, int lineno)
 
bool ecpg_get_data (const PGresult *, int, int, int, enum ECPGttype type, enum ECPGttype, char *, char *, long, long, long, enum ARRAY_TYPE, enum COMPAT_MODE, bool)
 
void ecpg_pthreads_init (void)
 
struct connectionecpg_get_connection (const char *connection_name)
 
char * ecpg_alloc (long size, int lineno)
 
char * ecpg_auto_alloc (long size, int lineno)
 
char * ecpg_realloc (void *ptr, long size, int lineno)
 
void ecpg_free (void *ptr)
 
bool ecpg_init (const struct connection *con, const char *connection_name, const int lineno)
 
char * ecpg_strdup (const char *string, int lineno, bool *alloc_failed)
 
const char * ecpg_type_name (enum ECPGttype typ)
 
int ecpg_dynamic_type (Oid type)
 
int sqlda_dynamic_type (Oid type, enum COMPAT_MODE compat)
 
void ecpg_clear_auto_mem (void)
 
struct descriptorecpg_find_desc (int line, const char *name)
 
struct prepared_statementecpg_find_prepared_statement (const char *name, struct connection *con, struct prepared_statement **prev_)
 
bool ecpg_store_result (const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
 
bool ecpg_store_input (const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
 
void ecpg_free_params (struct statement *stmt, bool print)
 
bool ecpg_do_prologue (int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, enum ECPG_statement_type statement_type, const char *query, va_list args, struct statement **stmt_out)
 
bool ecpg_build_params (struct statement *stmt)
 
bool ecpg_autostart_transaction (struct statement *stmt)
 
bool ecpg_execute (struct statement *stmt)
 
bool ecpg_process_output (struct statement *stmt, bool clear_result)
 
void ecpg_do_epilogue (struct statement *stmt)
 
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)
 
bool ecpg_check_PQresult (PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
 
void ecpg_raise (int line, int code, const char *sqlstate, const char *str)
 
void ecpg_raise_backend (int line, PGresult *result, PGconn *conn, int compat)
 
char * ecpg_prepared (const char *name, struct connection *con)
 
bool ecpg_deallocate_all_conn (int lineno, enum COMPAT_MODE c, struct connection *con)
 
void ecpg_log (const char *format,...) pg_attribute_printf(1
 
void bool ecpg_auto_prepare (int lineno, const char *connection_name, const int compat, char **name, const char *query)
 
bool ecpg_register_prepared_stmt (struct statement *stmt)
 
void ecpg_init_sqlca (struct sqlca_t *sqlca)
 
struct sqlda_compatecpg_build_compat_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
 
void ecpg_set_compat_sqlda (int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
 
struct sqlda_structecpg_build_native_sqlda (int line, PGresult *res, int row, enum COMPAT_MODE compat)
 
void ecpg_set_native_sqlda (int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
 
unsigned ecpg_hex_dec_len (unsigned srclen)
 
unsigned ecpg_hex_enc_len (unsigned srclen)
 
unsigned ecpg_hex_encode (const char *src, unsigned len, char *dst)
 

Variables

bool ecpg_internal_regression_mode
 
struct var_listivlist
 

Macro Definition Documentation

◆ ecpg_gettext

#define ecpg_gettext (   x)    (x)

Definition at line 239 of file ecpglib_extern.h.

◆ ECPG_IS_ARRAY

#define ECPG_IS_ARRAY (   X)    ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)

Definition at line 32 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION

#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION   "25001"

Definition at line 255 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_CARDINALITY_VIOLATION

#define ECPG_SQLSTATE_CARDINALITY_VIOLATION   "21000"

Definition at line 253 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST

#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST   "08003"

Definition at line 251 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_DATATYPE_MISMATCH

#define ECPG_SQLSTATE_DATATYPE_MISMATCH   "42804"

Definition at line 261 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_DUPLICATE_CURSOR

#define ECPG_SQLSTATE_DUPLICATE_CURSOR   "42P03"

Definition at line 262 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_ECPG_INTERNAL_ERROR

#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR   "YE000"

Definition at line 265 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY

#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY   "YE001"

Definition at line 266 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_INVALID_CURSOR_NAME

#define ECPG_SQLSTATE_INVALID_CURSOR_NAME   "34000"

Definition at line 259 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX

#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX   "07009"

Definition at line 249 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME

#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME   "33000"

Definition at line 258 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME

#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME   "26000"

Definition at line 257 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION

#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION   "25P01"

Definition at line 256 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_NO_DATA

#define ECPG_SQLSTATE_NO_DATA   "02000"

Definition at line 245 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER

#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER   "22002"

Definition at line 254 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION

#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION   "07006"

Definition at line 248 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION

#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION   "08001"

Definition at line 250 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_SYNTAX_ERROR

#define ECPG_SQLSTATE_SYNTAX_ERROR   "42601"

Definition at line 260 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN

#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN   "08007"

Definition at line 252 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS

#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS   "07001"

Definition at line 246 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS

#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS   "07002"

Definition at line 247 of file ecpglib_extern.h.

◆ INFORMIX_MODE

#define INFORMIX_MODE (   X)    ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)

Definition at line 24 of file ecpglib_extern.h.

◆ ORACLE_MODE

#define ORACLE_MODE (   X)    ((X) == ECPG_COMPAT_ORACLE)

Definition at line 25 of file ecpglib_extern.h.

Enumeration Type Documentation

◆ ARRAY_TYPE

enum ARRAY_TYPE
Enumerator
ECPG_ARRAY_ERROR 
ECPG_ARRAY_NOT_SET 
ECPG_ARRAY_ARRAY 
ECPG_ARRAY_VECTOR 
ECPG_ARRAY_NONE 

Definition at line 27 of file ecpglib_extern.h.

28{
30};
@ ECPG_ARRAY_NOT_SET
@ ECPG_ARRAY_ARRAY
@ ECPG_ARRAY_VECTOR
@ ECPG_ARRAY_NONE
@ ECPG_ARRAY_ERROR

◆ COMPAT_MODE

Enumerator
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_ORACLE 

Definition at line 17 of file ecpglib_extern.h.

18{
20};
@ ECPG_COMPAT_PGSQL
@ ECPG_COMPAT_ORACLE
@ ECPG_COMPAT_INFORMIX
@ ECPG_COMPAT_INFORMIX_SE

Function Documentation

◆ ecpg_add_mem()

bool ecpg_add_mem ( void *  ptr,
int  lineno 
)

Definition at line 126 of file memory.c.

127{
128 struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);
129
130 if (!am)
131 return false;
132
133 am->pointer = ptr;
134 am->next = get_auto_allocs();
135 set_auto_allocs(am);
136 return true;
137}
static struct auto_mem * get_auto_allocs(void)
Definition: memory.c:97
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
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_alloc(), get_auto_allocs(), auto_mem::next, auto_mem::pointer, and set_auto_allocs().

Referenced by ecpg_auto_alloc().

◆ ecpg_alloc()

char * ecpg_alloc ( long  size,
int  lineno 
)

◆ ecpg_auto_alloc()

char * ecpg_auto_alloc ( long  size,
int  lineno 
)

Definition at line 110 of file memory.c.

111{
112 void *ptr = ecpg_alloc(size, lineno);
113
114 if (!ptr)
115 return NULL;
116
117 if (!ecpg_add_mem(ptr, lineno))
118 {
119 ecpg_free(ptr);
120 return NULL;
121 }
122 return ptr;
123}
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:126
void ecpg_free(void *ptr)
Definition: memory.c:13

References ecpg_add_mem(), ecpg_alloc(), and ecpg_free().

Referenced by ecpg_store_result(), and ECPGget_desc().

◆ ecpg_auto_prepare()

void bool ecpg_auto_prepare ( int  lineno,
const char *  connection_name,
const int  compat,
char **  name,
const char *  query 
)

Definition at line 587 of file prepare.c.

588{
589 int entNo;
590
591 /* search the statement cache for this statement */
592 entNo = SearchStmtCache(query);
593
594 /* if not found - add the statement to the cache */
595 if (entNo)
596 {
597 char *stmtID;
598 struct connection *con;
599 struct prepared_statement *prep;
600
601 ecpg_log("ecpg_auto_prepare on line %d: statement found in cache; entry %d\n", lineno, entNo);
602
603 stmtID = stmtCacheEntries[entNo].stmtID;
604 *name = ecpg_strdup(stmtID, lineno, NULL);
605 if (*name == NULL)
606 return false;
607
608 con = ecpg_get_connection(connection_name);
609 prep = ecpg_find_prepared_statement(stmtID, con, NULL);
610 /* This prepared name doesn't exist on this connection. */
611 if (!prep && !prepare_common(lineno, con, stmtID, query))
612 {
613 ecpg_free(*name);
614 return false;
615 }
616
617 }
618 else
619 {
620 char stmtID[STMTID_SIZE];
621
622 ecpg_log("ecpg_auto_prepare on line %d: statement not in cache; inserting\n", lineno);
623
624 /* generate a statement ID */
625 sprintf(stmtID, "ecpg%d", nextStmtID++);
626 *name = ecpg_strdup(stmtID, lineno, NULL);
627 if (*name == NULL)
628 return false;
629
630 if (!ECPGprepare(lineno, connection_name, 0, stmtID, query))
631 {
632 ecpg_free(*name);
633 return false;
634 }
635
636 entNo = AddStmtToCache(lineno, stmtID, connection_name, compat, query);
637 if (entNo < 0)
638 {
639 ecpg_free(*name);
640 return false;
641 }
642 }
643
644 /* increase usage counter */
645 stmtCacheEntries[entNo].execs++;
646
647 return true;
648}
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:76
enum COMPAT_MODE compat
Definition: ecpg.c:26
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_free(void *ptr)
Definition: memory.c:13
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:172
static int nextStmtID
Definition: prepare.c:37
static int AddStmtToCache(int lineno, const char *stmtID, const char *connection, int compat, const char *ecpgQuery)
Definition: prepare.c:523
static int SearchStmtCache(const char *ecpgQuery)
Definition: prepare.c:447
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:249
#define STMTID_SIZE
Definition: prepare.c:14
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:271
static stmtCacheEntry * stmtCacheEntries
Definition: prepare.c:38
#define sprintf
Definition: port.h:262
Definition: type.h:109
char stmtID[STMTID_SIZE]
Definition: prepare.c:31
long execs
Definition: prepare.c:33
const char * name

References AddStmtToCache(), compat, ecpg_find_prepared_statement(), ecpg_free(), ecpg_get_connection(), ecpg_log(), ecpg_strdup(), ECPGprepare(), stmtCacheEntry::execs, name, nextStmtID, prepare_common(), SearchStmtCache(), sprintf, stmtCacheEntries, stmtCacheEntry::stmtID, and STMTID_SIZE.

Referenced by ecpg_do_prologue().

◆ ecpg_autostart_transaction()

bool ecpg_autostart_transaction ( struct statement stmt)

Definition at line 1579 of file execute.c.

1580{
1581 if (PQtransactionStatus(stmt->connection->connection) == PQTRANS_IDLE && !stmt->connection->autocommit)
1582 {
1583 stmt->results = PQexec(stmt->connection->connection, "begin transaction");
1584 if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1585 {
1586 ecpg_free_params(stmt, false);
1587 return false;
1588 }
1589 PQclear(stmt->results);
1590 stmt->results = NULL;
1591 }
1592 return true;
1593}
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:281
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1106
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:7649
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2279
#define stmt
Definition: indent_codes.h:59
#define PQclear
Definition: libpq-be-fe.h:245
@ PQTRANS_IDLE
Definition: libpq-fe.h:147

References ecpg_check_PQresult(), ecpg_free_params(), PQclear, PQexec(), PQTRANS_IDLE, PQtransactionStatus(), and stmt.

Referenced by ecpg_do().

◆ ecpg_build_compat_sqlda()

struct sqlda_compat * ecpg_build_compat_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 205 of file sqlda.c.

206{
207 struct sqlda_compat *sqlda;
208 struct sqlvar_compat *sqlvar;
209 char *fname;
210 long size;
211 int sqld;
212 int i;
213
214 size = sqlda_compat_total_size(res, row, compat);
215 sqlda = (struct sqlda_compat *) ecpg_alloc(size, line);
216 if (!sqlda)
217 return NULL;
218
219 memset(sqlda, 0, size);
220 sqlvar = (struct sqlvar_compat *) (sqlda + 1);
221 sqld = PQnfields(res);
222 fname = (char *) (sqlvar + sqld);
223
224 sqlda->sqld = sqld;
225 ecpg_log("ecpg_build_compat_sqlda on line %d sqld = %d\n", line, sqld);
226 sqlda->desc_occ = size; /* cheat here, keep the full allocated size */
227 sqlda->sqlvar = sqlvar;
228
229 for (i = 0; i < sqlda->sqld; i++)
230 {
232 strcpy(fname, PQfname(res, i));
233 sqlda->sqlvar[i].sqlname = fname;
234 fname += strlen(sqlda->sqlvar[i].sqlname) + 1;
235
236 /*
237 * this is reserved for future use, so we leave it empty for the time
238 * being
239 */
240 /* sqlda->sqlvar[i].sqlformat = (char *) (long) PQfformat(res, i); */
241 sqlda->sqlvar[i].sqlxid = PQftype(res, i);
242 sqlda->sqlvar[i].sqltypelen = PQfsize(res, i);
243 }
244
245 return sqlda;
246}
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
int sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
Definition: typename.c:107
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3736
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3747
int i
Definition: isn.c:77
#define PQnfields
Definition: libpq-be-fe.h:252
#define PQfname
Definition: libpq-be-fe.h:256
static long sqlda_compat_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:157
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40
short desc_occ
Definition: sqlda-compat.h:42
short sqltypelen
Definition: sqlda-compat.h:21
char * sqlname
Definition: sqlda-compat.h:14

References compat, sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, PQfname, PQfsize(), PQftype(), PQnfields, sqlda_compat::sqld, sqlda_compat_total_size(), sqlda_dynamic_type(), sqlvar_compat::sqlname, sqlvar_compat::sqltype, sqlvar_compat::sqltypelen, sqlda_compat::sqlvar, and sqlvar_compat::sqlxid.

Referenced by ecpg_process_output(), and ECPGdescribe().

◆ ecpg_build_native_sqlda()

struct sqlda_struct * ecpg_build_native_sqlda ( int  line,
PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 412 of file sqlda.c.

413{
414 struct sqlda_struct *sqlda;
415 long size;
416 int i;
417
418 size = sqlda_native_total_size(res, row, compat);
419 sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
420 if (!sqlda)
421 return NULL;
422
423 memset(sqlda, 0, size);
424
425 sprintf(sqlda->sqldaid, "SQLDA ");
426 sqlda->sqld = sqlda->sqln = PQnfields(res);
427 ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
428 sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
429
430 for (i = 0; i < sqlda->sqld; i++)
431 {
432 char *fname;
433
435 fname = PQfname(res, i);
436 sqlda->sqlvar[i].sqlname.length = strlen(fname);
437 strcpy(sqlda->sqlvar[i].sqlname.data, fname);
438 }
439
440 return sqlda;
441}
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:186
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
char sqldaid[8]
Definition: sqlda-native.h:35
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
short length
Definition: sqlda-native.h:20
struct sqlname sqlname
Definition: sqlda-native.h:30

References compat, sqlname::data, ecpg_alloc(), ecpg_log(), i, sqlname::length, PQfname, PQftype(), PQnfields, sprintf, sqlda_struct::sqld, sqlda_dynamic_type(), sqlda_native_total_size(), sqlda_struct::sqldabc, sqlda_struct::sqldaid, sqlda_struct::sqln, sqlvar_struct::sqlname, sqlvar_struct::sqltype, and sqlda_struct::sqlvar.

Referenced by ecpg_process_output(), and ECPGdescribe().

◆ ecpg_build_params()

bool ecpg_build_params ( struct statement stmt)

Definition at line 1211 of file execute.c.

1212{
1213 struct variable *var;
1214 int desc_counter = 0;
1215 int position = 0;
1216 const char *value;
1217 bool std_strings = false;
1218
1219 /* Get standard_conforming_strings setting. */
1220 value = PQparameterStatus(stmt->connection->connection, "standard_conforming_strings");
1221 if (value && strcmp(value, "on") == 0)
1222 std_strings = true;
1223
1224 /*
1225 * If the type is one of the fill in types then we take the argument and
1226 * enter it to our parameter array at the first position. Then if there
1227 * are any more fill in types we add more parameters.
1228 */
1229 var = stmt->inlist;
1230 while (var)
1231 {
1232 char *tobeinserted;
1233 int counter = 1;
1234 bool binary_format;
1235 int binary_length;
1236
1237
1238 tobeinserted = NULL;
1239 binary_length = 0;
1240 binary_format = false;
1241
1242 /*
1243 * A descriptor is a special case since it contains many variables but
1244 * is listed only once.
1245 */
1246 if (var->type == ECPGt_descriptor)
1247 {
1248 /*
1249 * We create an additional variable list here, so the same logic
1250 * applies.
1251 */
1252 struct descriptor *desc;
1253 struct descriptor_item *desc_item;
1254
1255 desc = ecpg_find_desc(stmt->lineno, var->pointer);
1256 if (desc == NULL)
1257 return false;
1258
1259 desc_counter++;
1260 for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
1261 {
1262 if (desc_item->num != desc_counter)
1263 continue;
1264
1265 if (!store_input_from_desc(stmt, desc_item, &tobeinserted))
1266 return false;
1267
1268 if (desc_item->is_binary)
1269 {
1270 binary_length = desc_item->data_len;
1271 binary_format = true;
1272 }
1273 break;
1274 }
1275 if (desc->count == desc_counter)
1276 desc_counter = 0;
1277 }
1278 else if (var->type == ECPGt_sqlda)
1279 {
1280 if (INFORMIX_MODE(stmt->compat))
1281 {
1282 struct sqlda_compat *sqlda = *(struct sqlda_compat **) var->pointer;
1283 struct variable desc_inlist;
1284 int i;
1285
1286 if (sqlda == NULL)
1287 return false;
1288
1289 desc_counter++;
1290 for (i = 0; i < sqlda->sqld; i++)
1291 {
1292 if (i + 1 == desc_counter)
1293 {
1294 desc_inlist.type = sqlda->sqlvar[i].sqltype;
1295 desc_inlist.value = sqlda->sqlvar[i].sqldata;
1296 desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1297 switch (desc_inlist.type)
1298 {
1299 case ECPGt_char:
1300 case ECPGt_varchar:
1301 desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1302 break;
1303 default:
1304 desc_inlist.varcharsize = 0;
1305 break;
1306 }
1307 desc_inlist.arrsize = 1;
1308 desc_inlist.offset = 0;
1309 if (sqlda->sqlvar[i].sqlind)
1310 {
1311 desc_inlist.ind_type = ECPGt_short;
1312 /* ECPG expects indicator value < 0 */
1313 if (*(sqlda->sqlvar[i].sqlind))
1314 *(sqlda->sqlvar[i].sqlind) = -1;
1315 desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1316 desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1317 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1318 desc_inlist.ind_offset = 0;
1319 }
1320 else
1321 {
1322 desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1323 desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1324 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1325 }
1326 if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1327 return false;
1328
1329 break;
1330 }
1331 }
1332 if (sqlda->sqld == desc_counter)
1333 desc_counter = 0;
1334 }
1335 else
1336 {
1337 struct sqlda_struct *sqlda = *(struct sqlda_struct **) var->pointer;
1338 struct variable desc_inlist;
1339 int i;
1340
1341 if (sqlda == NULL)
1342 return false;
1343
1344 desc_counter++;
1345 for (i = 0; i < sqlda->sqln; i++)
1346 {
1347 if (i + 1 == desc_counter)
1348 {
1349 desc_inlist.type = sqlda->sqlvar[i].sqltype;
1350 desc_inlist.value = sqlda->sqlvar[i].sqldata;
1351 desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1352 switch (desc_inlist.type)
1353 {
1354 case ECPGt_char:
1355 case ECPGt_varchar:
1356 desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1357 break;
1358 default:
1359 desc_inlist.varcharsize = 0;
1360 break;
1361 }
1362 desc_inlist.arrsize = 1;
1363 desc_inlist.offset = 0;
1364 if (sqlda->sqlvar[i].sqlind)
1365 {
1366 desc_inlist.ind_type = ECPGt_short;
1367 /* ECPG expects indicator value < 0 */
1368 if (*(sqlda->sqlvar[i].sqlind))
1369 *(sqlda->sqlvar[i].sqlind) = -1;
1370 desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1371 desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1372 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1373 desc_inlist.ind_offset = 0;
1374 }
1375 else
1376 {
1377 desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1378 desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1379 desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1380 }
1381 if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1382 return false;
1383
1384 break;
1385 }
1386 }
1387 if (sqlda->sqln == desc_counter)
1388 desc_counter = 0;
1389 }
1390 }
1391 else
1392 {
1393 if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
1394 return false;
1395
1396 if (var->type == ECPGt_bytea)
1397 {
1398 binary_length = ((struct ECPGgeneric_bytea *) (var->value))->len;
1399 binary_format = true;
1400 }
1401 }
1402
1403 /*
1404 * now tobeinserted points to an area that contains the next
1405 * parameter; now find the position in the string where it belongs
1406 */
1407 if ((position = next_insert(stmt->command, position, stmt->questionmarks, std_strings) + 1) == 0)
1408 {
1409 /*
1410 * We have an argument but we don't have the matched up
1411 * placeholder in the string
1412 */
1415 NULL);
1416 ecpg_free_params(stmt, false);
1417 ecpg_free(tobeinserted);
1418 return false;
1419 }
1420
1421 /*
1422 * if var->type=ECPGt_char_variable we have a dynamic cursor we have
1423 * to simulate a dynamic cursor because there is no backend
1424 * functionality for it
1425 */
1426 if (var->type == ECPGt_char_variable)
1427 {
1428 int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1429
1430 if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))
1431 {
1432 ecpg_free_params(stmt, false);
1433 return false;
1434 }
1435 tobeinserted = NULL;
1436 }
1437
1438 /*
1439 * if the placeholder is '$0' we have to replace it on the client side
1440 * this is for places we want to support variables at that are not
1441 * supported in the backend
1442 */
1443 else if (stmt->command[position] == '0')
1444 {
1445 if (stmt->statement_type == ECPGst_prepare ||
1446 stmt->statement_type == ECPGst_exec_with_exprlist)
1447 {
1448 /* Need to double-quote the inserted statement name. */
1449 char *str = ecpg_alloc(strlen(tobeinserted) + 2 + 1,
1450 stmt->lineno);
1451
1452 if (!str)
1453 {
1454 ecpg_free(tobeinserted);
1455 ecpg_free_params(stmt, false);
1456 return false;
1457 }
1458 sprintf(str, "\"%s\"", tobeinserted);
1459 ecpg_free(tobeinserted);
1460 tobeinserted = str;
1461 }
1462
1463 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1464 {
1465 ecpg_free_params(stmt, false);
1466 return false;
1467 }
1468 tobeinserted = NULL;
1469 }
1470 else if (stmt->statement_type == ECPGst_exec_with_exprlist)
1471 {
1472 if (binary_format)
1473 {
1474 char *p = convert_bytea_to_string(tobeinserted,
1475 binary_length,
1476 stmt->lineno);
1477
1478 ecpg_free(tobeinserted);
1479 if (!p)
1480 {
1481 ecpg_free_params(stmt, false);
1482 return false;
1483 }
1484 tobeinserted = p;
1485 }
1486
1487 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1488 {
1489 ecpg_free_params(stmt, false);
1490 return false;
1491 }
1492 tobeinserted = NULL;
1493 }
1494 else
1495 {
1496 bool realloc_failed = false;
1497 char **newparamvalues;
1498 int *newparamlengths;
1499 int *newparamformats;
1500
1501 /* enlarge all the param arrays */
1502 if ((newparamvalues = (char **) ecpg_realloc(stmt->paramvalues, sizeof(char *) * (stmt->nparams + 1), stmt->lineno)))
1503 stmt->paramvalues = newparamvalues;
1504 else
1505 realloc_failed = true;
1506
1507 if ((newparamlengths = (int *) ecpg_realloc(stmt->paramlengths, sizeof(int) * (stmt->nparams + 1), stmt->lineno)))
1508 stmt->paramlengths = newparamlengths;
1509 else
1510 realloc_failed = true;
1511
1512 if ((newparamformats = (int *) ecpg_realloc(stmt->paramformats, sizeof(int) * (stmt->nparams + 1), stmt->lineno)))
1513 stmt->paramformats = newparamformats;
1514 else
1515 realloc_failed = true;
1516
1517 if (realloc_failed)
1518 {
1519 ecpg_free_params(stmt, false);
1520 ecpg_free(tobeinserted);
1521 return false;
1522 }
1523
1524 /* only now can we assign ownership of "tobeinserted" to stmt */
1525 stmt->paramvalues[stmt->nparams] = tobeinserted;
1526 stmt->paramlengths[stmt->nparams] = binary_length;
1527 stmt->paramformats[stmt->nparams] = (binary_format ? 1 : 0);
1528 stmt->nparams++;
1529
1530 /* let's see if this was an old style placeholder */
1531 if (stmt->command[position] == '?')
1532 {
1533 /* yes, replace with new style */
1534 int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
1535 * size we need */
1536
1537 if (!(tobeinserted = ecpg_alloc(buffersize, stmt->lineno)))
1538 {
1539 ecpg_free_params(stmt, false);
1540 return false;
1541 }
1542
1543 snprintf(tobeinserted, buffersize, "$%d", counter++);
1544
1545 if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1546 {
1547 ecpg_free_params(stmt, false);
1548 return false;
1549 }
1550 tobeinserted = NULL;
1551 }
1552 }
1553
1554 if (desc_counter == 0)
1555 var = var->next;
1556 }
1557
1558 /*
1559 * Check if there are unmatched things left. PREPARE AS has no parameter.
1560 * Check other statement.
1561 */
1562 if (stmt->statement_type != ECPGst_prepare &&
1563 next_insert(stmt->command, position, stmt->questionmarks, std_strings) >= 0)
1564 {
1567 ecpg_free_params(stmt, false);
1568 return false;
1569 }
1570
1571 return true;
1572}
#define ECPG_TOO_MANY_ARGUMENTS
Definition: ecpgerrno.h:19
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:840
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS
char * ecpg_realloc(void *ptr, long size, int lineno)
Definition: memory.c:33
#define INFORMIX_MODE(X)
@ ECPGst_exec_with_exprlist
Definition: ecpgtype.h:102
@ ECPGst_prepare
Definition: ecpgtype.h:101
@ ECPGt_sqlda
Definition: ecpgtype.h:66
@ ECPGt_short
Definition: ecpgtype.h:43
@ ECPGt_char_variable
Definition: ecpgtype.h:60
@ ECPGt_bytea
Definition: ecpgtype.h:67
@ ECPGt_varchar
Definition: ecpgtype.h:48
@ ECPGt_NO_INDICATOR
Definition: ecpgtype.h:64
@ ECPGt_descriptor
Definition: ecpgtype.h:59
@ ECPGt_char
Definition: ecpgtype.h:43
static bool insert_tobeinserted(int position, int ph_len, struct statement *stmt, char *tobeinserted)
Definition: execute.c:1127
static char * convert_bytea_to_string(char *from_data, int from_len, int lineno)
Definition: execute.c:488
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
Definition: execute.c:506
static bool store_input_from_desc(struct statement *stmt, struct descriptor_item *desc_item, char **tobeinserted)
Definition: execute.c:1157
static int next_insert(char *text, int pos, bool questionmarks, bool std_strings)
Definition: execute.c:111
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:7659
const char * str
static struct @171 value
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
const void size_t len
#define snprintf
Definition: port.h:260
struct descriptor_item * next
struct descriptor_item * items
short * sqlind
Definition: sqlda-compat.h:13
char * sqldata
Definition: sqlda-compat.h:12
char * sqldata
Definition: sqlda-native.h:28
short * sqlind
Definition: sqlda-native.h:29
void * value
struct variable * next
enum ECPGttype type
void * pointer

References convert_bytea_to_string(), descriptor::count, descriptor_item::data_len, ecpg_alloc(), ecpg_find_desc(), ecpg_free(), ecpg_free_params(), ecpg_raise(), ecpg_realloc(), ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, ecpg_store_input(), ECPG_TOO_FEW_ARGUMENTS, ECPG_TOO_MANY_ARGUMENTS, ECPGst_exec_with_exprlist, ECPGst_prepare, ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_descriptor, ECPGt_NO_INDICATOR, ECPGt_short, ECPGt_sqlda, ECPGt_varchar, i, if(), INFORMIX_MODE, insert_tobeinserted(), descriptor_item::is_binary, descriptor::items, len, descriptor_item::next, variable::next, next_insert(), descriptor_item::num, variable::pointer, PQparameterStatus(), snprintf, sprintf, sqlda_compat::sqld, sqlvar_compat::sqldata, sqlvar_struct::sqldata, sqlvar_compat::sqlind, sqlvar_struct::sqlind, sqlda_struct::sqln, sqlvar_compat::sqltype, sqlvar_struct::sqltype, sqlda_compat::sqlvar, sqlda_struct::sqlvar, stmt, store_input_from_desc(), str, variable::type, value, and variable::value.

Referenced by ecpg_do().

◆ ecpg_check_PQresult()

bool ecpg_check_PQresult ( PGresult results,
int  lineno,
PGconn connection,
enum COMPAT_MODE  compat 
)

Definition at line 281 of file error.c.

282{
283 if (results == NULL)
284 {
285 ecpg_log("ecpg_check_PQresult on line %d: no result - %s", lineno, PQerrorMessage(connection));
286 ecpg_raise_backend(lineno, NULL, connection, compat);
287 return false;
288 }
289
290 switch (PQresultStatus(results))
291 {
292
293 case PGRES_TUPLES_OK:
294 return true;
295 break;
297 /* do nothing */
299 PQclear(results);
300 return false;
301 break;
302 case PGRES_COMMAND_OK:
303 return true;
304 break;
308 ecpg_log("ecpg_check_PQresult on line %d: bad response - %s", lineno, PQresultErrorMessage(results));
309 ecpg_raise_backend(lineno, results, connection, compat);
310 PQclear(results);
311 return false;
312 break;
313 case PGRES_COPY_OUT:
314 return true;
315 break;
316 case PGRES_COPY_IN:
317 ecpg_log("ecpg_check_PQresult on line %d: COPY IN data transfer in progress\n", lineno);
319 PQclear(results);
320 return false;
321 break;
322 default:
323 ecpg_log("ecpg_check_PQresult on line %d: unknown execution status type\n",
324 lineno);
325 ecpg_raise_backend(lineno, results, connection, compat);
326 PQclear(results);
327 return false;
328 break;
329 }
330}
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7704
int PQendcopy(PGconn *conn)
Definition: fe-exec.c:2966
#define PQresultErrorMessage
#define PQresultStatus
Definition: libpq-be-fe.h:247
@ PGRES_COPY_IN
Definition: libpq-fe.h:132
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:125
@ PGRES_FATAL_ERROR
Definition: libpq-fe.h:136
@ PGRES_COPY_OUT
Definition: libpq-fe.h:131
@ PGRES_EMPTY_QUERY
Definition: libpq-fe.h:124
@ PGRES_BAD_RESPONSE
Definition: libpq-fe.h:133
@ PGRES_NONFATAL_ERROR
Definition: libpq-fe.h:135
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:128

References compat, ECPG_EMPTY, ecpg_log(), ecpg_raise(), ecpg_raise_backend(), ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, PGRES_BAD_RESPONSE, PGRES_COMMAND_OK, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_EMPTY_QUERY, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PGRES_TUPLES_OK, PQclear, PQendcopy(), PQerrorMessage(), PQresultErrorMessage, and PQresultStatus.

Referenced by deallocate_one(), ecpg_autostart_transaction(), ecpg_execute(), ecpg_is_type_an_array(), ECPGdescribe(), ECPGsetcommit(), ECPGtrans(), and prepare_common().

◆ ecpg_clear_auto_mem()

void ecpg_clear_auto_mem ( void  )

Definition at line 160 of file memory.c.

161{
162 struct auto_mem *am = get_auto_allocs();
163
164 /* only free our own structure */
165 if (am)
166 {
167 do
168 {
169 struct auto_mem *act = am;
170
171 am = am->next;
172 ecpg_free(act);
173 } while (am);
174 set_auto_allocs(NULL);
175 }
176}

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

Referenced by ecpg_do_prologue(), and ECPGconnect().

◆ ecpg_deallocate_all_conn()

bool ecpg_deallocate_all_conn ( int  lineno,
enum COMPAT_MODE  c,
struct connection con 
)

Definition at line 369 of file prepare.c.

370{
371 /* deallocate all prepared statements */
372 while (con->prep_stmts)
373 {
374 if (!deallocate_one(lineno, c, con, NULL, con->prep_stmts))
375 return false;
376 }
377
378 return true;
379}
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
char * c
struct prepared_statement * prep_stmts

References deallocate_one(), and connection::prep_stmts.

Referenced by ecpg_finish(), and ECPGdeallocate_all().

◆ ecpg_do()

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

2258{
2259 struct statement *stmt = NULL;
2260
2261 if (!ecpg_do_prologue(lineno, compat, force_indicator, connection_name,
2263 query, args, &stmt))
2264 goto fail;
2265
2266 if (!ecpg_build_params(stmt))
2267 goto fail;
2268
2270 goto fail;
2271
2272 if (!ecpg_execute(stmt))
2273 goto fail;
2274
2275 if (!ecpg_process_output(stmt, true))
2276 goto fail;
2277
2279 return true;
2280
2281fail:
2283 return false;
2284}
bool force_indicator
Definition: ecpg.c:18
bool questionmarks
Definition: ecpg.c:19
ECPG_statement_type
Definition: ecpgtype.h:96
bool ecpg_build_params(struct statement *stmt)
Definition: execute.c:1211
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1600
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:2230
bool ecpg_do_prologue(int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, enum ECPG_statement_type statement_type, const char *query, va_list args, struct statement **stmt_out)
Definition: execute.c:1942
bool ecpg_process_output(struct statement *stmt, bool clear_result)
Definition: execute.c:1669
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1579

References generate_unaccent_rules::args, compat, ecpg_autostart_transaction(), ecpg_build_params(), ecpg_do_epilogue(), ecpg_do_prologue(), ecpg_execute(), ecpg_process_output(), force_indicator, statement::lineno, questionmarks, and stmt.

Referenced by ECPGdo().

◆ ecpg_do_epilogue()

void ecpg_do_epilogue ( struct statement stmt)

Definition at line 2230 of file execute.c.

2231{
2232 if (stmt == NULL)
2233 return;
2234
2235#ifdef HAVE_USELOCALE
2236 if (stmt->oldlocale != (locale_t) 0)
2237 uselocale(stmt->oldlocale);
2238#else
2239 if (stmt->oldlocale)
2240 {
2241 setlocale(LC_NUMERIC, stmt->oldlocale);
2242#ifdef WIN32
2243 _configthreadlocale(stmt->oldthreadlocale);
2244#endif
2245 }
2246#endif
2247
2249}
static void free_statement(struct statement *stmt)
Definition: execute.c:96
#define locale_t
Definition: win32_port.h:432
#define setlocale(a, b)
Definition: win32_port.h:475

References free_statement(), locale_t, setlocale, and stmt.

Referenced by ecpg_do(), and ecpg_do_prologue().

◆ ecpg_do_prologue()

bool ecpg_do_prologue ( int  lineno,
const int  compat,
const int  force_indicator,
const char *  connection_name,
const bool  questionmarks,
enum ECPG_statement_type  statement_type,
const char *  query,
va_list  args,
struct statement **  stmt_out 
)

Definition at line 1942 of file execute.c.

1946{
1947 struct statement *stmt = NULL;
1948 struct connection *con;
1949 enum ECPGttype type;
1950 struct variable **list;
1951 char *prepname;
1952 bool is_prepared_name_set;
1953
1954 *stmt_out = NULL;
1955
1956 if (!query)
1957 {
1959 return false;
1960 }
1961
1963
1964 con = ecpg_get_connection(connection_name);
1965
1966 if (!ecpg_init(con, connection_name, lineno))
1967 return false;
1968
1969 stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
1970
1971 if (stmt == NULL)
1972 return false;
1973
1974 /*
1975 * Make sure we do NOT honor the locale for numeric input/output since the
1976 * database wants the standard decimal point. If available, use
1977 * uselocale() for this because it's thread-safe. Windows doesn't have
1978 * that, but it does have _configthreadlocale().
1979 */
1980#ifdef HAVE_USELOCALE
1981
1982 /*
1983 * Since ecpg_init() succeeded, we have a connection. Any successful
1984 * connection initializes ecpg_clocale.
1985 */
1986 Assert(ecpg_clocale);
1987 stmt->oldlocale = uselocale(ecpg_clocale);
1988 if (stmt->oldlocale == (locale_t) 0)
1989 {
1991 return false;
1992 }
1993#else
1994#ifdef WIN32
1995 stmt->oldthreadlocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
1996 if (stmt->oldthreadlocale == -1)
1997 {
1999 return false;
2000 }
2001#endif
2002 stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno,
2003 NULL);
2004 if (stmt->oldlocale == NULL)
2005 {
2007 return false;
2008 }
2009 setlocale(LC_NUMERIC, "C");
2010#endif
2011
2012 /*
2013 * If statement type is ECPGst_prepnormal we are supposed to prepare the
2014 * statement before executing them
2015 */
2017 {
2018 if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query))
2019 {
2021 return false;
2022 }
2023
2024 /*
2025 * statement is now prepared, so instead of the query we have to
2026 * execute the name
2027 */
2028 stmt->command = prepname;
2030 }
2031 else
2032 {
2033 stmt->command = ecpg_strdup(query, lineno, NULL);
2034 if (!stmt->command)
2035 {
2037 return false;
2038 }
2039 }
2040
2041 stmt->name = NULL;
2042
2044 {
2045 /* if we have an EXECUTE command, only the name is send */
2046 char *command = ecpg_prepared(stmt->command, con);
2047
2048 if (command)
2049 {
2050 stmt->name = stmt->command;
2051 stmt->command = ecpg_strdup(command, lineno, NULL);
2052 if (!stmt->command)
2053 {
2055 return false;
2056 }
2057 }
2058 else
2059 {
2062 return false;
2063 }
2064 }
2065 /* name of PREPARE AS will be set in loop of inlist */
2066
2067 stmt->connection = con;
2068 stmt->lineno = lineno;
2069 stmt->compat = compat;
2070 stmt->force_indicator = force_indicator;
2071 stmt->questionmarks = questionmarks;
2072 stmt->statement_type = statement_type;
2073
2074 /*------
2075 * create a list of variables
2076 *
2077 * The variables are listed with input variables preceding output
2078 * variables. The end of each group is marked by an end marker.
2079 * Per variable we list:
2080 *
2081 * type - as defined in ecpgtype.h
2082 * value - where to store the data
2083 * varcharsize - length of string in case we have a stringvariable, else 0
2084 * arraysize - 0 for pointer (we don't know the size of the array), 1 for
2085 * simple variable, size for arrays
2086 * offset - offset between ith and (i+1)th entry in an array, normally
2087 * that means sizeof(type)
2088 * ind_type - type of indicator variable
2089 * ind_pointer - pointer to indicator variable
2090 * ind_varcharsize - empty
2091 * ind_arrsize - arraysize of indicator array
2092 * ind_offset - indicator offset
2093 *------
2094 */
2095
2096 is_prepared_name_set = false;
2097
2098 list = &(stmt->inlist);
2099
2100 type = va_arg(args, enum ECPGttype);
2101
2102 while (type != ECPGt_EORT)
2103 {
2104 if (type == ECPGt_EOIT)
2105 list = &(stmt->outlist);
2106 else
2107 {
2108 struct variable *var,
2109 *ptr;
2110
2111 if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
2112 {
2114 return false;
2115 }
2116
2117 var->type = type;
2118 var->pointer = va_arg(args, char *);
2119
2120 var->varcharsize = va_arg(args, long);
2121 var->arrsize = va_arg(args, long);
2122 var->offset = va_arg(args, long);
2123
2124 /*
2125 * Unknown array size means pointer to an array. Unknown
2126 * varcharsize usually also means pointer. But if the type is
2127 * character and the array size is known, it is an array of
2128 * pointers to char, so use var->pointer as it is.
2129 */
2130 if (var->arrsize == 0 ||
2131 (var->varcharsize == 0 && ((var->type != ECPGt_char && var->type != ECPGt_unsigned_char) || (var->arrsize <= 1))))
2132 var->value = *((char **) (var->pointer));
2133 else
2134 var->value = var->pointer;
2135
2136 /*
2137 * negative values are used to indicate an array without given
2138 * bounds
2139 */
2140 /* reset to zero for us */
2141 if (var->arrsize < 0)
2142 var->arrsize = 0;
2143 if (var->varcharsize < 0)
2144 var->varcharsize = 0;
2145
2146 var->next = NULL;
2147
2148 var->ind_type = va_arg(args, enum ECPGttype);
2149 var->ind_pointer = va_arg(args, char *);
2150 var->ind_varcharsize = va_arg(args, long);
2151 var->ind_arrsize = va_arg(args, long);
2152 var->ind_offset = va_arg(args, long);
2153
2154 if (var->ind_type != ECPGt_NO_INDICATOR
2155 && (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
2156 var->ind_value = *((char **) (var->ind_pointer));
2157 else
2158 var->ind_value = var->ind_pointer;
2159
2160 /*
2161 * negative values are used to indicate an array without given
2162 * bounds
2163 */
2164 /* reset to zero for us */
2165 if (var->ind_arrsize < 0)
2166 var->ind_arrsize = 0;
2167 if (var->ind_varcharsize < 0)
2168 var->ind_varcharsize = 0;
2169
2170 /* if variable is NULL, the statement hasn't been prepared */
2171 if (var->pointer == NULL)
2172 {
2174 ecpg_free(var);
2176 return false;
2177 }
2178
2179 for (ptr = *list; ptr && ptr->next; ptr = ptr->next)
2180 ;
2181
2182 if (ptr == NULL)
2183 *list = var;
2184 else
2185 ptr->next = var;
2186
2187 if (!is_prepared_name_set && stmt->statement_type == ECPGst_prepare)
2188 {
2189 stmt->name = ecpg_strdup(var->value, lineno, NULL);
2190 if (!stmt->name)
2191 {
2193 return false;
2194 }
2195 is_prepared_name_set = true;
2196 }
2197 }
2198
2199 type = va_arg(args, enum ECPGttype);
2200 }
2201
2202 /* are we connected? */
2203 if (con == NULL || con->connection == NULL)
2204 {
2205 ecpg_raise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : ecpg_gettext("<empty>"));
2207 return false;
2208 }
2209
2210 if (!is_prepared_name_set && stmt->statement_type == ECPGst_prepare)
2211 {
2214 return false;
2215 }
2216
2217 /* initialize auto_mem struct */
2219
2220 *stmt_out = stmt;
2221
2222 return true;
2223}
void ecpg_pthreads_init(void)
Definition: connect.c:30
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
#define ECPG_NOT_CONN
Definition: ecpgerrno.h:37
#define ecpg_gettext(x)
void bool ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, char **name, const char *query)
Definition: prepare.c:587
void ecpg_clear_auto_mem(void)
Definition: memory.c:160
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
Definition: misc.c:73
char * ecpg_prepared(const char *name, struct connection *con)
Definition: prepare.c:389
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
@ ECPGst_execute
Definition: ecpgtype.h:98
@ ECPGst_prepnormal
Definition: ecpgtype.h:100
ECPGttype
Definition: ecpgtype.h:42
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_unsigned_char
Definition: ecpgtype.h:43
@ ECPGt_EORT
Definition: ecpgtype.h:63
Assert(PointerIsAligned(start, uint64))
PGconn * connection
char * command
enum ECPG_statement_type statement_type
long ind_arrsize
long ind_offset
void * ind_value
long ind_varcharsize
long varcharsize
enum ECPGttype ind_type
void * ind_pointer
const char * type

References generate_unaccent_rules::args, variable::arrsize, Assert(), statement::command, compat, connection::connection, ecpg_alloc(), ecpg_auto_prepare(), ecpg_clear_auto_mem(), ecpg_do_epilogue(), ECPG_EMPTY, ecpg_free(), ecpg_get_connection(), ecpg_gettext, ecpg_init(), ECPG_INVALID_STMT, ECPG_NOT_CONN, ecpg_prepared(), ecpg_pthreads_init(), ecpg_raise(), ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, ecpg_strdup(), ECPG_TOO_FEW_ARGUMENTS, ECPGst_execute, ECPGst_prepare, ECPGst_prepnormal, ECPGt_char, ECPGt_EOIT, ECPGt_EORT, ECPGt_NO_INDICATOR, ECPGt_unsigned_char, force_indicator, variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, statement::lineno, sort-test::list, locale_t, connection::name, variable::next, variable::offset, variable::pointer, questionmarks, setlocale, statement::statement_type, stmt, type, variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_do().

◆ ecpg_dynamic_type()

int ecpg_dynamic_type ( Oid  type)

Definition at line 73 of file typename.c.

74{
75 switch (type)
76 {
77 case BOOLOID:
78 return SQL3_BOOLEAN; /* bool */
79 case INT2OID:
80 return SQL3_SMALLINT; /* int2 */
81 case INT4OID:
82 return SQL3_INTEGER; /* int4 */
83 case TEXTOID:
84 return SQL3_CHARACTER; /* text */
85 case FLOAT4OID:
86 return SQL3_REAL; /* float4 */
87 case FLOAT8OID:
88 return SQL3_DOUBLE_PRECISION; /* float8 */
89 case BPCHAROID:
90 return SQL3_CHARACTER; /* bpchar */
91 case VARCHAROID:
92 return SQL3_CHARACTER_VARYING; /* varchar */
93 case DATEOID:
94 return SQL3_DATE_TIME_TIMESTAMP; /* date */
95 case TIMEOID:
96 return SQL3_DATE_TIME_TIMESTAMP; /* time */
97 case TIMESTAMPOID:
98 return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
99 case NUMERICOID:
100 return SQL3_NUMERIC; /* numeric */
101 default:
102 return 0;
103 }
104}
@ SQL3_DATE_TIME_TIMESTAMP
Definition: sql3types.h:18
@ SQL3_INTEGER
Definition: sql3types.h:13
@ SQL3_BOOLEAN
Definition: sql3types.h:24
@ SQL3_CHARACTER_VARYING
Definition: sql3types.h:20
@ SQL3_SMALLINT
Definition: sql3types.h:14
@ SQL3_DOUBLE_PRECISION
Definition: sql3types.h:17
@ SQL3_NUMERIC
Definition: sql3types.h:11
@ SQL3_CHARACTER
Definition: sql3types.h:10
@ SQL3_REAL
Definition: sql3types.h:16

References SQL3_BOOLEAN, SQL3_CHARACTER, SQL3_CHARACTER_VARYING, SQL3_DATE_TIME_TIMESTAMP, SQL3_DOUBLE_PRECISION, SQL3_INTEGER, SQL3_NUMERIC, SQL3_REAL, SQL3_SMALLINT, and type.

Referenced by ecpg_is_type_an_array(), and ECPGget_desc().

◆ ecpg_execute()

bool ecpg_execute ( struct statement stmt)

Definition at line 1600 of file execute.c.

1601{
1602 ecpg_log("ecpg_execute on line %d: query: %s; with %d parameter(s) on connection %s\n", stmt->lineno, stmt->command, stmt->nparams, stmt->connection->name);
1603 if (stmt->statement_type == ECPGst_execute)
1604 {
1605 stmt->results = PQexecPrepared(stmt->connection->connection,
1606 stmt->name,
1607 stmt->nparams,
1608 (const char *const *) stmt->paramvalues,
1609 (const int *) stmt->paramlengths,
1610 (const int *) stmt->paramformats,
1611 0);
1612 ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
1613 }
1614 else
1615 {
1616 if (stmt->nparams == 0)
1617 {
1618 stmt->results = PQexec(stmt->connection->connection, stmt->command);
1619 ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
1620 }
1621 else
1622 {
1623 stmt->results = PQexecParams(stmt->connection->connection,
1624 stmt->command, stmt->nparams, NULL,
1625 (const char *const *) stmt->paramvalues,
1626 (const int *) stmt->paramlengths,
1627 (const int *) stmt->paramformats,
1628 0);
1629
1630 ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
1631 }
1632
1633 if (stmt->statement_type == ECPGst_prepare)
1634 {
1636 {
1637 ecpg_free_params(stmt, true);
1638 return false;
1639 }
1640 }
1641 }
1642
1643 ecpg_free_params(stmt, true);
1644
1645 if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1646 return false;
1647
1648 return true;
1649}
bool ecpg_register_prepared_stmt(struct statement *stmt)
Definition: prepare.c:59
PGresult * PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:2293
PGresult * PQexecPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
Definition: fe-exec.c:2340

References ecpg_check_PQresult(), ecpg_free_params(), ecpg_log(), ecpg_register_prepared_stmt(), ECPGst_execute, ECPGst_prepare, PQexec(), PQexecParams(), PQexecPrepared(), and stmt.

Referenced by ecpg_do().

◆ ecpg_find_desc()

struct descriptor * ecpg_find_desc ( int  line,
const char *  name 
)

Definition at line 840 of file descriptor.c.

841{
842 struct descriptor *desc;
843
844 for (desc = get_descriptors(); desc; desc = desc->next)
845 {
846 if (strcmp(name, desc->name) == 0)
847 return desc;
848 }
849
851 return NULL; /* not found */
852}
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
static struct descriptor * get_descriptors(void)
Definition: descriptor.c:40
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
struct descriptor * next

References ecpg_raise(), ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, ECPG_UNKNOWN_DESCRIPTOR, get_descriptors(), name, descriptor::name, and descriptor::next.

Referenced by ecpg_build_params(), ecpg_process_output(), ecpg_result_by_descriptor(), ECPGdescribe(), ECPGset_desc(), and ECPGset_desc_header().

◆ ecpg_find_prepared_statement()

struct prepared_statement * ecpg_find_prepared_statement ( const char *  name,
struct connection con,
struct prepared_statement **  prev_ 
)

Definition at line 271 of file prepare.c.

273{
274 struct prepared_statement *this,
275 *prev;
276
277 for (this = con->prep_stmts, prev = NULL;
278 this != NULL;
279 prev = this, this = this->next)
280 {
281 if (strcmp(this->name, name) == 0)
282 {
283 if (prev_)
284 *prev_ = prev;
285 return this;
286 }
287 }
288 return NULL;
289}
struct prepared_statement * next

References name, prepared_statement::next, and connection::prep_stmts.

Referenced by ecpg_auto_prepare(), ecpg_freeStmtCacheEntry(), ecpg_prepared(), ecpg_register_prepared_stmt(), ECPGdeallocate(), ECPGdescribe(), and ECPGprepare().

◆ ecpg_free()

◆ ecpg_free_params()

void ecpg_free_params ( struct statement stmt,
bool  print 
)

Definition at line 1106 of file execute.c.

1107{
1108 int n;
1109
1110 for (n = 0; n < stmt->nparams; n++)
1111 {
1112 if (print)
1113 print_param_value(stmt->paramvalues[n], stmt->paramlengths[n],
1114 stmt->paramformats[n], stmt->lineno, n + 1);
1115 ecpg_free(stmt->paramvalues[n]);
1116 }
1117 ecpg_free(stmt->paramvalues);
1118 ecpg_free(stmt->paramlengths);
1119 ecpg_free(stmt->paramformats);
1120 stmt->paramvalues = NULL;
1121 stmt->paramlengths = NULL;
1122 stmt->paramformats = NULL;
1123 stmt->nparams = 0;
1124}
void print(const void *obj)
Definition: print.c:36
static void print_param_value(char *value, int len, int is_binary, int lineno, int nth)
Definition: execute.c:1076

References ecpg_free(), print(), print_param_value(), and stmt.

Referenced by ecpg_autostart_transaction(), ecpg_build_params(), and ecpg_execute().

◆ ecpg_get_connection()

struct connection * ecpg_get_connection ( const char *  connection_name)

Definition at line 76 of file connect.c.

77{
78 struct connection *ret = NULL;
79
80 if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
81 {
82 ecpg_pthreads_init(); /* ensure actual_connection_key is valid */
83
85
86 /*
87 * if no connection in TSD for this thread, get the global default
88 * connection and hope the user knows what they're doing (i.e. using
89 * their own mutex to protect that connection from concurrent accesses
90 */
91 if (ret == NULL)
92 /* no TSD connection here either, using global */
94 }
95 else
96 {
98
99 ret = ecpg_get_connection_nr(connection_name);
100
102 }
103
104 return ret;
105}
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
static pthread_mutex_t connections_mutex
Definition: connect.c:17
static pthread_key_t actual_connection_key
Definition: connect.c:18
static struct connection * actual_connection
Definition: connect.c:20
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_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29

References actual_connection, actual_connection_key, connections_mutex, ecpg_get_connection_nr(), ecpg_pthreads_init(), pthread_getspecific(), pthread_mutex_lock(), and pthread_mutex_unlock().

Referenced by ecpg_auto_prepare(), ecpg_do_prologue(), ecpg_freeStmtCacheEntry(), ECPGconnect(), ECPGdeallocate(), ECPGdeallocate_all(), ECPGdescribe(), ECPGget_desc(), ECPGget_PGconn(), ECPGprepare(), ECPGprepared_statement(), ECPGsetcommit(), ECPGsetconn(), ECPGstatus(), ECPGtrans(), and ECPGtransactionStatus().

◆ ecpg_get_data()

bool ecpg_get_data ( const PGresult results,
int  act_tuple,
int  act_field,
int  lineno,
enum ECPGttype  type,
enum  ECPGttype,
char *  var,
char *  ind,
long  varcharsize,
long  offset,
long  ind_offset,
enum  ARRAY_TYPE,
enum  COMPAT_MODE,
bool  force_indicator 
)

Definition at line 195 of file data.c.

199{
200 struct sqlca_t *sqlca = ECPGget_sqlca();
201 char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
202 int binary = PQfformat(results, act_field);
203 int size = PQgetlength(results, act_tuple, act_field);
204 int value_for_indicator = 0;
205 long log_offset;
206
207 if (sqlca == NULL)
208 {
211 return false;
212 }
213
214 /*
215 * If we are running in a regression test, do not log the offset variable,
216 * it depends on the machine's alignment.
217 */
219 log_offset = -1;
220 else
221 log_offset = offset;
222
223 ecpg_log("ecpg_get_data on line %d: RESULT: %s offset: %ld; array: %s\n", lineno, pval ? (binary ? "BINARY" : pval) : "EMPTY", log_offset, ECPG_IS_ARRAY(isarray) ? "yes" : "no");
224
225 /* pval is a pointer to the value */
226 if (!pval)
227 {
228 /*
229 * This should never happen because we already checked that we found
230 * at least one tuple, but let's play it safe.
231 */
233 return false;
234 }
235
236 /* We will have to decode the value */
237
238 /*
239 * check for null value and set indicator accordingly, i.e. -1 if NULL and
240 * 0 if not
241 */
242 if (PQgetisnull(results, act_tuple, act_field))
243 value_for_indicator = -1;
244
245 switch (ind_type)
246 {
247 case ECPGt_short:
249 *((short *) (ind + ind_offset * act_tuple)) = value_for_indicator;
250 break;
251 case ECPGt_int:
253 *((int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
254 break;
255 case ECPGt_long:
257 *((long *) (ind + ind_offset * act_tuple)) = value_for_indicator;
258 break;
259 case ECPGt_long_long:
261 *((long long int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
262 break;
264 if (value_for_indicator == -1)
265 {
266 if (force_indicator == false)
267 {
268 /*
269 * Informix has an additional way to specify NULLs note
270 * that this uses special values to denote NULL
271 */
272 ECPGset_noind_null(type, var + offset * act_tuple);
273 }
274 else
275 {
278 NULL);
279 return false;
280 }
281 }
282 break;
283 default:
286 ecpg_type_name(ind_type));
287 return false;
288 break;
289 }
290
291 if (value_for_indicator == -1)
292 return true;
293
294 /* let's check if it really is an array if it should be one */
295 if (isarray == ECPG_ARRAY_ARRAY)
296 {
297 if (*pval != '{')
298 {
301 return false;
302 }
303
304 switch (type)
305 {
306 case ECPGt_char:
308 case ECPGt_varchar:
309 case ECPGt_string:
310 break;
311
312 default:
313 pval++;
314 break;
315 }
316 }
317
318 do
319 {
320 if (binary)
321 {
322 if (varcharsize == 0 || varcharsize * offset >= size)
323 memcpy(var + offset * act_tuple, pval, size);
324 else
325 {
326 memcpy(var + offset * act_tuple, pval, varcharsize * offset);
327
328 if (varcharsize * offset < size)
329 {
330 /* truncation */
331 switch (ind_type)
332 {
333 case ECPGt_short:
335 *((short *) (ind + ind_offset * act_tuple)) = size;
336 break;
337 case ECPGt_int:
339 *((int *) (ind + ind_offset * act_tuple)) = size;
340 break;
341 case ECPGt_long:
343 *((long *) (ind + ind_offset * act_tuple)) = size;
344 break;
345 case ECPGt_long_long:
347 *((long long int *) (ind + ind_offset * act_tuple)) = size;
348 break;
349 default:
350 break;
351 }
352 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
353 }
354 }
355 pval += size;
356 }
357 else
358 {
359 switch (type)
360 {
361 long res;
362 unsigned long ures;
363 double dres;
364 char *scan_length;
365 numeric *nres;
366 date ddres;
367 timestamp tres;
368 interval *ires;
369 char *endptr,
370 endchar;
371
372 case ECPGt_short:
373 case ECPGt_int:
374 case ECPGt_long:
375 res = strtol(pval, &scan_length, 10);
376 if (garbage_left(isarray, &scan_length, compat))
377 {
380 return false;
381 }
382 pval = scan_length;
383
384 switch (type)
385 {
386 case ECPGt_short:
387 *((short *) (var + offset * act_tuple)) = (short) res;
388 break;
389 case ECPGt_int:
390 *((int *) (var + offset * act_tuple)) = (int) res;
391 break;
392 case ECPGt_long:
393 *((long *) (var + offset * act_tuple)) = (long) res;
394 break;
395 default:
396 /* Cannot happen */
397 break;
398 }
399 break;
400
404 ures = strtoul(pval, &scan_length, 10);
405 if (garbage_left(isarray, &scan_length, compat))
406 {
409 return false;
410 }
411 pval = scan_length;
412
413 switch (type)
414 {
416 *((unsigned short *) (var + offset * act_tuple)) = (unsigned short) ures;
417 break;
419 *((unsigned int *) (var + offset * act_tuple)) = (unsigned int) ures;
420 break;
422 *((unsigned long *) (var + offset * act_tuple)) = (unsigned long) ures;
423 break;
424 default:
425 /* Cannot happen */
426 break;
427 }
428 break;
429
430 case ECPGt_long_long:
431 *((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
432 if (garbage_left(isarray, &scan_length, compat))
433 {
435 return false;
436 }
437 pval = scan_length;
438
439 break;
440
442 *((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
443 if (garbage_left(isarray, &scan_length, compat))
444 {
446 return false;
447 }
448 pval = scan_length;
449
450 break;
451
452 case ECPGt_float:
453 case ECPGt_double:
454 if (isarray && *pval == '"')
455 pval++;
456
457 if (!check_special_value(pval, &dres, &scan_length))
458 dres = strtod(pval, &scan_length);
459
460 if (isarray && *scan_length == '"')
461 scan_length++;
462
463 /* no special INFORMIX treatment for floats */
464 if (garbage_left(isarray, &scan_length, ECPG_COMPAT_PGSQL))
465 {
468 return false;
469 }
470 pval = scan_length;
471
472 switch (type)
473 {
474 case ECPGt_float:
475 *((float *) (var + offset * act_tuple)) = dres;
476 break;
477 case ECPGt_double:
478 *((double *) (var + offset * act_tuple)) = dres;
479 break;
480 default:
481 /* Cannot happen */
482 break;
483 }
484 break;
485
486 case ECPGt_bool:
487 if (pval[0] == 'f' && pval[1] == '\0')
488 {
489 *((bool *) (var + offset * act_tuple)) = false;
490 pval++;
491 break;
492 }
493 else if (pval[0] == 't' && pval[1] == '\0')
494 {
495 *((bool *) (var + offset * act_tuple)) = true;
496 pval++;
497 break;
498 }
499 else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
500 {
501 /* NULL is valid */
502 break;
503 }
504
507 return false;
508 break;
509
510 case ECPGt_bytea:
511 {
513 (struct ECPGgeneric_bytea *) (var + offset * act_tuple);
514 long dst_size,
515 src_size,
516 dec_size;
517
518 dst_size = ecpg_hex_enc_len(varcharsize);
519 src_size = size - 2; /* exclude backslash + 'x' */
520 dec_size = src_size < dst_size ? src_size : dst_size;
521 variable->len = hex_decode(pval + 2, dec_size, variable->arr);
522
523 if (dst_size < src_size)
524 {
525 long rcv_size = ecpg_hex_dec_len(size - 2);
526
527 /* truncation */
528 switch (ind_type)
529 {
530 case ECPGt_short:
532 *((short *) (ind + ind_offset * act_tuple)) = rcv_size;
533 break;
534 case ECPGt_int:
536 *((int *) (ind + ind_offset * act_tuple)) = rcv_size;
537 break;
538 case ECPGt_long:
540 *((long *) (ind + ind_offset * act_tuple)) = rcv_size;
541 break;
542 case ECPGt_long_long:
544 *((long long int *) (ind + ind_offset * act_tuple)) = rcv_size;
545 break;
546 default:
547 break;
548 }
549 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
550 }
551
552 pval += size;
553 }
554 break;
555
556 case ECPGt_char:
558 case ECPGt_string:
559 {
560 char *str = (char *) (var + offset * act_tuple);
561
562 /*
563 * If varcharsize is unknown and the offset is that of
564 * char *, then this variable represents the array of
565 * character pointers. So, use extra indirection.
566 */
567 if (varcharsize == 0 && offset == sizeof(char *))
568 str = *(char **) str;
569
570 if (varcharsize > size)
571 {
572 /*
573 * compatibility mode, blank pad and null
574 * terminate char array
575 */
577 {
578 memset(str, ' ', varcharsize);
579 memcpy(str, pval, size);
580 str[varcharsize - 1] = '\0';
581
582 /*
583 * compatibility mode empty string gets -1
584 * indicator but no warning
585 */
586 if (size == 0)
587 {
588 /* truncation */
589 switch (ind_type)
590 {
591 case ECPGt_short:
593 *((short *) (ind + ind_offset * act_tuple)) = -1;
594 break;
595 case ECPGt_int:
597 *((int *) (ind + ind_offset * act_tuple)) = -1;
598 break;
599 case ECPGt_long:
601 *((long *) (ind + ind_offset * act_tuple)) = -1;
602 break;
603 case ECPGt_long_long:
605 *((long long int *) (ind + ind_offset * act_tuple)) = -1;
606 break;
607 default:
608 break;
609 }
610 }
611 }
612 else
613 {
614 strncpy(str, pval, size + 1);
615 }
616 /* do the rtrim() */
617 if (type == ECPGt_string)
618 {
619 char *last = str + size;
620
621 while (last > str && (*last == ' ' || *last == '\0'))
622 {
623 *last = '\0';
624 last--;
625 }
626 }
627 }
628 else
629 {
630 int charsize = varcharsize;
631
632 /*
633 * assume that the caller provided storage exactly
634 * fit when varcharsize is zero.
635 */
636 if (varcharsize == 0)
637 charsize = size + 1;
638
639 strncpy(str, pval, charsize);
640
641 /* compatibility mode, null terminate char array */
642 if (ORACLE_MODE(compat) && (charsize - 1) < size)
643 {
645 str[charsize - 1] = '\0';
646 }
647
648 if (charsize < size || (ORACLE_MODE(compat) && (charsize - 1) < size))
649 {
650 /* truncation */
651 switch (ind_type)
652 {
653 case ECPGt_short:
655 *((short *) (ind + ind_offset * act_tuple)) = size;
656 break;
657 case ECPGt_int:
659 *((int *) (ind + ind_offset * act_tuple)) = size;
660 break;
661 case ECPGt_long:
663 *((long *) (ind + ind_offset * act_tuple)) = size;
664 break;
665 case ECPGt_long_long:
667 *((long long int *) (ind + ind_offset * act_tuple)) = size;
668 break;
669 default:
670 break;
671 }
672 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
673 }
674 }
675 pval += size;
676 }
677 break;
678
679 case ECPGt_varchar:
680 {
682 (struct ECPGgeneric_varchar *) (var + offset * act_tuple);
683
684 variable->len = size;
685 if (varcharsize == 0)
686 strncpy(variable->arr, pval, variable->len);
687 else
688 {
689 strncpy(variable->arr, pval, varcharsize);
690
691 if (variable->len > varcharsize)
692 {
693 /* truncation */
694 switch (ind_type)
695 {
696 case ECPGt_short:
698 *((short *) (ind + ind_offset * act_tuple)) = variable->len;
699 break;
700 case ECPGt_int:
702 *((int *) (ind + ind_offset * act_tuple)) = variable->len;
703 break;
704 case ECPGt_long:
706 *((long *) (ind + ind_offset * act_tuple)) = variable->len;
707 break;
708 case ECPGt_long_long:
710 *((long long int *) (ind + ind_offset * act_tuple)) = variable->len;
711 break;
712 default:
713 break;
714 }
715 sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
716
717 variable->len = varcharsize;
718 }
719 }
720 pval += size;
721 }
722 break;
723
724 case ECPGt_decimal:
725 case ECPGt_numeric:
726 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
727 endchar = *endptr;
728 *endptr = '\0';
729 nres = PGTYPESnumeric_from_asc(pval, &scan_length);
730 *endptr = endchar;
731
732 /* did we get an error? */
733 if (nres == NULL)
734 {
735 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
736 lineno, pval, errno);
737
739 {
740 /*
741 * Informix wants its own NULL value here instead
742 * of an error
743 */
744 nres = PGTYPESnumeric_new();
745 if (nres)
747 else
748 {
751 return false;
752 }
753 }
754 else
755 {
758 return false;
759 }
760 }
761 else
762 {
763 if (!isarray && garbage_left(isarray, &scan_length, compat))
764 {
765 free(nres);
768 return false;
769 }
770 }
771 pval = scan_length;
772
773 if (type == ECPGt_numeric)
774 PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
775 else
776 PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
777
779 break;
780
781 case ECPGt_interval:
782 if (*pval == '"')
783 pval++;
784
785 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
786 endchar = *endptr;
787 *endptr = '\0';
788 ires = PGTYPESinterval_from_asc(pval, &scan_length);
789 *endptr = endchar;
790
791 /* did we get an error? */
792 if (ires == NULL)
793 {
794 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
795 lineno, pval, errno);
796
798 {
799 /*
800 * Informix wants its own NULL value here instead
801 * of an error
802 */
803 ires = (interval *) ecpg_alloc(sizeof(interval), lineno);
804 if (!ires)
805 return false;
806
808 }
809 else
810 {
813 return false;
814 }
815 }
816 else
817 {
818 if (*scan_length == '"')
819 scan_length++;
820
821 if (!isarray && garbage_left(isarray, &scan_length, compat))
822 {
823 free(ires);
826 return false;
827 }
828 }
829 pval = scan_length;
830
831 PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
832 free(ires);
833 break;
834
835 case ECPGt_date:
836 if (*pval == '"')
837 pval++;
838
839 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
840 endchar = *endptr;
841 *endptr = '\0';
842 ddres = PGTYPESdate_from_asc(pval, &scan_length);
843 *endptr = endchar;
844
845 /* did we get an error? */
846 if (errno != 0)
847 {
848 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
849 lineno, pval, errno);
850
852 {
853 /*
854 * Informix wants its own NULL value here instead
855 * of an error
856 */
858 }
859 else
860 {
863 return false;
864 }
865 }
866 else
867 {
868 if (*scan_length == '"')
869 scan_length++;
870
871 if (!isarray && garbage_left(isarray, &scan_length, compat))
872 {
875 return false;
876 }
877 }
878
879 *((date *) (var + offset * act_tuple)) = ddres;
880 pval = scan_length;
881 break;
882
883 case ECPGt_timestamp:
884 if (*pval == '"')
885 pval++;
886
887 for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
888 endchar = *endptr;
889 *endptr = '\0';
890 tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
891 *endptr = endchar;
892
893 /* did we get an error? */
894 if (errno != 0)
895 {
896 ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
897 lineno, pval, errno);
898
900 {
901 /*
902 * Informix wants its own NULL value here instead
903 * of an error
904 */
906 }
907 else
908 {
911 return false;
912 }
913 }
914 else
915 {
916 if (*scan_length == '"')
917 scan_length++;
918
919 if (!isarray && garbage_left(isarray, &scan_length, compat))
920 {
923 return false;
924 }
925 }
926
927 *((timestamp *) (var + offset * act_tuple)) = tres;
928 pval = scan_length;
929 break;
930
931 default:
935 return false;
936 break;
937 }
938 if (ECPG_IS_ARRAY(isarray))
939 {
940 bool string = false;
941
942 /* set array to next entry */
943 ++act_tuple;
944
945 /* set pval to the next entry */
946
947 /*
948 * *pval != '\0' should not be needed, but is used as a safety
949 * guard
950 */
951 for (; *pval != '\0' && (string || (!array_delimiter(isarray, *pval) && !array_boundary(isarray, *pval))); ++pval)
952 if (*pval == '"')
953 string = string ? false : true;
954
955 if (array_delimiter(isarray, *pval))
956 ++pval;
957 }
958 }
959 } while (*pval != '\0' && !array_boundary(isarray, *pval));
960
961 return true;
962}
unsigned ecpg_hex_enc_len(unsigned srclen)
Definition: data.c:117
static bool garbage_left(enum ARRAY_TYPE isarray, char **scan_length, enum COMPAT_MODE compat)
Definition: data.c:46
unsigned ecpg_hex_dec_len(unsigned srclen)
Definition: data.c:123
static unsigned hex_decode(const char *src, unsigned len, char *dst)
Definition: data.c:150
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
Definition: data.c:20
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
Definition: data.c:33
static bool check_special_value(char *ptr, double *retval, char **endptr)
Definition: data.c:90
#define ECPG_CONVERT_BOOL
Definition: ecpgerrno.h:29
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
#define ECPG_FLOAT_FORMAT
Definition: ecpgerrno.h:24
#define ECPG_INT_FORMAT
Definition: ecpgerrno.h:22
#define ECPG_MISSING_INDICATOR
Definition: ecpgerrno.h:31
#define ECPG_INTERVAL_FORMAT
Definition: ecpgerrno.h:26
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
#define ECPG_DATA_NOT_ARRAY
Definition: ecpgerrno.h:33
#define ECPG_NUMERIC_FORMAT
Definition: ecpgerrno.h:25
#define ECPG_DATE_FORMAT
Definition: ecpgerrno.h:27
#define ECPG_TIMESTAMP_FORMAT
Definition: ecpgerrno.h:28
#define ECPG_SQLSTATE_NO_DATA
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER
#define ORACLE_MODE(X)
const char * ecpg_type_name(enum ECPGttype typ)
Definition: typename.c:17
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
#define ECPG_IS_ARRAY(X)
bool ecpg_internal_regression_mode
Definition: misc.c:29
@ ECPGt_float
Definition: ecpgtype.h:47
@ ECPGt_long_long
Definition: ecpgtype.h:45
@ ECPGt_decimal
Definition: ecpgtype.h:51
@ ECPGt_numeric
Definition: ecpgtype.h:49
@ 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_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_bool
Definition: ecpgtype.h:46
@ ECPGt_unsigned_long_long
Definition: ecpgtype.h:45
@ ECPGt_unsigned_int
Definition: ecpgtype.h:44
@ ECPGt_string
Definition: ecpgtype.h:65
int PQfformat(const PGresult *res, int field_num)
Definition: fe-exec.c:3725
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:108
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:292
return false
Definition: isn.c:135
#define PQgetvalue
Definition: libpq-be-fe.h:253
#define PQgetlength
Definition: libpq-be-fe.h:254
#define PQgetisnull
Definition: libpq-be-fe.h:255
long date
Definition: pgtypes_date.h:9
date PGTYPESdate_from_asc(char *str, char **endptr)
Definition: datetime.c:47
int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest)
Definition: interval.c:1082
interval * PGTYPESinterval_from_asc(char *str, char **endptr)
Definition: interval.c:1003
int PGTYPESnumeric_copy(numeric *src, numeric *dst)
Definition: numeric.c:1388
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:42
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
Definition: numeric.c:1547
void PGTYPESnumeric_free(numeric *var)
Definition: numeric.c:385
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
Definition: numeric.c:321
timestamp PGTYPEStimestamp_from_asc(char *str, char **endptr)
Definition: timestamp.c:202
int64 timestamp
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

References array_boundary(), array_delimiter(), check_special_value(), compat, ecpg_alloc(), ECPG_ARRAY_ARRAY, ECPG_COMPAT_PGSQL, ECPG_CONVERT_BOOL, ECPG_DATA_NOT_ARRAY, ECPG_DATE_FORMAT, ECPG_FLOAT_FORMAT, ecpg_hex_dec_len(), ecpg_hex_enc_len(), ECPG_INT_FORMAT, ecpg_internal_regression_mode, ECPG_INTERVAL_FORMAT, ECPG_IS_ARRAY, ecpg_log(), ECPG_MISSING_INDICATOR, ECPG_NOT_FOUND, ECPG_NUMERIC_FORMAT, ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_DATATYPE_MISMATCH, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_NO_DATA, ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, ECPG_TIMESTAMP_FORMAT, ecpg_type_name(), ECPG_UINT_FORMAT, ECPG_UNSUPPORTED, ECPGget_sqlca(), ECPGset_noind_null(), ECPGt_bool, ECPGt_bytea, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, 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, false, force_indicator, free, garbage_left(), hex_decode(), INFORMIX_MODE, ORACLE_MODE, PGTYPESdate_from_asc(), PGTYPESinterval_copy(), PGTYPESinterval_from_asc(), PGTYPESnumeric_copy(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PGTYPESnumeric_new(), PGTYPESnumeric_to_decimal(), PGTYPEStimestamp_from_asc(), PQfformat(), PQgetisnull, PQgetlength, PQgetvalue, sqlca, str, and type.

Referenced by ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), and ecpg_store_result().

◆ ecpg_hex_dec_len()

unsigned ecpg_hex_dec_len ( unsigned  srclen)

Definition at line 123 of file data.c.

124{
125 return srclen >> 1;
126}

Referenced by ecpg_get_data().

◆ ecpg_hex_enc_len()

unsigned ecpg_hex_enc_len ( unsigned  srclen)

Definition at line 117 of file data.c.

118{
119 return srclen << 1;
120}

Referenced by convert_bytea_to_string(), ecpg_get_data(), and print_param_value().

◆ ecpg_hex_encode()

unsigned ecpg_hex_encode ( const char *  src,
unsigned  len,
char *  dst 
)

Definition at line 180 of file data.c.

181{
182 static const char hextbl[] = "0123456789abcdef";
183 const char *end = src + len;
184
185 while (src < end)
186 {
187 *dst++ = hextbl[(*src >> 4) & 0xF];
188 *dst++ = hextbl[*src & 0xF];
189 src++;
190 }
191 return len * 2;
192}
static const char hextbl[]
Definition: pgp-info.c:87

References hextbl, and len.

Referenced by convert_bytea_to_string(), and print_param_value().

◆ ecpg_init()

bool ecpg_init ( const struct connection con,
const char *  connection_name,
const int  lineno 
)

Definition at line 73 of file misc.c.

74{
75 struct sqlca_t *sqlca = ECPGget_sqlca();
76
77 if (sqlca == NULL)
78 {
80 NULL);
81 return false;
82 }
83
85 if (con == NULL)
86 {
88 connection_name ? connection_name : ecpg_gettext("NULL"));
89 return false;
90 }
91
92 return true;
93}
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67

References ecpg_gettext, ecpg_init_sqlca(), ECPG_NO_CONN, ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPGget_sqlca(), and sqlca.

Referenced by ecpg_do_prologue(), ECPGdeallocate(), ECPGdisconnect(), ECPGprepare(), ECPGsetcommit(), ECPGsetconn(), ECPGstatus(), and ECPGtrans().

◆ ecpg_init_sqlca()

void ecpg_init_sqlca ( struct sqlca_t sqlca)

Definition at line 67 of file misc.c.

68{
69 memcpy(sqlca, &sqlca_init, sizeof(struct sqlca_t));
70}
static struct sqlca_t sqlca_init
Definition: misc.c:31

References sqlca, and sqlca_init.

Referenced by ecpg_init(), ECPGallocate_desc(), ECPGconnect(), ECPGdeallocate_desc(), ECPGdisconnect(), ECPGget_desc(), ECPGget_desc_header(), ECPGget_sqlca(), and ECPGset_var().

◆ ecpg_log()

◆ ecpg_prepared()

char * ecpg_prepared ( const char *  name,
struct connection con 
)

Definition at line 389 of file prepare.c.

390{
391 struct prepared_statement *this;
392
393 this = ecpg_find_prepared_statement(name, con, NULL);
394 return this ? this->stmt->command : NULL;
395}

References ecpg_find_prepared_statement(), name, and stmt.

Referenced by ecpg_do_prologue(), and ECPGprepared_statement().

◆ ecpg_process_output()

bool ecpg_process_output ( struct statement stmt,
bool  clear_result 
)

Definition at line 1669 of file execute.c.

1670{
1671 struct variable *var;
1672 bool status = false;
1673 char *cmdstat;
1674 PGnotify *notify;
1675 struct sqlca_t *sqlca = ECPGget_sqlca();
1676 int nfields,
1677 ntuples,
1678 act_field;
1679
1680 if (sqlca == NULL)
1681 {
1684 return false;
1685 }
1686
1687 var = stmt->outlist;
1688 switch (PQresultStatus(stmt->results))
1689 {
1690 case PGRES_TUPLES_OK:
1691 nfields = PQnfields(stmt->results);
1692 sqlca->sqlerrd[2] = ntuples = PQntuples(stmt->results);
1693
1694 ecpg_log("ecpg_process_output on line %d: correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
1695 status = true;
1696
1697 if (ntuples < 1)
1698 {
1699 if (ntuples)
1700 ecpg_log("ecpg_process_output on line %d: incorrect number of matches (%d)\n",
1701 stmt->lineno, ntuples);
1703 status = false;
1704 break;
1705 }
1706
1707 if (var != NULL && var->type == ECPGt_descriptor)
1708 {
1709 struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
1710
1711 if (desc == NULL)
1712 status = false;
1713 else
1714 {
1715 PQclear(desc->result);
1716 desc->result = stmt->results;
1717 clear_result = false;
1718 ecpg_log("ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
1719 stmt->lineno, PQntuples(stmt->results), (const char *) var->pointer);
1720 }
1721 var = var->next;
1722 }
1723 else if (var != NULL && var->type == ECPGt_sqlda)
1724 {
1725 if (INFORMIX_MODE(stmt->compat))
1726 {
1727 struct sqlda_compat **_sqlda = (struct sqlda_compat **) var->pointer;
1728 struct sqlda_compat *sqlda = *_sqlda;
1729 struct sqlda_compat *sqlda_new;
1730 int i;
1731
1732 /*
1733 * If we are passed in a previously existing sqlda (chain)
1734 * then free it.
1735 */
1736 while (sqlda)
1737 {
1738 sqlda_new = sqlda->desc_next;
1739 free(sqlda);
1740 sqlda = sqlda_new;
1741 }
1742 *_sqlda = sqlda = sqlda_new = NULL;
1743 for (i = ntuples - 1; i >= 0; i--)
1744 {
1745 /*
1746 * Build a new sqlda structure. Note that only
1747 * fetching 1 record is supported
1748 */
1749 sqlda_new = ecpg_build_compat_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1750
1751 if (!sqlda_new)
1752 {
1753 /* cleanup all SQLDAs we created up */
1754 while (sqlda)
1755 {
1756 sqlda_new = sqlda->desc_next;
1757 free(sqlda);
1758 sqlda = sqlda_new;
1759 }
1760 *_sqlda = NULL;
1761
1762 ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1763 status = false;
1764 break;
1765 }
1766 else
1767 {
1768 ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1769
1770 *_sqlda = sqlda_new;
1771
1772 ecpg_set_compat_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1773 ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1774 stmt->lineno, PQnfields(stmt->results));
1775
1776 sqlda_new->desc_next = sqlda;
1777 sqlda = sqlda_new;
1778 }
1779 }
1780 }
1781 else
1782 {
1783 struct sqlda_struct **_sqlda = (struct sqlda_struct **) var->pointer;
1784 struct sqlda_struct *sqlda = *_sqlda;
1785 struct sqlda_struct *sqlda_new;
1786 int i;
1787
1788 /*
1789 * If we are passed in a previously existing sqlda (chain)
1790 * then free it.
1791 */
1792 while (sqlda)
1793 {
1794 sqlda_new = sqlda->desc_next;
1795 free(sqlda);
1796 sqlda = sqlda_new;
1797 }
1798 *_sqlda = sqlda = sqlda_new = NULL;
1799 for (i = ntuples - 1; i >= 0; i--)
1800 {
1801 /*
1802 * Build a new sqlda structure. Note that only
1803 * fetching 1 record is supported
1804 */
1805 sqlda_new = ecpg_build_native_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1806
1807 if (!sqlda_new)
1808 {
1809 /* cleanup all SQLDAs we created up */
1810 while (sqlda)
1811 {
1812 sqlda_new = sqlda->desc_next;
1813 free(sqlda);
1814 sqlda = sqlda_new;
1815 }
1816 *_sqlda = NULL;
1817
1818 ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1819 status = false;
1820 break;
1821 }
1822 else
1823 {
1824 ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1825
1826 *_sqlda = sqlda_new;
1827
1828 ecpg_set_native_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1829 ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1830 stmt->lineno, PQnfields(stmt->results));
1831
1832 sqlda_new->desc_next = sqlda;
1833 sqlda = sqlda_new;
1834 }
1835 }
1836 }
1837
1838 var = var->next;
1839 }
1840 else
1841 for (act_field = 0; act_field < nfields && status; act_field++)
1842 {
1843 if (var != NULL)
1844 {
1845 status = ecpg_store_result(stmt->results, act_field, stmt, var);
1846 var = var->next;
1847 }
1848 else if (!INFORMIX_MODE(stmt->compat))
1849 {
1851 return false;
1852 }
1853 }
1854
1855 if (status && var != NULL)
1856 {
1858 status = false;
1859 }
1860
1861 break;
1862 case PGRES_COMMAND_OK:
1863 status = true;
1864 cmdstat = PQcmdStatus(stmt->results);
1865 sqlca->sqlerrd[1] = PQoidValue(stmt->results);
1866 sqlca->sqlerrd[2] = atol(PQcmdTuples(stmt->results));
1867 ecpg_log("ecpg_process_output on line %d: OK: %s\n", stmt->lineno, cmdstat);
1868 if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
1869 !sqlca->sqlerrd[2] &&
1870 (strncmp(cmdstat, "UPDATE", 6) == 0
1871 || strncmp(cmdstat, "INSERT", 6) == 0
1872 || strncmp(cmdstat, "DELETE", 6) == 0))
1874 break;
1875 case PGRES_COPY_OUT:
1876 {
1877 char *buffer;
1878 int res;
1879
1880 ecpg_log("ecpg_process_output on line %d: COPY OUT data transfer in progress\n", stmt->lineno);
1881 while ((res = PQgetCopyData(stmt->connection->connection,
1882 &buffer, 0)) > 0)
1883 {
1884 printf("%s", buffer);
1885 PQfreemem(buffer);
1886 }
1887 if (res == -1)
1888 {
1889 /* COPY done */
1890 PQclear(stmt->results);
1891 stmt->results = PQgetResult(stmt->connection->connection);
1892 if (PQresultStatus(stmt->results) == PGRES_COMMAND_OK)
1893 ecpg_log("ecpg_process_output on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
1894 else
1895 ecpg_log("ecpg_process_output on line %d: got error after PGRES_COPY_OUT: %s", stmt->lineno, PQresultErrorMessage(stmt->results));
1896 }
1897 break;
1898 }
1899 default:
1900
1901 /*
1902 * execution should never reach this code because it is already
1903 * handled in ecpg_check_PQresult()
1904 */
1905 ecpg_log("ecpg_process_output on line %d: unknown execution status type\n",
1906 stmt->lineno);
1907 ecpg_raise_backend(stmt->lineno, stmt->results, stmt->connection->connection, stmt->compat);
1908 status = false;
1909 break;
1910 }
1911
1912 if (clear_result)
1913 {
1914 PQclear(stmt->results);
1915 stmt->results = NULL;
1916 }
1917
1918 /* check for asynchronous returns */
1919 PQconsumeInput(stmt->connection->connection);
1920 while ((notify = PQnotifies(stmt->connection->connection)) != NULL)
1921 {
1922 ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
1923 stmt->lineno, notify->relname, notify->be_pid);
1924 PQfreemem(notify);
1925 PQconsumeInput(stmt->connection->connection);
1926 }
1927
1928 return status;
1929}
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
void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:255
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS
void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:444
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:303
void PQfreemem(void *ptr)
Definition: fe-exec.c:4049
int PQconsumeInput(PGconn *conn)
Definition: fe-exec.c:2001
Oid PQoidValue(const PGresult *res)
Definition: fe-exec.c:3810
PGnotify * PQnotifies(PGconn *conn)
Definition: fe-exec.c:2684
int PQgetCopyData(PGconn *conn, char **buffer, int async)
Definition: fe-exec.c:2833
#define PQgetResult
Definition: libpq-be-fe.h:246
#define PQcmdStatus
Definition: libpq-be-fe.h:250
#define PQcmdTuples
Definition: libpq-be-fe.h:257
#define PQntuples
Definition: libpq-be-fe.h:251
while(p+4<=pend)
#define printf(...)
Definition: port.h:266
PGresult * result
int be_pid
Definition: libpq-fe.h:231
char * relname
Definition: libpq-fe.h:230

References pgNotify::be_pid, ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), ECPG_COMPAT_INFORMIX_SE, ecpg_find_desc(), ecpg_log(), ECPG_NOT_FOUND, ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_raise_backend(), ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_NO_DATA, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, ecpg_store_result(), ECPG_TOO_FEW_ARGUMENTS, ECPG_TOO_MANY_ARGUMENTS, ECPGget_sqlca(), ECPGt_descriptor, ECPGt_sqlda, free, i, INFORMIX_MODE, variable::next, PGRES_COMMAND_OK, PGRES_COPY_OUT, PGRES_TUPLES_OK, variable::pointer, PQclear, PQcmdStatus, PQcmdTuples, PQconsumeInput(), PQfreemem(), PQgetCopyData(), PQgetResult, PQnfields, PQnotifies(), PQntuples, PQoidValue(), PQresultErrorMessage, PQresultStatus, printf, pgNotify::relname, descriptor::result, sqlca, stmt, variable::type, and while().

Referenced by ecpg_do().

◆ 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

◆ ecpg_raise()

void ecpg_raise ( int  line,
int  code,
const char *  sqlstate,
const char *  str 
)

Definition at line 13 of file error.c.

14{
15 struct sqlca_t *sqlca = ECPGget_sqlca();
16
17 if (sqlca == NULL)
18 {
19 ecpg_log("out of memory");
21 return;
22 }
23
24 sqlca->sqlcode = code;
25 strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
26
27 switch (code)
28 {
29 case ECPG_NOT_FOUND:
30 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
31 /*------
32 translator: this string will be truncated at 149 characters expanded. */
33 ecpg_gettext("no data found on line %d"), line);
34 break;
35
37 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
38 /*------
39 translator: this string will be truncated at 149 characters expanded. */
40 ecpg_gettext("out of memory on line %d"), line);
41 break;
42
44 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
45 /*------
46 translator: this string will be truncated at 149 characters expanded. */
47 ecpg_gettext("unsupported type \"%s\" on line %d"), str, line);
48 break;
49
51 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
52 /*------
53 translator: this string will be truncated at 149 characters expanded. */
54 ecpg_gettext("too many arguments on line %d"), line);
55 break;
56
58 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
59 /*------
60 translator: this string will be truncated at 149 characters expanded. */
61 ecpg_gettext("too few arguments on line %d"), line);
62 break;
63
64 case ECPG_INT_FORMAT:
65 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
66 /*------
67 translator: this string will be truncated at 149 characters expanded. */
68 ecpg_gettext("invalid input syntax for type int: \"%s\", on line %d"), str, line);
69 break;
70
72 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
73 /*------
74 translator: this string will be truncated at 149 characters expanded. */
75 ecpg_gettext("invalid input syntax for type unsigned int: \"%s\", on line %d"), str, line);
76 break;
77
79 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
80 /*------
81 translator: this string will be truncated at 149 characters expanded. */
82 ecpg_gettext("invalid input syntax for floating-point type: \"%s\", on line %d"), str, line);
83 break;
84
86 if (str)
87 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
88 /*------
89 translator: this string will be truncated at 149 characters expanded. */
90 ecpg_gettext("invalid syntax for type boolean: \"%s\", on line %d"), str, line);
91 else
92 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
93 /*------
94 translator: this string will be truncated at 149 characters expanded. */
95 ecpg_gettext("could not convert boolean value: size mismatch, on line %d"), line);
96 break;
97
98 case ECPG_EMPTY:
99 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
100 /*------
101 translator: this string will be truncated at 149 characters expanded. */
102 ecpg_gettext("empty query on line %d"), line);
103 break;
104
106 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
107 /*------
108 translator: this string will be truncated at 149 characters expanded. */
109 ecpg_gettext("null value without indicator on line %d"), line);
110 break;
111
112 case ECPG_NO_ARRAY:
113 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
114 /*------
115 translator: this string will be truncated at 149 characters expanded. */
116 ecpg_gettext("variable does not have an array type on line %d"), line);
117 break;
118
120 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
121 /*------
122 translator: this string will be truncated at 149 characters expanded. */
123 ecpg_gettext("data read from server is not an array on line %d"), line);
124 break;
125
127 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
128 /*------
129 translator: this string will be truncated at 149 characters expanded. */
130 ecpg_gettext("inserting an array of variables is not supported on line %d"), line);
131 break;
132
133 case ECPG_NO_CONN:
134 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
135 /*------
136 translator: this string will be truncated at 149 characters expanded. */
137 ecpg_gettext("connection \"%s\" does not exist on line %d"), str, line);
138 break;
139
140 case ECPG_NOT_CONN:
141 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
142 /*------
143 translator: this string will be truncated at 149 characters expanded. */
144 ecpg_gettext("not connected to connection \"%s\" on line %d"), str, line);
145 break;
146
148 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
149 /*------
150 translator: this string will be truncated at 149 characters expanded. */
151 ecpg_gettext("invalid statement name \"%s\" on line %d"), str, line);
152 break;
153
155 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
156 /*------
157 translator: this string will be truncated at 149 characters expanded. */
158 ecpg_gettext("descriptor \"%s\" not found on line %d"), str, line);
159 break;
160
162 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
163 /*------
164 translator: this string will be truncated at 149 characters expanded. */
165 ecpg_gettext("descriptor index out of range on line %d"), line);
166 break;
167
169 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
170 /*------
171 translator: this string will be truncated at 149 characters expanded. */
172 ecpg_gettext("unrecognized descriptor item \"%s\" on line %d"), str, line);
173 break;
174
176 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
177 /*------
178 translator: this string will be truncated at 149 characters expanded. */
179 ecpg_gettext("variable does not have a numeric type on line %d"), line);
180 break;
181
183 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
184 /*------
185 translator: this string will be truncated at 149 characters expanded. */
186 ecpg_gettext("variable does not have a character type on line %d"), line);
187 break;
188
189 case ECPG_TRANS:
190 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
191 /*------
192 translator: this string will be truncated at 149 characters expanded. */
193 ecpg_gettext("error in transaction processing on line %d"), line);
194 break;
195
196 case ECPG_CONNECT:
197 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
198 /*------
199 translator: this string will be truncated at 149 characters expanded. */
200 ecpg_gettext("could not connect to database \"%s\" on line %d"), str, line);
201 break;
202
203 default:
204 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
205 /*------
206 translator: this string will be truncated at 149 characters expanded. */
207 ecpg_gettext("SQL error %d on line %d"), code, line);
208 break;
209 }
210
211 sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
212 ecpg_log("raising sqlcode %d on line %d: %s\n", code, line, sqlca->sqlerrm.sqlerrmc);
213
214 /* free all memory we have allocated for the user */
216}
#define ECPG_ARRAY_INSERT
Definition: ecpgerrno.h:34
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
#define ECPG_INVALID_DESCRIPTOR_INDEX
Definition: ecpgerrno.h:43
#define ECPG_VAR_NOT_NUMERIC
Definition: ecpgerrno.h:45
#define ECPG_VAR_NOT_CHAR
Definition: ecpgerrno.h:46
#define ECPG_TRANS
Definition: ecpgerrno.h:50
#define ECPG_NO_ARRAY
Definition: ecpgerrno.h:32
#define ECPG_CONNECT
Definition: ecpgerrno.h:51
void ECPGfree_auto_mem(void)
Definition: memory.c:140
char sqlstate[5]
Definition: sqlca.h:53

References ECPG_ARRAY_INSERT, ECPG_CONNECT, ECPG_CONVERT_BOOL, ECPG_DATA_NOT_ARRAY, ECPG_EMPTY, ECPG_FLOAT_FORMAT, ecpg_gettext, ECPG_INT_FORMAT, ECPG_INVALID_DESCRIPTOR_INDEX, ECPG_INVALID_STMT, ecpg_log(), ECPG_MISSING_INDICATOR, ECPG_NO_ARRAY, ECPG_NO_CONN, ECPG_NOT_CONN, ECPG_NOT_FOUND, ECPG_OUT_OF_MEMORY, ECPG_TOO_FEW_ARGUMENTS, ECPG_TOO_MANY_ARGUMENTS, ECPG_TRANS, ECPG_UINT_FORMAT, ECPG_UNKNOWN_DESCRIPTOR, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_UNSUPPORTED, ECPG_VAR_NOT_CHAR, ECPG_VAR_NOT_NUMERIC, ECPGfree_auto_mem(), ECPGget_sqlca(), snprintf, sqlca, sqlca_t::sqlstate, and str.

Referenced by deallocate_one(), ecpg_alloc(), ecpg_build_params(), ecpg_check_PQresult(), ecpg_do_prologue(), ecpg_find_desc(), ecpg_get_data(), ecpg_init(), ecpg_process_output(), ecpg_realloc(), ecpg_store_input(), ecpg_store_result(), ecpg_strdup(), ECPGallocate_desc(), ECPGconnect(), ECPGdeallocate(), ECPGdeallocate_desc(), ECPGdescribe(), ECPGdisconnect(), ECPGget_desc(), ECPGget_desc_header(), ECPGset_desc(), ECPGset_var(), ECPGstatus(), get_char_item(), get_int_item(), and set_int_item().

◆ ecpg_raise_backend()

void ecpg_raise_backend ( int  line,
PGresult result,
PGconn conn,
int  compat 
)

Definition at line 219 of file error.c.

220{
221 struct sqlca_t *sqlca = ECPGget_sqlca();
222 char *sqlstate;
223 char *message;
224
225 if (sqlca == NULL)
226 {
227 ecpg_log("out of memory");
229 return;
230 }
231
232 /*
233 * PQresultErrorField will return NULL if "result" is NULL, or if there is
234 * no such field, which will happen for libpq-generated errors. Fall back
235 * to PQerrorMessage in such cases.
236 */
238 if (sqlstate == NULL)
241 if (message == NULL)
242 message = PQerrorMessage(conn);
243
245 {
246 /*
247 * we might get here if the connection breaks down, so let's check for
248 * this instead of giving just the generic internal error
249 */
251 {
252 sqlstate = "57P02";
253 message = ecpg_gettext("the connection to the server was lost");
254 }
255 }
256
257 /* copy error message */
258 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "%s on line %d", message, line);
259 sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
260
261 /* copy SQLSTATE */
262 strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
263
264 /* assign SQLCODE for backward compatibility */
265 if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)
267 else if (strncmp(sqlca->sqlstate, "21000", sizeof(sqlca->sqlstate)) == 0)
269 else
270 sqlca->sqlcode = ECPG_PGSQL;
271
272 ecpg_log("raising sqlstate %.*s (sqlcode %ld): %s\n",
273 (int) sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, sqlca->sqlerrm.sqlerrmc);
274
275 /* free all memory we have allocated for the user */
277}
#define ECPG_PGSQL
Definition: ecpgerrno.h:49
#define ECPG_SUBSELECT_NOT_ONE
Definition: ecpgerrno.h:53
#define ECPG_INFORMIX_SUBSELECT_NOT_ONE
Definition: ecpgerrno.h:58
#define ECPG_DUPLICATE_KEY
Definition: ecpgerrno.h:52
#define ECPG_INFORMIX_DUPLICATE_KEY
Definition: ecpgerrno.h:57
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:7641
#define PQresultErrorField
Definition: libpq-be-fe.h:249
@ CONNECTION_BAD
Definition: libpq-fe.h:85
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
PGconn * conn
Definition: streamutil.c:52

References compat, conn, CONNECTION_BAD, ECPG_DUPLICATE_KEY, ecpg_gettext, ECPG_INFORMIX_DUPLICATE_KEY, ECPG_INFORMIX_SUBSELECT_NOT_ONE, ecpg_log(), ECPG_PGSQL, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPG_SUBSELECT_NOT_ONE, ECPGfree_auto_mem(), ECPGget_sqlca(), INFORMIX_MODE, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SQLSTATE, PQerrorMessage(), PQresultErrorField, PQstatus(), snprintf, sqlca, and sqlca_t::sqlstate.

Referenced by ecpg_check_PQresult(), and ecpg_process_output().

◆ ecpg_realloc()

char * ecpg_realloc ( void *  ptr,
long  size,
int  lineno 
)

Definition at line 33 of file memory.c.

34{
35 char *new = (char *) realloc(ptr, size);
36
37 if (!new)
38 {
40 return NULL;
41 }
42
43 return new;
44}
#define realloc(a, b)
Definition: header.h:60

References ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, and realloc.

Referenced by ecpg_build_params(), and ecpg_store_input().

◆ ecpg_register_prepared_stmt()

bool ecpg_register_prepared_stmt ( struct statement stmt)

Definition at line 59 of file prepare.c.

60{
61 struct statement *prep_stmt;
62 struct prepared_statement *this;
63 struct connection *con = stmt->connection;
64 struct prepared_statement *prev = NULL;
65 int lineno = stmt->lineno;
66
67 /* check if we already have prepared this statement */
68 this = ecpg_find_prepared_statement(stmt->name, con, &prev);
69 if (this && !deallocate_one(lineno, ECPG_COMPAT_PGSQL, con, prev, this))
70 return false;
71
72 /* allocate new statement */
73 this = (struct prepared_statement *) ecpg_alloc(sizeof(struct prepared_statement), lineno);
74 if (!this)
75 return false;
76
77 prep_stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
78 if (!prep_stmt)
79 {
80 ecpg_free(this);
81 return false;
82 }
83 memset(prep_stmt, 0, sizeof(struct statement));
84
85 /* create statement */
86 prep_stmt->lineno = lineno;
87 prep_stmt->connection = con;
88 prep_stmt->command = ecpg_strdup(stmt->command, lineno, NULL);
89 if (!prep_stmt->command)
90 {
91 ecpg_free(prep_stmt);
92 ecpg_free(this);
93 return false;
94 }
95 prep_stmt->inlist = prep_stmt->outlist = NULL;
96 this->name = ecpg_strdup(stmt->name, lineno, NULL);
97 if (!this->name)
98 {
99 ecpg_free(prep_stmt->command);
100 ecpg_free(prep_stmt);
101 ecpg_free(this);
102 return false;
103 }
104 this->stmt = prep_stmt;
105 this->prepared = true;
106
107 if (con->prep_stmts == NULL)
108 this->next = NULL;
109 else
110 this->next = con->prep_stmts;
111
112 con->prep_stmts = this;
113 return true;
114}
static int32 next
Definition: blutils.c:224
struct variable * inlist
struct variable * outlist
struct connection * connection
char * name

References statement::command, statement::connection, deallocate_one(), ecpg_alloc(), ECPG_COMPAT_PGSQL, ecpg_find_prepared_statement(), ecpg_free(), ecpg_strdup(), statement::inlist, statement::lineno, name, statement::name, next, statement::outlist, connection::prep_stmts, and stmt.

Referenced by ecpg_execute().

◆ ecpg_set_compat_sqlda()

void ecpg_set_compat_sqlda ( int  lineno,
struct sqlda_compat **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 255 of file sqlda.c.

256{
257 struct sqlda_compat *sqlda = (*_sqlda);
258 int i;
259 long offset,
260 next_offset;
261
262 if (row < 0)
263 return;
264
265 /* Offset for the first field value */
266 offset = sqlda_compat_empty_size(res);
267
268 /*
269 * Set sqlvar[i]->sqldata pointers and convert values to correct format
270 */
271 for (i = 0; i < sqlda->sqld; i++)
272 {
273 int isnull;
274 int datalen;
275 bool set_data = true;
276
277 switch (sqlda->sqlvar[i].sqltype)
278 {
279 case ECPGt_short:
281 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
282 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
283 sqlda->sqlvar[i].sqllen = sizeof(short);
284 break;
285 case ECPGt_int:
287 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
288 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
289 sqlda->sqlvar[i].sqllen = sizeof(int);
290 break;
291 case ECPGt_long:
293 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
294 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
295 sqlda->sqlvar[i].sqllen = sizeof(long);
296 break;
297 case ECPGt_long_long:
299 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
300 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
301 sqlda->sqlvar[i].sqllen = sizeof(long long);
302 break;
303 case ECPGt_bool:
304 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
305 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
306 sqlda->sqlvar[i].sqllen = sizeof(bool);
307 break;
308 case ECPGt_float:
309 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
310 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
311 sqlda->sqlvar[i].sqllen = sizeof(float);
312 break;
313 case ECPGt_double:
314 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
315 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
316 sqlda->sqlvar[i].sqllen = sizeof(double);
317 break;
318 case ECPGt_decimal:
319 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
320 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
321 sqlda->sqlvar[i].sqllen = sizeof(decimal);
322 break;
323 case ECPGt_numeric:
324 {
325 numeric *num;
326 char *val;
327
328 set_data = false;
329
330 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
331 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
332 sqlda->sqlvar[i].sqllen = sizeof(numeric);
333
334 if (PQgetisnull(res, row, i))
335 {
337 break;
338 }
339
340 val = PQgetvalue(res, row, i);
341 num = PGTYPESnumeric_from_asc(val, NULL);
342 if (!num)
343 {
345 break;
346 }
347
348 memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
349
350 if (num->buf)
351 {
352 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
353 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
354
355 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
356 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
357 }
358
360
361 break;
362 }
363 case ECPGt_date:
364 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
365 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
366 sqlda->sqlvar[i].sqllen = sizeof(date);
367 break;
368 case ECPGt_timestamp:
369 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
370 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
371 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
372 break;
373 case ECPGt_interval:
374 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
375 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
376 sqlda->sqlvar[i].sqllen = sizeof(interval);
377 break;
378 case ECPGt_char:
380 case ECPGt_string:
381 default:
382 datalen = strlen(PQgetvalue(res, row, i)) + 1;
383 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
384 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
385 sqlda->sqlvar[i].sqllen = datalen;
386 if (datalen > 32768)
387 sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
388 break;
389 }
390
391 isnull = PQgetisnull(res, row, i);
392 ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
393 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
394 sqlda->sqlvar[i].sqlitype = ECPGt_short;
395 sqlda->sqlvar[i].sqlilen = sizeof(short);
396 if (!isnull)
397 {
398 if (set_data)
399 ecpg_get_data(res, row, i, lineno,
401 sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
402 ECPG_ARRAY_NONE, compat, false);
403 }
404 else
406
407 offset = next_offset;
408 }
409}
int16 NumericDigit
Definition: numeric.c:103
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:1229
int64_t int64
Definition: c.h:538
bool ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, enum ECPGttype type, enum ECPGttype ind_type, char *var, char *ind, long varcharsize, long offset, long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator)
Definition: data.c:195
long val
Definition: informix.c:689
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:33
static long sqlda_compat_empty_size(const PGresult *res)
Definition: sqlda.c:45
static int16 value_is_null
Definition: sqlda.c:251
static int16 value_is_not_null
Definition: sqlda.c:252
NumericDigit * digits
NumericDigit * buf
char * sqlilongdata
Definition: sqlda-compat.h:32

References numeric::buf, compat, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, numeric(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull, PQgetvalue, sqlda_compat::sqld, sqlda_compat_empty_size(), sqlvar_compat::sqldata, sqlvar_compat::sqlilen, sqlvar_compat::sqlilongdata, sqlvar_compat::sqlind, sqlvar_compat::sqlitype, sqlvar_compat::sqllen, sqlvar_compat::sqltype, sqlda_compat::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_process_output().

◆ ecpg_set_native_sqlda()

void ecpg_set_native_sqlda ( int  lineno,
struct sqlda_struct **  _sqlda,
const PGresult res,
int  row,
enum COMPAT_MODE  compat 
)

Definition at line 444 of file sqlda.c.

445{
446 struct sqlda_struct *sqlda = (*_sqlda);
447 int i;
448 long offset,
449 next_offset;
450
451 if (row < 0)
452 return;
453
454 /* Offset for the first field value */
455 offset = sqlda_native_empty_size(res);
456
457 /*
458 * Set sqlvar[i]->sqldata pointers and convert values to correct format
459 */
460 for (i = 0; i < sqlda->sqld; i++)
461 {
462 int isnull;
463 int datalen;
464 bool set_data = true;
465
466 switch (sqlda->sqlvar[i].sqltype)
467 {
468 case ECPGt_short:
470 ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
471 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
472 sqlda->sqlvar[i].sqllen = sizeof(short);
473 break;
474 case ECPGt_int:
476 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
477 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
478 sqlda->sqlvar[i].sqllen = sizeof(int);
479 break;
480 case ECPGt_long:
482 ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
483 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
484 sqlda->sqlvar[i].sqllen = sizeof(long);
485 break;
486 case ECPGt_long_long:
488 ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
489 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
490 sqlda->sqlvar[i].sqllen = sizeof(long long);
491 break;
492 case ECPGt_bool:
493 ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
494 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
495 sqlda->sqlvar[i].sqllen = sizeof(bool);
496 break;
497 case ECPGt_float:
498 ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
499 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
500 sqlda->sqlvar[i].sqllen = sizeof(float);
501 break;
502 case ECPGt_double:
503 ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
504 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
505 sqlda->sqlvar[i].sqllen = sizeof(double);
506 break;
507 case ECPGt_decimal:
508 ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
509 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
510 sqlda->sqlvar[i].sqllen = sizeof(decimal);
511 break;
512 case ECPGt_numeric:
513 {
514 numeric *num;
515 char *val;
516
517 set_data = false;
518
519 ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
520 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
521 sqlda->sqlvar[i].sqllen = sizeof(numeric);
522
523 if (PQgetisnull(res, row, i))
524 {
526 break;
527 }
528
529 val = PQgetvalue(res, row, i);
530 num = PGTYPESnumeric_from_asc(val, NULL);
531 if (!num)
532 {
534 break;
535 }
536
537 memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
538
539 if (num->buf)
540 {
541 ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->digits - num->buf + num->ndigits, &offset, &next_offset);
542 memcpy((char *) sqlda + offset, num->buf, num->digits - num->buf + num->ndigits);
543
544 ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
545 ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
546 }
547
549
550 break;
551 }
552 case ECPGt_date:
553 ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
554 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
555 sqlda->sqlvar[i].sqllen = sizeof(date);
556 break;
557 case ECPGt_timestamp:
558 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
559 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
560 sqlda->sqlvar[i].sqllen = sizeof(timestamp);
561 break;
562 case ECPGt_interval:
563 ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
564 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
565 sqlda->sqlvar[i].sqllen = sizeof(interval);
566 break;
567 case ECPGt_char:
569 case ECPGt_string:
570 default:
571 datalen = strlen(PQgetvalue(res, row, i)) + 1;
572 ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
573 sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
574 sqlda->sqlvar[i].sqllen = datalen;
575 break;
576 }
577
578 isnull = PQgetisnull(res, row, i);
579 ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
580 sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
581 if (!isnull)
582 {
583 if (set_data)
584 ecpg_get_data(res, row, i, lineno,
586 sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
587 ECPG_ARRAY_NONE, compat, false);
588 }
589
590 offset = next_offset;
591 }
592}
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:171

References numeric::buf, compat, numeric::digits, ECPG_ARRAY_NONE, ecpg_get_data(), ecpg_log(), ecpg_sqlda_align_add_size(), ECPGset_noind_null(), ECPGt_bool, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, i, numeric::ndigits, numeric(), PGTYPESnumeric_free(), PGTYPESnumeric_from_asc(), PQgetisnull, PQgetvalue, sqlda_struct::sqld, sqlda_native_empty_size(), sqlvar_struct::sqldata, sqlvar_struct::sqlind, sqlvar_struct::sqllen, sqlvar_struct::sqltype, sqlda_struct::sqlvar, val, value_is_not_null, and value_is_null.

Referenced by ecpg_process_output().

◆ ecpg_store_input()

bool ecpg_store_input ( const int  lineno,
const bool  force_indicator,
const struct variable var,
char **  tobeinserted_p,
bool  quote 
)

Definition at line 506 of file execute.c.

508{
509 char *mallocedval = NULL;
510 char *newcopy = NULL;
511
512 /*
513 * arrays are not possible unless the column is an array, too FIXME: we do
514 * not know if the column is an array here array input to singleton column
515 * will result in a runtime error
516 */
517
518 /*
519 * Some special treatment is needed for records since we want their
520 * contents to arrive in a comma-separated list on insert (I think).
521 */
522
523 *tobeinserted_p = "";
524
525 /* check for null value and set input buffer accordingly */
526 switch (var->ind_type)
527 {
528 case ECPGt_short:
530 if (*(short *) var->ind_value < 0)
531 *tobeinserted_p = NULL;
532 break;
533 case ECPGt_int:
535 if (*(int *) var->ind_value < 0)
536 *tobeinserted_p = NULL;
537 break;
538 case ECPGt_long:
540 if (*(long *) var->ind_value < 0L)
541 *tobeinserted_p = NULL;
542 break;
543 case ECPGt_long_long:
545 if (*(long long int *) var->ind_value < (long long) 0)
546 *tobeinserted_p = NULL;
547 break;
549 if (force_indicator == false)
550 {
551 if (ECPGis_noind_null(var->type, var->value))
552 *tobeinserted_p = NULL;
553 }
554 break;
555 default:
556 break;
557 }
558 if (*tobeinserted_p != NULL)
559 {
560 int asize = var->arrsize ? var->arrsize : 1;
561
562 switch (var->type)
563 {
564 int element;
565
566 case ECPGt_short:
567 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
568 return false;
569
570 if (asize > 1)
571 {
572 strcpy(mallocedval, "{");
573
574 for (element = 0; element < asize; element++)
575 sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
576
577 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
578 }
579 else
580 sprintf(mallocedval, "%hd", *((short *) var->value));
581
582 *tobeinserted_p = mallocedval;
583 break;
584
585 case ECPGt_int:
586 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
587 return false;
588
589 if (asize > 1)
590 {
591 strcpy(mallocedval, "{");
592
593 for (element = 0; element < asize; element++)
594 sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
595
596 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
597 }
598 else
599 sprintf(mallocedval, "%d", *((int *) var->value));
600
601 *tobeinserted_p = mallocedval;
602 break;
603
605 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
606 return false;
607
608 if (asize > 1)
609 {
610 strcpy(mallocedval, "{");
611
612 for (element = 0; element < asize; element++)
613 sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
614
615 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
616 }
617 else
618 sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
619
620 *tobeinserted_p = mallocedval;
621 break;
622
624 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
625 return false;
626
627 if (asize > 1)
628 {
629 strcpy(mallocedval, "{");
630
631 for (element = 0; element < asize; element++)
632 sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
633
634 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
635 }
636 else
637 sprintf(mallocedval, "%u", *((unsigned int *) var->value));
638
639 *tobeinserted_p = mallocedval;
640 break;
641
642 case ECPGt_long:
643 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
644 return false;
645
646 if (asize > 1)
647 {
648 strcpy(mallocedval, "{");
649
650 for (element = 0; element < asize; element++)
651 sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
652
653 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
654 }
655 else
656 sprintf(mallocedval, "%ld", *((long *) var->value));
657
658 *tobeinserted_p = mallocedval;
659 break;
660
662 if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
663 return false;
664
665 if (asize > 1)
666 {
667 strcpy(mallocedval, "{");
668
669 for (element = 0; element < asize; element++)
670 sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
671
672 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
673 }
674 else
675 sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
676
677 *tobeinserted_p = mallocedval;
678 break;
679
680 case ECPGt_long_long:
681 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
682 return false;
683
684 if (asize > 1)
685 {
686 strcpy(mallocedval, "{");
687
688 for (element = 0; element < asize; element++)
689 sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long int *) var->value)[element]);
690
691 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
692 }
693 else
694 sprintf(mallocedval, "%lld", *((long long int *) var->value));
695
696 *tobeinserted_p = mallocedval;
697 break;
698
700 if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
701 return false;
702
703 if (asize > 1)
704 {
705 strcpy(mallocedval, "{");
706
707 for (element = 0; element < asize; element++)
708 sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long int *) var->value)[element]);
709
710 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
711 }
712 else
713 sprintf(mallocedval, "%llu", *((unsigned long long int *) var->value));
714
715 *tobeinserted_p = mallocedval;
716 break;
717
718 case ECPGt_float:
719 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
720 return false;
721
722 if (asize > 1)
723 {
724 strcpy(mallocedval, "{");
725
726 for (element = 0; element < asize; element++)
727 sprintf_float_value(mallocedval + strlen(mallocedval), ((float *) var->value)[element], ",");
728
729 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
730 }
731 else
732 sprintf_float_value(mallocedval, *((float *) var->value), "");
733
734 *tobeinserted_p = mallocedval;
735 break;
736
737 case ECPGt_double:
738 if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
739 return false;
740
741 if (asize > 1)
742 {
743 strcpy(mallocedval, "{");
744
745 for (element = 0; element < asize; element++)
746 sprintf_double_value(mallocedval + strlen(mallocedval), ((double *) var->value)[element], ",");
747
748 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
749 }
750 else
751 sprintf_double_value(mallocedval, *((double *) var->value), "");
752
753 *tobeinserted_p = mallocedval;
754 break;
755
756 case ECPGt_bool:
757 if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("{}"), lineno)))
758 return false;
759
760 if (var->arrsize > 1)
761 {
762 strcpy(mallocedval, "{");
763
764 for (element = 0; element < asize; element++)
765 sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f');
766
767 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
768 }
769 else
770 {
771 if (var->offset == sizeof(char))
772 sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
773 else if (var->offset == sizeof(int))
774 sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
775 else
777 }
778
779 *tobeinserted_p = mallocedval;
780 break;
781
782 case ECPGt_char:
784 case ECPGt_string:
785 {
786 /* set slen to string length if type is char * */
787 int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : (unsigned int) var->varcharsize;
788
789 if (!(newcopy = ecpg_alloc(slen + 1, lineno)))
790 return false;
791
792 strncpy(newcopy, (char *) var->value, slen);
793 newcopy[slen] = '\0';
794
795 mallocedval = quote_postgres(newcopy, quote, lineno);
796 if (!mallocedval)
797 {
798 ecpg_free(newcopy);
799 return false;
800 }
801
802 *tobeinserted_p = mallocedval;
803 }
804 break;
805 case ECPGt_const:
807 {
808 int slen = strlen((char *) var->value);
809
810 if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
811 return false;
812
813 strncpy(mallocedval, (char *) var->value, slen);
814 mallocedval[slen] = '\0';
815
816 *tobeinserted_p = mallocedval;
817 }
818 break;
819
820 case ECPGt_bytea:
821 {
823 (struct ECPGgeneric_bytea *) (var->value);
824
825 if (!(mallocedval = ecpg_alloc(variable->len, lineno)))
826 return false;
827
828 memcpy(mallocedval, variable->arr, variable->len);
829 *tobeinserted_p = mallocedval;
830 }
831 break;
832
833 case ECPGt_varchar:
834 {
836 (struct ECPGgeneric_varchar *) (var->value);
837
838 if (!(newcopy = ecpg_alloc(variable->len + 1, lineno)))
839 return false;
840
841 strncpy(newcopy, variable->arr, variable->len);
842 newcopy[variable->len] = '\0';
843
844 mallocedval = quote_postgres(newcopy, quote, lineno);
845 if (!mallocedval)
846 {
847 ecpg_free(newcopy);
848 return false;
849 }
850
851 *tobeinserted_p = mallocedval;
852 }
853 break;
854
855 case ECPGt_decimal:
856 case ECPGt_numeric:
857 {
858 char *str = NULL;
859 int slen;
860 numeric *nval;
861
862 if (var->arrsize > 1)
863 mallocedval = ecpg_strdup("{", lineno, NULL);
864 else
865 mallocedval = ecpg_strdup("", lineno, NULL);
866
867 if (!mallocedval)
868 return false;
869
870 for (element = 0; element < asize; element++)
871 {
872 int result;
873
874 nval = PGTYPESnumeric_new();
875 if (!nval)
876 {
877 ecpg_free(mallocedval);
878 return false;
879 }
880
881 if (var->type == ECPGt_numeric)
882 result = PGTYPESnumeric_copy(&(((numeric *) (var->value))[element]), nval);
883 else
884 result = PGTYPESnumeric_from_decimal(&(((decimal *) (var->value))[element]), nval);
885
886 if (result != 0)
887 {
889 ecpg_free(mallocedval);
890 return false;
891 }
892
893 str = PGTYPESnumeric_to_asc(nval, nval->dscale);
894 slen = strlen(str);
896
897 if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
898 {
899 ecpg_free(mallocedval);
900 ecpg_free(str);
901 return false;
902 }
903 mallocedval = newcopy;
904
905 /* also copy trailing '\0' */
906 memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
907 if (var->arrsize > 1)
908 strcpy(mallocedval + strlen(mallocedval), ",");
909
910 ecpg_free(str);
911 }
912
913 if (var->arrsize > 1)
914 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
915
916 *tobeinserted_p = mallocedval;
917 }
918 break;
919
920 case ECPGt_interval:
921 {
922 char *str = NULL;
923 int slen;
924
925 if (var->arrsize > 1)
926 mallocedval = ecpg_strdup("{", lineno, NULL);
927 else
928 mallocedval = ecpg_strdup("", lineno, NULL);
929
930 if (!mallocedval)
931 return false;
932
933 for (element = 0; element < asize; element++)
934 {
935 str = quote_postgres(PGTYPESinterval_to_asc(&(((interval *) (var->value))[element])), quote, lineno);
936 if (!str)
937 {
938 ecpg_free(mallocedval);
939 return false;
940 }
941
942 slen = strlen(str);
943
944 if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
945 {
946 ecpg_free(mallocedval);
947 ecpg_free(str);
948 return false;
949 }
950 mallocedval = newcopy;
951
952 /* also copy trailing '\0' */
953 memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
954 if (var->arrsize > 1)
955 strcpy(mallocedval + strlen(mallocedval), ",");
956
957 ecpg_free(str);
958 }
959
960 if (var->arrsize > 1)
961 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
962
963 *tobeinserted_p = mallocedval;
964 }
965 break;
966
967 case ECPGt_date:
968 {
969 char *str = NULL;
970 int slen;
971
972 if (var->arrsize > 1)
973 mallocedval = ecpg_strdup("{", lineno, NULL);
974 else
975 mallocedval = ecpg_strdup("", lineno, NULL);
976
977 if (!mallocedval)
978 return false;
979
980 for (element = 0; element < asize; element++)
981 {
982 str = quote_postgres(PGTYPESdate_to_asc(((date *) (var->value))[element]), quote, lineno);
983 if (!str)
984 {
985 ecpg_free(mallocedval);
986 return false;
987 }
988
989 slen = strlen(str);
990
991 if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
992 {
993 ecpg_free(mallocedval);
994 ecpg_free(str);
995 return false;
996 }
997 mallocedval = newcopy;
998
999 /* also copy trailing '\0' */
1000 memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
1001 if (var->arrsize > 1)
1002 strcpy(mallocedval + strlen(mallocedval), ",");
1003
1004 ecpg_free(str);
1005 }
1006
1007 if (var->arrsize > 1)
1008 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
1009
1010 *tobeinserted_p = mallocedval;
1011 }
1012 break;
1013
1014 case ECPGt_timestamp:
1015 {
1016 char *str = NULL;
1017 int slen;
1018
1019 if (var->arrsize > 1)
1020 mallocedval = ecpg_strdup("{", lineno, NULL);
1021 else
1022 mallocedval = ecpg_strdup("", lineno, NULL);
1023
1024 if (!mallocedval)
1025 return false;
1026
1027 for (element = 0; element < asize; element++)
1028 {
1029 str = quote_postgres(PGTYPEStimestamp_to_asc(((timestamp *) (var->value))[element]), quote, lineno);
1030 if (!str)
1031 {
1032 ecpg_free(mallocedval);
1033 return false;
1034 }
1035
1036 slen = strlen(str);
1037
1038 if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
1039 {
1040 ecpg_free(mallocedval);
1041 ecpg_free(str);
1042 return false;
1043 }
1044 mallocedval = newcopy;
1045
1046 /* also copy trailing '\0' */
1047 memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
1048 if (var->arrsize > 1)
1049 strcpy(mallocedval + strlen(mallocedval), ",");
1050
1051 ecpg_free(str);
1052 }
1053
1054 if (var->arrsize > 1)
1055 strcpy(mallocedval + strlen(mallocedval) - 1, "}");
1056
1057 *tobeinserted_p = mallocedval;
1058 }
1059 break;
1060
1061 case ECPGt_descriptor:
1062 case ECPGt_sqlda:
1063 break;
1064
1065 default:
1066 /* Not implemented yet */
1068 return false;
1069 break;
1070 }
1071 }
1072 return true;
1073}
@ ECPGt_const
Definition: ecpgtype.h:61
static void sprintf_double_value(char *ptr, double value, const char *delim)
Definition: execute.c:456
static char * quote_postgres(char *arg, bool quote, int lineno)
Definition: execute.c:40
static void sprintf_float_value(char *ptr, float value, const char *delim)
Definition: execute.c:472
bool ECPGis_noind_null(enum ECPGttype type, const void *ptr)
Definition: misc.c:361
char * PGTYPESdate_to_asc(date dDate)
Definition: datetime.c:101
char * PGTYPESinterval_to_asc(interval *span)
Definition: interval.c:1062
int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)
Definition: numeric.c:1570
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
Definition: numeric.c:343
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
Definition: timestamp.c:268
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376

References variable::arrsize, numeric::dscale, ecpg_alloc(), ECPG_CONVERT_BOOL, ecpg_free(), ecpg_raise(), ecpg_realloc(), ECPG_SQLSTATE_DATATYPE_MISMATCH, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ecpg_strdup(), ecpg_type_name(), ECPG_UNSUPPORTED, ECPGis_noind_null(), ECPGt_bool, ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_const, ECPGt_date, ECPGt_decimal, ECPGt_descriptor, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_NO_INDICATOR, ECPGt_numeric, ECPGt_short, ECPGt_sqlda, ECPGt_string, ECPGt_timestamp, ECPGt_unsigned_char, ECPGt_unsigned_int, ECPGt_unsigned_long, ECPGt_unsigned_long_long, ECPGt_unsigned_short, ECPGt_varchar, element(), force_indicator, variable::ind_type, variable::ind_value, variable::offset, PGTYPESdate_to_asc(), PGTYPESinterval_to_asc(), PGTYPESnumeric_copy(), PGTYPESnumeric_free(), PGTYPESnumeric_from_decimal(), PGTYPESnumeric_new(), PGTYPESnumeric_to_asc(), PGTYPEStimestamp_to_asc(), quote_postgres(), sprintf, sprintf_double_value(), sprintf_float_value(), str, variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_build_params(), ECPGset_desc(), and store_input_from_desc().

◆ ecpg_store_result()

bool ecpg_store_result ( const PGresult results,
int  act_field,
const struct statement stmt,
struct variable var 
)

Definition at line 303 of file execute.c.

305{
306 enum ARRAY_TYPE isarray;
307 int act_tuple,
308 ntuples = PQntuples(results);
309 bool status = true;
310
311 if ((isarray = ecpg_is_type_an_array(PQftype(results, act_field), stmt, var)) == ECPG_ARRAY_ERROR)
312 {
314 return false;
315 }
316
317 if (isarray == ECPG_ARRAY_NONE)
318 {
319 /*
320 * if we don't have enough space, we cannot read all tuples
321 */
322 if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
323 {
324 ecpg_log("ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
325 stmt->lineno, ntuples, var->arrsize);
327 return false;
328 }
329 }
330 else
331 {
332 /*
333 * since we read an array, the variable has to be an array too
334 */
335 if (var->arrsize == 0)
336 {
338 return false;
339 }
340 }
341
342 /*
343 * allocate memory for NULL pointers
344 */
345 if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
346 {
347 int len = 0;
348
349 if (!PQfformat(results, act_field))
350 {
351 switch (var->type)
352 {
353 case ECPGt_char:
355 case ECPGt_string:
356 if (!var->varcharsize && !var->arrsize)
357 {
358 /* special mode for handling char**foo=0 */
359 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
360 len += strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
361 len *= var->offset; /* should be 1, but YMNK */
362 len += (ntuples + 1) * sizeof(char *);
363 }
364 else
365 {
366 var->varcharsize = 0;
367 /* check strlen for each tuple */
368 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
369 {
370 int slen = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
371
372 if (slen > var->varcharsize)
373 var->varcharsize = slen;
374 }
375 var->offset *= var->varcharsize;
376 len = var->offset * ntuples;
377 }
378 break;
379 case ECPGt_varchar:
380 len = ntuples * (var->varcharsize + sizeof(int));
381 break;
382 default:
383 len = var->offset * ntuples;
384 break;
385 }
386 }
387 else
388 {
389 for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
390 len += PQgetlength(results, act_tuple, act_field);
391 }
392
393 ecpg_log("ecpg_store_result on line %d: allocating memory for %d tuples\n", stmt->lineno, ntuples);
394 var->value = ecpg_auto_alloc(len, stmt->lineno);
395 if (!var->value)
396 return false;
397 *((char **) var->pointer) = var->value;
398 }
399
400 /* allocate indicator variable if needed */
401 if ((var->ind_arrsize == 0 || var->ind_varcharsize == 0) && var->ind_value == NULL && var->ind_pointer != NULL)
402 {
403 int len = var->ind_offset * ntuples;
404
405 var->ind_value = ecpg_auto_alloc(len, stmt->lineno);
406 if (!var->ind_value)
407 return false;
408 *((char **) var->ind_pointer) = var->ind_value;
409 }
410
411 /* fill the variable with the tuple(s) */
412 if (!var->varcharsize && !var->arrsize &&
413 (var->type == ECPGt_char || var->type == ECPGt_unsigned_char || var->type == ECPGt_string))
414 {
415 /* special mode for handling char**foo=0 */
416
417 /* filling the array of (char*)s */
418 char **current_string = (char **) var->value;
419
420 /* storing the data (after the last array element) */
421 char *current_data_location = (char *) &current_string[ntuples + 1];
422
423 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
424 {
425 int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
426
427 if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
428 var->type, var->ind_type, current_data_location,
429 var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
430 status = false;
431 else
432 {
433 *current_string = current_data_location;
434 current_data_location += len;
435 current_string++;
436 }
437 }
438
439 /* terminate the list */
440 *current_string = NULL;
441 }
442 else
443 {
444 for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
445 {
446 if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
447 var->type, var->ind_type, var->value,
448 var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
449 status = false;
450 }
451 }
452 return status;
453}
#define ECPG_TOO_MANY_MATCHES
Definition: ecpgerrno.h:21
char * ecpg_auto_alloc(long size, int lineno)
Definition: memory.c:110
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION
ARRAY_TYPE
static enum ARRAY_TYPE ecpg_is_type_an_array(int type, const struct statement *stmt, const struct variable *var)
Definition: execute.c:164

References variable::arrsize, ECPG_ARRAY_ERROR, ECPG_ARRAY_NONE, ecpg_auto_alloc(), ecpg_get_data(), ECPG_INFORMIX_SUBSELECT_NOT_ONE, ecpg_is_type_an_array(), ecpg_log(), ECPG_NO_ARRAY, ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_CARDINALITY_VIOLATION, ECPG_SQLSTATE_DATATYPE_MISMATCH, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_TOO_MANY_MATCHES, ECPGt_char, ECPGt_string, ECPGt_unsigned_char, ECPGt_varchar, variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, INFORMIX_MODE, ECPGtype_information_cache::isarray, len, variable::offset, variable::pointer, PQfformat(), PQftype(), PQgetlength, PQgetvalue, PQntuples, stmt, variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_process_output(), and ECPGget_desc().

◆ ecpg_strdup()

char * ecpg_strdup ( const char *  string,
int  lineno,
bool *  alloc_failed 
)

Definition at line 54 of file memory.c.

55{
56 char *new;
57
58 if (string == NULL)
59 return NULL;
60
61 new = strdup(string);
62 if (!new)
63 {
64 if (alloc_failed)
65 *alloc_failed = true;
67 return NULL;
68 }
69
70 return new;
71}

References ECPG_OUT_OF_MEMORY, ecpg_raise(), and ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY.

Referenced by AddStmtToCache(), ecpg_auto_prepare(), ecpg_do_prologue(), ecpg_register_prepared_stmt(), ecpg_store_input(), ECPGconnect(), ECPGget_desc(), and prepare_common().

◆ ecpg_type_name()

const char * ecpg_type_name ( enum ECPGttype  typ)

Definition at line 17 of file typename.c.

18{
19 switch (typ)
20 {
21 case ECPGt_char:
22 case ECPGt_string:
23 return "char";
25 return "unsigned char";
26 case ECPGt_short:
27 return "short";
29 return "unsigned short";
30 case ECPGt_int:
31 return "int";
33 return "unsigned int";
34 case ECPGt_long:
35 return "long";
37 return "unsigned long";
38 case ECPGt_long_long:
39 return "long long";
41 return "unsigned long long";
42 case ECPGt_float:
43 return "float";
44 case ECPGt_double:
45 return "double";
46 case ECPGt_bool:
47 return "bool";
48 case ECPGt_varchar:
49 return "varchar";
50 case ECPGt_bytea:
51 return "bytea";
53 return "char";
54 case ECPGt_decimal:
55 return "decimal";
56 case ECPGt_numeric:
57 return "numeric";
58 case ECPGt_date:
59 return "date";
60 case ECPGt_timestamp:
61 return "timestamp";
62 case ECPGt_interval:
63 return "interval";
64 case ECPGt_const:
65 return "Const";
66 default:
67 abort();
68 }
69 return ""; /* keep MSC compiler happy */
70}

References ECPGt_bool, ECPGt_bytea, ECPGt_char, ECPGt_char_variable, ECPGt_const, 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, and ECPGt_varchar.

Referenced by ecpg_get_data(), ecpg_store_input(), and ECPGdump_a_simple().

◆ sqlda_dynamic_type()

int sqlda_dynamic_type ( Oid  type,
enum COMPAT_MODE  compat 
)

Definition at line 107 of file typename.c.

108{
109 switch (type)
110 {
111 case CHAROID:
112 case VARCHAROID:
113 case BPCHAROID:
114 case TEXTOID:
115 return ECPGt_char;
116 case INT2OID:
117 return ECPGt_short;
118 case INT4OID:
119 return ECPGt_int;
120 case FLOAT8OID:
121 return ECPGt_double;
122 case FLOAT4OID:
123 return ECPGt_float;
124 case NUMERICOID:
126 case DATEOID:
127 return ECPGt_date;
128 case TIMESTAMPOID:
129 case TIMESTAMPTZOID:
130 return ECPGt_timestamp;
131 case INTERVALOID:
132 return ECPGt_interval;
133 case INT8OID:
134#if SIZEOF_LONG == 8
135 return ECPGt_long;
136#elif SIZEOF_LONG_LONG == 8
137 return ECPGt_long_long;
138#else
139#error "cannot find integer type of the same size as INT8OID"
140#endif
141 /* Unhandled types always return a string */
142 default:
143 return ECPGt_char;
144 }
145}

References compat, ECPGt_char, ECPGt_date, ECPGt_decimal, ECPGt_double, ECPGt_float, ECPGt_int, ECPGt_interval, ECPGt_long, ECPGt_long_long, ECPGt_numeric, ECPGt_short, ECPGt_timestamp, INFORMIX_MODE, and type.

Referenced by ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), and sqlda_common_total_size().

Variable Documentation

◆ ecpg_internal_regression_mode

bool ecpg_internal_regression_mode
extern

Definition at line 29 of file misc.c.

Referenced by ecpg_get_data(), ecpg_log(), ECPGconnect(), and ECPGdebug().

◆ ivlist

struct var_list* ivlist
extern

Definition at line 535 of file misc.c.

Referenced by ecpg_finish(), ECPGget_var(), and ECPGset_var().