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));
91 this->stmt = prep_stmt;
92 this->prepared =
true;
110 for (; (*text)[ptr] !=
'\0'; ptr++)
112 if ((*
text)[ptr] ==
'\'')
113 string =
string ?
false :
true;
115 if (
string || (((*
text)[ptr] !=
':') && ((*
text)[ptr] !=
'?')))
118 if (((*
text)[ptr] ==
':') && ((*
text)[ptr + 1] ==
':'))
123 int buffersize =
sizeof(int) * CHAR_BIT * 10 / 3;
131 snprintf(buffer, buffersize,
"$%d", counter++);
141 memcpy(newcopy, *
text, ptr);
142 strcpy(newcopy + ptr, buffer);
143 strcat(newcopy, (*
text) +ptr +
len);
150 if ((*
text)[ptr] ==
'\0')
179 stmt->connection = con;
181 stmt->inlist =
stmt->outlist = NULL;
201 ecpg_log(
"prepare_common on line %d: name %s; query: \"%s\"\n",
stmt->lineno,
name,
stmt->command);
203 this->prepared =
true;
227 if (!
ecpg_init(con, connection_name, lineno))
247 prev =
this,
this = this->
next)
249 if (strcmp(this->name,
name) == 0)
265 ecpg_log(
"deallocate_one on line %d: name %s\n", lineno, this->
name);
278 query =
PQexec(this->
stmt->connection->connection, text);
281 this->
stmt->connection->connection,
322 if (!
ecpg_init(con, connection_name, lineno))
362 return this ? this->
stmt->command : NULL;
388 stmtLeng = strlen(ecpgQuery);
390 if (hashLeng > stmtLeng)
394 for (stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
396 hashVal = hashVal + (
unsigned char) ecpgQuery[stmtIx];
398 hashVal = hashVal << 13;
399 rotVal = (hashVal &
UINT64CONST(0x1fff00000000)) >> 32;
400 hashVal = (hashVal &
UINT64CONST(0xffffffff)) | rotVal;
495 const char *ecpgQuery)
567 ecpg_log(
"ecpg_auto_prepare on line %d: statement found in cache; entry %d\n", lineno, entNo);
583 ecpg_log(
"ecpg_auto_prepare on line %d: statement not in cache; inserting\n", lineno);
588 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_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)
char * ecpg_strdup(const char *string, int lineno)
void ecpg_free(void *ptr)
#define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME
void PQclear(PGresult *res)
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