PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
extern.h File Reference
#include "libpq-fe.h"
#include "sqlca.h"
#include "sqlda-native.h"
#include "sqlda-compat.h"
#include "ecpg_config.h"
#include <limits.h>
Include dependency graph for 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  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 ECPG_IS_ARRAY(X)   ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
 
#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_PGSQL = 0,
  ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
}
 
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_free_auto_mem (void)
 
void ecpg_clear_auto_mem (void)
 
struct descriptorecpggetdescp (int, char *)
 
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 *)
 
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)
 

Variables

bool ecpg_internal_regression_mode
 
struct var_listivlist
 

Macro Definition Documentation

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

Definition at line 30 of file extern.h.

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

#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION   "25001"

Definition at line 210 of file extern.h.

Referenced by ECPGnoticeReceiver().

#define ECPG_SQLSTATE_CARDINALITY_VIOLATION   "21000"

Definition at line 208 of file extern.h.

Referenced by ecpg_store_result(), and ECPGget_desc().

#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST   "08003"

Definition at line 206 of file extern.h.

Referenced by ecpg_init(), and ECPGdescribe().

#define ECPG_SQLSTATE_DATATYPE_MISMATCH   "42804"

Definition at line 216 of file extern.h.

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

#define ECPG_SQLSTATE_DUPLICATE_CURSOR   "42P03"

Definition at line 217 of file extern.h.

Referenced by ECPGnoticeReceiver().

#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR   "YE000"
#define ECPG_SQLSTATE_INVALID_CURSOR_NAME   "34000"

Definition at line 214 of file extern.h.

Referenced by ECPGnoticeReceiver().

#define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX   "07009"

Definition at line 204 of file extern.h.

Referenced by ECPGget_desc().

#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME   "33000"

Definition at line 213 of file extern.h.

Referenced by ecpg_find_desc(), and ECPGdeallocate_desc().

#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME   "26000"

Definition at line 212 of file extern.h.

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

#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION   "25P01"

Definition at line 211 of file extern.h.

Referenced by ECPGnoticeReceiver().

#define ECPG_SQLSTATE_NO_DATA   "02000"

Definition at line 200 of file extern.h.

Referenced by ecpg_get_data(), and ecpg_process_output().

#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER   "22002"

Definition at line 209 of file extern.h.

Referenced by ecpg_get_data().

#define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION   "07006"

Definition at line 203 of file extern.h.

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

#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION   "08001"

Definition at line 205 of file extern.h.

Referenced by ECPGconnect().

#define ECPG_SQLSTATE_SYNTAX_ERROR   "42601"

Definition at line 215 of file extern.h.

#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN   "08007"

Definition at line 207 of file extern.h.

#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS   "07001"

Definition at line 201 of file extern.h.

Referenced by ecpg_build_params().

#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS   "07002"

Definition at line 202 of file extern.h.

Referenced by ecpg_process_output().

Enumeration Type Documentation

enum ARRAY_TYPE
Enumerator
ECPG_ARRAY_ERROR 
ECPG_ARRAY_NOT_SET 
ECPG_ARRAY_ARRAY 
ECPG_ARRAY_VECTOR 
ECPG_ARRAY_NONE 

Definition at line 25 of file extern.h.

Enumerator
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 
ECPG_COMPAT_PGSQL 
ECPG_COMPAT_INFORMIX 
ECPG_COMPAT_INFORMIX_SE 

Definition at line 16 of file extern.h.

Function Documentation

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
char* ecpg_alloc ( long  ,
int   
)

Definition at line 19 of file memory.c.

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

Referenced by 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_store_input(), ecpg_type_infocache_push(), ECPGallocate_desc(), ECPGconnect(), ECPGset_desc(), insert_tobeinserted(), prepare_common(), quote_postgres(), and replace_variables().

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
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define NULL
Definition: c.h:229
char* ecpg_auto_alloc ( long  ,
int   
)

Definition at line 108 of file memory.c.

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

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
#define NULL
Definition: c.h:229
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:124
void bool ecpg_auto_prepare ( int  ,
const char *  ,
const int  ,
char **  ,
const char *   
)

Definition at line 468 of file prepare.c.

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

Referenced by ecpg_do_prologue().

469 {
470  int entNo;
471 
472  /* search the statement cache for this statement */
473  entNo = SearchStmtCache(query);
474 
475  /* if not found - add the statement to the cache */
476  if (entNo)
477  {
478  char *stmtID;
479  struct connection *con;
480  struct prepared_statement *prep;
481 
482  ecpg_log("ecpg_auto_prepare on line %d: statement found in cache; entry %d\n", lineno, entNo);
483 
484  stmtID = stmtCacheEntries[entNo].stmtID;
485 
486  con = ecpg_get_connection(connection_name);
487  prep = ecpg_find_prepared_statement(stmtID, con, NULL);
488  /* This prepared name doesn't exist on this connection. */
489  if (!prep && !prepare_common(lineno, con, stmtID, query))
490  return (false);
491 
492  *name = ecpg_strdup(stmtID, lineno);
493  }
494  else
495  {
496  char stmtID[STMTID_SIZE];
497 
498  ecpg_log("ecpg_auto_prepare on line %d: statement not in cache; inserting\n", lineno);
499 
500  /* generate a statement ID */
501  sprintf(stmtID, "ecpg%d", nextStmtID++);
502 
503  if (!ECPGprepare(lineno, connection_name, 0, stmtID, query))
504  return (false);
505  if (AddStmtToCache(lineno, stmtID, connection_name, compat, query) < 0)
506  return (false);
507 
508  *name = ecpg_strdup(stmtID, lineno);
509  }
510 
511  /* increase usage counter */
512  stmtCacheEntries[entNo].execs++;
513 
514  return (true);
515 }
static int SearchStmtCache(const char *ecpgQuery)
Definition: prepare.c:351
Definition: type.h:102
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition: prepare.c:161
long execs
Definition: prepare.c:21
char stmtID[STMTID_SIZE]
Definition: prepare.c:19
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
static int AddStmtToCache(int lineno, const char *stmtID, const char *connection, int compat, const char *ecpgQuery)
Definition: prepare.c:418
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:103
static int nextStmtID
Definition: prepare.c:25
static stmtCacheEntry stmtCacheEntries[16384]
Definition: prepare.c:28
#define NULL
Definition: c.h:229
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:182
const char * name
Definition: encode.c:521
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
#define STMTID_SIZE
Definition: prepare.c:14
bool ecpg_autostart_transaction ( struct statement stmt)

Definition at line 1405 of file execute.c.

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

Referenced by ecpg_do().

