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)
 
struct connectionecpg_get_connection (const char *)
 
char * ecpg_alloc (long, int)
 
char * ecpg_auto_alloc (long, int)
 
char * ecpg_realloc (void *, long, int)
 
void ecpg_free (void *)
 
bool ecpg_init (const struct connection *, const char *, const int)
 
char * ecpg_strdup (const char *, int)
 
const char * ecpg_type_name (enum ECPGttype)
 
int ecpg_dynamic_type (Oid)
 
int sqlda_dynamic_type (Oid, enum COMPAT_MODE)
 
void ecpg_clear_auto_mem (void)
 
struct descriptorecpg_find_desc (int line, const char *name)
 
struct prepared_statementecpg_find_prepared_statement (const char *, struct connection *, struct prepared_statement **)
 
bool ecpg_store_result (const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
 
bool ecpg_store_input (const int, const bool, const struct variable *, char **, bool)
 
void ecpg_free_params (struct statement *stmt, bool print)
 
bool ecpg_do_prologue (int, const int, const int, const char *, const bool, enum ECPG_statement_type, const char *, va_list, struct statement **)
 
bool ecpg_build_params (struct statement *)
 
bool ecpg_autostart_transaction (struct statement *stmt)
 
bool ecpg_execute (struct statement *stmt)
 
bool ecpg_process_output (struct statement *, bool)
 
void ecpg_do_epilogue (struct statement *)
 
bool ecpg_do (const int, const int, const int, const char *, const bool, const int, const char *, va_list)
 
bool ecpg_check_PQresult (PGresult *, int, PGconn *, enum COMPAT_MODE)
 
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 *, struct connection *)
 
bool ecpg_deallocate_all_conn (int lineno, enum COMPAT_MODE c, struct connection *conn)
 
void ecpg_log (const char *format,...) pg_attribute_printf(1
 
void bool ecpg_auto_prepare (int, const char *, const int, char **, const char *)
 
bool ecpg_register_prepared_stmt (struct statement *)
 
void ecpg_init_sqlca (struct sqlca_t *sqlca)
 
struct sqlda_compatecpg_build_compat_sqlda (int, PGresult *, int, enum COMPAT_MODE)
 
void ecpg_set_compat_sqlda (int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE)
 
struct sqlda_structecpg_build_native_sqlda (int, PGresult *, int, enum COMPAT_MODE)
 
void ecpg_set_native_sqlda (int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE)
 
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

◆ ECPG_IS_ARRAY

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

Definition at line 35 of file ecpglib_extern.h.

Referenced by ecpg_get_data(), ecpg_is_type_an_array(), and garbage_left().

◆ ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION

#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION   "25001"

Definition at line 241 of file ecpglib_extern.h.

Referenced by ECPGnoticeReceiver().

◆ ECPG_SQLSTATE_CARDINALITY_VIOLATION

#define ECPG_SQLSTATE_CARDINALITY_VIOLATION   "21000"

Definition at line 239 of file ecpglib_extern.h.

Referenced by ecpg_store_result(), and ECPGget_desc().

◆ ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST

#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST   "08003"

Definition at line 237 of file ecpglib_extern.h.

Referenced by ecpg_init(), and ECPGdescribe().

◆ ECPG_SQLSTATE_DATATYPE_MISMATCH

#define ECPG_SQLSTATE_DATATYPE_MISMATCH   "42804"

Definition at line 247 of file ecpglib_extern.h.

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

◆ ECPG_SQLSTATE_DUPLICATE_CURSOR

#define ECPG_SQLSTATE_DUPLICATE_CURSOR   "42P03"

Definition at line 248 of file ecpglib_extern.h.

Referenced by ECPGnoticeReceiver().

◆ ECPG_SQLSTATE_ECPG_INTERNAL_ERROR

#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR   "YE000"

◆ ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY

◆ ECPG_SQLSTATE_INVALID_CURSOR_NAME

#define ECPG_SQLSTATE_INVALID_CURSOR_NAME   "34000"

Definition at line 245 of file ecpglib_extern.h.

Referenced by ECPGnoticeReceiver().

◆ ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX

#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX   "07009"

Definition at line 235 of file ecpglib_extern.h.

Referenced by ECPGget_desc().

◆ ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME

#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME   "33000"

Definition at line 244 of file ecpglib_extern.h.

Referenced by ecpg_find_desc(), and ECPGdeallocate_desc().

◆ ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME

#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME   "26000"

Definition at line 243 of file ecpglib_extern.h.

Referenced by deallocate_one(), ecpg_do_prologue(), ECPGdeallocate(), and ECPGdescribe().

◆ ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION

#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION   "25P01"

Definition at line 242 of file ecpglib_extern.h.

Referenced by ECPGnoticeReceiver().

◆ ECPG_SQLSTATE_NO_DATA

#define ECPG_SQLSTATE_NO_DATA   "02000"

Definition at line 231 of file ecpglib_extern.h.

Referenced by ecpg_get_data(), and ecpg_process_output().

◆ ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER

#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER   "22002"

Definition at line 240 of file ecpglib_extern.h.

Referenced by ecpg_get_data().

◆ ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION

#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION   "07006"

Definition at line 234 of file ecpglib_extern.h.

Referenced by get_char_item(), get_int_item(), and set_int_item().

◆ ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION

#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION   "08001"

Definition at line 236 of file ecpglib_extern.h.

Referenced by ECPGconnect().

◆ ECPG_SQLSTATE_SYNTAX_ERROR

#define ECPG_SQLSTATE_SYNTAX_ERROR   "42601"

Definition at line 246 of file ecpglib_extern.h.

◆ ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN

#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN   "08007"

Definition at line 238 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 232 of file ecpglib_extern.h.

Referenced by ecpg_build_params().

◆ ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS

#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS   "07002"

Definition at line 233 of file ecpglib_extern.h.

Referenced by ecpg_process_output().

◆ INFORMIX_MODE

◆ ORACLE_MODE

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

Definition at line 28 of file ecpglib_extern.h.

Referenced by ecpg_get_data().

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 30 of file ecpglib_extern.h.

◆ 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 20 of file ecpglib_extern.h.

Function Documentation

◆ ecpg_add_mem()

bool ecpg_add_mem ( void *  ptr,
int  lineno 
)

Definition at line 124 of file memory.c.

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

Referenced by ecpg_auto_alloc().

125 {
126  struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);
127 
128  if (!am)
129  return false;
130 
131  am->pointer = ptr;
132  am->next = get_auto_allocs();
133  set_auto_allocs(am);
134  return true;
135 }
void * pointer
Definition: memory.c:67
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
struct auto_mem * next
Definition: memory.c:68

