mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
pgindent run for 8.3.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.52 2007/10/03 13:20:19 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.53 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
@@ -201,7 +201,7 @@ deccvasc(char *cp, int len, decimal *np)
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = PGTYPESnumeric_to_decimal(result, np);
|
||||
int i = PGTYPESnumeric_to_decimal(result, np);
|
||||
|
||||
free(result);
|
||||
if (i != 0)
|
||||
@@ -700,7 +700,7 @@ initValue(long lng_val)
|
||||
value.remaining = value.digits;
|
||||
|
||||
/* convert the long to string */
|
||||
if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL)
|
||||
if ((value.val_string = (char *) malloc(value.digits + 1)) == NULL)
|
||||
return -1;
|
||||
dig = value.val;
|
||||
for (i = value.digits, j = 0; i > 0; i--, j++)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.47 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.48 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "sqlca.h"
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_key_t actual_connection_key;
|
||||
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
|
||||
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_key_t actual_connection_key;
|
||||
static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
|
||||
#endif
|
||||
static struct connection *actual_connection = NULL;
|
||||
static struct connection *all_connections = NULL;
|
||||
@@ -272,7 +272,10 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
|
||||
ecpg_init_sqlca(sqlca);
|
||||
|
||||
/* clear auto_mem structure because some error handling functions might access it */
|
||||
/*
|
||||
* clear auto_mem structure because some error handling functions might
|
||||
* access it
|
||||
*/
|
||||
ecpg_clear_auto_mem();
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
@@ -305,7 +308,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
{
|
||||
ecpg_free(dbname);
|
||||
ecpg_log("ECPGconnect: connection identifier %s is already in use\n",
|
||||
connection_name);
|
||||
connection_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -458,11 +461,11 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
actual_connection = all_connections;
|
||||
|
||||
ecpg_log("ECPGconnect: opening database %s on %s port %s %s%s%s%s\n",
|
||||
realname ? realname : "<DEFAULT>",
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
options ? "with options " : "", options ? options : "",
|
||||
user ? "for user " : "", user ? user : "");
|
||||
realname ? realname : "<DEFAULT>",
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
options ? "with options " : "", options ? options : "",
|
||||
user ? "for user " : "", user ? user : "");
|
||||
|
||||
this->connection = PQsetdbLogin(host, port, options, NULL, realname, user, passwd);
|
||||
|
||||
@@ -472,12 +475,12 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
||||
const char *db = realname ? realname : "<DEFAULT>";
|
||||
|
||||
ecpg_log("ECPGconnect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
|
||||
db,
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
options ? "with options " : "", options ? options : "",
|
||||
user ? "for user " : "", user ? user : "",
|
||||
lineno, errmsg);
|
||||
db,
|
||||
host ? host : "<DEFAULT>",
|
||||
port ? (ecpg_internal_regression_mode ? "<REGRESSION_PORT>" : port) : "<DEFAULT>",
|
||||
options ? "with options " : "", options ? options : "",
|
||||
user ? "for user " : "", user ? user : "",
|
||||
lineno, errmsg);
|
||||
|
||||
ecpg_finish(this);
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.39 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.40 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -40,9 +40,9 @@ garbage_left(enum ARRAY_TYPE isarray, char *scan_length, enum COMPAT_MODE compat
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
|
||||
@@ -105,16 +105,16 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
else
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_MISSING_INDICATOR,
|
||||
ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER,
|
||||
NULL);
|
||||
ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER,
|
||||
NULL);
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ecpg_raise(lineno, ECPG_UNSUPPORTED,
|
||||
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
|
||||
ecpg_type_name(ind_type));
|
||||
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
|
||||
ecpg_type_name(ind_type));
|
||||
return (false);
|
||||
break;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (!pval || *pval != '{')
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_DATA_NOT_ARRAY,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
|
||||
return (false);
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (garbage_left(isarray, scan_length, compat))
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_INT_FORMAT,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
}
|
||||
pval = scan_length;
|
||||
@@ -248,7 +248,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (garbage_left(isarray, scan_length, compat))
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_UINT_FORMAT,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
}
|
||||
pval = scan_length;
|
||||
@@ -326,7 +326,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (garbage_left(isarray, scan_length, compat))
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_FLOAT_FORMAT,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
}
|
||||
pval = scan_length;
|
||||
@@ -359,8 +359,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
*((int *) (var + offset * act_tuple)) = false;
|
||||
else
|
||||
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH,
|
||||
"different size");
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH,
|
||||
"different size");
|
||||
break;
|
||||
}
|
||||
else if (pval[0] == 't' && pval[1] == '\0')
|
||||
@@ -371,8 +371,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
*((int *) (var + offset * act_tuple)) = true;
|
||||
else
|
||||
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH,
|
||||
"different size");
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH,
|
||||
"different size");
|
||||
break;
|
||||
}
|
||||
else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
|
||||
@@ -383,7 +383,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
}
|
||||
|
||||
ecpg_raise(lineno, ECPG_CONVERT_BOOL,
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
|
||||
return (false);
|
||||
break;
|
||||
|
||||
@@ -491,7 +491,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (nres == NULL)
|
||||
{
|
||||
ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",
|
||||
lineno, pval ? pval : "", errno);
|
||||
lineno, pval ? pval : "", errno);
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
{
|
||||
@@ -554,7 +554,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (ires == NULL)
|
||||
{
|
||||
ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",
|
||||
lineno, pval ? pval : "", errno);
|
||||
lineno, pval ? pval : "", errno);
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
{
|
||||
@@ -608,7 +608,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (errno != 0)
|
||||
{
|
||||
ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",
|
||||
lineno, pval ? pval : "", errno);
|
||||
lineno, pval ? pval : "", errno);
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
{
|
||||
@@ -655,7 +655,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
if (errno != 0)
|
||||
{
|
||||
ecpg_log("ecpg_get_data line %d: RESULT: %s errno %d\n",
|
||||
lineno, pval ? pval : "", errno);
|
||||
lineno, pval ? pval : "", errno);
|
||||
|
||||
if (INFORMIX_MODE(compat))
|
||||
{
|
||||
@@ -692,8 +692,8 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
|
||||
default:
|
||||
ecpg_raise(lineno, ECPG_UNSUPPORTED,
|
||||
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
|
||||
ecpg_type_name(type));
|
||||
ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
|
||||
ecpg_type_name(type));
|
||||
return (false);
|
||||
break;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/* dynamic SQL support routines
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.27 2007/10/03 16:03:25 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.28 2007/11/15 21:14:45 momjian Exp $
|
||||
*/
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
@@ -15,14 +15,14 @@
|
||||
#include "sqlca.h"
|
||||
#include "sql3types.h"
|
||||
|
||||
static void descriptor_free(struct descriptor *desc);
|
||||
static void descriptor_free(struct descriptor * desc);
|
||||
|
||||
/* We manage descriptors separately for each thread. */
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_key_t descriptor_key;
|
||||
static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT;
|
||||
static pthread_key_t descriptor_key;
|
||||
static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void descriptor_deallocate_all(struct descriptor *list);
|
||||
static void descriptor_deallocate_all(struct descriptor * list);
|
||||
|
||||
static void
|
||||
descriptor_destructor(void *arg)
|
||||
@@ -44,13 +44,13 @@ get_descriptors(void)
|
||||
}
|
||||
|
||||
static void
|
||||
set_descriptors(struct descriptor *value)
|
||||
set_descriptors(struct descriptor * value)
|
||||
{
|
||||
pthread_setspecific(descriptor_key, value);
|
||||
}
|
||||
|
||||
#else
|
||||
static struct descriptor *all_descriptors = NULL;
|
||||
static struct descriptor *all_descriptors = NULL;
|
||||
|
||||
#define get_descriptors() (all_descriptors)
|
||||
#define set_descriptors(value) do { all_descriptors = (value); } while(0)
|
||||
#endif
|
||||
@@ -60,6 +60,7 @@ static PGresult *
|
||||
ecpg_result_by_descriptor(int line, const char *name)
|
||||
{
|
||||
struct descriptor *desc = ecpg_find_desc(line, name);
|
||||
|
||||
if (desc == NULL)
|
||||
return NULL;
|
||||
return desc->result;
|
||||
@@ -381,7 +382,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
|
||||
if (arrsize > 0 && ntuples > arrsize)
|
||||
{
|
||||
ecpg_log("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
|
||||
lineno, ntuples, arrsize);
|
||||
lineno, ntuples, arrsize);
|
||||
ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
|
||||
return false;
|
||||
}
|
||||
@@ -450,7 +451,7 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
|
||||
if (data_var.ind_arrsize > 0 && ntuples > data_var.ind_arrsize)
|
||||
{
|
||||
ecpg_log("ECPGget_desc line %d: Incorrect number of matches (indicator): %d don't fit into array of %d\n",
|
||||
lineno, ntuples, data_var.ind_arrsize);
|
||||
lineno, ntuples, data_var.ind_arrsize);
|
||||
ecpg_raise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
|
||||
return false;
|
||||
}
|
||||
@@ -483,6 +484,7 @@ bool
|
||||
ECPGset_desc_header(int lineno, const char *desc_name, int count)
|
||||
{
|
||||
struct descriptor *desc = ecpg_find_desc(lineno, desc_name);
|
||||
|
||||
if (desc == NULL)
|
||||
return false;
|
||||
desc->count = count;
|
||||
@@ -556,7 +558,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
|
||||
var->varcharsize = 0;
|
||||
|
||||
var->next = NULL;
|
||||
|
||||
|
||||
switch (itemtype)
|
||||
{
|
||||
case ECPGd_data:
|
||||
@@ -567,7 +569,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
|
||||
return false;
|
||||
}
|
||||
|
||||
ecpg_free(desc_item->data); /* free() takes care of a potential NULL value */
|
||||
ecpg_free(desc_item->data); /* free() takes care of a
|
||||
* potential NULL value */
|
||||
desc_item->data = (char *) tobeinserted;
|
||||
tobeinserted = NULL;
|
||||
break;
|
||||
@@ -611,7 +614,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
|
||||
|
||||
/* Free the descriptor and items in it. */
|
||||
static void
|
||||
descriptor_free(struct descriptor *desc)
|
||||
descriptor_free(struct descriptor * desc)
|
||||
{
|
||||
struct descriptor_item *desc_item;
|
||||
|
||||
@@ -658,17 +661,17 @@ ECPGdeallocate_desc(int line, const char *name)
|
||||
|
||||
/* Deallocate all descriptors in the list */
|
||||
static void
|
||||
descriptor_deallocate_all(struct descriptor *list)
|
||||
descriptor_deallocate_all(struct descriptor * list)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
struct descriptor *next = list->next;
|
||||
|
||||
descriptor_free(list);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
|
||||
bool
|
||||
ECPGallocate_desc(int line, const char *name)
|
||||
@@ -715,7 +718,7 @@ ecpg_find_desc(int line, const char *name)
|
||||
}
|
||||
|
||||
ecpg_raise(line, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, name);
|
||||
return NULL; /* not found */
|
||||
return NULL; /* not found */
|
||||
}
|
||||
|
||||
bool
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.18 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.19 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -189,7 +189,7 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
|
||||
sqlca->sqlcode = ECPG_PGSQL;
|
||||
|
||||
ecpg_log("raising sqlstate %.*s (sqlcode: %d) in line %d, '%s'.\n",
|
||||
sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, line, sqlca->sqlerrm.sqlerrmc);
|
||||
sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, line, sqlca->sqlerrm.sqlerrmc);
|
||||
|
||||
/* free all memory we have allocated for the user */
|
||||
ECPGfree_auto_mem();
|
||||
@@ -197,7 +197,7 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
|
||||
|
||||
/* filter out all error codes */
|
||||
bool
|
||||
ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
|
||||
ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
|
||||
{
|
||||
if (results == NULL)
|
||||
{
|
||||
@@ -230,20 +230,20 @@ ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMP
|
||||
return (false);
|
||||
break;
|
||||
case PGRES_COPY_OUT:
|
||||
return(true);
|
||||
return (true);
|
||||
break;
|
||||
case PGRES_COPY_IN:
|
||||
ecpg_log("ecpg_check_PQresult line %d: Got PGRES_COPY_IN ... tossing.\n", lineno);
|
||||
PQendcopy(connection);
|
||||
PQclear(results);
|
||||
return(false);
|
||||
return (false);
|
||||
break;
|
||||
default:
|
||||
ecpg_log("ecpg_check_PQresult line %d: Got something else, postgres error.\n",
|
||||
lineno);
|
||||
lineno);
|
||||
ecpg_raise_backend(lineno, results, connection, compat);
|
||||
PQclear(results);
|
||||
return(false);
|
||||
return (false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.72 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.73 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
/*
|
||||
* The aim is to get a simpler inteface to the database routines.
|
||||
@@ -38,10 +38,10 @@
|
||||
static char *
|
||||
quote_postgres(char *arg, bool quote, int lineno)
|
||||
{
|
||||
char *res;
|
||||
size_t length;
|
||||
size_t escaped_len;
|
||||
size_t buffer_len;
|
||||
char *res;
|
||||
size_t length;
|
||||
size_t escaped_len;
|
||||
size_t buffer_len;
|
||||
|
||||
/*
|
||||
* if quote is false we just need to store things in a descriptor they
|
||||
@@ -56,22 +56,22 @@ quote_postgres(char *arg, bool quote, int lineno)
|
||||
res = (char *) ecpg_alloc(buffer_len + 3, lineno);
|
||||
if (!res)
|
||||
return (res);
|
||||
escaped_len = PQescapeString(res+1, arg, buffer_len);
|
||||
escaped_len = PQescapeString(res + 1, arg, buffer_len);
|
||||
if (length == escaped_len)
|
||||
{
|
||||
res[0] = res[escaped_len+1] = '\'';
|
||||
res[escaped_len+2] = '\0';
|
||||
res[0] = res[escaped_len + 1] = '\'';
|
||||
res[escaped_len + 2] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
/*
|
||||
* We don't know if the target database is using
|
||||
* standard_conforming_strings, so we always use E'' strings.
|
||||
*/
|
||||
memmove(res+2, res+1, escaped_len);
|
||||
memmove(res + 2, res + 1, escaped_len);
|
||||
res[0] = ESCAPE_STRING_SYNTAX;
|
||||
res[1] = res[escaped_len+2] = '\'';
|
||||
res[escaped_len+3] = '\0';
|
||||
res[1] = res[escaped_len + 2] = '\'';
|
||||
res[escaped_len + 3] = '\0';
|
||||
}
|
||||
ecpg_free(arg);
|
||||
return res;
|
||||
@@ -108,31 +108,31 @@ free_statement(struct statement * stmt)
|
||||
ecpg_free(stmt);
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
next_insert(char *text, int pos, bool questionmarks)
|
||||
{
|
||||
bool string = false;
|
||||
int p = pos;
|
||||
int p = pos;
|
||||
|
||||
for (; text[p] != '\0'; p++)
|
||||
{
|
||||
if (text[p] == '\\') /* escape character */
|
||||
if (text[p] == '\\') /* escape character */
|
||||
p++;
|
||||
else if (text[p] == '\'')
|
||||
string = string ? false : true;
|
||||
else if (!string)
|
||||
{
|
||||
if (text[p] == '$' && isdigit(text[p+1]))
|
||||
if (text[p] == '$' && isdigit(text[p + 1]))
|
||||
{
|
||||
/* this can be either a dollar quote or a variable */
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = p + 1; isdigit(text[i]); i++);
|
||||
if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
|
||||
if (!isalpha(text[i]) &&isascii(text[i]) &&text[i] != '_')
|
||||
/* not dollar delimeted quote */
|
||||
return p;
|
||||
}
|
||||
else if (questionmarks && text[p] == '?')
|
||||
else if (questionmarks && text[p] == '?')
|
||||
{
|
||||
/* also allow old style placeholders */
|
||||
return p;
|
||||
@@ -306,7 +306,7 @@ ecpg_is_type_an_array(int type, const struct statement * stmt, const struct vari
|
||||
|
||||
bool
|
||||
ecpg_store_result(const PGresult *results, int act_field,
|
||||
const struct statement * stmt, struct variable * var)
|
||||
const struct statement * stmt, struct variable * var)
|
||||
{
|
||||
enum ARRAY_TYPE isarray;
|
||||
int act_tuple,
|
||||
@@ -327,7 +327,7 @@ ecpg_store_result(const PGresult *results, int act_field,
|
||||
if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
|
||||
{
|
||||
ecpg_log("ecpg_store_result line %d: Incorrect number of matches: %d don't fit into array of %d\n",
|
||||
stmt->lineno, ntuples, var->arrsize);
|
||||
stmt->lineno, ntuples, var->arrsize);
|
||||
ecpg_raise(stmt->lineno, INFORMIX_MODE(stmt->compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
|
||||
return false;
|
||||
}
|
||||
@@ -422,8 +422,8 @@ ecpg_store_result(const PGresult *results, int act_field,
|
||||
int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
|
||||
|
||||
if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
|
||||
var->type, var->ind_type, current_data_location,
|
||||
var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
|
||||
var->type, var->ind_type, current_data_location,
|
||||
var->ind_value, len, 0, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
|
||||
status = false;
|
||||
else
|
||||
{
|
||||
@@ -441,8 +441,8 @@ ecpg_store_result(const PGresult *results, int act_field,
|
||||
for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
|
||||
{
|
||||
if (!ecpg_get_data(results, act_tuple, act_field, stmt->lineno,
|
||||
var->type, var->ind_type, var->value,
|
||||
var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
|
||||
var->type, var->ind_type, var->value,
|
||||
var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray, stmt->compat, stmt->force_indicator))
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -451,7 +451,7 @@ ecpg_store_result(const PGresult *results, int act_field,
|
||||
|
||||
bool
|
||||
ecpg_store_input(const int lineno, const bool force_indicator, const struct variable * var,
|
||||
const char **tobeinserted_p, bool quote)
|
||||
const char **tobeinserted_p, bool quote)
|
||||
{
|
||||
char *mallocedval = NULL;
|
||||
char *newcopy = NULL;
|
||||
@@ -1035,13 +1035,13 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
|
||||
static void
|
||||
free_params(const char **paramValues, int nParams, bool print, int lineno)
|
||||
{
|
||||
int n;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < nParams; n++)
|
||||
{
|
||||
if (print)
|
||||
ecpg_log("free_params line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null");
|
||||
ecpg_free((void *)(paramValues[n]));
|
||||
ecpg_free((void *) (paramValues[n]));
|
||||
}
|
||||
ecpg_free(paramValues);
|
||||
}
|
||||
@@ -1055,22 +1055,22 @@ ecpg_execute(struct statement * stmt)
|
||||
PGnotify *notify;
|
||||
struct variable *var;
|
||||
int desc_counter = 0;
|
||||
const char * *paramValues = NULL;
|
||||
int nParams = 0;
|
||||
int position = 0;
|
||||
const char **paramValues = NULL;
|
||||
int nParams = 0;
|
||||
int position = 0;
|
||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||
bool clear_result = true;
|
||||
bool clear_result = true;
|
||||
|
||||
/*
|
||||
* If the type is one of the fill in types then we take the argument
|
||||
* and enter it to our parameter array at the first position. Then if there
|
||||
* If the type is one of the fill in types then we take the argument and
|
||||
* enter it to our parameter array at the first position. Then if there
|
||||
* are any more fill in types we add more parameters.
|
||||
*/
|
||||
var = stmt->inlist;
|
||||
while (var)
|
||||
{
|
||||
const char *tobeinserted;
|
||||
int counter = 1;
|
||||
int counter = 1;
|
||||
|
||||
tobeinserted = NULL;
|
||||
|
||||
@@ -1134,8 +1134,9 @@ ecpg_execute(struct statement * stmt)
|
||||
|
||||
/*
|
||||
* now tobeinserted points to an area that contains the next parameter
|
||||
* if var->type=ECPGt_char_variable we have a dynamic cursor
|
||||
* we have to simulate a dynamic cursor because there is no backend functionality for it
|
||||
* if var->type=ECPGt_char_variable we have a dynamic cursor we have
|
||||
* to simulate a dynamic cursor because there is no backend
|
||||
* functionality for it
|
||||
*/
|
||||
if (var->type != ECPGt_char_variable)
|
||||
{
|
||||
@@ -1156,17 +1157,19 @@ ecpg_execute(struct statement * stmt)
|
||||
*/
|
||||
ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
|
||||
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
|
||||
NULL);
|
||||
NULL);
|
||||
free_params(paramValues, nParams, false, stmt->lineno);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* let's see if this was an old style placeholder */
|
||||
if (stmt->command[position-1] == '?')
|
||||
if (stmt->command[position - 1] == '?')
|
||||
{
|
||||
/* yes, replace with new style */
|
||||
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */
|
||||
char *buffer, *newcopy;
|
||||
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
|
||||
* size we need */
|
||||
char *buffer,
|
||||
*newcopy;
|
||||
|
||||
if (!(buffer = (char *) ecpg_alloc(buffersize, stmt->lineno)))
|
||||
{
|
||||
@@ -1202,11 +1205,11 @@ ecpg_execute(struct statement * stmt)
|
||||
}
|
||||
else
|
||||
{
|
||||
char *newcopy;
|
||||
char *newcopy;
|
||||
|
||||
if (!(newcopy = (char *) ecpg_alloc(strlen(stmt->command)
|
||||
+ strlen(tobeinserted)
|
||||
+ 1, stmt->lineno)))
|
||||
+ strlen(tobeinserted)
|
||||
+ 1, stmt->lineno)))
|
||||
{
|
||||
free_params(paramValues, nParams, false, stmt->lineno);
|
||||
return false;
|
||||
@@ -1221,14 +1224,14 @@ ecpg_execute(struct statement * stmt)
|
||||
*/
|
||||
ecpg_raise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
|
||||
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
|
||||
NULL);
|
||||
NULL);
|
||||
free_params(paramValues, nParams, false, stmt->lineno);
|
||||
ecpg_free(newcopy);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
|
||||
int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
|
||||
|
||||
strcpy(newcopy + position - 1, tobeinserted);
|
||||
|
||||
@@ -1238,14 +1241,14 @@ ecpg_execute(struct statement * stmt)
|
||||
*/
|
||||
strcat(newcopy,
|
||||
stmt->command
|
||||
+ position
|
||||
+ position
|
||||
+ ph_len - 1);
|
||||
}
|
||||
|
||||
ecpg_free(stmt->command);
|
||||
stmt->command = newcopy;
|
||||
|
||||
ecpg_free((char *)tobeinserted);
|
||||
|
||||
ecpg_free((char *) tobeinserted);
|
||||
tobeinserted = NULL;
|
||||
}
|
||||
|
||||
@@ -1257,7 +1260,7 @@ ecpg_execute(struct statement * stmt)
|
||||
if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
|
||||
{
|
||||
ecpg_raise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
|
||||
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
|
||||
ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
|
||||
free_params(paramValues, nParams, false, stmt->lineno);
|
||||
return false;
|
||||
}
|
||||
@@ -1304,9 +1307,9 @@ ecpg_execute(struct statement * stmt)
|
||||
var = stmt->outlist;
|
||||
switch (PQresultStatus(results))
|
||||
{
|
||||
int nfields,
|
||||
ntuples,
|
||||
act_field;
|
||||
int nfields,
|
||||
ntuples,
|
||||
act_field;
|
||||
|
||||
case PGRES_TUPLES_OK:
|
||||
nfields = PQnfields(results);
|
||||
@@ -1318,7 +1321,7 @@ ecpg_execute(struct statement * stmt)
|
||||
{
|
||||
if (ntuples)
|
||||
ecpg_log("ecpg_execute line %d: Incorrect number of matches: %d\n",
|
||||
stmt->lineno, ntuples);
|
||||
stmt->lineno, ntuples);
|
||||
ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
|
||||
status = false;
|
||||
break;
|
||||
@@ -1327,6 +1330,7 @@ ecpg_execute(struct statement * stmt)
|
||||
if (var != NULL && var->type == ECPGt_descriptor)
|
||||
{
|
||||
struct descriptor *desc = ecpg_find_desc(stmt->lineno, var->pointer);
|
||||
|
||||
if (desc == NULL)
|
||||
status = false;
|
||||
else
|
||||
@@ -1399,9 +1403,13 @@ ecpg_execute(struct statement * stmt)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* execution should never reach this code because it is already handled in ECPGcheck_PQresult() */
|
||||
|
||||
/*
|
||||
* execution should never reach this code because it is already
|
||||
* handled in ECPGcheck_PQresult()
|
||||
*/
|
||||
ecpg_log("ecpg_execute line %d: Got something else, postgres error.\n",
|
||||
stmt->lineno);
|
||||
stmt->lineno);
|
||||
ecpg_raise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
|
||||
status = false;
|
||||
break;
|
||||
@@ -1414,7 +1422,7 @@ ecpg_execute(struct statement * stmt)
|
||||
if (notify)
|
||||
{
|
||||
ecpg_log("ecpg_execute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
|
||||
stmt->lineno, notify->relname, notify->be_pid);
|
||||
stmt->lineno, notify->relname, notify->be_pid);
|
||||
PQfreemem(notify);
|
||||
}
|
||||
|
||||
@@ -1432,12 +1440,12 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
enum ECPGttype type;
|
||||
struct variable **list;
|
||||
enum ECPG_statement_type statement_type = st;
|
||||
char *prepname;
|
||||
char *prepname;
|
||||
|
||||
if (!query)
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
/* Make sure we do NOT honor the locale for numeric input/output */
|
||||
@@ -1462,22 +1470,16 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
va_start(args, query);
|
||||
|
||||
/*
|
||||
* create a list of variables
|
||||
* The variables are listed with input variables preceding outputvariables
|
||||
* The end of each group is marked by an end marker.
|
||||
* per variable we list:
|
||||
* type - as defined in ecpgtype.h
|
||||
* value - where to store the data
|
||||
* varcharsize - length of string in case we have a stringvariable, else 0
|
||||
* arraysize - 0 for pointer (we don't know the size of the array),
|
||||
* 1 for simple variable, size for arrays
|
||||
* offset - offset between ith and (i+1)th entry in an array,
|
||||
* normally that means sizeof(type)
|
||||
* ind_type - type of indicator variable
|
||||
* ind_value - pointer to indicator variable
|
||||
* ind_varcharsize - empty
|
||||
* ind_arraysize - arraysize of indicator array
|
||||
* ind_offset - indicator offset
|
||||
* create a list of variables The variables are listed with input
|
||||
* variables preceding outputvariables The end of each group is marked by
|
||||
* an end marker. per variable we list: type - as defined in ecpgtype.h
|
||||
* value - where to store the data varcharsize - length of string in case
|
||||
* we have a stringvariable, else 0 arraysize - 0 for pointer (we don't
|
||||
* know the size of the array), 1 for simple variable, size for arrays
|
||||
* offset - offset between ith and (i+1)th entry in an array, normally
|
||||
* that means sizeof(type) ind_type - type of indicator variable ind_value
|
||||
* - pointer to indicator variable ind_varcharsize - empty ind_arraysize -
|
||||
* arraysize of indicator array ind_offset - indicator offset
|
||||
*/
|
||||
if (!(stmt = (struct statement *) ecpg_alloc(sizeof(struct statement), lineno)))
|
||||
{
|
||||
@@ -1487,14 +1489,19 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If statement type is ECPGst_prepnormal we are supposed to prepare
|
||||
* the statement before executing them */
|
||||
/*
|
||||
* If statement type is ECPGst_prepnormal we are supposed to prepare the
|
||||
* statement before executing them
|
||||
*/
|
||||
if (statement_type == ECPGst_prepnormal)
|
||||
{
|
||||
if (!ecpg_auto_prepare(lineno, connection_name, questionmarks, &prepname, query))
|
||||
return(false);
|
||||
return (false);
|
||||
|
||||
/* statement is now prepared, so instead of the query we have to execute the name */
|
||||
/*
|
||||
* statement is now prepared, so instead of the query we have to
|
||||
* execute the name
|
||||
*/
|
||||
stmt->command = prepname;
|
||||
statement_type = ECPGst_execute;
|
||||
}
|
||||
@@ -1506,7 +1513,7 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
if (statement_type == ECPGst_execute)
|
||||
{
|
||||
/* if we have an EXECUTE command, only the name is send */
|
||||
char *command = ecpg_prepared(stmt->command, con, lineno);
|
||||
char *command = ecpg_prepared(stmt->command, con, lineno);
|
||||
|
||||
if (command)
|
||||
{
|
||||
@@ -1559,7 +1566,8 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
var->value = var->pointer;
|
||||
|
||||
/*
|
||||
* negative values are used to indicate an array without given bounds
|
||||
* negative values are used to indicate an array without given
|
||||
* bounds
|
||||
*/
|
||||
/* reset to zero for us */
|
||||
if (var->arrsize < 0)
|
||||
@@ -1582,7 +1590,8 @@ ECPGdo(const int lineno, const int compat, const int force_indicator, const char
|
||||
var->ind_value = var->ind_pointer;
|
||||
|
||||
/*
|
||||
* negative values are used to indicate an array without given bounds
|
||||
* negative values are used to indicate an array without given
|
||||
* bounds
|
||||
*/
|
||||
/* reset to zero for us */
|
||||
if (var->ind_arrsize < 0)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.31 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.32 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#ifndef _ECPG_LIB_EXTERN_H
|
||||
#define _ECPG_LIB_EXTERN_H
|
||||
@@ -53,7 +53,7 @@ struct statement
|
||||
enum COMPAT_MODE compat;
|
||||
bool force_indicator;
|
||||
enum ECPG_statement_type statement_type;
|
||||
bool questionmarks;
|
||||
bool questionmarks;
|
||||
struct variable *inlist;
|
||||
struct variable *outlist;
|
||||
};
|
||||
@@ -115,8 +115,8 @@ struct variable
|
||||
void 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);
|
||||
enum ECPGttype, char *, char *, long, long, long,
|
||||
enum ARRAY_TYPE, enum COMPAT_MODE, bool);
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
void ecpg_pthreads_init(void);
|
||||
@@ -128,7 +128,7 @@ 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 ecpg_dynamic_type(Oid);
|
||||
void ecpg_free_auto_mem(void);
|
||||
void ecpg_clear_auto_mem(void);
|
||||
|
||||
@@ -137,17 +137,17 @@ struct descriptor *ecpggetdescp(int, char *);
|
||||
struct descriptor *ecpg_find_desc(int line, const char *name);
|
||||
|
||||
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 *, const char **, bool);
|
||||
const struct statement * stmt, struct variable * var);
|
||||
bool ecpg_store_input(const int, const bool, const struct variable *, const char **, bool);
|
||||
|
||||
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 *, int);
|
||||
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *conn);
|
||||
void ecpg_log(const char *format,...);
|
||||
bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
|
||||
void ecpg_init_sqlca(struct sqlca_t * sqlca);
|
||||
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 *, int);
|
||||
bool ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
|
||||
void ecpg_log(const char *format,...);
|
||||
bool ecpg_auto_prepare(int, const char *, const int, char **, const char *);
|
||||
void ecpg_init_sqlca(struct sqlca_t * sqlca);
|
||||
|
||||
/* SQLSTATE values generated or processed by ecpglib (intentionally
|
||||
* not exported -- users should refer to the codes directly) */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.11 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.12 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -69,8 +69,8 @@ struct auto_mem
|
||||
};
|
||||
|
||||
#ifdef ENABLE_THREAD_SAFETY
|
||||
static pthread_key_t auto_mem_key;
|
||||
static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
|
||||
static pthread_key_t auto_mem_key;
|
||||
static pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void
|
||||
auto_mem_destructor(void *arg)
|
||||
@@ -92,13 +92,13 @@ get_auto_allocs(void)
|
||||
}
|
||||
|
||||
static void
|
||||
set_auto_allocs(struct auto_mem *am)
|
||||
set_auto_allocs(struct auto_mem * am)
|
||||
{
|
||||
pthread_setspecific(auto_mem_key, am);
|
||||
}
|
||||
|
||||
#else
|
||||
static struct auto_mem *auto_allocs = NULL;
|
||||
static struct auto_mem *auto_allocs = NULL;
|
||||
|
||||
#define get_auto_allocs() (auto_allocs)
|
||||
#define set_auto_allocs(am) do { auto_allocs = (am); } while(0)
|
||||
#endif
|
||||
@@ -124,10 +124,11 @@ ECPGfree_auto_mem(void)
|
||||
do
|
||||
{
|
||||
struct auto_mem *act = am;
|
||||
|
||||
am = am->next;
|
||||
ecpg_free(act->pointer);
|
||||
ecpg_free(act);
|
||||
} while(am);
|
||||
} while (am);
|
||||
set_auto_allocs(NULL);
|
||||
}
|
||||
}
|
||||
@@ -143,9 +144,10 @@ ecpg_clear_auto_mem(void)
|
||||
do
|
||||
{
|
||||
struct auto_mem *act = am;
|
||||
|
||||
am = am->next;
|
||||
ecpg_free(act);
|
||||
} while(am);
|
||||
} while (am);
|
||||
set_auto_allocs(NULL);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.40 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.41 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -26,7 +26,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool ecpg_internal_regression_mode = false;
|
||||
bool ecpg_internal_regression_mode = false;
|
||||
|
||||
static struct sqlca_t sqlca_init =
|
||||
{
|
||||
@@ -109,7 +109,7 @@ ecpg_init(const struct connection * con, const char *connection_name, const int
|
||||
if (con == NULL)
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_NO_CONN, ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST,
|
||||
connection_name ? connection_name : "NULL");
|
||||
connection_name ? connection_name : "NULL");
|
||||
return (false);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ ecpg_init(const struct connection * con, const char *connection_name, const int
|
||||
static void
|
||||
ecpg_sqlca_key_destructor(void *arg)
|
||||
{
|
||||
free(arg); /* sqlca structure allocated in ECPGget_sqlca */
|
||||
free(arg); /* sqlca structure allocated in ECPGget_sqlca */
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -219,10 +219,10 @@ ECPGdebug(int n, FILE *dbgs)
|
||||
pthread_mutex_lock(&debug_init_mutex);
|
||||
#endif
|
||||
|
||||
if (n > 100)
|
||||
if (n > 100)
|
||||
{
|
||||
ecpg_internal_regression_mode = true;
|
||||
simple_debug = n-100;
|
||||
simple_debug = n - 100;
|
||||
}
|
||||
else
|
||||
simple_debug = n;
|
||||
@@ -420,18 +420,18 @@ win32_pthread_mutex(volatile pthread_mutex_t *mutex)
|
||||
{
|
||||
if (mutex->handle == NULL)
|
||||
{
|
||||
while (InterlockedExchange((LONG *)&mutex->initlock, 1) == 1)
|
||||
while (InterlockedExchange((LONG *) & mutex->initlock, 1) == 1)
|
||||
Sleep(0);
|
||||
if (mutex->handle == NULL)
|
||||
mutex->handle = CreateMutex(NULL, FALSE, NULL);
|
||||
InterlockedExchange((LONG *)&mutex->initlock, 0);
|
||||
InterlockedExchange((LONG *) & mutex->initlock, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static pthread_mutex_t win32_pthread_once_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t win32_pthread_once_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void
|
||||
win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void))
|
||||
win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void))
|
||||
{
|
||||
if (!*once)
|
||||
{
|
||||
@@ -444,6 +444,6 @@ win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void))
|
||||
pthread_mutex_unlock(&win32_pthread_once_lock);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32 */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.23 2007/11/05 20:57:24 tgl Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.24 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -13,32 +13,32 @@
|
||||
|
||||
struct prepared_statement
|
||||
{
|
||||
char *name;
|
||||
bool prepared;
|
||||
struct statement *stmt;
|
||||
struct prepared_statement *next;
|
||||
char *name;
|
||||
bool prepared;
|
||||
struct statement *stmt;
|
||||
struct prepared_statement *next;
|
||||
};
|
||||
|
||||
#define STMTID_SIZE 32
|
||||
|
||||
typedef struct
|
||||
typedef struct
|
||||
{
|
||||
int lineno;
|
||||
char stmtID[STMTID_SIZE];
|
||||
char *ecpgQuery;
|
||||
long execs; /* # of executions */
|
||||
char *connection; /* connection for the statement */
|
||||
} stmtCacheEntry;
|
||||
int lineno;
|
||||
char stmtID[STMTID_SIZE];
|
||||
char *ecpgQuery;
|
||||
long execs; /* # of executions */
|
||||
char *connection; /* connection for the statement */
|
||||
} stmtCacheEntry;
|
||||
|
||||
static int nextStmtID = 1;
|
||||
static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */
|
||||
static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */
|
||||
static stmtCacheEntry stmtCacheEntries[16384] = {{0,{0},0,0,0}};
|
||||
static int nextStmtID = 1;
|
||||
static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */
|
||||
static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */
|
||||
static stmtCacheEntry stmtCacheEntries[16384] = {{0, {0}, 0, 0, 0}};
|
||||
|
||||
static struct prepared_statement *find_prepared_statement(const char *name,
|
||||
struct connection *con, struct prepared_statement **prev);
|
||||
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con,
|
||||
struct prepared_statement *prev, struct prepared_statement *this);
|
||||
struct connection * con, struct prepared_statement ** prev);
|
||||
static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection * con,
|
||||
struct prepared_statement * prev, struct prepared_statement * this);
|
||||
|
||||
static bool
|
||||
isvarchar(unsigned char c)
|
||||
@@ -58,8 +58,9 @@ isvarchar(unsigned char c)
|
||||
static bool
|
||||
replace_variables(char **text, int lineno, bool questionmarks)
|
||||
{
|
||||
bool string = false;
|
||||
int counter = 1, ptr = 0;
|
||||
bool string = false;
|
||||
int counter = 1,
|
||||
ptr = 0;
|
||||
|
||||
for (; (*text)[ptr] != '\0'; ptr++)
|
||||
{
|
||||
@@ -69,21 +70,23 @@ replace_variables(char **text, int lineno, bool questionmarks)
|
||||
if (string || (((*text)[ptr] != ':') && ((*text)[ptr] != '?')))
|
||||
continue;
|
||||
|
||||
if (((*text)[ptr] == ':') && ((*text)[ptr+1] == ':'))
|
||||
ptr += 2; /* skip '::' */
|
||||
if (((*text)[ptr] == ':') && ((*text)[ptr + 1] == ':'))
|
||||
ptr += 2; /* skip '::' */
|
||||
else
|
||||
{
|
||||
int len;
|
||||
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */
|
||||
char *buffer, *newcopy;
|
||||
int len;
|
||||
int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the
|
||||
* size we need */
|
||||
char *buffer,
|
||||
*newcopy;
|
||||
|
||||
if (!(buffer = (char *) ecpg_alloc(buffersize, lineno)))
|
||||
return false;
|
||||
|
||||
snprintf(buffer, buffersize, "$%d", counter++);
|
||||
|
||||
for (len=1; (*text)[ptr+len] && isvarchar((*text)[ptr+len]); len++);
|
||||
if (!(newcopy = (char *) ecpg_alloc(strlen(*text) - len + strlen(buffer) + 1, lineno)))
|
||||
for (len = 1; (*text)[ptr + len] && isvarchar((*text)[ptr + len]); len++);
|
||||
if (!(newcopy = (char *) ecpg_alloc(strlen(*text) -len + strlen(buffer) + 1, lineno)))
|
||||
{
|
||||
ecpg_free(buffer);
|
||||
return false;
|
||||
@@ -91,16 +94,16 @@ replace_variables(char **text, int lineno, bool questionmarks)
|
||||
|
||||
strncpy(newcopy, *text, ptr);
|
||||
strcpy(newcopy + ptr, buffer);
|
||||
strcat(newcopy, (*text) + ptr + len);
|
||||
strcat(newcopy, (*text) +ptr + len);
|
||||
|
||||
ecpg_free(*text);
|
||||
ecpg_free(buffer);
|
||||
|
||||
*text = newcopy;
|
||||
|
||||
if ((*text)[ptr] == '\0') /* we reached the end */
|
||||
ptr--; /* since we will (*text)[ptr]++ in the top level for
|
||||
* loop */
|
||||
if ((*text)[ptr] == '\0') /* we reached the end */
|
||||
ptr--; /* since we will (*text)[ptr]++ in the top
|
||||
* level for loop */
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -110,10 +113,10 @@ replace_variables(char **text, int lineno, bool questionmarks)
|
||||
bool
|
||||
ECPGprepare(int lineno, const char *connection_name, const int questionmarks, const char *name, const char *variable)
|
||||
{
|
||||
struct connection *con;
|
||||
struct statement *stmt;
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
struct connection *con;
|
||||
struct statement *stmt;
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||
PGresult *query;
|
||||
|
||||
@@ -174,11 +177,12 @@ ECPGprepare(int lineno, const char *connection_name, const int questionmarks, co
|
||||
return true;
|
||||
}
|
||||
|
||||
static struct prepared_statement *find_prepared_statement(const char *name,
|
||||
struct connection *con, struct prepared_statement **prev_)
|
||||
static struct prepared_statement *
|
||||
find_prepared_statement(const char *name,
|
||||
struct connection * con, struct prepared_statement ** prev_)
|
||||
{
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
|
||||
for (this = con->prep_stmts, prev = NULL; this != NULL; prev = this, this = this->next)
|
||||
{
|
||||
@@ -193,19 +197,20 @@ static struct prepared_statement *find_prepared_statement(const char *name,
|
||||
}
|
||||
|
||||
static bool
|
||||
deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct prepared_statement *prev, struct prepared_statement *this)
|
||||
deallocate_one(int lineno, enum COMPAT_MODE c, struct connection * con, struct prepared_statement * prev, struct prepared_statement * this)
|
||||
{
|
||||
bool r = false;
|
||||
bool r = false;
|
||||
|
||||
ecpg_log("ECPGdeallocate line %d: NAME: %s\n", lineno, this->name);
|
||||
|
||||
/* first deallocate the statement in the backend */
|
||||
if (this->prepared)
|
||||
{
|
||||
char *text;
|
||||
PGresult *query;
|
||||
|
||||
char *text;
|
||||
PGresult *query;
|
||||
|
||||
text = (char *) ecpg_alloc(strlen("deallocate \"\" ") + strlen(this->name), this->stmt->lineno);
|
||||
|
||||
if (text)
|
||||
{
|
||||
sprintf(text, "deallocate \"%s\"", this->name);
|
||||
@@ -220,15 +225,15 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr
|
||||
}
|
||||
|
||||
/*
|
||||
* Just ignore all errors since we do not know the list of cursors we
|
||||
* are allowed to free. We have to trust the software.
|
||||
* Just ignore all errors since we do not know the list of cursors we are
|
||||
* allowed to free. We have to trust the software.
|
||||
*/
|
||||
if (!r && !INFORMIX_MODE(c))
|
||||
{
|
||||
ecpg_raise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, this->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* okay, free all the resources */
|
||||
ecpg_free(this->stmt->command);
|
||||
ecpg_free(this->stmt);
|
||||
@@ -245,9 +250,9 @@ deallocate_one(int lineno, enum COMPAT_MODE c, struct connection *con, struct pr
|
||||
bool
|
||||
ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
|
||||
{
|
||||
struct connection *con;
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
struct connection *con;
|
||||
struct prepared_statement *this,
|
||||
*prev;
|
||||
|
||||
con = ecpg_get_connection(connection_name);
|
||||
|
||||
@@ -263,7 +268,7 @@ ECPGdeallocate(int lineno, int c, const char *connection_name, const char *name)
|
||||
}
|
||||
|
||||
bool
|
||||
ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection *con)
|
||||
ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * con)
|
||||
{
|
||||
/* deallocate all prepared statements */
|
||||
while (con->prep_stmts)
|
||||
@@ -282,9 +287,10 @@ ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
|
||||
}
|
||||
|
||||
char *
|
||||
ecpg_prepared(const char *name, struct connection *con, int lineno)
|
||||
ecpg_prepared(const char *name, struct connection * con, int lineno)
|
||||
{
|
||||
struct prepared_statement *this;
|
||||
struct prepared_statement *this;
|
||||
|
||||
this = find_prepared_statement(name, con, NULL);
|
||||
return this ? this->stmt->command : NULL;
|
||||
}
|
||||
@@ -302,97 +308,102 @@ ECPGprepared_statement(const char *connection_name, const char *name, int lineno
|
||||
static int
|
||||
HashStmt(const char *ecpgQuery)
|
||||
{
|
||||
int stmtIx, bucketNo, hashLeng, stmtLeng;
|
||||
long long hashVal, rotVal;
|
||||
int stmtIx,
|
||||
bucketNo,
|
||||
hashLeng,
|
||||
stmtLeng;
|
||||
long long hashVal,
|
||||
rotVal;
|
||||
|
||||
stmtLeng = strlen(ecpgQuery);
|
||||
hashLeng = 50; /* use 1st 50 characters of statement */
|
||||
if(hashLeng > stmtLeng) /* if the statement isn't that long */
|
||||
hashLeng = stmtLeng; /* use its actual length */
|
||||
stmtLeng = strlen(ecpgQuery);
|
||||
hashLeng = 50; /* use 1st 50 characters of statement */
|
||||
if (hashLeng > stmtLeng) /* if the statement isn't that long */
|
||||
hashLeng = stmtLeng; /* use its actual length */
|
||||
|
||||
hashVal = 0;
|
||||
for(stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
|
||||
{
|
||||
hashVal = hashVal + (int) ecpgQuery[stmtIx];
|
||||
hashVal = hashVal << 13;
|
||||
rotVal = (hashVal & 0x1fff00000000LL) >> 32;
|
||||
hashVal = (hashVal & 0xffffffffLL) | rotVal;
|
||||
}
|
||||
hashVal = 0;
|
||||
for (stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
|
||||
{
|
||||
hashVal = hashVal + (int) ecpgQuery[stmtIx];
|
||||
hashVal = hashVal << 13;
|
||||
rotVal = (hashVal & 0x1fff00000000LL) >> 32;
|
||||
hashVal = (hashVal & 0xffffffffLL) | rotVal;
|
||||
}
|
||||
|
||||
bucketNo = hashVal % stmtCacheNBuckets;
|
||||
bucketNo += 1; /* don't use bucket # 0 */
|
||||
bucketNo = hashVal % stmtCacheNBuckets;
|
||||
bucketNo += 1; /* don't use bucket # 0 */
|
||||
|
||||
return (bucketNo * stmtCacheEntPerBucket);
|
||||
return (bucketNo * stmtCacheEntPerBucket);
|
||||
}
|
||||
|
||||
/*
|
||||
* search the statement cache - search for entry with matching ECPG-format query
|
||||
* Returns entry # in cache if found
|
||||
* OR zero if not present (zero'th entry isn't used)
|
||||
* OR zero if not present (zero'th entry isn't used)
|
||||
*/
|
||||
static int
|
||||
SearchStmtCache(const char *ecpgQuery)
|
||||
{
|
||||
int entNo, entIx;
|
||||
int entNo,
|
||||
entIx;
|
||||
|
||||
/* hash the statement */
|
||||
entNo = HashStmt(ecpgQuery);
|
||||
/* hash the statement */
|
||||
entNo = HashStmt(ecpgQuery);
|
||||
|
||||
/* search the cache */
|
||||
for(entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx)
|
||||
{
|
||||
if(stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */
|
||||
{
|
||||
if(!strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery))
|
||||
break; /* found it */
|
||||
}
|
||||
++entNo; /* incr entry # */
|
||||
}
|
||||
/* search the cache */
|
||||
for (entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx)
|
||||
{
|
||||
if (stmtCacheEntries[entNo].stmtID[0]) /* check if entry is in use */
|
||||
{
|
||||
if (!strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery))
|
||||
break; /* found it */
|
||||
}
|
||||
++entNo; /* incr entry # */
|
||||
}
|
||||
|
||||
/* if entry wasn't found - set entry # to zero */
|
||||
if(entIx >= stmtCacheEntPerBucket)
|
||||
entNo = 0;
|
||||
if (entIx >= stmtCacheEntPerBucket)
|
||||
entNo = 0;
|
||||
|
||||
return(entNo);
|
||||
return (entNo);
|
||||
}
|
||||
|
||||
/*
|
||||
* free an entry in the statement cache
|
||||
* Returns entry # in cache used
|
||||
* OR negative error code
|
||||
* OR negative error code
|
||||
*/
|
||||
static int
|
||||
ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */
|
||||
ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */
|
||||
{
|
||||
stmtCacheEntry *entry;
|
||||
PGresult *results;
|
||||
char deallocText[100];
|
||||
struct connection *con;
|
||||
stmtCacheEntry *entry;
|
||||
PGresult *results;
|
||||
char deallocText[100];
|
||||
struct connection *con;
|
||||
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
if(!entry->stmtID[0]) /* return if the entry isn't in use */
|
||||
return(0);
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
if (!entry->stmtID[0]) /* return if the entry isn't in use */
|
||||
return (0);
|
||||
|
||||
con = ecpg_get_connection(entry->connection);
|
||||
/* free the server resources for the statement */
|
||||
ecpg_log("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo);
|
||||
sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID);
|
||||
results = PQexec(con->connection, deallocText);
|
||||
con = ecpg_get_connection(entry->connection);
|
||||
/* free the server resources for the statement */
|
||||
ecpg_log("ecpg_freeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo);
|
||||
sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID);
|
||||
results = PQexec(con->connection, deallocText);
|
||||
|
||||
if (!ecpg_check_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
return(-1);
|
||||
PQclear(results);
|
||||
if (!ecpg_check_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL))
|
||||
return (-1);
|
||||
PQclear(results);
|
||||
|
||||
entry->stmtID[0] = '\0';
|
||||
entry->stmtID[0] = '\0';
|
||||
|
||||
/* free the memory used by the cache entry */
|
||||
if(entry->ecpgQuery)
|
||||
{
|
||||
ecpg_free(entry->ecpgQuery);
|
||||
entry->ecpgQuery = 0;
|
||||
}
|
||||
/* free the memory used by the cache entry */
|
||||
if (entry->ecpgQuery)
|
||||
{
|
||||
ecpg_free(entry->ecpgQuery);
|
||||
entry->ecpgQuery = 0;
|
||||
}
|
||||
|
||||
return(entNo);
|
||||
return (entNo);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -400,63 +411,67 @@ ecpg_freeStmtCacheEntry(int entNo) /* entry # to free */
|
||||
* returns entry # in cache used OR negative error code
|
||||
*/
|
||||
static int
|
||||
AddStmtToCache(int lineno, /* line # of statement */
|
||||
char *stmtID, /* statement ID */
|
||||
const char *connection, /* connection */
|
||||
const char *ecpgQuery) /* query */
|
||||
AddStmtToCache(int lineno, /* line # of statement */
|
||||
char *stmtID, /* statement ID */
|
||||
const char *connection, /* connection */
|
||||
const char *ecpgQuery) /* query */
|
||||
{
|
||||
int ix, initEntNo, luEntNo, entNo;
|
||||
stmtCacheEntry *entry;
|
||||
int ix,
|
||||
initEntNo,
|
||||
luEntNo,
|
||||
entNo;
|
||||
stmtCacheEntry *entry;
|
||||
|
||||
/* hash the statement */
|
||||
initEntNo = HashStmt(ecpgQuery);
|
||||
/* hash the statement */
|
||||
initEntNo = HashStmt(ecpgQuery);
|
||||
|
||||
/* search for an unused entry */
|
||||
entNo = initEntNo; /* start with the initial entry # for the bucket */
|
||||
luEntNo = initEntNo; /* use it as the initial 'least used' entry */
|
||||
for(ix = 0; ix < stmtCacheEntPerBucket; ++ix)
|
||||
{
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
if(!entry->stmtID[0]) /* unused entry - use it */
|
||||
break;
|
||||
if(entry->execs < stmtCacheEntries[luEntNo].execs)
|
||||
luEntNo = entNo; /* save new 'least used' entry */
|
||||
++entNo; /* increment entry # */
|
||||
}
|
||||
/* search for an unused entry */
|
||||
entNo = initEntNo; /* start with the initial entry # for the
|
||||
* bucket */
|
||||
luEntNo = initEntNo; /* use it as the initial 'least used' entry */
|
||||
for (ix = 0; ix < stmtCacheEntPerBucket; ++ix)
|
||||
{
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
if (!entry->stmtID[0]) /* unused entry - use it */
|
||||
break;
|
||||
if (entry->execs < stmtCacheEntries[luEntNo].execs)
|
||||
luEntNo = entNo; /* save new 'least used' entry */
|
||||
++entNo; /* increment entry # */
|
||||
}
|
||||
|
||||
/* if no unused entries were found - use the 'least used' entry found in the bucket */
|
||||
if(ix >= stmtCacheEntPerBucket) /* if no unused entries were found */
|
||||
entNo = luEntNo; /* re-use the 'least used' entry */
|
||||
/* if no unused entries were found - use the 'least used' entry found in the bucket */
|
||||
if (ix >= stmtCacheEntPerBucket) /* if no unused entries were found */
|
||||
entNo = luEntNo; /* re-use the 'least used' entry */
|
||||
|
||||
/* 'entNo' is the entry to use - make sure its free */
|
||||
if (ecpg_freeStmtCacheEntry(entNo) < 0)
|
||||
return (-1);
|
||||
/* 'entNo' is the entry to use - make sure its free */
|
||||
if (ecpg_freeStmtCacheEntry(entNo) < 0)
|
||||
return (-1);
|
||||
|
||||
/* add the query to the entry */
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
entry->lineno = lineno;
|
||||
entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno);
|
||||
entry->connection = (char *)connection;
|
||||
entry->execs = 0;
|
||||
memcpy(entry->stmtID, stmtID, sizeof(entry->stmtID));
|
||||
/* add the query to the entry */
|
||||
entry = &stmtCacheEntries[entNo];
|
||||
entry->lineno = lineno;
|
||||
entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno);
|
||||
entry->connection = (char *) connection;
|
||||
entry->execs = 0;
|
||||
memcpy(entry->stmtID, stmtID, sizeof(entry->stmtID));
|
||||
|
||||
return(entNo);
|
||||
return (entNo);
|
||||
}
|
||||
|
||||
/* handle cache and preparation of statments in auto-prepare mode */
|
||||
bool
|
||||
ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmarks, char **name, const char *query)
|
||||
{
|
||||
int entNo;
|
||||
int entNo;
|
||||
|
||||
/* search the statement cache for this statement */
|
||||
/* search the statement cache for this statement */
|
||||
entNo = SearchStmtCache(query);
|
||||
|
||||
/* if not found - add the statement to the cache */
|
||||
if(entNo)
|
||||
/* if not found - add the statement to the cache */
|
||||
if (entNo)
|
||||
{
|
||||
ecpg_log("ecpg_auto_prepare line %d: stmt found in cache, entry %d\n", lineno, entNo);
|
||||
*name = ecpg_strdup(stmtCacheEntries[entNo].stmtID, lineno);
|
||||
*name = ecpg_strdup(stmtCacheEntries[entNo].stmtID, lineno);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -467,13 +482,13 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int questionmar
|
||||
sprintf(*name, "ecpg%d", nextStmtID++);
|
||||
|
||||
if (!ECPGprepare(lineno, connection_name, questionmarks, ecpg_strdup(*name, lineno), query))
|
||||
return(false);
|
||||
return (false);
|
||||
if (AddStmtToCache(lineno, *name, connection_name, query) < 0)
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
/* increase usage counter */
|
||||
stmtCacheEntries[entNo].execs++;
|
||||
|
||||
return(true);
|
||||
return (true);
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.13 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.14 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#define POSTGRES_ECPG_INTERNAL
|
||||
#include "postgres_fe.h"
|
||||
@@ -96,6 +96,6 @@ ecpg_dynamic_type(Oid type)
|
||||
case NUMERICOID:
|
||||
return SQL3_NUMERIC; /* numeric */
|
||||
default:
|
||||
return -(int)type;
|
||||
return -(int) type;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.4 2007/10/03 08:55:23 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpg-pthread-win32.h,v 1.5 2007/11/15 21:14:45 momjian Exp $ */
|
||||
/*
|
||||
* pthread mapping macros for win32 native thread implementation
|
||||
*/
|
||||
@@ -10,7 +10,6 @@
|
||||
#ifndef WIN32
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#else
|
||||
|
||||
typedef struct pthread_mutex_t
|
||||
@@ -19,14 +18,14 @@ typedef struct pthread_mutex_t
|
||||
LONG initlock;
|
||||
} pthread_mutex_t;
|
||||
|
||||
typedef DWORD pthread_key_t;
|
||||
typedef bool pthread_once_t;
|
||||
typedef DWORD pthread_key_t;
|
||||
typedef bool pthread_once_t;
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER { NULL, 0 }
|
||||
#define PTHREAD_ONCE_INIT false
|
||||
|
||||
void win32_pthread_mutex(volatile pthread_mutex_t *mutex);
|
||||
void win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void));
|
||||
void win32_pthread_mutex(volatile pthread_mutex_t *mutex);
|
||||
void win32_pthread_once(volatile pthread_once_t *once, void (*fn) (void));
|
||||
|
||||
#define pthread_mutex_lock(mutex) \
|
||||
do { \
|
||||
@@ -53,9 +52,7 @@ void win32_pthread_once(volatile pthread_once_t *once, void (*fn)(void));
|
||||
if (!*(once)) \
|
||||
win32_pthread_once((once), (fn)); \
|
||||
} while(0)
|
||||
#endif /* WIN32 */
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* ENABLE_THREAD_SAFETY */
|
||||
|
||||
#endif /* _ECPG_PTHREAD_WIN32_H */
|
||||
#endif /* _ECPG_PTHREAD_WIN32_H */
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.33 2007/08/14 10:01:52 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.34 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@@ -75,7 +75,7 @@ PGTYPESdate_from_asc(char *str, char **endptr)
|
||||
}
|
||||
|
||||
if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
|
||||
DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0)
|
||||
DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0)
|
||||
{
|
||||
errno = PGTYPES_DATE_BAD_DATE;
|
||||
return INT_MIN;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.38 2007/08/22 08:20:58 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.39 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#ifndef DT_H
|
||||
#define DT_H
|
||||
@@ -310,24 +310,24 @@ do { \
|
||||
#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
|
||||
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
|
||||
|
||||
int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *);
|
||||
int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *);
|
||||
int DecodeTime(char *, int, int *, struct tm *, fsec_t *);
|
||||
int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *);
|
||||
int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool);
|
||||
int EncodeInterval(struct tm *, fsec_t, int, char *);
|
||||
int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
|
||||
int DecodeUnits(int field, char *lowtoken, int *val);
|
||||
bool CheckDateTokenTables(void);
|
||||
int EncodeDateOnly(struct tm *, int, char *, bool);
|
||||
void GetEpochTime(struct tm *);
|
||||
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
|
||||
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
|
||||
void j2date(int, int *, int *, int *);
|
||||
void GetCurrentDateTime(struct tm *);
|
||||
int date2j(int, int, int);
|
||||
void TrimTrailingZeros(char *);
|
||||
void dt2time(double, int *, int *, int *, fsec_t *);
|
||||
int DecodeTimeOnly(char **, int *, int, int *, struct tm *, fsec_t *, int *);
|
||||
int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *);
|
||||
int DecodeTime(char *, int, int *, struct tm *, fsec_t *);
|
||||
int EncodeTimeOnly(struct tm *, fsec_t, int *, int, char *);
|
||||
int EncodeDateTime(struct tm *, fsec_t, int *, char **, int, char *, bool);
|
||||
int EncodeInterval(struct tm *, fsec_t, int, char *);
|
||||
int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
|
||||
int DecodeUnits(int field, char *lowtoken, int *val);
|
||||
bool CheckDateTokenTables(void);
|
||||
int EncodeDateOnly(struct tm *, int, char *, bool);
|
||||
void GetEpochTime(struct tm *);
|
||||
int ParseDateTime(char *, char *, char **, int *, int, int *, char **);
|
||||
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
|
||||
void j2date(int, int *, int *, int *);
|
||||
void GetCurrentDateTime(struct tm *);
|
||||
int date2j(int, int, int);
|
||||
void TrimTrailingZeros(char *);
|
||||
void dt2time(double, int *, int *, int *, fsec_t *);
|
||||
|
||||
extern char *pgtypes_date_weekdays_short[];
|
||||
extern char *pgtypes_date_months[];
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.43 2007/09/30 11:38:48 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.44 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@@ -214,7 +214,7 @@ static datetkn datetktbl[] = {
|
||||
{"irkst", DTZ, POS(36)}, /* Irkutsk Summer Time */
|
||||
{"irkt", TZ, POS(32)}, /* Irkutsk Time */
|
||||
{"irt", TZ, POS(14)}, /* Iran Time */
|
||||
{"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */
|
||||
{"isodow", RESERV, DTK_ISODOW}, /* ISO day of week, Sunday == 7 */
|
||||
#if 0
|
||||
isst
|
||||
#endif
|
||||
@@ -1816,7 +1816,7 @@ ParseDateTime(char *timestr, char *lowstr,
|
||||
*/
|
||||
int
|
||||
DecodeDateTime(char **field, int *ftype, int nf,
|
||||
int *dtype, struct tm * tm, fsec_t *fsec, bool EuroDates)
|
||||
int *dtype, struct tm * tm, fsec_t *fsec, bool EuroDates)
|
||||
{
|
||||
int fmask = 0,
|
||||
tmask,
|
||||
@@ -1829,7 +1829,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
||||
int is2digits = FALSE;
|
||||
int bc = FALSE;
|
||||
int t = 0;
|
||||
int *tzp = &t;
|
||||
int *tzp = &t;
|
||||
|
||||
/***
|
||||
* We'll insist on at least all of the date fields, but initialize the
|
||||
@@ -2377,12 +2377,13 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
||||
if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
|
||||
return -1;
|
||||
|
||||
/* backend tried to find local timezone here
|
||||
* but we don't use the result afterwards anyway
|
||||
* so we only check for this error:
|
||||
* daylight savings time modifier but no standard timezone? */
|
||||
/*
|
||||
* backend tried to find local timezone here but we don't use the
|
||||
* result afterwards anyway so we only check for this error: daylight
|
||||
* savings time modifier but no standard timezone?
|
||||
*/
|
||||
if ((fmask & DTK_DATE_M) == DTK_DATE_M && tzp != NULL && !(fmask & DTK_M(TZ)) && (fmask & DTK_M(DTZMOD)))
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.101 2007/08/29 13:58:13 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.102 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
||||
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
||||
@@ -22,7 +22,7 @@ int ret_value = 0,
|
||||
regression_mode = false,
|
||||
auto_prepare = false;
|
||||
|
||||
char *output_filename;
|
||||
char *output_filename;
|
||||
|
||||
enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL;
|
||||
|
||||
@@ -126,7 +126,7 @@ main(int argc, char *const argv[])
|
||||
{"help", no_argument, NULL, ECPG_GETOPT_LONG_HELP},
|
||||
{"version", no_argument, NULL, ECPG_GETOPT_LONG_VERSION},
|
||||
{"regression", no_argument, NULL, ECPG_GETOPT_LONG_REGRESSION},
|
||||
{ NULL, 0, NULL, 0}
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
int fnr,
|
||||
@@ -154,12 +154,14 @@ main(int argc, char *const argv[])
|
||||
case ECPG_GETOPT_LONG_HELP:
|
||||
help(progname);
|
||||
exit(0);
|
||||
/*
|
||||
* -? is an alternative spelling of --help. However it is also
|
||||
* returned by getopt_long for unknown options. We can distinguish
|
||||
* both cases by means of the optopt variable which is set to 0 if
|
||||
* it was really -? and not an unknown option character.
|
||||
*/
|
||||
|
||||
/*
|
||||
* -? is an alternative spelling of --help. However it is also
|
||||
* returned by getopt_long for unknown options. We can
|
||||
* distinguish both cases by means of the optopt variable
|
||||
* which is set to 0 if it was really -? and not an unknown
|
||||
* option character.
|
||||
*/
|
||||
case '?':
|
||||
if (optopt == 0)
|
||||
{
|
||||
@@ -177,7 +179,7 @@ main(int argc, char *const argv[])
|
||||
else
|
||||
yyout = fopen(output_filename, PG_BINARY_W);
|
||||
|
||||
if (yyout == NULL)
|
||||
if (yyout == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: could not open file \"%s\": %s\n",
|
||||
progname, output_filename, strerror(errno));
|
||||
@@ -280,7 +282,7 @@ main(int argc, char *const argv[])
|
||||
/* after the options there must not be anything but filenames */
|
||||
for (fnr = optind; fnr < argc; fnr++)
|
||||
{
|
||||
char *ptr2ext;
|
||||
char *ptr2ext;
|
||||
|
||||
/* If argv[fnr] is "-" we have to read from stdin */
|
||||
if (strcmp(argv[fnr], "-") == 0)
|
||||
@@ -430,7 +432,7 @@ main(int argc, char *const argv[])
|
||||
|
||||
/* we need several includes */
|
||||
/* but not if we are in header mode */
|
||||
if (regression_mode)
|
||||
if (regression_mode)
|
||||
fprintf(yyout, "/* Processed by ecpg (regression mode) */\n");
|
||||
else
|
||||
fprintf(yyout, "/* Processed by ecpg (%d.%d.%d) */\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
|
||||
@@ -446,7 +448,7 @@ main(int argc, char *const argv[])
|
||||
fprintf(yyout, "/* End of automatic include section */\n");
|
||||
}
|
||||
|
||||
if (regression_mode)
|
||||
if (regression_mode)
|
||||
fprintf(yyout, "#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))\n");
|
||||
|
||||
output_line_number();
|
||||
|
@@ -4,7 +4,7 @@
|
||||
* lexical token lookup for reserved words in postgres embedded SQL
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.36 2007/08/22 08:20:58 meskes Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.37 2007/11/15 21:14:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -63,4 +63,3 @@ static const ScanKeyword ScanECPGKeywords[] = {
|
||||
{"var", SQL_VAR},
|
||||
{"whenever", SQL_WHENEVER},
|
||||
};
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.69 2007/08/22 08:20:58 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.70 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#ifndef _ECPG_PREPROC_EXTERN_H
|
||||
#define _ECPG_PREPROC_EXTERN_H
|
||||
@@ -97,11 +97,11 @@ extern void remove_typedefs(int);
|
||||
extern void remove_variables(int);
|
||||
extern struct variable *new_variable(const char *, struct ECPGtype *, int);
|
||||
extern const ScanKeyword *ScanKeywordLookup(char *text);
|
||||
extern const ScanKeyword *DoLookup(char *, const ScanKeyword *,const ScanKeyword *);
|
||||
extern const ScanKeyword *DoLookup(char *, const ScanKeyword *, const ScanKeyword *);
|
||||
extern void scanner_init(const char *);
|
||||
extern void parser_init(void);
|
||||
extern void scanner_finish(void);
|
||||
extern int filtered_base_yylex(void);
|
||||
extern int filtered_base_yylex(void);
|
||||
|
||||
/* return codes */
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.83 2007/10/10 06:33:17 meskes Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.84 2007/11/15 21:14:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -474,4 +474,3 @@ ScanKeywordLookup(char *text)
|
||||
|
||||
return DoLookup(word, &ScanECPGKeywords[0], endof(ScanECPGKeywords) - 1);
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.22 2007/09/26 10:57:00 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.23 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@@ -130,7 +130,7 @@ output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
|
||||
fputs("ECPGt_EORT);", yyout);
|
||||
reset_variables();
|
||||
|
||||
whenever_action(whenever_mode|2);
|
||||
whenever_action(whenever_mode | 2);
|
||||
free(stmt);
|
||||
if (connection != NULL)
|
||||
free(connection);
|
||||
@@ -153,7 +153,8 @@ output_prepare_statement(char *name, char *stmt)
|
||||
void
|
||||
output_deallocate_prepare_statement(char *name)
|
||||
{
|
||||
const char* con = connection ? connection : "NULL";
|
||||
const char *con = connection ? connection : "NULL";
|
||||
|
||||
if (strcmp(name, "all"))
|
||||
{
|
||||
fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, ", compat, con);
|
||||
@@ -172,10 +173,12 @@ output_deallocate_prepare_statement(char *name)
|
||||
static void
|
||||
output_escaped_str(char *str, bool quoted)
|
||||
{
|
||||
int i = 0;
|
||||
int len = strlen(str);
|
||||
|
||||
if (quoted && str[0] == '\"' && str[len-1] == '\"') /* do not escape quotes at beginning and end if quoted string */
|
||||
int i = 0;
|
||||
int len = strlen(str);
|
||||
|
||||
if (quoted && str[0] == '\"' && str[len - 1] == '\"') /* do not escape quotes
|
||||
* at beginning and end
|
||||
* if quoted string */
|
||||
{
|
||||
i = 1;
|
||||
len--;
|
||||
@@ -200,6 +203,6 @@ output_escaped_str(char *str, bool quoted)
|
||||
fputc(str[i], yyout);
|
||||
}
|
||||
|
||||
if (quoted && str[0] == '\"' && str[len] == '\"')
|
||||
if (quoted && str[0] == '\"' && str[len] == '\"')
|
||||
fputs("\"", yyout);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parser.c,v 1.1 2007/10/26 14:17:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parser.c,v 1.2 2007/11/15 21:14:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -25,8 +25,8 @@
|
||||
#include "preproc.h"
|
||||
|
||||
|
||||
static bool have_lookahead; /* is lookahead info valid? */
|
||||
static int lookahead_token; /* one-token lookahead */
|
||||
static bool have_lookahead; /* is lookahead info valid? */
|
||||
static int lookahead_token; /* one-token lookahead */
|
||||
static YYSTYPE lookahead_yylval; /* yylval for lookahead token */
|
||||
static YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */
|
||||
|
||||
@@ -67,6 +67,7 @@ filtered_base_yylex(void)
|
||||
switch (cur_token)
|
||||
{
|
||||
case NULLS_P:
|
||||
|
||||
/*
|
||||
* NULLS FIRST and NULLS LAST must be reduced to one token
|
||||
*/
|
||||
@@ -95,6 +96,7 @@ filtered_base_yylex(void)
|
||||
break;
|
||||
|
||||
case WITH:
|
||||
|
||||
/*
|
||||
* WITH CASCADED, LOCAL, or CHECK must be reduced to one token
|
||||
*
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.75 2007/10/03 11:11:12 meskes Exp $ */
|
||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.76 2007/11/15 21:14:45 momjian Exp $ */
|
||||
|
||||
#include "postgres_fe.h"
|
||||
|
||||
@@ -101,7 +101,7 @@ ECPGmake_simple_type(enum ECPGttype type, char *size, int lineno)
|
||||
ne->size = size;
|
||||
ne->u.element = NULL;
|
||||
ne->struct_sizeof = NULL;
|
||||
ne->lineno = lineno; /* only needed for varchar */
|
||||
ne->lineno = lineno; /* only needed for varchar */
|
||||
|
||||
return ne;
|
||||
}
|
||||
@@ -259,7 +259,7 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
|
||||
|
||||
ECPGdump_a_simple(o, name,
|
||||
type->u.element->type,
|
||||
type->u.element->size, type->size, NULL, prefix, type->lineno);
|
||||
type->u.element->size, type->size, NULL, prefix, type->lineno);
|
||||
|
||||
if (ind_type != NULL)
|
||||
{
|
||||
@@ -328,7 +328,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
|
||||
else
|
||||
{
|
||||
char *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
|
||||
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize)+ sizeof(int) * CHAR_BIT * 10 / 3);
|
||||
char *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize) + sizeof(int) * CHAR_BIT * 10 / 3);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
@@ -25,7 +25,7 @@ struct ECPGtype
|
||||
struct ECPGstruct_member *members; /* A pointer to a list of
|
||||
* members. */
|
||||
} u;
|
||||
int lineno;
|
||||
int lineno;
|
||||
};
|
||||
|
||||
/* Everything is malloced. */
|
||||
@@ -97,9 +97,9 @@ struct su_symbol
|
||||
|
||||
struct prep
|
||||
{
|
||||
char *name;
|
||||
char *stmt;
|
||||
char *type;
|
||||
char *name;
|
||||
char *stmt;
|
||||
char *type;
|
||||
};
|
||||
|
||||
struct this_type
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress_ecpg.c,v 1.2 2007/06/14 13:10:11 mha Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress_ecpg.c,v 1.3 2007/11/15 21:14:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,13 +23,12 @@ static void
|
||||
ecpg_filter(const char *sourcefile, const char *outfile)
|
||||
{
|
||||
/*
|
||||
* Create a filtered copy of sourcefile, replacing
|
||||
* #line x "./../bla/foo.h"
|
||||
* with
|
||||
* #line x "foo.h"
|
||||
* Create a filtered copy of sourcefile, replacing #line x
|
||||
* "./../bla/foo.h" with #line x "foo.h"
|
||||
*/
|
||||
FILE *s, *t;
|
||||
char linebuf[LINEBUFSIZE];
|
||||
FILE *s,
|
||||
*t;
|
||||
char linebuf[LINEBUFSIZE];
|
||||
|
||||
s = fopen(sourcefile, "r");
|
||||
if (!s)
|
||||
@@ -49,9 +48,10 @@ ecpg_filter(const char *sourcefile, const char *outfile)
|
||||
/* check for "#line " in the beginning */
|
||||
if (strstr(linebuf, "#line ") == linebuf)
|
||||
{
|
||||
char *p = strchr(linebuf, '"');
|
||||
char *n;
|
||||
int plen = 1;
|
||||
char *p = strchr(linebuf, '"');
|
||||
char *n;
|
||||
int plen = 1;
|
||||
|
||||
while (*p && (*(p + plen) == '.' || strchr(p + plen, '/') != NULL))
|
||||
{
|
||||
plen++;
|
||||
@@ -60,8 +60,8 @@ ecpg_filter(const char *sourcefile, const char *outfile)
|
||||
if (plen > 1)
|
||||
{
|
||||
n = (char *) malloc(plen);
|
||||
strncpy(n, p+1, plen - 1);
|
||||
n[plen-1] = '\0';
|
||||
strncpy(n, p + 1, plen - 1);
|
||||
n[plen - 1] = '\0';
|
||||
replace_string(linebuf, n, "");
|
||||
}
|
||||
}
|
||||
@@ -78,18 +78,21 @@ ecpg_filter(const char *sourcefile, const char *outfile)
|
||||
|
||||
static PID_TYPE
|
||||
ecpg_start_test(const char *testname,
|
||||
_stringlist **resultfiles,
|
||||
_stringlist **expectfiles,
|
||||
_stringlist **tags)
|
||||
_stringlist ** resultfiles,
|
||||
_stringlist ** expectfiles,
|
||||
_stringlist ** tags)
|
||||
{
|
||||
PID_TYPE pid;
|
||||
char inprg[MAXPGPATH];
|
||||
char insource[MAXPGPATH];
|
||||
char *outfile_stdout, expectfile_stdout[MAXPGPATH];
|
||||
char *outfile_stderr, expectfile_stderr[MAXPGPATH];
|
||||
char *outfile_source, expectfile_source[MAXPGPATH];
|
||||
char *outfile_stdout,
|
||||
expectfile_stdout[MAXPGPATH];
|
||||
char *outfile_stderr,
|
||||
expectfile_stderr[MAXPGPATH];
|
||||
char *outfile_source,
|
||||
expectfile_source[MAXPGPATH];
|
||||
char cmd[MAXPGPATH * 3];
|
||||
char *testname_dash;
|
||||
char *testname_dash;
|
||||
|
||||
snprintf(inprg, sizeof(inprg), "%s/%s", inputdir, testname);
|
||||
|
||||
@@ -161,11 +164,11 @@ ecpg_init(void)
|
||||
/* no reason to set -w for ecpg checks, except for when on windows */
|
||||
if (strstr(host_platform, "-win32") || strstr(host_platform, "-mingw32"))
|
||||
basic_diff_opts = "-w";
|
||||
else
|
||||
else
|
||||
basic_diff_opts = "";
|
||||
if (strstr(host_platform, "-win32") || strstr(host_platform, "-mingw32"))
|
||||
pretty_diff_opts = "-C3 -w";
|
||||
else
|
||||
else
|
||||
pretty_diff_opts = "-C3";
|
||||
}
|
||||
|
||||
@@ -174,4 +177,3 @@ main(int argc, char *argv[])
|
||||
{
|
||||
return regression_main(argc, argv, ecpg_init, ecpg_start_test);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user