1406 {
1408  {
1409  stmt->results = PQexec(stmt->connection->connection, "begin transaction");
1410  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1411  {
1412  ecpg_free_params(stmt, false);
1413  return false;
1414  }
1415  PQclear(stmt->results);
1416  stmt->results = NULL;
1417  }
1418  return true;
1419 }
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1052
PGresult * results
Definition: extern.h:66
bool autocommit
Definition: extern.h:83
struct connection * connection
Definition: extern.h:56
enum COMPAT_MODE compat
Definition: extern.h:57
int lineno
Definition: extern.h:53
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
Definition: fe-connect.c:6052
void PQclear(PGresult *res)
Definition: fe-exec.c:650
PGconn * connection
Definition: extern.h:82
#define NULL
Definition: c.h:229
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:283
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1846
struct sqlda_compat* ecpg_build_compat_sqlda ( int  ,
PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 202 of file sqlda.c.

References sqlda_compat::desc_occ, ecpg_alloc(), ecpg_log(), i, NULL, 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().

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

Definition at line 409 of file sqlda.c.

References sqlname::data, ecpg_alloc(), ecpg_log(), i, sqlname::length, NULL, PQfname(), PQftype(), PQnfields(), 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().

410 {
411  struct sqlda_struct *sqlda;
412  long size;
413  int i;
414 
415  size = sqlda_native_total_size(res, row, compat);
416  sqlda = (struct sqlda_struct *) ecpg_alloc(size, line);
417  if (!sqlda)
418  return NULL;
419 
420  memset(sqlda, 0, size);
421 
422  sprintf(sqlda->sqldaid, "SQLDA ");
423  sqlda->sqld = sqlda->sqln = PQnfields(res);
424  ecpg_log("ecpg_build_native_sqlda on line %d sqld = %d\n", line, sqlda->sqld);
425  sqlda->sqldabc = sizeof(struct sqlda_struct) + (sqlda->sqld - 1) * sizeof(struct sqlvar_struct);
426 
427  for (i = 0; i < sqlda->sqld; i++)
428  {
429  char *fname;
430 
431  sqlda->sqlvar[i].sqltype = sqlda_dynamic_type(PQftype(res, i), compat);
432  fname = PQfname(res, i);
433  sqlda->sqlvar[i].sqlname.length = strlen(fname);
434  strcpy(sqlda->sqlvar[i].sqlname.data, fname);
435  }
436 
437  return sqlda;
438 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
static long sqlda_native_total_size(const PGresult *res, int row, enum COMPAT_MODE compat)
Definition: sqlda.c:183
char * PQfname(const PGresult *res, int field_num)
Definition: fe-exec.c:2759
short length
Definition: sqlda-native.h:20
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
void ecpg_log(const char *format,...) pg_attribute_printf(1
Oid PQftype(const PGresult *res, int field_num)
Definition: fe-exec.c:2911
char sqldaid[8]
Definition: sqlda-native.h:35
char * ecpg_alloc(long, int)
Definition: memory.c:19
enum COMPAT_MODE compat
Definition: ecpg.c:25
#define NULL
Definition: c.h:229
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:105
struct sqlname sqlname
Definition: sqlda-native.h:30
bool ecpg_build_params ( struct statement )

Definition at line 1107 of file execute.c.

References variable::arrsize, statement::command, statement::compat, descriptor::count, descriptor_item::data, ecpg_alloc(), ecpg_find_desc(), 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, ECPGt_char, ECPGt_char_variable, ECPGt_descriptor, ECPGt_int, ECPGt_NO_INDICATOR, ECPGt_short, ECPGt_sqlda, ECPGt_varchar, statement::force_indicator, i, variable::ind_arrsize, variable::ind_offset, variable::ind_pointer, variable::ind_type, variable::ind_value, variable::ind_varcharsize, descriptor_item::indicator, INFORMIX_MODE, statement::inlist, insert_tobeinserted(), descriptor::items, statement::lineno, descriptor_item::next, variable::next, next_insert(), statement::nparams, NULL, descriptor_item::num, variable::offset, statement::paramvalues, variable::pointer, statement::questionmarks, snprintf(), 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, variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_do().

1108 {
1109  struct variable *var;
1110  int desc_counter = 0;
1111  int position = 0;
1112 
1113  /*
1114  * If the type is one of the fill in types then we take the argument and
1115  * enter it to our parameter array at the first position. Then if there
1116  * are any more fill in types we add more parameters.
1117  */
1118  var = stmt->inlist;
1119  while (var)
1120  {
1121  char *tobeinserted;
1122  int counter = 1;
1123 
1124  tobeinserted = NULL;
1125 
1126  /*
1127  * A descriptor is a special case since it contains many variables but
1128  * is listed only once.
1129  */
1130  if (var->type == ECPGt_descriptor)
1131  {
1132  /*
1133  * We create an additional variable list here, so the same logic
1134  * applies.
1135  */
1136  struct variable desc_inlist;
1137  struct descriptor *desc;
1138  struct descriptor_item *desc_item;
1139 
1140  desc = ecpg_find_desc(stmt->lineno, var->pointer);
1141  if (desc == NULL)
1142  return false;
1143 
1144  desc_counter++;
1145  for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
1146  {
1147  if (desc_item->num == desc_counter)
1148  {
1149  desc_inlist.type = ECPGt_char;
1150  desc_inlist.value = desc_item->data;
1151  desc_inlist.pointer = &(desc_item->data);
1152  desc_inlist.varcharsize = strlen(desc_item->data);
1153  desc_inlist.arrsize = 1;
1154  desc_inlist.offset = 0;
1155  if (!desc_item->indicator)
1156  {
1157  desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1158  desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1159  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1160  }
1161  else
1162  {
1163  desc_inlist.ind_type = ECPGt_int;
1164  desc_inlist.ind_value = &(desc_item->indicator);
1165  desc_inlist.ind_pointer = &(desc_inlist.ind_value);
1166  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1167  desc_inlist.ind_offset = 0;
1168  }
1169  if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1170  return false;
1171 
1172  break;
1173  }
1174  }
1175  if (desc->count == desc_counter)
1176  desc_counter = 0;
1177  }
1178  else if (var->type == ECPGt_sqlda)
1179  {
1180  if (INFORMIX_MODE(stmt->compat))
1181  {
1182  struct sqlda_compat *sqlda = *(struct sqlda_compat **) var->pointer;
1183  struct variable desc_inlist;
1184  int i;
1185 
1186  if (sqlda == NULL)
1187  return false;
1188 
1189  desc_counter++;
1190  for (i = 0; i < sqlda->sqld; i++)
1191  {
1192  if (i + 1 == desc_counter)
1193  {
1194  desc_inlist.type = sqlda->sqlvar[i].sqltype;
1195  desc_inlist.value = sqlda->sqlvar[i].sqldata;
1196  desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1197  switch (desc_inlist.type)
1198  {
1199  case ECPGt_char:
1200  case ECPGt_varchar:
1201  desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1202  break;
1203  default:
1204  desc_inlist.varcharsize = 0;
1205  break;
1206  }
1207  desc_inlist.arrsize = 1;
1208  desc_inlist.offset = 0;
1209  if (sqlda->sqlvar[i].sqlind)
1210  {
1211  desc_inlist.ind_type = ECPGt_short;
1212  /* ECPG expects indicator value < 0 */
1213  if (*(sqlda->sqlvar[i].sqlind))
1214  *(sqlda->sqlvar[i].sqlind) = -1;
1215  desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1216  desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1217  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1218  desc_inlist.ind_offset = 0;
1219  }
1220  else
1221  {
1222  desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1223  desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1224  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1225  }
1226  if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1227  return false;
1228 
1229  break;
1230  }
1231  }
1232  if (sqlda->sqld == desc_counter)
1233  desc_counter = 0;
1234  }
1235  else
1236  {
1237  struct sqlda_struct *sqlda = *(struct sqlda_struct **) var->pointer;
1238  struct variable desc_inlist;
1239  int i;
1240 
1241  if (sqlda == NULL)
1242  return false;
1243 
1244  desc_counter++;
1245  for (i = 0; i < sqlda->sqln; i++)
1246  {
1247  if (i + 1 == desc_counter)
1248  {
1249  desc_inlist.type = sqlda->sqlvar[i].sqltype;
1250  desc_inlist.value = sqlda->sqlvar[i].sqldata;
1251  desc_inlist.pointer = &(sqlda->sqlvar[i].sqldata);
1252  switch (desc_inlist.type)
1253  {
1254  case ECPGt_char:
1255  case ECPGt_varchar:
1256  desc_inlist.varcharsize = strlen(sqlda->sqlvar[i].sqldata);
1257  break;
1258  default:
1259  desc_inlist.varcharsize = 0;
1260  break;
1261  }
1262  desc_inlist.arrsize = 1;
1263  desc_inlist.offset = 0;
1264  if (sqlda->sqlvar[i].sqlind)
1265  {
1266  desc_inlist.ind_type = ECPGt_short;
1267  /* ECPG expects indicator value < 0 */
1268  if (*(sqlda->sqlvar[i].sqlind))
1269  *(sqlda->sqlvar[i].sqlind) = -1;
1270  desc_inlist.ind_value = sqlda->sqlvar[i].sqlind;
1271  desc_inlist.ind_pointer = &(sqlda->sqlvar[i].sqlind);
1272  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
1273  desc_inlist.ind_offset = 0;
1274  }
1275  else
1276  {
1277  desc_inlist.ind_type = ECPGt_NO_INDICATOR;
1278  desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
1279  desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
1280  }
1281  if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
1282  return false;
1283 
1284  break;
1285  }
1286  }
1287  if (sqlda->sqln == desc_counter)
1288  desc_counter = 0;
1289  }
1290 
1291  }
1292  else
1293  {
1294  if (!ecpg_store_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
1295  return false;
1296  }
1297 
1298  /*
1299  * now tobeinserted points to an area that contains the next
1300  * parameter; now find the position in the string where it belongs
1301  */
1302  if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
1303  {
1304  /*
1305  * We have an argument but we dont have the matched up placeholder
1306  * in the string
1307  */
1308  ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
1310  NULL);
1311  ecpg_free_params(stmt, false);
1312  return false;
1313  }
1314 
1315  /*
1316  * if var->type=ECPGt_char_variable we have a dynamic cursor we have
1317  * to simulate a dynamic cursor because there is no backend
1318  * functionality for it
1319  */
1320  if (var->type == ECPGt_char_variable)
1321  {
1322  int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
1323 
1324  if (!insert_tobeinserted(position, ph_len, stmt, tobeinserted))
1325  {
1326  ecpg_free_params(stmt, false);
1327  return false;
1328  }
1329  tobeinserted = NULL;
1330  }
1331 
1332  /*
1333  * if the placeholder is '$0' we have to replace it on the client side
1334  * this is for places we want to support variables at that are not
1335  * supported in the backend
1336  */
1337  else if (stmt->command[position] == '0')
1338  {
1339  if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1340  {
1341  ecpg_free_params(stmt, false);
1342  return false;
1343  }
1344  tobeinserted = NULL;
1345  }
1346  else
1347  {
1348  char **paramvalues;
1349 
1350  if (!(paramvalues = (char **) ecpg_realloc(stmt->paramvalues, sizeof(char *) * (stmt->nparams + 1), stmt->lineno)))
1351  {
1352  ecpg_free_params(stmt, false);
1353  return false;
1354  }
1355 
1356  stmt->nparams++;
1357  stmt->paramvalues = paramvalues;
1358  stmt->paramvalues[stmt->nparams - 1] = tobeinserted;
1359 
1360  /* let's see if this was an old style placeholder */
1361  if (stmt->command[position] == '?')
1362  {
1363  /* yes, replace with new style */
1364  int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
1365  * size we need */
1366 
1367  if (!(tobeinserted = (char *) ecpg_alloc(buffersize, stmt->lineno)))
1368  {
1369  ecpg_free_params(stmt, false);
1370  return false;
1371  }
1372 
1373  snprintf(tobeinserted, buffersize, "$%d", counter++);
1374 
1375  if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
1376  {
1377  ecpg_free_params(stmt, false);
1378  return false;
1379  }
1380  tobeinserted = NULL;
1381  }
1382  }
1383 
1384  if (desc_counter == 0)
1385  var = var->next;
1386  }
1387 
1388  /* Check if there are unmatched things left. */
1389  if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
1390  {
1391  ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
1393  ecpg_free_params(stmt, false);
1394  return false;
1395  }
1396 
1397  return true;
1398 }
static bool insert_tobeinserted(int position, int ph_len, struct statement *stmt, char *tobeinserted)
Definition: execute.c:1068
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1052
#define INFORMIX_MODE(X)
Definition: extern.h:23
char * data
Definition: extern.h:102
void * pointer
Definition: extern.h:115
enum ECPGttype type
Definition: extern.h:113
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
#define ECPG_TOO_MANY_ARGUMENTS
Definition: ecpgerrno.h:19
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * sqldata
Definition: sqlda-native.h:28
struct variable * next
Definition: extern.h:125
char * sqldata
Definition: sqlda-compat.h:12
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:799
char * ecpg_alloc(long, int)
Definition: memory.c:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
int count
Definition: extern.h:95
#define NULL
Definition: c.h:229
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
struct descriptor_item * items
Definition: extern.h:96
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS
Definition: extern.h:201
short * sqlind
Definition: sqlda-native.h:29
struct descriptor_item * next
Definition: extern.h:108
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:494
short * sqlind
Definition: sqlda-compat.h:13
static int next_insert(char *text, int pos, bool questionmarks)
Definition: execute.c:111
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40
char * ecpg_realloc(void *, long, int)
Definition: memory.c:33
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, NULL, 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));
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:6097
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:2596
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
void ecpg_log(const char *format,...) pg_attribute_printf(1
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
enum COMPAT_MODE compat
Definition: ecpg.c:25
void PQclear(PGresult *res)
Definition: fe-exec.c:650
int PQendcopy(PGconn *conn)
Definition: fe-exec.c:2522
#define NULL
Definition: c.h:229
char * PQresultErrorMessage(const PGresult *res)
Definition: fe-exec.c:2612
void ecpg_clear_auto_mem ( void  )

Definition at line 158 of file memory.c.

References ecpg_free(), get_auto_allocs, auto_mem::next, NULL, 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);
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
#define NULL
Definition: c.h:229
struct auto_mem * next
Definition: memory.c:68
bool ecpg_deallocate_all_conn ( int  lineno,
enum COMPAT_MODE  c,
struct connection conn 
)

Definition at line 276 of file prepare.c.

References deallocate_one(), NULL, and connection::prep_stmts.

Referenced by ecpg_finish(), and ECPGdeallocate_all().

277 {
278  /* deallocate all prepared statements */
279  while (con->prep_stmts)
280  {
281  if (!deallocate_one(lineno, c, con, NULL, con->prep_stmts))
282  return false;
283  }
284 
285  return true;
286 }
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
Definition: prepare.c:201
char * c
#define NULL
Definition: c.h:229
bool ecpg_do ( const int  ,
const int  ,
const int  ,
const char *  ,
const bool  ,
const int  ,
const char *  ,
va_list   
)

Definition at line 1996 of file execute.c.

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

Referenced by ECPGdo().

1997 {
1998  struct statement *stmt = NULL;
1999 
2000  if (!ecpg_do_prologue(lineno, compat, force_indicator, connection_name,
2002  query, args, &stmt))
2003  goto fail;
2004 
2005  if (!ecpg_build_params(stmt))
2006  goto fail;
2007 
2008  if (!ecpg_autostart_transaction(stmt))
2009  goto fail;
2010 
2011  if (!ecpg_execute(stmt))
2012  goto fail;
2013 
2014  if (!ecpg_process_output(stmt, true))
2015  goto fail;
2016 
2017  ecpg_do_epilogue(stmt);
2018  return true;
2019 
2020 fail:
2021  ecpg_do_epilogue(stmt);
2022  return false;
2023 }
bool ecpg_process_output(struct statement *stmt, bool clear_result)
Definition: execute.c:1474
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1405
ECPG_statement_type
Definition: ecpgtype.h:94
bool ecpg_build_params(struct statement *stmt)
Definition: execute.c:1107
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1426
int lineno
Definition: extern.h:53
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:1747
#define NULL
Definition: c.h:229
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:1979
bool force_indicator
Definition: ecpg.c:18
void ecpg_do_epilogue ( struct statement )

Definition at line 1979 of file execute.c.

References free_statement(), NULL, and statement::oldlocale.

Referenced by ecpg_do(), and ecpg_do_prologue().

1980 {
1981  if (stmt == NULL)
1982  return;
1983 
1984  if (stmt->oldlocale)
1985  setlocale(LC_NUMERIC, stmt->oldlocale);
1986 
1987  free_statement(stmt);
1988 }
static void free_statement(struct statement *stmt)
Definition: execute.c:98
#define NULL
Definition: c.h:229
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 1747 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(), ECPGst_execute, 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, statement::name, connection::name, variable::next, NULL, variable::offset, statement::oldlocale, statement::outlist, variable::pointer, questionmarks, statement::questionmarks, statement::statement_type, variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_do().

1751 {
1752  struct statement *stmt;
1753  struct connection *con;
1754  enum ECPGttype type;
1755  struct variable **list;
1756  char *prepname;
1757 
1758  *stmt_out = NULL;
1759 
1760  if (!query)
1761  {
1763  return false;
1764  }
1765 
1766  stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno);
1767 
1768  if (stmt == NULL)
1769  return false;
1770 
1771  /*
1772  * Make sure we do NOT honor the locale for numeric input/output since the
1773  * database wants the standard decimal point
1774  */
1775  stmt->oldlocale = ecpg_strdup(setlocale(LC_NUMERIC, NULL), lineno);
1776  if (stmt->oldlocale == NULL)
1777  {
1778  ecpg_do_epilogue(stmt);
1779  return false;
1780  }
1781  setlocale(LC_NUMERIC, "C");
1782 
1783 #ifdef ENABLE_THREAD_SAFETY
1784  ecpg_pthreads_init();
1785 #endif
1786 
1787  con = ecpg_get_connection(connection_name);
1788 
1789  if (!ecpg_init(con, connection_name, lineno))
1790  {
1791  ecpg_do_epilogue(stmt);
1792  return false;
1793  }
1794 
1795  /*
1796  * If statement type is ECPGst_prepnormal we are supposed to prepare the
1797  * statement before executing them
1798  */
1800  {
1801  if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query))
1802  {
1803  ecpg_do_epilogue(stmt);
1804  return false;
1805  }
1806 
1807  /*
1808  * statement is now prepared, so instead of the query we have to
1809  * execute the name
1810  */
1811  stmt->command = prepname;
1813  }
1814  else
1815  stmt->command = ecpg_strdup(query, lineno);
1816 
1817  stmt->name = NULL;
1818 
1820  {
1821  /* if we have an EXECUTE command, only the name is send */
1822  char *command = ecpg_prepared(stmt->command, con);
1823 
1824  if (command)
1825  {
1826  stmt->name = stmt->command;
1827  stmt->command = ecpg_strdup(command, lineno);
1828  }
1829  else
1830  {
1832  ecpg_do_epilogue(stmt);
1833  return (false);
1834  }
1835  }
1836 
1837  stmt->connection = con;
1838  stmt->lineno = lineno;
1839  stmt->compat = compat;
1841  stmt->questionmarks = questionmarks;
1843 
1844  /*------
1845  * create a list of variables
1846  *
1847  * The variables are listed with input variables preceding outputvariables
1848  * The end of each group is marked by an end marker. per variable we list:
1849  *
1850  * type - as defined in ecpgtype.h
1851  * value - where to store the data
1852  * varcharsize - length of string in case we have a stringvariable, else 0
1853  * arraysize - 0 for pointer (we don't know the size of the array), 1 for
1854  * simple variable, size for arrays
1855  * offset - offset between ith and (i+1)th entry in an array, normally
1856  * that means sizeof(type)
1857  * ind_type - type of indicator variable
1858  * ind_value - pointer to indicator variable
1859  * ind_varcharsize - empty
1860  * ind_arraysize - arraysize of indicator array
1861  * ind_offset - indicator offset
1862  *------
1863  */
1864 
1865  list = &(stmt->inlist);
1866 
1867  type = va_arg(args, enum ECPGttype);
1868 
1869  while (type != ECPGt_EORT)
1870  {
1871  if (type == ECPGt_EOIT)
1872  list = &(stmt->outlist);
1873  else
1874  {
1875  struct variable *var,
1876  *ptr;
1877 
1878  if (!(var = (struct variable *) ecpg_alloc(sizeof(struct variable), lineno)))
1879  {
1880  ecpg_do_epilogue(stmt);
1881  return false;
1882  }
1883 
1884  var->type = type;
1885  var->pointer = va_arg(args, char *);
1886 
1887  var->varcharsize = va_arg(args, long);
1888  var->arrsize = va_arg(args, long);
1889  var->offset = va_arg(args, long);
1890 
1891  /*
1892  * Unknown array size means pointer to an array. Unknown
1893  * varcharsize usually also means pointer. But if the type is
1894  * character and the array size is known, it is an array of
1895  * pointers to char, so use var->pointer as it is.
1896  */
1897  if (var->arrsize == 0 ||
1898  (var->varcharsize == 0 && ((var->type != ECPGt_char && var->type != ECPGt_unsigned_char) || (var->arrsize <= 1))))
1899  var->value = *((char **) (var->pointer));
1900  else
1901  var->value = var->pointer;
1902 
1903  /*
1904  * negative values are used to indicate an array without given
1905  * bounds
1906  */
1907  /* reset to zero for us */
1908  if (var->arrsize < 0)
1909  var->arrsize = 0;
1910  if (var->varcharsize < 0)
1911  var->varcharsize = 0;
1912 
1913  var->next = NULL;
1914 
1915  var->ind_type = va_arg(args, enum ECPGttype);
1916  var->ind_pointer = va_arg(args, char *);
1917  var->ind_varcharsize = va_arg(args, long);
1918  var->ind_arrsize = va_arg(args, long);
1919  var->ind_offset = va_arg(args, long);
1920 
1921  if (var->ind_type != ECPGt_NO_INDICATOR
1922  && (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
1923  var->ind_value = *((char **) (var->ind_pointer));
1924  else
1925  var->ind_value = var->ind_pointer;
1926 
1927  /*
1928  * negative values are used to indicate an array without given
1929  * bounds
1930  */
1931  /* reset to zero for us */
1932  if (var->ind_arrsize < 0)
1933  var->ind_arrsize = 0;
1934  if (var->ind_varcharsize < 0)
1935  var->ind_varcharsize = 0;
1936 
1937  /* if variable is NULL, the statement hasn't been prepared */
1938  if (var->pointer == NULL)
1939  {
1941  ecpg_free(var);
1942  ecpg_do_epilogue(stmt);
1943  return false;
1944  }
1945 
1946  for (ptr = *list; ptr && ptr->next; ptr = ptr->next)
1947  ;
1948 
1949  if (ptr == NULL)
1950  *list = var;
1951  else
1952  ptr->next = var;
1953  }
1954 
1955  type = va_arg(args, enum ECPGttype);
1956  }
1957 
1958  /* are we connected? */
1959  if (con == NULL || con->connection == NULL)
1960  {
1961  ecpg_raise(lineno, ECPG_NOT_CONN, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (con) ? con->name : ecpg_gettext("<empty>"));
1962  ecpg_do_epilogue(stmt);
1963  return false;
1964  }
1965 
1966  /* initialize auto_mem struct */
1968 
1969  *stmt_out = stmt;
1970 
1971  return true;
1972 }
long ind_arrsize
Definition: extern.h:123
bool ecpg_init(const struct connection *, const char *, const int)
Definition: misc.c:105
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
#define ECPG_NOT_CONN
Definition: ecpgerrno.h:37
void ecpg_free(void *)
Definition: memory.c:13
#define ECPG_INVALID_STMT
Definition: ecpgerrno.h:39
char * name
Definition: extern.h:81
enum ECPG_statement_type statement_type
Definition: extern.h:59
void * pointer
Definition: extern.h:115
enum ECPGttype type
Definition: extern.h:113
char * ecpg_strdup(const char *, int)
Definition: memory.c:47
struct variable * next
Definition: extern.h:125
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
char * oldlocale
Definition: extern.h:63
struct connection * connection
Definition: extern.h:56
enum COMPAT_MODE compat
Definition: extern.h:57
int lineno
Definition: extern.h:53
void * value
Definition: extern.h:114
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:468
void ecpg_clear_auto_mem(void)
Definition: memory.c:158
bool questionmarks
Definition: ecpg.c:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
enum COMPAT_MODE compat
Definition: ecpg.c:25
char * ecpg_prepared(const char *, struct connection *)
Definition: prepare.c:295
#define ecpg_gettext(x)
Definition: ecpglib.h:18
void * ind_pointer
Definition: extern.h:121
long offset
Definition: extern.h:118
char * command
Definition: extern.h:54
struct variable * inlist
Definition: extern.h:61
PGconn * connection
Definition: extern.h:82
#define NULL
Definition: c.h:229
long ind_varcharsize
Definition: extern.h:122
bool force_indicator
Definition: extern.h:58
enum ECPGttype ind_type
Definition: extern.h:119
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
Definition: extern.h:212
char * name
Definition: extern.h:55
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:1979
long ind_offset
Definition: extern.h:124
tuple list
Definition: sort-test.py:11
bool questionmarks
Definition: extern.h:60
long arrsize
Definition: extern.h:117
struct connection * ecpg_get_connection(const char *connection_name)
Definition: connect.c:74
bool force_indicator
Definition: ecpg.c:18
void * ind_value
Definition: extern.h:120
long varcharsize
Definition: extern.h:116
struct variable * outlist
Definition: extern.h:62
ECPGttype
Definition: ecpgtype.h:41
int ecpg_dynamic_type ( Oid  )

Definition at line 71 of file typename.c.

References BOOLOID, BPCHAROID, DATEOID, FLOAT4OID, FLOAT8OID, INT2OID, INT4OID, NUMERICOID, SQL3_BOOLEAN, SQL3_CHARACTER, SQL3_CHARACTER_VARYING, SQL3_DATE_TIME_TIMESTAMP, SQL3_DOUBLE_PRECISION, SQL3_INTEGER, SQL3_NUMERIC, SQL3_REAL, SQL3_SMALLINT, TEXTOID, TIMEOID, TIMESTAMPOID, and VARCHAROID.

Referenced by ecpg_is_type_an_array(), and ECPGget_desc().

72 {
73  switch (type)
74  {
75  case BOOLOID:
76  return SQL3_BOOLEAN; /* bool */
77  case INT2OID:
78  return SQL3_SMALLINT; /* int2 */
79  case INT4OID:
80  return SQL3_INTEGER; /* int4 */
81  case TEXTOID:
82  return SQL3_CHARACTER; /* text */
83  case FLOAT4OID:
84  return SQL3_REAL; /* float4 */
85  case FLOAT8OID:
86  return SQL3_DOUBLE_PRECISION; /* float8 */
87  case BPCHAROID:
88  return SQL3_CHARACTER; /* bpchar */
89  case VARCHAROID:
90  return SQL3_CHARACTER_VARYING; /* varchar */
91  case DATEOID:
92  return SQL3_DATE_TIME_TIMESTAMP; /* date */
93  case TIMEOID:
94  return SQL3_DATE_TIME_TIMESTAMP; /* time */
95  case TIMESTAMPOID:
96  return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
97  case NUMERICOID:
98  return SQL3_NUMERIC; /* numeric */
99  default:
100  return 0;
101  }
102 }
#define TIMEOID
Definition: pg_type.h:514
#define BPCHAROID
Definition: pg_type.h:504
#define DATEOID
Definition: pg_type.h:511
#define TEXTOID
Definition: pg_type.h:324
#define NUMERICOID
Definition: pg_type.h:554
#define INT4OID
Definition: pg_type.h:316
enum ECPGttype type
Definition: extern.h:113
#define TIMESTAMPOID
Definition: pg_type.h:519
#define INT2OID
Definition: pg_type.h:308
#define VARCHAROID
Definition: pg_type.h:507
#define FLOAT4OID
Definition: pg_type.h:416
#define FLOAT8OID
Definition: pg_type.h:419
#define BOOLOID
Definition: pg_type.h:288
bool ecpg_execute ( struct statement stmt)

Definition at line 1426 of file execute.c.

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

Referenced by ecpg_do().

1427 {
1428  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);
1429  if (stmt->statement_type == ECPGst_execute)
1430  {
1431  stmt->results = PQexecPrepared(stmt->connection->connection, stmt->name, stmt->nparams, (const char *const *) stmt->paramvalues, NULL, NULL, 0);
1432  ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
1433  }
1434  else
1435  {
1436  if (stmt->nparams == 0)
1437  {
1438  stmt->results = PQexec(stmt->connection->connection, stmt->command);
1439  ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
1440  }
1441  else
1442  {
1443  stmt->results = PQexecParams(stmt->connection->connection, stmt->command, stmt->nparams, NULL, (const char *const *) stmt->paramvalues, NULL, NULL, 0);
1444  ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
1445  }
1446  }
1447 
1448  ecpg_free_params(stmt, true);
1449 
1450  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1451  return false;
1452 
1453  return true;
1454 }
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:1907
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1052
char * name
Definition: extern.h:81
enum ECPG_statement_type statement_type
Definition: extern.h:59
PGresult * results
Definition: extern.h:66
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct connection * connection
Definition: extern.h:56
enum COMPAT_MODE compat
Definition: extern.h:57
int lineno
Definition: extern.h:53
char * command
Definition: extern.h:54
PGconn * connection
Definition: extern.h:82
#define NULL
Definition: c.h:229
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
Definition: error.c:283
char * name
Definition: extern.h:55
char ** paramvalues
Definition: extern.h:65
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:1860
int nparams
Definition: extern.h:64
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:1846
struct descriptor* ecpg_find_desc ( int  line,
const char *  name 
)