◆ ecpg_alloc()

char* ecpg_alloc ( long  ,
int   
)

Definition at line 19 of file memory.c.

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

Referenced by AddStmtToCache(), convert_bytea_to_string(), deallocate_one(), ecpg_add_mem(), ecpg_auto_alloc(), ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), ecpg_build_params(), ecpg_do_prologue(), ecpg_get_data(), ecpg_is_type_an_array(), ecpg_register_prepared_stmt(), ecpg_store_input(), ecpg_type_infocache_push(), ECPGallocate_desc(), ECPGconnect(), ECPGset_desc(), insert_tobeinserted(), prepare_common(), print_param_value(), quote_postgres(), replace_variables(), and store_input_from_desc().

20 {
21  char *new = (char *) calloc(1L, size);
22 
23  if (!new)
24  {
26  return NULL;
27  }
28 
29  return new;
30 }
#define calloc(a, b)
Definition: header.h:55
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15

◆ ecpg_auto_alloc()

char* ecpg_auto_alloc ( long  ,
int   
)

Definition at line 108 of file memory.c.

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

Referenced by ecpg_store_result(), and ECPGget_desc().

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

◆ ecpg_auto_prepare()

void bool ecpg_auto_prepare ( int  ,
const char *  ,
const int  ,
char **  ,
const char *   
)

Definition at line 553 of file prepare.c.

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

Referenced by ecpg_do_prologue().

554 {
555  int entNo;
556 
557  /* search the statement cache for this statement */
558  entNo = SearchStmtCache(query);
559 
560  /* if not found - add the statement to the cache */
561  if (entNo)
562  {
563  char *stmtID;
564  struct connection *con;
565  struct prepared_statement *prep;
566 
567  ecpg_log("ecpg_auto_prepare on line %d: statement found in cache; entry %d\n", lineno, entNo);
568 
569  stmtID = stmtCacheEntries[entNo].stmtID;
570 
571  con = ecpg_get_connection(connection_name);
572  prep = ecpg_find_prepared_statement(stmtID, con, NULL);
573  /* This prepared name doesn't exist on this connection. */
574  if (!prep && !prepare_common(lineno, con, stmtID, query))
575  return false;
576 
577  *name = ecpg_strdup(stmtID, lineno);
578  }
579  else
580  {
581  char stmtID[STMTID_SIZE];
582 
583  ecpg_log("ecpg_auto_prepare on line %d: statement not in cache; inserting\n", lineno);
584 
585  /* generate a statement ID */
586  sprintf(stmtID, "ecpg%d", nextStmtID++);
587 
588  if (!ECPGprepare(lineno, connection_name, 0, stmtID, query))
589  return false;
590 
591  entNo = AddStmtToCache(lineno, stmtID, connection_name, compat, query);
592  if (entNo < 0)
593  return false;
594 
595  *name = ecpg_strdup(stmtID, lineno);
596  }
597 
598  /* increase usage counter */
599  stmtCacheEntries[entNo].execs++;
600 
601  return true;
602 }
static int SearchStmtCache(const char *ecpgQuery)
Definition: prepare.c:415
Definition: type.h:102
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:217
long execs
Definition: prepare.c:33
char stmtID[STMTID_SIZE]
Definition: prepare.c:31
static int AddStmtToCache(int lineno, const char *stmtID, const char *connection, int compat, const char *ecpgQuery)
Definition: prepare.c:491
#define sprintf
Definition: port.h:194
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
Definition: prepare.c:159
static int nextStmtID
Definition: prepare.c:37
static stmtCacheEntry * stmtCacheEntries
Definition: prepare.c:38
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
#define STMTID_SIZE
Definition: prepare.c:14

◆ ecpg_autostart_transaction()

bool ecpg_autostart_transaction ( struct statement stmt)

Definition at line 1574 of file execute.c.

References connection::autocommit, statement::compat, statement::connection, connection::connection, ecpg_check_PQresult(), ecpg_free_params(), statement::lineno, PQclear(), PQexec(), PQTRANS_IDLE, PQtransactionStatus(), and statement::results.

Referenced by ecpg_do().

1575 {
1577  {
1578  stmt->results = PQexec(stmt->connection->connection, "begin transaction");
1579  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1580  {
1581  ecpg_free_params(stmt, false);
1582  return false;
1583  }
1584  PQclear(stmt->results);
1585  stmt->results = NULL;
1586  }
1587  return true;
1588 }
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1109
PGresult * results
struct connection * connection
enum COMPAT_MODE compat
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6578
void PQclear(PGresult *res)
Definition: fe-exec.c:694
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1939

◆ ecpg_build_compat_sqlda()

