aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/ecpglib')
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c106
-rw-r--r--src/interfaces/ecpg/ecpglib/data.c47
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c4
-rw-r--r--src/interfaces/ecpg/ecpglib/error.c13
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c161
-rw-r--r--src/interfaces/ecpg/ecpglib/extern.h12
-rw-r--r--src/interfaces/ecpg/ecpglib/misc.c103
-rw-r--r--src/interfaces/ecpg/ecpglib/prepare.c20
8 files changed, 246 insertions, 220 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 1030b041ab1..679efb6466b 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.14 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.15 2003/08/04 00:43:32 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -15,49 +15,48 @@
#ifdef USE_THREADS
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
-static struct connection *all_connections = NULL;
+static struct connection *all_connections = NULL;
static struct connection *actual_connection = NULL;
static struct connection *
ecpg_get_connection_nr(const char *connection_name)
{
- struct connection *ret = NULL;
-
- if( (connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0) )
- {
- ret = actual_connection;
- }
- else
- {
- struct connection *con;
-
- for( con = all_connections; con != NULL; con = con->next)
+ struct connection *ret = NULL;
+
+ if ((connection_name == NULL) || (strcmp(connection_name, "CURRENT") == 0))
+ ret = actual_connection;
+ else
{
- if( strcmp(connection_name, con->name) == 0 )
- break;
+ struct connection *con;
+
+ for (con = all_connections; con != NULL; con = con->next)
+ {
+ if (strcmp(connection_name, con->name) == 0)
+ break;
+ }
+ ret = con;
}
- ret = con;
- }
- return( ret );
+ return (ret);
}
struct connection *
ECPGget_connection(const char *connection_name)
{
- struct connection *ret = NULL;
+ struct connection *ret = NULL;
+
#ifdef USE_THREADS
- pthread_mutex_lock(&connections_mutex);
+ pthread_mutex_lock(&connections_mutex);
#endif
-
- ret = ecpg_get_connection_nr(connection_name);
+
+ ret = ecpg_get_connection_nr(connection_name);
#ifdef USE_THREADS
- pthread_mutex_unlock(&connections_mutex);
+ pthread_mutex_unlock(&connections_mutex);
#endif
- return (ret);
-
+ return (ret);
+
}
static void
@@ -70,9 +69,10 @@ ecpg_finish(struct connection * act)
PQfinish(act->connection);
- /* no need to lock connections_mutex - we're always called
- by ECPGdisconnect or ECPGconnect, which are holding
- the lock */
+ /*
+ * no need to lock connections_mutex - we're always called by
+ * ECPGdisconnect or ECPGconnect, which are holding the lock
+ */
/* remove act from the list */
if (act == all_connections)
@@ -158,26 +158,26 @@ ECPGsetconn(int lineno, const char *connection_name)
static void
ECPGnoticeReceiver(void *arg, const PGresult *result)
{
- char *sqlstate = PQresultErrorField(result, 'C');
- char *message = PQresultErrorField(result, 'M');
+ char *sqlstate = PQresultErrorField(result, 'C');
+ char *message = PQresultErrorField(result, 'M');
struct sqlca_t *sqlca = ECPGget_sqlca();
- int sqlcode;
+ int sqlcode;
/* these are not warnings */
- if (strncmp(sqlstate, "00", 2)==0)
+ if (strncmp(sqlstate, "00", 2) == 0)
return;
ECPGlog("%s", message);
/* map to SQLCODE for backward compatibility */
- if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME)==0)
+ if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME) == 0)
sqlcode = ECPG_WARNING_UNKNOWN_PORTAL;
- else if (strcmp(sqlstate, ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION)==0)
+ else if (strcmp(sqlstate, ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION) == 0)
sqlcode = ECPG_WARNING_IN_TRANSACTION;
- else if (strcmp(sqlstate, ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION)==0)
+ else if (strcmp(sqlstate, ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION) == 0)
sqlcode = ECPG_WARNING_NO_TRANSACTION;
- else if (strcmp(sqlstate, ECPG_SQLSTATE_DUPLICATE_CURSOR)==0)
+ else if (strcmp(sqlstate, ECPG_SQLSTATE_DUPLICATE_CURSOR) == 0)
sqlcode = ECPG_WARNING_PORTAL_EXISTS;
else
sqlcode = 0;
@@ -210,21 +210,23 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
*options = NULL;
ECPGinit_sqlca(sqlca);
-
+
if (INFORMIX_MODE(compat))
{
- char *envname;
-
- /* Informix uses an environment variable DBPATH that overrides
- * the connection parameters given here.
- * We do the same with PG_DBPATH as the syntax is different. */
+ char *envname;
+
+ /*
+ * Informix uses an environment variable DBPATH that overrides the
+ * connection parameters given here. We do the same with PG_DBPATH
+ * as the syntax is different.
+ */
envname = getenv("PG_DBPATH");
if (envname)
{
ECPGfree(dbname);
dbname = strdup(envname);
}
-
+
}
if ((this = (struct connection *) ECPGalloc(sizeof(struct connection), lineno)) == NULL)
@@ -378,21 +380,21 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
if (PQstatus(this->connection) == CONNECTION_BAD)
{
- const char *errmsg = PQerrorMessage(this->connection);
- char *db = realname ? realname : "<DEFAULT>";
+ const char *errmsg = PQerrorMessage(this->connection);
+ char *db = realname ? realname : "<DEFAULT>";
ecpg_finish(this);
#ifdef USE_THREADS
pthread_mutex_unlock(&connections_mutex);
#endif
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
- db,
+ db,
host ? host : "<DEFAULT>",
port ? port : "<DEFAULT>",
options ? "with options " : "", options ? options : "",
user ? "for user " : "", user ? user : "",
lineno, errmsg);
-
+
ECPGraise(lineno, ECPG_CONNECT, ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION, db);
if (host)
ECPGfree(host);
@@ -455,14 +457,14 @@ ECPGdisconnect(int lineno, const char *connection_name)
con = ecpg_get_connection_nr(connection_name);
if (!ECPGinit(con, connection_name, lineno))
- {
+ {
#ifdef USE_THREADS
- pthread_mutex_unlock(&connections_mutex);
+ pthread_mutex_unlock(&connections_mutex);
#endif
- return (false);
- }
+ return (false);
+ }
else
- ecpg_finish(con);
+ ecpg_finish(con);
}
#ifdef USE_THREADS
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 14e459d1b60..e095ed671d3 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.15 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.16 2003/08/04 00:43:32 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -24,7 +24,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
struct sqlca_t *sqlca = ECPGget_sqlca();
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
- int value_for_indicator = 0;
+ int value_for_indicator = 0;
ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld\n", lineno, pval ? pval : "", offset);
@@ -54,11 +54,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
/* We will have to decode the value */
/*
- * check for null value and set indicator accordingly, i.e. -1 if NULL and 0 if not
+ * check for null value and set indicator accordingly, i.e. -1 if NULL
+ * and 0 if not
*/
if (PQgetisnull(results, act_tuple, act_field))
value_for_indicator = -1;
-
+
switch (ind_type)
{
case ECPGt_short:
@@ -81,11 +82,13 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
#endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_NO_INDICATOR:
if (value_for_indicator == -1)
- {
+ {
if (force_indicator == false)
{
- /* Informix has an additional way to specify NULLs
- * note that this uses special values to denote NULL */
+ /*
+ * Informix has an additional way to specify NULLs
+ * note that this uses special values to denote NULL
+ */
ECPGset_informix_null(type, var + offset * act_tuple);
}
else
@@ -109,13 +112,13 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
switch (type)
{
long res;
- unsigned long ures;
+ unsigned long ures;
double dres;
- char *scan_length;
- Numeric *nres;
+ char *scan_length;
+ Numeric *nres;
Date ddres;
Timestamp tres;
- Interval *ires;
+ Interval *ires;
case ECPGt_short:
case ECPGt_int:
@@ -294,9 +297,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_unsigned_char:
{
if (varcharsize == 0)
- {
- strncpy((char *) ((long) var + offset * act_tuple), pval, strlen(pval)+1);
- }
+ strncpy((char *) ((long) var + offset * act_tuple), pval, strlen(pval) + 1);
else
{
strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
@@ -340,9 +341,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
variable->len = strlen(pval);
if (varcharsize == 0)
- {
strncpy(variable->arr, pval, variable->len);
- }
else
{
strncpy(variable->arr, pval, varcharsize);
@@ -403,12 +402,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else
nres = PGTYPESnumeric_from_asc("0.0", &scan_length);
- if (type == ECPGt_numeric)
- PGTYPESnumeric_copy(nres, (Numeric *)(var + offset * act_tuple));
+ if (type == ECPGt_numeric)
+ PGTYPESnumeric_copy(nres, (Numeric *) (var + offset * act_tuple));
else
- PGTYPESnumeric_to_decimal(nres, (Decimal *)(var + offset * act_tuple));
+ PGTYPESnumeric_to_decimal(nres, (Decimal *) (var + offset * act_tuple));
break;
-
+
case ECPGt_interval:
if (pval)
{
@@ -430,7 +429,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else
ires = PGTYPESinterval_from_asc("0 seconds", NULL);
- PGTYPESinterval_copy(ires, (Interval *)(var + offset * act_tuple));
+ PGTYPESinterval_copy(ires, (Interval *) (var + offset * act_tuple));
break;
case ECPGt_date:
if (pval)
@@ -450,7 +449,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
return (false);
}
- *((Date *)(var + offset * act_tuple)) = ddres;
+ *((Date *) (var + offset * act_tuple)) = ddres;
}
break;
@@ -472,10 +471,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
return (false);
}
- *((Timestamp *)(var + offset * act_tuple)) = tres;
+ *((Timestamp *) (var + offset * act_tuple)) = tres;
}
break;
-
+
default:
ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(type));
return (false);
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 0beae2d93ab..839fc780cbc 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -1,6 +1,6 @@
/* dynamic SQL support routines
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.5 2003/08/01 13:53:36 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.6 2003/08/04 00:43:32 momjian Exp $
*/
#define POSTGRES_ECPG_INTERNAL
@@ -454,7 +454,7 @@ ECPGdescriptor_lvalue(int line, const char *descriptor)
}
bool
-ECPGdescribe(int line, bool input, const char *statement, ...)
+ECPGdescribe(int line, bool input, const char *statement,...)
{
ECPGlog("ECPGdescribe called on line %d for %s in %s\n", line, (input) ? "input" : "output", statement);
return false;
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index cfeb4e65b0b..33bac6e892d 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.5 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.6 2003/08/04 00:43:32 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -13,9 +13,10 @@
void
-ECPGraise(int line, int code, const char * sqlstate, const char *str)
+ECPGraise(int line, int code, const char *sqlstate, const char *str)
{
struct sqlca_t *sqlca = ECPGget_sqlca();
+
sqlca->sqlcode = code;
strncpy(sqlca->sqlstate, sqlstate, sizeof(sqlca->sqlstate));
@@ -161,8 +162,8 @@ ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
/* copy error message */
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
- "'%s' in line %d.",
- result ? PQresultErrorField(result, 'M') : PQerrorMessage(conn),
+ "'%s' in line %d.",
+ result ? PQresultErrorField(result, 'M') : PQerrorMessage(conn),
line);
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
@@ -172,9 +173,9 @@ ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
sizeof(sqlca->sqlstate));
/* assign SQLCODE for backward compatibility */
- if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate))==0)
+ if (strncmp(sqlca->sqlstate, "23505", sizeof(sqlca->sqlstate)) == 0)
sqlca->sqlcode = INFORMIX_MODE(compat) ? ECPG_INFORMIX_DUPLICATE_KEY : ECPG_DUPLICATE_KEY;
- if (strncmp(sqlca->sqlstate, "21000", sizeof(sqlca->sqlstate))==0)
+ if (strncmp(sqlca->sqlstate, "21000", sizeof(sqlca->sqlstate)) == 0)
sqlca->sqlcode = INFORMIX_MODE(compat) ? ECPG_INFORMIX_SUBSELECT_NOT_ONE : ECPG_SUBSELECT_NOT_ONE;
else
sqlca->sqlcode = ECPG_PGSQL;
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 0d4247897d5..c45441d47ca 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.22 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.23 2003/08/04 00:43:32 momjian Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -65,7 +65,7 @@ quote_postgres(char *arg, int lineno)
res[ri++] = '\'';
res[ri] = '\0';
-
+
return res;
}
@@ -138,13 +138,16 @@ create_statement(int lineno, int compat, int force_indicator, struct connection
else
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)
var->arrsize = 0;
if (var->varcharsize < 0)
var->varcharsize = 0;
-
+
var->ind_type = va_arg(ap, enum ECPGttype);
var->ind_pointer = va_arg(ap, char *);
var->ind_varcharsize = va_arg(ap, long);
@@ -157,8 +160,11 @@ create_statement(int lineno, int compat, int force_indicator, struct connection
var->ind_value = *((char **) (var->ind_pointer));
else
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)
var->ind_arrsize = 0;
@@ -482,11 +488,11 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
* we do not know if the attribute is an array here
*/
#if 0
- if (var->arrsize > 1 && ...)
- {
+ if (var->arrsize > 1 &&...)
+ {
ECPGraise(stmt->lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
return false;
- }
+ }
#endif
/*
@@ -739,7 +745,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
break;
case ECPGt_bool:
- if (!(mallocedval = ECPGalloc(var->arrsize +sizeof ("array []"), stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize + sizeof("array []"), stmt->lineno)))
return false;
if (var->arrsize > 1)
@@ -838,30 +844,30 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
case ECPGt_decimal:
case ECPGt_numeric:
{
- char *str = NULL;
- int slen;
- Numeric *nval = PGTYPESnumeric_new();
-
+ char *str = NULL;
+ int slen;
+ Numeric *nval = PGTYPESnumeric_new();
+
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
if (var->type == ECPGt_numeric)
- PGTYPESnumeric_copy((Numeric *)((var + var->offset * element)->value), nval);
+ PGTYPESnumeric_copy((Numeric *) ((var + var->offset * element)->value), nval);
else
- PGTYPESnumeric_from_decimal((Decimal *)((var + var->offset * element)->value), nval);
-
+ PGTYPESnumeric_from_decimal((Decimal *) ((var + var->offset * element)->value), nval);
+
str = PGTYPESnumeric_to_asc(nval, 0);
PGTYPESnumeric_free(nval);
- slen = strlen (str);
-
+ slen = strlen(str);
+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), stmt->lineno)))
return false;
-
+
if (!element)
strcpy(mallocedval, "array [");
-
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
@@ -869,22 +875,22 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
else
{
if (var->type == ECPGt_numeric)
- PGTYPESnumeric_copy((Numeric *)(var->value), nval);
+ PGTYPESnumeric_copy((Numeric *) (var->value), nval);
else
- PGTYPESnumeric_from_decimal((Decimal *)(var->value), nval);
-
+ PGTYPESnumeric_from_decimal((Decimal *) (var->value), nval);
+
str = PGTYPESnumeric_to_asc(nval, 0);
PGTYPESnumeric_free(nval);
- slen = strlen (str);
-
+ slen = strlen(str);
+
if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
return false;
- strncpy(mallocedval, str , slen);
+ strncpy(mallocedval, str, slen);
mallocedval[slen] = '\0';
}
-
+
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
@@ -893,41 +899,41 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
case ECPGt_interval:
{
- char *str = NULL;
- int slen;
-
+ char *str = NULL;
+ int slen;
+
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPESinterval_to_asc((Interval *)((var + var->offset * element)->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPESinterval_to_asc((Interval *) ((var + var->offset * element)->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), stmt->lineno)))
return false;
-
+
if (!element)
strcpy(mallocedval, "array [");
-
+
strcpy(mallocedval + strlen(mallocedval), "interval ");
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
- str = quote_postgres(PGTYPESinterval_to_asc((Interval *)(var->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPESinterval_to_asc((Interval *) (var->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, stmt->lineno)))
return false;
strcpy(mallocedval, "interval ");
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
}
-
+
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
@@ -936,90 +942,90 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
case ECPGt_date:
{
- char *str = NULL;
- int slen;
-
+ char *str = NULL;
+ int slen;
+
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPESdate_to_asc(*(Date *)((var + var->offset * element)->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPESdate_to_asc(*(Date *) ((var + var->offset * element)->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), stmt->lineno)))
return false;
-
+
if (!element)
strcpy(mallocedval, "array [");
-
+
strcpy(mallocedval + strlen(mallocedval), "date ");
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
- str = quote_postgres(PGTYPESdate_to_asc(*(Date *)(var->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPESdate_to_asc(*(Date *) (var->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, stmt->lineno)))
return false;
strcpy(mallocedval, "date ");
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
}
-
+
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
}
break;
-
+
case ECPGt_timestamp:
{
- char *str = NULL;
- int slen;
-
+ char *str = NULL;
+ int slen;
+
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)((var + var->offset * element)->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) ((var + var->offset * element)->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), stmt->lineno)))
return false;
-
+
if (!element)
strcpy(mallocedval, "array [");
-
+
strcpy(mallocedval + strlen(mallocedval), "timestamp ");
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)(var->value)), stmt->lineno);
- slen = strlen (str);
-
+ str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *) (var->value)), stmt->lineno);
+ slen = strlen(str);
+
if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, stmt->lineno)))
return false;
strcpy(mallocedval, "timestamp ");
/* also copy trailing '\0' */
- strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
+ strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
}
-
+
*tobeinserted_p = mallocedval;
*malloced_p = true;
free(str);
}
break;
-
+
default:
/* Not implemented yet */
ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, (char *) ECPGtype_name(var->type));
@@ -1219,10 +1225,10 @@ ECPGexecute(struct statement * stmt)
sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
- !sqlca->sqlerrd[2] &&
- ( !strncmp(cmdstat, "UPDATE", 6)
- || !strncmp(cmdstat, "INSERT", 6)
- || !strncmp(cmdstat, "DELETE", 6)))
+ !sqlca->sqlerrd[2] &&
+ (!strncmp(cmdstat, "UPDATE", 6)
+ || !strncmp(cmdstat, "INSERT", 6)
+ || !strncmp(cmdstat, "DELETE", 6)))
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
break;
case PGRES_NONFATAL_ERROR:
@@ -1326,4 +1332,3 @@ ECPGdo_descriptor(int line, const char *connection,
ECPGt_descriptor, descriptor, 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
}
-
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index d98f158bacc..3976d5b24db 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -5,7 +5,11 @@
#include "libpq-fe.h"
#include "sqlca.h"
-enum COMPAT_MODE { ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE};
+enum COMPAT_MODE
+{
+ ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX, ECPG_COMPAT_INFORMIX_SE
+};
+
#define INFORMIX_MODE(X) ((X) == ECPG_COMPAT_INFORMIX || (X) == ECPG_COMPAT_INFORMIX_SE)
/* Here are some methods used by the lib. */
@@ -51,7 +55,7 @@ struct statement
char *command;
struct connection *connection;
enum COMPAT_MODE compat;
- bool force_indicator;
+ bool force_indicator;
struct variable *inlist;
struct variable *outlist;
};
@@ -109,7 +113,7 @@ bool ECPGstore_result(const PGresult *results, int act_field,
#define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION "08001"
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST "08003"
#define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN "08007"
-#define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
+#define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
#define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
#define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION "25001"
#define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION "25P01"
@@ -124,4 +128,4 @@ bool ECPGstore_result(const PGresult *results, int act_field,
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR "YE000"
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY "YE001"
-#endif /* _ECPG_LIB_EXTERN_H */
+#endif /* _ECPG_LIB_EXTERN_H */
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index f42b8f721e7..e87643d8df5 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.12 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.13 2003/08/04 00:43:32 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -23,7 +23,7 @@
#define LONG_LONG_MIN LLONG_MIN
#endif
#endif
-
+
static struct sqlca_t sqlca_init =
{
{
@@ -52,8 +52,9 @@ static struct sqlca_t sqlca_init =
};
#ifdef USE_THREADS
-static pthread_key_t sqlca_key;
-static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
+static pthread_key_t sqlca_key;
+static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT;
+
#else
static struct sqlca_t sqlca =
{
@@ -84,22 +85,23 @@ static struct sqlca_t sqlca =
#endif
#ifdef USE_THREADS
-static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
-static int simple_debug = 0;
+static int simple_debug = 0;
static FILE *debugstream = NULL;
void
-ECPGinit_sqlca(struct sqlca_t *sqlca)
+ECPGinit_sqlca(struct sqlca_t * sqlca)
{
- memcpy((char *)sqlca, (char *)&sqlca_init, sizeof(struct sqlca_t));
+ memcpy((char *) sqlca, (char *) &sqlca_init, sizeof(struct sqlca_t));
}
bool
ECPGinit(const struct connection * con, const char *connection_name, const int lineno)
{
struct sqlca_t *sqlca = ECPGget_sqlca();
+
ECPGinit_sqlca(sqlca);
if (con == NULL)
{
@@ -115,7 +117,7 @@ ECPGinit(const struct connection * con, const char *connection_name, const int l
static void
ecpg_sqlca_key_init(void)
{
- pthread_key_create(&sqlca_key, NULL);
+ pthread_key_create(&sqlca_key, NULL);
}
#endif
@@ -123,20 +125,20 @@ struct sqlca_t *
ECPGget_sqlca(void)
{
#ifdef USE_THREADS
- struct sqlca_t *sqlca;
-
- pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
-
- sqlca = pthread_getspecific(sqlca_key);
- if( sqlca == NULL )
- {
- sqlca = malloc(sizeof(struct sqlca_t));
- ECPGinit_sqlca(sqlca);
- pthread_setspecific(sqlca_key, sqlca);
- }
- return( sqlca );
+ struct sqlca_t *sqlca;
+
+ pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
+
+ sqlca = pthread_getspecific(sqlca_key);
+ if (sqlca == NULL)
+ {
+ sqlca = malloc(sizeof(struct sqlca_t));
+ ECPGinit_sqlca(sqlca);
+ pthread_setspecific(sqlca_key, sqlca);
+ }
+ return (sqlca);
#else
- return( &sqlca );
+ return (&sqlca);
#endif
}
@@ -227,16 +229,17 @@ ECPGlog(const char *format,...)
pthread_mutex_lock(&debug_mutex);
#endif
- if( simple_debug )
+ if (simple_debug)
{
- char *f = (char *)malloc(strlen(format) + 100);
- if( f == NULL )
- {
+ char *f = (char *) malloc(strlen(format) + 100);
+
+ if (f == NULL)
+ {
#ifdef USE_THREADS
pthread_mutex_unlock(&debug_mutex);
#endif
return;
- }
+ }
sprintf(f, "[%d]: %s", (int) getpid(), format);
@@ -258,7 +261,7 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr)
{
switch (type)
{
- case ECPGt_char:
+ case ECPGt_char:
case ECPGt_unsigned_char:
*((char *) ptr) = 0x00;
break;
@@ -307,10 +310,12 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr)
}
}
-static bool _check(unsigned char *ptr, int length)
+static bool
+_check(unsigned char *ptr, int length)
{
- for (;ptr[--length] == 0xff && length >= 0; length --);
- if (length < 0) return true;
+ for (; ptr[--length] == 0xff && length >= 0; length--);
+ if (length < 0)
+ return true;
return false;
}
@@ -319,49 +324,57 @@ ECPGis_informix_null(enum ECPGttype type, void *ptr)
{
switch (type)
{
- case ECPGt_char:
+ case ECPGt_char:
case ECPGt_unsigned_char:
- if (*((char *)ptr) == 0x00) return true;
+ if (*((char *) ptr) == 0x00)
+ return true;
break;
case ECPGt_short:
case ECPGt_unsigned_short:
- if (*((short int *) ptr) == SHRT_MIN) return true;
+ if (*((short int *) ptr) == SHRT_MIN)
+ return true;
break;
case ECPGt_int:
case ECPGt_unsigned_int:
- if (*((int *) ptr) == INT_MIN) return true;
+ if (*((int *) ptr) == INT_MIN)
+ return true;
break;
case ECPGt_long:
case ECPGt_unsigned_long:
case ECPGt_date:
- if (*((long *) ptr) == LONG_MIN) return true;
+ if (*((long *) ptr) == LONG_MIN)
+ return true;
break;
#ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long:
case ECPGt_unsigned_long_long:
- if (*((long long *) ptr) == LONG_LONG_MIN) return true;
+ if (*((long long *) ptr) == LONG_LONG_MIN)
+ return true;
break;
#endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_float:
- return(_check(ptr, sizeof(float)));
+ return (_check(ptr, sizeof(float)));
break;
case ECPGt_double:
- return(_check(ptr, sizeof(double)));
+ return (_check(ptr, sizeof(double)));
break;
case ECPGt_varchar:
- if (*(((struct ECPGgeneric_varchar *) ptr)->arr) == 0x00) return true;
+ if (*(((struct ECPGgeneric_varchar *) ptr)->arr) == 0x00)
+ return true;
break;
case ECPGt_decimal:
- if (((Decimal *) ptr)->sign == NUMERIC_NAN) return true;
+ if (((Decimal *) ptr)->sign == NUMERIC_NAN)
+ return true;
break;
case ECPGt_numeric:
- if (((Numeric *) ptr)->sign == NUMERIC_NAN) return true;
+ if (((Numeric *) ptr)->sign == NUMERIC_NAN)
+ return true;
break;
case ECPGt_interval:
- return(_check(ptr, sizeof(Interval)));
+ return (_check(ptr, sizeof(Interval)));
break;
case ECPGt_timestamp:
- return(_check(ptr, sizeof(Timestamp)));
+ return (_check(ptr, sizeof(Timestamp)));
break;
default:
break;
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index 5569d36da07..55f497e03ab 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.8 2003/08/01 13:53:36 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.9 2003/08/04 00:43:32 momjian Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -66,7 +66,7 @@ ECPGprepare(int lineno, char *name, char *variable)
for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
if (this)
{
- bool b = ECPGdeallocate(lineno, ECPG_COMPAT_PGSQL, name);
+ bool b = ECPGdeallocate(lineno, ECPG_COMPAT_PGSQL, name);
if (!b)
return false;
@@ -109,17 +109,19 @@ ECPGprepare(int lineno, char *name, char *variable)
bool
ECPGdeallocate(int lineno, int c, char *name)
{
- bool ret = ECPGdeallocate_one(lineno, name);
+ bool ret = ECPGdeallocate_one(lineno, name);
enum COMPAT_MODE compat = c;
if (INFORMIX_MODE(compat))
{
- /* Just ignore all errors since we do not know the list of cursors we
- * are allowed to free. We have to trust that the software. */
- return true;
+ /*
+ * Just ignore all errors since we do not know the list of cursors
+ * we are allowed to free. We have to trust that the software.
+ */
+ return true;
}
-
- if (!ret)
+
+ if (!ret)
ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, name);
return ret;
@@ -156,7 +158,7 @@ ECPGdeallocate_all(int lineno)
/* deallocate all prepared statements */
while (prep_stmts != NULL)
{
- bool b = ECPGdeallocate(lineno, ECPG_COMPAT_PGSQL, prep_stmts->name);
+ bool b = ECPGdeallocate(lineno, ECPG_COMPAT_PGSQL, prep_stmts->name);
if (!b)
return false;