Definition at line 799 of file descriptor.c.

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

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

800 {
801  struct descriptor *desc;
802 
803  for (desc = get_descriptors(); desc; desc = desc->next)
804  {
805  if (strcmp(name, desc->name) == 0)
806  return desc;
807  }
808 
810  return NULL; /* not found */
811 }
#define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME
Definition: extern.h:213
struct descriptor * next
Definition: extern.h:94
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
char * name
Definition: extern.h:92
#define get_descriptors()
Definition: descriptor.c:55
struct prepared_statement* ecpg_find_prepared_statement ( const char *  ,
struct connection ,
struct prepared_statement **   
)

Definition at line 182 of file prepare.c.

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

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

184 {
185  struct prepared_statement *this,
186  *prev;
187 
188  for (this = con->prep_stmts, prev = NULL; this != NULL; prev = this, this = this->next)
189  {
190  if (strcmp(this->name, name) == 0)
191  {
192  if (prev_)
193  *prev_ = prev;
194  return this;
195  }
196  }
197  return NULL;
198 }
struct prepared_statement * next
Definition: extern.h:75
#define NULL
Definition: c.h:229
const char * name
Definition: encode.c:521
void ecpg_free_auto_mem ( void  )
void ecpg_free_params ( struct statement stmt,
bool  print 
)