struct sqlda_compat* ecpg_build_compat_sqlda ( int  ,
PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 205 of file sqlda.c.

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

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  {
231  sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
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 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
int PQfsize(const PGresult *res, int field_num)
Definition: fe-exec.c:3018
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2855
short sqltypelen
Definition: sqlda-compat.h:21
char * sqlname
Definition: sqlda-compat.h:14
short desc_occ
Definition: sqlda-compat.h:42
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3007
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
char * ecpg_alloc(long, int)
Definition: memory.c:19
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:107
int i
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

◆ ecpg_build_native_sqlda()

struct sqlda_struct* ecpg_build_native_sqlda ( int  ,
PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 412 of file sqlda.c.

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

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 
434  sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
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 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2777
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:186
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2855
short length
Definition: sqlda-native.h:20
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
#define sprintf
Definition: port.h:194
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:3007
char sqldaid[8]
Definition: sqlda-native.h:35
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
char * ecpg_alloc(long, int)
Definition: memory.c:19
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:107
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
struct sqlname sqlname
Definition: sqlda-native.h:30

◆ ecpg_build_params()

bool ecpg_build_params ( struct statement )

Definition at line 1216 of file execute.c.

References statement::command, statement::compat, statement::connection, connection::connection, 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, statement::force_indicator, i, INFORMIX_MODE, statement::inlist, insert_tobeinserted(), descriptor_item::is_binary, descriptor::items, ECPGgeneric_varchar::len, statement::lineno, descriptor_item::next, variable::next, next_insert(), statement::nparams, descriptor_item::num, statement::paramformats, statement::paramlengths, statement::paramvalues, variable::pointer, PQparameterStatus(), statement::questionmarks, 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_struct::sqlvar, sqlda_compat::sqlvar, statement::statement_type, store_input_from_desc(), generate_unaccent_rules::str, variable::type, variable::value, and value.

Referenced by ecpg_do().

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

◆ ecpg_check_PQresult()

bool ecpg_check_PQresult ( PGresult ,
int  ,
PGconn ,
enum  COMPAT_MODE 
)

Definition at line 283 of file error.c.

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

284 {
285  if (results == NULL)
286  {
287  ecpg_log("ecpg_check_PQresult on line %d: no result - %s", lineno, PQerrorMessage(connection));
288  ecpg_raise_backend(lineno, NULL, connection, compat);
289  return false;
290  }
291 
292  switch (PQresultStatus(results))
293  {
294 
295  case PGRES_TUPLES_OK:
296  return true;
297  break;
298  case PGRES_EMPTY_QUERY:
299  /* do nothing */
301  PQclear(results);
302  return false;
303  break;
304  case PGRES_COMMAND_OK:
305  return true;
306  break;
308  case PGRES_FATAL_ERROR:
309  case PGRES_BAD_RESPONSE:
310  ecpg_log("ecpg_check_PQresult on line %d: bad response - %s", lineno, PQresultErrorMessage(results));
311  ecpg_raise_backend(lineno, results, connection, compat);
312  PQclear(results);
313  return false;
314  break;
315  case PGRES_COPY_OUT:
316  return true;
317  break;
318  case PGRES_COPY_IN:
319  ecpg_log("ecpg_check_PQresult on line %d: COPY IN data transfer in progress\n", lineno);
321  PQclear(results);
322  return false;
323  break;
324  default:
325  ecpg_log("ecpg_check_PQresult on line %d: unknown execution status type\n",
326  lineno);
327  ecpg_raise_backend(lineno, results, connection, compat);
328  PQclear(results);
329  return false;
330  break;
331  }
332 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6623
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:2692
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
void PQclear(PGresult *res)
Definition: fe-exec.c:694
int PQendcopy(PGconn *conn)
Definition: fe-exec.c:2618
char * PQresultErrorMessage(const PGresult *res)
Definition: fe-exec.c:2708

◆ ecpg_clear_auto_mem()

void ecpg_clear_auto_mem ( void  )

Definition at line 158 of file memory.c.

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

Referenced by ecpg_do_prologue(), and ECPGconnect().

159 {
160  struct auto_mem *am = get_auto_allocs();
161 
162  /* only free our own structure */
163  if (am)
164  {
165  do
166  {
167  struct auto_mem *act = am;
168 
169  am = am->next;
170  ecpg_free(act);
171  } while (am);
172  set_auto_allocs(NULL);
173  }
174 }
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
void ecpg_free(void *ptr)
Definition: memory.c:13
struct auto_mem * next
Definition: memory.c:68

◆ ecpg_deallocate_all_conn()

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

Definition at line 337 of file prepare.c.

References deallocate_one(), and connection::prep_stmts.

Referenced by ecpg_finish(), and ECPGdeallocate_all().

338 {
339  /* deallocate all prepared statements */
340  while (con->prep_stmts)
341  {
342  if (!deallocate_one(lineno, c, con, NULL, con->prep_stmts))
343  return false;
344  }
345 
346  return true;
347 }
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:260
char * c

◆ ecpg_do()

bool ecpg_do ( const int  ,
const int  ,
const int  ,
const char *  ,
const bool  ,
const int  ,
const char *  ,
va_list   
)

Definition at line 2242 of file execute.c.

References ecpg_autostart_transaction(), ecpg_build_params(), ecpg_do_epilogue(), ecpg_do_prologue(), ecpg_execute(), and ecpg_process_output().

Referenced by ECPGdo().

2243 {
2244  struct statement *stmt = NULL;
2245 
2246  if (!ecpg_do_prologue(lineno, compat, force_indicator, connection_name,
2248  query, args, &stmt))
2249  goto fail;
2250 
2251  if (!ecpg_build_params(stmt))
2252  goto fail;
2253 
2254  if (!ecpg_autostart_transaction(stmt))
2255  goto fail;
2256 
2257  if (!ecpg_execute(stmt))
2258  goto fail;
2259 
2260  if (!ecpg_process_output(stmt, true))
2261  goto fail;
2262 
2263  ecpg_do_epilogue(stmt);
2264  return true;
2265 
2266 fail:
2267  ecpg_do_epilogue(stmt);
2268  return false;
2269 }
bool ecpg_process_output(struct statement *stmt, bool clear_result)
Definition: execute.c:1664
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1574
ECPG_statement_type
Definition: ecpgtype.h:95
bool ecpg_build_params(struct statement *stmt)
Definition: execute.c:1216
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1595
bool questionmarks
Definition: ecpg.c:19
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:1938
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:2210
bool force_indicator
Definition: ecpg.c:18

◆ ecpg_do_epilogue()

void ecpg_do_epilogue ( struct statement )

Definition at line 2210 of file execute.c.

References free_statement(), locale_t, statement::oldlocale, and setlocale.

Referenced by ecpg_do(), and ecpg_do_prologue().

2211 {
2212  if (stmt == NULL)
2213  return;
2214 
2215 #ifdef HAVE_USELOCALE
2216  if (stmt->oldlocale != (locale_t) 0)
2217  uselocale(stmt->oldlocale);
2218 #else
2219  if (stmt->oldlocale)
2220  setlocale(LC_NUMERIC, stmt->oldlocale);
2221 #ifdef HAVE__CONFIGTHREADLOCALE
2222 
2223  /*
2224  * This is a bit trickier than it looks: if we failed partway through
2225  * statement initialization, oldthreadlocale could still be 0. But that's
2226  * okay because a call with 0 is defined to be a no-op.
2227  */
2228  if (stmt->oldthreadlocale != -1)
2229  (void) _configthreadlocale(stmt->oldthreadlocale);
2230 #endif
2231 #endif
2232 
2233  free_statement(stmt);
2234 }
#define setlocale(a, b)
Definition: win32_port.h:408
static void free_statement(struct statement *stmt)
Definition: execute.c:96
#define locale_t
Definition: win32_port.h:363

◆ ecpg_do_prologue()

bool ecpg_do_prologue ( int  ,
const int  ,
const int  ,
const char *  ,
const bool  ,
enum  ECPG_statement_type,
const char *  ,
va_list  ,
struct statement **   
)

Definition at line 1938 of file execute.c.

References variable::arrsize, statement::command, compat, statement::compat, statement::connection, 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_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, statement::force_indicator, variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, statement::inlist, statement::lineno, sort-test::list, locale_t, statement::name, connection::name, variable::next, variable::offset, statement::oldlocale, statement::outlist, variable::pointer, questionmarks, statement::questionmarks, setlocale, statement::statement_type, variable::type, generate_unaccent_rules::type, variable::value, and variable::varcharsize.

Referenced by ecpg_do().

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

◆ ecpg_dynamic_type()

int ecpg_dynamic_type ( Oid  )

Definition at line 73 of file typename.c.

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

Referenced by ecpg_is_type_an_array(), and ECPGget_desc().

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 }

◆ ecpg_execute()

bool ecpg_execute ( struct statement stmt)

Definition at line 1595 of file execute.c.

References statement::command, statement::compat, statement::connection, connection::connection, ecpg_check_PQresult(), ecpg_free_params(), ecpg_log(), ecpg_register_prepared_stmt(), ECPGst_execute, ECPGst_prepare, statement::lineno, statement::name, connection::name, statement::nparams, statement::paramformats, statement::paramlengths, statement::paramvalues, PQexec(), PQexecParams(), PQexecPrepared(), statement::results, and statement::statement_type.

Referenced by ecpg_do().

1596 {
1597  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);
1598  if (stmt->statement_type == ECPGst_execute)
1599  {
1601  stmt->name,
1602  stmt->nparams,
1603  (const char *const *) stmt->paramvalues,
1604  (const int *) stmt->paramlengths,
1605  (const int *) stmt->paramformats,
1606  0);
1607  ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
1608  }
1609  else
1610  {
1611  if (stmt->nparams == 0)
1612  {
1613  stmt->results = PQexec(stmt->connection->connection, stmt->command);
1614  ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
1615  }
1616  else
1617  {
1618  stmt->results = PQexecParams(stmt->connection->connection,
1619  stmt->command, stmt->nparams, NULL,
1620  (const char *const *) stmt->paramvalues,
1621  (const int *) stmt->paramlengths,
1622  (const int *) stmt->paramformats,
1623  0);
1624 
1625  ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
1626  }
1627 
1628  if (stmt->statement_type == ECPGst_prepare)
1629  {
1630  if (!ecpg_register_prepared_stmt(stmt))
1631  {
1632  ecpg_free_params(stmt, true);
1633  return false;
1634  }
1635  }
1636  }
1637 
1638  ecpg_free_params(stmt, true);
1639 
1640  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1641  return false;
1642 
1643  return true;
1644 }
bool ecpg_register_prepared_stmt(struct statement *)
Definition: prepare.c:59
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:2000
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1109
enum ECPG_statement_type statement_type
PGresult * results
int * paramformats
struct connection * connection
enum COMPAT_MODE compat
void ecpg_log(const char *format,...) pg_attribute_printf(1
char * command
bool ecpg_check_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE)
Definition: error.c:283
PGconn * connection
char * name
char ** paramvalues
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:1953
int * paramlengths
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1939

◆ ecpg_find_desc()

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

Definition at line 837 of file descriptor.c.

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

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

838 {
839  struct descriptor *desc;
840 
841  for (desc = get_descriptors(); desc; desc = desc->next)
842  {
843  if (strcmp(name, desc->name) == 0)
844  return desc;
845  }
846 
848  return NULL; /* not found */
849 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
struct descriptor * next
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
const char * name
Definition: encode.c:521
#define get_descriptors()
Definition: descriptor.c:55

◆ ecpg_find_prepared_statement()

struct prepared_statement* ecpg_find_prepared_statement ( const char *  ,
struct connection ,
struct prepared_statement **   
)

Definition at line 239 of file prepare.c.

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

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

241 {
242  struct prepared_statement *this,
243  *prev;
244 
245  for (this = con->prep_stmts, prev = NULL;
246  this != NULL;
247  prev = this, this = this->next)
248  {
249  if (strcmp(this->name, name) == 0)
250  {
251  if (prev_)
252  *prev_ = prev;
253  return this;
254  }
255  }
256  return NULL;
257 }
struct prepared_statement * next
const char * name
Definition: encode.c:521

◆ ecpg_free()

◆ ecpg_free_params()

void ecpg_free_params ( struct statement stmt,
bool  print 
)

Definition at line 1109 of file execute.c.

References ecpg_free(), statement::lineno, statement::nparams, statement::paramformats, statement::paramlengths, statement::paramvalues, and print_param_value().

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

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

◆ ecpg_get_connection()

struct connection* ecpg_get_connection ( const char *  )

Definition at line 74 of file connect.c.

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

75 {
76  struct connection *ret = NULL;
77 
78  if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
79  {
80 #ifdef ENABLE_THREAD_SAFETY
81  ret = pthread_getspecific(actual_connection_key);
82 
83  /*
84  * if no connection in TSD for this thread, get the global default
85  * connection and hope the user knows what they're doing (i.e. using
86  * their own mutex to protect that connection from concurrent accesses
87  */
88  /* if !ret then we got the connection from TSD */
89  if (NULL == ret)
90  /* no TSD connection here either, using global */
91  ret = actual_connection;
92 #else
93  ret = actual_connection;
94 #endif
95  }
96  else
97  {
98 #ifdef ENABLE_THREAD_SAFETY
99  pthread_mutex_lock(&connections_mutex);
100 #endif
101 
102  ret = ecpg_get_connection_nr(connection_name);
103 
104 #ifdef ENABLE_THREAD_SAFETY
105  pthread_mutex_unlock(&connections_mutex);
106 #endif
107  }
108 
109  return ret;
110 }
int pthread_mutex_lock(pthread_mutex_t *mp)
Definition: pthread-win32.c:45
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:54
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
static struct connection * ecpg_get_connection_nr(const char *connection_name)
Definition: connect.c:36
static struct connection * actual_connection
Definition: connect.c:18

◆ ecpg_get_data()

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   
)

Definition at line 206 of file data.c.

References ECPGgeneric_varchar::arr, array_boundary(), array_delimiter(), check_special_value(), 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, free, garbage_left(), hex_decode(), INFORMIX_MODE, ECPGgeneric_varchar::len, 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, sqlca_t::sqlwarn, and generate_unaccent_rules::str.

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

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

◆ ecpg_hex_dec_len()

unsigned ecpg_hex_dec_len ( unsigned  srclen)

Definition at line 134 of file data.c.

Referenced by ecpg_get_data().

135 {
136  return srclen >> 1;
137 }

◆ ecpg_hex_enc_len()

unsigned ecpg_hex_enc_len ( unsigned  srclen)

Definition at line 128 of file data.c.

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

129 {
130  return srclen << 1;
131 }

◆ ecpg_hex_encode()

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

Definition at line 191 of file data.c.

References hextbl.

Referenced by convert_bytea_to_string(), and print_param_value().

192 {
193  static const char hextbl[] = "0123456789abcdef";
194  const char *end = src + len;
195 
196  while (src < end)
197  {
198  *dst++ = hextbl[(*src >> 4) & 0xF];
199  *dst++ = hextbl[*src & 0xF];
200  src++;
201  }
202  return len * 2;
203 }
static const char hextbl[]
Definition: pgp-info.c:87

◆ ecpg_init()

bool ecpg_init ( const struct connection ,
const char *  ,
const int   
)

Definition at line 104 of file misc.c.

References arg, 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 free.

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

105 {
106  struct sqlca_t *sqlca = ECPGget_sqlca();
107 
108  if (sqlca == NULL)
109  {
111  NULL);
112  return false;
113  }
114 
115  ecpg_init_sqlca(sqlca);
116  if (con == NULL)
117  {
119  connection_name ? connection_name : ecpg_gettext("NULL"));
120  return false;
121  }
122 
123  return true;
124 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ecpg_gettext(x)
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
Definition: sqlca.h:19
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
static struct sqlca_t sqlca
Definition: misc.c:62
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36

