PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
extern.h File Reference
#include "postgres_fe.h"
#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:50
#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:226
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:226
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:103
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:226
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 1406 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().

1407 {
1409  {
1410  stmt->results = PQexec(stmt->connection->connection, "begin transaction");
1411  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1412  {
1413  ecpg_free_params(stmt, false);
1414  return false;
1415  }
1416  PQclear(stmt->results);
1417  stmt->results = NULL;
1418  }
1419  return true;
1420 }
void ecpg_free_params(struct statement *stmt, bool print)
Definition: execute.c:1053
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:5915
void PQclear(PGresult *res)
Definition: fe-exec.c:650
PGconn * connection
Definition: extern.h:82
#define NULL
Definition: c.h:226
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:226
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:106
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:226
char data[NAMEDATALEN]
Definition: sqlda-native.h:21
int i
int sqlda_dynamic_type(Oid, enum COMPAT_MODE)
Definition: typename.c:106
struct sqlname sqlname
Definition: sqlda-native.h:30
bool ecpg_build_params ( struct statement )

Definition at line 1108 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().

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

Definition at line 1997 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().

1998 {
1999  struct statement *stmt = NULL;
2000 
2001  if (!ecpg_do_prologue(lineno, compat, force_indicator, connection_name,
2003  query, args, &stmt))
2004  goto fail;
2005 
2006  if (!ecpg_build_params(stmt))
2007  goto fail;
2008 
2009  if (!ecpg_autostart_transaction(stmt))
2010  goto fail;
2011 
2012  if (!ecpg_execute(stmt))
2013  goto fail;
2014 
2015  if (!ecpg_process_output(stmt, true))
2016  goto fail;
2017 
2018  ecpg_do_epilogue(stmt);
2019  return true;
2020 
2021 fail:
2022  ecpg_do_epilogue(stmt);
2023  return false;
2024 }
bool ecpg_process_output(struct statement *stmt, bool clear_result)
Definition: execute.c:1475
bool ecpg_autostart_transaction(struct statement *stmt)
Definition: execute.c:1406
ECPG_statement_type
Definition: ecpgtype.h:94
bool ecpg_build_params(struct statement *stmt)
Definition: execute.c:1108
bool ecpg_execute(struct statement *stmt)
Definition: execute.c:1427
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:1748
#define NULL
Definition: c.h:226
void ecpg_do_epilogue(struct statement *stmt)
Definition: execute.c:1980
bool force_indicator
Definition: ecpg.c:18
void ecpg_do_epilogue ( struct statement )

Definition at line 1980 of file execute.c.

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

Referenced by ecpg_do(), and ecpg_do_prologue().

1981 {
1982  if (stmt == NULL)
1983  return;
1984 
1985  if (stmt->oldlocale)
1986  setlocale(LC_NUMERIC, stmt->oldlocale);
1987 
1988  free_statement(stmt);
1989 }
static void free_statement(struct statement *stmt)
Definition: execute.c:99
#define NULL
Definition: c.h:226
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 1748 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().

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

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

Definition at line 1427 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().

1428 {
1429  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);
1430  if (stmt->statement_type == ECPGst_execute)
1431  {
1432  stmt->results = PQexecPrepared(stmt->connection->connection, stmt->name, stmt->nparams, (const char *const *) stmt->paramvalues, NULL, NULL, 0);
1433  ecpg_log("ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n", stmt->lineno, stmt->command);
1434  }
1435  else
1436  {
1437  if (stmt->nparams == 0)
1438  {
1439  stmt->results = PQexec(stmt->connection->connection, stmt->command);
1440  ecpg_log("ecpg_execute on line %d: using PQexec\n", stmt->lineno);
1441  }
1442  else
1443  {
1444  stmt->results = PQexecParams(stmt->connection->connection, stmt->command, stmt->nparams, NULL, (const char *const *) stmt->paramvalues, NULL, NULL, 0);
1445  ecpg_log("ecpg_execute on line %d: using PQexecParams\n", stmt->lineno);
1446  }
1447  }
1448 
1449  ecpg_free_params(stmt, true);
1450 
1451  if (!ecpg_check_PQresult(stmt->results, stmt->lineno, stmt->connection->connection, stmt->compat))
1452  return false;
1453 
1454  return true;
1455 }
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:1053
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:226
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:226
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:226
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 1053 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().

1054 {
1055  int n;
1056 
1057  for (n = 0; n < stmt->nparams; n++)
1058  {
1059  if (print)
1060  ecpg_log("ecpg_free_params on line %d: parameter %d = %s\n", stmt->lineno, n + 1, stmt->paramvalues[n] ? stmt->paramvalues[n] : "null");
1061  ecpg_free(stmt->paramvalues[n]);
1062  }
1063  ecpg_free(stmt->paramvalues);
1064  stmt->paramvalues = NULL;
1065  stmt->nparams = 0;
1066 }
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:226
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:46
int pthread_mutex_unlock(pthread_mutex_t *mp)
Definition: pthread-win32.c:55
#define NULL
Definition: c.h:226
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:30
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 123 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().

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

