3#define POSTGRES_ECPG_INTERNAL
23#define stmtCacheNBuckets 2039
24#define stmtCacheEntPerBucket 8
26#define stmtCacheArraySize (stmtCacheNBuckets * stmtCacheEntPerBucket + 1)
49 if (
c ==
'_' ||
c ==
'>' ||
c ==
'-' ||
c ==
'.')
65 int lineno =
stmt->lineno;
83 memset(prep_stmt, 0,
sizeof(
struct statement));
104 this->stmt = prep_stmt;
105 this->prepared =
true;
123 for (; (*text)[ptr] !=
'\0'; ptr++)
125 if ((*
text)[ptr] ==
'\'')
126 string =
string ?
false :
true;
128 if (
string || (((*
text)[ptr] !=
':') && ((*
text)[ptr] !=
'?')))
131 if (((*
text)[ptr] ==
':') && ((*
text)[ptr + 1] ==
':'))
136 int buffersize =
sizeof(int) * CHAR_BIT * 10 / 3;
144 snprintf(buffer, buffersize,
"$%d", counter++);
154 memcpy(newcopy, *
text, ptr);
155 strcpy(newcopy + ptr, buffer);
156 strcat(newcopy, (*
text) +ptr +
len);
163 if ((*
text)[ptr] ==
'\0')
192 stmt->connection = con;
200 stmt->inlist =
stmt->outlist = NULL;
227 ecpg_log(
"prepare_common on line %d: name %s; query: \"%s\"\n",
stmt->lineno,
name,
stmt->command);
229 this->prepared =
true;
253 if (!
ecpg_init(con, connection_name, lineno))
273 prev =
this,
this = this->
next)
275 if (strcmp(this->name,
name) == 0)
291 ecpg_log(
"deallocate_one on line %d: name %s\n", lineno, this->
name);
304 query =
PQexec(this->
stmt->connection->connection, text);
307 this->
stmt->connection->connection,
348 if (!
ecpg_init(con, connection_name, lineno))
388 return this ? this->
stmt->command : NULL;
414 stmtLeng = strlen(ecpgQuery);
416 if (hashLeng > stmtLeng)
420 for (stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
422 hashVal = hashVal + (
unsigned char) ecpgQuery[stmtIx];
424 hashVal = hashVal << 13;
425 rotVal = (hashVal &
UINT64CONST(0x1fff00000000)) >> 32;
426 hashVal = (hashVal &
UINT64CONST(0xffffffff)) | rotVal;
521 const char *ecpgQuery)
595 ecpg_log(
"ecpg_auto_prepare on line %d: statement found in cache; entry %d\n", lineno, entNo);
616 ecpg_log(
"ecpg_auto_prepare on line %d: statement not in cache; inserting\n", lineno);
624 if (!
ECPGprepare(lineno, connection_name, 0, stmtID, query))
struct connection * ecpg_get_connection(const char *connection_name)
#define ECPG_INVALID_STMT
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
char * ecpg_strdup(const char *string, int lineno, bool *alloc_failed)
char * ecpg_alloc(long size, int lineno)
void ecpg_log(const char *format,...) pg_attribute_printf(1
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
void ecpg_free(void *ptr)
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
PGresult * PQprepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
PGresult * PQexec(PGconn *conn, const char *query)
static bool prepare_common(int lineno, struct connection *con, const char *name, const char *variable)
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
bool ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
static int ecpg_freeStmtCacheEntry(int lineno, int compat, int entNo)
static int AddStmtToCache(int lineno, const char *stmtID, const char *connection, int compat, const char *ecpgQuery)
bool ecpg_register_prepared_stmt(struct statement *stmt)
static int SearchStmtCache(const char *ecpgQuery)
static bool isvarchar(unsigned char c)
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
static int HashStmt(const char *ecpgQuery)
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
char * ecpg_prepared(const char *name, struct connection *con)
#define stmtCacheEntPerBucket
struct prepared_statement * ecpg_find_prepared_statement(const char *name, struct connection *con, struct prepared_statement **prev_)
static stmtCacheEntry * stmtCacheEntries
bool ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, char **name, const char *query)
static bool replace_variables(char **text, int lineno)
bool ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
#define stmtCacheNBuckets
#define stmtCacheArraySize
struct prepared_statement * prep_stmts
struct prepared_statement * next
struct variable * outlist
struct connection * connection