◆ ecpg_init_sqlca()

void ecpg_init_sqlca ( struct sqlca_t sqlca)

Definition at line 98 of file misc.c.

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

99 {
100  memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
101 }
Definition: sqlca.h:19
static struct sqlca_t sqlca_init
Definition: misc.c:31

◆ ecpg_log()

◆ ecpg_prepared()

char* ecpg_prepared ( const char *  ,
struct connection  
)

Definition at line 357 of file prepare.c.

References statement::command, ecpg_find_prepared_statement(), and prepared_statement::stmt.

Referenced by ecpg_do_prologue(), and ECPGprepared_statement().

358 {
359  struct prepared_statement *this;
360 
361  this = ecpg_find_prepared_statement(name, con, NULL);
362  return this ? this->stmt->command : NULL;
363 }
struct statement * stmt
char * command
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
const char * name
Definition: encode.c:521

◆ ecpg_process_output()

bool ecpg_process_output ( struct statement ,
bool   
)

Definition at line 1664 of file execute.c.

References pgNotify::be_pid, statement::compat, statement::connection, connection::connection, 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, statement::lineno, variable::next, statement::outlist, 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, statement::results, sqlca, sqlca_t::sqlerrd, status(), and variable::type.

Referenced by ecpg_do().

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

◆ ecpg_raise()

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