Definition at line 1052 of file execute.c.

References ecpg_free(), ecpg_log(), statement::lineno, statement::nparams, NULL, and statement::paramvalues.

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

1053 {
1054  int n;
1055 
1056  for (n = 0; n < stmt->nparams; n++)
1057  {
1058  if (print)
1059  ecpg_log("ecpg_free_params on line %d: parameter %d = %s\n", stmt->lineno, n + 1, stmt->paramvalues[n] ? stmt->paramvalues[n] : "null");
1060  ecpg_free(stmt->paramvalues[n]);
1061  }
1062  ecpg_free(stmt->paramvalues);
1063  stmt->paramvalues = NULL;
1064  stmt->nparams = 0;
1065 }
void print(const void *obj)
Definition: print.c:35
void ecpg_free(void *)
Definition: memory.c:13
void ecpg_log(const char *format,...) pg_attribute_printf(1
int lineno
Definition: extern.h:53
#define NULL
Definition: c.h:229
char ** paramvalues
Definition: extern.h:65
int nparams
Definition: extern.h:64
struct connection* ecpg_get_connection ( const char *  )

Definition at line 74 of file connect.c.

References actual_connection, ecpg_get_connection_nr(), NULL, 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
#define NULL
Definition: c.h:229
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
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 121 of file data.c.

References ECPGgeneric_varchar::arr, array_boundary(), array_delimiter(), check_special_value(), ecpg_alloc(), ECPG_ARRAY_ARRAY, ECPG_CONVERT_BOOL, ECPG_DATA_NOT_ARRAY, ECPG_DATE_FORMAT, ECPG_FLOAT_FORMAT, 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_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, free, garbage_left(), INFORMIX_MODE, ECPGgeneric_varchar::len, NULL, 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, and sqlca_t::sqlwarn.

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

125 {
126  struct sqlca_t *sqlca = ECPGget_sqlca();
127  char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
128  int binary = PQfformat(results, act_field);
129  int size = PQgetlength(results, act_tuple, act_field);
130  int value_for_indicator = 0;
131  long log_offset;
132 
133  if (sqlca == NULL)
134  {
137  return (false);
138  }
139 
140  /*
141  * If we are running in a regression test, do not log the offset variable,
142  * it depends on the machine's alignment.
143  */
145  log_offset = -1;
146  else
147  log_offset = offset;
148 
149  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");
150 
151  /* pval is a pointer to the value */
152  if (!pval)
153  {
154  /*
155  * This should never happen because we already checked that we found
156  * at least one tuple, but let's play it safe.
157  */
159  return (false);
160  }
161 
162  /* We will have to decode the value */
163 
164  /*
165  * check for null value and set indicator accordingly, i.e. -1 if NULL and
166  * 0 if not
167  */
168  if (PQgetisnull(results, act_tuple, act_field))
169  value_for_indicator = -1;
170 
171  switch (ind_type)
172  {
173  case ECPGt_short:
175  *((short *) (ind + ind_offset * act_tuple)) = value_for_indicator;
176  break;
177  case ECPGt_int:
178  case ECPGt_unsigned_int:
179  *((int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
180  break;
181  case ECPGt_long:
182  case ECPGt_unsigned_long:
183  *((long *) (ind + ind_offset * act_tuple)) = value_for_indicator;
184  break;
185 #ifdef HAVE_LONG_LONG_INT
186  case ECPGt_long_long:
188  *((long long int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
189  break;
190 #endif /* HAVE_LONG_LONG_INT */
191  case ECPGt_NO_INDICATOR:
192  if (value_for_indicator == -1)
193  {
194  if (force_indicator == false)
195  {
196  /*
197  * Informix has an additional way to specify NULLs note
198  * that this uses special values to denote NULL
199  */
200  ECPGset_noind_null(type, var + offset * act_tuple);
201  }
202  else
203  {
206  NULL);
207  return (false);
208  }
209  }
210  break;
211  default:
214  ecpg_type_name(ind_type));
215  return (false);
216  break;
217  }
218 
219  if (value_for_indicator == -1)
220  return (true);
221 
222  /* let's check if it really is an array if it should be one */
223  if (isarray == ECPG_ARRAY_ARRAY)
224  {
225  if (*pval != '{')
226  {
229  return (false);
230  }
231 
232  switch (type)
233  {
234  case ECPGt_char:
235  case ECPGt_unsigned_char:
236  case ECPGt_varchar:
237  case ECPGt_string:
238  break;
239 
240  default:
241  pval++;
242  break;
243  }
244  }
245 
246  do
247  {
248  if (binary)
249  {
250  if (varcharsize == 0 || varcharsize * offset >= size)
251  memcpy(var + offset * act_tuple, pval, size);
252  else
253  {
254  memcpy(var + offset * act_tuple, pval, varcharsize * offset);
255 
256  if (varcharsize * offset < size)
257  {
258  /* truncation */
259  switch (ind_type)
260  {
261  case ECPGt_short:
263  *((short *) (ind + ind_offset * act_tuple)) = size;
264  break;
265  case ECPGt_int:
266  case ECPGt_unsigned_int:
267  *((int *) (ind + ind_offset * act_tuple)) = size;
268  break;
269  case ECPGt_long:
270  case ECPGt_unsigned_long:
271  *((long *) (ind + ind_offset * act_tuple)) = size;
272  break;
273 #ifdef HAVE_LONG_LONG_INT
274  case ECPGt_long_long:
276  *((long long int *) (ind + ind_offset * act_tuple)) = size;
277  break;
278 #endif /* HAVE_LONG_LONG_INT */
279  default:
280  break;
281  }
282  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
283  }
284  }
285  pval += size;
286  }
287  else
288  {
289  switch (type)
290  {
291  long res;
292  unsigned long ures;
293  double dres;
294  char *scan_length;
295  numeric *nres;
296  date ddres;
297  timestamp tres;
298  interval *ires;
299  char *endptr,
300  endchar;
301 
302  case ECPGt_short:
303  case ECPGt_int:
304  case ECPGt_long:
305  res = strtol(pval, &scan_length, 10);
306  if (garbage_left(isarray, scan_length, compat))
307  {
308  ecpg_raise(lineno, ECPG_INT_FORMAT,
310  return (false);
311  }
312  pval = scan_length;
313 
314  switch (type)
315  {
316  case ECPGt_short:
317  *((short *) (var + offset * act_tuple)) = (short) res;
318  break;
319  case ECPGt_int:
320  *((int *) (var + offset * act_tuple)) = (int) res;
321  break;
322  case ECPGt_long:
323  *((long *) (var + offset * act_tuple)) = (long) res;
324  break;
325  default:
326  /* Cannot happen */
327  break;
328  }
329  break;
330 
332  case ECPGt_unsigned_int:
333  case ECPGt_unsigned_long:
334  ures = strtoul(pval, &scan_length, 10);
335  if (garbage_left(isarray, scan_length, compat))
336  {
339  return (false);
340  }
341  pval = scan_length;
342 
343  switch (type)
344  {
346  *((unsigned short *) (var + offset * act_tuple)) = (unsigned short) ures;
347  break;
348  case ECPGt_unsigned_int:
349  *((unsigned int *) (var + offset * act_tuple)) = (unsigned int) ures;
350  break;
351  case ECPGt_unsigned_long:
352  *((unsigned long *) (var + offset * act_tuple)) = (unsigned long) ures;
353  break;
354  default:
355  /* Cannot happen */
356  break;
357  }
358  break;
359 
360 #ifdef HAVE_LONG_LONG_INT
361 #ifdef HAVE_STRTOLL
362  case ECPGt_long_long:
363  *((long long int *) (var + offset * act_tuple)) = strtoll(pval, &scan_length, 10);
364  if (garbage_left(isarray, scan_length, compat))
365  {
367  return (false);
368  }
369  pval = scan_length;
370 
371  break;
372 #endif /* HAVE_STRTOLL */
373 #ifdef HAVE_STRTOULL
375  *((unsigned long long int *) (var + offset * act_tuple)) = strtoull(pval, &scan_length, 10);
376  if (garbage_left(isarray, scan_length, compat))
377  {
379  return (false);
380  }
381  pval = scan_length;
382 
383  break;
384 #endif /* HAVE_STRTOULL */
385 #endif /* HAVE_LONG_LONG_INT */
386 
387  case ECPGt_float:
388  case ECPGt_double:
389  if (isarray && *pval == '"')
390  pval++;
391 
392  if (!check_special_value(pval, &dres, &scan_length))
393  dres = strtod(pval, &scan_length);
394 
395  if (isarray && *scan_length == '"')
396  scan_length++;
397 
398  if (garbage_left(isarray, scan_length, compat))
399  {
402  return (false);
403  }
404  pval = scan_length;
405 
406  switch (type)
407  {
408  case ECPGt_float:
409  *((float *) (var + offset * act_tuple)) = dres;
410  break;
411  case ECPGt_double:
412  *((double *) (var + offset * act_tuple)) = dres;
413  break;
414  default:
415  /* Cannot happen */
416  break;
417  }
418  break;
419 
420  case ECPGt_bool:
421  if (pval[0] == 'f' && pval[1] == '\0')
422  {
423  *((bool *) (var + offset * act_tuple)) = false;
424  pval++;
425  break;
426  }
427  else if (pval[0] == 't' && pval[1] == '\0')
428  {
429  *((bool *) (var + offset * act_tuple)) = true;
430  pval++;
431  break;
432  }
433  else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
434  {
435  /* NULL is valid */
436  break;
437  }
438 
441  return (false);
442  break;
443 
444  case ECPGt_char:
445  case ECPGt_unsigned_char:
446  case ECPGt_string:
447  {
448  char *str = (char *) (var + offset * act_tuple);
449 
450  /*
451  * If varcharsize is unknown and the offset is that of
452  * char *, then this variable represents the array of
453  * character pointers. So, use extra indirection.
454  */
455  if (varcharsize == 0 && offset == sizeof(char *))
456  str = *(char **) str;
457 
458  if (varcharsize == 0 || varcharsize > size)
459  {
460  strncpy(str, pval, size + 1);
461  /* do the rtrim() */
462  if (type == ECPGt_string)
463  {
464  char *last = str + size;
465 
466  while (last > str && (*last == ' ' || *last == '\0'))
467  {
468  *last = '\0';
469  last--;
470  }
471  }
472  }
473  else
474  {
475  strncpy(str, pval, varcharsize);
476 
477  if (varcharsize < size)
478  {
479  /* truncation */
480  switch (ind_type)
481  {
482  case ECPGt_short:
484  *((short *) (ind + ind_offset * act_tuple)) = size;
485  break;
486  case ECPGt_int:
487  case ECPGt_unsigned_int:
488  *((int *) (ind + ind_offset * act_tuple)) = size;
489  break;
490  case ECPGt_long:
491  case ECPGt_unsigned_long:
492  *((long *) (ind + ind_offset * act_tuple)) = size;
493  break;
494 #ifdef HAVE_LONG_LONG_INT
495  case ECPGt_long_long:
497  *((long long int *) (ind + ind_offset * act_tuple)) = size;
498  break;
499 #endif /* HAVE_LONG_LONG_INT */
500  default:
501  break;
502  }
503  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
504  }
505  }
506  pval += size;
507  }
508  break;
509 
510  case ECPGt_varchar:
511  {
512  struct ECPGgeneric_varchar *variable =
513  (struct ECPGgeneric_varchar *) (var + offset * act_tuple);
514 
515  variable->len = size;
516  if (varcharsize == 0)
517  strncpy(variable->arr, pval, variable->len);
518  else
519  {
520  strncpy(variable->arr, pval, varcharsize);
521 
522  if (variable->len > varcharsize)
523  {
524  /* truncation */
525  switch (ind_type)
526  {
527  case ECPGt_short:
529  *((short *) (ind + ind_offset * act_tuple)) = variable->len;
530  break;
531  case ECPGt_int:
532  case ECPGt_unsigned_int:
533  *((int *) (ind + ind_offset * act_tuple)) = variable->len;
534  break;
535  case ECPGt_long:
536  case ECPGt_unsigned_long:
537  *((long *) (ind + ind_offset * act_tuple)) = variable->len;
538  break;
539 #ifdef HAVE_LONG_LONG_INT
540  case ECPGt_long_long:
542  *((long long int *) (ind + ind_offset * act_tuple)) = variable->len;
543  break;
544 #endif /* HAVE_LONG_LONG_INT */
545  default:
546  break;
547  }
548  sqlca->sqlwarn[0] = sqlca->sqlwarn[1] = 'W';
549 
550  variable->len = varcharsize;
551  }
552  }
553  pval += size;
554  }
555  break;
556 
557  case ECPGt_decimal:
558  case ECPGt_numeric:
559  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '}'; endptr++);
560  endchar = *endptr;
561  *endptr = '\0';
562  nres = PGTYPESnumeric_from_asc(pval, &scan_length);
563  *endptr = endchar;
564 
565  /* did we get an error? */
566  if (nres == NULL)
567  {
568  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
569  lineno, pval, errno);
570 
571  if (INFORMIX_MODE(compat))
572  {
573  /*
574  * Informix wants its own NULL value here instead
575  * of an error
576  */
577  nres = PGTYPESnumeric_new();
578  if (nres)
580  else
581  {
584  return (false);
585  }
586  }
587  else
588  {
591  return (false);
592  }
593  }
594  else
595  {
596  if (!isarray && garbage_left(isarray, scan_length, compat))
597  {
598  free(nres);
601  return (false);
602  }
603  }
604  pval = scan_length;
605 
606  if (type == ECPGt_numeric)
607  PGTYPESnumeric_copy(nres, (numeric *) (var + offset * act_tuple));
608  else
609  PGTYPESnumeric_to_decimal(nres, (decimal *) (var + offset * act_tuple));
610 
611  PGTYPESnumeric_free(nres);
612  break;
613 
614  case ECPGt_interval:
615  if (*pval == '"')
616  pval++;
617 
618  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
619  endchar = *endptr;
620  *endptr = '\0';
621  ires = PGTYPESinterval_from_asc(pval, &scan_length);
622  *endptr = endchar;
623 
624  /* did we get an error? */
625  if (ires == NULL)
626  {
627  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
628  lineno, pval, errno);
629 
630  if (INFORMIX_MODE(compat))
631  {
632  /*
633  * Informix wants its own NULL value here instead
634  * of an error
635  */
636  ires = (interval *) ecpg_alloc(sizeof(interval), lineno);
637  if (!ires)
638  return (false);
639 
641  }
642  else
643  {
646  return (false);
647  }
648  }
649  else
650  {
651  if (*scan_length == '"')
652  scan_length++;
653 
654  if (!isarray && garbage_left(isarray, scan_length, compat))
655  {
656  free(ires);
659  return (false);
660  }
661  }
662  pval = scan_length;
663 
664  PGTYPESinterval_copy(ires, (interval *) (var + offset * act_tuple));
665  free(ires);
666  break;
667 
668  case ECPGt_date:
669  if (*pval == '"')
670  pval++;
671 
672  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
673  endchar = *endptr;
674  *endptr = '\0';
675  ddres = PGTYPESdate_from_asc(pval, &scan_length);
676  *endptr = endchar;
677 
678  /* did we get an error? */
679  if (errno != 0)
680  {
681  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
682  lineno, pval, errno);
683 
684  if (INFORMIX_MODE(compat))
685  {
686  /*
687  * Informix wants its own NULL value here instead
688  * of an error
689  */
691  }
692  else
693  {
696  return (false);
697  }
698  }
699  else
700  {
701  if (*scan_length == '"')
702  scan_length++;
703 
704  if (!isarray && garbage_left(isarray, scan_length, compat))
705  {
708  return (false);
709  }
710  }
711 
712  *((date *) (var + offset * act_tuple)) = ddres;
713  pval = scan_length;
714  break;
715 
716  case ECPGt_timestamp:
717  if (*pval == '"')
718  pval++;
719 
720  for (endptr = pval; *endptr && *endptr != ',' && *endptr != '"' && *endptr != '}'; endptr++);
721  endchar = *endptr;
722  *endptr = '\0';
723  tres = PGTYPEStimestamp_from_asc(pval, &scan_length);
724  *endptr = endchar;
725 
726  /* did we get an error? */
727  if (errno != 0)
728  {
729  ecpg_log("ecpg_get_data on line %d: RESULT %s; errno %d\n",
730  lineno, pval, errno);
731 
732  if (INFORMIX_MODE(compat))
733  {
734  /*
735  * Informix wants its own NULL value here instead
736  * of an error
737  */
739  }
740  else
741  {
744  return (false);
745  }
746  }
747  else
748  {
749  if (*scan_length == '"')
750  scan_length++;
751 
752  if (!isarray && garbage_left(isarray, scan_length, compat))
753  {
756  return (false);
757  }
758  }
759 
760  *((timestamp *) (var + offset * act_tuple)) = tres;
761  pval = scan_length;
762  break;
763 
764  default:
767  ecpg_type_name(type));
768  return (false);
769  break;
770  }
771  if (ECPG_IS_ARRAY(isarray))
772  {
773  bool string = false;
774 
775  /* set array to next entry */
776  ++act_tuple;
777 
778  /* set pval to the next entry */
779 
780  /*
781  * *pval != '\0' should not be needed, but is used as a safety
782  * guard
783  */
784  for (; *pval != '\0' && (string || (!array_delimiter(isarray, *pval) && !array_boundary(isarray, *pval))); ++pval)
785  if (*pval == '"')
786  string = string ? false : true;
787 
788  if (array_delimiter(isarray, *pval))
789  ++pval;
790  }
791  }
792  } while (*pval != '\0' && !array_boundary(isarray, *pval));
793 
794  return (true);
795 }
#define ECPG_DATA_NOT_ARRAY
Definition: ecpgerrno.h:33
int PQgetlength(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3078
date PGTYPESdate_from_asc(char *, char **)
Definition: datetime.c:48
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
Definition: extern.h:216
int PGTYPESnumeric_copy(numeric *, numeric *)
Definition: numeric.c:1475
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
char arr[FLEXIBLE_ARRAY_MEMBER]
Definition: extern.h:36
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
#define INFORMIX_MODE(X)
Definition: extern.h:23
int PGTYPESinterval_copy(interval *, interval *)
Definition: interval.c:1104
#define ECPG_NUMERIC_FORMAT
Definition: ecpgerrno.h:25
#define sqlca
Definition: sqlca.h:59
int64 timestamp
#define ECPG_INTERVAL_FORMAT
Definition: ecpgerrno.h:26
char sqlwarn[8]
Definition: sqlca.h:39
static bool array_delimiter(enum ARRAY_TYPE isarray, char c)
Definition: data.c:21
#define ECPG_CONVERT_BOOL
Definition: ecpgerrno.h:29
int PGTYPESnumeric_to_decimal(numeric *, decimal *)
Definition: numeric.c:1629
static bool array_boundary(enum ARRAY_TYPE isarray, char c)
Definition: data.c:34
long date
Definition: pgtypes_date.h:8
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER
Definition: extern.h:209
#define ECPG_SQLSTATE_NO_DATA
Definition: extern.h:200
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:127
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
#define ECPG_DATE_FORMAT
Definition: ecpgerrno.h:27
const char * ecpg_type_name(enum ECPGttype)
Definition: typename.c:17
Definition: sqlca.h:19
interval * PGTYPESinterval_from_asc(char *, char **)
Definition: interval.c:1021
char * ecpg_alloc(long, int)
Definition: memory.c:19
#define ECPG_FLOAT_FORMAT
Definition: ecpgerrno.h:24
#define ECPG_UNSUPPORTED
Definition: ecpgerrno.h:18
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
enum COMPAT_MODE compat
Definition: ecpg.c:25
bool ecpg_internal_regression_mode
Definition: misc.c:30
#define ECPG_MISSING_INDICATOR
Definition: ecpgerrno.h:31
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
#define ECPG_IS_ARRAY(X)
Definition: extern.h:30
static bool check_special_value(char *ptr, double *retval, char **endptr)
Definition: data.c:96
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static bool garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat)
Definition: data.c:47
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
#define ECPG_TIMESTAMP_FORMAT
Definition: ecpgerrno.h:28
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:3092
int PQfformat(const PGresult *res, int field_num)
Definition: fe-exec.c:2900
timestamp PGTYPEStimestamp_from_asc(char *, char **)
Definition: timestamp.c:209
bool ecpg_init ( const struct connection ,
const char *  ,
const int   
)

