mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
Ye-old pgindent run. Same 4-space tabs.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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 */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
|
||||
return (false);
|
||||
dres = 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
dres = 0.0;
|
||||
|
||||
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')
|
||||
{
|
||||
((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;
|
||||
|
||||
case ECPGt_char:
|
||||
case ECPGt_unsigned_char:
|
||||
{
|
||||
strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
|
||||
if (varcharsize && varcharsize < strlen(pval))
|
||||
{
|
||||
/* truncation */
|
||||
switch (ind_type)
|
||||
res = strtol(pval, &scan_length, 10);
|
||||
if ((isarray && *scan_length != ',' && *scan_length != '}')
|
||||
|| (!isarray && *scan_length != '\0')) /* Garbage left */
|
||||
{
|
||||
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;
|
||||
ECPGraise(lineno, ECPG_INT_FORMAT, pval);
|
||||
return (false);
|
||||
res = 0L;
|
||||
}
|
||||
sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
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);
|
||||
res = 0L;
|
||||
|
||||
variable->len = strlen(pval);
|
||||
if (varcharsize > 0 && variable->len > varcharsize)
|
||||
switch (type)
|
||||
{
|
||||
/* 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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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 */
|
||||
{
|
||||
ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval);
|
||||
return (false);
|
||||
dres = 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
dres = 0.0;
|
||||
|
||||
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')
|
||||
{
|
||||
((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;
|
||||
|
||||
case ECPGt_char:
|
||||
case ECPGt_unsigned_char:
|
||||
{
|
||||
strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize);
|
||||
if (varcharsize && varcharsize < strlen(pval))
|
||||
{
|
||||
/* 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';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
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);
|
||||
|
||||
variable->len = strlen(pval);
|
||||
if (varcharsize > 0 && variable->len > varcharsize)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
} while (isarray && *pval != '}');
|
||||
|
||||
return (true);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
--index;
|
||||
|
||||
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:
|
||||
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:
|
||||
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);
|
||||
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;
|
||||
return (false);
|
||||
|
||||
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;
|
||||
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_data:
|
||||
if (!get_data(ECPGresult, 0, index, lineno, vartype, ECPGt_NO_INDICATOR, var, NULL, varcharsize, offset, false))
|
||||
return (false);
|
||||
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
|
||||
{
|
||||
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
|
||||
return (false);
|
||||
}
|
||||
return (false);
|
||||
|
||||
return (true);
|
||||
break;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index))
|
||||
{
|
||||
ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL);
|
||||
return (false);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
{
|
||||
case ECPG_NOT_FOUND:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"No data found in line %d.", 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);
|
||||
case ECPG_OUT_OF_MEMORY:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Out of memory in line %d.", line);
|
||||
break;
|
||||
|
||||
case ECPG_EMPTY:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Empty query in line %d.", line);
|
||||
case ECPG_UNSUPPORTED:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Unsupported type %s in line %d.", str, 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);
|
||||
case ECPG_TOO_MANY_ARGUMENTS:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Too many arguments in line %d.", line);
|
||||
break;
|
||||
|
||||
case ECPG_INVALID_STMT:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Invalid statement name in line %d.", line);
|
||||
case ECPG_TOO_FEW_ARGUMENTS:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Too few arguments 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);
|
||||
|
||||
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_INVALID_DESCRIPTOR_INDEX:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Sescriptor index out of range in line %d.", line);
|
||||
|
||||
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_UNKNOWN_DESCRIPTOR_ITEM:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Unknown descriptor item %s in line %d.", str, line);
|
||||
|
||||
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_VAR_NOT_NUMERIC:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Variable is not a numeric type in line %d.", line);
|
||||
|
||||
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_VAR_NOT_CHAR:
|
||||
snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc),
|
||||
"Variable is not a character type in line %d.", line);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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 */
|
||||
|
||||
@@ -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 <christof.petig@wtal.de>
|
||||
*
|
||||
* $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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user