Definition at line 13 of file error.c.

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::sqlcode, sqlca_t::sqlerrm, sqlca_t::sqlerrmc, sqlca_t::sqlerrml, and sqlca_t::sqlstate.

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

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 
36  case ECPG_OUT_OF_MEMORY:
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 
43  case ECPG_UNSUPPORTED:
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 
71  case ECPG_UINT_FORMAT:
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 
78  case ECPG_FLOAT_FORMAT:
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 
85  case ECPG_CONVERT_BOOL:
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 
119  case ECPG_DATA_NOT_ARRAY:
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 
126  case ECPG_ARRAY_INSERT:
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 
147  case ECPG_INVALID_STMT:
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 
182  case ECPG_VAR_NOT_CHAR:
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_DATA_NOT_ARRAY
Definition: ecpgerrno.h:33
#define ECPG_CONNECT
Definition: ecpgerrno.h:51
#define ECPG_NOT_CONN
Definition: ecpgerrno.h:37
void ECPGfree_auto_mem(void)
Definition: memory.c:138
#define sqlca
Definition: sqlca.h:59
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
#define ECPG_VAR_NOT_CHAR
Definition: ecpgerrno.h:46
#define ECPG_CONVERT_BOOL
Definition: ecpgerrno.h:29
#define ECPG_INVALID_DESCRIPTOR_INDEX
Definition: ecpgerrno.h:43
#define ECPG_UNKNOWN_DESCRIPTOR_ITEM
Definition: ecpgerrno.h:44
int sqlerrml
Definition: sqlca.h:26
#define ECPG_TOO_MANY_ARGUMENTS
Definition: ecpgerrno.h:19
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
#define ECPG_TRANS
Definition: ecpgerrno.h:50
#define ecpg_gettext(x)
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
#define ECPG_NO_ARRAY
Definition: ecpgerrno.h:32
Definition: sqlca.h:19
#define ECPG_FLOAT_FORMAT
Definition: ecpgerrno.h:24
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
char sqlstate[5]
Definition: sqlca.h:53
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ECPG_ARRAY_INSERT
Definition: ecpgerrno.h:34
#define ECPG_MISSING_INDICATOR
Definition: ecpgerrno.h:31
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
long sqlcode
Definition: sqlca.h:23
#define ECPG_VAR_NOT_NUMERIC
Definition: ecpgerrno.h:45
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
struct sqlca_t::@148 sqlerrm
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
#define ECPG_INT_FORMAT
Definition: ecpgerrno.h:22
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36
#define snprintf
Definition: port.h:192