Definition at line 105 of file misc.c.

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

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

106 {
107  struct sqlca_t *sqlca = ECPGget_sqlca();
108 
109  if (sqlca == NULL)
110  {
112  NULL);
113  return (false);
114  }
115 
116  ecpg_init_sqlca(sqlca);
117  if (con == NULL)
118  {
120  connection_name ? connection_name : ecpg_gettext("NULL"));
121  return (false);
122  }
123 
124  return (true);
125 }
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:99
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
Definition: extern.h:206
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
Definition: sqlca.h:19
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ecpg_gettext(x)
Definition: ecpglib.h:18
#define NULL
Definition: c.h:229
static struct sqlca_t sqlca
Definition: misc.c:63
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36
void ecpg_init_sqlca ( struct sqlca_t sqlca)

Definition at line 99 of file misc.c.

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

100 {
101  memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
102 }
Definition: sqlca.h:19
static struct sqlca_t sqlca_init
Definition: misc.c:32
char* ecpg_prepared ( const char *  ,
struct connection  
)

Definition at line 295 of file prepare.c.

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

Referenced by ecpg_do_prologue(), and ECPGprepared_statement().

296 {
297  struct prepared_statement *this;
298 
299  this = ecpg_find_prepared_statement(name, con, NULL);
300  return this ? this->stmt->command : NULL;
301 }
struct statement * stmt
Definition: extern.h:74
char * command
Definition: extern.h:54
#define NULL
Definition: c.h:229
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
Definition: prepare.c:182
const char * name
Definition: encode.c:521
bool ecpg_process_output ( struct statement ,
bool   
)

