summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg')
-rw-r--r--src/interfaces/ecpg/include/ecpgerrno.h2
-rw-r--r--src/interfaces/ecpg/include/ecpglib.h20
-rw-r--r--src/interfaces/ecpg/include/ecpgtype.h2
-rw-r--r--src/interfaces/ecpg/include/sql3types.h23
-rw-r--r--src/interfaces/ecpg/include/sqlca.h3
-rw-r--r--src/interfaces/ecpg/lib/connect.c13
-rw-r--r--src/interfaces/ecpg/lib/data.c394
-rw-r--r--src/interfaces/ecpg/lib/descriptor.c409
-rw-r--r--src/interfaces/ecpg/lib/error.c256
-rw-r--r--src/interfaces/ecpg/lib/execute.c246
-rw-r--r--src/interfaces/ecpg/lib/extern.h33
-rw-r--r--src/interfaces/ecpg/lib/misc.c12
-rw-r--r--src/interfaces/ecpg/lib/prepare.c28
-rw-r--r--src/interfaces/ecpg/lib/typename.c45
-rw-r--r--src/interfaces/ecpg/preproc/descriptor.c104
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c56
-rw-r--r--src/interfaces/ecpg/preproc/ecpg_keywords.c3
-rw-r--r--src/interfaces/ecpg/preproc/extern.h39
-rw-r--r--src/interfaces/ecpg/preproc/output.c97
-rw-r--r--src/interfaces/ecpg/preproc/type.c36
-rw-r--r--src/interfaces/ecpg/preproc/type.h23
-rw-r--r--src/interfaces/ecpg/preproc/variable.c430
-rw-r--r--src/interfaces/ecpg/test/header_test.h26
23 files changed, 1197 insertions, 1103 deletions
diff --git a/src/interfaces/ecpg/include/ecpgerrno.h b/src/interfaces/ecpg/include/ecpgerrno.h
index 37443badcd2..2a826988be5 100644
--- a/src/interfaces/ecpg/include/ecpgerrno.h
+++ b/src/interfaces/ecpg/include/ecpgerrno.h
@@ -14,7 +14,7 @@
/* first we have a set of ecpg messages, they start at 200 */
#define ECPG_UNSUPPORTED -200
-#define ECPG_TOO_MANY_ARGUMENTS -201
+#define ECPG_TOO_MANY_ARGUMENTS -201
#define ECPG_TOO_FEW_ARGUMENTS -202
#define ECPG_TOO_MANY_MATCHES -203
#define ECPG_INT_FORMAT -204
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index 8b8dd3f3b5c..8b7e1ecd403 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -17,27 +17,27 @@ extern "C"
bool ECPGprepare(int, char *, char *);
bool ECPGdeallocate(int, char *);
bool ECPGdeallocate_all(int);
- char *ECPGprepared_statement(char *);
-
+ char *ECPGprepared_statement(char *);
+
void ECPGlog(const char *format,...);
-
+
/* print an error message */
void sqlprint(void);
-
+
/* define this for simplicity as well as compatibility */
#define SQLCODE sqlca.sqlcode
/* dynamic SQL */
- bool ECPGdo_descriptor(int line,const char *connection,
- const char *descriptor,const char *query);
- bool ECPGdeallocate_desc(int line,const char *name);
- bool ECPGallocate_desc(int line,const char *name);
+ bool ECPGdo_descriptor(int line, const char *connection,
+ const char *descriptor, const char *query);
+ bool ECPGdeallocate_desc(int line, const char *name);
+ bool ECPGallocate_desc(int line, const char *name);
void ECPGraise(int line, int code, char *str);
bool ECPGget_desc_header(int, char *, int *);
- bool ECPGget_desc(int, char *, int, ...);
-
+ bool ECPGget_desc(int, char *, int,...);
+
#ifdef __cplusplus
}
diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h
index b19ba177c0c..8268e5495bd 100644
--- a/src/interfaces/ecpg/include/ecpgtype.h
+++ b/src/interfaces/ecpg/include/ecpgtype.h
@@ -50,7 +50,7 @@ extern "C"
ECPGt_NO_INDICATOR /* no indicator */
};
- /* descriptor items */
+ /* descriptor items */
enum ECPGdtype
{
ECPGd_count,
diff --git a/src/interfaces/ecpg/include/sql3types.h b/src/interfaces/ecpg/include/sql3types.h
index 3aa86f50f09..e7e153f34ca 100644
--- a/src/interfaces/ecpg/include/sql3types.h
+++ b/src/interfaces/ecpg/include/sql3types.h
@@ -2,12 +2,14 @@
*
* Copyright (c) 2000, Christof Petig <[email protected]>
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.3 2000/03/17 23:26:30 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.4 2000/04/12 17:17:01 momjian Exp $
*/
/* chapter 13.1 table 2: Codes used for SQL data types in Dynamic SQL */
-enum { SQL3_CHARACTER=1,
+enum
+{
+ SQL3_CHARACTER = 1,
SQL3_NUMERIC,
SQL3_DECIMAL,
SQL3_INTEGER,
@@ -16,23 +18,26 @@ enum { SQL3_CHARACTER=1,
SQL3_REAL,
SQL3_DOUBLE_PRECISION,
SQL3_DATE_TIME_TIMESTAMP,
- SQL3_INTERVAL, /* 10 */
- SQL3_CHARACTER_VARYING=12,
+ SQL3_INTERVAL, /* 10 */
+ SQL3_CHARACTER_VARYING = 12,
SQL3_ENUMERATED,
SQL3_BIT,
SQL3_BIT_VARYING,
SQL3_BOOLEAN,
SQL3_abstract
/* the rest is xLOB stuff */
- };
+};
/* chapter 13.1 table 3: Codes associated with datetime data types in Dynamic SQL */
-enum { SQL3_DDT_DATE=1,
+enum
+{
+ SQL3_DDT_DATE = 1,
SQL3_DDT_TIME,
SQL3_DDT_TIMESTAMP,
SQL3_DDT_TIME_WITH_TIME_ZONE,
SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE,
-
- SQL3_DDT_ILLEGAL /* not a datetime data type (not part of standard) */
- };
+
+ SQL3_DDT_ILLEGAL /* not a datetime data type (not part of
+ * standard) */
+};
diff --git a/src/interfaces/ecpg/include/sqlca.h b/src/interfaces/ecpg/include/sqlca.h
index 0fa4a624181..71987648b4d 100644
--- a/src/interfaces/ecpg/include/sqlca.h
+++ b/src/interfaces/ecpg/include/sqlca.h
@@ -21,7 +21,7 @@ extern "C"
char sqlerrp[8];
long sqlerrd[6];
/* Element 0: empty */
- /* 1: OID of processed tuple if applicable */
+ /* 1: OID of processed tuple if applicable */
/* 2: number of rows processed */
/* after an INSERT, UPDATE or */
/* DELETE statement */
@@ -48,6 +48,7 @@ extern "C"
#ifdef __cplusplus
}
+
#endif
#endif
diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c
index 0a4d915c3e9..8452271926e 100644
--- a/src/interfaces/ecpg/lib/connect.c
+++ b/src/interfaces/ecpg/lib/connect.c
@@ -4,7 +4,8 @@
#include "extern.h"
#include <sqlca.h>
-static struct connection *all_connections = NULL, *actual_connection = NULL;
+static struct connection *all_connections = NULL,
+ *actual_connection = NULL;
struct connection *
get_connection(const char *connection_name)
@@ -58,10 +59,10 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
PGresult *results;
if (!ecpg_init(con, connection_name, lineno))
- return(false);
+ return (false);
ECPGlog("ECPGsetcommit line %d action = %s connection = %s\n", lineno, mode, con->name);
-
+
if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0)
{
if (con->committed)
@@ -100,7 +101,7 @@ ECPGsetconn(int lineno, const char *connection_name)
struct connection *con = get_connection(connection_name);
if (!ecpg_init(con, connection_name, lineno))
- return(false);
+ return (false);
actual_connection = con;
return true;
@@ -112,7 +113,7 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd
struct connection *this;
init_sqlca();
-
+
if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
return false;
@@ -171,7 +172,7 @@ ECPGdisconnect(int lineno, const char *connection_name)
con = get_connection(connection_name);
if (!ecpg_init(con, connection_name, lineno))
- return(false);
+ return (false);
else
ecpg_finish(con);
}
diff --git a/src/interfaces/ecpg/lib/data.c b/src/interfaces/ecpg/lib/data.c
index b7398caf6d7..1b97478e20d 100644
--- a/src/interfaces/ecpg/lib/data.c
+++ b/src/interfaces/ecpg/lib/data.c
@@ -8,11 +8,11 @@
bool
get_data(PGresult *results, int act_tuple, int act_field, int lineno,
- enum ECPGttype type, enum ECPGttype ind_type,
- void *var, void *ind, long varcharsize, long offset,
- bool isarray)
+ enum ECPGttype type, enum ECPGttype ind_type,
+ void *var, void *ind, long varcharsize, long offset,
+ bool isarray)
{
- char *pval = (char *)PQgetvalue(results, act_tuple, act_field);
+ char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
ECPGlog("get_data line %d: RESULT: %s\n", lineno, pval ? pval : "");
@@ -20,20 +20,20 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
/* let's check is it really is an array if it should be */
if (isarray)
{
- if (*pval != '{')
+ if (*pval != '{')
{
ECPGlog("get_data data entry does not look like an array in line %d\n", lineno);
ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, NULL);
- return(false);
+ return (false);
}
- else ++pval;
+ else
+ ++pval;
}
/* We will have to decode the value */
/*
- * check for null value and set indicator
- * accordingly
+ * check for null value and set indicator accordingly
*/
switch (ind_type)
{
@@ -61,226 +61,226 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno,
return (false);
break;
}
-
+
do
- {
- switch (type)
- {
- long res;
- unsigned long ures;
- double dres;
- char *scan_length;
+ {
+ switch (type)
+ {
+ long res;
+ unsigned long ures;
+ double dres;
+ char *scan_length;
- case ECPGt_short:
- case ECPGt_int:
- case ECPGt_long:
- if (pval)
- {
- res = strtol(pval, &scan_length, 10);
- if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0')) /* Garbage left */
+ case ECPGt_short:
+ case ECPGt_int:
+ case ECPGt_long:
+ if (pval)
{
- ECPGraise(lineno, ECPG_INT_FORMAT, pval);
- return (false);
- res = 0L;
+ res = strtol(pval, &scan_length, 10);
+ if ((isarray && *scan_length != ',' && *scan_length != '}')
+ || (!isarray && *scan_length != '\0')) /* Garbage left */
+ {
+ ECPGraise(lineno, ECPG_INT_FORMAT, pval);
+ return (false);
+ res = 0L;
+ }
}
- }
- else
- res = 0L;
-
- switch (type)
- {
- case ECPGt_short:
- ((short *) var)[act_tuple] = (short) res;
- break;
- case ECPGt_int:
- ((int *) var)[act_tuple] = (int) res;
- break;
- case ECPGt_long:
- ((long *) var)[act_tuple] = res;
- break;
- default:
- /* Cannot happen */
- break;
- }
- break;
+ else
+ res = 0L;
- case ECPGt_unsigned_short:
- case ECPGt_unsigned_int:
- case ECPGt_unsigned_long:
- if (pval)
- {
- ures = strtoul(pval, &scan_length, 10);
- if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0')) /* Garbage left */
+ switch (type)
{
- ECPGraise(lineno, ECPG_UINT_FORMAT, pval);
- return (false);
- ures = 0L;
+ case ECPGt_short:
+ ((short *) var)[act_tuple] = (short) res;
+ break;
+ case ECPGt_int:
+ ((int *) var)[act_tuple] = (int) res;
+ break;
+ case ECPGt_long:
+ ((long *) var)[act_tuple] = res;
+ break;
+ default:
+ /* Cannot happen */
+ break;
}
- }
- else
- ures = 0L;
-
- switch (type)
- {
- case ECPGt_unsigned_short:
- ((unsigned short *) var)[act_tuple] = (unsigned short) ures;
- break;
- case ECPGt_unsigned_int:
- ((unsigned int *) var)[act_tuple] = (unsigned int) ures;
- break;
- case ECPGt_unsigned_long:
- ((unsigned long *) var)[act_tuple] = ures;
- break;
- default:
- /* Cannot happen */
- break;
- }
- break;
+ break;
+ case ECPGt_unsigned_short:
+ case ECPGt_unsigned_int:
+ case ECPGt_unsigned_long:
+ if (pval)
+ {
+ ures = strtoul(pval, &scan_length, 10);
+ if ((isarray && *scan_length != ',' && *scan_length != '}')
+ || (!isarray && *scan_length != '\0')) /* Garbage left */
+ {
+ ECPGraise(lineno, ECPG_UINT_FORMAT, pval);
+ return (false);
+ ures = 0L;
+ }
+ }
+ else
+ ures = 0L;
- case ECPGt_float:
- case ECPGt_double:
- if (pval)
- {
- dres = strtod(pval, &scan_length);
- if ((isarray && *scan_length != ',' && *scan_length != '}')
- || (!isarray && *scan_length != '\0')) /* Garbage left */
+ switch (type)
{
- ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
- return (false);
- dres = 0.0;
+ case ECPGt_unsigned_short:
+ ((unsigned short *) var)[act_tuple] = (unsigned short) ures;
+ break;
+ case ECPGt_unsigned_int:
+ ((unsigned int *) var)[act_tuple] = (unsigned int) ures;
+ break;
+ case ECPGt_unsigned_long:
+ ((unsigned long *) var)[act_tuple] = ures;
+ break;
+ default:
+ /* Cannot happen */
+ break;
}
- }
- else
- dres = 0.0;
+ break;
- switch (type)
- {
- case ECPGt_float:
- ((float *) var)[act_tuple] = dres;
- break;
- case ECPGt_double:
- ((double *) var)[act_tuple] = dres;
- break;
- default:
- /* Cannot happen */
- break;
- }
- break;
- case ECPGt_bool:
- if (pval)
- {
- if (pval[0] == 'f' && pval[1] == '\0')
+ case ECPGt_float:
+ case ECPGt_double:
+ if (pval)
{
- ((char *) var)[act_tuple] = false;
- break;
+ dres = strtod(pval, &scan_length);
+ if ((isarray && *scan_length != ',' && *scan_length != '}')
+ || (!isarray && *scan_length != '\0')) /* Garbage left */
+ {
+ ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
+ return (false);
+ dres = 0.0;
+ }
}
- else if (pval[0] == 't' && pval[1] == '\0')
+ else
+ dres = 0.0;
+
+ switch (type)
{
- ((char *) var)[act_tuple] = true;
- break;
+ case ECPGt_float:
+ ((float *) var)[act_tuple] = dres;
+ break;
+ case ECPGt_double:
+ ((double *) var)[act_tuple] = dres;
+ break;
+ default:
+ /* Cannot happen */
+ break;
}
- else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
+ break;
+
+ case ECPGt_bool:
+ if (pval)
{
- /* NULL is valid */
- break;
+ if (pval[0] == 'f' && pval[1] == '\0')
+ {
+ ((char *) var)[act_tuple] = false;
+ break;
+ }
+ else if (pval[0] == 't' && pval[1] == '\0')
+ {
+ ((char *) var)[act_tuple] = true;
+ break;
+ }
+ else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
+ {
+ /* NULL is valid */
+ break;
+ }
}
- }
- ECPGraise(lineno, ECPG_CONVERT_BOOL, pval);
- return (false);
- break;
+ ECPGraise(lineno, ECPG_CONVERT_BOOL, pval);
+ return (false);
+ break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- {
- strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
- if (varcharsize && varcharsize < strlen(pval))
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
{
- /* truncation */
- switch (ind_type)
+ strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
+ if (varcharsize && varcharsize < strlen(pval))
{
- case ECPGt_short:
- case ECPGt_unsigned_short:
- ((short *) ind)[act_tuple] = varcharsize;
- break;
- case ECPGt_int:
- case ECPGt_unsigned_int:
- ((int *) ind)[act_tuple] = varcharsize;
- break;
- case ECPGt_long:
- case ECPGt_unsigned_long:
- ((long *) ind)[act_tuple] = varcharsize;
- break;
- default:
- break;
+ /* truncation */
+ switch (ind_type)
+ {
+ case ECPGt_short:
+ case ECPGt_unsigned_short:
+ ((short *) ind)[act_tuple] = varcharsize;
+ break;
+ case ECPGt_int:
+ case ECPGt_unsigned_int:
+ ((int *) ind)[act_tuple] = varcharsize;
+ break;
+ case ECPGt_long:
+ case ECPGt_unsigned_long:
+ ((long *) ind)[act_tuple] = varcharsize;
+ break;
+ default:
+ break;
+ }
+ sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
}
- sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
}
- }
- break;
+ break;
- case ECPGt_varchar:
- {
- struct ECPGgeneric_varchar *variable =
- (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
+ case ECPGt_varchar:
+ {
+ struct ECPGgeneric_varchar *variable =
+ (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
- if (varcharsize == 0)
- strncpy(variable->arr, pval, strlen(pval));
- else
- strncpy(variable->arr, pval, varcharsize);
+ if (varcharsize == 0)
+ strncpy(variable->arr, pval, strlen(pval));
+ else
+ strncpy(variable->arr, pval, varcharsize);
- variable->len = strlen(pval);
- if (varcharsize > 0 && variable->len > varcharsize)
- {
- /* truncation */
- switch (ind_type)
+ variable->len = strlen(pval);
+ if (varcharsize > 0 && variable->len > varcharsize)
{
- case ECPGt_short:
- case ECPGt_unsigned_short:
- ((short *) ind)[act_tuple] = varcharsize;
- break;
- case ECPGt_int:
- case ECPGt_unsigned_int:
- ((int *) ind)[act_tuple] = varcharsize;
- break;
- case ECPGt_long:
- case ECPGt_unsigned_long:
- ((long *) ind)[act_tuple] = varcharsize;
- break;
- default:
- break;
- }
- sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
+ /* truncation */
+ switch (ind_type)
+ {
+ case ECPGt_short:
+ case ECPGt_unsigned_short:
+ ((short *) ind)[act_tuple] = varcharsize;
+ break;
+ case ECPGt_int:
+ case ECPGt_unsigned_int:
+ ((int *) ind)[act_tuple] = varcharsize;
+ break;
+ case ECPGt_long:
+ case ECPGt_unsigned_long:
+ ((long *) ind)[act_tuple] = varcharsize;
+ break;
+ default:
+ break;
+ }
+ sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
- variable->len = varcharsize;
+ variable->len = varcharsize;
+ }
}
- }
- break;
+ break;
- default:
- ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type));
- return (false);
- break;
- }
- if (isarray)
- {
- bool string = false;
-
- /* set array to next entry */
- ++act_tuple;
-
- /* set pval to the next entry */
- for (; string || (*pval != ',' && *pval != '}'); ++pval)
- if (*pval == '"')
- string = string ? false : true;
-
- if (*pval == ',')
- ++pval;
- }
+ default:
+ ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type));
+ return (false);
+ break;
+ }
+ if (isarray)
+ {
+ bool string = false;
+
+ /* set array to next entry */
+ ++act_tuple;
+
+ /* set pval to the next entry */
+ for (; string || (*pval != ',' && *pval != '}'); ++pval)
+ if (*pval == '"')
+ string = string ? false : true;
+
+ if (*pval == ',')
+ ++pval;
+ }
} while (isarray && *pval != '}');
return (true);
diff --git a/src/interfaces/ecpg/lib/descriptor.c b/src/interfaces/ecpg/lib/descriptor.c
index b1fe2b79d04..c79baf799ac 100644
--- a/src/interfaces/ecpg/lib/descriptor.c
+++ b/src/interfaces/ecpg/lib/descriptor.c
@@ -6,265 +6,270 @@
struct descriptor
{
- char *name;
- PGresult *result;
- struct descriptor *next;
-} *all_descriptors = NULL;
-
+ char *name;
+ PGresult *result;
+ struct descriptor *next;
+} *all_descriptors = NULL;
+
static PGresult
-*ECPGresultByDescriptor(int line,const char *name)
+ *
+ECPGresultByDescriptor(int line, const char *name)
{
struct descriptor *i;
-
+
for (i = all_descriptors; i != NULL; i = i->next)
{
- if (!strcmp(name, i->name)) return i->result;
+ if (!strcmp(name, i->name))
+ return i->result;
}
-
+
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
-
+
return NULL;
-}
+}
static unsigned int
ECPGDynamicType_DDT(Oid type)
{
- switch(type)
- {
- case 1082: return SQL3_DDT_DATE; /* date */
- case 1083: return SQL3_DDT_TIME; /* time */
- case 1184: return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* datetime */
- case 1296: return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* timestamp */
+ switch (type)
+ {
+ case 1082:return SQL3_DDT_DATE; /* date */
+ case 1083:
+ return SQL3_DDT_TIME; /* time */
+ case 1184:
+ return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* datetime */
+ case 1296:
+ return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* timestamp */
default:
return SQL3_DDT_ILLEGAL;
}
}
bool
-ECPGget_desc_header(int lineno, char * desc_name, int *count)
+ECPGget_desc_header(int lineno, char *desc_name, int *count)
{
- PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
-
+ PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
+
if (!ECPGresult)
return false;
*count = PQnfields(ECPGresult);
ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count);
return true;
-}
+}
static bool
get_int_item(int lineno, void *var, enum ECPGdtype vartype, int value)
{
switch (vartype)
- {
- case ECPGt_short:
- *(short *)var = value;
- break;
+ {
+ case ECPGt_short:
+ *(short *) var = value;
+ break;
case ECPGt_int:
- *(int *)var = value;
- break;
- case ECPGt_long:
- *(long *)var = value;
- break;
- case ECPGt_unsigned_short:
- *(unsigned short *)var = value;
- break;
+ *(int *) var = value;
+ break;
+ case ECPGt_long:
+ *(long *) var = value;
+ break;
+ case ECPGt_unsigned_short:
+ *(unsigned short *) var = value;
+ break;
case ECPGt_unsigned_int:
- *(unsigned int *)var = value;
- break;
- case ECPGt_unsigned_long:
- *(unsigned long *)var = value;
- break;
- case ECPGt_float:
- *(float *)var = value;
- break;
- case ECPGt_double:
- *(double *)var = value;
- break;
- default:
- ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL);
- return (false);
+ *(unsigned int *) var = value;
+ break;
+ case ECPGt_unsigned_long:
+ *(unsigned long *) var = value;
+ break;
+ case ECPGt_float:
+ *(float *) var = value;
+ break;
+ case ECPGt_double:
+ *(double *) var = value;
+ break;
+ default:
+ ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL);
+ return (false);
}
-
- return(true);
+
+ return (true);
}
static bool
get_char_item(int lineno, void *var, enum ECPGdtype vartype, char *value, int varcharsize)
{
switch (vartype)
- {
- case ECPGt_char:
- case ECPGt_unsigned_char:
- strncpy((char *) var, value, varcharsize);
- break;
- case ECPGt_varchar:
- {
- struct ECPGgeneric_varchar *variable =
- (struct ECPGgeneric_varchar *) var;
-
- if (varcharsize == 0)
+ {
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
+ strncpy((char *) var, value, varcharsize);
+ break;
+ case ECPGt_varchar:
+ {
+ struct ECPGgeneric_varchar *variable =
+ (struct ECPGgeneric_varchar *) var;
+
+ if (varcharsize == 0)
strncpy(variable->arr, value, strlen(value));
- else
- strncpy(variable->arr, value, varcharsize);
-
- variable->len = strlen(value);
- if (varcharsize > 0 && variable->len > varcharsize)
- variable->len = varcharsize;
- }
- break;
- default:
- ECPGraise(lineno, ECPG_VAR_NOT_CHAR, NULL);
- return (false);
+ else
+ strncpy(variable->arr, value, varcharsize);
+
+ variable->len = strlen(value);
+ if (varcharsize > 0 && variable->len > varcharsize)
+ variable->len = varcharsize;
+ }
+ break;
+ default:
+ ECPGraise(lineno, ECPG_VAR_NOT_CHAR, NULL);
+ return (false);
}
-
- return(true);
+
+ return (true);
}
bool
-ECPGget_desc(int lineno, char *desc_name, int index, ...)
+ECPGget_desc(int lineno, char *desc_name, int index,...)
{
- va_list args;
- PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
- enum ECPGdtype type;
+ va_list args;
+ PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
+ enum ECPGdtype type;
bool DataButNoIndicator = false;
-
+
va_start(args, index);
- if (!ECPGresult)
- return (false);
-
- if (PQntuples(ECPGresult) < 1)
- {
- ECPGraise(lineno, ECPG_NOT_FOUND, NULL);
- return (false);
- }
-
- if (index < 1 || index >PQnfields(ECPGresult))
- {
- ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL);
- return (false);
- }
+ if (!ECPGresult)
+ return (false);
+
+ if (PQntuples(ECPGresult) < 1)
+ {
+ ECPGraise(lineno, ECPG_NOT_FOUND, NULL);
+ return (false);
+ }
+
+ if (index < 1 || index > PQnfields(ECPGresult))
+ {
+ ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL);
+ return (false);
+ }
ECPGlog("ECPGget_desc: reading items for tuple %d\n", index);
- --index;
-
- type = va_arg(args, enum ECPGdtype);
-
- while (type != ECPGd_EODT)
- {
- char type_str[20];
- long varcharsize;
- long offset;
- long arrsize;
- enum ECPGttype vartype;
- void *var;
-
- vartype = va_arg(args, enum ECPGttype);
- var = va_arg(args, void *);
- varcharsize = va_arg(args, long);
- arrsize = va_arg(args, long);
+ --index;
+
+ type = va_arg(args, enum ECPGdtype);
+
+ while (type != ECPGd_EODT)
+ {
+ char type_str[20];
+ long varcharsize;
+ long offset;
+ long arrsize;
+ enum ECPGttype vartype;
+ void *var;
+
+ vartype = va_arg(args, enum ECPGttype);
+ var = va_arg(args, void *);
+ varcharsize = va_arg(args, long);
+ arrsize = va_arg(args, long);
offset = va_arg(args, long);
-
- switch (type)
- {
- case (ECPGd_indicator):
- if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index)))
- return (false);
-
- ECPGlog("ECPGget_desc: INDICATOR = %d\n", -PQgetisnull(ECPGresult, 0, index));
- break;
-
- case ECPGd_name:
- if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize))
- return(false);
-
- ECPGlog("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index));
- break;
-
- case ECPGd_nullable:
- if (!get_int_item(lineno, var, vartype, 1))
- return (false);
-
- break;
-
- case ECPGd_key_member:
- if (!get_int_item(lineno, var, vartype, 0))
- return (false);
-
- break;
-
- case ECPGd_scale:
- if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
- return (false);
-
- ECPGlog("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff);
- break;
-
- case ECPGd_precision:
- if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
- return (false);
-
- ECPGlog("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16);
- break;
-
- case ECPGd_ret_length:
+
+ switch (type)
+ {
+ case (ECPGd_indicator):
+ if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index)))
+ return (false);
+
+ ECPGlog("ECPGget_desc: INDICATOR = %d\n", -PQgetisnull(ECPGresult, 0, index));
+ break;
+
+ case ECPGd_name:
+ if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize))
+ return (false);
+
+ ECPGlog("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index));
+ break;
+
+ case ECPGd_nullable:
+ if (!get_int_item(lineno, var, vartype, 1))
+ return (false);
+
+ break;
+
+ case ECPGd_key_member:
+ if (!get_int_item(lineno, var, vartype, 0))
+ return (false);
+
+ break;
+
+ case ECPGd_scale:
+ if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff))
+ return (false);
+
+ ECPGlog("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff);
+ break;
+
+ case ECPGd_precision:
+ if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16))
+ return (false);
+
+ ECPGlog("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16);
+ break;
+
+ case ECPGd_ret_length:
case ECPGd_ret_octet:
if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, 0, index)))
- return (false);
-
- ECPGlog("ECPGget_desc: RETURNED = %d\n", PQgetlength(ECPGresult, 0, index));
- break;
-
+ return (false);
+
+ ECPGlog("ECPGget_desc: RETURNED = %d\n", PQgetlength(ECPGresult, 0, index));
+ break;
+
case ECPGd_octet:
if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index)))
- return (false);
-
- ECPGlog("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index));
- break;
+ return (false);
+
+ ECPGlog("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index));
+ break;
case ECPGd_length:
if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ))
- return (false);
-
- ECPGlog("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ);
+ return (false);
+
+ ECPGlog("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ);
+ break;
+
+ case ECPGd_type:
+ if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index))))
+ return (false);
+
+ ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType(PQftype(ECPGresult, index)));
+ break;
+
+ case ECPGd_di_code:
+ if (!get_int_item(lineno, var, vartype, ECPGDynamicType_DDT(PQftype(ECPGresult, index))))
+ return (false);
+
+ ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index)));
break;
-
- case ECPGd_type:
- if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index))))
- return (false);
-
- ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType(PQftype(ECPGresult, index)));
- break;
-
- case ECPGd_di_code:
- if (!get_int_item(lineno, var, vartype, ECPGDynamicType_DDT(PQftype(ECPGresult, index))))
- return (false);
-
- ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index)));
- break;
case ECPGd_data:
if (!get_data(ECPGresult, 0, index, lineno, vartype, ECPGt_NO_INDICATOR, var, NULL, varcharsize, offset, false))
- return (false);
-
+ return (false);
+
break;
-
- default:
- snprintf(type_str, sizeof(type_str), "%d", type);
- ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str);
- return(false);
+
+ default:
+ snprintf(type_str, sizeof(type_str), "%d", type);
+ ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str);
+ return (false);
}
-
- type = va_arg(args, enum ECPGdtype);
+
+ type = va_arg(args, enum ECPGdtype);
+ }
+
+ if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
+ {
+ ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
+ return (false);
}
-
- if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
- {
- ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
- return (false);
- }
-
- return (true);
+
+ return (true);
}
bool
@@ -272,7 +277,7 @@ ECPGdeallocate_desc(int line, const char *name)
{
struct descriptor *i;
struct descriptor **lastptr = &all_descriptors;
-
+
for (i = all_descriptors; i; lastptr = &i->next, i = i->next)
{
if (!strcmp(name, i->name))
@@ -286,15 +291,15 @@ ECPGdeallocate_desc(int line, const char *name)
}
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name);
return false;
-}
+}
bool
-ECPGallocate_desc(int line,const char *name)
+ECPGallocate_desc(int line, const char *name)
{
- struct descriptor *new = (struct descriptor *)malloc(sizeof(struct descriptor));
-
+ struct descriptor *new = (struct descriptor *) malloc(sizeof(struct descriptor));
+
new->next = all_descriptors;
- new->name = malloc(strlen(name)+1);
+ new->name = malloc(strlen(name) + 1);
new->result = PQmakeEmptyPGresult(NULL, 0);
strcpy(new->name, name);
all_descriptors = new;
diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c
index e7e976116b8..e2da331757a 100644
--- a/src/interfaces/ecpg/lib/error.c
+++ b/src/interfaces/ecpg/lib/error.c
@@ -10,143 +10,143 @@ void
ECPGraise(int line, int code, char *str)
{
sqlca.sqlcode = code;
-
+
switch (code)
- {
- case ECPG_NOT_FOUND:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "No data found in line %d.", line);
- break;
-
- case ECPG_OUT_OF_MEMORY:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Out of memory in line %d.", line);
- break;
-
- case ECPG_UNSUPPORTED:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Unsupported type %s in line %d.", str, line);
- break;
-
- case ECPG_TOO_MANY_ARGUMENTS:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Too many arguments in line %d.", line);
- break;
-
- case ECPG_TOO_FEW_ARGUMENTS:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Too few arguments in line %d.", line);
- break;
-
- case ECPG_INT_FORMAT:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Not correctly formatted int type: %s line %d.", str, line);
- break;
-
- case ECPG_UINT_FORMAT:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Not correctly formatted unsigned type: %s in line %d.", str, line);
- break;
-
- case ECPG_FLOAT_FORMAT:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Not correctly formatted floating point type: %s in line %d.", str, line);
- break;
-
- case ECPG_CONVERT_BOOL:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Unable to convert %s to bool on line %d.", str, line);
- break;
-
- case ECPG_EMPTY:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Empty query in line %d.", line);
- break;
-
- case ECPG_MISSING_INDICATOR:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "NULL value without indicator in line %d.", line);
- break;
-
- case ECPG_NO_ARRAY:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "variable is not an array in line %d.", line);
- break;
-
- case ECPG_DATA_NOT_ARRAY:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "data read from backend is not an array in line %d.", line);
- break;
-
- case ECPG_NO_CONN:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "No such connection %s in line %d.", str, line);
- break;
-
- case ECPG_NOT_CONN:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Not connected in line %d.", line);
- break;
-
- case ECPG_INVALID_STMT:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Invalid statement name in line %d.", line);
- break;
-
- case ECPG_UNKNOWN_DESCRIPTOR:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Sescriptor %s not found in line %d.", str, line);
- break;
-
- case ECPG_INVALID_DESCRIPTOR_INDEX:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Sescriptor index out of range in line %d.", line);
- break;
-
- case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Unknown descriptor item %s in line %d.", str, line);
- break;
-
- case ECPG_VAR_NOT_NUMERIC:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Variable is not a numeric type in line %d.", line);
- break;
-
- case ECPG_VAR_NOT_CHAR:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Variable is not a character type in line %d.", line);
+ {
+ case ECPG_NOT_FOUND:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "No data found in line %d.", line);
+ break;
+
+ case ECPG_OUT_OF_MEMORY:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Out of memory in line %d.", line);
+ break;
+
+ case ECPG_UNSUPPORTED:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Unsupported type %s in line %d.", str, line);
+ break;
+
+ case ECPG_TOO_MANY_ARGUMENTS:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Too many arguments in line %d.", line);
+ break;
+
+ case ECPG_TOO_FEW_ARGUMENTS:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Too few arguments in line %d.", line);
+ break;
+
+ case ECPG_INT_FORMAT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Not correctly formatted int type: %s line %d.", str, line);
+ break;
+
+ case ECPG_UINT_FORMAT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Not correctly formatted unsigned type: %s in line %d.", str, line);
+ break;
+
+ case ECPG_FLOAT_FORMAT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Not correctly formatted floating point type: %s in line %d.", str, line);
+ break;
+
+ case ECPG_CONVERT_BOOL:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Unable to convert %s to bool on line %d.", str, line);
+ break;
+
+ case ECPG_EMPTY:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Empty query in line %d.", line);
+ break;
+
+ case ECPG_MISSING_INDICATOR:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "NULL value without indicator in line %d.", line);
+ break;
+
+ case ECPG_NO_ARRAY:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "variable is not an array in line %d.", line);
+ break;
+
+ case ECPG_DATA_NOT_ARRAY:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "data read from backend is not an array in line %d.", line);
break;
-
+
+ case ECPG_NO_CONN:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "No such connection %s in line %d.", str, line);
+ break;
+
+ case ECPG_NOT_CONN:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Not connected in line %d.", line);
+ break;
+
+ case ECPG_INVALID_STMT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Invalid statement name in line %d.", line);
+ break;
+
+ case ECPG_UNKNOWN_DESCRIPTOR:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Sescriptor %s not found in line %d.", str, line);
+ break;
+
+ case ECPG_INVALID_DESCRIPTOR_INDEX:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Sescriptor index out of range in line %d.", line);
+ break;
+
+ case ECPG_UNKNOWN_DESCRIPTOR_ITEM:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Unknown descriptor item %s in line %d.", str, line);
+ break;
+
+ case ECPG_VAR_NOT_NUMERIC:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Variable is not a numeric type in line %d.", line);
+ break;
+
+ case ECPG_VAR_NOT_CHAR:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Variable is not a character type in line %d.", line);
+ break;
+
case ECPG_PGSQL:
/* strip trailing newline */
- if (str[strlen(str)-1] == '\n')
- str[strlen(str)-1] = '\0';
-
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "'%s' in line %d.", str, line);
- break;
-
- case ECPG_TRANS:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Error in transaction processing in line %d.", line);
- break;
-
- case ECPG_CONNECT:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "Could not connect to database %s in line %d.", str, line);
- break;
-
+ if (str[strlen(str) - 1] == '\n')
+ str[strlen(str) - 1] = '\0';
+
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "'%s' in line %d.", str, line);
+ break;
+
+ case ECPG_TRANS:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Error in transaction processing in line %d.", line);
+ break;
+
+ case ECPG_CONNECT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Could not connect to database %s in line %d.", str, line);
+ break;
+
default:
- snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
- "SQL error #%d in line %d.", code, line);
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "SQL error #%d in line %d.", code, line);
break;
}
-
+
sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc);
- /* free all memory we have allocated for the user */
- free_auto_mem();
+ /* free all memory we have allocated for the user */
+ free_auto_mem();
}
/* print out an error message */
diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c
index f8910aa7e8f..43b7a603876 100644
--- a/src/interfaces/ecpg/lib/execute.c
+++ b/src/interfaces/ecpg/lib/execute.c
@@ -54,9 +54,9 @@ struct variable
/* keep a list of memory we allocated for the user */
static struct auto_mem
{
- void *pointer;
- struct auto_mem *next;
-} *auto_allocs = NULL;
+ void *pointer;
+ struct auto_mem *next;
+} *auto_allocs = NULL;
static void
add_mem(void *ptr, int lineno)
@@ -67,20 +67,21 @@ add_mem(void *ptr, int lineno)
auto_allocs = am;
}
-void free_auto_mem(void)
+void
+free_auto_mem(void)
{
struct auto_mem *am;
-
- /* free all memory we have allocated for the user */
- for (am = auto_allocs; am;)
- {
- struct auto_mem *act = am;
-
- am = am->next;
- free(act->pointer);
- free(act);
+
+ /* free all memory we have allocated for the user */
+ for (am = auto_allocs; am;)
+ {
+ struct auto_mem *act = am;
+
+ am = am->next;
+ free(act->pointer);
+ free(act);
}
-
+
auto_allocs = NULL;
}
@@ -245,7 +246,7 @@ next_insert(char *text)
bool string = false;
for (; *ptr != '\0' && (*ptr != '?' || string); ptr++)
- if (*ptr == '\'' && *(ptr-1) != '\\')
+ if (*ptr == '\'' && *(ptr - 1) != '\\')
string = string ? false : true;
return (*ptr == '\0') ? NULL : ptr;
@@ -256,7 +257,8 @@ ECPGexecute(struct statement * stmt)
{
bool status = false;
char *copiedquery;
- PGresult *results, *query;
+ PGresult *results,
+ *query;
PGnotify *notify;
struct variable *var;
@@ -275,7 +277,7 @@ ECPGexecute(struct statement * stmt)
char *mallocedval = NULL;
char *tobeinserted = NULL;
char *p;
- char buff[20];
+ char buff[20];
/*
* Some special treatment is needed for records since we want
@@ -311,20 +313,20 @@ ECPGexecute(struct statement * stmt)
{
switch (var->type)
{
- int element;
-
+ int element;
+
case ECPGt_short:
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%hd", *((short *) var->value));
@@ -338,12 +340,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%d", *((int *) var->value));
@@ -357,12 +359,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
@@ -376,12 +378,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%u", *((unsigned int *) var->value));
@@ -392,15 +394,15 @@ ECPGexecute(struct statement * stmt)
case ECPGt_long:
if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
return false;
-
+
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%ld", *((long *) var->value));
@@ -414,12 +416,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
@@ -433,12 +435,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%.14g", *((float *) var->value));
@@ -452,12 +454,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "%.14g", *((double *) var->value));
@@ -471,12 +473,12 @@ ECPGexecute(struct statement * stmt)
if (var->arrsize > 1)
{
- strncpy(mallocedval, "'{", sizeof("'{"));
-
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
}
else
sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f');
@@ -541,7 +543,7 @@ ECPGexecute(struct statement * stmt)
default:
/* Not implemented yet */
- ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *)ECPGtype_name(var->type));
+ ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type));
return false;
break;
}
@@ -656,7 +658,7 @@ ECPGexecute(struct statement * stmt)
for (act_field = 0; act_field < nfields && status; act_field++)
{
char *array_query;
-
+
if (var == NULL)
{
ECPGlog("ECPGexecute line %d: Too few arguments.\n", stmt->lineno);
@@ -664,16 +666,21 @@ ECPGexecute(struct statement * stmt)
return (false);
}
- array_query = (char *)ecpg_alloc(strlen("select typelem from pg_type where oid=") + 11, stmt -> lineno);
+ array_query = (char *) ecpg_alloc(strlen("select typelem from pg_type where oid=") + 11, stmt->lineno);
sprintf(array_query, "select typelem from pg_type where oid=%d", PQftype(results, act_field));
query = PQexec(stmt->connection->connection, array_query);
isarray = 0;
- if (PQresultStatus(query) == PGRES_TUPLES_OK) {
- isarray = atol((char *)PQgetvalue(query, 0, 0));
+ if (PQresultStatus(query) == PGRES_TUPLES_OK)
+ {
+ isarray = atol((char *) PQgetvalue(query, 0, 0));
if (ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER ||
- ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER_VARYING)
+ ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER_VARYING)
{
- /* arrays of character strings are not yet implemented */
+
+ /*
+ * arrays of character strings are not yet
+ * implemented
+ */
isarray = false;
}
ECPGlog("ECPGexecute line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, PQftype(results, act_field), var->type, isarray ? "yes" : "no");
@@ -682,14 +689,15 @@ ECPGexecute(struct statement * stmt)
if (!isarray)
{
+
/*
- * if we don't have enough space, we cannot read all
- * tuples
+ * if we don't have enough space, we cannot read
+ * all tuples
*/
if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize))
{
ECPGlog("ECPGexecute 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);
ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
status = false;
break;
@@ -697,6 +705,7 @@ ECPGexecute(struct statement * stmt)
}
else
{
+
/*
* since we read an array, the variable has to be
* an array too
@@ -707,9 +716,9 @@ ECPGexecute(struct statement * stmt)
ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL);
status = false;
break;
- }
+ }
}
-
+
/*
* allocate memory for NULL pointers
*/
@@ -744,13 +753,13 @@ ECPGexecute(struct statement * stmt)
*((void **) var->pointer) = var->value;
add_mem(var->value, stmt->lineno);
}
-
+
for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
{
if (!get_data(results, act_tuple, act_field, stmt->lineno,
- var->type, var->ind_type, var->value,
- var->ind_value, var->varcharsize, var->offset, isarray))
- status = false;
+ var->type, var->ind_type, var->value,
+ var->ind_value, var->varcharsize, var->offset, isarray))
+ status = false;
}
var = var->next;
}
@@ -811,13 +820,13 @@ ECPGexecute(struct statement * stmt)
}
bool
-ECPGdo(int lineno, const char *connection_name, char *query, ...)
+ECPGdo(int lineno, const char *connection_name, char *query,...)
{
- va_list args;
- struct statement *stmt;
- struct connection *con = get_connection(connection_name);
- bool status=true;
- char *locale = setlocale(LC_NUMERIC, NULL);
+ va_list args;
+ struct statement *stmt;
+ struct connection *con = get_connection(connection_name);
+ bool status = true;
+ char *locale = setlocale(LC_NUMERIC, NULL);
/* Make sure we do NOT honor the locale for numeric input/output */
/* since the database wants teh standard decimal point */
@@ -826,7 +835,7 @@ ECPGdo(int lineno, const char *connection_name, char *query, ...)
if (!ecpg_init(con, connection_name, lineno))
{
setlocale(LC_NUMERIC, locale);
- return(false);
+ return (false);
}
va_start(args, query);
@@ -859,26 +868,27 @@ ECPGdo(int lineno, const char *connection_name, char *query, ...)
*
* Copyright (c) 2000, Christof Petig <[email protected]>
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.5 2000/04/05 15:51:25 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.6 2000/04/12 17:17:03 momjian Exp $
*/
-PGconn *ECPG_internal_get_connection(char *name);
+PGconn *ECPG_internal_get_connection(char *name);
extern struct descriptor
{
- char *name;
- PGresult *result;
- struct descriptor *next;
-} *all_descriptors;
+ char *name;
+ PGresult *result;
+ struct descriptor *next;
+} *all_descriptors;
/* like ECPGexecute */
-static bool execute_descriptor(int lineno,const char *query
- ,struct connection *con,PGresult **resultptr)
+static bool
+execute_descriptor(int lineno, const char *query
+ ,struct connection * con, PGresult **resultptr)
{
- bool status = false;
+ bool status = false;
PGresult *results;
PGnotify *notify;
-
+
/* Now the request is built. */
if (con->committed && !con->autocommit)
@@ -902,9 +912,12 @@ static bool execute_descriptor(int lineno,const char *query
ECPGraise(lineno, ECPG_PGSQL, PQerrorMessage(con->connection));
}
else
- { *resultptr=results;
+ {
+ *resultptr = results;
switch (PQresultStatus(results))
- { int ntuples;
+ {
+ int ntuples;
+
case PGRES_TUPLES_OK:
status = true;
sqlca.sqlerrd[2] = ntuples = PQntuples(results);
@@ -917,7 +930,7 @@ static bool execute_descriptor(int lineno,const char *query
break;
}
break;
-#if 1 /* strictly these are not needed (yet) */
+#if 1 /* strictly these are not needed (yet) */
case PGRES_EMPTY_QUERY:
/* do nothing */
ECPGraise(lineno, ECPG_EMPTY, NULL);
@@ -972,20 +985,22 @@ static bool execute_descriptor(int lineno,const char *query
}
/* like ECPGdo */
-static bool do_descriptor2(int lineno,const char *connection_name,
- PGresult **resultptr, const char *query)
+static bool
+do_descriptor2(int lineno, const char *connection_name,
+ PGresult **resultptr, const char *query)
{
struct connection *con = get_connection(connection_name);
- bool status=true;
- char *locale = setlocale(LC_NUMERIC, NULL);
+ bool status = true;
+ char *locale = setlocale(LC_NUMERIC, NULL);
/* Make sure we do NOT honor the locale for numeric input/output */
/* since the database wants teh standard decimal point */
setlocale(LC_NUMERIC, "C");
if (!ecpg_init(con, connection_name, lineno))
- { setlocale(LC_NUMERIC, locale);
- return(false);
+ {
+ setlocale(LC_NUMERIC, locale);
+ return (false);
}
/* are we connected? */
@@ -997,33 +1012,38 @@ static bool do_descriptor2(int lineno,const char *connection_name,
return false;
}
- status = execute_descriptor(lineno,query,con,resultptr);
+ status = execute_descriptor(lineno, query, con, resultptr);
/* and reset locale value so our application is not affected */
setlocale(LC_NUMERIC, locale);
return (status);
}
-bool ECPGdo_descriptor(int line,const char *connection,
- const char *descriptor,const char *query)
+bool
+ECPGdo_descriptor(int line, const char *connection,
+ const char *descriptor, const char *query)
{
struct descriptor *i;
- for (i=all_descriptors;i!=NULL;i=i->next)
- { if (!strcmp(descriptor,i->name))
- {
- bool status;
+
+ for (i = all_descriptors; i != NULL; i = i->next)
+ {
+ if (!strcmp(descriptor, i->name))
+ {
+ bool status;
/* free previous result */
- if (i->result) PQclear(i->result);
- i->result=NULL;
-
- status=do_descriptor2(line,connection,&i->result,query);
-
- if (!i->result) PQmakeEmptyPGresult(NULL, 0);
+ if (i->result)
+ PQclear(i->result);
+ i->result = NULL;
+
+ status = do_descriptor2(line, connection, &i->result, query);
+
+ if (!i->result)
+ PQmakeEmptyPGresult(NULL, 0);
return (status);
- }
+ }
}
-
+
ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, (char *) descriptor);
return false;
}
diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h
index ef9515d7c96..86cc8bbab87 100644
--- a/src/interfaces/ecpg/lib/extern.h
+++ b/src/interfaces/ecpg/lib/extern.h
@@ -3,14 +3,14 @@
/* Here are some methods used by the lib. */
/* Returns a pointer to a string containing a simple type name. */
-void free_auto_mem(void);
+void free_auto_mem(void);
bool get_data(PGresult *, int, int, int, enum ECPGttype type,
- enum ECPGttype, void *, void *, long, long, bool);
+ enum ECPGttype, void *, void *, long, long, bool);
struct connection *get_connection(const char *);
-void init_sqlca(void);
-char *ecpg_alloc(long, int);
-bool ecpg_init(const struct connection *, const char *, const int);
-char *ecpg_strdup(const char *, int);
+void init_sqlca(void);
+char *ecpg_alloc(long, int);
+bool ecpg_init(const struct connection *, const char *, const int);
+char *ecpg_strdup(const char *, int);
const char *ECPGtype_name(enum ECPGttype);
unsigned int ECPGDynamicType(Oid);
@@ -24,20 +24,19 @@ struct ECPGgeneric_varchar
/* structure to store one statement */
struct statement
{
- int lineno;
- char *command;
- struct connection *connection;
- struct variable *inlist;
- struct variable *outlist;
+ int lineno;
+ char *command;
+ struct connection *connection;
+ struct variable *inlist;
+ struct variable *outlist;
};
/* structure to store connections */
struct connection
{
- char *name;
- PGconn *connection;
- bool committed;
- int autocommit;
- struct connection *next;
+ char *name;
+ PGconn *connection;
+ bool committed;
+ int autocommit;
+ struct connection *next;
};
-
diff --git a/src/interfaces/ecpg/lib/misc.c b/src/interfaces/ecpg/lib/misc.c
index 55e0cfc8177..dbfb8b810de 100644
--- a/src/interfaces/ecpg/lib/misc.c
+++ b/src/interfaces/ecpg/lib/misc.c
@@ -27,7 +27,7 @@ init_sqlca(void)
}
bool
-ecpg_init(const struct connection *con, const char * connection_name, const int lineno)
+ecpg_init(const struct connection * con, const char *connection_name, const int lineno)
{
init_sqlca();
if (con == NULL)
@@ -35,7 +35,7 @@ ecpg_init(const struct connection *con, const char * connection_name, const int
ECPGraise(lineno, ECPG_NO_CONN, connection_name ? connection_name : "NULL");
return (false);
}
-
+
return (true);
}
@@ -45,7 +45,7 @@ ECPGstatus(int lineno, const char *connection_name)
struct connection *con = get_connection(connection_name);
if (!ecpg_init(con, connection_name, lineno))
- return(false);
+ return (false);
/* are we connected? */
if (con->connection == NULL)
@@ -65,7 +65,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
struct connection *con = get_connection(connection_name);
if (!ecpg_init(con, connection_name, lineno))
- return(false);
+ return (false);
ECPGlog("ECPGtrans line %d action = %s connection = %s\n", lineno, transaction, con->name);
@@ -79,14 +79,14 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
}
PQclear(res);
}
-
+
if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0)
{
con->committed = true;
/* deallocate all prepared statements */
if (!ECPGdeallocate_all(lineno))
- return false;
+ return false;
}
return true;
diff --git a/src/interfaces/ecpg/lib/prepare.c b/src/interfaces/ecpg/lib/prepare.c
index 2155177edec..c49d44ab8d8 100644
--- a/src/interfaces/ecpg/lib/prepare.c
+++ b/src/interfaces/ecpg/lib/prepare.c
@@ -8,10 +8,10 @@
static struct prepared_statement
{
- char *name;
- struct statement *stmt;
- struct prepared_statement *next;
-} *prep_stmts = NULL;
+ char *name;
+ struct statement *stmt;
+ struct prepared_statement *next;
+} *prep_stmts = NULL;
static bool
isvarchar(unsigned char c)
@@ -47,7 +47,7 @@ replace_variables(char *text)
}
}
}
-
+
/* handle the EXEC SQL PREPARE statement */
bool
ECPGprepare(int lineno, char *name, char *variable)
@@ -117,7 +117,7 @@ ECPGdeallocate(int lineno, char *name)
prev->next = this->next;
else
prep_stmts = this->next;
-
+
free(this);
return true;
}
@@ -130,15 +130,15 @@ bool
ECPGdeallocate_all(int lineno)
{
/* deallocate all prepared statements */
- while(prep_stmts != NULL)
- {
- bool b = ECPGdeallocate(lineno, prep_stmts->name);
-
- if (!b)
+ while (prep_stmts != NULL)
+ {
+ bool b = ECPGdeallocate(lineno, prep_stmts->name);
+
+ if (!b)
return false;
- }
-
- return true;
+ }
+
+ return true;
}
/* return the prepared statement */
diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c
index 2b64c19a8ce..19f1fcdbf23 100644
--- a/src/interfaces/ecpg/lib/typename.c
+++ b/src/interfaces/ecpg/lib/typename.c
@@ -12,7 +12,7 @@ ECPGtype_name(enum ECPGttype typ)
{
switch (typ)
{
- case ECPGt_char:
+ case ECPGt_char:
return "char";
case ECPGt_unsigned_char:
return "unsigned char";
@@ -47,21 +47,34 @@ ECPGtype_name(enum ECPGttype typ)
unsigned int
ECPGDynamicType(Oid type)
{
- switch(type)
+ switch (type)
{
- case 16: return SQL3_BOOLEAN; /* bool */
- case 21: return SQL3_SMALLINT; /* int2 */
- case 23: return SQL3_INTEGER; /* int4 */
- case 25: return SQL3_CHARACTER; /* text */
- case 700: return SQL3_REAL; /* float4 */
- case 701: return SQL3_DOUBLE_PRECISION; /* float8 */
- case 1042: return SQL3_CHARACTER; /* bpchar */
- case 1043: return SQL3_CHARACTER_VARYING; /* varchar */
- case 1082: return SQL3_DATE_TIME_TIMESTAMP; /* date */
- case 1083: return SQL3_DATE_TIME_TIMESTAMP; /* time */
- case 1184: return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
- case 1296: return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */
- case 1700: return SQL3_NUMERIC; /* numeric */
- default: return -type;
+ case 16:return SQL3_BOOLEAN; /* bool */
+ case 21:
+ return SQL3_SMALLINT; /* int2 */
+ case 23:
+ return SQL3_INTEGER;/* int4 */
+ case 25:
+ return SQL3_CHARACTER; /* text */
+ case 700:
+ return SQL3_REAL; /* float4 */
+ case 701:
+ return SQL3_DOUBLE_PRECISION; /* float8 */
+ case 1042:
+ return SQL3_CHARACTER; /* bpchar */
+ case 1043:
+ return SQL3_CHARACTER_VARYING; /* varchar */
+ case 1082:
+ return SQL3_DATE_TIME_TIMESTAMP; /* date */
+ case 1083:
+ return SQL3_DATE_TIME_TIMESTAMP; /* time */
+ case 1184:
+ return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
+ case 1296:
+ return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */
+ case 1700:
+ return SQL3_NUMERIC;/* numeric */
+ default:
+ return -type;
}
}
diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c
index e55aa886cf8..792b286d8c0 100644
--- a/src/interfaces/ecpg/preproc/descriptor.c
+++ b/src/interfaces/ecpg/preproc/descriptor.c
@@ -3,18 +3,19 @@
*/
#include "postgres.h"
-#include "extern.h"
+#include "extern.h"
/*
* assignment handling function (descriptor)
*/
-
+
struct assignment *assignments;
-void push_assignment(char *var, enum ECPGdtype value)
+void
+push_assignment(char *var, enum ECPGdtype value)
{
- struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment));
-
+ struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));
+
new->next = assignments;
new->variable = mm_alloc(strlen(var) + 1);
strcpy(new->variable, var);
@@ -35,91 +36,94 @@ drop_assignments(void)
}
}
-static void ECPGnumeric_lvalue(FILE *f,char *name)
+static void
+ECPGnumeric_lvalue(FILE *f, char *name)
{
- const struct variable *v=find_variable(name);
+ const struct variable *v = find_variable(name);
- switch(v->type->typ)
+ switch (v->type->typ)
{
case ECPGt_short:
- case ECPGt_int:
+ case ECPGt_int:
case ECPGt_long:
case ECPGt_unsigned_short:
case ECPGt_unsigned_int:
case ECPGt_unsigned_long:
- fputs(name,yyout);
+ fputs(name, yyout);
break;
default:
- snprintf(errortext,sizeof errortext,"variable %s: numeric type needed"
- ,name);
- mmerror(ET_ERROR,errortext);
+ snprintf(errortext, sizeof errortext, "variable %s: numeric type needed"
+ ,name);
+ mmerror(ET_ERROR, errortext);
break;
- }
+ }
}
/*
* descriptor name lookup
*/
-
+
static struct descriptor *descriptors;
-void add_descriptor(char *name,char *connection)
+void
+add_descriptor(char *name, char *connection)
{
- struct descriptor *new = (struct descriptor *)mm_alloc(sizeof(struct descriptor));
-
+ struct descriptor *new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
+
new->next = descriptors;
new->name = mm_alloc(strlen(name) + 1);
- strcpy(new->name,name);
- if (connection)
+ strcpy(new->name, name);
+ if (connection)
{
new->connection = mm_alloc(strlen(connection) + 1);
strcpy(new->connection, connection);
}
- else new->connection = connection;
+ else
+ new->connection = connection;
descriptors = new;
}
void
-drop_descriptor(char *name,char *connection)
+drop_descriptor(char *name, char *connection)
{
struct descriptor *i;
- struct descriptor **lastptr=&descriptors;
-
- for (i=descriptors;i;lastptr=&i->next,i=i->next)
+ struct descriptor **lastptr = &descriptors;
+
+ for (i = descriptors; i; lastptr = &i->next, i = i->next)
{
- if (!strcmp(name,i->name))
+ if (!strcmp(name, i->name))
{
- if ((!connection && !i->connection)
- || (connection && i->connection
- && !strcmp(connection,i->connection)))
+ if ((!connection && !i->connection)
+ || (connection && i->connection
+ && !strcmp(connection, i->connection)))
{
- *lastptr=i->next;
- if (i->connection) free(i->connection);
+ *lastptr = i->next;
+ if (i->connection)
+ free(i->connection);
free(i->name);
free(i);
return;
}
}
}
- snprintf(errortext,sizeof errortext,"unknown descriptor %s",name);
- mmerror(ET_WARN,errortext);
+ snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
+ mmerror(ET_WARN, errortext);
}
struct descriptor
-*lookup_descriptor(char *name, char *connection)
+ *
+lookup_descriptor(char *name, char *connection)
{
struct descriptor *i;
-
+
for (i = descriptors; i; i = i->next)
{
if (!strcmp(name, i->name))
{
- if ((!connection && !i->connection)
- || (connection && i->connection
- && !strcmp(connection,i->connection)))
- {
+ if ((!connection && !i->connection)
+ || (connection && i->connection
+ && !strcmp(connection, i->connection)))
return i;
- }
}
}
snprintf(errortext, sizeof errortext, "unknown descriptor %s", name);
@@ -136,14 +140,14 @@ output_get_descr_header(char *desc_name)
for (results = assignments; results != NULL; results = results->next)
{
if (results->value == ECPGd_count)
- ECPGnumeric_lvalue(yyout,results->variable);
+ ECPGnumeric_lvalue(yyout, results->variable);
else
{
snprintf(errortext, sizeof errortext, "unknown descriptor header item '%d'", results->value);
mmerror(ET_WARN, errortext);
}
}
-
+
drop_assignments();
fprintf(yyout, "));\n");
whenever_action(3);
@@ -154,27 +158,27 @@ output_get_descr(char *desc_name, char *index)
{
struct assignment *results;
- fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
+ fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index);
for (results = assignments; results != NULL; results = results->next)
{
const struct variable *v = find_variable(results->variable);
-
+
switch (results->value)
{
case ECPGd_nullable:
- mmerror(ET_WARN,"nullable is always 1");
+ mmerror(ET_WARN, "nullable is always 1");
break;
case ECPGd_key_member:
- mmerror(ET_WARN,"key_member is always 0");
+ mmerror(ET_WARN, "key_member is always 0");
break;
default:
- break;
+ break;
}
fprintf(yyout, "%s,", get_dtype(results->value));
ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL);
}
drop_assignments();
- fputs("ECPGd_EODT);\n",yyout);
-
- whenever_action(2|1);
+ fputs("ECPGd_EODT);\n", yyout);
+
+ whenever_action(2 | 1);
}
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 31bc48752f7..1cc00dbcc7c 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -11,7 +11,8 @@
#include "extern.h"
-int ret_value = OK, autocommit = 0;
+int ret_value = OK,
+ autocommit = 0;
struct _include_path *include_paths = NULL;
struct cursor *cur = NULL;
struct typedefs *types = NULL;
@@ -85,8 +86,8 @@ main(int argc, char *const argv[])
verbose = true;
break;
case 'D':
- add_preprocessor_define(optarg);
- break;
+ add_preprocessor_define(optarg);
+ break;
default:
usage(argv[0]);
return ILLEGAL_OPTION;
@@ -102,7 +103,7 @@ main(int argc, char *const argv[])
fprintf(stderr, "End of search list.\n");
return OK;
}
-
+
if (optind >= argc) /* no files specified */
{
usage(argv[0]);
@@ -123,7 +124,7 @@ main(int argc, char *const argv[])
/* take care of relative paths */
ptr2ext = strrchr(input_filename, '/');
ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.'));
-
+
/* no extension? */
if (ptr2ext == NULL)
{
@@ -137,7 +138,7 @@ main(int argc, char *const argv[])
ptr2ext[4] = '\0';
}
- if (out_option == 0) /* calculate the output name */
+ if (out_option == 0)/* calculate the output name */
{
output_filename = strdup(input_filename);
@@ -177,7 +178,8 @@ main(int argc, char *const argv[])
for (ptr = cur; ptr != NULL;)
{
struct cursor *this = ptr;
- struct arguments *l1, *l2;
+ struct arguments *l1,
+ *l2;
free(ptr->command);
free(ptr->connection);
@@ -198,26 +200,28 @@ main(int argc, char *const argv[])
cur = NULL;
/* remove non-pertinent old defines as well */
- while ( defines && !defines->pertinent ) {
- defptr = defines;
- defines = defines->next;
+ while (defines && !defines->pertinent)
+ {
+ defptr = defines;
+ defines = defines->next;
- free(defptr->new);
- free(defptr->old);
- free(defptr);
+ free(defptr->new);
+ free(defptr->old);
+ free(defptr);
}
- for (defptr = defines; defptr != NULL; defptr = defptr->next )
+ for (defptr = defines; defptr != NULL; defptr = defptr->next)
{
- struct _defines *this = defptr->next;
-
- if ( this && !this->pertinent ) {
- defptr->next = this->next;
+ struct _defines *this = defptr->next;
- free(this->new);
- free(this->old);
- free(this);
- }
+ if (this && !this->pertinent)
+ {
+ defptr->next = this->next;
+
+ free(this->new);
+ free(this->old);
+ free(this);
+ }
}
/* and old typedefs */
@@ -232,18 +236,18 @@ main(int argc, char *const argv[])
free(this);
}
types = NULL;
-
+
/* initialize whenever structures */
memset(&when_error, 0, sizeof(struct when));
memset(&when_nf, 0, sizeof(struct when));
memset(&when_warn, 0, sizeof(struct when));
-
+
/* and structure member lists */
memset(struct_member_list, 0, sizeof(struct_member_list));
-
+
/* finally the actual connection */
connection = NULL;
-
+
/* initialize lex */
lex_init();
diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c
index 0a468c041ea..a1a0452e1cb 100644
--- a/src/interfaces/ecpg/preproc/ecpg_keywords.c
+++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c
@@ -61,7 +61,8 @@ static ScanKeyword ScanKeywords[] = {
{"section", SQL_SECTION},
{"short", SQL_SHORT},
{"signed", SQL_SIGNED},
- {"sql",SQL_SQL}, /* strange thing, used for into sql descriptor MYDESC; */
+ {"sql", SQL_SQL}, /* strange thing, used for into sql
+ * descriptor MYDESC; */
{"sqlerror", SQL_SQLERROR},
{"sqlprint", SQL_SQLPRINT},
{"sqlwarning", SQL_SQLWARNING},
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index bcdba111915..779985ac169 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -10,16 +10,19 @@
/* variables */
extern int braces_open,
- autocommit,
- ret_value,
- struct_level;
+ autocommit,
+ ret_value,
+ struct_level;
extern char *descriptor_index;
extern char *descriptor_name;
extern char *connection;
-extern char *input_filename;
-extern char *yytext, errortext[128];
-extern int yylineno, yyleng;
-extern FILE *yyin, *yyout;
+extern char *input_filename;
+extern char *yytext,
+ errortext[128];
+extern int yylineno,
+ yyleng;
+extern FILE *yyin,
+ *yyout;
extern struct _include_path *include_paths;
extern struct cursor *cur;
@@ -29,7 +32,9 @@ extern struct ECPGtype ecpg_no_indicator;
extern struct variable no_indicator;
extern struct arguments *argsinsert;
extern struct arguments *argsresult;
-extern struct when when_error, when_nf, when_warn;
+extern struct when when_error,
+ when_nf,
+ when_warn;
extern struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH];
extern struct descriptor *descriptors;
@@ -47,19 +52,19 @@ extern int yylex(void);
extern void yyerror(char *);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
extern char *mm_strdup(const char *);
-extern void mmerror(enum errortype, char * );
+extern void mmerror(enum errortype, char *);
extern ScanKeyword *ScanECPGKeywordLookup(char *);
extern ScanKeyword *ScanCKeywordLookup(char *);
extern void output_get_descr_header(char *);
extern void output_get_descr(char *, char *);
extern void push_assignment(char *, enum ECPGdtype);
-extern struct variable * find_variable(char *);
+extern struct variable *find_variable(char *);
extern void whenever_action(int);
-extern void add_descriptor(char *,char *);
-extern void drop_descriptor(char *,char *);
-extern struct descriptor *lookup_descriptor(char *,char *);
-extern void add_variable(struct arguments ** , struct variable * , struct variable *);
-extern void append_variable(struct arguments ** , struct variable * , struct variable *);
+extern void add_descriptor(char *, char *);
+extern void drop_descriptor(char *, char *);
+extern struct descriptor *lookup_descriptor(char *, char *);
+extern void add_variable(struct arguments **, struct variable *, struct variable *);
+extern void append_variable(struct arguments **, struct variable *, struct variable *);
extern void dump_variables(struct arguments *, int);
extern struct typedefs *get_typedef(char *);
extern void adjust_array(enum ECPGttype, int *, int *, int, int, bool);
@@ -67,13 +72,13 @@ extern void reset_variables(void);
extern void check_indicator(struct ECPGtype *);
extern void remove_variables(int);
extern struct variable *new_variable(const char *, struct ECPGtype *);
-
+
/* return codes */
#define OK 0
#define PARSE_ERROR -1
#define ILLEGAL_OPTION -2
-#define INDICATOR_NOT_ARRAY -3
+#define INDICATOR_NOT_ARRAY -3
#define NO_INCLUDE_FILE ENOENT
#define OUT_OF_MEMORY ENOMEM
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 760751affd3..7fe282586f6 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -6,74 +6,83 @@
void
output_line_number()
{
- if (input_filename)
- fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
+ if (input_filename)
+ fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename);
}
void
output_simple_statement(char *cmd)
{
- int i, j = strlen(cmd);;
-
+ int i,
+ j = strlen(cmd);;
+
/* do this char by char as we have to filter '\"' */
- for (i = 0; i < j; i++) {
+ for (i = 0; i < j; i++)
+ {
if (cmd[i] != '"')
fputc(cmd[i], yyout);
else
fputs("\\\"", yyout);
}
output_line_number();
- free(cmd);
+ free(cmd);
}
/*
* store the whenever action here
*/
-struct when when_error, when_nf, when_warn;
+struct when when_error,
+ when_nf,
+ when_warn;
static void
-print_action(struct when *w)
+print_action(struct when * w)
{
switch (w->code)
{
- case W_SQLPRINT: fprintf(yyout, "sqlprint();");
- break;
- case W_GOTO: fprintf(yyout, "goto %s;", w->command);
- break;
- case W_DO: fprintf(yyout, "%s;", w->command);
- break;
- case W_STOP: fprintf(yyout, "exit (1);");
- break;
- case W_BREAK: fprintf(yyout, "break;");
- break;
- default: fprintf(yyout, "{/* %d not implemented yet */}", w->code);
- break;
+ case W_SQLPRINT:fprintf(yyout, "sqlprint();");
+ break;
+ case W_GOTO:
+ fprintf(yyout, "goto %s;", w->command);
+ break;
+ case W_DO:
+ fprintf(yyout, "%s;", w->command);
+ break;
+ case W_STOP:
+ fprintf(yyout, "exit (1);");
+ break;
+ case W_BREAK:
+ fprintf(yyout, "break;");
+ break;
+ default:
+ fprintf(yyout, "{/* %d not implemented yet */}", w->code);
+ break;
}
}
void
whenever_action(int mode)
{
- if ((mode&1) == 1 && when_nf.code != W_NOTHING)
+ if ((mode & 1) == 1 && when_nf.code != W_NOTHING)
{
output_line_number();
fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
print_action(&when_nf);
}
if (when_warn.code != W_NOTHING)
- {
+ {
output_line_number();
- fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
+ fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
print_action(&when_warn);
- }
+ }
if (when_error.code != W_NOTHING)
- {
+ {
output_line_number();
- fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
+ fprintf(yyout, "\nif (sqlca.sqlcode < 0) ");
print_action(&when_error);
- }
+ }
- if ((mode&2) == 2)
+ if ((mode & 2) == 2)
fputc('}', yyout);
output_line_number();
@@ -82,30 +91,33 @@ whenever_action(int mode)
char *
hashline_number(void)
{
- if (input_filename)
- {
- char* line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
- sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
+ if (input_filename)
+ {
+ char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
- return line;
- }
+ sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
- return EMPTY;
+ return line;
+ }
+
+ return EMPTY;
}
void
-output_statement(char * stmt, int mode, char *descriptor, char *con)
+output_statement(char *stmt, int mode, char *descriptor, char *con)
{
- int i, j = strlen(stmt);
+ int i,
+ j = strlen(stmt);
if (descriptor == NULL)
fprintf(yyout, "{ ECPGdo(__LINE__, %s, \"", con ? con : "NULL");
else
- fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
- con ? con : "NULL", descriptor);
+ fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"",
+ con ? con : "NULL", descriptor);
/* do this char by char as we have to filter '\"' */
- for (i = 0; i < j; i++) {
+ for (i = 0; i < j; i++)
+ {
if (stmt[i] != '"')
fputc(stmt[i], yyout);
else
@@ -115,7 +127,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
if (descriptor == NULL)
{
fputs("\", ", yyout);
-
+
/* dump variables to C file */
dump_variables(argsinsert, 1);
fputs("ECPGt_EOIT, ", yyout);
@@ -125,7 +137,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
}
else
fputs("\");", yyout);
-
+
mode |= 2;
whenever_action(mode);
free(stmt);
@@ -134,4 +146,3 @@ output_statement(char * stmt, int mode, char *descriptor, char *con)
if (connection != NULL)
free(connection);
}
-
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 95c79e3f09e..8d292e11098 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -124,7 +124,7 @@ get_type(enum ECPGttype typ)
{
switch (typ)
{
- case ECPGt_char:
+ case ECPGt_char:
return ("ECPGt_char");
break;
case ECPGt_unsigned_char:
@@ -163,7 +163,7 @@ get_type(enum ECPGttype typ)
return ("ECPGt_NO_INDICATOR");
break;
case ECPGt_char_variable: /* string that should not be
- * quoted */
+ * quoted */
return ("ECPGt_char_variable");
break;
default:
@@ -200,10 +200,10 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in
{
switch (typ->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
switch (typ->u.element->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
yyerror("No nested arrays allowed (except strings)"); /* array of array */
break;
case ECPGt_struct:
@@ -269,7 +269,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
switch (typ)
{
case ECPGt_varchar:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -280,7 +284,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
case ECPGt_char:
case ECPGt_unsigned_char:
case ECPGt_char_variable:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (varcharsize > 1 || arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -289,7 +297,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize);
break;
default:
- /* we have to use the pointer except for arrays with given bounds */
+
+ /*
+ * we have to use the pointer except for arrays with given
+ * bounds
+ */
if (arrsize > 0)
sprintf(variable, "(%s%s)", prefix ? prefix : "", name);
else
@@ -375,10 +387,10 @@ ECPGfree_type(struct ECPGtype * typ)
{
switch (typ->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
switch (typ->u.element->typ)
{
- case ECPGt_array:
+ case ECPGt_array:
yyerror("internal error, found multi-dimensional array\n");
break;
case ECPGt_struct:
@@ -412,7 +424,7 @@ get_dtype(enum ECPGdtype typ)
{
switch (typ)
{
- case ECPGd_count:
+ case ECPGd_count:
return ("ECPGd_countr");
break;
case ECPGd_data:
@@ -450,10 +462,10 @@ get_dtype(enum ECPGdtype typ)
case ECPGd_ret_octet:
return ("ECPGd_ret_octet");
break;
- case ECPGd_scale:
+ case ECPGd_scale:
return ("ECPGd_scale");
break;
- case ECPGd_type:
+ case ECPGd_type:
return ("ECPGd_type");
break;
default:
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index 29525c392c3..7ce1e892870 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -119,7 +119,7 @@ struct _defines
{
char *old;
char *new;
- int pertinent;
+ int pertinent;
struct _defines *next;
};
@@ -141,22 +141,25 @@ struct arguments
struct descriptor
{
- char *name;
- char *connection;
+ char *name;
+ char *connection;
struct descriptor *next;
};
struct assignment
-{
- char *variable;
- enum ECPGdtype value;
- struct assignment *next;
+{
+ char *variable;
+ enum ECPGdtype value;
+ struct assignment *next;
};
-enum errortype {ET_WARN, ET_ERROR, ET_FATAL};
+enum errortype
+{
+ ET_WARN, ET_ERROR, ET_FATAL
+};
struct fetch_desc
{
- char *str;
- char *name;
+ char *str;
+ char *name;
};
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index 3de45350b1c..f3d2dca0597 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -2,174 +2,177 @@
#include "extern.h"
-struct variable * allvariables = NULL;
+struct variable *allvariables = NULL;
struct variable *
-new_variable(const char * name, struct ECPGtype * type)
+new_variable(const char *name, struct ECPGtype * type)
{
- struct variable * p = (struct variable*) mm_alloc(sizeof(struct variable));
+ struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));
- p->name = mm_strdup(name);
- p->type = type;
- p->brace_level = braces_open;
+ p->name = mm_strdup(name);
+ p->type = type;
+ p->brace_level = braces_open;
- p->next = allvariables;
- allvariables = p;
+ p->next = allvariables;
+ allvariables = p;
- return(p);
+ return (p);
}
static struct variable *
-find_struct_member(char *name, char *str, struct ECPGstruct_member *members)
+find_struct_member(char *name, char *str, struct ECPGstruct_member * members)
{
- char *next = strchr(++str, '.'), c = '\0';
+ char *next = strchr(++str, '.'),
+ c = '\0';
- if (next != NULL)
- {
- c = *next;
- *next = '\0';
- }
+ if (next != NULL)
+ {
+ c = *next;
+ *next = '\0';
+ }
- for (; members; members = members->next)
- {
- if (strcmp(members->name, str) == 0)
+ for (; members; members = members->next)
{
- if (c == '\0')
+ if (strcmp(members->name, str) == 0)
{
- /* found the end */
- switch (members->typ->typ)
+ if (c == '\0')
{
- case ECPGt_array:
- return(new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size)));
- case ECPGt_struct:
- case ECPGt_union:
- return(new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ)));
- default:
- return(new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size)));
+ /* found the end */
+ switch (members->typ->typ)
+ {
+ case ECPGt_array:
+ return (new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size)));
+ case ECPGt_struct:
+ case ECPGt_union:
+ return (new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ)));
+ default:
+ return (new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size)));
+ }
}
- }
- else
- {
- *next = c;
- if (c == '-')
+ else
{
- next++;
- return(find_struct_member(name, next, members->typ->u.element->u.members));
+ *next = c;
+ if (c == '-')
+ {
+ next++;
+ return (find_struct_member(name, next, members->typ->u.element->u.members));
+ }
+ else
+ return (find_struct_member(name, next, members->typ->u.members));
}
- else return(find_struct_member(name, next, members->typ->u.members));
}
}
- }
- return(NULL);
+ return (NULL);
}
static struct variable *
-find_struct(char * name, char *next)
+find_struct(char *name, char *next)
{
- struct variable * p;
- char c = *next;
-
- /* first get the mother structure entry */
- *next = '\0';
- p = find_variable(name);
-
- if (c == '-')
- {
- if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
- {
- sprintf(errortext, "variable %s is not a pointer", name);
- mmerror(ET_FATAL, errortext);
- }
-
- if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union)
- {
- sprintf(errortext, "variable %s is not a pointer to a structure or a union", name);
- mmerror(ET_FATAL, errortext);
- }
-
- /* restore the name, we will need it later on */
- *next = c;
- next++;
-
- return find_struct_member(name, next, p->type->u.element->u.members);
- }
- else
- {
- if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ struct variable *p;
+ char c = *next;
+
+ /* first get the mother structure entry */
+ *next = '\0';
+ p = find_variable(name);
+
+ if (c == '-')
{
- sprintf(errortext, "variable %s is neither a structure nor a union", name);
- mmerror(ET_FATAL, errortext);
+ if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is not a pointer", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is not a pointer to a structure or a union", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ /* restore the name, we will need it later on */
+ *next = c;
+ next++;
+
+ return find_struct_member(name, next, p->type->u.element->u.members);
}
+ else
+ {
+ if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union)
+ {
+ sprintf(errortext, "variable %s is neither a structure nor a union", name);
+ mmerror(ET_FATAL, errortext);
+ }
- /* restore the name, we will need it later on */
- *next = c;
+ /* restore the name, we will need it later on */
+ *next = c;
- return find_struct_member(name, next, p->type->u.members);
- }
+ return find_struct_member(name, next, p->type->u.members);
+ }
}
static struct variable *
-find_simple(char * name)
+find_simple(char *name)
{
- struct variable * p;
+ struct variable *p;
- for (p = allvariables; p; p = p->next)
- {
- if (strcmp(p->name, name) == 0)
- return p;
- }
+ for (p = allvariables; p; p = p->next)
+ {
+ if (strcmp(p->name, name) == 0)
+ return p;
+ }
- return(NULL);
+ return (NULL);
}
/* Note that this function will end the program in case of an unknown */
/* variable */
struct variable *
-find_variable(char * name)
+find_variable(char *name)
{
- char * next;
- struct variable * p;
-
- if ((next = strchr(name, '.')) != NULL)
- p = find_struct(name, next);
- else if ((next = strstr(name, "->")) != NULL)
- p = find_struct(name, next);
- else
- p = find_simple(name);
-
- if (p == NULL)
- {
- sprintf(errortext, "The variable %s is not declared", name);
- mmerror(ET_FATAL, errortext);
- }
-
- return(p);
+ char *next;
+ struct variable *p;
+
+ if ((next = strchr(name, '.')) != NULL)
+ p = find_struct(name, next);
+ else if ((next = strstr(name, "->")) != NULL)
+ p = find_struct(name, next);
+ else
+ p = find_simple(name);
+
+ if (p == NULL)
+ {
+ sprintf(errortext, "The variable %s is not declared", name);
+ mmerror(ET_FATAL, errortext);
+ }
+
+ return (p);
}
void
remove_variables(int brace_level)
{
- struct variable * p, *prev;
+ struct variable *p,
+ *prev;
- for (p = prev = allvariables; p; p = p ? p->next : NULL)
- {
- if (p->brace_level >= brace_level)
+ for (p = prev = allvariables; p; p = p ? p->next : NULL)
{
- /* remove it */
- if (p == allvariables)
- prev = allvariables = p->next;
- else
- prev->next = p->next;
-
- ECPGfree_type(p->type);
- free(p->name);
- free(p);
- p = prev;
+ if (p->brace_level >= brace_level)
+ {
+ /* remove it */
+ if (p == allvariables)
+ prev = allvariables = p->next;
+ else
+ prev->next = p->next;
+
+ ECPGfree_type(p->type);
+ free(p->name);
+ free(p);
+ p = prev;
+ }
+ else
+ prev = p;
}
- else
- prev = p;
- }
}
@@ -179,44 +182,45 @@ remove_variables(int brace_level)
* I will make two lists for them.
*/
-struct arguments * argsinsert = NULL;
-struct arguments * argsresult = NULL;
+struct arguments *argsinsert = NULL;
+struct arguments *argsresult = NULL;
void
reset_variables(void)
{
- argsinsert = NULL;
- argsresult = NULL;
+ argsinsert = NULL;
+ argsresult = NULL;
}
/* Insert a new variable into our request list. */
void
add_variable(struct arguments ** list, struct variable * var, struct variable * ind)
{
- struct arguments *p = (struct arguments *)mm_alloc(sizeof(struct arguments));
-
- p->variable = var;
- p->indicator = ind;
- p->next = *list;
- *list = p;
+ struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments));
+
+ p->variable = var;
+ p->indicator = ind;
+ p->next = *list;
+ *list = p;
}
/* Append a new variable to our request list. */
void
append_variable(struct arguments ** list, struct variable * var, struct variable * ind)
{
- struct arguments *p, *new = (struct arguments *)mm_alloc(sizeof(struct arguments));
-
- for (p = *list; p && p->next; p = p->next);
-
- new->variable = var;
- new->indicator = ind;
- new->next = NULL;
-
- if (p)
- p->next = new;
- else
- *list = new;
+ struct arguments *p,
+ *new = (struct arguments *) mm_alloc(sizeof(struct arguments));
+
+ for (p = *list; p && p->next; p = p->next);
+
+ new->variable = var;
+ new->indicator = ind;
+ new->next = NULL;
+
+ if (p)
+ p->next = new;
+ else
+ *list = new;
}
/* Dump out a list of all the variable on this list.
@@ -226,33 +230,32 @@ append_variable(struct arguments ** list, struct variable * var, struct variable
void
dump_variables(struct arguments * list, int mode)
{
- if (list == NULL)
- {
- return;
- }
+ if (list == NULL)
+ return;
- /* The list is build up from the beginning so lets first dump the
- end of the list:
- */
+ /*
+ * The list is build up from the beginning so lets first dump the end
+ * of the list:
+ */
- dump_variables(list->next, mode);
+ dump_variables(list->next, mode);
- /* Then the current element and its indicator */
- ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
- list->indicator->name, list->indicator->type, NULL, NULL);
+ /* Then the current element and its indicator */
+ ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
+ list->indicator->name, list->indicator->type, NULL, NULL);
- /* Then release the list element. */
- if (mode != 0)
- free(list);
+ /* Then release the list element. */
+ if (mode != 0)
+ free(list);
}
void
-check_indicator(struct ECPGtype *var)
+check_indicator(struct ECPGtype * var)
{
/* make sure this is a valid indicator variable */
switch (var->typ)
{
- struct ECPGstruct_member *p;
+ struct ECPGstruct_member *p;
case ECPGt_short:
case ECPGt_int:
@@ -271,7 +274,7 @@ check_indicator(struct ECPGtype *var)
case ECPGt_array:
check_indicator(var->u.element);
break;
- default:
+ default:
mmerror(ET_ERROR, "indicator variable must be integer type");
break;
}
@@ -289,20 +292,20 @@ get_typedef(char *name)
mmerror(ET_FATAL, errortext);
}
- return(this);
+ return (this);
}
void
adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, bool pointer)
{
- if (type_index >= 0)
+ if (type_index >= 0)
{
if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support");
+ mmerror(ET_FATAL, "No multi-dimensional array support");
*length = type_index;
}
-
+
if (type_dimension >= 0)
{
if (*dimension >= 0 && *length >= 0)
@@ -319,56 +322,57 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
switch (type_enum)
{
- case ECPGt_struct:
- case ECPGt_union:
- /* pointer has to get dimension 0 */
- if (pointer)
- {
- *length = *dimension;
- *dimension = 0;
- }
-
- if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support for structures");
-
- break;
- case ECPGt_varchar:
- /* pointer has to get dimension 0 */
- if (pointer)
- *dimension = 0;
-
- /* one index is the string length */
- if (*length < 0)
- {
- *length = *dimension;
- *dimension = -1;
- }
-
- break;
- case ECPGt_char:
- case ECPGt_unsigned_char:
- /* pointer has to get length 0 */
- if (pointer)
- *length=0;
-
- /* one index is the string length */
- if (*length < 0)
- {
- *length = (*dimension < 0) ? 1 : *dimension;
- *dimension = -1;
- }
-
- break;
- default:
- /* a pointer has dimension = 0 */
- if (pointer) {
- *length = *dimension;
- *dimension = 0;
- }
-
- if (*length >= 0)
- mmerror(ET_FATAL, "No multi-dimensional array support for simple data types");
-
- break;
+ case ECPGt_struct:
+ case ECPGt_union:
+ /* pointer has to get dimension 0 */
+ if (pointer)
+ {
+ *length = *dimension;
+ *dimension = 0;
+ }
+
+ if (*length >= 0)
+ mmerror(ET_FATAL, "No multi-dimensional array support for structures");
+
+ break;
+ case ECPGt_varchar:
+ /* pointer has to get dimension 0 */
+ if (pointer)
+ *dimension = 0;
+
+ /* one index is the string length */
+ if (*length < 0)
+ {
+ *length = *dimension;
+ *dimension = -1;
+ }
+
+ break;
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
+ /* pointer has to get length 0 */
+ if (pointer)
+ *length = 0;
+
+ /* one index is the string length */
+ if (*length < 0)
+ {
+ *length = (*dimension < 0) ? 1 : *dimension;
+ *dimension = -1;
+ }
+
+ break;
+ default:
+ /* a pointer has dimension = 0 */
+ if (pointer)
+ {
+ *length = *dimension;
+ *dimension = 0;
+ }
+
+ if (*length >= 0)
+ mmerror(ET_FATAL, "No multi-dimensional array support for simple data types");
+
+ break;
}
}
diff --git a/src/interfaces/ecpg/test/header_test.h b/src/interfaces/ecpg/test/header_test.h
index 71017aacbbd..741c6fa4b7a 100644
--- a/src/interfaces/ecpg/test/header_test.h
+++ b/src/interfaces/ecpg/test/header_test.h
@@ -1,26 +1,32 @@
exec sql include sqlca;
-void Finish(msg)
+void
+Finish(msg)
{
fprintf(stderr, "Error in statement '%s':\n", msg);
sqlprint();
-
+
/* finish transaction */
- exec sql rollback;
-
+ exec sql rollback;
+
/* and remove test table */
exec sql drop table meskes;
- exec sql commit;
+ exec sql commit;
+
+ exec sql disconnect;
- exec sql disconnect;
-
exit(-1);
}
-void warn(void)
+void
+warn(void)
{
fprintf(stderr, "Warning: At least one column was truncated\n");
}
-exec sql whenever sqlerror do Finish(msg);
-exec sql whenever sqlwarning do warn();
+exec sql whenever sqlerror
+do
+ Finish(msg);
+exec sql whenever sqlwarning
+do
+ warn();