◆ ecpg_raise_backend()

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

Definition at line 219 of file error.c.

References 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, sqlca_t::sqlcode, sqlca_t::sqlerrm, sqlca_t::sqlerrmc, sqlca_t::sqlerrml, and sqlca_t::sqlstate.

Referenced by ecpg_check_PQresult(), and ecpg_process_output().

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  if (result)
233  {
234  sqlstate = PQresultErrorField(result, PG_DIAG_SQLSTATE);
235  if (sqlstate == NULL)
237  message = PQresultErrorField(result, PG_DIAG_MESSAGE_PRIMARY);
238  }
239  else
240  {
242  message = PQerrorMessage(conn);
243  }
244 
245  if (strcmp(sqlstate, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR) == 0)
246  {
247  /*
248  * we might get here if the connection breaks down, so let's check for
249  * this instead of giving just the generic internal error
250  */
251  if (PQstatus(conn) == CONNECTION_BAD)
252  {
253  sqlstate = "57P02";
254  message = ecpg_gettext("the connection to the server was lost");
255  }
256  }
257 
258  /* copy error message */
259  snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "%s on line %d", message, line);
260  sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
261 
262  /* copy SQLSTATE */
263  strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
264 
265  /* assign SQLCODE for backward compatibility */
266  if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)
268  else if (strncmp(sqlca->sqlstate, "21000", sizeof(sqlca->sqlstate)) == 0)
270  else
271  sqlca->sqlcode = ECPG_PGSQL;
272 
273  /* %.*s is safe here as long as sqlstate is all-ASCII */
274  ecpg_log("raising sqlstate %.*s (sqlcode %ld): %s\n",
275  (int) sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, sqlca->sqlerrm.sqlerrmc);
276 
277  /* free all memory we have allocated for the user */
279 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6623
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
void ECPGfree_auto_mem(void)
Definition: memory.c:138
#define sqlca
Definition: sqlca.h:59
#define INFORMIX_MODE(X)
int sqlerrml
Definition: sqlca.h:26
#define ECPG_PGSQL
Definition: ecpgerrno.h:49
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
#define ecpg_gettext(x)
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:141
#define ECPG_SUBSELECT_NOT_ONE
Definition: ecpgerrno.h:53
Definition: sqlca.h:19
#define ECPG_INFORMIX_DUPLICATE_KEY
Definition: ecpgerrno.h:57
char sqlstate[5]
Definition: sqlca.h:53
void ecpg_log(const char *format,...) pg_attribute_printf(1
enum COMPAT_MODE compat
Definition: ecpg.c:25
long sqlcode
Definition: sqlca.h:23
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:2754
#define ECPG_DUPLICATE_KEY
Definition: ecpgerrno.h:52
#define ECPG_INFORMIX_SUBSELECT_NOT_ONE
Definition: ecpgerrno.h:58
struct sqlca_t::@148 sqlerrm
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6570
#define snprintf
Definition: port.h:192

◆ ecpg_realloc()

char* ecpg_realloc ( void *  ,
long  ,
int   
)

Definition at line 33 of file memory.c.

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

Referenced by ecpg_build_params(), and ecpg_store_input().

34 {
35  char *new = (char *) realloc(ptr, size);
36 
37  if (!new)
38  {
40  return NULL;
41  }
42 
43  return new;
44 }
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
#define realloc(a, b)
Definition: header.h:60

◆ ecpg_register_prepared_stmt()

bool ecpg_register_prepared_stmt ( struct statement )

Definition at line 59 of file prepare.c.

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

Referenced by ecpg_execute().

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);
89  prep_stmt->inlist = prep_stmt->outlist = NULL;
90  this->name = ecpg_strdup(stmt->name, lineno);
91  this->stmt = prep_stmt;
92  this->prepared = true;
93 
94  if (con->prep_stmts == NULL)
95  this->next = NULL;
96  else
97  this->next = con->prep_stmts;
98 
99  con->prep_stmts = this;
100  return true;
101 }
static int32 next
Definition: blutils.c:213
void ecpg_free(void *)
Definition: memory.c:13
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
struct connection * connection
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:260
struct statement * stmt
char * ecpg_alloc(long, int)
Definition: memory.c:19
char * command
struct variable * inlist
PGconn * connection
char * name
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:239
const char * name
Definition: encode.c:521
struct variable * outlist
struct prepared_statement * prep_stmts

◆ ecpg_set_compat_sqlda()

