16#define POSTGRES_ECPG_INTERNAL
21#include "catalog/pg_type_d.h"
104#ifndef HAVE_USELOCALE
116 for (;
text[p] !=
'\0'; p++)
118 if (
string && !std_strings &&
text[p] ==
'\\')
120 else if (
text[p] ==
'\'')
121 string =
string ?
false :
true;
171 if ((
stmt->connection->cache_head) ==
NULL)
177#define not_an_array_in_ecpg ECPG_ARRAY_NONE
324 ecpg_log(
"ecpg_store_result on line %d: incorrect number of matches; %d don't fit into array of %ld\n",
362 len += (ntuples + 1) *
sizeof(
char *);
393 ecpg_log(
"ecpg_store_result on line %d: allocating memory for %d tuples\n",
stmt->lineno, ntuples);
459 sprintf(ptr,
"%s%s",
"NaN", delim);
463 sprintf(ptr,
"%s%s",
"-Infinity", delim);
465 sprintf(ptr,
"%s%s",
"Infinity", delim);
475 sprintf(ptr,
"%s%s",
"NaN", delim);
479 sprintf(ptr,
"%s%s",
"-Infinity", delim);
481 sprintf(ptr,
"%s%s",
"Infinity", delim);
545 if (*(
long long int *) var->
ind_value < (
long long) 0)
771 if (var->
offset ==
sizeof(
char))
773 else if (var->
offset ==
sizeof(
int))
1083 else if (!is_binary)
1095 value_s =
"no memory for logging of parameter";
1098 ecpg_log(
"ecpg_free_params on line %d: parameter %d = %s\n",
1110 for (n = 0; n <
stmt->nparams; n++)
1114 stmt->paramformats[n],
stmt->lineno, n + 1);
1217 bool std_strings =
false;
1309 if (
sqlda->sqlvar[
i].sqlind)
1313 if (*(
sqlda->sqlvar[
i].sqlind))
1314 *(
sqlda->sqlvar[
i].sqlind) = -1;
1364 if (
sqlda->sqlvar[
i].sqlind)
1368 if (*(
sqlda->sqlvar[
i].sqlind))
1369 *(
sqlda->sqlvar[
i].sqlind) = -1;
1407 if ((position =
next_insert(
stmt->command, position,
stmt->questionmarks, std_strings) + 1) == 0)
1443 else if (
stmt->command[position] ==
'0')
1531 if (
stmt->command[position] ==
'?')
1583 stmt->results =
PQexec(
stmt->connection->connection,
"begin transaction");
1602 ecpg_log(
"ecpg_execute on line %d: query: %s; with %d parameter(s) on connection %s\n",
stmt->lineno,
stmt->command,
stmt->nparams,
stmt->connection->name);
1608 (
const char *
const *)
stmt->paramvalues,
1609 (
const int *)
stmt->paramlengths,
1610 (
const int *)
stmt->paramformats,
1612 ecpg_log(
"ecpg_execute on line %d: using PQexecPrepared for \"%s\"\n",
stmt->lineno,
stmt->command);
1616 if (
stmt->nparams == 0)
1619 ecpg_log(
"ecpg_execute on line %d: using PQexec\n",
stmt->lineno);
1625 (
const char *
const *)
stmt->paramvalues,
1626 (
const int *)
stmt->paramlengths,
1627 (
const int *)
stmt->paramformats,
1630 ecpg_log(
"ecpg_execute on line %d: using PQexecParams\n",
stmt->lineno);
1672 bool status =
false;
1687 var =
stmt->outlist;
1694 ecpg_log(
"ecpg_process_output on line %d: correctly got %d tuples with %d fields\n",
stmt->lineno, ntuples, nfields);
1700 ecpg_log(
"ecpg_process_output on line %d: incorrect number of matches (%d)\n",
1701 stmt->lineno, ntuples);
1718 ecpg_log(
"ecpg_process_output on line %d: putting result (%d tuples) into descriptor %s\n",
1743 for (
i = ntuples - 1;
i >= 0;
i--)
1762 ecpg_log(
"ecpg_process_output on line %d: out of memory allocating a new sqlda\n",
stmt->lineno);
1768 ecpg_log(
"ecpg_process_output on line %d: new sqlda was built\n",
stmt->lineno);
1773 ecpg_log(
"ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1799 for (
i = ntuples - 1;
i >= 0;
i--)
1818 ecpg_log(
"ecpg_process_output on line %d: out of memory allocating a new sqlda\n",
stmt->lineno);
1824 ecpg_log(
"ecpg_process_output on line %d: new sqlda was built\n",
stmt->lineno);
1829 ecpg_log(
"ecpg_process_output on line %d: putting result (1 tuple %d fields) into sqlda descriptor\n",
1855 if (status && var !=
NULL)
1869 !
sqlca->sqlerrd[2] &&
1880 ecpg_log(
"ecpg_process_output on line %d: COPY OUT data transfer in progress\n",
stmt->lineno);
1893 ecpg_log(
"ecpg_process_output on line %d: got PGRES_COMMAND_OK after PGRES_COPY_OUT\n",
stmt->lineno);
1905 ecpg_log(
"ecpg_process_output on line %d: unknown execution status type\n",
1922 ecpg_log(
"ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
1980#ifdef HAVE_USELOCALE
1996 if (
stmt->oldthreadlocale == -1)
2028 stmt->command = prepname;
2067 stmt->connection = con;
2098 list = &(
stmt->inlist);
2105 list = &(
stmt->outlist);
2179 for (ptr = *list; ptr && ptr->
next; ptr = ptr->
next)
2235#ifdef HAVE_USELOCALE
2239 if (
stmt->oldlocale)
2263 query, args, &
stmt))
void print(const void *obj)
#define Assert(condition)
#define ESCAPE_STRING_SYNTAX
void ecpg_pthreads_init(void)
struct connection * ecpg_get_connection(const char *connection_name)
unsigned ecpg_hex_enc_len(unsigned srclen)
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)
unsigned ecpg_hex_encode(const char *src, unsigned len, char *dst)
#define ECPG_CONVERT_BOOL
#define ECPG_TOO_MANY_ARGUMENTS
#define ECPG_TOO_FEW_ARGUMENTS
#define ECPG_INVALID_STMT
#define ECPG_INFORMIX_SUBSELECT_NOT_ONE
#define ECPG_TOO_MANY_MATCHES
#define ECPG_OUT_OF_MEMORY
struct descriptor * ecpg_find_desc(int line, const char *name)
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
#define ECPG_SQLSTATE_NO_DATA
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
@ ECPG_COMPAT_INFORMIX_SE
char * ecpg_strdup(const char *string, int lineno, bool *alloc_failed)
char * ecpg_alloc(long size, int lineno)
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
struct sqlda_struct * ecpg_build_native_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
char * ecpg_auto_alloc(long size, int lineno)
bool ecpg_register_prepared_stmt(struct statement *stmt)
void ecpg_log(const char *format,...) pg_attribute_printf(1
void bool ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, char **name, const char *query)
void ecpg_clear_auto_mem(void)
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS
struct sqlda_compat * ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compat)
#define ECPG_SQLSTATE_CARDINALITY_VIOLATION
char * ecpg_prepared(const char *name, struct connection *con)
void ecpg_set_compat_sqlda(int lineno, struct sqlda_compat **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
char * ecpg_realloc(void *ptr, long size, int lineno)
#define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS
const char * ecpg_type_name(enum ECPGttype typ)
#define ECPG_SQLSTATE_DATATYPE_MISMATCH
void ecpg_set_native_sqlda(int lineno, struct sqlda_struct **_sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
int ecpg_dynamic_type(Oid type)
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
void ecpg_free(void *ptr)
void ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
@ ECPGst_exec_with_exprlist
@ ECPGt_unsigned_long_long
static bool ecpg_type_infocache_push(struct ECPGtype_information_cache **cache, int oid, enum ARRAY_TYPE isarray, int lineno)
bool ecpg_build_params(struct statement *stmt)
bool ecpg_store_result(const PGresult *results, int act_field, const struct statement *stmt, struct variable *var)
static void sprintf_double_value(char *ptr, double value, const char *delim)
static void print_param_value(char *value, int len, int is_binary, int lineno, int nth)
static bool insert_tobeinserted(int position, int ph_len, struct statement *stmt, char *tobeinserted)
bool ecpg_execute(struct statement *stmt)
static char * quote_postgres(char *arg, bool quote, int lineno)
void ecpg_free_params(struct statement *stmt, bool print)
static char * convert_bytea_to_string(char *from_data, int from_len, int lineno)
static enum ARRAY_TYPE ecpg_is_type_an_array(int type, const struct statement *stmt, const struct variable *var)
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable *var, char **tobeinserted_p, bool quote)
static bool store_input_from_desc(struct statement *stmt, struct descriptor_item *desc_item, char **tobeinserted)
static void sprintf_float_value(char *ptr, float value, const char *delim)
void ecpg_do_epilogue(struct statement *stmt)
bool ecpg_do(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query, va_list args)
static void free_variable(struct variable *var)
bool ecpg_do_prologue(int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, enum ECPG_statement_type statement_type, const char *query, va_list args, struct statement **stmt_out)
bool ecpg_process_output(struct statement *stmt, bool clear_result)
bool ecpg_autostart_transaction(struct statement *stmt)
bool ECPGdo_descriptor(int line, const char *connection, const char *descriptor, const char *query)
static void free_statement(struct statement *stmt)
#define not_an_array_in_ecpg
static int next_insert(char *text, int pos, bool questionmarks, bool std_strings)
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
void PQfreemem(void *ptr)
Oid PQftype(const PGresult *res, int field_num)
PGresult * PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
PGresult * PQexecPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
int PQfformat(const PGresult *res, int field_num)
size_t PQescapeString(char *to, const char *from, size_t length)
int PQconsumeInput(PGconn *conn)
PGresult * PQexec(PGconn *conn, const char *query)
Oid PQoidValue(const PGresult *res)
PGnotify * PQnotifies(PGconn *conn)
int PQgetCopyData(PGconn *conn, char **buffer, int async)
struct sqlca_t * ECPGget_sqlca(void)
bool ECPGis_noind_null(enum ECPGttype type, const void *ptr)
#define PQresultErrorMessage
char * PGTYPESdate_to_asc(date dDate)
char * PGTYPESinterval_to_asc(interval *span)
int PGTYPESnumeric_copy(numeric *src, numeric *dst)
int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)
numeric * PGTYPESnumeric_new(void)
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
void PGTYPESnumeric_free(numeric *var)
char * PGTYPEStimestamp_to_asc(timestamp tstamp)
static chr element(struct vars *v, const chr *startp, const chr *endp)
struct descriptor_item * items
struct sqlda_compat * desc_next
struct sqlda_struct * desc_next
enum ECPG_statement_type statement_type