Definition at line 1474 of file execute.c.

References pgNotify::be_pid, buffer, 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, NULL, statement::outlist, PGRES_COMMAND_OK, PGRES_COPY_OUT, PGRES_TUPLES_OK, variable::pointer, PQclear(), PQcmdStatus(), PQcmdTuples(), PQfreemem(), PQgetCopyData(), PQgetResult(), PQnfields(), PQnotifies(), PQntuples(), PQoidValue(), PQresultErrorMessage(), PQresultStatus(), pgNotify::relname, descriptor::result, statement::results, sqlca, sqlca_t::sqlerrd, status(), and variable::type.

Referenced by ecpg_do().

1475 {
1476  struct variable *var;
1477  bool status = false;
1478  char *cmdstat;
1479  PGnotify *notify;
1480  struct sqlca_t *sqlca = ECPGget_sqlca();
1481  int nfields,
1482  ntuples,
1483  act_field;
1484 
1485  if (sqlca == NULL)
1486  {
1487  ecpg_raise(stmt->lineno, ECPG_OUT_OF_MEMORY,
1489  return (false);
1490  }
1491 
1492  var = stmt->outlist;
1493  switch (PQresultStatus(stmt->results))
1494  {
1495  case PGRES_TUPLES_OK:
1496  nfields = PQnfields(stmt->results);
1497  sqlca->sqlerrd[2] = ntuples = PQntuples(stmt->results);
1498 
1499  ecpg_log("ecpg_process_output on line %d: correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
1500  status = true;
1501 
1502  if (ntuples < 1)
1503  {
1504  if (ntuples)
1505  ecpg_log("ecpg_process_output on line %d: incorrect number of matches (%d)\n",
1506  stmt->lineno, ntuples);
1508  status = false;
1509  break;
1510  }
1511 
1512  if (var != NULL && var->type == ECPGt_descriptor)
1513  {
1514  struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
1515 
1516  if (desc == NULL)
1517  status = false;
1518  else
1519  {
1520  if (desc->result)
1521  PQclear(desc->result);
1522  desc->result = stmt->results;
1523  clear_result = false;
1524  ecpg_log("ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
1525  stmt->lineno, PQntuples(stmt->results), (const char *) var->pointer);
1526  }
1527  var = var->next;
1528  }
1529  else if (var != NULL && var->type == ECPGt_sqlda)
1530  {
1531  if (INFORMIX_MODE(stmt->compat))
1532  {
1533  struct sqlda_compat **_sqlda = (struct sqlda_compat **) var->pointer;
1534  struct sqlda_compat *sqlda = *_sqlda;
1535  struct sqlda_compat *sqlda_new;
1536  int i;
1537 
1538  /*
1539  * If we are passed in a previously existing sqlda (chain)
1540  * then free it.
1541  */
1542  while (sqlda)
1543  {
1544  sqlda_new = sqlda->desc_next;
1545  free(sqlda);
1546  sqlda = sqlda_new;
1547  }
1548  *_sqlda = sqlda = sqlda_new = NULL;
1549  for (i = ntuples - 1; i >= 0; i--)
1550  {
1551  /*
1552  * Build a new sqlda structure. Note that only
1553  * fetching 1 record is supported
1554  */
1555  sqlda_new = ecpg_build_compat_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1556 
1557  if (!sqlda_new)
1558  {
1559  /* cleanup all SQLDAs we created up */
1560  while (sqlda)
1561  {
1562  sqlda_new = sqlda->desc_next;
1563  free(sqlda);
1564  sqlda = sqlda_new;
1565  }
1566  *_sqlda = NULL;
1567 
1568  ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1569  status = false;
1570  break;
1571  }
1572  else
1573  {
1574  ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1575 
1576  *_sqlda = sqlda_new;
1577 
1578  ecpg_set_compat_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1579  ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1580  stmt->lineno, PQnfields(stmt->results));
1581 
1582  sqlda_new->desc_next = sqlda;
1583  sqlda = sqlda_new;
1584  }
1585  }
1586  }
1587  else
1588  {
1589  struct sqlda_struct **_sqlda = (struct sqlda_struct **) var->pointer;
1590  struct sqlda_struct *sqlda = *_sqlda;
1591  struct sqlda_struct *sqlda_new;
1592  int i;
1593 
1594  /*
1595  * If we are passed in a previously existing sqlda (chain)
1596  * then free it.
1597  */
1598  while (sqlda)
1599  {
1600  sqlda_new = sqlda->desc_next;
1601  free(sqlda);
1602  sqlda = sqlda_new;
1603  }
1604  *_sqlda = sqlda = sqlda_new = NULL;
1605  for (i = ntuples - 1; i >= 0; i--)
1606  {
1607  /*
1608  * Build a new sqlda structure. Note that only
1609  * fetching 1 record is supported
1610  */
1611  sqlda_new = ecpg_build_native_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1612 
1613  if (!sqlda_new)
1614  {
1615  /* cleanup all SQLDAs we created up */
1616  while (sqlda)
1617  {
1618  sqlda_new = sqlda->desc_next;
1619  free(sqlda);
1620  sqlda = sqlda_new;
1621  }
1622  *_sqlda = NULL;
1623 
1624  ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1625  status = false;
1626  break;
1627  }
1628  else
1629  {
1630  ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1631 
1632  *_sqlda = sqlda_new;
1633 
1634  ecpg_set_native_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1635  ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1636  stmt->lineno, PQnfields(stmt->results));
1637 
1638  sqlda_new->desc_next = sqlda;
1639  sqlda = sqlda_new;
1640  }
1641  }
1642  }
1643 
1644  var = var->next;
1645  }
1646  else
1647  for (act_field = 0; act_field < nfields && status; act_field++)
1648  {
1649  if (var != NULL)
1650  {
1651  status = ecpg_store_result(stmt->results, act_field, stmt, var);
1652  var = var->next;
1653  }
1654  else if (!INFORMIX_MODE(stmt->compat))
1655  {
1657  return (false);
1658  }
1659  }
1660 
1661  if (status && var != NULL)
1662  {
1664  status = false;
1665  }
1666 
1667  break;
1668  case PGRES_COMMAND_OK:
1669  status = true;
1670  cmdstat = PQcmdStatus(stmt->results);
1671  sqlca->sqlerrd[1] = PQoidValue(stmt->results);
1672  sqlca->sqlerrd[2] = atol(PQcmdTuples(stmt->results));
1673  ecpg_log("ecpg_process_output on line %d: OK: %s\n", stmt->lineno, cmdstat);
1674  if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
1675  !sqlca->sqlerrd[2] &&
1676  (strncmp(cmdstat, "UPDATE", 6) == 0
1677  || strncmp(cmdstat, "INSERT", 6) == 0
1678  || strncmp(cmdstat, "DELETE", 6) == 0))
1680  break;
1681  case PGRES_COPY_OUT:
1682  {
1683  char *buffer;
1684  int res;
1685 
1686  ecpg_log("ecpg_process_output on line %d: COPY OUT data transfer in progress\n", stmt->lineno);
1687  while ((res = PQgetCopyData(stmt->connection->connection,
1688  &buffer, 0)) > 0)
1689  {
1690  printf("%s", buffer);
1691  PQfreemem(buffer);
1692  }
1693  if (res == -1)
1694  {
1695  /* COPY done */
1696  PQclear(stmt->results);
1697  stmt->results = PQgetResult(stmt->connection->connection);
1698  if (PQresultStatus(stmt->results) == PGRES_COMMAND_OK)
1699  ecpg_log("ecpg_process_output on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
1700  else
1701  ecpg_log("ecpg_process_output on line %d: got error after PGRES_COPY_OUT: %s", stmt->lineno, PQresultErrorMessage(stmt->results));
1702  }
1703  break;
1704  }
1705  default:
1706 
1707  /*
1708  * execution should never reach this code because it is already
1709  * handled in ECPGcheck_PQresult()
1710  */
1711  ecpg_log("ecpg_process_output on line %d: unknown execution status type\n",
1712  stmt->lineno);
1713  ecpg_raise_backend(stmt->lineno, stmt->results, stmt->connection->connection, stmt->compat);
1714  status = false;
1715  break;
1716  }
1717 
1718  if (clear_result)
1719  {
1720  PQclear(stmt->results);
1721  stmt->results = NULL;
1722  }
1723 
1724  /* check for asynchronous returns */
1725  notify = PQnotifies(stmt->connection->connection);
1726  if (notify)
1727  {
1728  ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
1729  stmt->lineno, notify->relname, notify->be_pid);
1730  PQfreemem(notify);
1731  }
1732 
1733  return status;
1734 }
int PQnfields(const PGresult *res)
Definition: fe-exec.c:2681
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
Definition: execute.c:309
PGnotify * PQnotifies(PGconn *conn)
Definition: fe-exec.c:2193
#define INFORMIX_MODE(X)
Definition: extern.h:23
#define sqlca
Definition: sqlca.h:59
char * PQcmdTuples(PGresult *res)
Definition: fe-exec.c:3014
Oid PQoidValue(const PGresult *res)
Definition: fe-exec.c:2985
void * pointer
Definition: extern.h:115
enum ECPGttype type
Definition: extern.h:113
#define ECPG_TOO_MANY_ARGUMENTS
Definition: ecpgerrno.h:19
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
struct variable * next
Definition: extern.h:125
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2673
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:2596
int PQgetCopyData(PGconn *conn, char **buffer, int async)
Definition: fe-exec.c:2377
#define ECPG_SQLSTATE_NO_DATA
Definition: extern.h:200
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS
Definition: extern.h:202
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
Definition: error.c:219
void ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:252
int be_pid
Definition: libpq-fe.h:164
Definition: sqlca.h:19
struct descriptor * ecpg_find_desc(int line, const char *name)
Definition: descriptor.c:799
PGresult * result
Definition: extern.h:93
char * relname
Definition: libpq-fe.h:163
long sqlerrd[6]
Definition: sqlca.h:30
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define ECPG_NOT_FOUND
Definition: ecpgerrno.h:10
char * PQcmdStatus(PGresult *res)
Definition: fe-exec.c:2944
struct sqlda_compat * ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:202
struct sqlda_struct * ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:409
void PQclear(PGresult *res)
Definition: fe-exec.c:650
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
char * PQresultErrorMessage(const PGresult *res)
Definition: fe-exec.c:2612
int i
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
void ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE)
Definition: sqlda.c:441
void PQfreemem(void *ptr)
Definition: fe-exec.c:3200
PGresult * PQgetResult(PGconn *conn)
Definition: fe-exec.c:1702
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(), NULL, 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
struct sqlca_t::@124 sqlerrm
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
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define ECPG_UINT_FORMAT
Definition: ecpgerrno.h:23
#define ECPG_EMPTY
Definition: ecpgerrno.h:30
#define ECPG_TRANS
Definition: ecpgerrno.h:50
void ecpg_log(const char *format,...) pg_attribute_printf(1
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
#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
#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_gettext(x)
Definition: ecpglib.h:18
#define ECPG_VAR_NOT_NUMERIC
Definition: ecpgerrno.h:45
#define ECPG_UNKNOWN_DESCRIPTOR
Definition: ecpgerrno.h:42
#define NULL
Definition: c.h:229
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
#define ECPG_INT_FORMAT
Definition: ecpgerrno.h:22
#define ECPG_NO_CONN
Definition: ecpgerrno.h:36
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, NULL, 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:6097
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:58
struct sqlca_t::@124 sqlerrm
void ECPGfree_auto_mem(void)
Definition: memory.c:138
#define INFORMIX_MODE(X)
Definition: extern.h:23
#define sqlca
Definition: sqlca.h:59
int sqlerrml
Definition: sqlca.h:26
#define ECPG_PGSQL
Definition: ecpgerrno.h:49
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:57
void ecpg_log(const char *format,...) pg_attribute_printf(1
struct sqlca_t * ECPGget_sqlca(void)
Definition: misc.c:142
#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
enum COMPAT_MODE compat
Definition: ecpg.c:25
long sqlcode
Definition: sqlca.h:23
#define ecpg_gettext(x)
Definition: ecpglib.h:18
char * PQresultErrorField(const PGresult *res, int fieldcode)
Definition: fe-exec.c:2658
#define NULL
Definition: c.h:229
#define ECPG_DUPLICATE_KEY
Definition: ecpgerrno.h:52
#define ECPG_INFORMIX_SUBSELECT_NOT_ONE
Definition: ecpgerrno.h:58
char sqlerrmc[SQLERRMC_LEN]
Definition: sqlca.h:27
ConnStatusType PQstatus(const PGconn *conn)
Definition: fe-connect.c:6044
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, NULL, 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 }
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define NULL
Definition: c.h:229
#define realloc(a, b)
Definition: header.h:60
void ecpg_set_compat_sqlda ( int  ,
struct sqlda_compat **  ,
const PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 252 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, NULL, 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().

253 {
254  struct sqlda_compat *sqlda = (*_sqlda);
255  int i;
256  long offset,
257  next_offset;
258 
259  if (row < 0)
260  return;
261 
262  /* Offset for the first field value */
263  offset = sqlda_compat_empty_size(res);
264 
265  /*
266  * Set sqlvar[i]->sqldata pointers and convert values to correct format
267  */
268  for (i = 0; i < sqlda->sqld; i++)
269  {
270  int isnull;
271  int datalen;
272  bool set_data = true;
273 
274  switch (sqlda->sqlvar[i].sqltype)
275  {
276  case ECPGt_short:
278  ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
279  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
280  sqlda->sqlvar[i].sqllen = sizeof(short);
281  break;
282  case ECPGt_int:
283  case ECPGt_unsigned_int:
284  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
285  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
286  sqlda->sqlvar[i].sqllen = sizeof(int);
287  break;
288  case ECPGt_long:
289  case ECPGt_unsigned_long:
290  ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
291  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
292  sqlda->sqlvar[i].sqllen = sizeof(long);
293  break;
294  case ECPGt_long_long:
296  ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
297  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
298  sqlda->sqlvar[i].sqllen = sizeof(long long);
299  break;
300  case ECPGt_bool:
301  ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
302  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
303  sqlda->sqlvar[i].sqllen = sizeof(bool);
304  break;
305  case ECPGt_float:
306  ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
307  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
308  sqlda->sqlvar[i].sqllen = sizeof(float);
309  break;
310  case ECPGt_double:
311  ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
312  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
313  sqlda->sqlvar[i].sqllen = sizeof(double);
314  break;
315  case ECPGt_decimal:
316  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
317  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
318  sqlda->sqlvar[i].sqllen = sizeof(decimal);
319  break;
320  case ECPGt_numeric:
321  {
322  numeric *num;
323  char *val;
324 
325  set_data = false;
326 
327  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
328  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
329  sqlda->sqlvar[i].sqllen = sizeof(numeric);
330 
331  if (PQgetisnull(res, row, i))
332  {
334  break;
335  }
336 
337  val = PQgetvalue(res, row, i);
338  num = PGTYPESnumeric_from_asc(val, NULL);
339  if (!num)
340  {
342  break;
343  }
344 
345  memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
346 
347  if (num->ndigits)
348  {
349  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
350  memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
351 
352  ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
353  ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
354  }
355 
356  PGTYPESnumeric_free(num);
357 
358  break;
359  }
360  case ECPGt_date:
361  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
362  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
363  sqlda->sqlvar[i].sqllen = sizeof(date);
364  break;
365  case ECPGt_timestamp:
366  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
367  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
368  sqlda->sqlvar[i].sqllen = sizeof(timestamp);
369  break;
370  case ECPGt_interval:
371  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
372  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
373  sqlda->sqlvar[i].sqllen = sizeof(interval);
374  break;
375  case ECPGt_char:
376  case ECPGt_unsigned_char:
377  case ECPGt_string:
378  default:
379  datalen = strlen(PQgetvalue(res, row, i)) + 1;
380  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
381  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
382  sqlda->sqlvar[i].sqllen = datalen;
383  if (datalen > 32768)
384  sqlda->sqlvar[i].sqlilongdata = sqlda->sqlvar[i].sqldata;
385  break;
386  }
387 
388  isnull = PQgetisnull(res, row, i);
389  ecpg_log("ecpg_set_compat_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
390  sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
391  sqlda->sqlvar[i].sqlitype = ECPGt_short;
392  sqlda->sqlvar[i].sqlilen = sizeof(short);
393  if (!isnull)
394  {
395  if (set_data)
396  ecpg_get_data(res, row, i, lineno,
397  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
398  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
399  ECPG_ARRAY_NONE, compat, false);
400  }
401  else
402  ECPGset_noind_null(sqlda->sqlvar[i].sqltype, sqlda->sqlvar[i].sqldata);
403 
404  offset = next_offset;
405  }
406 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
int64 timestamp
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:249
long date
Definition: pgtypes_date.h:8
char bool
Definition: c.h:202
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
void ecpg_log(const char *format,...) pg_attribute_printf(1
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:933
int16 NumericDigit
Definition: numeric.c:99
static int16 value_is_null
Definition: sqlda.c:248
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:121
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define NULL
Definition: c.h:229
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
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:3092
long val
Definition: informix.c:689
struct sqlvar_compat * sqlvar
Definition: sqlda-compat.h:40
void ecpg_set_native_sqlda ( int  ,
struct sqlda_struct **  ,
const PGresult ,
int  ,
enum  COMPAT_MODE 
)

Definition at line 441 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, NULL, 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().

442 {
443  struct sqlda_struct *sqlda = (*_sqlda);
444  int i;
445  long offset,
446  next_offset;
447 
448  if (row < 0)
449  return;
450 
451  /* Offset for the first field value */
452  offset = sqlda_native_empty_size(res);
453 
454  /*
455  * Set sqlvar[i]->sqldata pointers and convert values to correct format
456  */
457  for (i = 0; i < sqlda->sqld; i++)
458  {
459  int isnull;
460  int datalen;
461  bool set_data = true;
462 
463  switch (sqlda->sqlvar[i].sqltype)
464  {
465  case ECPGt_short:
467  ecpg_sqlda_align_add_size(offset, sizeof(short), sizeof(short), &offset, &next_offset);
468  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
469  sqlda->sqlvar[i].sqllen = sizeof(short);
470  break;
471  case ECPGt_int:
472  case ECPGt_unsigned_int:
473  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(int), &offset, &next_offset);
474  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
475  sqlda->sqlvar[i].sqllen = sizeof(int);
476  break;
477  case ECPGt_long:
478  case ECPGt_unsigned_long:
479  ecpg_sqlda_align_add_size(offset, sizeof(long), sizeof(long), &offset, &next_offset);
480  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
481  sqlda->sqlvar[i].sqllen = sizeof(long);
482  break;
483  case ECPGt_long_long:
485  ecpg_sqlda_align_add_size(offset, sizeof(long long), sizeof(long long), &offset, &next_offset);
486  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
487  sqlda->sqlvar[i].sqllen = sizeof(long long);
488  break;
489  case ECPGt_bool:
490  ecpg_sqlda_align_add_size(offset, sizeof(bool), sizeof(bool), &offset, &next_offset);
491  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
492  sqlda->sqlvar[i].sqllen = sizeof(bool);
493  break;
494  case ECPGt_float:
495  ecpg_sqlda_align_add_size(offset, sizeof(float), sizeof(float), &offset, &next_offset);
496  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
497  sqlda->sqlvar[i].sqllen = sizeof(float);
498  break;
499  case ECPGt_double:
500  ecpg_sqlda_align_add_size(offset, sizeof(double), sizeof(double), &offset, &next_offset);
501  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
502  sqlda->sqlvar[i].sqllen = sizeof(double);
503  break;
504  case ECPGt_decimal:
505  ecpg_sqlda_align_add_size(offset, sizeof(int), sizeof(decimal), &offset, &next_offset);
506  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
507  sqlda->sqlvar[i].sqllen = sizeof(decimal);
508  break;
509  case ECPGt_numeric:
510  {
511  numeric *num;
512  char *val;
513 
514  set_data = false;
515 
516  ecpg_sqlda_align_add_size(offset, sizeof(NumericDigit *), sizeof(numeric), &offset, &next_offset);
517  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
518  sqlda->sqlvar[i].sqllen = sizeof(numeric);
519 
520  if (PQgetisnull(res, row, i))
521  {
523  break;
524  }
525 
526  val = PQgetvalue(res, row, i);
527  num = PGTYPESnumeric_from_asc(val, NULL);
528  if (!num)
529  {
531  break;
532  }
533 
534  memcpy(sqlda->sqlvar[i].sqldata, num, sizeof(numeric));
535 
536  if (num->ndigits)
537  {
538  ecpg_sqlda_align_add_size(next_offset, sizeof(int), num->ndigits + 1, &offset, &next_offset);
539  memcpy((char *) sqlda + offset, num->buf, num->ndigits + 1);
540 
541  ((numeric *) sqlda->sqlvar[i].sqldata)->buf = (NumericDigit *) sqlda + offset;
542  ((numeric *) sqlda->sqlvar[i].sqldata)->digits = (NumericDigit *) sqlda + offset + (num->digits - num->buf);
543  }
544 
545  PGTYPESnumeric_free(num);
546 
547  break;
548  }
549  case ECPGt_date:
550  ecpg_sqlda_align_add_size(offset, sizeof(date), sizeof(date), &offset, &next_offset);
551  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
552  sqlda->sqlvar[i].sqllen = sizeof(date);
553  break;
554  case ECPGt_timestamp:
555  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(timestamp), &offset, &next_offset);
556  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
557  sqlda->sqlvar[i].sqllen = sizeof(timestamp);
558  break;
559  case ECPGt_interval:
560  ecpg_sqlda_align_add_size(offset, sizeof(int64), sizeof(interval), &offset, &next_offset);
561  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
562  sqlda->sqlvar[i].sqllen = sizeof(interval);
563  break;
564  case ECPGt_char:
565  case ECPGt_unsigned_char:
566  case ECPGt_string:
567  default:
568  datalen = strlen(PQgetvalue(res, row, i)) + 1;
569  ecpg_sqlda_align_add_size(offset, sizeof(int), datalen, &offset, &next_offset);
570  sqlda->sqlvar[i].sqldata = (char *) sqlda + offset;
571  sqlda->sqlvar[i].sqllen = datalen;
572  break;
573  }
574 
575  isnull = PQgetisnull(res, row, i);
576  ecpg_log("ecpg_set_native_sqlda on line %d row %d col %d %s\n", lineno, row, i, isnull ? "IS NULL" : "IS NOT NULL");
577  sqlda->sqlvar[i].sqlind = isnull ? &value_is_null : &value_is_not_null;
578  if (!isnull)
579  {
580  if (set_data)
581  ecpg_get_data(res, row, i, lineno,
582  sqlda->sqlvar[i].sqltype, ECPGt_NO_INDICATOR,
583  sqlda->sqlvar[i].sqldata, NULL, 0, 0, 0,
584  ECPG_ARRAY_NONE, compat, false);
585  }
586 
587  offset = next_offset;
588  }
589 }
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3067
int64 timestamp
struct sqlvar_struct sqlvar[1]
Definition: sqlda-native.h:40
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:249
long date
Definition: pgtypes_date.h:8
char * sqldata
Definition: sqlda-native.h:28
char bool
Definition: c.h:202
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:470
void ecpg_log(const char *format,...) pg_attribute_printf(1
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:933
int16 NumericDigit
Definition: numeric.c:99
static int16 value_is_null
Definition: sqlda.c:248
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:121
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define NULL
Definition: c.h:229
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:320
short * sqlind
Definition: sqlda-native.h:29
int i
static long sqlda_native_empty_size(const PGresult *res)
Definition: sqlda.c:168
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3092
long val
Definition: informix.c:689
bool ecpg_store_input ( const int  ,
const bool  ,
const struct variable ,
char **  ,
bool   
)

Definition at line 494 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_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, NULL, 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(), result, sprintf_double_value(), sprintf_float_value(), variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_build_params(), and ECPGset_desc().

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

Definition at line 309 of file execute.c.

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

Referenced by ecpg_process_output(), and ECPGget_desc().

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