void ecpg_set_compat_sqlda ( int  ,
struct sqlda_compat **  ,
const PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 255 of file sqlda.c.

References numeric::buf, 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().

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:
286  case ECPGt_unsigned_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:
292  case ECPGt_unsigned_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 
359  PGTYPESnumeric_free(num);
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:
379  case ECPGt_unsigned_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,
400  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
401  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
402  ECPG_ARRAY_NONE, compat, false);
403  }
404  else
405  ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);
406 
407  offset = next_offset;
408  }
409 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
int64 timestamp
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:252
long date
Definition: pgtypes_date.h:9
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:471
char * sqldata
Definition: sqlda-compat.h:12
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:33
NumericDigit * digits
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:955
int16 NumericDigit
Definition: numeric.c:102
void ecpg_log(const char *format,...) pg_attribute_printf(1
static int16 value_is_null
Definition: sqlda.c:251
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:206
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:407
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:319
int i
static long sqlda_compat_empty_size(const PGresult *res)
Definition: sqlda.c:45
short * sqlind
Definition: sqlda-compat.h:13
char * sqlilongdata
Definition: sqlda-compat.h:32
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
long val
Definition: informix.c:664
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40
unsigned char bool
Definition: c.h:309

◆ ecpg_set_native_sqlda()

void ecpg_set_native_sqlda ( int  ,
struct sqlda_struct **  ,
const PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 444 of file sqlda.c.

References numeric::buf, 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().

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:
475  case ECPGt_unsigned_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:
481  case ECPGt_unsigned_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 
548  PGTYPESnumeric_free(num);
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:
568  case ECPGt_unsigned_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,
585  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
586  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
587  ECPG_ARRAY_NONE, compat, false);
588  }
589 
590  offset = next_offset;
591  }
592 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
int64 timestamp
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:252
long date
Definition: pgtypes_date.h:9
char * sqldata
Definition: sqlda-native.h:28
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:471
static void ecpg_sqlda_align_add_size(long offset, int alignment, int size, long *current, long *next)
Definition: sqlda.c:33
NumericDigit * digits
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:955
int16 NumericDigit
Definition: numeric.c:102
void ecpg_log(const char *format,...) pg_attribute_printf(1
static int16 value_is_null
Definition: sqlda.c:251
enum COMPAT_MODE compat
Definition: ecpg.c:25
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:206
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:407
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:319
short * sqlind
Definition: sqlda-native.h:29
int i
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:171
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3188
long val
Definition: informix.c:664
unsigned char bool
Definition: c.h:309

◆ ecpg_store_input()

bool ecpg_store_input ( const int  ,
const bool  ,
const struct variable ,
char **  ,
bool   
)

Definition at line 509 of file execute.c.

References ECPGgeneric_varchar::arr, 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(), variable::ind_type, variable::ind_value, ECPGgeneric_varchar::len, 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(), generate_unaccent_rules::str, variable::type, variable::value, and variable::varcharsize.

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

511 {
512  char *mallocedval = NULL;
513  char *newcopy = NULL;
514 
515  /*
516  * arrays are not possible unless the column is an array, too FIXME: we do
517  * not know if the column is an array here array input to singleton column
518  * will result in a runtime error
519  */
520 
521  /*
522  * Some special treatment is needed for records since we want their
523  * contents to arrive in a comma-separated list on insert (I think).
524  */
525 
526  *tobeinserted_p = "";
527 
528  /* check for null value and set input buffer accordingly */
529  switch (var->ind_type)
530  {
531  case ECPGt_short:
533  if (*(short *) var->ind_value < 0)
534  *tobeinserted_p = NULL;
535  break;
536  case ECPGt_int:
537  case ECPGt_unsigned_int:
538  if (*(int *) var->ind_value < 0)
539  *tobeinserted_p = NULL;
540  break;
541  case ECPGt_long:
542  case ECPGt_unsigned_long:
543  if (*(long *) var->ind_value < 0L)
544  *tobeinserted_p = NULL;
545  break;
546  case ECPGt_long_long:
548  if (*(long long int *) var->ind_value < (long long) 0)
549  *tobeinserted_p = NULL;
550  break;
551  case ECPGt_NO_INDICATOR:
552  if (force_indicator == false)
553  {
554  if (ECPGis_noind_null(var->type, var->value))
555  *tobeinserted_p = NULL;
556  }
557  break;
558  default:
559  break;
560  }
561  if (*tobeinserted_p != NULL)
562  {
563  int asize = var->arrsize ? var->arrsize : 1;
564 
565  switch (var->type)
566  {
567  int element;
568 
569  case ECPGt_short:
570  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
571  return false;
572 
573  if (asize > 1)
574  {
575  strcpy(mallocedval, "{");
576 
577  for (element = 0; element < asize; element++)
578  sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
579 
580  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
581  }
582  else
583  sprintf(mallocedval, "%hd", *((short *) var->value));
584 
585  *tobeinserted_p = mallocedval;
586  break;
587 
588  case ECPGt_int:
589  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
590  return false;
591 
592  if (asize > 1)
593  {
594  strcpy(mallocedval, "{");
595 
596  for (element = 0; element < asize; element++)
597  sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
598 
599  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
600  }
601  else
602  sprintf(mallocedval, "%d", *((int *) var->value));
603 
604  *tobeinserted_p = mallocedval;
605  break;
606 
608  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
609  return false;
610 
611  if (asize > 1)
612  {
613  strcpy(mallocedval, "{");
614 
615  for (element = 0; element < asize; element++)
616  sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
617 
618  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
619  }
620  else
621  sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
622 
623  *tobeinserted_p = mallocedval;
624  break;
625 
626  case ECPGt_unsigned_int:
627  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
628  return false;
629 
630  if (asize > 1)
631  {
632  strcpy(mallocedval, "{");
633 
634  for (element = 0; element < asize; element++)
635  sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
636 
637  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
638  }
639  else
640  sprintf(mallocedval, "%u", *((unsigned int *) var->value));
641 
642  *tobeinserted_p = mallocedval;
643  break;
644 
645  case ECPGt_long:
646  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
647  return false;
648 
649  if (asize > 1)
650  {
651  strcpy(mallocedval, "{");
652 
653  for (element = 0; element < asize; element++)
654  sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
655 
656  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
657  }
658  else
659  sprintf(mallocedval, "%ld", *((long *) var->value));
660 
661  *tobeinserted_p = mallocedval;
662  break;
663 
664  case ECPGt_unsigned_long:
665  if (!(mallocedval = ecpg_alloc(asize * 20, lineno)))
666  return false;
667 
668  if (asize > 1)
669  {
670  strcpy(mallocedval, "{");
671 
672  for (element = 0; element < asize; element++)
673  sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
674 
675  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
676  }
677  else
678  sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
679 
680  *tobeinserted_p = mallocedval;
681  break;
682 
683  case ECPGt_long_long:
684  if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
685  return false;
686 
687  if (asize > 1)
688  {
689  strcpy(mallocedval, "{");
690 
691  for (element = 0; element < asize; element++)
692  sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long int *) var->value)[element]);
693 
694  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
695  }
696  else
697  sprintf(mallocedval, "%lld", *((long long int *) var->value));
698 
699  *tobeinserted_p = mallocedval;
700  break;
701 
703  if (!(mallocedval = ecpg_alloc(asize * 30, lineno)))
704  return false;
705 
706  if (asize > 1)
707  {
708  strcpy(mallocedval, "{");
709 
710  for (element = 0; element < asize; element++)
711  sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long int *) var->value)[element]);
712 
713  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
714  }
715  else
716  sprintf(mallocedval, "%llu", *((unsigned long long int *) var->value));
717 
718  *tobeinserted_p = mallocedval;
719  break;
720 
721  case ECPGt_float:
722  if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
723  return false;
724 
725  if (asize > 1)
726  {
727  strcpy(mallocedval, "{");
728 
729  for (element = 0; element < asize; element++)
730  sprintf_float_value(mallocedval + strlen(mallocedval), ((float *) var->value)[element], ",");
731 
732  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
733  }
734  else
735  sprintf_float_value(mallocedval, *((float *) var->value), "");
736 
737  *tobeinserted_p = mallocedval;
738  break;
739 
740  case ECPGt_double:
741  if (!(mallocedval = ecpg_alloc(asize * 25, lineno)))
742  return false;
743 
744  if (asize > 1)
745  {
746  strcpy(mallocedval, "{");
747 
748  for (element = 0; element < asize; element++)
749  sprintf_double_value(mallocedval + strlen(mallocedval), ((double *) var->value)[element], ",");
750 
751  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
752  }
753  else
754  sprintf_double_value(mallocedval, *((double *) var->value), "");
755 
756  *tobeinserted_p = mallocedval;
757  break;
758 
759  case ECPGt_bool:
760  if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("{}"), lineno)))
761  return false;
762 
763  if (var->arrsize > 1)
764  {
765  strcpy(mallocedval, "{");
766 
767  for (element = 0; element < asize; element++)
768  sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f');
769 
770  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
771  }
772  else
773  {
774  if (var->offset == sizeof(char))
775  sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
776  else if (var->offset == sizeof(int))
777  sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
778  else
780  }
781 
782  *tobeinserted_p = mallocedval;
783  break;
784 
785  case ECPGt_char:
786  case ECPGt_unsigned_char:
787  case ECPGt_string:
788  {
789  /* set slen to string length if type is char * */
790  int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : (unsigned int) var->varcharsize;
791 
792  if (!(newcopy = ecpg_alloc(slen + 1, lineno)))
793  return false;
794 
795  strncpy(newcopy, (char *) var->value, slen);
796  newcopy[slen] = '\0';
797 
798  mallocedval = quote_postgres(newcopy, quote, lineno);
799  if (!mallocedval)
800  {
801  ecpg_free(newcopy);
802  return false;
803  }
804 
805  *tobeinserted_p = mallocedval;
806  }
807  break;
808  case ECPGt_const:
809  case ECPGt_char_variable:
810  {
811  int slen = strlen((char *) var->value);
812 
813  if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
814  return false;
815 
816  strncpy(mallocedval, (char *) var->value, slen);
817  mallocedval[slen] = '\0';
818 
819  *tobeinserted_p = mallocedval;
820  }
821  break;
822 
823  case ECPGt_bytea:
824  {
825  struct ECPGgeneric_varchar *variable =
826  (struct ECPGgeneric_varchar *) (var->value);
827 
828  if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno)))
829  return false;
830 
831  memcpy(mallocedval, variable->arr, variable->len);
832  *tobeinserted_p = mallocedval;
833  }
834  break;
835 
836  case ECPGt_varchar:
837  {
838  struct ECPGgeneric_varchar *variable =
839  (struct ECPGgeneric_varchar *) (var->value);
840 
841  if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, lineno)))
842  return false;
843 
844  strncpy(newcopy, variable->arr, variable->len);
845  newcopy[variable->len] = '\0';
846 
847  mallocedval = quote_postgres(newcopy, quote, lineno);
848  if (!mallocedval)
849  {
850  ecpg_free(newcopy);
851  return false;
852  }
853 
854  *tobeinserted_p = mallocedval;
855  }
856  break;
857 
858  case ECPGt_decimal:
859  case ECPGt_numeric:
860  {
861  char *str = NULL;
862  int slen;
863  numeric *nval;
864 
865  if (var->arrsize > 1)
866  mallocedval = ecpg_strdup("{", lineno);
867  else
868  mallocedval = ecpg_strdup("", lineno);
869 
870  if (!mallocedval)
871  return false;
872 
873  for (element = 0; element < asize; element++)
874  {
875  int result;
876 
877  nval = PGTYPESnumeric_new();
878  if (!nval)
879  {
880  ecpg_free(mallocedval);
881  return false;
882  }
883 
884  if (var->type == ECPGt_numeric)
885  result = PGTYPESnumeric_copy(&(((numeric *) (var->value))[element]), nval);
886  else
887  result = PGTYPESnumeric_from_decimal(&(((decimal *) (var->value))[element]), nval);
888 
889  if (result != 0)
890  {
891  PGTYPESnumeric_free(nval);
892  ecpg_free(mallocedval);
893  return false;
894  }
895 
896  str = PGTYPESnumeric_to_asc(nval, nval->dscale);
897  slen = strlen(str);
898  PGTYPESnumeric_free(nval);
899 
900  if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
901  {
902  ecpg_free(mallocedval);
903  ecpg_free(str);
904  return false;
905  }
906  mallocedval = newcopy;
907 
908  /* also copy trailing '\0' */
909  memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
910  if (var->arrsize > 1)
911  strcpy(mallocedval + strlen(mallocedval), ",");
912 
913  ecpg_free(str);
914  }
915 
916  if (var->arrsize > 1)
917  strcpy(mallocedval + strlen(mallocedval) - 1, "}");
918 
919  *tobeinserted_p = mallocedval;
920  }
921  break;
922 
923  case ECPGt_interval:
924  {
925  char *str = NULL;
926  int slen;
927 
928  if (var->arrsize > 1)
929  mallocedval = ecpg_strdup("{", lineno);
930  else
931  mallocedval = ecpg_strdup("", lineno);
932 
933  if (!mallocedval)
934  return false;
935 
936  for (element = 0; element < asize; element++)
937  {
938  str = quote_postgres(PGTYPESinterval_to_asc(&(((interval *) (var->value))[element])), quote, lineno);
939  if (!str)
940  {
941  ecpg_free(mallocedval);
942  return false;