References pgNotify::be_pid, statement::compat, statement::connection, connection::connection, ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), ECPG_COMPAT_INFORMIX_SE, ecpg_find_desc(), ecpg_log(), ECPG_NOT_FOUND, ECPG_OUT_OF_MEMORY, ecpg_raise(), ecpg_raise_backend(), ecpg_set_compat_sqlda(), ecpg_set_native_sqlda(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_NO_DATA, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, ecpg_store_result(), ECPG_TOO_FEW_ARGUMENTS, ECPG_TOO_MANY_ARGUMENTS, ECPGget_sqlca(), ECPGt_descriptor, ECPGt_sqlda, free, i, INFORMIX_MODE, statement::lineno, variable::next, 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().

1476 {
1477  struct variable *var;
1478  bool status = false;
1479  char *cmdstat;
1480  PGnotify *notify;
1481  struct sqlca_t *sqlca = ECPGget_sqlca();
1482  int nfields,
1483  ntuples,
1484  act_field;
1485 
1486  if (sqlca == NULL)
1487  {
1488  ecpg_raise(stmt->lineno, ECPG_OUT_OF_MEMORY,
1490  return (false);
1491  }
1492 
1493  var = stmt->outlist;
1494  switch (PQresultStatus(stmt->results))
1495  {
1496  case PGRES_TUPLES_OK:
1497  nfields = PQnfields(stmt->results);
1498  sqlca->sqlerrd[2] = ntuples = PQntuples(stmt->results);
1499 
1500  ecpg_log("ecpg_process_output on line %d: correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
1501  status = true;
1502 
1503  if (ntuples < 1)
1504  {
1505  if (ntuples)
1506  ecpg_log("ecpg_process_output on line %d: incorrect number of matches (%d)\n",
1507  stmt->lineno, ntuples);
1509  status = false;
1510  break;
1511  }
1512 
1513  if (var != NULL && var->type == ECPGt_descriptor)
1514  {
1515  struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
1516 
1517  if (desc == NULL)
1518  status = false;
1519  else
1520  {
1521  if (desc->result)
1522  PQclear(desc->result);
1523  desc->result = stmt->results;
1524  clear_result = false;
1525  ecpg_log("ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
1526  stmt->lineno, PQntuples(stmt->results), (const char *) var->pointer);
1527  }
1528  var = var->next;
1529  }
1530  else if (var != NULL && var->type == ECPGt_sqlda)
1531  {
1532  if (INFORMIX_MODE(stmt->compat))
1533  {
1534  struct sqlda_compat **_sqlda = (struct sqlda_compat **) var->pointer;
1535  struct sqlda_compat *sqlda = *_sqlda;
1536  struct sqlda_compat *sqlda_new;
1537  int i;
1538 
1539  /*
1540  * If we are passed in a previously existing sqlda (chain)
1541  * then free it.
1542  */
1543  while (sqlda)
1544  {
1545  sqlda_new = sqlda->desc_next;
1546  free(sqlda);
1547  sqlda = sqlda_new;
1548  }
1549  *_sqlda = sqlda = sqlda_new = NULL;
1550  for (i = ntuples - 1; i >= 0; i--)
1551  {
1552  /*
1553  * Build a new sqlda structure. Note that only
1554  * fetching 1 record is supported
1555  */
1556  sqlda_new = ecpg_build_compat_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1557 
1558  if (!sqlda_new)
1559  {
1560  /* cleanup all SQLDAs we created up */
1561  while (sqlda)
1562  {
1563  sqlda_new = sqlda->desc_next;
1564  free(sqlda);
1565  sqlda = sqlda_new;
1566  }
1567  *_sqlda = NULL;
1568 
1569  ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1570  status = false;
1571  break;
1572  }
1573  else
1574  {
1575  ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1576 
1577  *_sqlda = sqlda_new;
1578 
1579  ecpg_set_compat_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1580  ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1581  stmt->lineno, PQnfields(stmt->results));
1582 
1583  sqlda_new->desc_next = sqlda;
1584  sqlda = sqlda_new;
1585  }
1586  }
1587  }
1588  else
1589  {
1590  struct sqlda_struct **_sqlda = (struct sqlda_struct **) var->pointer;
1591  struct sqlda_struct *sqlda = *_sqlda;
1592  struct sqlda_struct *sqlda_new;
1593  int i;
1594 
1595  /*
1596  * If we are passed in a previously existing sqlda (chain)
1597  * then free it.
1598  */
1599  while (sqlda)
1600  {
1601  sqlda_new = sqlda->desc_next;
1602  free(sqlda);
1603  sqlda = sqlda_new;
1604  }
1605  *_sqlda = sqlda = sqlda_new = NULL;
1606  for (i = ntuples - 1; i >= 0; i--)
1607  {
1608  /*
1609  * Build a new sqlda structure. Note that only
1610  * fetching 1 record is supported
1611  */
1612  sqlda_new = ecpg_build_native_sqlda(stmt->lineno, stmt->results, i, stmt->compat);
1613 
1614  if (!sqlda_new)
1615  {
1616  /* cleanup all SQLDAs we created up */
1617  while (sqlda)
1618  {
1619  sqlda_new = sqlda->desc_next;
1620  free(sqlda);
1621  sqlda = sqlda_new;
1622  }
1623  *_sqlda = NULL;
1624 
1625  ecpg_log("ecpg_process_output on line %d: out of memory allocating a new sqlda\n", stmt->lineno);
1626  status = false;
1627  break;
1628  }
1629  else
1630  {
1631  ecpg_log("ecpg_process_output on line %d: new sqlda was built\n", stmt->lineno);
1632 
1633  *_sqlda = sqlda_new;
1634 
1635  ecpg_set_native_sqlda(stmt->lineno, _sqlda, stmt->results, i, stmt->compat);
1636  ecpg_log("ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1637  stmt->lineno, PQnfields(stmt->results));
1638 
1639  sqlda_new->desc_next = sqlda;
1640  sqlda = sqlda_new;
1641  }
1642  }
1643  }
1644 
1645  var = var->next;
1646  }
1647  else
1648  for (act_field = 0; act_field < nfields && status; act_field++)
1649  {
1650  if (var != NULL)
1651  {
1652  status = ecpg_store_result(stmt->results, act_field, stmt, var);
1653  var = var->next;
1654  }
1655  else if (!INFORMIX_MODE(stmt->compat))
1656  {
1658  return (false);
1659  }
1660  }
1661 
1662  if (status && var != NULL)
1663  {
1665  status = false;
1666  }
1667 
1668  break;
1669  case PGRES_COMMAND_OK:
1670  status = true;
1671  cmdstat = PQcmdStatus(stmt->results);
1672  sqlca->sqlerrd[1] = PQoidValue(stmt->results);
1673  sqlca->sqlerrd[2] = atol(PQcmdTuples(stmt->results));
1674  ecpg_log("ecpg_process_output on line %d: OK: %s\n", stmt->lineno, cmdstat);
1675  if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
1676  !sqlca->sqlerrd[2] &&
1677  (strncmp(cmdstat, "UPDATE", 6) == 0
1678  || strncmp(cmdstat, "INSERT", 6) == 0
1679  || strncmp(cmdstat, "DELETE", 6) == 0))
1681  break;
1682  case PGRES_COPY_OUT:
1683  {
1684  char *buffer;
1685  int res;
1686 
1687  ecpg_log("ecpg_process_output on line %d: COPY OUT data transfer in progress\n", stmt->lineno);
1688  while ((res = PQgetCopyData(stmt->connection->connection,
1689  &buffer, 0)) > 0)
1690  {
1691  printf("%s", buffer);
1692  PQfreemem(buffer);
1693  }
1694  if (res == -1)
1695  {
1696  /* COPY done */
1697  PQclear(stmt->results);
1698  stmt->results = PQgetResult(stmt->connection->connection);
1699  if (PQresultStatus(stmt->results) == PGRES_COMMAND_OK)
1700  ecpg_log("ecpg_process_output on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
1701  else
1702  ecpg_log("ecpg_process_output on line %d: got error after PGRES_COPY_OUT: %s", stmt->lineno, PQresultErrorMessage(stmt->results));
1703  }
1704  break;
1705  }
1706  default:
1707 
1708  /*
1709  * execution should never reach this code because it is already
1710  * handled in ECPGcheck_PQresult()
1711  */
1712  ecpg_log("ecpg_process_output on line %d: unknown execution status type\n",
1713  stmt->lineno);
1714  ecpg_raise_backend(stmt->lineno, stmt->results, stmt->connection->connection, stmt->compat);
1715  status = false;
1716  break;
1717  }
1718 
1719  if (clear_result)
1720  {
1721  PQclear(stmt->results);
1722  stmt->results = NULL;
1723  }
1724 
1725  /* check for asynchronous returns */
1726  notify = PQnotifies(stmt->connection->connection);
1727  if (notify)
1728  {
1729  ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
1730  stmt->lineno, notify->relname, notify->be_pid);
1731  PQfreemem(notify);
1732  }
1733 
1734  return status;
1735 }
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:310
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:60
#define NULL
Definition: c.h:226
#define ECPG_TOO_FEW_ARGUMENTS
Definition: ecpgerrno.h:20
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:222
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
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
struct sqlca_t::@79 sqlerrm
#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:226
#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:5960
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
Definition: extern.h:220
#define PG_DIAG_MESSAGE_PRIMARY
Definition: postgres_ext.h:54
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
struct sqlca_t::@79 sqlerrm
#define PG_DIAG_SQLSTATE
Definition: postgres_ext.h:53
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:226
#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:5907
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:226
#define realloc(a, b)
Definition: header.h:55
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
NumericDigit * buf
static int16 value_is_not_null
Definition: sqlda.c:249
long date
Definition: pgtypes_date.h:8
char bool
Definition: c.h:199
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:934
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:123
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define NULL
Definition: c.h:226
double timestamp
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:314
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
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:199
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:934
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:123
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:406
#define NULL
Definition: c.h:226
double timestamp
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
Definition: misc.c:314
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 495 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(), sprintf_double_value(), sprintf_float_value(), variable::type, variable::value, and variable::varcharsize.

Referenced by ecpg_build_params(), and ECPGset_desc().

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

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