summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-10-25 05:50:21 +0000
committerBruce Momjian <bruce@momjian.us>2001-10-25 05:50:21 +0000
commitb81844b1738c584d92330a5ccd0fbd8b603d2886 (patch)
tree4fae0d4cd26048177fc5cd1a2dd91abc99ba0f99 /src/interfaces/ecpg
parent59da2105d8e6d95345b3b942a2e2aba8cead4838 (diff)
downloadpostgresql-b81844b1738c584d92330a5ccd0fbd8b603d2886.tar.gz
pgindent run on all C files. Java run to follow. initdb/regression
tests pass.
Diffstat (limited to 'src/interfaces/ecpg')
-rw-r--r--src/interfaces/ecpg/include/ecpgerrno.h1
-rw-r--r--src/interfaces/ecpg/include/ecpglib.h1
-rw-r--r--src/interfaces/ecpg/include/ecpgtype.h3
-rw-r--r--src/interfaces/ecpg/include/sql3types.h46
-rw-r--r--src/interfaces/ecpg/include/sqlca.h8
-rw-r--r--src/interfaces/ecpg/lib/connect.c4
-rw-r--r--src/interfaces/ecpg/lib/descriptor.c98
-rw-r--r--src/interfaces/ecpg/lib/execute.c812
-rw-r--r--src/interfaces/ecpg/lib/extern.h9
-rw-r--r--src/interfaces/ecpg/lib/misc.c33
-rw-r--r--src/interfaces/ecpg/lib/pg_type.h3
-rw-r--r--src/interfaces/ecpg/lib/typename.c11
-rw-r--r--src/interfaces/ecpg/preproc/descriptor.c37
-rw-r--r--src/interfaces/ecpg/preproc/ecpg.c10
-rw-r--r--src/interfaces/ecpg/preproc/extern.h3
-rw-r--r--src/interfaces/ecpg/preproc/output.c3
-rw-r--r--src/interfaces/ecpg/preproc/type.c13
-rw-r--r--src/interfaces/ecpg/preproc/type.h16
18 files changed, 578 insertions, 533 deletions
diff --git a/src/interfaces/ecpg/include/ecpgerrno.h b/src/interfaces/ecpg/include/ecpgerrno.h
index 49e6269d8a..81d67277fe 100644
--- a/src/interfaces/ecpg/include/ecpgerrno.h
+++ b/src/interfaces/ecpg/include/ecpgerrno.h
@@ -61,5 +61,4 @@
#define ECPG_NOTICE_NO_TRANSACTION -604
/* NOTICE: BlankPortalAssignName: portal * already exists */
#define ECPG_NOTICE_PORTAL_EXISTS -605
-
#endif /* !_ECPG_ERROR_H */
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index acb022aa1b..732e70f3ce 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -70,5 +70,4 @@ extern "C"
#ifdef __cplusplus
}
-
#endif
diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h
index 3e6875cf1d..c2e698b84f 100644
--- a/src/interfaces/ecpg/include/ecpgtype.h
+++ b/src/interfaces/ecpg/include/ecpgtype.h
@@ -47,7 +47,7 @@ extern "C"
ECPGt_EORT, /* End of result types. */
ECPGt_NO_INDICATOR, /* no indicator */
ECPGt_long_long, ECPGt_unsigned_long_long,
- ECPGt_descriptor /* sql descriptor, no C variable */
+ ECPGt_descriptor /* sql descriptor, no C variable */
};
/* descriptor items */
@@ -76,5 +76,4 @@ extern "C"
#ifdef __cplusplus
}
-
#endif
diff --git a/src/interfaces/ecpg/include/sql3types.h b/src/interfaces/ecpg/include/sql3types.h
index 17fe493c11..02305dd54a 100644
--- a/src/interfaces/ecpg/include/sql3types.h
+++ b/src/interfaces/ecpg/include/sql3types.h
@@ -2,29 +2,29 @@
*
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.5 2001/09/19 14:09:32 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.6 2001/10/25 05:50:11 momjian Exp $
*/
/* chapter 13.1 table 2: Codes used for SQL data types in Dynamic SQL */
enum
{
- SQL3_CHARACTER = 1,
- SQL3_NUMERIC,
- SQL3_DECIMAL,
- SQL3_INTEGER,
- SQL3_SMALLINT,
- SQL3_FLOAT,
- SQL3_REAL,
- SQL3_DOUBLE_PRECISION,
- SQL3_DATE_TIME_TIMESTAMP,
- SQL3_INTERVAL, /* 10 */
- SQL3_CHARACTER_VARYING = 12,
- SQL3_ENUMERATED,
- SQL3_BIT,
- SQL3_BIT_VARYING,
- SQL3_BOOLEAN,
- SQL3_abstract
+ SQL3_CHARACTER = 1,
+ SQL3_NUMERIC,
+ SQL3_DECIMAL,
+ SQL3_INTEGER,
+ SQL3_SMALLINT,
+ SQL3_FLOAT,
+ SQL3_REAL,
+ SQL3_DOUBLE_PRECISION,
+ SQL3_DATE_TIME_TIMESTAMP,
+ SQL3_INTERVAL, /* 10 */
+ SQL3_CHARACTER_VARYING = 12,
+ SQL3_ENUMERATED,
+ SQL3_BIT,
+ SQL3_BIT_VARYING,
+ SQL3_BOOLEAN,
+ SQL3_abstract
/* the rest is xLOB stuff */
};
@@ -32,12 +32,12 @@ enum
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_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
+ 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 3f7e307da7..28ab20533d 100644
--- a/src/interfaces/ecpg/include/sqlca.h
+++ b/src/interfaces/ecpg/include/sqlca.h
@@ -6,8 +6,8 @@
#define DLLIMPORT __declspec (dllimport)
#else
#define DLLIMPORT
-#endif /* __CYGWIN__ */
-#endif /* DLLIMPORT */
+#endif /* __CYGWIN__ */
+#endif /* DLLIMPORT */
#define SQLERRMC_LEN 70
@@ -44,7 +44,7 @@ extern "C"
/*
* 2: if 'W' a (hopefully) non-fatal notice occured
- *//* 3: empty */
+*//* 3: empty */
/* 4: empty */
/* 5: empty */
/* 6: empty */
@@ -58,7 +58,5 @@ extern "C"
#ifdef __cplusplus
}
-
#endif
-
#endif
diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c
index 9da651a020..239c766d7c 100644
--- a/src/interfaces/ecpg/lib/connect.c
+++ b/src/interfaces/ecpg/lib/connect.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.12 2001/09/19 14:09:32 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.13 2001/10/25 05:50:11 momjian Exp $ */
#include "postgres_fe.h"
@@ -313,7 +313,7 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
/*------
* new style:
- * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
+ * <tcp|unix>:postgresql://server[:port|:/unixsocket/path:]
* [/db name][?options]
*------
*/
diff --git a/src/interfaces/ecpg/lib/descriptor.c b/src/interfaces/ecpg/lib/descriptor.c
index ba11f5af5e..af30723266 100644
--- a/src/interfaces/ecpg/lib/descriptor.c
+++ b/src/interfaces/ecpg/lib/descriptor.c
@@ -1,6 +1,6 @@
/* dynamic SQL support routines
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/descriptor.c,v 1.16 2001/09/19 14:09:32 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/descriptor.c,v 1.17 2001/10/25 05:50:11 momjian Exp $
*/
#include "postgres_fe.h"
@@ -18,8 +18,10 @@ static PGresult
*
ECPGresultByDescriptor(int line, const char *name)
{
- PGresult **resultpp = ECPGdescriptor_lvalue ( line, name );
- if (resultpp) return *resultpp;
+ PGresult **resultpp = ECPGdescriptor_lvalue(line, name);
+
+ if (resultpp)
+ return *resultpp;
return NULL;
}
@@ -28,7 +30,8 @@ ECPGDynamicType_DDT(Oid type)
{
switch (type)
{
- case 1082:return SQL3_DDT_DATE; /* date */
+ case 1082:
+ return SQL3_DDT_DATE; /* date */
case 1083:
return SQL3_DDT_TIME; /* time */
case 1184:
@@ -103,8 +106,8 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
{
switch (vartype)
{
- case ECPGt_char:
- case ECPGt_unsigned_char:
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
strncpy((char *) var, value, varcharsize);
break;
case ECPGt_varchar:
@@ -136,9 +139,10 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
va_list args;
PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name);
enum ECPGdtype type;
- bool Indicator_seen = false,
- Data_seen = false;
- int ntuples, act_tuple;
+ bool Indicator_seen = false,
+ Data_seen = false;
+ int ntuples,
+ act_tuple;
va_start(args, index);
if (!ECPGresult)
@@ -180,21 +184,24 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
switch (type)
{
case (ECPGd_indicator):
- /* this is like ECPGexecute
- * missing : allocate arrays, perhaps this should go into
- * a common function !!
+
+ /*
+ * this is like ECPGexecute missing : allocate arrays,
+ * perhaps this should go into a common function !!
*/
if (ntuples > arrsize)
- { ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
- lineno, ntuples, arrsize);
+ {
+ ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
+ lineno, ntuples, arrsize);
ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, NULL);
return false;
}
Indicator_seen = true;
- for (act_tuple = 0; act_tuple < ntuples ; act_tuple++)
- { if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, act_tuple, index)))
+ for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
+ {
+ if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, act_tuple, index)))
return (false);
- var = (char*)var + offset;
+ var = (char *) var + offset;
ECPGlog("ECPGget_desc: INDICATOR[%d] = %d\n", act_tuple, -PQgetisnull(ECPGresult, act_tuple, index));
}
break;
@@ -234,20 +241,23 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
case ECPGd_ret_length:
case ECPGd_ret_octet:
- /* this is like ECPGexecute
- * missing : allocate arrays, perhaps this should go into
- * a common function !!
+
+ /*
+ * this is like ECPGexecute missing : allocate arrays,
+ * perhaps this should go into a common function !!
*/
if (ntuples > arrsize)
- { ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
- lineno, ntuples, arrsize);
+ {
+ ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
+ lineno, ntuples, arrsize);
ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, NULL);
return false;
}
- for (act_tuple = 0; act_tuple < ntuples ; act_tuple++)
- { if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, act_tuple, index)))
+ for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
+ {
+ if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, act_tuple, index)))
return (false);
- var = (char*)var + offset;
+ var = (char *) var + offset;
ECPGlog("ECPGget_desc: RETURNED[%d] = %d\n", act_tuple, PQgetlength(ECPGresult, act_tuple, index));
}
break;
@@ -280,27 +290,30 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index)));
break;
case ECPGd_data:
- /* this is like ECPGexecute
- * missing : allocate arrays, perhaps this should go into
- * a common function !!
+
+ /*
+ * this is like ECPGexecute missing : allocate arrays,
+ * perhaps this should go into a common function !!
*/
if (ntuples > arrsize)
- { ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
- lineno, ntuples, arrsize);
+ {
+ ECPGlog("ECPGget_desc line %d: Incorrect number of matches: %d don't fit into array of %d\n",
+ lineno, ntuples, arrsize);
ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, NULL);
return false;
}
Data_seen = true;
- for (act_tuple = 0; act_tuple < ntuples ; act_tuple++)
- { if (PQgetisnull(ECPGresult, act_tuple, index))
- continue; /* do not touch data on null value */
- if (!get_data(ECPGresult, act_tuple, index, lineno,
- vartype, ECPGt_NO_INDICATOR, var, NULL,
- varcharsize, offset, false))
+ for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
+ {
+ if (PQgetisnull(ECPGresult, act_tuple, index))
+ continue; /* do not touch data on null value */
+ if (!get_data(ECPGresult, act_tuple, index, lineno,
+ vartype, ECPGt_NO_INDICATOR, var, NULL,
+ varcharsize, offset, false))
return (false);
}
break;
-
+
case ECPGd_cardinality:
if (!get_int_item(lineno, var, vartype, PQntuples(ECPGresult)))
return (false);
@@ -318,9 +331,10 @@ ECPGget_desc(int lineno, char *desc_name, int index,...)
}
if (Data_seen && !Indicator_seen)
- {
- for (act_tuple = 0; act_tuple < ntuples ; act_tuple++)
- { if (PQgetisnull(ECPGresult, act_tuple, index))
+ {
+ for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
+ {
+ if (PQgetisnull(ECPGresult, act_tuple, index))
{
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
return (false);
@@ -365,14 +379,14 @@ ECPGallocate_desc(int line, const char *name)
return true;
}
-PGresult **
+PGresult **
ECPGdescriptor_lvalue(int line, const char *descriptor)
{
struct descriptor *i;
for (i = all_descriptors; i != NULL; i = i->next)
{
- if (!strcmp(descriptor, i->name))
+ if (!strcmp(descriptor, i->name))
return &i->result;
}
diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c
index 099b4cff27..e9454ec215 100644
--- a/src/interfaces/ecpg/lib/execute.c
+++ b/src/interfaces/ecpg/lib/execute.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.28 2001/10/05 17:37:07 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.29 2001/10/25 05:50:11 momjian Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -30,14 +30,29 @@
/* variables visible to the programs */
struct sqlca sqlca =
{
- {'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
- sizeof(struct sqlca),
- 0,
- {0, {0}},
- {'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
- {0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0}
+ {
+ 'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
+ } ,
+ sizeof(struct sqlca),
+ 0,
+ {
+ 0,
+ {
+ 0
+ }
+ },
+ {
+ 'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
+ },
+ {
+ 0, 0, 0, 0, 0, 0
+ },
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0
+ },
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0
+ }
};
struct variable
@@ -288,7 +303,6 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
if ((stmt->connection->cache_head) == NULL)
{
-
/*
* Text like types are not an array for ecpg, but postgres counts
* them as an array. This define reminds you to not 'correct'
@@ -356,7 +370,6 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
if (ECPGDynamicType(type) == SQL3_CHARACTER ||
ECPGDynamicType(type) == SQL3_CHARACTER_VARYING)
{
-
/*
* arrays of character strings are not yet implemented
*/
@@ -371,443 +384,439 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
bool
-ECPGstore_result(const PGresult *results, int act_field,
- const struct statement * stmt, struct variable *var)
-{ int isarray,
- act_tuple,
- ntuples = PQntuples(results);
- bool status = true;
-
- isarray = ECPGis_type_an_array(PQftype(results, act_field), stmt, var);
-
- if (!isarray)
- {
+ECPGstore_result(const PGresult *results, int act_field,
+ const struct statement * stmt, struct variable * var)
+{
+ int isarray,
+ act_tuple,
+ ntuples = PQntuples(results);
+ bool status = true;
- /*
- * 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);
- ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
- return false;
- }
- }
- else
- {
+ isarray = ECPGis_type_an_array(PQftype(results, act_field), stmt, var);
- /*
- * since we read an array, the variable has to be
- * an array too
- */
- if (var->arrsize == 0)
- {
- ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL);
- return false;
- }
- }
+ if (!isarray)
+ {
+ /*
+ * 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);
+ ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL);
+ return false;
+ }
+ }
+ else
+ {
+ /*
+ * since we read an array, the variable has to be an array too
+ */
+ if (var->arrsize == 0)
+ {
+ ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL);
+ return false;
+ }
+ }
- /*
- * allocate memory for NULL pointers
- */
- if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
- {
- int len = 0;
+ /*
+ * allocate memory for NULL pointers
+ */
+ if ((var->arrsize == 0 || var->varcharsize == 0) && var->value == NULL)
+ {
+ int len = 0;
- switch (var->type)
- {
- case ECPGt_char:
- case ECPGt_unsigned_char:
- var->varcharsize = 0;
- /* check strlen for each tuple */
- for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
- {
- int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
-
- if (len > var->varcharsize)
- var->varcharsize = len;
- }
- var->offset *= var->varcharsize;
- len = var->offset * ntuples;
- break;
- case ECPGt_varchar:
- len = ntuples * (var->varcharsize + sizeof(int));
- break;
- default:
- len = var->offset * ntuples;
- break;
- }
- var->value = (void *) ecpg_alloc(len, stmt->lineno);
- *((void **) var->pointer) = var->value;
- add_mem(var->value, stmt->lineno);
- }
+ switch (var->type)
+ {
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
+ var->varcharsize = 0;
+ /* check strlen for each tuple */
+ for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
+ {
+ int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
- 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;
- }
+ if (len > var->varcharsize)
+ var->varcharsize = len;
+ }
+ var->offset *= var->varcharsize;
+ len = var->offset * ntuples;
+ break;
+ case ECPGt_varchar:
+ len = ntuples * (var->varcharsize + sizeof(int));
+ break;
+ default:
+ len = var->offset * ntuples;
+ break;
+ }
+ var->value = (void *) ecpg_alloc(len, stmt->lineno);
+ *((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;
+ }
return status;
}
static bool
-ECPGstore_input(const struct statement * stmt, const struct variable *var,
- const char **tobeinserted_p, bool *malloced_p)
+ECPGstore_input(const struct statement * stmt, const struct variable * var,
+ const char **tobeinserted_p, bool *malloced_p)
{
- char *mallocedval = NULL;
- char *newcopy = NULL;
+ char *mallocedval = NULL;
+ char *newcopy = NULL;
- /*
- * Some special treatment is needed for records since we want
- * their contents to arrive in a comma-separated list on insert (I
- * think).
- */
-
- *malloced_p=false;
- *tobeinserted_p="";
+ /*
+ * Some special treatment is needed for records since we want their
+ * contents to arrive in a comma-separated list on insert (I think).
+ */
- /* check for null value and set input buffer accordingly */
- switch (var->ind_type)
- {
- case ECPGt_short:
- case ECPGt_unsigned_short:
- if (*(short *) var->ind_value < 0)
- *tobeinserted_p="null";
- break;
- case ECPGt_int:
- case ECPGt_unsigned_int:
- if (*(int *) var->ind_value < 0)
- *tobeinserted_p="null";
- break;
- case ECPGt_long:
- case ECPGt_unsigned_long:
- if (*(long *) var->ind_value < 0L)
- *tobeinserted_p="null";
- break;
+ *malloced_p = false;
+ *tobeinserted_p = "";
+
+ /* check for null value and set input buffer accordingly */
+ switch (var->ind_type)
+ {
+ case ECPGt_short:
+ case ECPGt_unsigned_short:
+ if (*(short *) var->ind_value < 0)
+ *tobeinserted_p = "null";
+ break;
+ case ECPGt_int:
+ case ECPGt_unsigned_int:
+ if (*(int *) var->ind_value < 0)
+ *tobeinserted_p = "null";
+ break;
+ case ECPGt_long:
+ case ECPGt_unsigned_long:
+ if (*(long *) var->ind_value < 0L)
+ *tobeinserted_p = "null";
+ break;
#ifdef HAVE_LONG_LONG_INT_64
- case ECPGt_long_long:
- case ECPGt_unsigned_long_long:
- if (*(long long int *) var->ind_value < (long long) 0)
- *tobeinserted_p="null";
- break;
+ case ECPGt_long_long:
+ case ECPGt_unsigned_long_long:
+ if (*(long long int *) var->ind_value < (long long) 0)
+ *tobeinserted_p = "null";
+ break;
#endif /* HAVE_LONG_LONG_INT_64 */
- default:
- break;
- }
+ default:
+ break;
+ }
- if (**tobeinserted_p == '\0')
+ if (**tobeinserted_p == '\0')
+ {
+ switch (var->type)
{
- switch (var->type)
- {
- int element;
+ int element;
- case ECPGt_short:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_short:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%hd", *((short *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%hd", *((short *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_int:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_int:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%d", *((int *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%d", *((int *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_unsigned_short:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_unsigned_short:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_unsigned_int:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_unsigned_int:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%u", *((unsigned int *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%u", *((unsigned int *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_long:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_long:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%ld", *((long *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%ld", *((long *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_unsigned_long:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_unsigned_long:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
#ifdef HAVE_LONG_LONG_INT_64
- case ECPGt_long_long:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 25, stmt->lineno)))
- return false;
+ case ECPGt_long_long:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 25, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%lld", *((long long *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%lld", *((long long *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_unsigned_long_long:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 25, stmt->lineno)))
- return false;
+ case ECPGt_unsigned_long_long:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 25, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
#endif /* HAVE_LONG_LONG_INT_64 */
- case ECPGt_float:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_float:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%.14g", *((float *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%.14g", *((float *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_double:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_double:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
- else
- sprintf(mallocedval, "%.14g", *((double *) var->value));
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ sprintf(mallocedval, "%.14g", *((double *) var->value));
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
- case ECPGt_bool:
- if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
- return false;
+ case ECPGt_bool:
+ if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno)))
+ return false;
- if (var->arrsize > 1)
- {
- strncpy(mallocedval, "'{", sizeof("'{"));
-
- if (var->offset == sizeof(char))
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
-
- /*
- * this is necessary since sizeof(C++'s
- * bool)==sizeof(int)
- */
- else if (var->offset == sizeof(int))
- for (element = 0; element < var->arrsize; element++)
- sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
- else
- ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size");
-
- strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
- }
+ if (var->arrsize > 1)
+ {
+ strncpy(mallocedval, "'{", sizeof("'{"));
+
+ if (var->offset == sizeof(char))
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
+
+ /*
+ * this is necessary since sizeof(C++'s
+ * bool)==sizeof(int)
+ */
+ else if (var->offset == sizeof(int))
+ for (element = 0; element < var->arrsize; element++)
+ sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
else
- {
- if (var->offset == sizeof(char))
- sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f');
- else if (var->offset == sizeof(int))
- sprintf(mallocedval, "'%c'", (*((int *) var->value)) ? 't' : 'f');
- else
- ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size");
- }
+ ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size");
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- break;
+ strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'"));
+ }
+ else
+ {
+ if (var->offset == sizeof(char))
+ sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f');
+ else if (var->offset == sizeof(int))
+ sprintf(mallocedval, "'%c'", (*((int *) var->value)) ? 't' : 'f');
+ else
+ ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size");
+ }
- case ECPGt_char:
- case ECPGt_unsigned_char:
- {
- /* set slen to string length if type is char * */
- int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ break;
+
+ case ECPGt_char:
+ case ECPGt_unsigned_char:
+ {
+ /* set slen to string length if type is char * */
+ int slen = (var->varcharsize == 0) ? strlen((char *) var->value) : var->varcharsize;
- if (!(newcopy = ecpg_alloc(slen + 1, stmt->lineno)))
- return false;
+ if (!(newcopy = ecpg_alloc(slen + 1, stmt->lineno)))
+ return false;
- strncpy(newcopy, (char *) var->value, slen);
- newcopy[slen] = '\0';
+ strncpy(newcopy, (char *) var->value, slen);
+ newcopy[slen] = '\0';
- mallocedval = quote_postgres(newcopy, stmt->lineno);
- if (!mallocedval)
- return false;
+ mallocedval = quote_postgres(newcopy, stmt->lineno);
+ if (!mallocedval)
+ return false;
- free(newcopy);
+ free(newcopy);
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- }
- break;
- case ECPGt_char_variable:
- {
- int slen = strlen((char *) var->value);
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ }
+ break;
+ case ECPGt_char_variable:
+ {
+ int slen = strlen((char *) var->value);
- if (!(mallocedval = ecpg_alloc(slen + 1, stmt->lineno)))
- return false;
+ if (!(mallocedval = ecpg_alloc(slen + 1, stmt->lineno)))
+ return false;
- strncpy(mallocedval, (char *) var->value, slen);
- mallocedval[slen] = '\0';
+ strncpy(mallocedval, (char *) var->value, slen);
+ mallocedval[slen] = '\0';
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- }
- break;
- case ECPGt_varchar:
- {
- struct ECPGgeneric_varchar *variable =
- (struct ECPGgeneric_varchar *) (var->value);
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ }
+ break;
+ case ECPGt_varchar:
+ {
+ struct ECPGgeneric_varchar *variable =
+ (struct ECPGgeneric_varchar *) (var->value);
- if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, stmt->lineno)))
- return false;
+ if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, stmt->lineno)))
+ return false;
- strncpy(newcopy, variable->arr, variable->len);
- newcopy[variable->len] = '\0';
+ strncpy(newcopy, variable->arr, variable->len);
+ newcopy[variable->len] = '\0';
- mallocedval = quote_postgres(newcopy, stmt->lineno);
- if (!mallocedval)
- return false;
+ mallocedval = quote_postgres(newcopy, stmt->lineno);
+ if (!mallocedval)
+ return false;
- free(newcopy);
+ free(newcopy);
- *tobeinserted_p = mallocedval;
- *malloced_p = true;
- }
- break;
+ *tobeinserted_p = mallocedval;
+ *malloced_p = true;
+ }
+ break;
- default:
- /* Not implemented yet */
- ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type));
- return false;
- break;
- }
+ default:
+ /* Not implemented yet */
+ ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type));
+ return false;
+ break;
}
+ }
return true;
}
@@ -831,15 +840,15 @@ ECPGexecute(struct statement * stmt)
var = stmt->inlist;
while (var)
{
- char *newcopy = NULL;
+ char *newcopy = NULL;
const char *tobeinserted = NULL;
char *p;
- bool malloced=FALSE;
- int hostvarl = 0;
+ bool malloced = FALSE;
+ int hostvarl = 0;
if (!ECPGstore_input(stmt, var, &tobeinserted, &malloced))
return false;
-
+
/*
* Now tobeinserted points to an area that is to be inserted at
* the first %s
@@ -850,7 +859,6 @@ ECPGexecute(struct statement * stmt)
strcpy(newcopy, copiedquery);
if ((p = next_insert(newcopy + hostvarl)) == NULL)
{
-
/*
* We have an argument but we dont have the matched up string
* in the string
@@ -880,7 +888,7 @@ ECPGexecute(struct statement * stmt)
*/
if (malloced)
{
- free((char*)tobeinserted);
+ free((char *) tobeinserted);
tobeinserted = NULL;
}
@@ -921,11 +929,14 @@ ECPGexecute(struct statement * stmt)
ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
}
else
- /* note: since some of the following code is duplicated in descriptor.c
- * it should go into a separate function
- */
+
+ /*
+ * note: since some of the following code is duplicated in
+ * descriptor.c it should go into a separate function
+ */
{
- bool clear_result = TRUE;
+ bool clear_result = TRUE;
+
var = stmt->outlist;
switch (PQresultStatus(results))
{
@@ -940,37 +951,43 @@ ECPGexecute(struct statement * stmt)
if (ntuples < 1)
{
- if (ntuples) ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
- stmt->lineno, ntuples);
+ if (ntuples)
+ ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
+ stmt->lineno, ntuples);
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
status = false;
break;
}
- if (var != NULL && var->type==ECPGt_descriptor)
- { PGresult **resultpp = ECPGdescriptor_lvalue(stmt->lineno, (const char*)var->pointer);
- if (resultpp == NULL) status = false;
+ if (var != NULL && var->type == ECPGt_descriptor)
+ {
+ PGresult **resultpp = ECPGdescriptor_lvalue(stmt->lineno, (const char *) var->pointer);
+
+ if (resultpp == NULL)
+ status = false;
else
- { if (*resultpp)
- PQclear(*resultpp);
- *resultpp=results;
+ {
+ if (*resultpp)
+ PQclear(*resultpp);
+ *resultpp = results;
clear_result = FALSE;
- ECPGlog("ECPGexecute putting result (%d tuples) into descriptor '%s'\n", PQntuples(results), (const char*)var->pointer);
+ ECPGlog("ECPGexecute putting result (%d tuples) into descriptor '%s'\n", PQntuples(results), (const char *) var->pointer);
}
var = var->next;
}
- else for (act_field = 0; act_field < nfields && status; act_field++)
- {
- if (var == NULL)
+ else
+ for (act_field = 0; act_field < nfields && status; act_field++)
{
- ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL);
- return (false);
- }
-
- status = ECPGstore_result(results, act_field, stmt, var);
+ if (var == NULL)
+ {
+ ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, NULL);
+ return (false);
+ }
- var = var->next;
- }
+ status = ECPGstore_result(results, act_field, stmt, var);
+
+ var = var->next;
+ }
if (status && var != NULL)
{
@@ -1016,7 +1033,8 @@ ECPGexecute(struct statement * stmt)
status = false;
break;
}
- if (clear_result) PQclear(results);
+ if (clear_result)
+ PQclear(results);
}
/* check for asynchronous returns */
@@ -1038,7 +1056,7 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
struct statement *stmt;
struct connection *con = get_connection(connection_name);
bool status;
- char *oldlocale;
+ char *oldlocale;
/* Make sure we do NOT honor the locale for numeric input/output */
/* since the database wants the standard decimal point */
@@ -1081,12 +1099,12 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
return (status);
}
-/* old descriptor interface */
+/* old descriptor interface */
bool
ECPGdo_descriptor(int line, const char *connection,
const char *descriptor, const char *query)
{
- return ECPGdo(line, connection, (char *)query, ECPGt_EOIT,
- ECPGt_descriptor, descriptor, 0L, 0L, 0L,
- ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+ return ECPGdo(line, connection, (char *) query, ECPGt_EOIT,
+ ECPGt_descriptor, descriptor, 0L, 0L, 0L,
+ ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
}
diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h
index 971924e708..8e7ba566a3 100644
--- a/src/interfaces/ecpg/lib/extern.h
+++ b/src/interfaces/ecpg/lib/extern.h
@@ -62,9 +62,8 @@ struct descriptor
struct descriptor *next;
};
-PGresult **
-ECPGdescriptor_lvalue(int line, const char *descriptor);
+PGresult **
+ ECPGdescriptor_lvalue(int line, const char *descriptor);
-bool
-ECPGstore_result(const PGresult *results, int act_field,
- const struct statement * stmt, struct variable *var);
+bool ECPGstore_result(const PGresult *results, int act_field,
+ const struct statement * stmt, struct variable * var);
diff --git a/src/interfaces/ecpg/lib/misc.c b/src/interfaces/ecpg/lib/misc.c
index b5dd56e3cf..a37cd7ceb6 100644
--- a/src/interfaces/ecpg/lib/misc.c
+++ b/src/interfaces/ecpg/lib/misc.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/misc.c,v 1.6 2001/10/05 17:37:07 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/misc.c,v 1.7 2001/10/25 05:50:12 momjian Exp $ */
#include "postgres_fe.h"
@@ -11,14 +11,29 @@
static struct sqlca sqlca_init =
{
- {'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
- sizeof(struct sqlca),
- 0,
- {0, {0}},
- {'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
- {0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0},
- {0, 0, 0, 0, 0, 0, 0, 0}
+ {
+ 'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
+ } ,
+ sizeof(struct sqlca),
+ 0,
+ {
+ 0,
+ {
+ 0
+ }
+ },
+ {
+ 'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
+ },
+ {
+ 0, 0, 0, 0, 0, 0
+ },
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0
+ },
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0
+ }
};
static int simple_debug = 0;
diff --git a/src/interfaces/ecpg/lib/pg_type.h b/src/interfaces/ecpg/lib/pg_type.h
index a9ffbfb627..5961dc23c6 100644
--- a/src/interfaces/ecpg/lib/pg_type.h
+++ b/src/interfaces/ecpg/lib/pg_type.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_type.h,v 1.2 2001/01/24 19:43:29 momjian Exp $
+ * $Id: pg_type.h,v 1.3 2001/10/25 05:50:12 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@@ -68,5 +68,4 @@
#define ZPBITOID 1560
#define VARBITOID 1562
#define NUMERICOID 1700
-
#endif /* PG_TYPE_H */
diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c
index 345a5f36f1..48747e2c71 100644
--- a/src/interfaces/ecpg/lib/typename.c
+++ b/src/interfaces/ecpg/lib/typename.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/typename.c,v 1.19 2001/09/19 14:09:32 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/typename.c,v 1.20 2001/10/25 05:50:12 momjian Exp $ */
#include "postgres_fe.h"
@@ -17,7 +17,7 @@ ECPGtype_name(enum ECPGttype typ)
{
switch (typ)
{
- case ECPGt_char:
+ case ECPGt_char:
return "char";
case ECPGt_unsigned_char:
return "unsigned char";
@@ -58,11 +58,12 @@ ECPGDynamicType(Oid type)
{
switch (type)
{
- case BOOLOID:return SQL3_BOOLEAN; /* bool */
+ case BOOLOID:
+ return SQL3_BOOLEAN; /* bool */
case INT2OID:
return SQL3_SMALLINT; /* int2 */
case INT4OID:
- return SQL3_INTEGER;/* int4 */
+ return SQL3_INTEGER; /* int4 */
case TEXTOID:
return SQL3_CHARACTER; /* text */
case FLOAT4OID:
@@ -80,7 +81,7 @@ ECPGDynamicType(Oid type)
case TIMESTAMPOID:
return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
case NUMERICOID:
- return SQL3_NUMERIC;/* numeric */
+ return SQL3_NUMERIC; /* numeric */
default:
return -type;
}
diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c
index 6542888dd7..372a0c362d 100644
--- a/src/interfaces/ecpg/preproc/descriptor.c
+++ b/src/interfaces/ecpg/preproc/descriptor.c
@@ -75,9 +75,10 @@ void
add_descriptor(char *name, char *connection)
{
struct descriptor *new;
-
- if (name[0]!='"') return;
-
+
+ if (name[0] != '"')
+ return;
+
new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));
new->next = descriptors;
@@ -99,7 +100,8 @@ drop_descriptor(char *name, char *connection)
struct descriptor *i;
struct descriptor **lastptr = &descriptors;
- if (name[0]!='"') return;
+ if (name[0] != '"')
+ return;
for (i = descriptors; i; lastptr = &i->next, i = i->next)
{
@@ -128,7 +130,8 @@ lookup_descriptor(char *name, char *connection)
{
struct descriptor *i;
- if (name[0]!='"') return NULL;
+ if (name[0] != '"')
+ return NULL;
for (i = descriptors; i; i = i->next)
{
@@ -199,21 +202,23 @@ output_get_descr(char *desc_name, char *index)
/* I consider dynamic allocation overkill since at most two descriptor
variables are possible per statement. (input and output descriptor)
- And descriptors are no normal variables, so they don't belong into
+ And descriptors are no normal variables, so they don't belong into
the variable list.
*/
-
+
#define MAX_DESCRIPTOR_NAMELEN 128
-struct variable *descriptor_variable(const char *name,int input)
-{ static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
+struct variable *
+descriptor_variable(const char *name, int input)
+{
+ static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
static const struct ECPGtype descriptor_type =
- { ECPGt_descriptor, 0 };
+ {ECPGt_descriptor, 0};
static const struct variable varspace[2] =
- {{ descriptor_names[0], (struct ECPGtype*)&descriptor_type, 0, NULL },
- { descriptor_names[1], (struct ECPGtype*)&descriptor_type, 0, NULL }
+ {{descriptor_names[0], (struct ECPGtype *) & descriptor_type, 0, NULL},
+ {descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL}
};
-
- strncpy(descriptor_names[input],name,MAX_DESCRIPTOR_NAMELEN);
- descriptor_names[input][MAX_DESCRIPTOR_NAMELEN-1]=0;
- return (struct variable*)&varspace[input];
+
+ strncpy(descriptor_names[input], name, MAX_DESCRIPTOR_NAMELEN);
+ descriptor_names[input][MAX_DESCRIPTOR_NAMELEN - 1] = 0;
+ return (struct variable *) & varspace[input];
}
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 4897f77393..7b6f33e794 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.49 2001/09/19 14:09:32 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.50 2001/10/25 05:50:12 momjian Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -32,7 +32,7 @@ help(const char *progname)
/* printf is a macro some places; don't #ifdef inside its arguments */
#ifdef YYDEBUG
printf("Usage:\n"
- " %s [-d] [-I DIRECTORY] [-o OUTFILE] [-t] file1 [file2...]\n\n",
+ " %s [-d] [-I DIRECTORY] [-o OUTFILE] [-t] file1 [file2...]\n\n",
progname);
#else
printf("Usage:\n"
@@ -47,7 +47,7 @@ help(const char *progname)
printf(" -o OUTFILE write result to OUTFILE\n");
printf(" -t turn on autocommit of transactions\n");
printf("\nIf no output file is specified, the name is formed by adding .c\n"
- "to the input file name, after stripping off .pgc if present.\n");
+ "to the input file name, after stripping off .pgc if present.\n");
printf("\nReport bugs to <pgsql-bugs@postgresql.org>.\n");
}
@@ -90,12 +90,12 @@ main(int argc, char *const argv[])
if (argc > 1)
{
- if (strcmp(argv[1], "--help")==0 || strcmp(argv[1], "-?")==0)
+ if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
{
help(progname);
exit(0);
}
- else if (strcmp(argv[1], "--version")==0)
+ else if (strcmp(argv[1], "--version") == 0)
{
printf("ecpg (PostgreSQL %s) %d.%d.%d\n", PG_VERSION,
MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index b393fd3ad7..43f99c9cc7 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -22,7 +22,6 @@ extern char *yytext,
#ifdef YYDEBUG
extern int yydebug;
-
#endif
extern int yylineno,
yyleng;
@@ -67,7 +66,7 @@ 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 struct variable *descriptor_variable(const char *name,int input);
+extern struct variable *descriptor_variable(const char *name, int input);
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);
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 690ed861a3..7e626b1971 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -39,7 +39,8 @@ print_action(struct when * w)
{
switch (w->code)
{
- case W_SQLPRINT:fprintf(yyout, "sqlprint();");
+ case W_SQLPRINT:
+ fprintf(yyout, "sqlprint();");
break;
case W_GOTO:
fprintf(yyout, "goto %s;", w->command);
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index be688ab63e..7efca2c376 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -121,7 +121,7 @@ get_type(enum ECPGttype typ)
{
switch (typ)
{
- case ECPGt_char:
+ case ECPGt_char:
return ("ECPGt_char");
break;
case ECPGt_unsigned_char:
@@ -212,10 +212,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:
@@ -351,7 +351,6 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ,
static void
ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, long arrsiz, struct ECPGtype * typ, struct ECPGtype * ind_typ, const char *offsetarg, const char *prefix, const char *ind_prefix)
{
-
/*
* If offset is NULL, then this is the first recursive level. If not
* then we are in a struct in a struct and the offset is used as
@@ -409,10 +408,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:
@@ -446,7 +445,7 @@ get_dtype(enum ECPGdtype typ)
{
switch (typ)
{
- case ECPGd_count:
+ case ECPGd_count:
return ("ECPGd_countr");
break;
case ECPGd_data:
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index 12e45ab43a..a44cbec1ca 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -60,13 +60,13 @@ extern const char *ECPGtype_name(enum ECPGttype typ);
/* some stuff for whenever statements */
enum WHEN_TYPE
{
- W_NOTHING,
- W_CONTINUE,
- W_BREAK,
- W_SQLPRINT,
- W_GOTO,
- W_DO,
- W_STOP
+ W_NOTHING,
+ W_CONTINUE,
+ W_BREAK,
+ W_SQLPRINT,
+ W_GOTO,
+ W_DO,
+ W_STOP
};
struct when
@@ -155,7 +155,7 @@ struct assignment
enum errortype
{
- ET_NOTICE, ET_ERROR, ET_FATAL
+ ET_NOTICE, ET_ERROR, ET_FATAL
};
struct fetch_desc