mirror of
https://github.com/postgres/postgres.git
synced 2025-05-12 16:21:30 +03:00
Run pgindent over ODBC source. We couldn't do this years ago because we
weren't the master source. We are now, and it really needs it.
This commit is contained in:
parent
505a828a66
commit
755a87332a
@ -35,7 +35,8 @@
|
||||
|
||||
/* Bind parameters on a statement handle */
|
||||
|
||||
RETCODE SQL_API SQLBindParameter(
|
||||
RETCODE SQL_API
|
||||
SQLBindParameter(
|
||||
HSTMT hstmt,
|
||||
UWORD ipar,
|
||||
SWORD fParamType,
|
||||
@ -52,20 +53,24 @@ static char *func="SQLBindParameter";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if(stmt->parameters_allocated < ipar) {
|
||||
if (stmt->parameters_allocated < ipar)
|
||||
{
|
||||
ParameterInfoClass *old_parameters;
|
||||
int i, old_parameters_allocated;
|
||||
int i,
|
||||
old_parameters_allocated;
|
||||
|
||||
old_parameters = stmt->parameters;
|
||||
old_parameters_allocated = stmt->parameters_allocated;
|
||||
|
||||
stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass) * (ipar));
|
||||
if ( ! stmt->parameters) {
|
||||
if (!stmt->parameters)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Could not allocate memory for statement parameters";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -75,7 +80,8 @@ static char *func="SQLBindParameter";
|
||||
stmt->parameters_allocated = ipar;
|
||||
|
||||
/* copy the old parameters over */
|
||||
for(i = 0; i < old_parameters_allocated; i++) {
|
||||
for (i = 0; i < old_parameters_allocated; i++)
|
||||
{
|
||||
/* a structure copy should work */
|
||||
stmt->parameters[i] = old_parameters[i];
|
||||
}
|
||||
@ -84,9 +90,13 @@ static char *func="SQLBindParameter";
|
||||
if (old_parameters)
|
||||
free(old_parameters);
|
||||
|
||||
/* zero out the newly allocated parameters (in case they skipped some, */
|
||||
/*
|
||||
* zero out the newly allocated parameters (in case they skipped
|
||||
* some,
|
||||
*/
|
||||
/* so we don't accidentally try to use them later) */
|
||||
for(; i < stmt->parameters_allocated; i++) {
|
||||
for (; i < stmt->parameters_allocated; i++)
|
||||
{
|
||||
stmt->parameters[i].buflen = 0;
|
||||
stmt->parameters[i].buffer = 0;
|
||||
stmt->parameters[i].used = 0;
|
||||
@ -102,7 +112,8 @@ static char *func="SQLBindParameter";
|
||||
}
|
||||
}
|
||||
|
||||
ipar--; /* use zero based column numbers for the below part */
|
||||
ipar--; /* use zero based column numbers for the
|
||||
* below part */
|
||||
|
||||
/* store the given info */
|
||||
stmt->parameters[ipar].buflen = cbValueMax;
|
||||
@ -114,15 +125,18 @@ static char *func="SQLBindParameter";
|
||||
stmt->parameters[ipar].precision = cbColDef;
|
||||
stmt->parameters[ipar].scale = ibScale;
|
||||
|
||||
/* If rebinding a parameter that had data-at-exec stuff in it,
|
||||
then free that stuff
|
||||
/*
|
||||
* If rebinding a parameter that had data-at-exec stuff in it, then
|
||||
* free that stuff
|
||||
*/
|
||||
if (stmt->parameters[ipar].EXEC_used) {
|
||||
if (stmt->parameters[ipar].EXEC_used)
|
||||
{
|
||||
free(stmt->parameters[ipar].EXEC_used);
|
||||
stmt->parameters[ipar].EXEC_used = NULL;
|
||||
}
|
||||
|
||||
if (stmt->parameters[ipar].EXEC_buffer) {
|
||||
if (stmt->parameters[ipar].EXEC_buffer)
|
||||
{
|
||||
if (stmt->parameters[ipar].SQLType != SQL_LONGVARBINARY)
|
||||
free(stmt->parameters[ipar].EXEC_buffer);
|
||||
stmt->parameters[ipar].EXEC_buffer = NULL;
|
||||
@ -142,7 +156,8 @@ static char *func="SQLBindParameter";
|
||||
/* - - - - - - - - - */
|
||||
|
||||
/* Associate a user-supplied buffer with a database column. */
|
||||
RETCODE SQL_API SQLBindCol(
|
||||
RETCODE SQL_API
|
||||
SQLBindCol(
|
||||
HSTMT hstmt,
|
||||
UWORD icol,
|
||||
SWORD fCType,
|
||||
@ -157,7 +172,8 @@ static char *func="SQLBindCol";
|
||||
|
||||
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -165,7 +181,8 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||
|
||||
SC_clear_error(stmt);
|
||||
|
||||
if( stmt->status == STMT_EXECUTING) {
|
||||
if (stmt->status == STMT_EXECUTING)
|
||||
{
|
||||
stmt->errormsg = "Can't bind columns while statement is still executing.";
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -173,15 +190,19 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||
}
|
||||
|
||||
/* If the bookmark column is being bound, then just save it */
|
||||
if (icol == 0) {
|
||||
if (icol == 0)
|
||||
{
|
||||
|
||||
if (rgbValue == NULL) {
|
||||
if (rgbValue == NULL)
|
||||
{
|
||||
stmt->bookmark.buffer = NULL;
|
||||
stmt->bookmark.used = NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* Make sure it is the bookmark data type */
|
||||
if ( fCType != SQL_C_BOOKMARK) {
|
||||
if (fCType != SQL_C_BOOKMARK)
|
||||
{
|
||||
stmt->errormsg = "Column 0 is not of type SQL_C_BOOKMARK";
|
||||
stmt->errornumber = STMT_PROGRAM_TYPE_OUT_OF_RANGE;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -202,25 +223,30 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||
extend_bindings(stmt, icol);
|
||||
|
||||
/* check to see if the bindings were allocated */
|
||||
if ( ! stmt->bindings) {
|
||||
if (!stmt->bindings)
|
||||
{
|
||||
stmt->errormsg = "Could not allocate memory for bindings.";
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
icol--; /* use zero based col numbers from here out */
|
||||
icol--; /* use zero based col numbers from here
|
||||
* out */
|
||||
|
||||
/* Reset for SQLGetData */
|
||||
stmt->bindings[icol].data_left = -1;
|
||||
|
||||
if (rgbValue == NULL) {
|
||||
if (rgbValue == NULL)
|
||||
{
|
||||
/* we have to unbind the column */
|
||||
stmt->bindings[icol].buflen = 0;
|
||||
stmt->bindings[icol].buffer = NULL;
|
||||
stmt->bindings[icol].used = NULL;
|
||||
stmt->bindings[icol].returntype = SQL_C_CHAR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ok, bind that column */
|
||||
stmt->bindings[icol].buflen = cbValueMax;
|
||||
stmt->bindings[icol].buffer = rgbValue;
|
||||
@ -242,7 +268,8 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||
/* it is best to say this function is not supported and let the application assume a */
|
||||
/* data type (most likely varchar). */
|
||||
|
||||
RETCODE SQL_API SQLDescribeParam(
|
||||
RETCODE SQL_API
|
||||
SQLDescribeParam(
|
||||
HSTMT hstmt,
|
||||
UWORD ipar,
|
||||
SWORD FAR * pfSqlType,
|
||||
@ -255,12 +282,14 @@ static char *func = "SQLDescribeParam";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if( (ipar < 1) || (ipar > stmt->parameters_allocated) ) {
|
||||
if ((ipar < 1) || (ipar > stmt->parameters_allocated))
|
||||
{
|
||||
stmt->errormsg = "Invalid parameter number for SQLDescribeParam.";
|
||||
stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -269,7 +298,10 @@ static char *func = "SQLDescribeParam";
|
||||
|
||||
ipar--;
|
||||
|
||||
/* This implementation is not very good, since it is supposed to describe */
|
||||
/*
|
||||
* This implementation is not very good, since it is supposed to
|
||||
* describe
|
||||
*/
|
||||
/* parameter markers, not bound parameters. */
|
||||
if (pfSqlType)
|
||||
*pfSqlType = stmt->parameters[ipar].SQLType;
|
||||
@ -290,7 +322,8 @@ static char *func = "SQLDescribeParam";
|
||||
|
||||
/* Sets multiple values (arrays) for the set of parameter markers. */
|
||||
|
||||
RETCODE SQL_API SQLParamOptions(
|
||||
RETCODE SQL_API
|
||||
SQLParamOptions(
|
||||
HSTMT hstmt,
|
||||
UDWORD crow,
|
||||
UDWORD FAR * pirow)
|
||||
@ -312,7 +345,8 @@ static char *func = "SQLParamOptions";
|
||||
/* like it does for SQLDescribeParam is that some applications don't care and try */
|
||||
/* to call it anyway. */
|
||||
/* If the statement does not have parameters, it should just return 0. */
|
||||
RETCODE SQL_API SQLNumParams(
|
||||
RETCODE SQL_API
|
||||
SQLNumParams(
|
||||
HSTMT hstmt,
|
||||
SWORD FAR * pcpar)
|
||||
{
|
||||
@ -323,32 +357,39 @@ static char *func = "SQLNumParams";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if(!stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (pcpar)
|
||||
*pcpar = 0;
|
||||
else {
|
||||
else
|
||||
{
|
||||
SC_log_error(func, "pcpar was null", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
if(!stmt->statement) {
|
||||
if (!stmt->statement)
|
||||
{
|
||||
/* no statement has been allocated */
|
||||
stmt->errormsg = "SQLNumParams called with no statement ready.";
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
for(i=0; i < strlen(stmt->statement); i++) {
|
||||
for (i = 0; i < strlen(stmt->statement); i++)
|
||||
{
|
||||
|
||||
if (stmt->statement[i] == '?' && !in_quote)
|
||||
(*pcpar)++;
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (stmt->statement[i] == '\'')
|
||||
in_quote = (in_quote ? FALSE : TRUE);
|
||||
}
|
||||
@ -368,11 +409,11 @@ BindInfoClass *new_bindings;
|
||||
int i;
|
||||
|
||||
new_bindings = (BindInfoClass *) malloc(num_columns * sizeof(BindInfoClass));
|
||||
if(!new_bindings) {
|
||||
if (!new_bindings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i=0; i < num_columns; i++) {
|
||||
for (i = 0; i < num_columns; i++)
|
||||
{
|
||||
new_bindings[i].buflen = 0;
|
||||
new_bindings[i].buffer = NULL;
|
||||
new_bindings[i].used = NULL;
|
||||
@ -393,13 +434,16 @@ mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func,
|
||||
|
||||
/* if we have too few, allocate room for more, and copy the old */
|
||||
/* entries into the new structure */
|
||||
if(stmt->bindings_allocated < num_columns) {
|
||||
if (stmt->bindings_allocated < num_columns)
|
||||
{
|
||||
|
||||
new_bindings = create_empty_bindings(num_columns);
|
||||
if ( ! new_bindings) {
|
||||
if (!new_bindings)
|
||||
{
|
||||
mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, stmt->bindings_allocated);
|
||||
|
||||
if (stmt->bindings) {
|
||||
if (stmt->bindings)
|
||||
{
|
||||
free(stmt->bindings);
|
||||
stmt->bindings = NULL;
|
||||
}
|
||||
@ -407,7 +451,8 @@ mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func,
|
||||
return;
|
||||
}
|
||||
|
||||
if(stmt->bindings) {
|
||||
if (stmt->bindings)
|
||||
{
|
||||
for (i = 0; i < stmt->bindings_allocated; i++)
|
||||
new_bindings[i] = stmt->bindings[i];
|
||||
|
||||
|
@ -15,18 +15,24 @@
|
||||
/*
|
||||
* BindInfoClass -- stores information about a bound column
|
||||
*/
|
||||
struct BindInfoClass_ {
|
||||
struct BindInfoClass_
|
||||
{
|
||||
Int4 buflen; /* size of buffer */
|
||||
Int4 data_left; /* amount of data left to read (SQLGetData) */
|
||||
Int4 data_left; /* amount of data left to read
|
||||
* (SQLGetData) */
|
||||
char *buffer; /* pointer to the buffer */
|
||||
Int4 *used; /* used space in the buffer (for strings not counting the '\0') */
|
||||
Int2 returntype; /* kind of conversion to be applied when returning (SQL_C_DEFAULT, SQL_C_CHAR...) */
|
||||
Int4 *used; /* used space in the buffer (for strings
|
||||
* not counting the '\0') */
|
||||
Int2 returntype; /* kind of conversion to be applied when
|
||||
* returning (SQL_C_DEFAULT,
|
||||
* SQL_C_CHAR...) */
|
||||
};
|
||||
|
||||
/*
|
||||
* ParameterInfoClass -- stores information about a bound parameter
|
||||
*/
|
||||
struct ParameterInfoClass_ {
|
||||
struct ParameterInfoClass_
|
||||
{
|
||||
Int4 buflen;
|
||||
char *buffer;
|
||||
Int4 *used;
|
||||
@ -36,7 +42,8 @@ struct ParameterInfoClass_ {
|
||||
UInt4 precision;
|
||||
Int2 scale;
|
||||
Oid lobj_oid;
|
||||
Int4 *EXEC_used; /* amount of data OR the oid of the large object */
|
||||
Int4 *EXEC_used; /* amount of data OR the oid of the large
|
||||
* object */
|
||||
char *EXEC_buffer; /* the data or the FD of the large object */
|
||||
char data_at_exec;
|
||||
};
|
||||
|
@ -24,7 +24,8 @@ ColumnInfoClass *rv;
|
||||
|
||||
rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
|
||||
|
||||
if (rv) {
|
||||
if (rv)
|
||||
{
|
||||
rv->num_fields = 0;
|
||||
rv->name = NULL;
|
||||
rv->adtid = NULL;
|
||||
@ -68,19 +69,22 @@ ConnInfo *ci;
|
||||
|
||||
mylog("num_fields = %d\n", new_num_fields);
|
||||
|
||||
if (self) { /* according to that allocate memory */
|
||||
if (self)
|
||||
{ /* according to that allocate memory */
|
||||
CI_set_num_fields(self, new_num_fields);
|
||||
}
|
||||
|
||||
/* now read in the descriptions */
|
||||
for(lf = 0; lf < new_num_fields; lf++) {
|
||||
for (lf = 0; lf < new_num_fields; lf++)
|
||||
{
|
||||
|
||||
SOCK_get_string(sock, new_field_name, MAX_MESSAGE_LEN);
|
||||
new_adtid = (Oid) SOCK_get_int(sock, 4);
|
||||
new_adtsize = (Int2) SOCK_get_int(sock, 2);
|
||||
|
||||
/* If 6.4 protocol, then read the atttypmod field */
|
||||
if (PG_VERSION_GE(conn, 6.4)) {
|
||||
if (PG_VERSION_GE(conn, 6.4))
|
||||
{
|
||||
|
||||
mylog("READING ATTTYPMOD\n");
|
||||
new_atttypmod = (Int4) SOCK_get_int(sock, 4);
|
||||
@ -109,7 +113,8 @@ CI_free_memory(ColumnInfoClass *self)
|
||||
register Int2 lf;
|
||||
int num_fields = self->num_fields;
|
||||
|
||||
for (lf = 0; lf < num_fields; lf++) {
|
||||
for (lf = 0; lf < num_fields; lf++)
|
||||
{
|
||||
if (self->name[lf])
|
||||
free(self->name[lf]);
|
||||
}
|
||||
@ -143,9 +148,8 @@ CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
|
||||
{
|
||||
|
||||
/* check bounds */
|
||||
if((field_num < 0) || (field_num >= self->num_fields)) {
|
||||
if ((field_num < 0) || (field_num >= self->num_fields))
|
||||
return;
|
||||
}
|
||||
|
||||
/* store the info */
|
||||
self->name[field_num] = strdup(new_name);
|
||||
@ -155,4 +159,3 @@ CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
|
||||
|
||||
self->display_size[field_num] = 0;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
#include "psqlodbc.h"
|
||||
|
||||
struct ColumnInfoClass_ {
|
||||
struct ColumnInfoClass_
|
||||
{
|
||||
Int2 num_fields;
|
||||
char **name; /* list of type names */
|
||||
Oid *adtid; /* list of type ids */
|
||||
|
@ -26,14 +26,16 @@
|
||||
#include <odbcinst.h>
|
||||
#endif
|
||||
|
||||
#define STMT_INCREMENT 16 /* how many statement holders to allocate at a time */
|
||||
#define STMT_INCREMENT 16 /* how many statement holders to allocate
|
||||
* at a time */
|
||||
|
||||
#define PRN_NULLCHECK
|
||||
|
||||
extern GLOBAL_VALUES globals;
|
||||
|
||||
|
||||
RETCODE SQL_API SQLAllocConnect(
|
||||
RETCODE SQL_API
|
||||
SQLAllocConnect(
|
||||
HENV henv,
|
||||
HDBC FAR * phdbc)
|
||||
{
|
||||
@ -46,7 +48,8 @@ static char *func="SQLAllocConnect";
|
||||
conn = CC_Constructor();
|
||||
mylog("**** %s: henv = %u, conn = %u\n", func, henv, conn);
|
||||
|
||||
if( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
env->errormsg = "Couldn't allocate memory for Connection object.";
|
||||
env->errornumber = ENV_ALLOC_ERROR;
|
||||
*phdbc = SQL_NULL_HDBC;
|
||||
@ -54,7 +57,8 @@ static char *func="SQLAllocConnect";
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
if ( ! EN_add_connection(env, conn)) {
|
||||
if (!EN_add_connection(env, conn))
|
||||
{
|
||||
env->errormsg = "Maximum number of connections exceeded.";
|
||||
env->errornumber = ENV_ALLOC_ERROR;
|
||||
CC_Destructor(conn);
|
||||
@ -71,7 +75,8 @@ static char *func="SQLAllocConnect";
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLConnect(
|
||||
RETCODE SQL_API
|
||||
SQLConnect(
|
||||
HDBC hdbc,
|
||||
UCHAR FAR * szDSN,
|
||||
SWORD cbDSN,
|
||||
@ -86,7 +91,8 @@ static char *func = "SQLConnect";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -100,8 +106,9 @@ static char *func = "SQLConnect";
|
||||
/* initialize pg_version from connInfo.protocol */
|
||||
CC_initialize_pg_version(conn);
|
||||
|
||||
/* override values from DSN info with UID and authStr(pwd)
|
||||
This only occurs if the values are actually there.
|
||||
/*
|
||||
* override values from DSN info with UID and authStr(pwd) This only
|
||||
* occurs if the values are actually there.
|
||||
*/
|
||||
make_string(szUID, cbUID, ci->username);
|
||||
make_string(szAuthStr, cbAuthStr, ci->password);
|
||||
@ -111,7 +118,8 @@ static char *func = "SQLConnect";
|
||||
|
||||
qlog("conn = %u, %s(DSN='%s', UID='%s', PWD='%s')\n", conn, func, ci->dsn, ci->username, ci->password);
|
||||
|
||||
if ( CC_connect(conn, FALSE) <= 0) {
|
||||
if (CC_connect(conn, FALSE) <= 0)
|
||||
{
|
||||
/* Error messages are filled in */
|
||||
CC_log_error(func, "Error on CC_connect", conn);
|
||||
return SQL_ERROR;
|
||||
@ -124,7 +132,8 @@ static char *func = "SQLConnect";
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLBrowseConnect(
|
||||
RETCODE SQL_API
|
||||
SQLBrowseConnect(
|
||||
HDBC hdbc,
|
||||
UCHAR FAR * szConnStrIn,
|
||||
SWORD cbConnStrIn,
|
||||
@ -142,7 +151,8 @@ static char *func="SQLBrowseConnect";
|
||||
/* - - - - - - - - - */
|
||||
|
||||
/* Drop any hstmts open on hdbc and disconnect from database */
|
||||
RETCODE SQL_API SQLDisconnect(
|
||||
RETCODE SQL_API
|
||||
SQLDisconnect(
|
||||
HDBC hdbc)
|
||||
{
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
@ -151,14 +161,16 @@ static char *func = "SQLDisconnect";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
qlog("conn=%u, %s\n", conn, func);
|
||||
|
||||
if (conn->status == CONN_EXECUTING) {
|
||||
if (conn->status == CONN_EXECUTING)
|
||||
{
|
||||
conn->errornumber = CONN_IN_USE;
|
||||
conn->errormsg = "A transaction is currently being executed";
|
||||
CC_log_error(func, "", conn);
|
||||
@ -179,7 +191,8 @@ static char *func = "SQLDisconnect";
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLFreeConnect(
|
||||
RETCODE SQL_API
|
||||
SQLFreeConnect(
|
||||
HDBC hdbc)
|
||||
{
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
@ -188,13 +201,15 @@ static char *func = "SQLFreeConnect";
|
||||
mylog("%s: entering...\n", func);
|
||||
mylog("**** in %s: hdbc=%u\n", func, hdbc);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* Remove the connection from the environment */
|
||||
if ( ! EN_remove_connection(conn->henv, conn)) {
|
||||
if (!EN_remove_connection(conn->henv, conn))
|
||||
{
|
||||
conn->errornumber = CONN_IN_USE;
|
||||
conn->errormsg = "A transaction is currently being executed";
|
||||
CC_log_error(func, "", conn);
|
||||
@ -215,13 +230,15 @@ static char *func = "SQLFreeConnect";
|
||||
*
|
||||
*/
|
||||
|
||||
ConnectionClass *CC_Constructor()
|
||||
ConnectionClass *
|
||||
CC_Constructor()
|
||||
{
|
||||
ConnectionClass *rv;
|
||||
|
||||
rv = (ConnectionClass *) malloc(sizeof(ConnectionClass));
|
||||
|
||||
if (rv != NULL) {
|
||||
if (rv != NULL)
|
||||
{
|
||||
|
||||
rv->henv = NULL; /* not yet associated with an environment */
|
||||
|
||||
@ -283,17 +300,22 @@ CC_Destructor(ConnectionClass *self)
|
||||
mylog("after CC_Cleanup\n");
|
||||
|
||||
/* Free up statement holders */
|
||||
if (self->stmts) {
|
||||
if (self->stmts)
|
||||
{
|
||||
free(self->stmts);
|
||||
self->stmts = NULL;
|
||||
}
|
||||
mylog("after free statement holders\n");
|
||||
|
||||
/* Free cached table info */
|
||||
if (self->col_info) {
|
||||
if (self->col_info)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < self->ntables; i++) {
|
||||
if (self->col_info[i]->result) /* Free the SQLColumns result structure */
|
||||
|
||||
for (i = 0; i < self->ntables; i++)
|
||||
{
|
||||
if (self->col_info[i]->result) /* Free the SQLColumns
|
||||
* result structure */
|
||||
QR_Destructor(self->col_info[i]->result);
|
||||
|
||||
free(self->col_info[i]);
|
||||
@ -313,11 +335,13 @@ int
|
||||
CC_cursor_count(ConnectionClass * self)
|
||||
{
|
||||
StatementClass *stmt;
|
||||
int i, count = 0;
|
||||
int i,
|
||||
count = 0;
|
||||
|
||||
mylog("CC_cursor_count: self=%u, num_stmts=%d\n", self, self->num_stmts);
|
||||
|
||||
for (i = 0; i < self->num_stmts; i++) {
|
||||
for (i = 0; i < self->num_stmts; i++)
|
||||
{
|
||||
stmt = self->stmts[i];
|
||||
if (stmt && stmt->result && stmt->result->cursor)
|
||||
count++;
|
||||
@ -343,7 +367,8 @@ CC_abort(ConnectionClass *self)
|
||||
{
|
||||
QResultClass *res;
|
||||
|
||||
if ( CC_is_in_trans(self)) {
|
||||
if (CC_is_in_trans(self))
|
||||
{
|
||||
res = NULL;
|
||||
|
||||
mylog("CC_abort: sending ABORT!\n");
|
||||
@ -382,7 +407,8 @@ StatementClass *stmt;
|
||||
mylog("after CC_abort\n");
|
||||
|
||||
/* This actually closes the connection to the dbase */
|
||||
if (self->sock) {
|
||||
if (self->sock)
|
||||
{
|
||||
SOCK_Destructor(self->sock);
|
||||
self->sock = NULL;
|
||||
}
|
||||
@ -390,9 +416,11 @@ StatementClass *stmt;
|
||||
mylog("after SOCK destructor\n");
|
||||
|
||||
/* Free all the stmts on this connection */
|
||||
for (i = 0; i < self->num_stmts; i++) {
|
||||
for (i = 0; i < self->num_stmts; i++)
|
||||
{
|
||||
stmt = self->stmts[i];
|
||||
if (stmt) {
|
||||
if (stmt)
|
||||
{
|
||||
stmt->hdbc = NULL; /* prevent any more dbase interactions */
|
||||
SC_Destructor(stmt);
|
||||
self->stmts[i] = NULL;
|
||||
@ -401,7 +429,8 @@ StatementClass *stmt;
|
||||
|
||||
/* Check for translation dll */
|
||||
#ifdef WIN32
|
||||
if ( self->translation_handle) {
|
||||
if (self->translation_handle)
|
||||
{
|
||||
FreeLibrary(self->translation_handle);
|
||||
self->translation_handle = NULL;
|
||||
}
|
||||
@ -417,7 +446,8 @@ CC_set_translation (ConnectionClass *self)
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
if (self->translation_handle != NULL) {
|
||||
if (self->translation_handle != NULL)
|
||||
{
|
||||
FreeLibrary(self->translation_handle);
|
||||
self->translation_handle = NULL;
|
||||
}
|
||||
@ -428,7 +458,8 @@ CC_set_translation (ConnectionClass *self)
|
||||
self->translation_option = atoi(self->connInfo.translation_option);
|
||||
self->translation_handle = LoadLibrary(self->connInfo.translation_dll);
|
||||
|
||||
if (self->translation_handle == NULL) {
|
||||
if (self->translation_handle == NULL)
|
||||
{
|
||||
self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
|
||||
self->errormsg = "Could not load the translation DLL.";
|
||||
return FALSE;
|
||||
@ -442,7 +473,8 @@ CC_set_translation (ConnectionClass *self)
|
||||
= (DriverToDataSourceProc) GetProcAddress(self->translation_handle,
|
||||
"SQLDriverToDataSource");
|
||||
|
||||
if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL) {
|
||||
if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL)
|
||||
{
|
||||
self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
|
||||
self->errormsg = "Could not find translation DLL functions.";
|
||||
return FALSE;
|
||||
@ -470,7 +502,8 @@ static char *func="CC_connect";
|
||||
|
||||
sock = self->sock; /* already connected, just authenticate */
|
||||
|
||||
else {
|
||||
else
|
||||
{
|
||||
|
||||
qlog("Global Options: Version='%s', fetch=%d, socket=%d, unknown_sizes=%d, max_varchar_size=%d, max_longvarchar_size=%d\n",
|
||||
POSTGRESDRIVERVERSION,
|
||||
@ -492,13 +525,15 @@ static char *func="CC_connect";
|
||||
globals.extra_systable_prefixes,
|
||||
globals.conn_settings);
|
||||
|
||||
if (self->status != CONN_NOT_CONNECTED) {
|
||||
if (self->status != CONN_NOT_CONNECTED)
|
||||
{
|
||||
self->errormsg = "Already connected.";
|
||||
self->errornumber = CONN_OPENDB_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ci->server[0] == '\0' || ci->port[0] == '\0' || ci->database[0] == '\0') {
|
||||
if (ci->server[0] == '\0' || ci->port[0] == '\0' || ci->database[0] == '\0')
|
||||
{
|
||||
self->errornumber = CONN_INIREAD_ERROR;
|
||||
self->errormsg = "Missing server name, port, or database name in call to CC_connect.";
|
||||
return 0;
|
||||
@ -506,12 +541,15 @@ static char *func="CC_connect";
|
||||
|
||||
mylog("CC_connect(): DSN = '%s', server = '%s', port = '%s', database = '%s', username = '%s', password='%s'\n", ci->dsn, ci->server, ci->port, ci->database, ci->username, ci->password);
|
||||
|
||||
/* If the socket was closed for some reason (like a SQLDisconnect, but no SQLFreeConnect
|
||||
then create a socket now.
|
||||
/*
|
||||
* If the socket was closed for some reason (like a SQLDisconnect,
|
||||
* but no SQLFreeConnect then create a socket now.
|
||||
*/
|
||||
if ( ! self->sock) {
|
||||
if (!self->sock)
|
||||
{
|
||||
self->sock = SOCK_Constructor();
|
||||
if ( ! self->sock) {
|
||||
if (!self->sock)
|
||||
{
|
||||
self->errornumber = CONNECTION_SERVER_NOT_REACHED;
|
||||
self->errormsg = "Could not open a socket to the server";
|
||||
return 0;
|
||||
@ -523,7 +561,8 @@ static char *func="CC_connect";
|
||||
mylog("connecting to the server socket...\n");
|
||||
|
||||
SOCK_connect_to(sock, (short) atoi(ci->port), ci->server);
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
mylog("connection to the server socket failed.\n");
|
||||
self->errornumber = CONNECTION_SERVER_NOT_REACHED;
|
||||
self->errormsg = "Could not connect to the server";
|
||||
@ -548,7 +587,8 @@ static char *func="CC_connect";
|
||||
|
||||
mylog("sent the authentication block.\n");
|
||||
|
||||
if (sock->errornumber != 0) {
|
||||
if (sock->errornumber != 0)
|
||||
{
|
||||
mylog("couldn't send the authentication block properly.\n");
|
||||
self->errornumber = CONN_INVALID_AUTHENTICATION;
|
||||
self->errormsg = "Sending the authentication packet failed";
|
||||
@ -564,14 +604,16 @@ static char *func="CC_connect";
|
||||
/* Now get the authentication request from backend */
|
||||
/* *************************************************** */
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
|
||||
if (do_password)
|
||||
beresp = 'R';
|
||||
else
|
||||
beresp = SOCK_get_char(sock);
|
||||
|
||||
switch(beresp) {
|
||||
switch (beresp)
|
||||
{
|
||||
case 'E':
|
||||
mylog("auth got 'E'\n");
|
||||
|
||||
@ -582,12 +624,14 @@ static char *func="CC_connect";
|
||||
return 0;
|
||||
case 'R':
|
||||
|
||||
if (do_password) {
|
||||
if (do_password)
|
||||
{
|
||||
mylog("in 'R' do_password\n");
|
||||
areq = AUTH_REQ_PASSWORD;
|
||||
do_password = FALSE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mylog("auth got 'R'\n");
|
||||
|
||||
areq = SOCK_get_int(sock, 4);
|
||||
@ -596,7 +640,8 @@ static char *func="CC_connect";
|
||||
|
||||
mylog("areq = %d\n", areq);
|
||||
}
|
||||
switch(areq) {
|
||||
switch (areq)
|
||||
{
|
||||
case AUTH_REQ_OK:
|
||||
break;
|
||||
|
||||
@ -613,7 +658,8 @@ static char *func="CC_connect";
|
||||
case AUTH_REQ_PASSWORD:
|
||||
mylog("in AUTH_REQ_PASSWORD\n");
|
||||
|
||||
if (ci->password[0] == '\0') {
|
||||
if (ci->password[0] == '\0')
|
||||
{
|
||||
self->errornumber = CONNECTION_NEED_PASSWORD;
|
||||
self->errormsg = "A password is required for this connection.";
|
||||
return -1; /* need password */
|
||||
@ -654,7 +700,8 @@ static char *func="CC_connect";
|
||||
mylog("sending an empty query...\n");
|
||||
|
||||
res = CC_send_query(self, " ", NULL);
|
||||
if ( res == NULL || QR_get_status(res) != PGRES_EMPTY_QUERY) {
|
||||
if (res == NULL || QR_get_status(res) != PGRES_EMPTY_QUERY)
|
||||
{
|
||||
mylog("got no result from the empty query. (probably database does not exist)\n");
|
||||
self->errornumber = CONNECTION_NO_SUCH_DATABASE;
|
||||
self->errormsg = "The database does not exist on the server\nor user authentication failed.";
|
||||
@ -673,13 +720,17 @@ static char *func="CC_connect";
|
||||
/******* Send any initial settings *********/
|
||||
/**********************************************/
|
||||
|
||||
/* Since these functions allocate statements, and since the connection is not
|
||||
established yet, it would violate odbc state transition rules. Therefore,
|
||||
these functions call the corresponding local function instead.
|
||||
/*
|
||||
* Since these functions allocate statements, and since the connection
|
||||
* is not established yet, it would violate odbc state transition
|
||||
* rules. Therefore, these functions call the corresponding local
|
||||
* function instead.
|
||||
*/
|
||||
CC_send_settings(self);
|
||||
CC_lookup_lo(self); /* a hack to get the oid of our large object oid type */
|
||||
CC_lookup_pg_version(self); /* Get PostgreSQL version for SQLGetInfo use */
|
||||
CC_lookup_lo(self); /* a hack to get the oid of our large
|
||||
* object oid type */
|
||||
CC_lookup_pg_version(self); /* Get PostgreSQL version for SQLGetInfo
|
||||
* use */
|
||||
|
||||
CC_clear_error(self); /* clear any initial command errors */
|
||||
self->status = CONN_CONNECTED;
|
||||
@ -697,8 +748,10 @@ int i;
|
||||
|
||||
mylog("CC_add_statement: self=%u, stmt=%u\n", self, stmt);
|
||||
|
||||
for (i = 0; i < self->num_stmts; i++) {
|
||||
if ( ! self->stmts[i]) {
|
||||
for (i = 0; i < self->num_stmts; i++)
|
||||
{
|
||||
if (!self->stmts[i])
|
||||
{
|
||||
stmt->hdbc = self;
|
||||
self->stmts[i] = stmt;
|
||||
return TRUE;
|
||||
@ -725,8 +778,10 @@ CC_remove_statement(ConnectionClass *self, StatementClass *stmt)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < self->num_stmts; i++) {
|
||||
if (self->stmts[i] == stmt && stmt->status != STMT_EXECUTING) {
|
||||
for (i = 0; i < self->num_stmts; i++)
|
||||
{
|
||||
if (self->stmts[i] == stmt && stmt->status != STMT_EXECUTING)
|
||||
{
|
||||
self->stmts[i] = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
@ -754,7 +809,8 @@ static char msg[4096];
|
||||
|
||||
mylog("msg = '%s'\n", msg);
|
||||
|
||||
if (sock && sock->errormsg && sock->errormsg[0] != '\0') {
|
||||
if (sock && sock->errormsg && sock->errormsg[0] != '\0')
|
||||
{
|
||||
pos = strlen(msg);
|
||||
sprintf(&msg[pos], ";\n%s", sock->errormsg);
|
||||
}
|
||||
@ -772,12 +828,14 @@ int rv;
|
||||
mylog("enter CC_get_error\n");
|
||||
|
||||
/* Create a very informative errormsg if it hasn't been done yet. */
|
||||
if ( ! self->errormsg_created) {
|
||||
if (!self->errormsg_created)
|
||||
{
|
||||
self->errormsg = CC_create_errormsg(self);
|
||||
self->errormsg_created = TRUE;
|
||||
}
|
||||
|
||||
if (self->errornumber) {
|
||||
if (self->errornumber)
|
||||
{
|
||||
*number = self->errornumber;
|
||||
*message = self->errormsg;
|
||||
}
|
||||
@ -802,19 +860,23 @@ int rv;
|
||||
QResultClass *
|
||||
CC_send_query(ConnectionClass * self, char *query, QueryInfo * qi)
|
||||
{
|
||||
QResultClass *result_in, *res = NULL;
|
||||
QResultClass *result_in,
|
||||
*res = NULL;
|
||||
char swallow;
|
||||
int id;
|
||||
SocketClass *sock = self->sock;
|
||||
static char msgbuffer[MAX_MESSAGE_LEN + 1];
|
||||
char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont need static */
|
||||
char cmdbuffer[MAX_MESSAGE_LEN + 1]; /* QR_set_command() dups
|
||||
* this string so dont
|
||||
* need static */
|
||||
|
||||
|
||||
mylog("send_query(): conn=%u, query='%s'\n", self, query);
|
||||
qlog("conn=%u, query='%s'\n", self, query);
|
||||
|
||||
/* Indicate that we are sending a query to the backend */
|
||||
if(strlen(query) > MAX_MESSAGE_LEN-2) {
|
||||
if (strlen(query) > MAX_MESSAGE_LEN - 2)
|
||||
{
|
||||
self->errornumber = CONNECTION_MSG_TOO_LONG;
|
||||
self->errormsg = "Query string is too long";
|
||||
return NULL;
|
||||
@ -823,7 +885,8 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
if ((NULL == query) || (query[0] == '\0'))
|
||||
return NULL;
|
||||
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_SEND;
|
||||
self->errormsg = "Could not send Query to backend";
|
||||
CC_set_no_trans(self);
|
||||
@ -831,7 +894,8 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
}
|
||||
|
||||
SOCK_put_char(sock, 'Q');
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_SEND;
|
||||
self->errormsg = "Could not send Query to backend";
|
||||
CC_set_no_trans(self);
|
||||
@ -841,7 +905,8 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
SOCK_put_string(sock, query);
|
||||
SOCK_flush_output(sock);
|
||||
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_SEND;
|
||||
self->errormsg = "Could not send Query to backend";
|
||||
CC_set_no_trans(self);
|
||||
@ -850,11 +915,13 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
|
||||
mylog("send_query: done sending query\n");
|
||||
|
||||
while(1) {
|
||||
while (1)
|
||||
{
|
||||
/* what type of message is coming now ? */
|
||||
id = SOCK_get_char(sock);
|
||||
|
||||
if ((SOCK_get_errcode(sock) != 0) || (id == EOF)) {
|
||||
if ((SOCK_get_errcode(sock) != 0) || (id == EOF))
|
||||
{
|
||||
self->errornumber = CONNECTION_NO_RESPONSE;
|
||||
self->errormsg = "No response from the backend";
|
||||
if (res)
|
||||
@ -867,22 +934,27 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
|
||||
mylog("send_query: got id = '%c'\n", id);
|
||||
|
||||
switch (id) {
|
||||
switch (id)
|
||||
{
|
||||
case 'A': /* Asynchronous Messages are ignored */
|
||||
(void) SOCK_get_int(sock, 4); /* id of notification */
|
||||
SOCK_get_string(sock, msgbuffer, MAX_MESSAGE_LEN);
|
||||
/* name of the relation the message comes from */
|
||||
break;
|
||||
case 'C' : /* portal query command, no tuples returned */
|
||||
case 'C': /* portal query command, no tuples
|
||||
* returned */
|
||||
/* read in the return message from the backend */
|
||||
SOCK_get_string(sock, cmdbuffer, MAX_MESSAGE_LEN);
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_NO_RESPONSE;
|
||||
self->errormsg = "No response from backend while receiving a portal query command";
|
||||
mylog("send_query: 'C' - %s\n", self->errormsg);
|
||||
CC_set_no_trans(self);
|
||||
return NULL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
char clear = 0;
|
||||
|
||||
@ -897,19 +969,22 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
QR_set_status(res, PGRES_COMMAND_OK);
|
||||
QR_set_command(res, cmdbuffer);
|
||||
|
||||
/* (Quotation from the original comments)
|
||||
since backend may produce more than one result for some commands
|
||||
we need to poll until clear
|
||||
so we send an empty query, and keep reading out of the pipe
|
||||
until an 'I' is received
|
||||
/*
|
||||
* (Quotation from the original comments) since
|
||||
* backend may produce more than one result for some
|
||||
* commands we need to poll until clear so we send an
|
||||
* empty query, and keep reading out of the pipe until
|
||||
* an 'I' is received
|
||||
*/
|
||||
|
||||
SOCK_put_string(sock, "Q ");
|
||||
SOCK_flush_output(sock);
|
||||
|
||||
while( ! clear) {
|
||||
while (!clear)
|
||||
{
|
||||
id = SOCK_get_char(sock);
|
||||
switch(id) {
|
||||
switch (id)
|
||||
{
|
||||
case 'I':
|
||||
(void) SOCK_get_char(sock);
|
||||
clear = TRUE;
|
||||
@ -927,13 +1002,17 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
case 'E':
|
||||
SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
|
||||
qlog("ERROR from backend during clear: '%s'\n", cmdbuffer);
|
||||
/* We must report this type of error as well
|
||||
(practically for reference integrity violation
|
||||
error reporting, from PostgreSQL 7.0).
|
||||
(Zoltan Kovacs, 04/26/2000)
|
||||
|
||||
/*
|
||||
* We must report this type of error as
|
||||
* well (practically for reference
|
||||
* integrity violation error reporting,
|
||||
* from PostgreSQL 7.0). (Zoltan Kovacs,
|
||||
* 04/26/2000)
|
||||
*/
|
||||
self->errormsg = cmdbuffer;
|
||||
if ( ! strncmp(self->errormsg, "FATAL", 5)) {
|
||||
if (!strncmp(self->errormsg, "FATAL", 5))
|
||||
{
|
||||
self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
|
||||
CC_set_no_trans(self);
|
||||
}
|
||||
@ -964,18 +1043,22 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
mylog("~~~ NOTICE: '%s'\n", cmdbuffer);
|
||||
qlog("NOTICE from backend during send_query: '%s'\n", cmdbuffer);
|
||||
|
||||
continue; /* dont return a result -- continue reading */
|
||||
continue; /* dont return a result -- continue
|
||||
* reading */
|
||||
|
||||
case 'I': /* The server sends an empty query */
|
||||
/* There is a closing '\0' following the 'I', so we eat it */
|
||||
swallow = SOCK_get_char(sock);
|
||||
if ((swallow != '\0') || SOCK_get_errcode(sock) != 0) {
|
||||
if ((swallow != '\0') || SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_BACKEND_CRAZY;
|
||||
self->errormsg = "Unexpected protocol character from backend (send_query - I)";
|
||||
res = QR_Constructor();
|
||||
QR_set_status(res, PGRES_FATAL_ERROR);
|
||||
return res;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We return the empty query */
|
||||
res = QR_Constructor();
|
||||
QR_set_status(res, PGRES_EMPTY_QUERY);
|
||||
@ -997,12 +1080,14 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
/* We should report that an error occured. Zoltan */
|
||||
res = QR_Constructor();
|
||||
|
||||
if ( ! strncmp(self->errormsg, "FATAL", 5)) {
|
||||
if (!strncmp(self->errormsg, "FATAL", 5))
|
||||
{
|
||||
self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
|
||||
CC_set_no_trans(self);
|
||||
QR_set_status(res, PGRES_FATAL_ERROR);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
|
||||
QR_set_status(res, PGRES_NONFATAL_ERROR);
|
||||
}
|
||||
@ -1015,10 +1100,12 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
case 'T': /* Tuple results start here */
|
||||
result_in = qi ? qi->result_in : NULL;
|
||||
|
||||
if ( result_in == NULL) {
|
||||
if (result_in == NULL)
|
||||
{
|
||||
result_in = QR_Constructor();
|
||||
mylog("send_query: 'T' no result_in: res = %u\n", result_in);
|
||||
if ( ! result_in) {
|
||||
if (!result_in)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
|
||||
self->errormsg = "Could not create result info in send_query.";
|
||||
return NULL;
|
||||
@ -1027,14 +1114,17 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
if (qi)
|
||||
QR_set_cache_size(result_in, qi->row_size);
|
||||
|
||||
if ( ! QR_fetch_tuples(result_in, self, qi ? qi->cursor : NULL)) {
|
||||
if (!QR_fetch_tuples(result_in, self, qi ? qi->cursor : NULL))
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
|
||||
self->errormsg = QR_get_message(result_in);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else { /* next fetch, so reuse an existing result */
|
||||
if ( ! QR_fetch_tuples(result_in, NULL, NULL)) {
|
||||
else
|
||||
{ /* next fetch, so reuse an existing result */
|
||||
if (!QR_fetch_tuples(result_in, NULL, NULL))
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
|
||||
self->errormsg = QR_get_message(result_in);
|
||||
return NULL;
|
||||
@ -1064,14 +1154,17 @@ char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont
|
||||
int
|
||||
CC_send_function(ConnectionClass * self, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG * args, int nargs)
|
||||
{
|
||||
char id, c, done;
|
||||
char id,
|
||||
c,
|
||||
done;
|
||||
SocketClass *sock = self->sock;
|
||||
static char msgbuffer[MAX_MESSAGE_LEN + 1];
|
||||
int i;
|
||||
|
||||
mylog("send_function(): conn=%u, fnid=%d, result_is_int=%d, nargs=%d\n", self, fnid, result_is_int, nargs);
|
||||
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_SEND;
|
||||
self->errormsg = "Could not send function to backend";
|
||||
CC_set_no_trans(self);
|
||||
@ -1079,7 +1172,8 @@ int i;
|
||||
}
|
||||
|
||||
SOCK_put_string(sock, "F ");
|
||||
if (SOCK_get_errcode(sock) != 0) {
|
||||
if (SOCK_get_errcode(sock) != 0)
|
||||
{
|
||||
self->errornumber = CONNECTION_COULD_NOT_SEND;
|
||||
self->errormsg = "Could not send function to backend";
|
||||
CC_set_no_trans(self);
|
||||
@ -1091,7 +1185,8 @@ int i;
|
||||
|
||||
mylog("send_function: done sending function\n");
|
||||
|
||||
for (i = 0; i < nargs; ++i) {
|
||||
for (i = 0; i < nargs; ++i)
|
||||
{
|
||||
|
||||
mylog(" arg[%d]: len = %d, isint = %d, integer = %d, ptr = %u\n", i, args[i].len, args[i].isint, args[i].u.integer, args[i].u.ptr);
|
||||
|
||||
@ -1108,11 +1203,13 @@ int i;
|
||||
mylog(" after flush output\n");
|
||||
|
||||
done = FALSE;
|
||||
while ( ! done) {
|
||||
while (!done)
|
||||
{
|
||||
id = SOCK_get_char(sock);
|
||||
mylog(" got id = %c\n", id);
|
||||
|
||||
switch(id) {
|
||||
switch (id)
|
||||
{
|
||||
case 'V':
|
||||
done = TRUE;
|
||||
break; /* ok */
|
||||
@ -1146,8 +1243,10 @@ int i;
|
||||
}
|
||||
|
||||
id = SOCK_get_char(sock);
|
||||
for (;;) {
|
||||
switch (id) {
|
||||
for (;;)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case 'G': /* function returned properly */
|
||||
mylog(" got G!\n");
|
||||
|
||||
@ -1182,7 +1281,8 @@ int i;
|
||||
mylog("send_function(G): 'N' - %s\n", msgbuffer);
|
||||
qlog("NOTICE from backend during send_function: '%s'\n", msgbuffer);
|
||||
|
||||
continue; /* dont return a result -- continue reading */
|
||||
continue; /* dont return a result -- continue
|
||||
* reading */
|
||||
|
||||
case '0': /* empty result */
|
||||
return TRUE;
|
||||
@ -1204,12 +1304,14 @@ CC_send_settings(ConnectionClass *self)
|
||||
{
|
||||
/* char ini_query[MAX_MESSAGE_LEN]; */
|
||||
ConnInfo *ci = &(self->connInfo);
|
||||
|
||||
/* QResultClass *res; */
|
||||
HSTMT hstmt;
|
||||
StatementClass *stmt;
|
||||
RETCODE result;
|
||||
char status = TRUE;
|
||||
char *cs, *ptr;
|
||||
char *cs,
|
||||
*ptr;
|
||||
static char *func = "CC_send_settings";
|
||||
|
||||
|
||||
@ -1220,9 +1322,8 @@ static char *func="CC_send_settings";
|
||||
*/
|
||||
|
||||
result = SQLAllocStmt(self, &hstmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
return FALSE;
|
||||
}
|
||||
stmt = (StatementClass *) hstmt;
|
||||
|
||||
stmt->internal = TRUE; /* ensure no BEGIN/COMMIT/ABORT stuff */
|
||||
@ -1235,7 +1336,8 @@ static char *func="CC_send_settings";
|
||||
mylog("%s: result %d, status %d from set DateStyle\n", func, result, status);
|
||||
|
||||
/* Disable genetic optimizer based on global flag */
|
||||
if (globals.disable_optimizer) {
|
||||
if (globals.disable_optimizer)
|
||||
{
|
||||
result = SQLExecDirect(hstmt, "set geqo to 'OFF'", SQL_NTS);
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
status = FALSE;
|
||||
@ -1245,7 +1347,8 @@ static char *func="CC_send_settings";
|
||||
}
|
||||
|
||||
/* KSQO */
|
||||
if (globals.ksqo) {
|
||||
if (globals.ksqo)
|
||||
{
|
||||
result = SQLExecDirect(hstmt, "set ksqo to 'ON'", SQL_NTS);
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
status = FALSE;
|
||||
@ -1255,10 +1358,12 @@ static char *func="CC_send_settings";
|
||||
}
|
||||
|
||||
/* Global settings */
|
||||
if (globals.conn_settings[0] != '\0') {
|
||||
if (globals.conn_settings[0] != '\0')
|
||||
{
|
||||
cs = strdup(globals.conn_settings);
|
||||
ptr = strtok(cs, ";");
|
||||
while (ptr) {
|
||||
while (ptr)
|
||||
{
|
||||
result = SQLExecDirect(hstmt, ptr, SQL_NTS);
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
status = FALSE;
|
||||
@ -1272,10 +1377,12 @@ static char *func="CC_send_settings";
|
||||
}
|
||||
|
||||
/* Per Datasource settings */
|
||||
if (ci->conn_settings[0] != '\0') {
|
||||
if (ci->conn_settings[0] != '\0')
|
||||
{
|
||||
cs = strdup(ci->conn_settings);
|
||||
ptr = strtok(cs, ";");
|
||||
while (ptr) {
|
||||
while (ptr)
|
||||
{
|
||||
result = SQLExecDirect(hstmt, ptr, SQL_NTS);
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
status = FALSE;
|
||||
@ -1312,25 +1419,27 @@ static char *func = "CC_lookup_lo";
|
||||
has not transitioned to "connected" yet.
|
||||
*/
|
||||
result = SQLAllocStmt(self, &hstmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
return;
|
||||
}
|
||||
stmt = (StatementClass *) hstmt;
|
||||
|
||||
result = SQLExecDirect(hstmt, "select oid from pg_type where typname='" PG_TYPE_LO_NAME "'", SQL_NTS);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
|
||||
result = SQLFetch(hstmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
|
||||
result = SQLGetData(hstmt, 1, SQL_C_SLONG, &self->lobj_type, sizeof(self->lobj_type), NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
@ -1353,6 +1462,7 @@ CC_initialize_pg_version(ConnectionClass *self)
|
||||
self->pg_version_major = 6;
|
||||
self->pg_version_minor = 4;
|
||||
}
|
||||
|
||||
/* This function gets the version of PostgreSQL that we're connected to.
|
||||
This is used to return the correct info in SQLGetInfo
|
||||
DJP - 25-1-2001
|
||||
@ -1364,7 +1474,8 @@ HSTMT hstmt;
|
||||
StatementClass *stmt;
|
||||
RETCODE result;
|
||||
char szVersion[32];
|
||||
int major, minor;
|
||||
int major,
|
||||
minor;
|
||||
static char *func = "CC_lookup_pg_version";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
@ -1373,26 +1484,28 @@ static char *func = "CC_lookup_pg_version";
|
||||
has not transitioned to "connected" yet.
|
||||
*/
|
||||
result = SQLAllocStmt(self, &hstmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
return;
|
||||
}
|
||||
stmt = (StatementClass *) hstmt;
|
||||
|
||||
/* get the server's version if possible */
|
||||
result = SQLExecDirect(hstmt, "select version()", SQL_NTS);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
|
||||
result = SQLFetch(hstmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
|
||||
result = SQLGetData(hstmt, 1, SQL_C_CHAR, self->pg_version, MAX_INFO_STRING, NULL);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
SQLFreeStmt(hstmt, SQL_DROP);
|
||||
return;
|
||||
}
|
||||
@ -1400,7 +1513,8 @@ static char *func = "CC_lookup_pg_version";
|
||||
/* Extract the Major and Minor numbers from the string. */
|
||||
/* This assumes the string starts 'Postgresql X.X' */
|
||||
strcpy(szVersion, "0.0");
|
||||
if (sscanf(self->pg_version, "%*s %d.%d", &major, &minor) >= 2) {
|
||||
if (sscanf(self->pg_version, "%*s %d.%d", &major, &minor) >= 2)
|
||||
{
|
||||
sprintf(szVersion, "%d.%d", major, minor);
|
||||
self->pg_version_major = major;
|
||||
self->pg_version_minor = minor;
|
||||
@ -1422,7 +1536,8 @@ CC_log_error(char *func, char *desc, ConnectionClass *self)
|
||||
#define nullcheck(a) (a ? a : "(NULL)")
|
||||
#endif
|
||||
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
qlog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
|
||||
mylog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
|
||||
qlog(" ------------------------------------------------------------\n");
|
||||
@ -1430,8 +1545,10 @@ CC_log_error(char *func, char *desc, ConnectionClass *self)
|
||||
qlog(" sock=%u, stmts=%u, lobj_type=%d\n", self->sock, self->stmts, self->lobj_type);
|
||||
|
||||
qlog(" ---------------- Socket Info -------------------------------\n");
|
||||
if (self->sock) {
|
||||
if (self->sock)
|
||||
{
|
||||
SocketClass *sock = self->sock;
|
||||
|
||||
qlog(" socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n", sock->socket, sock->reverse, sock->errornumber, nullcheck(sock->errormsg));
|
||||
qlog(" buffer_in=%u, buffer_out=%u\n", sock->buffer_in, sock->buffer_out);
|
||||
qlog(" buffer_filled_in=%d, buffer_filled_out=%d, buffer_read_in=%d\n", sock->buffer_filled_in, sock->buffer_filled_out, sock->buffer_read_in);
|
||||
@ -1441,4 +1558,3 @@ CC_log_error(char *func, char *desc, ConnectionClass *self)
|
||||
qlog("INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
|
||||
#undef PRN_NULLCHECK
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
CONN_NOT_CONNECTED, /* Connection has not been established */
|
||||
CONN_CONNECTED, /* Connection is up and has been established */
|
||||
CONN_CONNECTED, /* Connection is up and has been
|
||||
* established */
|
||||
CONN_DOWN, /* Connection is broken */
|
||||
CONN_EXECUTING /* the connection is currently executing a statement */
|
||||
CONN_EXECUTING /* the connection is currently executing a
|
||||
* statement */
|
||||
} CONN_Status;
|
||||
|
||||
/* These errors have general sql error state */
|
||||
@ -122,7 +125,8 @@ typedef struct _StartupPacket
|
||||
/* Structure to hold all the connection attributes for a specific
|
||||
connection (used for both registry and file, DSN and DRIVER)
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
char dsn[MEDIUM_REGISTRY_LEN];
|
||||
char desc[MEDIUM_REGISTRY_LEN];
|
||||
char driver[MEDIUM_REGISTRY_LEN];
|
||||
@ -180,7 +184,8 @@ typedef struct {
|
||||
#define PG_VERSION_LT(conn, ver) (! PG_VERSION_GE(conn, ver))
|
||||
|
||||
/* This is used to store cached table information in the connection */
|
||||
struct col_info {
|
||||
struct col_info
|
||||
{
|
||||
QResultClass *result;
|
||||
char name[MAX_TABLE_LEN + 1];
|
||||
};
|
||||
@ -217,8 +222,10 @@ typedef BOOL (FAR WINAPI *DriverToDataSourceProc) (UDWORD,
|
||||
SWORD FAR *);
|
||||
|
||||
/******* The Connection handle ************/
|
||||
struct ConnectionClass_ {
|
||||
HENV henv; /* environment this connection was created on */
|
||||
struct ConnectionClass_
|
||||
{
|
||||
HENV henv; /* environment this connection was created
|
||||
* on */
|
||||
StatementOptions stmtOptions;
|
||||
char *errormsg;
|
||||
int errornumber;
|
||||
@ -234,9 +241,13 @@ struct ConnectionClass_ {
|
||||
HINSTANCE translation_handle;
|
||||
DataSourceToDriverProc DataSourceToDriver;
|
||||
DriverToDataSourceProc DriverToDataSource;
|
||||
char transact_status; /* Is a transaction is currently in progress */
|
||||
char errormsg_created; /* has an informative error msg been created? */
|
||||
char pg_version[MAX_INFO_STRING]; /* Version of PostgreSQL we're connected to - DJP 25-1-2001 */
|
||||
char transact_status;/* Is a transaction is currently in
|
||||
* progress */
|
||||
char errormsg_created; /* has an informative error msg
|
||||
* been created? */
|
||||
char pg_version[MAX_INFO_STRING]; /* Version of PostgreSQL
|
||||
* we're connected to -
|
||||
* DJP 25-1-2001 */
|
||||
float pg_version_number;
|
||||
Int2 pg_version_major;
|
||||
Int2 pg_version_minor;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,8 @@
|
||||
#define COPY_GENERAL_ERROR 4
|
||||
#define COPY_NO_DATA_FOUND 5
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int m;
|
||||
int d;
|
||||
int y;
|
||||
|
@ -49,8 +49,13 @@ extern GLOBAL_VALUES globals;
|
||||
void
|
||||
SetDlgStuff(HWND hdlg, ConnInfo * ci)
|
||||
{
|
||||
/* If driver attribute NOT present, then set the datasource name and description */
|
||||
if (ci->driver[0] == '\0') {
|
||||
|
||||
/*
|
||||
* If driver attribute NOT present, then set the datasource name and
|
||||
* description
|
||||
*/
|
||||
if (ci->driver[0] == '\0')
|
||||
{
|
||||
SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);
|
||||
SetDlgItemText(hdlg, IDC_DESC, ci->desc);
|
||||
}
|
||||
@ -76,12 +81,14 @@ GetDlgStuff(HWND hdlg, ConnInfo *ci)
|
||||
|
||||
|
||||
|
||||
int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
int CALLBACK
|
||||
driver_optionsProc(HWND hdlg,
|
||||
WORD wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (wMsg) {
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
|
||||
CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
|
||||
@ -92,7 +99,8 @@ int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, globals.use_declarefetch);
|
||||
|
||||
/* Unknown (Default) Data Type sizes */
|
||||
switch(globals.unknown_sizes) {
|
||||
switch (globals.unknown_sizes)
|
||||
{
|
||||
case UNKNOWNS_AS_DONTKNOW:
|
||||
CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
|
||||
break;
|
||||
@ -125,7 +133,8 @@ int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||
{
|
||||
case IDOK:
|
||||
|
||||
globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
|
||||
@ -155,7 +164,8 @@ int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
|
||||
globals.fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
|
||||
globals.max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
|
||||
globals.max_longvarchar_size= GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE); /* allows for SQL_NO_TOTAL */
|
||||
globals.max_longvarchar_size = GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE); /* allows for
|
||||
* SQL_NO_TOTAL */
|
||||
|
||||
GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, sizeof(globals.extra_systable_prefixes));
|
||||
|
||||
@ -185,7 +195,8 @@ int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
|
||||
CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
|
||||
CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
|
||||
switch(DEFAULT_UNKNOWNSIZES) {
|
||||
switch (DEFAULT_UNKNOWNSIZES)
|
||||
{
|
||||
case UNKNOWNS_AS_DONTKNOW:
|
||||
CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
|
||||
break;
|
||||
@ -218,7 +229,8 @@ int CALLBACK driver_optionsProc(HWND hdlg,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int CALLBACK ds_optionsProc(HWND hdlg,
|
||||
int CALLBACK
|
||||
ds_optionsProc(HWND hdlg,
|
||||
WORD wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
@ -226,7 +238,8 @@ int CALLBACK ds_optionsProc(HWND hdlg,
|
||||
ConnInfo *ci;
|
||||
char buf[128];
|
||||
|
||||
switch (wMsg) {
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
ci = (ConnInfo *) lParam;
|
||||
SetWindowLong(hdlg, DWL_USER, lParam); /* save for OK */
|
||||
@ -234,7 +247,8 @@ char buf[128];
|
||||
/* Change window caption */
|
||||
if (ci->driver[0])
|
||||
SetWindowText(hdlg, "Advanced Options (Connection)");
|
||||
else {
|
||||
else
|
||||
{
|
||||
sprintf(buf, "Advanced Options (%s)", ci->dsn);
|
||||
SetWindowText(hdlg, buf);
|
||||
}
|
||||
@ -260,7 +274,8 @@ char buf[128];
|
||||
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||
{
|
||||
case DS_SHOWOIDCOLUMN:
|
||||
mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
|
||||
EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
|
||||
@ -376,7 +391,8 @@ copyAttributes(ConnInfo *ci, char *attribute, char *value)
|
||||
else if (stricmp(attribute, INI_SHOWSYSTEMTABLES) == 0)
|
||||
strcpy(ci->show_system_tables, value);
|
||||
|
||||
else if (stricmp(attribute, INI_CONNSETTINGS) == 0) {
|
||||
else if (stricmp(attribute, INI_CONNSETTINGS) == 0)
|
||||
{
|
||||
decode(value, ci->conn_settings);
|
||||
/* strcpy(ci->conn_settings, value); */
|
||||
}
|
||||
@ -419,7 +435,8 @@ char encoded_conn_settings[LARGE_REGISTRY_LEN];
|
||||
|
||||
/* If a driver keyword was present, then dont use a DSN and return. */
|
||||
/* If DSN is null and no driver, then use the default datasource. */
|
||||
if ( DSN[0] == '\0') {
|
||||
if (DSN[0] == '\0')
|
||||
{
|
||||
if (ci->driver[0] != '\0')
|
||||
return;
|
||||
else
|
||||
@ -427,7 +444,8 @@ char encoded_conn_settings[LARGE_REGISTRY_LEN];
|
||||
}
|
||||
|
||||
/* brute-force chop off trailing blanks... */
|
||||
while (*(DSN+strlen(DSN)-1) == ' ') *(DSN+strlen(DSN)-1) = '\0';
|
||||
while (*(DSN + strlen(DSN) - 1) == ' ')
|
||||
*(DSN + strlen(DSN) - 1) = '\0';
|
||||
|
||||
/* Proceed with getting info for the given DSN. */
|
||||
|
||||
@ -467,7 +485,8 @@ char encoded_conn_settings[LARGE_REGISTRY_LEN];
|
||||
if (ci->protocol[0] == '\0' || overwrite)
|
||||
SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
|
||||
|
||||
if ( ci->conn_settings[0] == '\0' || overwrite) {
|
||||
if (ci->conn_settings[0] == '\0' || overwrite)
|
||||
{
|
||||
SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_conn_settings, sizeof(encoded_conn_settings), ODBC_INI);
|
||||
decode(encoded_conn_settings, ci->conn_settings);
|
||||
}
|
||||
@ -584,7 +603,8 @@ char encoded_conn_settings[LARGE_REGISTRY_LEN];
|
||||
/* This function reads the ODBCINST.INI portion of
|
||||
the registry and gets any driver defaults.
|
||||
*/
|
||||
void getGlobalDefaults(char *section, char *filename, char override)
|
||||
void
|
||||
getGlobalDefaults(char *section, char *filename, char override)
|
||||
{
|
||||
char temp[256];
|
||||
|
||||
@ -592,7 +612,8 @@ char temp[256];
|
||||
/* Fetch Count is stored in driver section */
|
||||
SQLGetPrivateProfileString(section, INI_FETCH, "",
|
||||
temp, sizeof(temp), filename);
|
||||
if ( temp[0] ) {
|
||||
if (temp[0])
|
||||
{
|
||||
globals.fetch_max = atoi(temp);
|
||||
/* sanity check if using cursors */
|
||||
if (globals.fetch_max <= 0)
|
||||
@ -739,7 +760,11 @@ char temp[256];
|
||||
globals.bools_as_char = DEFAULT_BOOLSASCHAR;
|
||||
|
||||
/* Extra Systable prefixes */
|
||||
/* Use @@@ to distinguish between blank extra prefixes and no key entry */
|
||||
|
||||
/*
|
||||
* Use @@@ to distinguish between blank extra prefixes and no key
|
||||
* entry
|
||||
*/
|
||||
SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@",
|
||||
temp, sizeof(temp), filename);
|
||||
if (strcmp(temp, "@@@"))
|
||||
@ -751,9 +776,13 @@ char temp[256];
|
||||
|
||||
|
||||
/* Dont allow override of an override! */
|
||||
if ( ! override) {
|
||||
if (!override)
|
||||
{
|
||||
|
||||
/* ConnSettings is stored in the driver section and per datasource for override */
|
||||
/*
|
||||
* ConnSettings is stored in the driver section and per datasource
|
||||
* for override
|
||||
*/
|
||||
SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "",
|
||||
globals.conn_settings, sizeof(globals.conn_settings), filename);
|
||||
|
||||
@ -765,9 +794,10 @@ char temp[256];
|
||||
else
|
||||
globals.onlyread = DEFAULT_READONLY;
|
||||
|
||||
/* Default state for future DSN's protocol attribute
|
||||
This isn't a real driver option YET. This is more
|
||||
intended for customization from the install.
|
||||
/*
|
||||
* Default state for future DSN's protocol attribute This isn't a
|
||||
* real driver option YET. This is more intended for
|
||||
* customization from the install.
|
||||
*/
|
||||
SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
|
||||
temp, sizeof(temp), filename);
|
||||
@ -783,7 +813,8 @@ char temp[256];
|
||||
/* This function writes any global parameters (that can be manipulated)
|
||||
to the ODBCINST.INI portion of the registry
|
||||
*/
|
||||
void updateGlobals(void)
|
||||
void
|
||||
updateGlobals(void)
|
||||
{
|
||||
char tmp[128];
|
||||
|
||||
|
@ -44,10 +44,13 @@
|
||||
#endif /* WIN32 */
|
||||
|
||||
|
||||
#define INI_DSN DBMS_NAME /* Name of default Datasource in ini file (not used?) */
|
||||
#define INI_DSN DBMS_NAME /* Name of default Datasource in
|
||||
* ini file (not used?) */
|
||||
#define INI_KDESC "Description" /* Data source description */
|
||||
#define INI_SERVER "Servername" /* Name of Server running the Postgres service */
|
||||
#define INI_PORT "Port" /* Port on which the Postmaster is listening */
|
||||
#define INI_SERVER "Servername" /* Name of Server running the
|
||||
* Postgres service */
|
||||
#define INI_PORT "Port"/* Port on which the Postmaster is
|
||||
* listening */
|
||||
#define INI_DATABASE "Database" /* Database Name */
|
||||
#define INI_USER "Username" /* Default User Name */
|
||||
#define INI_PASSWORD "Password" /* Default Password */
|
||||
@ -55,17 +58,22 @@
|
||||
#define INI_FETCH "Fetch" /* Fetch Max Count */
|
||||
#define INI_SOCKET "Socket" /* Socket buffer size */
|
||||
#define INI_READONLY "ReadOnly" /* Database is read only */
|
||||
#define INI_COMMLOG "CommLog" /* Communication to backend logging */
|
||||
#define INI_COMMLOG "CommLog" /* Communication to backend
|
||||
* logging */
|
||||
#define INI_PROTOCOL "Protocol" /* What protocol (6.2) */
|
||||
#define INI_OPTIMIZER "Optimizer" /* Use backend genetic optimizer */
|
||||
#define INI_KSQO "Ksqo"/* Keyset query optimization */
|
||||
#define INI_CONNSETTINGS "ConnSettings" /* Anything to send to backend on successful connection */
|
||||
#define INI_CONNSETTINGS "ConnSettings" /* Anything to send to
|
||||
* backend on successful
|
||||
* connection */
|
||||
#define INI_UNIQUEINDEX "UniqueIndex" /* Recognize unique indexes */
|
||||
#define INI_UNKNOWNSIZES "UnknownSizes" /* How to handle unknown result set sizes */
|
||||
#define INI_UNKNOWNSIZES "UnknownSizes" /* How to handle unknown
|
||||
* result set sizes */
|
||||
|
||||
#define INI_CANCELASFREESTMT "CancelAsFreeStmt"
|
||||
|
||||
#define INI_USEDECLAREFETCH "UseDeclareFetch" /* Use Declare/Fetch cursors */
|
||||
#define INI_USEDECLAREFETCH "UseDeclareFetch" /* Use Declare/Fetch
|
||||
* cursors */
|
||||
|
||||
/* More ini stuff */
|
||||
#define INI_TEXTASLONGVARCHAR "TextAsLongVarchar"
|
||||
@ -90,7 +98,8 @@
|
||||
/* Connection Defaults */
|
||||
#define DEFAULT_PORT "5432"
|
||||
#define DEFAULT_READONLY 1
|
||||
#define DEFAULT_PROTOCOL "6.4" /* the latest protocol is the default */
|
||||
#define DEFAULT_PROTOCOL "6.4" /* the latest protocol is
|
||||
* the default */
|
||||
#define DEFAULT_USEDECLAREFETCH 0
|
||||
#define DEFAULT_TEXTASLONGVARCHAR 1
|
||||
#define DEFAULT_UNKNOWNSASLONGVARCHAR 0
|
||||
@ -129,6 +138,7 @@ int CALLBACK ds_optionsProc(HWND hdlg,
|
||||
WORD wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam);
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
void updateGlobals(void);
|
||||
|
@ -59,12 +59,14 @@ BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LP
|
||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo * ci);
|
||||
|
||||
extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
|
||||
|
||||
#endif
|
||||
|
||||
extern GLOBAL_VALUES globals;
|
||||
|
||||
|
||||
RETCODE SQL_API SQLDriverConnect(
|
||||
RETCODE SQL_API
|
||||
SQLDriverConnect(
|
||||
HDBC hdbc,
|
||||
HWND hwnd,
|
||||
UCHAR FAR * szConnStrIn,
|
||||
@ -77,8 +79,10 @@ RETCODE SQL_API SQLDriverConnect(
|
||||
static char *func = "SQLDriverConnect";
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
ConnInfo *ci;
|
||||
|
||||
#ifdef WIN32
|
||||
RETCODE dialog_result;
|
||||
|
||||
#endif
|
||||
RETCODE result;
|
||||
char connStrIn[MAX_CONNECT_STRING];
|
||||
@ -90,7 +94,8 @@ int len = 0;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -120,13 +125,13 @@ dialog:
|
||||
#endif
|
||||
ci->focus_password = password_required;
|
||||
|
||||
switch(fDriverCompletion) {
|
||||
switch (fDriverCompletion)
|
||||
{
|
||||
#ifdef WIN32
|
||||
case SQL_DRIVER_PROMPT:
|
||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||
if(dialog_result != SQL_SUCCESS) {
|
||||
if (dialog_result != SQL_SUCCESS)
|
||||
return dialog_result;
|
||||
}
|
||||
break;
|
||||
|
||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||
@ -140,13 +145,13 @@ dialog:
|
||||
ci->server[0] == '\0' ||
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0' ||
|
||||
password_required) {
|
||||
password_required)
|
||||
{
|
||||
|
||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||
if(dialog_result != SQL_SUCCESS) {
|
||||
if (dialog_result != SQL_SUCCESS)
|
||||
return dialog_result;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#else
|
||||
case SQL_DRIVER_PROMPT:
|
||||
@ -157,14 +162,17 @@ dialog:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Password is not a required parameter unless authentication asks for it.
|
||||
For now, I think it's better to just let the application ask over and over until
|
||||
a password is entered (the user can always hit Cancel to get out)
|
||||
/*
|
||||
* Password is not a required parameter unless authentication asks for
|
||||
* it. For now, I think it's better to just let the application ask
|
||||
* over and over until a password is entered (the user can always hit
|
||||
* Cancel to get out)
|
||||
*/
|
||||
if (ci->username[0] == '\0' ||
|
||||
ci->server[0] == '\0' ||
|
||||
ci->database[0] == '\0' ||
|
||||
ci->port[0] == '\0') {
|
||||
ci->port[0] == '\0')
|
||||
{
|
||||
/* (password_required && ci->password[0] == '\0')) */
|
||||
|
||||
return SQL_NO_DATA_FOUND;
|
||||
@ -173,12 +181,16 @@ dialog:
|
||||
|
||||
/* do the actual connect */
|
||||
retval = CC_connect(conn, password_required);
|
||||
if (retval < 0) { /* need a password */
|
||||
if (fDriverCompletion == SQL_DRIVER_NOPROMPT) {
|
||||
if (retval < 0)
|
||||
{ /* need a password */
|
||||
if (fDriverCompletion == SQL_DRIVER_NOPROMPT)
|
||||
{
|
||||
CC_log_error(func, "Need password but Driver_NoPrompt", conn);
|
||||
return SQL_ERROR; /* need a password but not allowed to prompt so error */
|
||||
return SQL_ERROR; /* need a password but not allowed to
|
||||
* prompt so error */
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
#ifdef WIN32
|
||||
password_required = TRUE;
|
||||
goto dialog;
|
||||
@ -187,7 +199,8 @@ dialog:
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (retval == 0) {
|
||||
else if (retval == 0)
|
||||
{
|
||||
/* error msg filled in above */
|
||||
CC_log_error(func, "Error from CC_Connect", conn);
|
||||
return SQL_ERROR;
|
||||
@ -201,18 +214,22 @@ dialog:
|
||||
makeConnectString(connStrOut, ci);
|
||||
len = strlen(connStrOut);
|
||||
|
||||
if(szConnStrOut) {
|
||||
if (szConnStrOut)
|
||||
{
|
||||
|
||||
/* Return the completed string to the caller. The correct method is to
|
||||
only construct the connect string if a dialog was put up, otherwise,
|
||||
it should just copy the connection input string to the output.
|
||||
However, it seems ok to just always construct an output string. There
|
||||
are possible bad side effects on working applications (Access) by
|
||||
implementing the correct behavior, anyway.
|
||||
/*
|
||||
* Return the completed string to the caller. The correct method
|
||||
* is to only construct the connect string if a dialog was put up,
|
||||
* otherwise, it should just copy the connection input string to
|
||||
* the output. However, it seems ok to just always construct an
|
||||
* output string. There are possible bad side effects on working
|
||||
* applications (Access) by implementing the correct behavior,
|
||||
* anyway.
|
||||
*/
|
||||
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
|
||||
|
||||
if (len >= cbConnStrOutMax) {
|
||||
if (len >= cbConnStrOutMax)
|
||||
{
|
||||
result = SQL_SUCCESS_WITH_INFO;
|
||||
conn->errornumber = CONN_TRUNCATED;
|
||||
conn->errormsg = "The buffer was too small for the result.";
|
||||
@ -231,27 +248,29 @@ dialog:
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci)
|
||||
RETCODE
|
||||
dconn_DoDialog(HWND hwnd, ConnInfo * ci)
|
||||
{
|
||||
int dialog_result;
|
||||
|
||||
mylog("dconn_DoDialog: ci = %u\n", ci);
|
||||
|
||||
if(hwnd) {
|
||||
if (hwnd)
|
||||
{
|
||||
dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
|
||||
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
|
||||
if(!dialog_result || (dialog_result == -1)) {
|
||||
if (!dialog_result || (dialog_result == -1))
|
||||
return SQL_NO_DATA_FOUND;
|
||||
} else {
|
||||
else
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
BOOL FAR PASCAL dconn_FDriverConnectProc(
|
||||
BOOL FAR PASCAL
|
||||
dconn_FDriverConnectProc(
|
||||
HWND hdlg,
|
||||
UINT wMsg,
|
||||
WPARAM wParam,
|
||||
@ -259,7 +278,8 @@ BOOL FAR PASCAL dconn_FDriverConnectProc(
|
||||
{
|
||||
ConnInfo *ci;
|
||||
|
||||
switch (wMsg) {
|
||||
switch (wMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
ci = (ConnInfo *) lParam;
|
||||
|
||||
@ -274,7 +294,8 @@ ConnInfo *ci;
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
|
||||
|
||||
SetWindowLong(hdlg, DWL_USER, lParam);/* Save the ConnInfo for the "OK" */
|
||||
SetWindowLong(hdlg, DWL_USER, lParam); /* Save the ConnInfo for
|
||||
* the "OK" */
|
||||
|
||||
SetDlgStuff(hdlg, ci);
|
||||
|
||||
@ -293,7 +314,8 @@ ConnInfo *ci;
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||
{
|
||||
case IDOK:
|
||||
|
||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||
@ -328,10 +350,14 @@ ConnInfo *ci;
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
|
||||
void
|
||||
dconn_get_connect_attributes(UCHAR FAR * connect_string, ConnInfo * ci)
|
||||
{
|
||||
char *our_connect_string;
|
||||
char *pair, *attribute, *value, *equals;
|
||||
char *pair,
|
||||
*attribute,
|
||||
*value,
|
||||
*equals;
|
||||
char *strtok_arg;
|
||||
|
||||
memset(ci, 0, sizeof(ConnInfo));
|
||||
@ -341,14 +367,13 @@ char *strtok_arg;
|
||||
|
||||
mylog("our_connect_string = '%s'\n", our_connect_string);
|
||||
|
||||
while(1) {
|
||||
while (1)
|
||||
{
|
||||
pair = strtok(strtok_arg, ";");
|
||||
if(strtok_arg) {
|
||||
if (strtok_arg)
|
||||
strtok_arg = 0;
|
||||
}
|
||||
if(!pair) {
|
||||
if (!pair)
|
||||
break;
|
||||
}
|
||||
|
||||
equals = strchr(pair, '=');
|
||||
if (!equals)
|
||||
@ -371,4 +396,3 @@ char *strtok_arg;
|
||||
|
||||
free(our_connect_string);
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,16 @@
|
||||
ConnectionClass *conns[MAX_CONNECTIONS];
|
||||
|
||||
|
||||
RETCODE SQL_API SQLAllocEnv(HENV FAR *phenv)
|
||||
RETCODE SQL_API
|
||||
SQLAllocEnv(HENV FAR * phenv)
|
||||
{
|
||||
static char *func = "SQLAllocEnv";
|
||||
|
||||
mylog("**** in SQLAllocEnv ** \n");
|
||||
|
||||
*phenv = (HENV) EN_Constructor();
|
||||
if ( ! *phenv) {
|
||||
if (!*phenv)
|
||||
{
|
||||
*phenv = SQL_NULL_HENV;
|
||||
EN_log_error(func, "Error allocating environment", NULL);
|
||||
return SQL_ERROR;
|
||||
@ -39,14 +41,16 @@ mylog("**** in SQLAllocEnv ** \n");
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
|
||||
RETCODE SQL_API SQLFreeEnv(HENV henv)
|
||||
RETCODE SQL_API
|
||||
SQLFreeEnv(HENV henv)
|
||||
{
|
||||
static char *func = "SQLFreeEnv";
|
||||
EnvironmentClass *env = (EnvironmentClass *) henv;
|
||||
|
||||
mylog("**** in SQLFreeEnv: env = %u ** \n", env);
|
||||
|
||||
if (env && EN_Destructor(env)) {
|
||||
if (env && EN_Destructor(env))
|
||||
{
|
||||
mylog(" ok\n");
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
@ -58,7 +62,8 @@ mylog("**** in SQLFreeEnv: env = %u ** \n", env);
|
||||
|
||||
/* Returns the next SQL error information. */
|
||||
|
||||
RETCODE SQL_API SQLError(
|
||||
RETCODE SQL_API
|
||||
SQLError(
|
||||
HENV henv,
|
||||
HDBC hdbc,
|
||||
HSTMT hstmt,
|
||||
@ -73,13 +78,16 @@ int status;
|
||||
|
||||
mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u\n", henv, hdbc, hstmt);
|
||||
|
||||
if (SQL_NULL_HSTMT != hstmt) {
|
||||
if (SQL_NULL_HSTMT != hstmt)
|
||||
{
|
||||
/* CC: return an error of a hstmt */
|
||||
StatementClass *stmt = (StatementClass *) hstmt;
|
||||
|
||||
if (SC_get_error(stmt, &status, &msg)) {
|
||||
if (SC_get_error(stmt, &status, &msg))
|
||||
{
|
||||
mylog("SC_get_error: status = %d, msg = #%s#\n", status, msg);
|
||||
if (NULL == msg) {
|
||||
if (NULL == msg)
|
||||
{
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
if (NULL != pcbErrorMsg)
|
||||
@ -100,7 +108,8 @@ int status;
|
||||
|
||||
if (NULL != szSqlState)
|
||||
|
||||
switch (status) {
|
||||
switch (status)
|
||||
{
|
||||
/* now determine the SQLSTATE to be returned */
|
||||
case STMT_TRUNCATED:
|
||||
strcpy(szSqlState, "01004");
|
||||
@ -152,7 +161,8 @@ int status;
|
||||
break;
|
||||
|
||||
case STMT_NOT_IMPLEMENTED_ERROR:
|
||||
strcpy(szSqlState, "S1C00"); /* == 'driver not capable' */
|
||||
strcpy(szSqlState, "S1C00"); /* == 'driver not
|
||||
* capable' */
|
||||
break;
|
||||
case STMT_OPTION_OUT_OF_RANGE_ERROR:
|
||||
strcpy(szSqlState, "S1092");
|
||||
@ -203,7 +213,9 @@ int status;
|
||||
|
||||
mylog(" szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
if (NULL != pcbErrorMsg)
|
||||
@ -216,13 +228,17 @@ int status;
|
||||
}
|
||||
return SQL_SUCCESS;
|
||||
|
||||
} else if (SQL_NULL_HDBC != hdbc) {
|
||||
}
|
||||
else if (SQL_NULL_HDBC != hdbc)
|
||||
{
|
||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
|
||||
mylog("calling CC_get_error\n");
|
||||
if (CC_get_error(conn, &status, &msg)) {
|
||||
if (CC_get_error(conn, &status, &msg))
|
||||
{
|
||||
mylog("CC_get_error: status = %d, msg = #%s#\n", status, msg);
|
||||
if (NULL == msg) {
|
||||
if (NULL == msg)
|
||||
{
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
if (NULL != pcbErrorMsg)
|
||||
@ -241,7 +257,8 @@ int status;
|
||||
*pfNativeError = status;
|
||||
|
||||
if (NULL != szSqlState)
|
||||
switch(status) {
|
||||
switch (status)
|
||||
{
|
||||
case STMT_OPTION_VALUE_CHANGED:
|
||||
case CONN_OPTION_VALUE_CHANGED:
|
||||
strcpy(szSqlState, "01S02");
|
||||
@ -280,7 +297,11 @@ int status;
|
||||
break;
|
||||
case CONN_TRANSACT_IN_PROGRES:
|
||||
strcpy(szSqlState, "S1010");
|
||||
/* when the user tries to switch commit mode in a transaction */
|
||||
|
||||
/*
|
||||
* when the user tries to switch commit mode in a
|
||||
* transaction
|
||||
*/
|
||||
/* -> function sequence error */
|
||||
break;
|
||||
case CONN_NO_MEMORY_ERROR:
|
||||
@ -302,7 +323,9 @@ int status;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
mylog("CC_Get_error returned nothing.\n");
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
@ -315,11 +338,16 @@ int status;
|
||||
}
|
||||
return SQL_SUCCESS;
|
||||
|
||||
} else if (SQL_NULL_HENV != henv) {
|
||||
}
|
||||
else if (SQL_NULL_HENV != henv)
|
||||
{
|
||||
EnvironmentClass *env = (EnvironmentClass *) henv;
|
||||
if(EN_get_error(env, &status, &msg)) {
|
||||
|
||||
if (EN_get_error(env, &status, &msg))
|
||||
{
|
||||
mylog("EN_get_error: status = %d, msg = #%s#\n", status, msg);
|
||||
if (NULL == msg) {
|
||||
if (NULL == msg)
|
||||
{
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
if (NULL != pcbErrorMsg)
|
||||
@ -337,8 +365,10 @@ int status;
|
||||
if (NULL != pfNativeError)
|
||||
*pfNativeError = status;
|
||||
|
||||
if(szSqlState) {
|
||||
switch(status) {
|
||||
if (szSqlState)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case ENV_ALLOC_ERROR:
|
||||
/* memory allocation failure */
|
||||
strcpy(szSqlState, "S1001");
|
||||
@ -349,7 +379,9 @@ int status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NULL != szSqlState)
|
||||
strcpy(szSqlState, "00000");
|
||||
if (NULL != pcbErrorMsg)
|
||||
@ -387,7 +419,8 @@ EnvironmentClass
|
||||
EnvironmentClass *rv;
|
||||
|
||||
rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
|
||||
if( rv) {
|
||||
if (rv)
|
||||
{
|
||||
rv->errormsg = 0;
|
||||
rv->errornumber = 0;
|
||||
}
|
||||
@ -408,7 +441,8 @@ char rv = 1;
|
||||
/* the source--they should not be freed */
|
||||
|
||||
/* Free any connections belonging to this environment */
|
||||
for (lf = 0; lf < MAX_CONNECTIONS; lf++) {
|
||||
for (lf = 0; lf < MAX_CONNECTIONS; lf++)
|
||||
{
|
||||
if (conns[lf] && conns[lf]->henv == self)
|
||||
rv = rv && CC_Destructor(conns[lf]);
|
||||
}
|
||||
@ -420,15 +454,16 @@ char rv = 1;
|
||||
char
|
||||
EN_get_error(EnvironmentClass * self, int *number, char **message)
|
||||
{
|
||||
if(self && self->errormsg && self->errornumber) {
|
||||
if (self && self->errormsg && self->errornumber)
|
||||
{
|
||||
*message = self->errormsg;
|
||||
*number = self->errornumber;
|
||||
self->errormsg = 0;
|
||||
self->errornumber = 0;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
char
|
||||
@ -438,8 +473,10 @@ int i;
|
||||
|
||||
mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
|
||||
|
||||
for (i = 0; i < MAX_CONNECTIONS; i++) {
|
||||
if ( ! conns[i]) {
|
||||
for (i = 0; i < MAX_CONNECTIONS; i++)
|
||||
{
|
||||
if (!conns[i])
|
||||
{
|
||||
conn->henv = self;
|
||||
conns[i] = conn;
|
||||
|
||||
@ -458,7 +495,8 @@ EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_CONNECTIONS; i++)
|
||||
if (conns[i] == conn && conns[i]->status != CONN_EXECUTING) {
|
||||
if (conns[i] == conn && conns[i]->status != CONN_EXECUTING)
|
||||
{
|
||||
conns[i] = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
@ -469,9 +507,8 @@ int i;
|
||||
void
|
||||
EN_log_error(char *func, char *desc, EnvironmentClass * self)
|
||||
{
|
||||
if (self) {
|
||||
if (self)
|
||||
qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg);
|
||||
}
|
||||
else
|
||||
qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@
|
||||
#define ENV_ALLOC_ERROR 1
|
||||
|
||||
/********** Environment Handle *************/
|
||||
struct EnvironmentClass_ {
|
||||
struct EnvironmentClass_
|
||||
{
|
||||
char *errormsg;
|
||||
int errornumber;
|
||||
};
|
||||
|
@ -39,7 +39,8 @@ extern GLOBAL_VALUES globals;
|
||||
|
||||
|
||||
/* Perform a Prepare on the SQL statement */
|
||||
RETCODE SQL_API SQLPrepare(HSTMT hstmt,
|
||||
RETCODE SQL_API
|
||||
SQLPrepare(HSTMT hstmt,
|
||||
UCHAR FAR * szSqlStr,
|
||||
SDWORD cbSqlStr)
|
||||
{
|
||||
@ -48,24 +49,30 @@ StatementClass *self = (StatementClass *) hstmt;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! self) {
|
||||
if (!self)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* According to the ODBC specs it is valid to call SQLPrepare mulitple times.
|
||||
In that case, the bound SQL statement is replaced by the new one
|
||||
/*
|
||||
* According to the ODBC specs it is valid to call SQLPrepare mulitple
|
||||
* times. In that case, the bound SQL statement is replaced by the new
|
||||
* one
|
||||
*/
|
||||
|
||||
switch(self->status) {
|
||||
switch (self->status)
|
||||
{
|
||||
case STMT_PREMATURE:
|
||||
mylog("**** SQLPrepare: STMT_PREMATURE, recycle\n");
|
||||
SC_recycle_statement(self); /* recycle the statement, but do not remove parameter bindings */
|
||||
SC_recycle_statement(self); /* recycle the statement, but do
|
||||
* not remove parameter bindings */
|
||||
break;
|
||||
|
||||
case STMT_FINISHED:
|
||||
mylog("**** SQLPrepare: STMT_FINISHED, recycle\n");
|
||||
SC_recycle_statement(self); /* recycle the statement, but do not remove parameter bindings */
|
||||
SC_recycle_statement(self); /* recycle the statement, but do
|
||||
* not remove parameter bindings */
|
||||
break;
|
||||
|
||||
case STMT_ALLOCATED:
|
||||
@ -97,7 +104,8 @@ StatementClass *self = (StatementClass *) hstmt;
|
||||
free(self->statement);
|
||||
|
||||
self->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
||||
if ( ! self->statement) {
|
||||
if (!self->statement)
|
||||
{
|
||||
self->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
self->errormsg = "No memory available to store statement";
|
||||
SC_log_error(func, "", self);
|
||||
@ -108,7 +116,8 @@ StatementClass *self = (StatementClass *) hstmt;
|
||||
self->statement_type = statement_type(self->statement);
|
||||
|
||||
/* Check if connection is onlyread (only selects are allowed) */
|
||||
if ( CC_is_onlyread(self->hdbc) && STMT_UPDATE(self)) {
|
||||
if (CC_is_onlyread(self->hdbc) && STMT_UPDATE(self))
|
||||
{
|
||||
self->errornumber = STMT_EXEC_ERROR;
|
||||
self->errormsg = "Connection is readonly, only select statements are allowed.";
|
||||
SC_log_error(func, "", self);
|
||||
@ -124,7 +133,8 @@ StatementClass *self = (StatementClass *) hstmt;
|
||||
|
||||
/* Performs the equivalent of SQLPrepare, followed by SQLExecute. */
|
||||
|
||||
RETCODE SQL_API SQLExecDirect(
|
||||
RETCODE SQL_API
|
||||
SQLExecDirect(
|
||||
HSTMT hstmt,
|
||||
UCHAR FAR * szSqlStr,
|
||||
SDWORD cbSqlStr)
|
||||
@ -135,7 +145,8 @@ static char *func = "SQLExecDirect";
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -146,7 +157,8 @@ static char *func = "SQLExecDirect";
|
||||
/* keep a copy of the un-parametrized statement, in case */
|
||||
/* they try to execute this statement again */
|
||||
stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
||||
if ( ! stmt->statement) {
|
||||
if (!stmt->statement)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "No memory available to store statement";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -166,7 +178,8 @@ static char *func = "SQLExecDirect";
|
||||
stmt->statement_type = statement_type(stmt->statement);
|
||||
|
||||
/* Check if connection is onlyread (only selects are allowed) */
|
||||
if ( CC_is_onlyread(stmt->hdbc) && STMT_UPDATE(stmt)) {
|
||||
if (CC_is_onlyread(stmt->hdbc) && STMT_UPDATE(stmt))
|
||||
{
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
stmt->errormsg = "Connection is readonly, only select statements are allowed.";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -182,34 +195,41 @@ static char *func = "SQLExecDirect";
|
||||
}
|
||||
|
||||
/* Execute a prepared SQL statement */
|
||||
RETCODE SQL_API SQLExecute(
|
||||
RETCODE SQL_API
|
||||
SQLExecute(
|
||||
HSTMT hstmt)
|
||||
{
|
||||
static char *func = "SQLExecute";
|
||||
StatementClass *stmt = (StatementClass *) hstmt;
|
||||
ConnectionClass *conn;
|
||||
int i, retval;
|
||||
int i,
|
||||
retval;
|
||||
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
mylog("%s: NULL statement so return SQL_INVALID_HANDLE\n", func);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* If the statement is premature, it means we already executed
|
||||
it from an SQLPrepare/SQLDescribeCol type of scenario. So
|
||||
just return success.
|
||||
/*
|
||||
* If the statement is premature, it means we already executed it from
|
||||
* an SQLPrepare/SQLDescribeCol type of scenario. So just return
|
||||
* success.
|
||||
*/
|
||||
if ( stmt->prepare && stmt->status == STMT_PREMATURE) {
|
||||
if (stmt->prepare && stmt->status == STMT_PREMATURE)
|
||||
{
|
||||
stmt->status = STMT_FINISHED;
|
||||
if (stmt->errormsg == NULL) {
|
||||
if (stmt->errormsg == NULL)
|
||||
{
|
||||
mylog("%s: premature statement but return SQL_SUCCESS\n", func);
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SC_log_error(func, "", stmt);
|
||||
mylog("%s: premature statement so return SQL_ERROR\n", func);
|
||||
return SQL_ERROR;
|
||||
@ -221,7 +241,8 @@ int i, retval;
|
||||
SC_clear_error(stmt);
|
||||
|
||||
conn = SC_get_conn(stmt);
|
||||
if (conn->status == CONN_EXECUTING) {
|
||||
if (conn->status == CONN_EXECUTING)
|
||||
{
|
||||
stmt->errormsg = "Connection is already in use.";
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -229,7 +250,8 @@ int i, retval;
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
if ( ! stmt->statement) {
|
||||
if (!stmt->statement)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_STMTSTRING;
|
||||
stmt->errormsg = "This handle does not have a SQL statement stored in it";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -237,18 +259,21 @@ int i, retval;
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
/* If SQLExecute is being called again, recycle the statement.
|
||||
Note this should have been done by the application in a call
|
||||
to SQLFreeStmt(SQL_CLOSE) or SQLCancel.
|
||||
/*
|
||||
* If SQLExecute is being called again, recycle the statement. Note
|
||||
* this should have been done by the application in a call to
|
||||
* SQLFreeStmt(SQL_CLOSE) or SQLCancel.
|
||||
*/
|
||||
if (stmt->status == STMT_FINISHED) {
|
||||
if (stmt->status == STMT_FINISHED)
|
||||
{
|
||||
mylog("%s: recycling statement (should have been done by app)...\n", func);
|
||||
SC_recycle_statement(stmt);
|
||||
}
|
||||
|
||||
/* Check if the statement is in the correct state */
|
||||
if ((stmt->prepare && stmt->status != STMT_READY) ||
|
||||
(stmt->status != STMT_ALLOCATED && stmt->status != STMT_READY)) {
|
||||
(stmt->status != STMT_ALLOCATED && stmt->status != STMT_READY))
|
||||
{
|
||||
|
||||
stmt->errornumber = STMT_STATUS_ERROR;
|
||||
stmt->errormsg = "The handle does not point to a statement that is ready to be executed";
|
||||
@ -258,13 +283,16 @@ int i, retval;
|
||||
}
|
||||
|
||||
|
||||
/* The bound parameters could have possibly changed since the last execute
|
||||
of this statement? Therefore check for params and re-copy.
|
||||
/*
|
||||
* The bound parameters could have possibly changed since the last
|
||||
* execute of this statement? Therefore check for params and re-copy.
|
||||
*/
|
||||
stmt->data_at_exec = -1;
|
||||
for (i = 0; i < stmt->parameters_allocated; i++) {
|
||||
for (i = 0; i < stmt->parameters_allocated; i++)
|
||||
{
|
||||
/* Check for data at execution parameters */
|
||||
if ( stmt->parameters[i].data_at_exec == TRUE) {
|
||||
if (stmt->parameters[i].data_at_exec == TRUE)
|
||||
{
|
||||
if (stmt->data_at_exec < 0)
|
||||
stmt->data_at_exec = 1;
|
||||
else
|
||||
@ -272,7 +300,11 @@ int i, retval;
|
||||
}
|
||||
}
|
||||
/* If there are some data at execution parameters, return need data */
|
||||
/* SQLParamData and SQLPutData will be used to send params and execute the statement. */
|
||||
|
||||
/*
|
||||
* SQLParamData and SQLPutData will be used to send params and execute
|
||||
* the statement.
|
||||
*/
|
||||
if (stmt->data_at_exec > 0)
|
||||
return SQL_NEED_DATA;
|
||||
|
||||
@ -296,7 +328,8 @@ int i, retval;
|
||||
|
||||
|
||||
/* - - - - - - - - - */
|
||||
RETCODE SQL_API SQLTransact(
|
||||
RETCODE SQL_API
|
||||
SQLTransact(
|
||||
HENV henv,
|
||||
HDBC hdbc,
|
||||
UWORD fType)
|
||||
@ -305,21 +338,26 @@ static char *func = "SQLTransact";
|
||||
extern ConnectionClass *conns[];
|
||||
ConnectionClass *conn;
|
||||
QResultClass *res;
|
||||
char ok, *stmt_string;
|
||||
char ok,
|
||||
*stmt_string;
|
||||
int lf;
|
||||
|
||||
mylog("entering %s: hdbc=%u, henv=%u\n", func, hdbc, henv);
|
||||
|
||||
if (hdbc == SQL_NULL_HDBC && henv == SQL_NULL_HENV) {
|
||||
if (hdbc == SQL_NULL_HDBC && henv == SQL_NULL_HENV)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* If hdbc is null and henv is valid,
|
||||
it means transact all connections on that henv.
|
||||
/*
|
||||
* If hdbc is null and henv is valid, it means transact all
|
||||
* connections on that henv.
|
||||
*/
|
||||
if (hdbc == SQL_NULL_HDBC && henv != SQL_NULL_HENV) {
|
||||
for (lf=0; lf <MAX_CONNECTIONS; lf++) {
|
||||
if (hdbc == SQL_NULL_HDBC && henv != SQL_NULL_HENV)
|
||||
{
|
||||
for (lf = 0; lf < MAX_CONNECTIONS; lf++)
|
||||
{
|
||||
conn = conns[lf];
|
||||
|
||||
if (conn && conn->henv == henv)
|
||||
@ -332,13 +370,18 @@ int lf;
|
||||
|
||||
conn = (ConnectionClass *) hdbc;
|
||||
|
||||
if (fType == SQL_COMMIT) {
|
||||
if (fType == SQL_COMMIT)
|
||||
{
|
||||
stmt_string = "COMMIT";
|
||||
|
||||
} else if (fType == SQL_ROLLBACK) {
|
||||
}
|
||||
else if (fType == SQL_ROLLBACK)
|
||||
{
|
||||
stmt_string = "ROLLBACK";
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
conn->errornumber = CONN_INVALID_ARGUMENT_NO;
|
||||
conn->errormsg = "SQLTransact can only be called with SQL_COMMIT or SQL_ROLLBACK as parameter";
|
||||
CC_log_error(func, "", conn);
|
||||
@ -346,14 +389,16 @@ int lf;
|
||||
}
|
||||
|
||||
/* If manual commit and in transaction, then proceed. */
|
||||
if ( ! CC_is_in_autocommit(conn) && CC_is_in_trans(conn)) {
|
||||
if (!CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
|
||||
{
|
||||
|
||||
mylog("SQLTransact: sending on conn %d '%s'\n", conn, stmt_string);
|
||||
|
||||
res = CC_send_query(conn, stmt_string, NULL);
|
||||
CC_set_no_trans(conn);
|
||||
|
||||
if ( ! res) {
|
||||
if (!res)
|
||||
{
|
||||
/* error msg will be in the connection */
|
||||
CC_log_error(func, "", conn);
|
||||
return SQL_ERROR;
|
||||
@ -362,7 +407,8 @@ int lf;
|
||||
ok = QR_command_successful(res);
|
||||
QR_Destructor(res);
|
||||
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
CC_log_error(func, "", conn);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
@ -372,46 +418,55 @@ int lf;
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLCancel(
|
||||
RETCODE SQL_API
|
||||
SQLCancel(
|
||||
HSTMT hstmt) /* Statement to cancel. */
|
||||
{
|
||||
static char *func = "SQLCancel";
|
||||
StatementClass *stmt = (StatementClass *) hstmt;
|
||||
RETCODE result;
|
||||
|
||||
#ifdef WIN32
|
||||
HMODULE hmodule;
|
||||
FARPROC addr;
|
||||
|
||||
#endif
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
/* Check if this can handle canceling in the middle of a SQLPutData? */
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
/* Not in the middle of SQLParamData/SQLPutData so cancel like a close. */
|
||||
if (stmt->data_at_exec < 0) {
|
||||
/*
|
||||
* Not in the middle of SQLParamData/SQLPutData so cancel like a
|
||||
* close.
|
||||
*/
|
||||
if (stmt->data_at_exec < 0)
|
||||
{
|
||||
|
||||
|
||||
/* MAJOR HACK for Windows to reset the driver manager's cursor state:
|
||||
Because of what seems like a bug in the Odbc driver manager,
|
||||
SQLCancel does not act like a SQLFreeStmt(CLOSE), as many
|
||||
applications depend on this behavior. So, this
|
||||
brute force method calls the driver manager's function on
|
||||
behalf of the application.
|
||||
/*
|
||||
* MAJOR HACK for Windows to reset the driver manager's cursor
|
||||
* state: Because of what seems like a bug in the Odbc driver
|
||||
* manager, SQLCancel does not act like a SQLFreeStmt(CLOSE), as
|
||||
* many applications depend on this behavior. So, this brute
|
||||
* force method calls the driver manager's function on behalf of
|
||||
* the application.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
if (globals.cancel_as_freestmt) {
|
||||
if (globals.cancel_as_freestmt)
|
||||
{
|
||||
hmodule = GetModuleHandle("ODBC32");
|
||||
addr = GetProcAddress(hmodule, "SQLFreeStmt");
|
||||
result = addr((char *) (stmt->phstmt) - 96, SQL_CLOSE);
|
||||
}
|
||||
else {
|
||||
else
|
||||
result = SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||
}
|
||||
#else
|
||||
result = SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||
#endif
|
||||
@ -423,7 +478,11 @@ FARPROC addr;
|
||||
}
|
||||
|
||||
/* In the middle of SQLParamData/SQLPutData, so cancel that. */
|
||||
/* Note, any previous data-at-exec buffers will be freed in the recycle */
|
||||
|
||||
/*
|
||||
* Note, any previous data-at-exec buffers will be freed in the
|
||||
* recycle
|
||||
*/
|
||||
/* if they call SQLExecDirect or SQLExecute again. */
|
||||
|
||||
stmt->data_at_exec = -1;
|
||||
@ -439,7 +498,8 @@ FARPROC addr;
|
||||
/* Returns the SQL string as modified by the driver. */
|
||||
/* Currently, just copy the input string without modification */
|
||||
/* observing buffer limits and truncation. */
|
||||
RETCODE SQL_API SQLNativeSql(
|
||||
RETCODE SQL_API
|
||||
SQLNativeSql(
|
||||
HDBC hdbc,
|
||||
UCHAR FAR * szSqlStrIn,
|
||||
SDWORD cbSqlStrIn,
|
||||
@ -456,7 +516,8 @@ RETCODE result;
|
||||
mylog("%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
|
||||
|
||||
ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL);
|
||||
if ( ! ptr) {
|
||||
if (!ptr)
|
||||
{
|
||||
conn->errornumber = CONN_NO_MEMORY_ERROR;
|
||||
conn->errormsg = "No memory available to store native sql string";
|
||||
CC_log_error(func, "", conn);
|
||||
@ -466,10 +527,12 @@ RETCODE result;
|
||||
result = SQL_SUCCESS;
|
||||
len = strlen(ptr);
|
||||
|
||||
if (szSqlStr) {
|
||||
if (szSqlStr)
|
||||
{
|
||||
strncpy_null(szSqlStr, ptr, cbSqlStrMax);
|
||||
|
||||
if (len >= cbSqlStrMax) {
|
||||
if (len >= cbSqlStrMax)
|
||||
{
|
||||
result = SQL_SUCCESS_WITH_INFO;
|
||||
conn->errornumber = STMT_TRUNCATED;
|
||||
conn->errormsg = "The buffer was too small for the result.";
|
||||
@ -489,31 +552,36 @@ RETCODE result;
|
||||
/* Supplies parameter data at execution time. Used in conjuction with */
|
||||
/* SQLPutData. */
|
||||
|
||||
RETCODE SQL_API SQLParamData(
|
||||
RETCODE SQL_API
|
||||
SQLParamData(
|
||||
HSTMT hstmt,
|
||||
PTR FAR * prgbValue)
|
||||
{
|
||||
static char *func = "SQLParamData";
|
||||
StatementClass *stmt = (StatementClass *) hstmt;
|
||||
int i, retval;
|
||||
int i,
|
||||
retval;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
mylog("%s: data_at_exec=%d, params_alloc=%d\n", func, stmt->data_at_exec, stmt->parameters_allocated);
|
||||
|
||||
if (stmt->data_at_exec < 0) {
|
||||
if (stmt->data_at_exec < 0)
|
||||
{
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
stmt->errormsg = "No execution-time parameters for this statement";
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
if (stmt->data_at_exec > stmt->parameters_allocated) {
|
||||
if (stmt->data_at_exec > stmt->parameters_allocated)
|
||||
{
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
stmt->errormsg = "Too many execution-time parameters were present";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -521,16 +589,19 @@ int i, retval;
|
||||
}
|
||||
|
||||
/* close the large object */
|
||||
if ( stmt->lobj_fd >= 0) {
|
||||
if (stmt->lobj_fd >= 0)
|
||||
{
|
||||
lo_close(stmt->hdbc, stmt->lobj_fd);
|
||||
|
||||
/* commit transaction if needed */
|
||||
if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc)) {
|
||||
if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
|
||||
{
|
||||
QResultClass *res;
|
||||
char ok;
|
||||
|
||||
res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
|
||||
if (!res) {
|
||||
if (!res)
|
||||
{
|
||||
stmt->errormsg = "Could not commit (in-line) a transaction";
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -538,7 +609,8 @@ int i, retval;
|
||||
}
|
||||
ok = QR_command_successful(res);
|
||||
QR_Destructor(res);
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
stmt->errormsg = "Could not commit (in-line) a transaction";
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -553,7 +625,8 @@ int i, retval;
|
||||
|
||||
|
||||
/* Done, now copy the params and then execute the statement */
|
||||
if (stmt->data_at_exec == 0) {
|
||||
if (stmt->data_at_exec == 0)
|
||||
{
|
||||
retval = copy_statement_with_parameters(stmt);
|
||||
if (retval != SQL_SUCCESS)
|
||||
return retval;
|
||||
@ -563,14 +636,17 @@ int i, retval;
|
||||
return SC_execute(stmt);
|
||||
}
|
||||
|
||||
/* Set beginning param; if first time SQLParamData is called , start at 0.
|
||||
Otherwise, start at the last parameter + 1.
|
||||
/*
|
||||
* Set beginning param; if first time SQLParamData is called , start
|
||||
* at 0. Otherwise, start at the last parameter + 1.
|
||||
*/
|
||||
i = stmt->current_exec_param >= 0 ? stmt->current_exec_param + 1 : 0;
|
||||
|
||||
/* At least 1 data at execution parameter, so Fill in the token value */
|
||||
for ( ; i < stmt->parameters_allocated; i++) {
|
||||
if (stmt->parameters[i].data_at_exec == TRUE) {
|
||||
for (; i < stmt->parameters_allocated; i++)
|
||||
{
|
||||
if (stmt->parameters[i].data_at_exec == TRUE)
|
||||
{
|
||||
stmt->data_at_exec--;
|
||||
stmt->current_exec_param = i;
|
||||
stmt->put_data = FALSE;
|
||||
@ -587,26 +663,30 @@ int i, retval;
|
||||
/* Supplies parameter data at execution time. Used in conjunction with */
|
||||
/* SQLParamData. */
|
||||
|
||||
RETCODE SQL_API SQLPutData(
|
||||
RETCODE SQL_API
|
||||
SQLPutData(
|
||||
HSTMT hstmt,
|
||||
PTR rgbValue,
|
||||
SDWORD cbValue)
|
||||
{
|
||||
static char *func = "SQLPutData";
|
||||
StatementClass *stmt = (StatementClass *) hstmt;
|
||||
int old_pos, retval;
|
||||
int old_pos,
|
||||
retval;
|
||||
ParameterInfoClass *current_param;
|
||||
char *buffer;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
if (stmt->current_exec_param < 0) {
|
||||
if (stmt->current_exec_param < 0)
|
||||
{
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
stmt->errormsg = "Previous call was not SQLPutData or SQLParamData";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -615,14 +695,16 @@ char *buffer;
|
||||
|
||||
current_param = &(stmt->parameters[stmt->current_exec_param]);
|
||||
|
||||
if ( ! stmt->put_data) { /* first call */
|
||||
if (!stmt->put_data)
|
||||
{ /* first call */
|
||||
|
||||
mylog("SQLPutData: (1) cbValue = %d\n", cbValue);
|
||||
|
||||
stmt->put_data = TRUE;
|
||||
|
||||
current_param->EXEC_used = (SDWORD *) malloc(sizeof(SDWORD));
|
||||
if ( ! current_param->EXEC_used) {
|
||||
if (!current_param->EXEC_used)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Out of memory in SQLPutData (1)";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -636,15 +718,18 @@ char *buffer;
|
||||
|
||||
|
||||
/* Handle Long Var Binary with Large Objects */
|
||||
if ( current_param->SQLType == SQL_LONGVARBINARY) {
|
||||
if (current_param->SQLType == SQL_LONGVARBINARY)
|
||||
{
|
||||
|
||||
/* begin transaction if needed */
|
||||
if(!CC_is_in_trans(stmt->hdbc)) {
|
||||
if (!CC_is_in_trans(stmt->hdbc))
|
||||
{
|
||||
QResultClass *res;
|
||||
char ok;
|
||||
|
||||
res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
|
||||
if (!res) {
|
||||
if (!res)
|
||||
{
|
||||
stmt->errormsg = "Could not begin (in-line) a transaction";
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -652,7 +737,8 @@ char *buffer;
|
||||
}
|
||||
ok = QR_command_successful(res);
|
||||
QR_Destructor(res);
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
stmt->errormsg = "Could not begin (in-line) a transaction";
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -664,7 +750,8 @@ char *buffer;
|
||||
|
||||
/* store the oid */
|
||||
current_param->lobj_oid = lo_creat(stmt->hdbc, INV_READ | INV_WRITE);
|
||||
if (current_param->lobj_oid == 0) {
|
||||
if (current_param->lobj_oid == 0)
|
||||
{
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
stmt->errormsg = "Couldnt create large object.";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -677,7 +764,8 @@ char *buffer;
|
||||
|
||||
/* store the fd */
|
||||
stmt->lobj_fd = lo_open(stmt->hdbc, current_param->lobj_oid, INV_WRITE);
|
||||
if ( stmt->lobj_fd < 0) {
|
||||
if (stmt->lobj_fd < 0)
|
||||
{
|
||||
stmt->errornumber = STMT_EXEC_ERROR;
|
||||
stmt->errormsg = "Couldnt open large object for writing.";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -688,20 +776,26 @@ char *buffer;
|
||||
mylog("lo_write: cbValue=%d, wrote %d bytes\n", cbValue, retval);
|
||||
|
||||
}
|
||||
else { /* for handling text fields and small binaries */
|
||||
else
|
||||
{ /* for handling text fields and small
|
||||
* binaries */
|
||||
|
||||
if (cbValue == SQL_NTS) {
|
||||
if (cbValue == SQL_NTS)
|
||||
{
|
||||
current_param->EXEC_buffer = strdup(rgbValue);
|
||||
if ( ! current_param->EXEC_buffer) {
|
||||
if (!current_param->EXEC_buffer)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Out of memory in SQLPutData (2)";
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
current_param->EXEC_buffer = malloc(cbValue + 1);
|
||||
if ( ! current_param->EXEC_buffer) {
|
||||
if (!current_param->EXEC_buffer)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Out of memory in SQLPutData (2)";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -713,11 +807,13 @@ char *buffer;
|
||||
}
|
||||
}
|
||||
|
||||
else { /* calling SQLPutData more than once */
|
||||
else
|
||||
{ /* calling SQLPutData more than once */
|
||||
|
||||
mylog("SQLPutData: (>1) cbValue = %d\n", cbValue);
|
||||
|
||||
if (current_param->SQLType == SQL_LONGVARBINARY) {
|
||||
if (current_param->SQLType == SQL_LONGVARBINARY)
|
||||
{
|
||||
|
||||
/* the large object fd is in EXEC_buffer */
|
||||
retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
|
||||
@ -725,13 +821,17 @@ char *buffer;
|
||||
|
||||
*current_param->EXEC_used += cbValue;
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
buffer = current_param->EXEC_buffer;
|
||||
|
||||
if (cbValue == SQL_NTS) {
|
||||
if (cbValue == SQL_NTS)
|
||||
{
|
||||
buffer = realloc(buffer, strlen(buffer) + strlen(rgbValue) + 1);
|
||||
if ( ! buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Out of memory in SQLPutData (3)";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -747,7 +847,8 @@ char *buffer;
|
||||
current_param->EXEC_buffer = buffer;
|
||||
|
||||
}
|
||||
else if (cbValue > 0) {
|
||||
else if (cbValue > 0)
|
||||
{
|
||||
|
||||
old_pos = *current_param->EXEC_used;
|
||||
|
||||
@ -757,7 +858,8 @@ char *buffer;
|
||||
|
||||
/* dont lose the old pointer in case out of memory */
|
||||
buffer = realloc(current_param->EXEC_buffer, *current_param->EXEC_used + 1);
|
||||
if ( ! buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->errormsg = "Out of memory in SQLPutData (3)";
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -771,7 +873,8 @@ char *buffer;
|
||||
current_param->EXEC_buffer = buffer;
|
||||
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SC_log_error(func, "bad cbValue", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
@ -40,10 +40,14 @@
|
||||
DWORD
|
||||
GetPrivateProfileString(char *theSection, /* section name */
|
||||
char *theKey, /* search key name */
|
||||
char *theDefault, /* default value if not found */
|
||||
char *theReturnBuffer, /* return value stored here */
|
||||
size_t theReturnBufferLength, /* byte length of return buffer */
|
||||
char *theIniFileName) /* pathname of ini file to search */
|
||||
char *theDefault, /* default value if not
|
||||
* found */
|
||||
char *theReturnBuffer, /* return value stored
|
||||
* here */
|
||||
size_t theReturnBufferLength, /* byte length of return
|
||||
* buffer */
|
||||
char *theIniFileName) /* pathname of ini file to
|
||||
* search */
|
||||
{
|
||||
char buf[MAXPGPATH];
|
||||
char *ptr = 0;
|
||||
@ -74,10 +78,10 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
if (ptr == NULL || *ptr == '\0')
|
||||
ptr = "/home";
|
||||
|
||||
/* This doesn't make it so we find an ini file but allows normal
|
||||
* processing to continue further on down. The likelihood is that
|
||||
* the file won't be found and thus the default value will be
|
||||
* returned.
|
||||
/*
|
||||
* This doesn't make it so we find an ini file but allows normal
|
||||
* processing to continue further on down. The likelihood is that the
|
||||
* file won't be found and thus the default value will be returned.
|
||||
*/
|
||||
if (MAXPGPATH - 1 < strlen(ptr) + j)
|
||||
{
|
||||
@ -89,11 +93,13 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
|
||||
sprintf(buf, "%s/%s", ptr, theIniFileName);
|
||||
|
||||
/* This code makes it so that a file in the users home dir
|
||||
* overrides a the "default" file as passed in
|
||||
/*
|
||||
* This code makes it so that a file in the users home dir overrides a
|
||||
* the "default" file as passed in
|
||||
*/
|
||||
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
|
||||
if(!aFile) {
|
||||
if (!aFile)
|
||||
{
|
||||
sprintf(buf, "%s", theIniFileName);
|
||||
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
|
||||
}
|
||||
@ -104,9 +110,7 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
if (theReturnBufferLength == 0 || theReturnBuffer == NULL)
|
||||
{
|
||||
if (aFile)
|
||||
{
|
||||
fclose(aFile);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -128,9 +132,7 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
aLineLength = strlen(aLine);
|
||||
/* strip final '\n' */
|
||||
if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
||||
{
|
||||
aLine[aLineLength - 1] = '\0';
|
||||
}
|
||||
switch (*aLine)
|
||||
{
|
||||
case ' ': /* blank line */
|
||||
@ -144,17 +146,17 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
{
|
||||
aStart = aLine + 1;
|
||||
aString--;
|
||||
while (isspace((unsigned char) *aStart)) aStart++;
|
||||
while (isspace((unsigned char) *aString)) aString--;
|
||||
while (isspace((unsigned char) *aStart))
|
||||
aStart++;
|
||||
while (isspace((unsigned char) *aString))
|
||||
aString--;
|
||||
*(aString + 1) = '\0';
|
||||
|
||||
/* accept as matched if NULL key or exact match */
|
||||
|
||||
if (!theSection || !strcmp(aStart, theSection))
|
||||
{
|
||||
aSectionFound = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -174,31 +176,24 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
/* strip leading blanks in value field */
|
||||
|
||||
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
||||
{
|
||||
*aValue++ = '\0';
|
||||
}
|
||||
if (aValue >= aLine + sizeof(aLine))
|
||||
{
|
||||
aValue = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aValue = "";
|
||||
}
|
||||
|
||||
aStart = aLine;
|
||||
while (isspace((unsigned char) *aStart)) aStart++;
|
||||
while (isspace((unsigned char) *aStart))
|
||||
aStart++;
|
||||
|
||||
/* strip trailing blanks from key */
|
||||
|
||||
if (aString)
|
||||
{
|
||||
while (--aString >= aStart && *aString == ' ')
|
||||
{
|
||||
*aString = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* see if key is matched */
|
||||
|
||||
@ -277,11 +272,10 @@ GetPrivateProfileString(char *theSection, /* section name */
|
||||
}
|
||||
|
||||
if (aFile)
|
||||
{
|
||||
fclose(aFile);
|
||||
}
|
||||
|
||||
if(!aKeyFound) { /* key wasn't found return default */
|
||||
if (!aKeyFound)
|
||||
{ /* key wasn't found return default */
|
||||
++aLength; /* room for NULL char */
|
||||
aLength = theReturnBufferLength < aLength ?
|
||||
theReturnBufferLength : aLength;
|
||||
@ -296,7 +290,8 @@ DWORD
|
||||
WritePrivateProfileString(char *theSection, /* section name */
|
||||
char *theKey, /* write key name */
|
||||
char *theBuffer, /* input buffer */
|
||||
char *theIniFileName) /* pathname of ini file to write */
|
||||
char *theIniFileName) /* pathname of ini file to
|
||||
* write */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -310,7 +305,8 @@ DWORD
|
||||
WritePrivateProfileString(char *theSection, /* section name */
|
||||
char *theKey, /* write key name */
|
||||
char *theBuffer, /* input buffer */
|
||||
char *theIniFileName) /* pathname of ini file to write */
|
||||
char *theIniFileName) /* pathname of ini file to
|
||||
* write */
|
||||
{
|
||||
char buf[MAXPGPATH];
|
||||
char *ptr = 0;
|
||||
@ -328,10 +324,12 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
|
||||
/* If this isn't correct processing we'll change it later */
|
||||
if (theSection == NULL || theKey == NULL || theBuffer == NULL ||
|
||||
theIniFileName == NULL) return 0;
|
||||
theIniFileName == NULL)
|
||||
return 0;
|
||||
|
||||
aLength = strlen(theBuffer);
|
||||
if(aLength == 0) return 0;
|
||||
if (aLength == 0)
|
||||
return 0;
|
||||
|
||||
j = strlen(theIniFileName) + 1;
|
||||
ptr = (char *) getpwuid(getuid()); /* get user info */
|
||||
@ -366,10 +364,12 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
/* overrides a the "default" file as passed in */
|
||||
/* */
|
||||
aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
|
||||
if(!aFile) {
|
||||
if (!aFile)
|
||||
{
|
||||
sprintf(buf, "%s", theIniFileName);
|
||||
aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
|
||||
if(!aFile) return 0;
|
||||
if (!aFile)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -384,9 +384,7 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
aLineLength = strlen(aLine);
|
||||
/* strip final '\n' */
|
||||
if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
||||
{
|
||||
aLine[aLineLength - 1] = '\0';
|
||||
}
|
||||
switch (*aLine)
|
||||
{
|
||||
case ' ': /* blank line */
|
||||
@ -403,10 +401,8 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
/* accept as matched if key exact match */
|
||||
|
||||
if (!strcmp(aLine + 1, theSection))
|
||||
{
|
||||
aSectionFound = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@ -426,28 +422,20 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
/* strip leading blanks in value field */
|
||||
|
||||
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
||||
{
|
||||
*aValue++ = '\0';
|
||||
}
|
||||
if (aValue >= aLine + sizeof(aLine))
|
||||
{
|
||||
aValue = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aValue = "";
|
||||
}
|
||||
|
||||
/* strip trailing blanks from key */
|
||||
|
||||
if (aString)
|
||||
{
|
||||
while (--aString >= aLine && *aString == ' ')
|
||||
{
|
||||
*aString = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* see if key is matched */
|
||||
|
||||
@ -469,14 +457,14 @@ WritePrivateProfileString(char *theSection, /* section name */
|
||||
}
|
||||
}
|
||||
|
||||
if(!keyFound) { /* theKey wasn't in file so */
|
||||
if (!keyFound)
|
||||
{ /* theKey wasn't in file so */
|
||||
if (aFile)
|
||||
{
|
||||
fclose(aFile);
|
||||
}
|
||||
|
||||
return aReturnLength > 0 ? aReturnLength - 1 : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -13,25 +13,32 @@
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
DWORD
|
||||
GetPrivateProfileString(char *theSection, /* section name */
|
||||
char *theKey, /* search key name */
|
||||
char *theDefault, /* default value if not found */
|
||||
char *theReturnBuffer, /* return valuse stored here */
|
||||
size_t theBufferLength, /* byte length of return buffer */
|
||||
char *theIniFileName); /* pathname of ini file to search */
|
||||
char *theDefault, /* default value if not
|
||||
* found */
|
||||
char *theReturnBuffer, /* return valuse stored
|
||||
* here */
|
||||
size_t theBufferLength, /* byte length of return
|
||||
* buffer */
|
||||
char *theIniFileName); /* pathname of ini file
|
||||
* to search */
|
||||
|
||||
DWORD
|
||||
WritePrivateProfileString(char *theSection, /* section name */
|
||||
char *theKey, /* write key name */
|
||||
char *theBuffer, /* input buffer */
|
||||
char *theIniFileName); /* pathname of ini file to write */
|
||||
char *theIniFileName); /* pathname of ini file
|
||||
* to write */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -233,5 +233,6 @@ RETCODE SQL_API SQLSetParam (HSTMT hstmt,
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -362,33 +362,39 @@ typedef long long int ODBCINT64;
|
||||
typedef unsigned ODBCINT64 SQLUBIGINT;
|
||||
typedef ODBCINT64 SQLBIGINT;
|
||||
|
||||
#else /* Used even on platforms with 64 bit ints but not GCC */
|
||||
#else /* Used even on platforms with 64 bit ints
|
||||
* but not GCC */
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SQLUINTEGER dwLowWord;
|
||||
SQLUINTEGER dwHighWord;
|
||||
} SQLUBIGINT;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SQLUINTEGER dwLowWord;
|
||||
SQLINTEGER dwHighWord;
|
||||
} SQLBIGINT;
|
||||
|
||||
#endif /* GCC */
|
||||
|
||||
typedef struct tagDATE_STRUCT {
|
||||
typedef struct tagDATE_STRUCT
|
||||
{
|
||||
SQLSMALLINT year;
|
||||
SQLUSMALLINT month;
|
||||
SQLUSMALLINT day;
|
||||
} DATE_STRUCT, SQL_DATE_STRUCT;
|
||||
|
||||
typedef struct tagTIME_STRUCT {
|
||||
typedef struct tagTIME_STRUCT
|
||||
{
|
||||
SQLUSMALLINT hour;
|
||||
SQLUSMALLINT minute;
|
||||
SQLUSMALLINT second;
|
||||
} TIME_STRUCT, SQL_TIME_STRUCT;
|
||||
|
||||
typedef struct tagTIMESTAMP_STRUCT {
|
||||
typedef struct tagTIMESTAMP_STRUCT
|
||||
{
|
||||
SQLSMALLINT year;
|
||||
SQLUSMALLINT month;
|
||||
SQLUSMALLINT day;
|
||||
@ -411,14 +417,16 @@ typedef struct tagSQL_NUMERIC_STRUCT {
|
||||
|
||||
*/
|
||||
|
||||
typedef struct tagSQLGUID {
|
||||
typedef struct tagSQLGUID
|
||||
{
|
||||
DWORD Data1;
|
||||
WORD Data2;
|
||||
WORD Data3;
|
||||
BYTE Data4[8];
|
||||
} SQLGUID;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
SQL_IS_YEAR = 1,
|
||||
SQL_IS_MONTH = 2,
|
||||
SQL_IS_DAY = 3,
|
||||
@ -434,12 +442,14 @@ typedef enum {
|
||||
SQL_IS_MINUTE_TO_SECOND = 13
|
||||
} SQLINTERVAL;
|
||||
|
||||
typedef struct tagSQL_YEAR_MONTH {
|
||||
typedef struct tagSQL_YEAR_MONTH
|
||||
{
|
||||
SQLUINTEGER year;
|
||||
SQLUINTEGER month;
|
||||
} SQL_YEAR_MONTH_STRUCT;
|
||||
|
||||
typedef struct tagSQL_DAY_SECOND {
|
||||
typedef struct tagSQL_DAY_SECOND
|
||||
{
|
||||
SQLUINTEGER day;
|
||||
SQLUINTEGER hour;
|
||||
SQLUINTEGER minute;
|
||||
@ -447,10 +457,12 @@ typedef struct tagSQL_DAY_SECOND {
|
||||
SQLUINTEGER fraction;
|
||||
} SQL_DAY_SECOND_STRUCT;
|
||||
|
||||
typedef struct tagSQL_INTERVAL_STRUCT {
|
||||
typedef struct tagSQL_INTERVAL_STRUCT
|
||||
{
|
||||
SQLINTERVAL interval_type;
|
||||
SQLSMALLINT interval_sign;
|
||||
union {
|
||||
union
|
||||
{
|
||||
SQL_YEAR_MONTH_STRUCT year_month;
|
||||
SQL_DAY_SECOND_STRUCT day_second;
|
||||
} intval;
|
||||
@ -1318,7 +1330,8 @@ typedef struct tagSQL_INTERVAL_STRUCT {
|
||||
"VALUE,,VARCHAR,VARYING,VIEW,WHEN,WHENEVER,WHERE,WITH,WORK,YEAR"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
RETCODE SQL_API SQLSetConnectOption(HDBC, UWORD, UDWORD);
|
||||
@ -1534,6 +1547,7 @@ RETCODE SQL_API SQLSetScrollOptions (HSTMT hstmt,
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -19,7 +19,8 @@ Oid
|
||||
lo_creat(ConnectionClass * conn, int mode)
|
||||
{
|
||||
LO_ARG argv[1];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
argv[0].isint = 1;
|
||||
argv[0].len = 4;
|
||||
@ -62,7 +63,8 @@ int
|
||||
lo_close(ConnectionClass * conn, int fd)
|
||||
{
|
||||
LO_ARG argv[1];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
|
||||
argv[0].isint = 1;
|
||||
@ -104,7 +106,8 @@ int
|
||||
lo_write(ConnectionClass * conn, int fd, char *buf, int len)
|
||||
{
|
||||
LO_ARG argv[2];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
|
||||
if (len <= 0)
|
||||
@ -129,7 +132,8 @@ int
|
||||
lo_lseek(ConnectionClass * conn, int fd, int offset, int whence)
|
||||
{
|
||||
LO_ARG argv[3];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
|
||||
argv[0].isint = 1;
|
||||
@ -155,7 +159,8 @@ int
|
||||
lo_tell(ConnectionClass * conn, int fd)
|
||||
{
|
||||
LO_ARG argv[1];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
|
||||
argv[0].isint = 1;
|
||||
@ -173,7 +178,8 @@ int
|
||||
lo_unlink(ConnectionClass * conn, Oid lobjId)
|
||||
{
|
||||
LO_ARG argv[1];
|
||||
int retval, result_len;
|
||||
int retval,
|
||||
result_len;
|
||||
|
||||
|
||||
argv[0].isint = 1;
|
||||
@ -186,11 +192,3 @@ int retval, result_len;
|
||||
else
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,7 +13,8 @@
|
||||
|
||||
#include "psqlodbc.h"
|
||||
|
||||
struct lo_arg {
|
||||
struct lo_arg
|
||||
{
|
||||
int isint;
|
||||
int len;
|
||||
union
|
||||
@ -45,4 +46,3 @@ int lo_tell(ConnectionClass *conn, int fd);
|
||||
int lo_unlink(ConnectionClass * conn, Oid lobjId);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -24,7 +24,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <process.h> /* Byron: is this where Windows keeps def. of getpid ? */
|
||||
#include <process.h> /* Byron: is this where Windows keeps def.
|
||||
* of getpid ? */
|
||||
#endif
|
||||
|
||||
extern GLOBAL_VALUES globals;
|
||||
@ -34,8 +35,10 @@ void
|
||||
generate_filename(char *dirname, char *prefix, char *filename)
|
||||
{
|
||||
int pid = 0;
|
||||
|
||||
#ifndef WIN32
|
||||
struct passwd *ptr = 0;
|
||||
|
||||
ptr = getpwuid(getuid());
|
||||
#endif
|
||||
pid = getpid();
|
||||
@ -62,10 +65,12 @@ mylog(char * fmt, ...)
|
||||
char filebuf[80];
|
||||
FILE *LOGFP = globals.mylogFP;
|
||||
|
||||
if ( globals.debug) {
|
||||
if (globals.debug)
|
||||
{
|
||||
va_start(args, fmt);
|
||||
|
||||
if (! LOGFP) {
|
||||
if (!LOGFP)
|
||||
{
|
||||
generate_filename(MYLOGDIR, MYLOGFILE, filebuf);
|
||||
LOGFP = fopen(filebuf, PG_BINARY_W);
|
||||
globals.mylogFP = LOGFP;
|
||||
@ -78,6 +83,7 @@ mylog(char * fmt, ...)
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -90,10 +96,12 @@ qlog(char * fmt, ...)
|
||||
char filebuf[80];
|
||||
FILE *LOGFP = globals.qlogFP;
|
||||
|
||||
if ( globals.commlog) {
|
||||
if (globals.commlog)
|
||||
{
|
||||
va_start(args, fmt);
|
||||
|
||||
if (! LOGFP) {
|
||||
if (!LOGFP)
|
||||
{
|
||||
generate_filename(QLOGDIR, QLOGFILE, filebuf);
|
||||
LOGFP = fopen(filebuf, PG_BINARY_W);
|
||||
globals.qlogFP = LOGFP;
|
||||
@ -106,6 +114,7 @@ qlog(char * fmt, ...)
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Undefine these because windows.h will redefine and cause a warning */
|
||||
@ -135,7 +144,8 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
||||
if (dst_len <= 0)
|
||||
return STRCPY_FAIL;
|
||||
|
||||
if (src_len == SQL_NULL_DATA) {
|
||||
if (src_len == SQL_NULL_DATA)
|
||||
{
|
||||
dst[0] = '\0';
|
||||
return STRCPY_NULL;
|
||||
}
|
||||
@ -145,12 +155,15 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
||||
if (src_len <= 0)
|
||||
return STRCPY_FAIL;
|
||||
|
||||
else {
|
||||
if (src_len < dst_len) {
|
||||
else
|
||||
{
|
||||
if (src_len < dst_len)
|
||||
{
|
||||
memcpy(dst, src, src_len);
|
||||
dst[src_len] = '\0';
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
memcpy(dst, src, dst_len - 1);
|
||||
dst[dst_len - 1] = '\0'; /* truncated */
|
||||
return STRCPY_TRUNCATED;
|
||||
@ -164,29 +177,30 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
||||
/* the destination string if src has len characters or more. */
|
||||
/* instead, I want it to copy up to len-1 characters and always */
|
||||
/* terminate the destination string. */
|
||||
char *strncpy_null(char *dst, const char *src, int len)
|
||||
char *
|
||||
strncpy_null(char *dst, const char *src, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
if (NULL != dst) {
|
||||
if (NULL != dst)
|
||||
{
|
||||
|
||||
/* Just in case, check for special lengths */
|
||||
if (len == SQL_NULL_DATA) {
|
||||
if (len == SQL_NULL_DATA)
|
||||
{
|
||||
dst[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
else if (len == SQL_NTS)
|
||||
len = strlen(src) + 1;
|
||||
|
||||
for(i = 0; src[i] && i < len - 1; i++) {
|
||||
for (i = 0; src[i] && i < len - 1; i++)
|
||||
dst[i] = src[i];
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
if (len > 0)
|
||||
dst[i] = '\0';
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
@ -199,10 +213,12 @@ make_string(char *s, int len, char *buf)
|
||||
int length;
|
||||
char *str;
|
||||
|
||||
if(s && (len > 0 || (len == SQL_NTS && strlen(s) > 0))) {
|
||||
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0)))
|
||||
{
|
||||
length = (len > 0) ? len : strlen(s);
|
||||
|
||||
if (buf) {
|
||||
if (buf)
|
||||
{
|
||||
strncpy_null(buf, s, length + 1);
|
||||
return buf;
|
||||
}
|
||||
@ -226,7 +242,8 @@ char *
|
||||
my_strcat(char *buf, char *fmt, char *s, int len)
|
||||
{
|
||||
|
||||
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0))) {
|
||||
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0)))
|
||||
{
|
||||
int length = (len > 0) ? len : strlen(s);
|
||||
|
||||
int pos = strlen(buf);
|
||||
@ -237,24 +254,26 @@ my_strcat(char *buf, char *fmt, char *s, int len)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void remove_newlines(char *string)
|
||||
void
|
||||
remove_newlines(char *string)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i < strlen(string); i++) {
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if ((string[i] == '\n') ||
|
||||
(string[i] == '\r')) {
|
||||
(string[i] == '\r'))
|
||||
string[i] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
trim(char *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = strlen(s) - 1; i >= 0; i--) {
|
||||
for (i = strlen(s) - 1; i >= 0; i--)
|
||||
{
|
||||
if (s[i] == ' ')
|
||||
s[i] = '\0';
|
||||
else
|
||||
|
@ -46,6 +46,7 @@
|
||||
#define MYLOGDIR "c:"
|
||||
#endif
|
||||
extern void mylog(char *fmt,...);
|
||||
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#define mylog(args...) /* GNU convention for variable arguments */
|
||||
@ -62,6 +63,7 @@
|
||||
#define QLOGDIR "c:"
|
||||
#endif
|
||||
extern void qlog(char *fmt,...);
|
||||
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#define qlog(args...) /* GNU convention for variable arguments */
|
||||
|
@ -44,7 +44,8 @@ RETCODE set_statement_option(ConnectionClass *conn,
|
||||
|
||||
|
||||
|
||||
RETCODE set_statement_option(ConnectionClass *conn,
|
||||
RETCODE
|
||||
set_statement_option(ConnectionClass * conn,
|
||||
StatementClass * stmt,
|
||||
UWORD fOption,
|
||||
UDWORD vParam)
|
||||
@ -53,70 +54,91 @@ static char *func="set_statement_option";
|
||||
char changed = FALSE;
|
||||
|
||||
|
||||
switch(fOption) {
|
||||
switch (fOption)
|
||||
{
|
||||
case SQL_ASYNC_ENABLE: /* ignored */
|
||||
break;
|
||||
|
||||
case SQL_BIND_TYPE:
|
||||
/* now support multi-column and multi-row binding */
|
||||
if (conn) conn->stmtOptions.bind_size = vParam;
|
||||
if (stmt) stmt->options.bind_size = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.bind_size = vParam;
|
||||
if (stmt)
|
||||
stmt->options.bind_size = vParam;
|
||||
break;
|
||||
|
||||
case SQL_CONCURRENCY:
|
||||
/* positioned update isn't supported so cursor concurrency is read-only */
|
||||
|
||||
if (conn) conn->stmtOptions.scroll_concurrency = vParam;
|
||||
if (stmt) stmt->options.scroll_concurrency = vParam;
|
||||
/*
|
||||
* positioned update isn't supported so cursor concurrency is
|
||||
* read-only
|
||||
*/
|
||||
|
||||
if (conn)
|
||||
conn->stmtOptions.scroll_concurrency = vParam;
|
||||
if (stmt)
|
||||
stmt->options.scroll_concurrency = vParam;
|
||||
break;
|
||||
|
||||
/*
|
||||
if (globals.lie) {
|
||||
if (conn) conn->stmtOptions.scroll_concurrency = vParam;
|
||||
if (stmt) stmt->options.scroll_concurrency = vParam;
|
||||
}
|
||||
else {
|
||||
|
||||
if (conn) conn->stmtOptions.scroll_concurrency = SQL_CONCUR_READ_ONLY;
|
||||
if (stmt) stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
|
||||
|
||||
if (vParam != SQL_CONCUR_READ_ONLY)
|
||||
changed = TRUE;
|
||||
}
|
||||
break;
|
||||
* if (globals.lie) { if (conn)
|
||||
* conn->stmtOptions.scroll_concurrency = vParam; if (stmt)
|
||||
* stmt->options.scroll_concurrency = vParam; } else {
|
||||
*
|
||||
* if (conn) conn->stmtOptions.scroll_concurrency =
|
||||
* SQL_CONCUR_READ_ONLY; if (stmt)
|
||||
* stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
|
||||
*
|
||||
* if (vParam != SQL_CONCUR_READ_ONLY) changed = TRUE; } break;
|
||||
*/
|
||||
|
||||
case SQL_CURSOR_TYPE:
|
||||
/* if declare/fetch, then type can only be forward.
|
||||
otherwise, it can only be forward or static.
|
||||
|
||||
/*
|
||||
* if declare/fetch, then type can only be forward. otherwise,
|
||||
* it can only be forward or static.
|
||||
*/
|
||||
mylog("SetStmtOption(): SQL_CURSOR_TYPE = %d\n", vParam);
|
||||
|
||||
if (globals.lie) {
|
||||
if (globals.lie)
|
||||
{
|
||||
|
||||
if (conn) conn->stmtOptions.cursor_type = vParam;
|
||||
if (stmt) stmt->options.cursor_type = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.cursor_type = vParam;
|
||||
if (stmt)
|
||||
stmt->options.cursor_type = vParam;
|
||||
|
||||
}
|
||||
else {
|
||||
if (globals.use_declarefetch) {
|
||||
else
|
||||
{
|
||||
if (globals.use_declarefetch)
|
||||
{
|
||||
|
||||
if (conn) conn->stmtOptions.cursor_type = SQL_CURSOR_FORWARD_ONLY;
|
||||
if (stmt) stmt->options.cursor_type = SQL_CURSOR_FORWARD_ONLY;
|
||||
if (conn)
|
||||
conn->stmtOptions.cursor_type = SQL_CURSOR_FORWARD_ONLY;
|
||||
if (stmt)
|
||||
stmt->options.cursor_type = SQL_CURSOR_FORWARD_ONLY;
|
||||
|
||||
if (vParam != SQL_CURSOR_FORWARD_ONLY)
|
||||
changed = TRUE;
|
||||
}
|
||||
else {
|
||||
if (vParam == SQL_CURSOR_FORWARD_ONLY || vParam == SQL_CURSOR_STATIC) {
|
||||
else
|
||||
{
|
||||
if (vParam == SQL_CURSOR_FORWARD_ONLY || vParam == SQL_CURSOR_STATIC)
|
||||
{
|
||||
|
||||
if (conn) conn->stmtOptions.cursor_type = vParam; /* valid type */
|
||||
if (stmt) stmt->options.cursor_type = vParam; /* valid type */
|
||||
if (conn)
|
||||
conn->stmtOptions.cursor_type = vParam; /* valid type */
|
||||
if (stmt)
|
||||
stmt->options.cursor_type = vParam; /* valid type */
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
|
||||
if (conn) conn->stmtOptions.cursor_type = SQL_CURSOR_STATIC;
|
||||
if (stmt) stmt->options.cursor_type = SQL_CURSOR_STATIC;
|
||||
if (conn)
|
||||
conn->stmtOptions.cursor_type = SQL_CURSOR_STATIC;
|
||||
if (stmt)
|
||||
stmt->options.cursor_type = SQL_CURSOR_STATIC;
|
||||
|
||||
changed = TRUE;
|
||||
}
|
||||
@ -127,32 +149,34 @@ char changed = FALSE;
|
||||
case SQL_KEYSET_SIZE: /* ignored, but saved and returned */
|
||||
mylog("SetStmtOption(): SQL_KEYSET_SIZE, vParam = %d\n", vParam);
|
||||
|
||||
if (conn) conn->stmtOptions.keyset_size = vParam;
|
||||
if (stmt) stmt->options.keyset_size = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.keyset_size = vParam;
|
||||
if (stmt)
|
||||
stmt->options.keyset_size = vParam;
|
||||
|
||||
break;
|
||||
|
||||
/*
|
||||
if (globals.lie)
|
||||
stmt->keyset_size = vParam;
|
||||
else {
|
||||
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
stmt->errormsg = "Driver does not support keyset size option";
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
* if (globals.lie) stmt->keyset_size = vParam; else {
|
||||
* stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
* stmt->errormsg = "Driver does not support keyset size
|
||||
* option"; SC_log_error(func, "", stmt); return SQL_ERROR; }
|
||||
*/
|
||||
|
||||
case SQL_MAX_LENGTH: /* ignored, but saved */
|
||||
mylog("SetStmtOption(): SQL_MAX_LENGTH, vParam = %d\n", vParam);
|
||||
if (conn) conn->stmtOptions.maxLength = vParam;
|
||||
if (stmt) stmt->options.maxLength = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.maxLength = vParam;
|
||||
if (stmt)
|
||||
stmt->options.maxLength = vParam;
|
||||
break;
|
||||
|
||||
case SQL_MAX_ROWS: /* ignored, but saved */
|
||||
mylog("SetStmtOption(): SQL_MAX_ROWS, vParam = %d\n", vParam);
|
||||
if (conn) conn->stmtOptions.maxRows = vParam;
|
||||
if (stmt) stmt->options.maxRows = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.maxRows = vParam;
|
||||
if (stmt)
|
||||
stmt->options.maxRows = vParam;
|
||||
break;
|
||||
|
||||
case SQL_NOSCAN: /* ignored */
|
||||
@ -166,39 +190,47 @@ char changed = FALSE;
|
||||
|
||||
case SQL_RETRIEVE_DATA:/* ignored, but saved */
|
||||
mylog("SetStmtOption(): SQL_RETRIEVE_DATA, vParam = %d\n", vParam);
|
||||
if (conn) conn->stmtOptions.retrieve_data = vParam;
|
||||
if (stmt) stmt->options.retrieve_data = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.retrieve_data = vParam;
|
||||
if (stmt)
|
||||
stmt->options.retrieve_data = vParam;
|
||||
break;
|
||||
|
||||
case SQL_ROWSET_SIZE:
|
||||
mylog("SetStmtOption(): SQL_ROWSET_SIZE, vParam = %d\n", vParam);
|
||||
|
||||
|
||||
/* Save old rowset size for SQLExtendedFetch purposes
|
||||
If the rowset_size is being changed since the last call
|
||||
to fetch rows.
|
||||
/*
|
||||
* Save old rowset size for SQLExtendedFetch purposes If the
|
||||
* rowset_size is being changed since the last call to fetch
|
||||
* rows.
|
||||
*/
|
||||
|
||||
if (stmt && stmt->save_rowset_size <= 0 && stmt->last_fetch_count > 0)
|
||||
stmt->save_rowset_size = stmt->options.rowset_size;
|
||||
|
||||
if (vParam < 1) {
|
||||
if (vParam < 1)
|
||||
{
|
||||
vParam = 1;
|
||||
changed = TRUE;
|
||||
}
|
||||
|
||||
if (conn) conn->stmtOptions.rowset_size = vParam;
|
||||
if (stmt) stmt->options.rowset_size = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.rowset_size = vParam;
|
||||
if (stmt)
|
||||
stmt->options.rowset_size = vParam;
|
||||
|
||||
break;
|
||||
|
||||
case SQL_SIMULATE_CURSOR: /* NOT SUPPORTED */
|
||||
if (stmt) {
|
||||
if (stmt)
|
||||
{
|
||||
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
stmt->errormsg = "Simulated positioned update/delete not supported. Use the cursor library.";
|
||||
SC_log_error(func, "", stmt);
|
||||
}
|
||||
if (conn) {
|
||||
if (conn)
|
||||
{
|
||||
conn->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
conn->errormsg = "Simulated positioned update/delete not supported. Use the cursor library.";
|
||||
CC_log_error(func, "", conn);
|
||||
@ -207,21 +239,25 @@ char changed = FALSE;
|
||||
|
||||
case SQL_USE_BOOKMARKS:
|
||||
|
||||
if (stmt) stmt->options.use_bookmarks = vParam;
|
||||
if (conn) conn->stmtOptions.use_bookmarks = vParam;
|
||||
if (stmt)
|
||||
stmt->options.use_bookmarks = vParam;
|
||||
if (conn)
|
||||
conn->stmtOptions.use_bookmarks = vParam;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
char option[64];
|
||||
|
||||
if (stmt) {
|
||||
if (stmt)
|
||||
{
|
||||
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
stmt->errormsg = "Unknown statement option (Set)";
|
||||
sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
|
||||
SC_log_error(func, option, stmt);
|
||||
}
|
||||
if (conn) {
|
||||
if (conn)
|
||||
{
|
||||
conn->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
conn->errormsg = "Unknown statement option (Set)";
|
||||
sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
|
||||
@ -232,12 +268,15 @@ char changed = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (stmt) {
|
||||
if (changed)
|
||||
{
|
||||
if (stmt)
|
||||
{
|
||||
stmt->errormsg = "Requested value changed.";
|
||||
stmt->errornumber = STMT_OPTION_VALUE_CHANGED;
|
||||
}
|
||||
if (conn) {
|
||||
if (conn)
|
||||
{
|
||||
conn->errormsg = "Requested value changed.";
|
||||
conn->errornumber = STMT_OPTION_VALUE_CHANGED;
|
||||
}
|
||||
@ -250,7 +289,8 @@ char changed = FALSE;
|
||||
|
||||
|
||||
/* Implements only SQL_AUTOCOMMIT */
|
||||
RETCODE SQL_API SQLSetConnectOption(
|
||||
RETCODE SQL_API
|
||||
SQLSetConnectOption(
|
||||
HDBC hdbc,
|
||||
UWORD fOption,
|
||||
UDWORD vParam)
|
||||
@ -263,15 +303,19 @@ int i;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if ( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
switch (fOption) {
|
||||
/* Statement Options
|
||||
(apply to all stmts on the connection and become defaults for new stmts)
|
||||
switch (fOption)
|
||||
{
|
||||
|
||||
/*
|
||||
* Statement Options (apply to all stmts on the connection and
|
||||
* become defaults for new stmts)
|
||||
*/
|
||||
case SQL_ASYNC_ENABLE:
|
||||
case SQL_BIND_TYPE:
|
||||
@ -288,13 +332,16 @@ int i;
|
||||
case SQL_USE_BOOKMARKS:
|
||||
|
||||
/* Affect all current Statements */
|
||||
for (i = 0; i < conn->num_stmts; i++) {
|
||||
if ( conn->stmts[i]) {
|
||||
for (i = 0; i < conn->num_stmts; i++)
|
||||
{
|
||||
if (conn->stmts[i])
|
||||
set_statement_option(NULL, conn->stmts[i], fOption, vParam);
|
||||
}
|
||||
}
|
||||
|
||||
/* Become the default for all future statements on this connection */
|
||||
/*
|
||||
* Become the default for all future statements on this
|
||||
* connection
|
||||
*/
|
||||
retval = set_statement_option(conn, NULL, fOption, vParam);
|
||||
|
||||
if (retval == SQL_SUCCESS_WITH_INFO)
|
||||
@ -313,7 +360,8 @@ int i;
|
||||
|
||||
case SQL_AUTOCOMMIT:
|
||||
|
||||
if (CC_is_in_trans(conn)) {
|
||||
if (CC_is_in_trans(conn))
|
||||
{
|
||||
conn->errormsg = "Cannot switch commit mode while a transaction is in progress";
|
||||
conn->errornumber = CONN_TRANSACT_IN_PROGRES;
|
||||
CC_log_error(func, "", conn);
|
||||
@ -322,7 +370,8 @@ int i;
|
||||
|
||||
mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
|
||||
|
||||
switch(vParam) {
|
||||
switch (vParam)
|
||||
{
|
||||
case SQL_AUTOCOMMIT_OFF:
|
||||
CC_set_autocommit_off(conn);
|
||||
break;
|
||||
@ -367,6 +416,7 @@ int i;
|
||||
default:
|
||||
{
|
||||
char option[64];
|
||||
|
||||
conn->errormsg = "Unknown connect option (Set)";
|
||||
conn->errornumber = CONN_UNSUPPORTED_OPTION;
|
||||
sprintf(option, "fOption=%d, vParam=%ld", fOption, vParam);
|
||||
@ -376,7 +426,8 @@ int i;
|
||||
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (changed)
|
||||
{
|
||||
conn->errornumber = CONN_OPTION_VALUE_CHANGED;
|
||||
conn->errormsg = "Requested value changed.";
|
||||
return SQL_SUCCESS_WITH_INFO;
|
||||
@ -388,7 +439,8 @@ int i;
|
||||
/* - - - - - - - - - */
|
||||
|
||||
/* This function just can tell you whether you are in Autcommit mode or not */
|
||||
RETCODE SQL_API SQLGetConnectOption(
|
||||
RETCODE SQL_API
|
||||
SQLGetConnectOption(
|
||||
HDBC hdbc,
|
||||
UWORD fOption,
|
||||
PTR pvParam)
|
||||
@ -398,12 +450,14 @@ ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if (! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
switch (fOption) {
|
||||
switch (fOption)
|
||||
{
|
||||
case SQL_ACCESS_MODE: /* NOT SUPPORTED */
|
||||
*((UDWORD *) pvParam) = SQL_MODE_READ_WRITE;
|
||||
break;
|
||||
@ -447,6 +501,7 @@ ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
default:
|
||||
{
|
||||
char option[64];
|
||||
|
||||
conn->errormsg = "Unknown connect option (Get)";
|
||||
conn->errornumber = CONN_UNSUPPORTED_OPTION;
|
||||
sprintf(option, "fOption=%d", fOption);
|
||||
@ -462,7 +517,8 @@ ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLSetStmtOption(
|
||||
RETCODE SQL_API
|
||||
SQLSetStmtOption(
|
||||
HSTMT hstmt,
|
||||
UWORD fOption,
|
||||
UDWORD vParam)
|
||||
@ -476,7 +532,8 @@ StatementClass *stmt = (StatementClass *) hstmt;
|
||||
/* all the time, but it tries to set a huge value for SQL_MAX_LENGTH */
|
||||
/* and expects the driver to reduce it to the real value */
|
||||
|
||||
if( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -487,7 +544,8 @@ StatementClass *stmt = (StatementClass *) hstmt;
|
||||
|
||||
/* - - - - - - - - - */
|
||||
|
||||
RETCODE SQL_API SQLGetStmtOption(
|
||||
RETCODE SQL_API
|
||||
SQLGetStmtOption(
|
||||
HSTMT hstmt,
|
||||
UWORD fOption,
|
||||
PTR pvParam)
|
||||
@ -502,29 +560,35 @@ QResultClass *res;
|
||||
/* all the time, but it tries to set a huge value for SQL_MAX_LENGTH */
|
||||
/* and expects the driver to reduce it to the real value */
|
||||
|
||||
if( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
switch(fOption) {
|
||||
switch (fOption)
|
||||
{
|
||||
case SQL_GET_BOOKMARK:
|
||||
case SQL_ROW_NUMBER:
|
||||
|
||||
res = stmt->result;
|
||||
|
||||
if ( stmt->manual_result || ! globals.use_declarefetch) {
|
||||
if (stmt->manual_result || !globals.use_declarefetch)
|
||||
{
|
||||
/* make sure we're positioned on a valid row */
|
||||
if ((stmt->currTuple < 0) ||
|
||||
(stmt->currTuple >= QR_get_num_tuples(res))) {
|
||||
(stmt->currTuple >= QR_get_num_tuples(res)))
|
||||
{
|
||||
stmt->errormsg = "Not positioned on a valid row.";
|
||||
stmt->errornumber = STMT_INVALID_CURSOR_STATE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (stmt->currTuple == -1 || ! res || ! res->tupleField) {
|
||||
else
|
||||
{
|
||||
if (stmt->currTuple == -1 || !res || !res->tupleField)
|
||||
{
|
||||
stmt->errormsg = "Not positioned on a valid row.";
|
||||
stmt->errornumber = STMT_INVALID_CURSOR_STATE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -532,7 +596,8 @@ QResultClass *res;
|
||||
}
|
||||
}
|
||||
|
||||
if (fOption == SQL_GET_BOOKMARK && stmt->options.use_bookmarks == SQL_UB_OFF) {
|
||||
if (fOption == SQL_GET_BOOKMARK && stmt->options.use_bookmarks == SQL_UB_OFF)
|
||||
{
|
||||
stmt->errormsg = "Operation invalid because use bookmarks not enabled.";
|
||||
stmt->errornumber = STMT_OPERATION_INVALID;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -602,6 +667,7 @@ QResultClass *res;
|
||||
default:
|
||||
{
|
||||
char option[64];
|
||||
|
||||
stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
|
||||
stmt->errormsg = "Unknown statement option (Get)";
|
||||
sprintf(option, "fOption=%d", fOption);
|
||||
|
@ -46,7 +46,8 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
|
||||
{
|
||||
int i = 0;
|
||||
int out = 0;
|
||||
char qc, in_escape = FALSE;
|
||||
char qc,
|
||||
in_escape = FALSE;
|
||||
|
||||
if (smax <= 1)
|
||||
return NULL;
|
||||
@ -54,43 +55,54 @@ char qc, in_escape = FALSE;
|
||||
smax--;
|
||||
|
||||
/* skip leading delimiters */
|
||||
while (isspace((unsigned char) s[i]) || s[i] == ',') {
|
||||
while (isspace((unsigned char) s[i]) || s[i] == ',')
|
||||
{
|
||||
/* mylog("skipping '%c'\n", s[i]); */
|
||||
i++;
|
||||
}
|
||||
|
||||
if (s[0] == '\0') {
|
||||
if (s[0] == '\0')
|
||||
{
|
||||
token[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (quote) *quote = FALSE;
|
||||
if (dquote) *dquote = FALSE;
|
||||
if (numeric) *numeric = FALSE;
|
||||
if (quote)
|
||||
*quote = FALSE;
|
||||
if (dquote)
|
||||
*dquote = FALSE;
|
||||
if (numeric)
|
||||
*numeric = FALSE;
|
||||
|
||||
/* get the next token */
|
||||
while (!isspace((unsigned char) s[i]) && s[i] != ',' &&
|
||||
s[i] != '\0' && out != smax) {
|
||||
s[i] != '\0' && out != smax)
|
||||
{
|
||||
|
||||
/* Handle quoted stuff */
|
||||
if ( out == 0 && (s[i] == '\"' || s[i] == '\'')) {
|
||||
if (out == 0 && (s[i] == '\"' || s[i] == '\''))
|
||||
{
|
||||
qc = s[i];
|
||||
if (qc == '\"') {
|
||||
if (dquote) *dquote = TRUE;
|
||||
if (qc == '\"')
|
||||
{
|
||||
if (dquote)
|
||||
*dquote = TRUE;
|
||||
}
|
||||
if (qc == '\'') {
|
||||
if (quote) *quote = TRUE;
|
||||
if (qc == '\'')
|
||||
{
|
||||
if (quote)
|
||||
*quote = TRUE;
|
||||
}
|
||||
|
||||
i++; /* dont return the quote */
|
||||
while (s[i] != '\0' && out != smax) {
|
||||
if (s[i] == qc && ! in_escape) {
|
||||
while (s[i] != '\0' && out != smax)
|
||||
{
|
||||
if (s[i] == qc && !in_escape)
|
||||
break;
|
||||
}
|
||||
if (s[i] == '\\' && ! in_escape) {
|
||||
if (s[i] == '\\' && !in_escape)
|
||||
in_escape = TRUE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
in_escape = FALSE;
|
||||
token[out++] = s[i];
|
||||
}
|
||||
@ -102,8 +114,10 @@ char qc, in_escape = FALSE;
|
||||
}
|
||||
|
||||
/* Check for numeric literals */
|
||||
if ( out == 0 && isdigit((unsigned char) s[i])) {
|
||||
if (numeric) *numeric = TRUE;
|
||||
if (out == 0 && isdigit((unsigned char) s[i]))
|
||||
{
|
||||
if (numeric)
|
||||
*numeric = TRUE;
|
||||
token[out++] = s[i++];
|
||||
while (isalnum((unsigned char) s[i]) || s[i] == '.')
|
||||
token[out++] = s[i++];
|
||||
@ -111,10 +125,12 @@ char qc, in_escape = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ispunct((unsigned char) s[i]) && s[i] != '_') {
|
||||
if (ispunct((unsigned char) s[i]) && s[i] != '_')
|
||||
{
|
||||
mylog("got ispunct: s[%d] = '%c'\n", i, s[i]);
|
||||
|
||||
if (out == 0) {
|
||||
if (out == 0)
|
||||
{
|
||||
token[out++] = s[i++];
|
||||
break;
|
||||
}
|
||||
@ -137,20 +153,25 @@ char qc, in_escape = FALSE;
|
||||
i++;
|
||||
|
||||
/* return the most priority delimiter */
|
||||
if (s[i] == ',') {
|
||||
if (delim) *delim = s[i];
|
||||
if (s[i] == ',')
|
||||
{
|
||||
if (delim)
|
||||
*delim = s[i];
|
||||
}
|
||||
else if (s[i] == '\0') {
|
||||
if (delim) *delim = '\0';
|
||||
else if (s[i] == '\0')
|
||||
{
|
||||
if (delim)
|
||||
*delim = '\0';
|
||||
}
|
||||
else {
|
||||
if (delim) *delim = ' ';
|
||||
else
|
||||
{
|
||||
if (delim)
|
||||
*delim = ' ';
|
||||
}
|
||||
|
||||
/* skip trailing blanks */
|
||||
while ( isspace((unsigned char) s[i])) {
|
||||
while (isspace((unsigned char) s[i]))
|
||||
i++;
|
||||
}
|
||||
|
||||
return &s[i];
|
||||
}
|
||||
@ -195,9 +216,11 @@ int k;
|
||||
char *col;
|
||||
|
||||
|
||||
for (k = 0; k < QR_get_num_tuples(col_info->result); k++) {
|
||||
for (k = 0; k < QR_get_num_tuples(col_info->result); k++)
|
||||
{
|
||||
col = QR_get_value_manual(col_info->result, k, 3);
|
||||
if ( ! strcmp(col, fi->name)) {
|
||||
if (!strcmp(col, fi->name))
|
||||
{
|
||||
getColInfo(col_info, fi, k);
|
||||
|
||||
mylog("PARSE: searchColInfo: \n");
|
||||
@ -214,11 +237,28 @@ parse_statement(StatementClass *stmt)
|
||||
{
|
||||
static char *func = "parse_statement";
|
||||
char token[256];
|
||||
char delim, quote, dquote, numeric, unquoted;
|
||||
char delim,
|
||||
quote,
|
||||
dquote,
|
||||
numeric,
|
||||
unquoted;
|
||||
char *ptr;
|
||||
char in_select = FALSE, in_distinct = FALSE, in_on = FALSE, in_from = FALSE, in_where = FALSE, in_table = FALSE;
|
||||
char in_field = FALSE, in_expr = FALSE, in_func = FALSE, in_dot = FALSE, in_as = FALSE;
|
||||
int j, i, k = 0, n, blevel = 0;
|
||||
char in_select = FALSE,
|
||||
in_distinct = FALSE,
|
||||
in_on = FALSE,
|
||||
in_from = FALSE,
|
||||
in_where = FALSE,
|
||||
in_table = FALSE;
|
||||
char in_field = FALSE,
|
||||
in_expr = FALSE,
|
||||
in_func = FALSE,
|
||||
in_dot = FALSE,
|
||||
in_as = FALSE;
|
||||
int j,
|
||||
i,
|
||||
k = 0,
|
||||
n,
|
||||
blevel = 0;
|
||||
FIELD_INFO **fi;
|
||||
TABLE_INFO **ti;
|
||||
char parse;
|
||||
@ -237,34 +277,39 @@ RETCODE result;
|
||||
stmt->nfld = 0;
|
||||
stmt->ntab = 0;
|
||||
|
||||
while ((ptr = getNextToken(ptr, token, sizeof(token), &delim, "e, &dquote, &numeric)) != NULL) {
|
||||
while ((ptr = getNextToken(ptr, token, sizeof(token), &delim, "e, &dquote, &numeric)) != NULL)
|
||||
{
|
||||
|
||||
unquoted = !(quote || dquote);
|
||||
|
||||
mylog("unquoted=%d, quote=%d, dquote=%d, numeric=%d, delim='%c', token='%s', ptr='%s'\n", unquoted, quote, dquote, numeric, delim, token, ptr);
|
||||
|
||||
if ( unquoted && ! stricmp(token, "select")) {
|
||||
if (unquoted && !stricmp(token, "select"))
|
||||
{
|
||||
in_select = TRUE;
|
||||
|
||||
mylog("SELECT\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( unquoted && in_select && ! stricmp(token, "distinct")) {
|
||||
if (unquoted && in_select && !stricmp(token, "distinct"))
|
||||
{
|
||||
in_distinct = TRUE;
|
||||
|
||||
mylog("DISTINCT\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( unquoted && ! stricmp(token, "into")) {
|
||||
if (unquoted && !stricmp(token, "into"))
|
||||
{
|
||||
in_select = FALSE;
|
||||
|
||||
mylog("INTO\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( unquoted && ! stricmp(token, "from")) {
|
||||
if (unquoted && !stricmp(token, "from"))
|
||||
{
|
||||
in_select = FALSE;
|
||||
in_from = TRUE;
|
||||
|
||||
@ -276,7 +321,8 @@ RETCODE result;
|
||||
!stricmp(token, "union") ||
|
||||
!stricmp(token, "order") ||
|
||||
!stricmp(token, "group") ||
|
||||
! stricmp(token, "having"))) {
|
||||
!stricmp(token, "having")))
|
||||
{
|
||||
|
||||
in_select = FALSE;
|
||||
in_from = FALSE;
|
||||
@ -286,17 +332,21 @@ RETCODE result;
|
||||
break;
|
||||
}
|
||||
|
||||
if (in_select) {
|
||||
if (in_select)
|
||||
{
|
||||
|
||||
if ( in_distinct) {
|
||||
if (in_distinct)
|
||||
{
|
||||
mylog("in distinct\n");
|
||||
|
||||
if (unquoted && ! stricmp(token, "on")) {
|
||||
if (unquoted && !stricmp(token, "on"))
|
||||
{
|
||||
in_on = TRUE;
|
||||
mylog("got on\n");
|
||||
continue;
|
||||
}
|
||||
if (in_on) {
|
||||
if (in_on)
|
||||
{
|
||||
in_distinct = FALSE;
|
||||
in_on = FALSE;
|
||||
continue; /* just skip the unique on field */
|
||||
@ -305,25 +355,30 @@ RETCODE result;
|
||||
in_distinct = FALSE;
|
||||
}
|
||||
|
||||
if ( in_expr || in_func) { /* just eat the expression */
|
||||
if (in_expr || in_func)
|
||||
{ /* just eat the expression */
|
||||
mylog("in_expr=%d or func=%d\n", in_expr, in_func);
|
||||
if (quote || dquote)
|
||||
continue;
|
||||
|
||||
if (in_expr && blevel == 0 && delim == ',') {
|
||||
if (in_expr && blevel == 0 && delim == ',')
|
||||
{
|
||||
mylog("**** in_expr and Got comma\n");
|
||||
in_expr = FALSE;
|
||||
in_field = FALSE;
|
||||
}
|
||||
|
||||
else if (token[0] == '(') {
|
||||
else if (token[0] == '(')
|
||||
{
|
||||
blevel++;
|
||||
mylog("blevel++ = %d\n", blevel);
|
||||
}
|
||||
else if (token[0] == ')') {
|
||||
else if (token[0] == ')')
|
||||
{
|
||||
blevel--;
|
||||
mylog("blevel-- = %d\n", blevel);
|
||||
if (delim==',') {
|
||||
if (delim == ',')
|
||||
{
|
||||
in_func = FALSE;
|
||||
in_expr = FALSE;
|
||||
in_field = FALSE;
|
||||
@ -332,15 +387,18 @@ RETCODE result;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! in_field) {
|
||||
if (!in_field)
|
||||
{
|
||||
|
||||
if (!token[0])
|
||||
continue;
|
||||
|
||||
if ( ! (stmt->nfld % FLD_INCR)) {
|
||||
if (!(stmt->nfld % FLD_INCR))
|
||||
{
|
||||
mylog("reallocing at nfld=%d\n", stmt->nfld);
|
||||
fi = (FIELD_INFO **) realloc(fi, (stmt->nfld + FLD_INCR) * sizeof(FIELD_INFO *));
|
||||
if ( ! fi) {
|
||||
if (!fi)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
@ -348,7 +406,8 @@ RETCODE result;
|
||||
}
|
||||
|
||||
fi[stmt->nfld] = (FIELD_INFO *) malloc(sizeof(FIELD_INFO));
|
||||
if (fi[stmt->nfld] == NULL) {
|
||||
if (fi[stmt->nfld] == NULL)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
@ -360,15 +419,18 @@ RETCODE result;
|
||||
if (dquote)
|
||||
fi[stmt->nfld]->dquote = TRUE;
|
||||
|
||||
if (quote) {
|
||||
if (quote)
|
||||
{
|
||||
fi[stmt->nfld++]->quote = TRUE;
|
||||
continue;
|
||||
}
|
||||
else if (numeric) {
|
||||
else if (numeric)
|
||||
{
|
||||
mylog("**** got numeric: nfld = %d\n", stmt->nfld);
|
||||
fi[stmt->nfld]->numeric = TRUE;
|
||||
}
|
||||
else if (token[0] == '(') { /* expression */
|
||||
else if (token[0] == '(')
|
||||
{ /* expression */
|
||||
mylog("got EXPRESSION\n");
|
||||
fi[stmt->nfld++]->expr = TRUE;
|
||||
in_expr = TRUE;
|
||||
@ -376,18 +438,17 @@ RETCODE result;
|
||||
continue;
|
||||
}
|
||||
|
||||
else {
|
||||
else
|
||||
{
|
||||
strcpy(fi[stmt->nfld]->name, token);
|
||||
fi[stmt->nfld]->dot[0] = '\0';
|
||||
}
|
||||
mylog("got field='%s', dot='%s'\n", fi[stmt->nfld]->name, fi[stmt->nfld]->dot);
|
||||
|
||||
if (delim == ',') {
|
||||
if (delim == ',')
|
||||
mylog("comma (1)\n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
in_field = TRUE;
|
||||
}
|
||||
stmt->nfld++;
|
||||
continue;
|
||||
}
|
||||
@ -395,14 +456,16 @@ RETCODE result;
|
||||
/**************************/
|
||||
/* We are in a field now */
|
||||
/**************************/
|
||||
if (in_dot) {
|
||||
if (in_dot)
|
||||
{
|
||||
stmt->nfld--;
|
||||
strcpy(fi[stmt->nfld]->dot, fi[stmt->nfld]->name);
|
||||
strcpy(fi[stmt->nfld]->name, token);
|
||||
stmt->nfld++;
|
||||
in_dot = FALSE;
|
||||
|
||||
if (delim == ',') {
|
||||
if (delim == ',')
|
||||
{
|
||||
mylog("in_dot: got comma\n");
|
||||
in_field = FALSE;
|
||||
}
|
||||
@ -410,7 +473,8 @@ RETCODE result;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_as) {
|
||||
if (in_as)
|
||||
{
|
||||
stmt->nfld--;
|
||||
strcpy(fi[stmt->nfld]->alias, token);
|
||||
mylog("alias for field '%s' is '%s'\n", fi[stmt->nfld]->name, fi[stmt->nfld]->alias);
|
||||
@ -419,29 +483,35 @@ RETCODE result;
|
||||
|
||||
stmt->nfld++;
|
||||
|
||||
if (delim == ',') {
|
||||
if (delim == ',')
|
||||
mylog("comma(2)\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Function */
|
||||
if (token[0] == '(') {
|
||||
if (token[0] == '(')
|
||||
{
|
||||
in_func = TRUE;
|
||||
blevel = 1;
|
||||
fi[stmt->nfld - 1]->func = TRUE;
|
||||
/* name will have the function name -- maybe useful some day */
|
||||
|
||||
/*
|
||||
* name will have the function name -- maybe useful some
|
||||
* day
|
||||
*/
|
||||
mylog("**** got function = '%s'\n", fi[stmt->nfld - 1]->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token[0] == '.') {
|
||||
if (token[0] == '.')
|
||||
{
|
||||
in_dot = TRUE;
|
||||
mylog("got dot\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! stricmp(token, "as")) {
|
||||
if (!stricmp(token, "as"))
|
||||
{
|
||||
in_as = TRUE;
|
||||
mylog("got AS\n");
|
||||
continue;
|
||||
@ -455,22 +525,27 @@ RETCODE result;
|
||||
|
||||
}
|
||||
|
||||
if (in_from) {
|
||||
if (in_from)
|
||||
{
|
||||
|
||||
if ( ! in_table) {
|
||||
if (!in_table)
|
||||
{
|
||||
if (!token[0])
|
||||
continue;
|
||||
|
||||
if ( ! (stmt->ntab % TAB_INCR)) {
|
||||
if (!(stmt->ntab % TAB_INCR))
|
||||
{
|
||||
ti = (TABLE_INFO **) realloc(ti, (stmt->ntab + TAB_INCR) * sizeof(TABLE_INFO *));
|
||||
if ( ! ti) {
|
||||
if (!ti)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
stmt->ti = ti;
|
||||
}
|
||||
ti[stmt->ntab] = (TABLE_INFO *) malloc(sizeof(TABLE_INFO));
|
||||
if (ti[stmt->ntab] == NULL) {
|
||||
if (ti[stmt->ntab] == NULL)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
@ -480,12 +555,10 @@ RETCODE result;
|
||||
strcpy(ti[stmt->ntab]->name, token);
|
||||
mylog("got table = '%s'\n", ti[stmt->ntab]->name);
|
||||
|
||||
if (delim == ',') {
|
||||
if (delim == ',')
|
||||
mylog("more than 1 tables\n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
in_table = TRUE;
|
||||
}
|
||||
stmt->ntab++;
|
||||
continue;
|
||||
}
|
||||
@ -493,11 +566,10 @@ RETCODE result;
|
||||
strcpy(ti[stmt->ntab - 1]->alias, token);
|
||||
mylog("alias for table '%s' is '%s'\n", ti[stmt->ntab - 1]->name, ti[stmt->ntab - 1]->alias);
|
||||
in_table = FALSE;
|
||||
if (delim == ',') {
|
||||
if (delim == ',')
|
||||
mylog("more than 1 tables\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*************************************************/
|
||||
@ -507,16 +579,19 @@ RETCODE result;
|
||||
parse = TRUE;
|
||||
|
||||
/* Resolve field names with tables */
|
||||
for (i = 0; i < stmt->nfld; i++) {
|
||||
for (i = 0; i < stmt->nfld; i++)
|
||||
{
|
||||
|
||||
if (fi[i]->func || fi[i]->expr || fi[i]->numeric) {
|
||||
if (fi[i]->func || fi[i]->expr || fi[i]->numeric)
|
||||
{
|
||||
fi[i]->ti = NULL;
|
||||
fi[i]->type = -1;
|
||||
parse = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (fi[i]->quote) { /* handle as text */
|
||||
else if (fi[i]->quote)
|
||||
{ /* handle as text */
|
||||
fi[i]->ti = NULL;
|
||||
fi[i]->type = PG_TYPE_TEXT;
|
||||
fi[i]->precision = 0;
|
||||
@ -524,13 +599,17 @@ RETCODE result;
|
||||
}
|
||||
|
||||
/* it's a dot, resolve to table or alias */
|
||||
else if (fi[i]->dot[0]) {
|
||||
for (k = 0; k < stmt->ntab; k++) {
|
||||
if ( ! stricmp(ti[k]->name, fi[i]->dot)) {
|
||||
else if (fi[i]->dot[0])
|
||||
{
|
||||
for (k = 0; k < stmt->ntab; k++)
|
||||
{
|
||||
if (!stricmp(ti[k]->name, fi[i]->dot))
|
||||
{
|
||||
fi[i]->ti = ti[k];
|
||||
break;
|
||||
}
|
||||
else if ( ! stricmp(ti[k]->alias, fi[i]->dot)) {
|
||||
else if (!stricmp(ti[k]->alias, fi[i]->dot))
|
||||
{
|
||||
fi[i]->ti = ti[k];
|
||||
break;
|
||||
}
|
||||
@ -543,15 +622,15 @@ RETCODE result;
|
||||
mylog("--------------------------------------------\n");
|
||||
mylog("nfld=%d, ntab=%d\n", stmt->nfld, stmt->ntab);
|
||||
|
||||
for (i=0; i < stmt->nfld; i++) {
|
||||
for (i = 0; i < stmt->nfld; i++)
|
||||
{
|
||||
mylog("Field %d: expr=%d, func=%d, quote=%d, dquote=%d, numeric=%d, name='%s', alias='%s', dot='%s'\n", i, fi[i]->expr, fi[i]->func, fi[i]->quote, fi[i]->dquote, fi[i]->numeric, fi[i]->name, fi[i]->alias, fi[i]->dot);
|
||||
if (fi[i]->ti)
|
||||
mylog(" ----> table_name='%s', table_alias='%s'\n", fi[i]->ti->name, fi[i]->ti->alias);
|
||||
}
|
||||
|
||||
for (i=0; i < stmt->ntab; i++) {
|
||||
for (i = 0; i < stmt->ntab; i++)
|
||||
mylog("Table %d: name='%s', alias='%s'\n", i, ti[i]->name, ti[i]->alias);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************/
|
||||
@ -560,24 +639,30 @@ RETCODE result;
|
||||
|
||||
|
||||
/* Call SQLColumns for each table and store the result */
|
||||
for (i = 0; i < stmt->ntab; i++) {
|
||||
for (i = 0; i < stmt->ntab; i++)
|
||||
{
|
||||
|
||||
/* See if already got it */
|
||||
char found = FALSE;
|
||||
for (k = 0; k < conn->ntables; k++) {
|
||||
if ( ! stricmp(conn->col_info[k]->name, ti[i]->name)) {
|
||||
|
||||
for (k = 0; k < conn->ntables; k++)
|
||||
{
|
||||
if (!stricmp(conn->col_info[k]->name, ti[i]->name))
|
||||
{
|
||||
mylog("FOUND col_info table='%s'\n", ti[i]->name);
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! found) {
|
||||
if (!found)
|
||||
{
|
||||
|
||||
mylog("PARSE: Getting SQLColumns for table[%d]='%s'\n", i, ti[i]->name);
|
||||
|
||||
result = SQLAllocStmt(stmt->hdbc, &hcol_stmt);
|
||||
if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
|
||||
{
|
||||
stmt->errormsg = "SQLAllocStmt failed in parse_statement for columns.";
|
||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
@ -591,14 +676,17 @@ RETCODE result;
|
||||
ti[i]->name, (SWORD) strlen(ti[i]->name), "", 0);
|
||||
|
||||
mylog(" Past SQLColumns\n");
|
||||
if (result == SQL_SUCCESS) {
|
||||
if (result == SQL_SUCCESS)
|
||||
{
|
||||
mylog(" Success\n");
|
||||
if ( ! (conn->ntables % COL_INCR)) {
|
||||
if (!(conn->ntables % COL_INCR))
|
||||
{
|
||||
|
||||
mylog("PARSE: Allocing col_info at ntables=%d\n", conn->ntables);
|
||||
|
||||
conn->col_info = (COL_INFO **) realloc(conn->col_info, (conn->ntables + COL_INCR) * sizeof(COL_INFO *));
|
||||
if ( ! conn->col_info) {
|
||||
if (!conn->col_info)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
@ -606,17 +694,22 @@ RETCODE result;
|
||||
|
||||
mylog("PARSE: malloc at conn->col_info[%d]\n", conn->ntables);
|
||||
conn->col_info[conn->ntables] = (COL_INFO *) malloc(sizeof(COL_INFO));
|
||||
if ( ! conn->col_info[conn->ntables]) {
|
||||
if (!conn->col_info[conn->ntables])
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Store the table name and the SQLColumns result structure */
|
||||
/*
|
||||
* Store the table name and the SQLColumns result
|
||||
* structure
|
||||
*/
|
||||
strcpy(conn->col_info[conn->ntables]->name, ti[i]->name);
|
||||
conn->col_info[conn->ntables]->result = col_stmt->result;
|
||||
|
||||
/* The connection will now free the result structures, so make
|
||||
sure that the statement doesn't free it
|
||||
/*
|
||||
* The connection will now free the result structures, so
|
||||
* make sure that the statement doesn't free it
|
||||
*/
|
||||
col_stmt->result = NULL;
|
||||
|
||||
@ -625,7 +718,8 @@ RETCODE result;
|
||||
SQLFreeStmt(hcol_stmt, SQL_DROP);
|
||||
mylog("Created col_info table='%s', ntables=%d\n", ti[i]->name, conn->ntables);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SQLFreeStmt(hcol_stmt, SQL_DROP);
|
||||
break;
|
||||
}
|
||||
@ -645,34 +739,41 @@ RETCODE result;
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < stmt->nfld;) {
|
||||
for (i = 0; i < stmt->nfld;)
|
||||
{
|
||||
|
||||
/* Dont worry about functions or quotes */
|
||||
if (fi[i]->func || fi[i]->quote || fi[i]->numeric) {
|
||||
if (fi[i]->func || fi[i]->quote || fi[i]->numeric)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Stars get expanded to all fields in the table */
|
||||
else if (fi[i]->name[0] == '*') {
|
||||
else if (fi[i]->name[0] == '*')
|
||||
{
|
||||
|
||||
char do_all_tables;
|
||||
int total_cols, old_size, need, cols;
|
||||
int total_cols,
|
||||
old_size,
|
||||
need,
|
||||
cols;
|
||||
|
||||
mylog("expanding field %d\n", i);
|
||||
|
||||
total_cols = 0;
|
||||
|
||||
if (fi[i]->ti) /* The star represents only the qualified table */
|
||||
if (fi[i]->ti) /* The star represents only the qualified
|
||||
* table */
|
||||
total_cols = QR_get_num_tuples(fi[i]->ti->col_info->result);
|
||||
|
||||
else { /* The star represents all tables */
|
||||
else
|
||||
{ /* The star represents all tables */
|
||||
|
||||
/* Calculate the total number of columns after expansion */
|
||||
for (k = 0; k < stmt->ntab; k++) {
|
||||
for (k = 0; k < stmt->ntab; k++)
|
||||
total_cols += QR_get_num_tuples(ti[k]->col_info->result);
|
||||
}
|
||||
}
|
||||
total_cols--; /* makes up for the star */
|
||||
|
||||
/* Allocate some more field pointers if necessary */
|
||||
@ -682,19 +783,27 @@ RETCODE result;
|
||||
|
||||
mylog("k=%d, total_cols=%d, old_size=%d, need=%d\n", k, total_cols, old_size, need);
|
||||
|
||||
if (need > 0) {
|
||||
if (need > 0)
|
||||
{
|
||||
int new_size = need / FLD_INCR * FLD_INCR + FLD_INCR;
|
||||
|
||||
mylog("need more cols: new_size = %d\n", new_size);
|
||||
fi = (FIELD_INFO **) realloc(fi, (old_size + new_size) * sizeof(FIELD_INFO *));
|
||||
if ( ! fi) {
|
||||
if (!fi)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------- */
|
||||
/* copy any other fields (if there are any) up past the expansion */
|
||||
for (j = stmt->nfld - 1; j > i; j--) {
|
||||
|
||||
/*
|
||||
* copy any other fields (if there are any) up past the
|
||||
* expansion
|
||||
*/
|
||||
for (j = stmt->nfld - 1; j > i; j--)
|
||||
{
|
||||
mylog("copying field %d to %d\n", j, total_cols + j);
|
||||
fi[total_cols + j] = fi[j];
|
||||
}
|
||||
@ -712,19 +821,23 @@ RETCODE result;
|
||||
|
||||
do_all_tables = (fi[i]->ti ? FALSE : TRUE);
|
||||
|
||||
for (k = 0; k < (do_all_tables ? stmt->ntab : 1); k++) {
|
||||
for (k = 0; k < (do_all_tables ? stmt->ntab : 1); k++)
|
||||
{
|
||||
|
||||
TABLE_INFO *the_ti = do_all_tables ? ti[k] : fi[i]->ti;
|
||||
|
||||
cols = QR_get_num_tuples(the_ti->col_info->result);
|
||||
|
||||
for (n = 0; n < cols; n++) {
|
||||
for (n = 0; n < cols; n++)
|
||||
{
|
||||
mylog("creating field info: n=%d\n", n);
|
||||
/* skip malloc (already did it for the Star) */
|
||||
if (k > 0 || n > 0) {
|
||||
if (k > 0 || n > 0)
|
||||
{
|
||||
mylog("allocating field info at %d\n", n + i);
|
||||
fi[n + i] = (FIELD_INFO *) malloc(sizeof(FIELD_INFO));
|
||||
if (fi[n + i] == NULL) {
|
||||
if (fi[n + i] == NULL)
|
||||
{
|
||||
stmt->parse_status = STMT_PARSE_FATAL;
|
||||
return FALSE;
|
||||
}
|
||||
@ -747,10 +860,13 @@ RETCODE result;
|
||||
/*------------------------------------------------------------- */
|
||||
}
|
||||
|
||||
/* We either know which table the field was in because it was qualified
|
||||
with a table name or alias -OR- there was only 1 table.
|
||||
/*
|
||||
* We either know which table the field was in because it was
|
||||
* qualified with a table name or alias -OR- there was only 1
|
||||
* table.
|
||||
*/
|
||||
else if (fi[i]->ti) {
|
||||
else if (fi[i]->ti)
|
||||
{
|
||||
|
||||
if (!searchColInfo(fi[i]->ti->col_info, fi[i]))
|
||||
parse = FALSE;
|
||||
@ -759,10 +875,13 @@ RETCODE result;
|
||||
}
|
||||
|
||||
/* Don't know the table -- search all tables in "from" list */
|
||||
else {
|
||||
else
|
||||
{
|
||||
parse = FALSE;
|
||||
for (k = 0; k < stmt->ntab; k++) {
|
||||
if ( searchColInfo(ti[k]->col_info, fi[i])) {
|
||||
for (k = 0; k < stmt->ntab; k++)
|
||||
{
|
||||
if (searchColInfo(ti[k]->col_info, fi[i]))
|
||||
{
|
||||
fi[i]->ti = ti[k]; /* now know the table */
|
||||
parse = TRUE;
|
||||
break;
|
||||
@ -782,4 +901,3 @@ RETCODE result;
|
||||
mylog("done parse_statement: parse=%d, parse_status=%d\n", parse, stmt->parse_status);
|
||||
return parse;
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,13 @@ Int2 sqlTypes [] = {
|
||||
0
|
||||
};
|
||||
|
||||
Int4 sqltype_to_pgtype(SWORD fSqlType)
|
||||
Int4
|
||||
sqltype_to_pgtype(SWORD fSqlType)
|
||||
{
|
||||
Int4 pgType;
|
||||
|
||||
switch(fSqlType) {
|
||||
switch (fSqlType)
|
||||
{
|
||||
|
||||
case SQL_BINARY:
|
||||
pgType = PG_TYPE_BYTEA;
|
||||
@ -192,122 +194,187 @@ Int4 pgType;
|
||||
know. This allows for supporting
|
||||
types that are unknown. All other pg routines in here return a suitable default.
|
||||
*/
|
||||
Int2 pgtype_to_sqltype(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_to_sqltype(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_CHAR:
|
||||
case PG_TYPE_CHAR2:
|
||||
case PG_TYPE_CHAR4:
|
||||
case PG_TYPE_CHAR8:
|
||||
case PG_TYPE_NAME:return SQL_CHAR;
|
||||
|
||||
case PG_TYPE_BPCHAR: return SQL_CHAR;
|
||||
case PG_TYPE_BPCHAR:
|
||||
return SQL_CHAR;
|
||||
|
||||
case PG_TYPE_VARCHAR: return SQL_VARCHAR;
|
||||
case PG_TYPE_VARCHAR:
|
||||
return SQL_VARCHAR;
|
||||
|
||||
case PG_TYPE_TEXT: return globals.text_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
|
||||
case PG_TYPE_TEXT:
|
||||
return globals.text_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
|
||||
|
||||
case PG_TYPE_BYTEA: return SQL_VARBINARY;
|
||||
case PG_TYPE_LO: return SQL_LONGVARBINARY;
|
||||
case PG_TYPE_BYTEA:
|
||||
return SQL_VARBINARY;
|
||||
case PG_TYPE_LO:
|
||||
return SQL_LONGVARBINARY;
|
||||
|
||||
case PG_TYPE_INT2: return SQL_SMALLINT;
|
||||
case PG_TYPE_INT2:
|
||||
return SQL_SMALLINT;
|
||||
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID:
|
||||
case PG_TYPE_INT4: return SQL_INTEGER;
|
||||
case PG_TYPE_INT4:
|
||||
return SQL_INTEGER;
|
||||
|
||||
/* Change this to SQL_BIGINT for ODBC v3 bjm 2001-01-23 */
|
||||
case PG_TYPE_INT8: return SQL_CHAR;
|
||||
case PG_TYPE_INT8:
|
||||
return SQL_CHAR;
|
||||
|
||||
case PG_TYPE_NUMERIC: return SQL_NUMERIC;
|
||||
case PG_TYPE_NUMERIC:
|
||||
return SQL_NUMERIC;
|
||||
|
||||
case PG_TYPE_FLOAT4: return SQL_REAL;
|
||||
case PG_TYPE_FLOAT8: return SQL_FLOAT;
|
||||
case PG_TYPE_DATE: return SQL_DATE;
|
||||
case PG_TYPE_TIME: return SQL_TIME;
|
||||
case PG_TYPE_FLOAT4:
|
||||
return SQL_REAL;
|
||||
case PG_TYPE_FLOAT8:
|
||||
return SQL_FLOAT;
|
||||
case PG_TYPE_DATE:
|
||||
return SQL_DATE;
|
||||
case PG_TYPE_TIME:
|
||||
return SQL_TIME;
|
||||
case PG_TYPE_ABSTIME:
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP: return SQL_TIMESTAMP;
|
||||
case PG_TYPE_MONEY: return SQL_FLOAT;
|
||||
case PG_TYPE_BOOL: return globals.bools_as_char ? SQL_CHAR : SQL_BIT;
|
||||
case PG_TYPE_TIMESTAMP:
|
||||
return SQL_TIMESTAMP;
|
||||
case PG_TYPE_MONEY:
|
||||
return SQL_FLOAT;
|
||||
case PG_TYPE_BOOL:
|
||||
return globals.bools_as_char ? SQL_CHAR : SQL_BIT;
|
||||
|
||||
default:
|
||||
|
||||
/* first, check to see if 'type' is in list. If not, look up with query.
|
||||
Add oid, name to list. If it's already in list, just return.
|
||||
/*
|
||||
* first, check to see if 'type' is in list. If not, look up
|
||||
* with query. Add oid, name to list. If it's already in
|
||||
* list, just return.
|
||||
*/
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent type is available */
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent
|
||||
* type is available */
|
||||
return SQL_LONGVARBINARY;
|
||||
|
||||
return globals.unknowns_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_to_ctype(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_to_ctype(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_INT8:return SQL_C_CHAR;
|
||||
case PG_TYPE_NUMERIC: return SQL_C_CHAR;
|
||||
case PG_TYPE_INT2: return SQL_C_SSHORT;
|
||||
case PG_TYPE_NUMERIC:
|
||||
return SQL_C_CHAR;
|
||||
case PG_TYPE_INT2:
|
||||
return SQL_C_SSHORT;
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID:
|
||||
case PG_TYPE_INT4: return SQL_C_SLONG;
|
||||
case PG_TYPE_FLOAT4: return SQL_C_FLOAT;
|
||||
case PG_TYPE_FLOAT8: return SQL_C_DOUBLE;
|
||||
case PG_TYPE_DATE: return SQL_C_DATE;
|
||||
case PG_TYPE_TIME: return SQL_C_TIME;
|
||||
case PG_TYPE_INT4:
|
||||
return SQL_C_SLONG;
|
||||
case PG_TYPE_FLOAT4:
|
||||
return SQL_C_FLOAT;
|
||||
case PG_TYPE_FLOAT8:
|
||||
return SQL_C_DOUBLE;
|
||||
case PG_TYPE_DATE:
|
||||
return SQL_C_DATE;
|
||||
case PG_TYPE_TIME:
|
||||
return SQL_C_TIME;
|
||||
case PG_TYPE_ABSTIME:
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP: return SQL_C_TIMESTAMP;
|
||||
case PG_TYPE_MONEY: return SQL_C_FLOAT;
|
||||
case PG_TYPE_BOOL: return globals.bools_as_char ? SQL_C_CHAR : SQL_C_BIT;
|
||||
case PG_TYPE_TIMESTAMP:
|
||||
return SQL_C_TIMESTAMP;
|
||||
case PG_TYPE_MONEY:
|
||||
return SQL_C_FLOAT;
|
||||
case PG_TYPE_BOOL:
|
||||
return globals.bools_as_char ? SQL_C_CHAR : SQL_C_BIT;
|
||||
|
||||
case PG_TYPE_BYTEA: return SQL_C_BINARY;
|
||||
case PG_TYPE_LO: return SQL_C_BINARY;
|
||||
case PG_TYPE_BYTEA:
|
||||
return SQL_C_BINARY;
|
||||
case PG_TYPE_LO:
|
||||
return SQL_C_BINARY;
|
||||
|
||||
default:
|
||||
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent type is available */
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent
|
||||
* type is available */
|
||||
return SQL_C_BINARY;
|
||||
|
||||
return SQL_C_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
char *pgtype_to_name(StatementClass *stmt, Int4 type)
|
||||
char *
|
||||
pgtype_to_name(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_CHAR:return "char";
|
||||
case PG_TYPE_CHAR2: return "char2";
|
||||
case PG_TYPE_CHAR4: return "char4";
|
||||
case PG_TYPE_CHAR8: return "char8";
|
||||
case PG_TYPE_INT8: return "int8";
|
||||
case PG_TYPE_NUMERIC: return "numeric";
|
||||
case PG_TYPE_VARCHAR: return "varchar";
|
||||
case PG_TYPE_BPCHAR: return "char";
|
||||
case PG_TYPE_TEXT: return "text";
|
||||
case PG_TYPE_NAME: return "name";
|
||||
case PG_TYPE_INT2: return "int2";
|
||||
case PG_TYPE_OID: return "oid";
|
||||
case PG_TYPE_INT4: return "int4";
|
||||
case PG_TYPE_FLOAT4: return "float4";
|
||||
case PG_TYPE_FLOAT8: return "float8";
|
||||
case PG_TYPE_DATE: return "date";
|
||||
case PG_TYPE_TIME: return "time";
|
||||
case PG_TYPE_ABSTIME: return "abstime";
|
||||
case PG_TYPE_DATETIME: return "datetime";
|
||||
case PG_TYPE_TIMESTAMP: return "timestamp";
|
||||
case PG_TYPE_MONEY: return "money";
|
||||
case PG_TYPE_BOOL: return "bool";
|
||||
case PG_TYPE_BYTEA: return "bytea";
|
||||
case PG_TYPE_CHAR2:
|
||||
return "char2";
|
||||
case PG_TYPE_CHAR4:
|
||||
return "char4";
|
||||
case PG_TYPE_CHAR8:
|
||||
return "char8";
|
||||
case PG_TYPE_INT8:
|
||||
return "int8";
|
||||
case PG_TYPE_NUMERIC:
|
||||
return "numeric";
|
||||
case PG_TYPE_VARCHAR:
|
||||
return "varchar";
|
||||
case PG_TYPE_BPCHAR:
|
||||
return "char";
|
||||
case PG_TYPE_TEXT:
|
||||
return "text";
|
||||
case PG_TYPE_NAME:
|
||||
return "name";
|
||||
case PG_TYPE_INT2:
|
||||
return "int2";
|
||||
case PG_TYPE_OID:
|
||||
return "oid";
|
||||
case PG_TYPE_INT4:
|
||||
return "int4";
|
||||
case PG_TYPE_FLOAT4:
|
||||
return "float4";
|
||||
case PG_TYPE_FLOAT8:
|
||||
return "float8";
|
||||
case PG_TYPE_DATE:
|
||||
return "date";
|
||||
case PG_TYPE_TIME:
|
||||
return "time";
|
||||
case PG_TYPE_ABSTIME:
|
||||
return "abstime";
|
||||
case PG_TYPE_DATETIME:
|
||||
return "datetime";
|
||||
case PG_TYPE_TIMESTAMP:
|
||||
return "timestamp";
|
||||
case PG_TYPE_MONEY:
|
||||
return "money";
|
||||
case PG_TYPE_BOOL:
|
||||
return "bool";
|
||||
case PG_TYPE_BYTEA:
|
||||
return "bytea";
|
||||
|
||||
case PG_TYPE_LO: return PG_TYPE_LO_NAME;
|
||||
|
||||
default:
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent type is available */
|
||||
case PG_TYPE_LO:
|
||||
return PG_TYPE_LO_NAME;
|
||||
|
||||
/* "unknown" can actually be used in alter table because it is a real PG type! */
|
||||
default:
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent
|
||||
* type is available */
|
||||
return PG_TYPE_LO_NAME;
|
||||
|
||||
/*
|
||||
* "unknown" can actually be used in alter table because it is
|
||||
* a real PG type!
|
||||
*/
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
@ -326,8 +393,12 @@ mylog("getNumericScale: type=%d, col=%d, unknown = %d\n", type,col);
|
||||
|
||||
result = SC_get_Result(stmt);
|
||||
|
||||
/* Manual Result Sets -- use assigned column width (i.e., from set_tuplefield_string) */
|
||||
if (stmt->manual_result) {
|
||||
/*
|
||||
* Manual Result Sets -- use assigned column width (i.e., from
|
||||
* set_tuplefield_string)
|
||||
*/
|
||||
if (stmt->manual_result)
|
||||
{
|
||||
flds = result->fields;
|
||||
if (flds)
|
||||
return flds->adtsize[col];
|
||||
@ -358,8 +429,12 @@ mylog("getNumericPrecision: type=%d, col=%d, unknown = %d\n", type,col);
|
||||
|
||||
result = SC_get_Result(stmt);
|
||||
|
||||
/* Manual Result Sets -- use assigned column width (i.e., from set_tuplefield_string) */
|
||||
if (stmt->manual_result) {
|
||||
/*
|
||||
* Manual Result Sets -- use assigned column width (i.e., from
|
||||
* set_tuplefield_string)
|
||||
*/
|
||||
if (stmt->manual_result)
|
||||
{
|
||||
flds = result->fields;
|
||||
if (flds)
|
||||
return flds->adtsize[col];
|
||||
@ -379,14 +454,16 @@ mylog("getNumericPrecision: type=%d, col=%d, unknown = %d\n", type,col);
|
||||
Int4
|
||||
getCharPrecision(StatementClass * stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
{
|
||||
int p = -1, maxsize;
|
||||
int p = -1,
|
||||
maxsize;
|
||||
QResultClass *result;
|
||||
ColumnInfoClass *flds;
|
||||
|
||||
mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type, col, handle_unknown_size_as);
|
||||
|
||||
/* Assign Maximum size based on parameters */
|
||||
switch(type) {
|
||||
switch (type)
|
||||
{
|
||||
case PG_TYPE_TEXT:
|
||||
if (globals.text_as_longvarchar)
|
||||
maxsize = globals.max_longvarchar_size;
|
||||
@ -407,16 +484,21 @@ mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type,col,handle_unkno
|
||||
break;
|
||||
}
|
||||
|
||||
/* Static Precision (i.e., the Maximum Precision of the datatype)
|
||||
This has nothing to do with a result set.
|
||||
/*
|
||||
* Static Precision (i.e., the Maximum Precision of the datatype) This
|
||||
* has nothing to do with a result set.
|
||||
*/
|
||||
if (col < 0)
|
||||
return maxsize;
|
||||
|
||||
result = SC_get_Result(stmt);
|
||||
|
||||
/* Manual Result Sets -- use assigned column width (i.e., from set_tuplefield_string) */
|
||||
if (stmt->manual_result) {
|
||||
/*
|
||||
* Manual Result Sets -- use assigned column width (i.e., from
|
||||
* set_tuplefield_string)
|
||||
*/
|
||||
if (stmt->manual_result)
|
||||
{
|
||||
flds = result->fields;
|
||||
if (flds)
|
||||
return flds->adtsize[col];
|
||||
@ -428,7 +510,8 @@ mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type,col,handle_unkno
|
||||
if (QR_get_atttypmod(result, col) > -1)
|
||||
return QR_get_atttypmod(result, col);
|
||||
|
||||
if (type == PG_TYPE_BPCHAR || handle_unknown_size_as == UNKNOWNS_AS_LONGEST) {
|
||||
if (type == PG_TYPE_BPCHAR || handle_unknown_size_as == UNKNOWNS_AS_LONGEST)
|
||||
{
|
||||
p = QR_get_display_size(result, col);
|
||||
mylog("getCharPrecision: LONGEST: p = %d\n", p);
|
||||
}
|
||||
@ -445,47 +528,65 @@ mylog("getCharPrecision: type=%d, col=%d, unknown = %d\n", type,col,handle_unkno
|
||||
If col >= 0, then will attempt to get the info from the result set.
|
||||
This is used for functions SQLDescribeCol and SQLColAttributes.
|
||||
*/
|
||||
Int4 pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
Int4
|
||||
pgtype_precision(StatementClass * stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case PG_TYPE_CHAR:return 1;
|
||||
case PG_TYPE_CHAR2: return 2;
|
||||
case PG_TYPE_CHAR4: return 4;
|
||||
case PG_TYPE_CHAR8: return 8;
|
||||
case PG_TYPE_CHAR2:
|
||||
return 2;
|
||||
case PG_TYPE_CHAR4:
|
||||
return 4;
|
||||
case PG_TYPE_CHAR8:
|
||||
return 8;
|
||||
|
||||
case PG_TYPE_NAME: return NAME_FIELD_SIZE;
|
||||
case PG_TYPE_NAME:
|
||||
return NAME_FIELD_SIZE;
|
||||
|
||||
case PG_TYPE_INT2: return 5;
|
||||
case PG_TYPE_INT2:
|
||||
return 5;
|
||||
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID:
|
||||
case PG_TYPE_INT4: return 10;
|
||||
case PG_TYPE_INT4:
|
||||
return 10;
|
||||
|
||||
case PG_TYPE_INT8: return 19; /* signed */
|
||||
case PG_TYPE_INT8:
|
||||
return 19; /* signed */
|
||||
|
||||
case PG_TYPE_NUMERIC: return getNumericPrecision(stmt,type,col);
|
||||
case PG_TYPE_NUMERIC:
|
||||
return getNumericPrecision(stmt, type, col);
|
||||
|
||||
case PG_TYPE_FLOAT4:
|
||||
case PG_TYPE_MONEY: return 7;
|
||||
case PG_TYPE_MONEY:
|
||||
return 7;
|
||||
|
||||
case PG_TYPE_FLOAT8: return 15;
|
||||
case PG_TYPE_FLOAT8:
|
||||
return 15;
|
||||
|
||||
case PG_TYPE_DATE: return 10;
|
||||
case PG_TYPE_TIME: return 8;
|
||||
case PG_TYPE_DATE:
|
||||
return 10;
|
||||
case PG_TYPE_TIME:
|
||||
return 8;
|
||||
|
||||
case PG_TYPE_ABSTIME:
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP: return 19;
|
||||
case PG_TYPE_TIMESTAMP:
|
||||
return 19;
|
||||
|
||||
case PG_TYPE_BOOL: return 1;
|
||||
case PG_TYPE_BOOL:
|
||||
return 1;
|
||||
|
||||
case PG_TYPE_LO: return SQL_NO_TOTAL;
|
||||
case PG_TYPE_LO:
|
||||
return SQL_NO_TOTAL;
|
||||
|
||||
default:
|
||||
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent type is available */
|
||||
if (type == stmt->hdbc->lobj_type) /* hack until permanent
|
||||
* type is available */
|
||||
return SQL_NO_TOTAL;
|
||||
|
||||
/* Handle Character types and unknown types */
|
||||
@ -493,26 +594,35 @@ Int4 pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unkno
|
||||
}
|
||||
}
|
||||
|
||||
Int4 pgtype_display_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
Int4
|
||||
pgtype_display_size(StatementClass * stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
switch (type)
|
||||
{
|
||||
case PG_TYPE_INT2:return 6;
|
||||
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID: return 10;
|
||||
case PG_TYPE_XID:
|
||||
return 10;
|
||||
|
||||
case PG_TYPE_INT4: return 11;
|
||||
case PG_TYPE_INT4:
|
||||
return 11;
|
||||
|
||||
case PG_TYPE_INT8: return 20; /* signed: 19 digits + sign */
|
||||
case PG_TYPE_INT8:
|
||||
return 20; /* signed: 19 digits + sign */
|
||||
|
||||
case PG_TYPE_NUMERIC: return getNumericPrecision(stmt,type,col) + 2;
|
||||
case PG_TYPE_NUMERIC:
|
||||
return getNumericPrecision(stmt, type, col) + 2;
|
||||
|
||||
case PG_TYPE_MONEY: return 15; /* ($9,999,999.99) */
|
||||
case PG_TYPE_MONEY:
|
||||
return 15; /* ($9,999,999.99) */
|
||||
|
||||
case PG_TYPE_FLOAT4: return 13;
|
||||
case PG_TYPE_FLOAT4:
|
||||
return 13;
|
||||
|
||||
case PG_TYPE_FLOAT8: return 22;
|
||||
case PG_TYPE_FLOAT8:
|
||||
return 22;
|
||||
|
||||
/* Character types use regular precision */
|
||||
default:
|
||||
@ -523,32 +633,41 @@ Int4 pgtype_display_size(StatementClass *stmt, Int4 type, int col, int handle_un
|
||||
/* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, SQLColumns will
|
||||
override this length with the atttypmod length from pg_attribute
|
||||
*/
|
||||
Int4 pgtype_length(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
Int4
|
||||
pgtype_length(StatementClass * stmt, Int4 type, int col, int handle_unknown_size_as)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case PG_TYPE_INT2:return 2;
|
||||
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID:
|
||||
case PG_TYPE_INT4: return 4;
|
||||
case PG_TYPE_INT4:
|
||||
return 4;
|
||||
|
||||
case PG_TYPE_INT8: return 20; /* signed: 19 digits + sign */
|
||||
case PG_TYPE_INT8:
|
||||
return 20; /* signed: 19 digits + sign */
|
||||
|
||||
case PG_TYPE_NUMERIC: return getNumericPrecision(stmt,type,col) + 2;
|
||||
case PG_TYPE_NUMERIC:
|
||||
return getNumericPrecision(stmt, type, col) + 2;
|
||||
|
||||
case PG_TYPE_FLOAT4:
|
||||
case PG_TYPE_MONEY: return 4;
|
||||
case PG_TYPE_MONEY:
|
||||
return 4;
|
||||
|
||||
case PG_TYPE_FLOAT8: return 8;
|
||||
case PG_TYPE_FLOAT8:
|
||||
return 8;
|
||||
|
||||
case PG_TYPE_DATE:
|
||||
case PG_TYPE_TIME: return 6;
|
||||
case PG_TYPE_TIME:
|
||||
return 6;
|
||||
|
||||
case PG_TYPE_ABSTIME:
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP: return 16;
|
||||
case PG_TYPE_TIMESTAMP:
|
||||
return 16;
|
||||
|
||||
|
||||
/* Character types (and NUMERIC) use the default precision */
|
||||
@ -557,9 +676,11 @@ Int4 pgtype_length(StatementClass *stmt, Int4 type, int col, int handle_unknown_
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_scale(StatementClass *stmt, Int4 type, int col)
|
||||
Int2
|
||||
pgtype_scale(StatementClass * stmt, Int4 type, int col)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
|
||||
case PG_TYPE_INT2:
|
||||
case PG_TYPE_OID:
|
||||
@ -571,21 +692,28 @@ Int2 pgtype_scale(StatementClass *stmt, Int4 type, int col)
|
||||
case PG_TYPE_MONEY:
|
||||
case PG_TYPE_BOOL:
|
||||
|
||||
/* Number of digits to the right of the decimal point in "yyyy-mm=dd hh:mm:ss[.f...]" */
|
||||
/*
|
||||
* Number of digits to the right of the decimal point in
|
||||
* "yyyy-mm=dd hh:mm:ss[.f...]"
|
||||
*/
|
||||
case PG_TYPE_ABSTIME:
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP:return 0;
|
||||
|
||||
case PG_TYPE_NUMERIC: return getNumericScale(stmt,type,col);
|
||||
case PG_TYPE_NUMERIC:
|
||||
return getNumericScale(stmt, type, col);
|
||||
|
||||
default: return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Int2 pgtype_radix(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_radix(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_INT2:
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_INT4:
|
||||
@ -595,18 +723,22 @@ Int2 pgtype_radix(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_MONEY:
|
||||
case PG_TYPE_FLOAT8:return 10;
|
||||
|
||||
default: return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_nullable(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_nullable(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
return SQL_NULLABLE; /* everything should be nullable */
|
||||
}
|
||||
|
||||
Int2 pgtype_auto_increment(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_auto_increment(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
|
||||
case PG_TYPE_INT2:
|
||||
case PG_TYPE_OID:
|
||||
@ -625,13 +757,16 @@ Int2 pgtype_auto_increment(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_DATETIME:
|
||||
case PG_TYPE_TIMESTAMP:return FALSE;
|
||||
|
||||
default: return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_case_sensitive(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_case_sensitive(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_CHAR:
|
||||
|
||||
case PG_TYPE_CHAR2:
|
||||
@ -643,21 +778,27 @@ Int2 pgtype_case_sensitive(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_TEXT:
|
||||
case PG_TYPE_NAME:return TRUE;
|
||||
|
||||
default: return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_money(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_money(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_MONEY:return TRUE;
|
||||
default: return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_searchable(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_searchable(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_CHAR:
|
||||
case PG_TYPE_CHAR2:
|
||||
case PG_TYPE_CHAR4:
|
||||
@ -668,13 +809,16 @@ Int2 pgtype_searchable(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_TEXT:
|
||||
case PG_TYPE_NAME:return SQL_SEARCHABLE;
|
||||
|
||||
default: return SQL_ALL_EXCEPT_LIKE;
|
||||
default:
|
||||
return SQL_ALL_EXCEPT_LIKE;
|
||||
}
|
||||
}
|
||||
|
||||
Int2 pgtype_unsigned(StatementClass *stmt, Int4 type)
|
||||
Int2
|
||||
pgtype_unsigned(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_OID:
|
||||
case PG_TYPE_XID:return TRUE;
|
||||
|
||||
@ -684,15 +828,19 @@ Int2 pgtype_unsigned(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_NUMERIC:
|
||||
case PG_TYPE_FLOAT4:
|
||||
case PG_TYPE_FLOAT8:
|
||||
case PG_TYPE_MONEY: return FALSE;
|
||||
case PG_TYPE_MONEY:
|
||||
return FALSE;
|
||||
|
||||
default: return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
char *pgtype_literal_prefix(StatementClass *stmt, Int4 type)
|
||||
char *
|
||||
pgtype_literal_prefix(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
|
||||
case PG_TYPE_INT2:
|
||||
case PG_TYPE_OID:
|
||||
@ -704,13 +852,16 @@ char *pgtype_literal_prefix(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_FLOAT8:
|
||||
case PG_TYPE_MONEY:return NULL;
|
||||
|
||||
default: return "'";
|
||||
default:
|
||||
return "'";
|
||||
}
|
||||
}
|
||||
|
||||
char *pgtype_literal_suffix(StatementClass *stmt, Int4 type)
|
||||
char *
|
||||
pgtype_literal_suffix(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
|
||||
case PG_TYPE_INT2:
|
||||
case PG_TYPE_OID:
|
||||
@ -722,25 +873,31 @@ char *pgtype_literal_suffix(StatementClass *stmt, Int4 type)
|
||||
case PG_TYPE_FLOAT8:
|
||||
case PG_TYPE_MONEY:return NULL;
|
||||
|
||||
default: return "'";
|
||||
default:
|
||||
return "'";
|
||||
}
|
||||
}
|
||||
|
||||
char *pgtype_create_params(StatementClass *stmt, Int4 type)
|
||||
char *
|
||||
pgtype_create_params(StatementClass * stmt, Int4 type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
switch(type) {
|
||||
case PG_TYPE_CHAR:
|
||||
case PG_TYPE_VARCHAR:return "max. length";
|
||||
default: return NULL;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Int2 sqltype_to_default_ctype(Int2 sqltype)
|
||||
Int2
|
||||
sqltype_to_default_ctype(Int2 sqltype)
|
||||
{
|
||||
/* from the table on page 623 of ODBC 2.0 Programmer's Reference */
|
||||
/* (Appendix D) */
|
||||
switch(sqltype) {
|
||||
switch (sqltype)
|
||||
{
|
||||
case SQL_CHAR:
|
||||
case SQL_VARCHAR:
|
||||
case SQL_LONGVARCHAR:
|
||||
@ -786,4 +943,3 @@ Int2 sqltype_to_default_ctype(Int2 sqltype)
|
||||
return SQL_C_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,4 +95,3 @@ char *pgtype_create_params(StatementClass *stmt, Int4 type);
|
||||
Int2 sqltype_to_default_ctype(Int2 sqltype);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -38,12 +38,14 @@ RETCODE SQL_API SQLDummyOrdinal(void);
|
||||
HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
||||
|
||||
/* This is where the Driver Manager attaches to this Driver */
|
||||
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
||||
BOOL WINAPI
|
||||
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
|
||||
switch (ul_reason_for_call) {
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
s_hModule = hInst; /* Save for dialog boxes */
|
||||
|
||||
@ -55,7 +57,8 @@ WSADATA wsaData;
|
||||
|
||||
/* Verify that this is the minimum version of WinSock */
|
||||
if (LOBYTE(wsaData.wVersion) != 1 ||
|
||||
HIBYTE( wsaData.wVersion ) != 1 ) {
|
||||
HIBYTE(wsaData.wVersion) != 1)
|
||||
{
|
||||
|
||||
WSACleanup();
|
||||
return FALSE;
|
||||
@ -134,8 +137,8 @@ _fini(void)
|
||||
Driver Manager do this. Also, the ordinal values of the
|
||||
functions must match the value of fFunction in SQLGetFunctions()
|
||||
*/
|
||||
RETCODE SQL_API SQLDummyOrdinal(void)
|
||||
RETCODE SQL_API
|
||||
SQLDummyOrdinal(void)
|
||||
{
|
||||
return SQL_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Comments: See "notice.txt" for copyright and license information.
|
||||
*
|
||||
* $Id: psqlodbc.h,v 1.31 2001/02/10 06:57:53 momjian Exp $
|
||||
* $Id: psqlodbc.h,v 1.32 2001/02/10 07:01:19 momjian Exp $
|
||||
*/
|
||||
|
||||
#ifndef __PSQLODBC_H__
|
||||
@ -25,6 +25,7 @@
|
||||
#define UInt2 unsigned short
|
||||
typedef float SFLOAT;
|
||||
typedef double SDOUBLE;
|
||||
|
||||
#else
|
||||
#define Int4 int
|
||||
#define UInt4 unsigned int
|
||||
@ -54,14 +55,18 @@ typedef UInt4 Oid;
|
||||
#define BLCKSZ 4096
|
||||
#endif
|
||||
|
||||
#define MAX_MESSAGE_LEN 65536 /* This puts a limit on query size but I don't */
|
||||
#define MAX_MESSAGE_LEN 65536 /* This puts a limit on
|
||||
* query size but I don't */
|
||||
/* see an easy way round this - DJP 24-1-2001 */
|
||||
#define MAX_CONNECT_STRING 4096
|
||||
#define ERROR_MSG_LENGTH 4096
|
||||
#define FETCH_MAX 100 /* default number of rows to cache for declare/fetch */
|
||||
#define FETCH_MAX 100 /* default number of rows to cache
|
||||
* for declare/fetch */
|
||||
#define TUPLE_MALLOC_INC 100
|
||||
#define SOCK_BUFFER_SIZE 4096 /* default socket buffer size */
|
||||
#define MAX_CONNECTIONS 128 /* conns per environment (arbitrary) */
|
||||
#define SOCK_BUFFER_SIZE 4096 /* default socket buffer
|
||||
* size */
|
||||
#define MAX_CONNECTIONS 128 /* conns per environment
|
||||
* (arbitrary) */
|
||||
#define MAX_FIELDS 512
|
||||
#define BYTELEN 8
|
||||
#define VARHDRSZ sizeof(Int4)
|
||||
@ -72,7 +77,8 @@ typedef UInt4 Oid;
|
||||
|
||||
/* Registry length limits */
|
||||
#define LARGE_REGISTRY_LEN 4096 /* used for special cases */
|
||||
#define MEDIUM_REGISTRY_LEN 256 /* normal size for user,database,etc. */
|
||||
#define MEDIUM_REGISTRY_LEN 256 /* normal size for
|
||||
* user,database,etc. */
|
||||
#define SMALL_REGISTRY_LEN 10 /* for 1/0 settings */
|
||||
|
||||
|
||||
@ -83,8 +89,10 @@ typedef UInt4 Oid;
|
||||
/* Info limits */
|
||||
#define MAX_INFO_STRING 128
|
||||
#define MAX_KEYPARTS 20
|
||||
#define MAX_KEYLEN 512 /* max key of the form "date+outlet+invoice" */
|
||||
#define MAX_ROW_SIZE 0 /* Unlimited rowsize with the Tuple Toaster */
|
||||
#define MAX_KEYLEN 512 /* max key of the form
|
||||
* "date+outlet+invoice" */
|
||||
#define MAX_ROW_SIZE 0 /* Unlimited rowsize with the Tuple
|
||||
* Toaster */
|
||||
#define MAX_STATEMENT_LEN 0 /* Unlimited statement size with 7.0 */
|
||||
|
||||
/* Previously, numerous query strings were defined of length MAX_STATEMENT_LEN */
|
||||
@ -120,7 +128,8 @@ typedef struct GlobalValues_
|
||||
char disable_optimizer;
|
||||
char ksqo;
|
||||
char unique_index;
|
||||
char onlyread; /* readonly is reserved on Digital C++ compiler */
|
||||
char onlyread; /* readonly is reserved on Digital C++
|
||||
* compiler */
|
||||
char use_declarefetch;
|
||||
char text_as_longvarchar;
|
||||
char unknowns_as_longvarchar;
|
||||
@ -130,15 +139,18 @@ typedef struct GlobalValues_
|
||||
char cancel_as_freestmt;
|
||||
char extra_systable_prefixes[MEDIUM_REGISTRY_LEN];
|
||||
char conn_settings[LARGE_REGISTRY_LEN];
|
||||
/* Protocol is not used anymore, but kept in case
|
||||
* it is useful in the future. bjm 2001-02-10
|
||||
|
||||
/*
|
||||
* Protocol is not used anymore, but kept in case it is useful in the
|
||||
* future. bjm 2001-02-10
|
||||
*/
|
||||
char protocol[SMALL_REGISTRY_LEN];
|
||||
FILE *mylogFP;
|
||||
FILE *qlogFP;
|
||||
} GLOBAL_VALUES;
|
||||
|
||||
typedef struct StatementOptions_ {
|
||||
typedef struct StatementOptions_
|
||||
{
|
||||
int maxRows;
|
||||
int maxLength;
|
||||
int rowset_size;
|
||||
@ -146,26 +158,32 @@ typedef struct StatementOptions_ {
|
||||
int cursor_type;
|
||||
int scroll_concurrency;
|
||||
int retrieve_data;
|
||||
int bind_size; /* size of each structure if using Row Binding */
|
||||
int bind_size; /* size of each structure if using Row
|
||||
* Binding */
|
||||
int use_bookmarks;
|
||||
} StatementOptions;
|
||||
|
||||
/* Used to pass extra query info to send_query */
|
||||
typedef struct QueryInfo_ {
|
||||
typedef struct QueryInfo_
|
||||
{
|
||||
int row_size;
|
||||
QResultClass *result_in;
|
||||
char *cursor;
|
||||
} QueryInfo;
|
||||
|
||||
|
||||
#define PG_TYPE_LO -999 /* hack until permanent type available */
|
||||
#define PG_TYPE_LO -999 /* hack until permanent type
|
||||
* available */
|
||||
#define PG_TYPE_LO_NAME "lo"
|
||||
#define OID_ATTNUM -2 /* the attnum in pg_index of the oid */
|
||||
#define OID_ATTNUM -2 /* the attnum in pg_index of the
|
||||
* oid */
|
||||
|
||||
/* sizes */
|
||||
#define TEXT_FIELD_SIZE 8190 /* size of text fields (not including null term) */
|
||||
#define TEXT_FIELD_SIZE 8190 /* size of text fields (not
|
||||
* including null term) */
|
||||
#define NAME_FIELD_SIZE 32 /* size of name fields */
|
||||
#define MAX_VARCHAR_SIZE 254 /* maximum size of a varchar (not including null term) */
|
||||
#define MAX_VARCHAR_SIZE 254 /* maximum size of a varchar (not
|
||||
* including null term) */
|
||||
|
||||
#define PG_NUMERIC_MAX_PRECISION 1000
|
||||
#define PG_NUMERIC_MAX_SCALE 1000
|
||||
|
@ -83,11 +83,13 @@ QResultClass *rv;
|
||||
mylog("in QR_Constructor\n");
|
||||
rv = (QResultClass *) malloc(sizeof(QResultClass));
|
||||
|
||||
if (rv != NULL) {
|
||||
if (rv != NULL)
|
||||
{
|
||||
rv->status = PGRES_EMPTY_QUERY;
|
||||
|
||||
/* construct the column info */
|
||||
if ( ! (rv->fields = CI_Constructor())) {
|
||||
if (!(rv->fields = CI_Constructor()))
|
||||
{
|
||||
free(rv);
|
||||
return NULL;
|
||||
}
|
||||
@ -174,19 +176,24 @@ QR_set_notice(QResultClass *self, char *msg)
|
||||
void
|
||||
QR_free_memory(QResultClass * self)
|
||||
{
|
||||
register int lf, row;
|
||||
register int lf,
|
||||
row;
|
||||
register TupleField *tuple = self->backend_tuples;
|
||||
int fcount = self->fcount;
|
||||
int num_fields = self->num_fields;
|
||||
|
||||
mylog("QResult: free memory in, fcount=%d\n", fcount);
|
||||
|
||||
if ( self->backend_tuples) {
|
||||
if (self->backend_tuples)
|
||||
{
|
||||
|
||||
for (row = 0; row < fcount; row++) {
|
||||
for (row = 0; row < fcount; row++)
|
||||
{
|
||||
mylog("row = %d, num_fields = %d\n", row, num_fields);
|
||||
for (lf=0; lf < num_fields; lf++) {
|
||||
if (tuple[lf].value != NULL) {
|
||||
for (lf = 0; lf < num_fields; lf++)
|
||||
{
|
||||
if (tuple[lf].value != NULL)
|
||||
{
|
||||
mylog("free [lf=%d] %u\n", lf, tuple[lf].value);
|
||||
free(tuple[lf].value);
|
||||
}
|
||||
@ -214,7 +221,8 @@ int tuple_size;
|
||||
/* and read the tuples. If conn is NULL, */
|
||||
/* it implies that we are being called from next_tuple(), */
|
||||
/* like to get more rows so don't call next_tuple again! */
|
||||
if (conn != NULL) {
|
||||
if (conn != NULL)
|
||||
{
|
||||
self->conn = conn;
|
||||
|
||||
mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor == NULL) ? "" : cursor, self->cursor);
|
||||
@ -222,8 +230,10 @@ int tuple_size;
|
||||
if (self->cursor)
|
||||
free(self->cursor);
|
||||
|
||||
if ( globals.use_declarefetch) {
|
||||
if (! cursor || cursor[0] == '\0') {
|
||||
if (globals.use_declarefetch)
|
||||
{
|
||||
if (!cursor || cursor[0] == '\0')
|
||||
{
|
||||
self->status = PGRES_INTERNAL_ERROR;
|
||||
QR_set_message(self, "Internal Error -- no cursor for fetch");
|
||||
return FALSE;
|
||||
@ -233,11 +243,13 @@ int tuple_size;
|
||||
|
||||
/* Read the field attributes. */
|
||||
/* $$$$ Should do some error control HERE! $$$$ */
|
||||
if ( CI_read_fields(self->fields, self->conn)) {
|
||||
if (CI_read_fields(self->fields, self->conn))
|
||||
{
|
||||
self->status = PGRES_FIELDS_OK;
|
||||
self->num_fields = CI_get_num_fields(self->fields);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
self->status = PGRES_BAD_RESPONSE;
|
||||
QR_set_message(self, "Error reading field information");
|
||||
return FALSE;
|
||||
@ -253,7 +265,8 @@ int tuple_size;
|
||||
/* allocate memory for the tuple cache */
|
||||
mylog("MALLOC: tuple_size = %d, size = %d\n", tuple_size, self->num_fields * sizeof(TupleField) * tuple_size);
|
||||
self->backend_tuples = (TupleField *) malloc(self->num_fields * sizeof(TupleField) * tuple_size);
|
||||
if ( ! self->backend_tuples) {
|
||||
if (!self->backend_tuples)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Could not get memory for tuple cache.");
|
||||
return FALSE;
|
||||
@ -269,12 +282,14 @@ int tuple_size;
|
||||
|
||||
return QR_next_tuple(self);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
|
||||
/* Always have to read the field attributes. */
|
||||
/* But we dont have to reallocate memory for them! */
|
||||
|
||||
if ( ! CI_read_fields(NULL, self->conn)) {
|
||||
if (!CI_read_fields(NULL, self->conn))
|
||||
{
|
||||
self->status = PGRES_BAD_RESPONSE;
|
||||
QR_set_message(self, "Error reading field information");
|
||||
return FALSE;
|
||||
@ -290,7 +305,8 @@ QR_close(QResultClass *self)
|
||||
{
|
||||
QResultClass *res;
|
||||
|
||||
if (globals.use_declarefetch && self->conn && self->cursor) {
|
||||
if (globals.use_declarefetch && self->conn && self->cursor)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
sprintf(buf, "close %s", self->cursor);
|
||||
@ -304,21 +320,24 @@ QResultClass *res;
|
||||
free(self->cursor);
|
||||
self->cursor = NULL;
|
||||
|
||||
if (res == NULL) {
|
||||
if (res == NULL)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Error closing cursor.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* End the transaction if there are no cursors left on this conn */
|
||||
if (CC_cursor_count(self->conn) == 0) {
|
||||
if (CC_cursor_count(self->conn) == 0)
|
||||
{
|
||||
mylog("QResult: END transaction on conn=%u\n", self->conn);
|
||||
|
||||
res = CC_send_query(self->conn, "END", NULL);
|
||||
|
||||
CC_set_no_trans(self->conn);
|
||||
|
||||
if (res == NULL) {
|
||||
if (res == NULL)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Error ending transaction.");
|
||||
return FALSE;
|
||||
@ -337,49 +356,60 @@ QR_next_tuple(QResultClass *self)
|
||||
int id;
|
||||
QResultClass *res;
|
||||
SocketClass *sock;
|
||||
|
||||
/* Speed up access */
|
||||
int fetch_count = self->fetch_count;
|
||||
int fcount = self->fcount;
|
||||
int fetch_size, offset= 0;
|
||||
int fetch_size,
|
||||
offset = 0;
|
||||
int end_tuple = self->rowset_size + self->base;
|
||||
char corrected = FALSE;
|
||||
TupleField *the_tuples = self->backend_tuples;
|
||||
static char msgbuffer[MAX_MESSAGE_LEN + 1];
|
||||
char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont need static */
|
||||
char cmdbuffer[MAX_MESSAGE_LEN + 1]; /* QR_set_command() dups
|
||||
* this string so dont
|
||||
* need static */
|
||||
char fetch[128];
|
||||
QueryInfo qi;
|
||||
|
||||
if (fetch_count < fcount) { /* return a row from cache */
|
||||
if (fetch_count < fcount)
|
||||
{ /* return a row from cache */
|
||||
mylog("next_tuple: fetch_count < fcount: returning tuple %d, fcount = %d\n", fetch_count, fcount);
|
||||
self->tupleField = the_tuples + (fetch_count * self->num_fields); /* next row */
|
||||
self->fetch_count++;
|
||||
return TRUE;
|
||||
}
|
||||
else if (self->fcount < self->cache_size) { /* last row from cache */
|
||||
else if (self->fcount < self->cache_size)
|
||||
{ /* last row from cache */
|
||||
/* We are done because we didn't even get CACHE_SIZE tuples */
|
||||
mylog("next_tuple: fcount < CACHE_SIZE: fcount = %d, fetch_count = %d\n", fcount, fetch_count);
|
||||
self->tupleField = NULL;
|
||||
self->status = PGRES_END_TUPLES;
|
||||
return -1; /* end of tuples */
|
||||
}
|
||||
else {
|
||||
/* See if we need to fetch another group of rows.
|
||||
We may be being called from send_query(), and
|
||||
if so, don't send another fetch, just fall through
|
||||
and read the tuples.
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* See if we need to fetch another group of rows. We may be being
|
||||
* called from send_query(), and if so, don't send another fetch,
|
||||
* just fall through and read the tuples.
|
||||
*/
|
||||
self->tupleField = NULL;
|
||||
|
||||
if ( ! self->inTuples) {
|
||||
if (!self->inTuples)
|
||||
{
|
||||
|
||||
if ( ! globals.use_declarefetch) {
|
||||
if (!globals.use_declarefetch)
|
||||
{
|
||||
mylog("next_tuple: ALL_ROWS: done, fcount = %d, fetch_count = %d\n", fcount, fetch_count);
|
||||
self->tupleField = NULL;
|
||||
self->status = PGRES_END_TUPLES;
|
||||
return -1; /* end of tuples */
|
||||
}
|
||||
|
||||
if (self->base == fcount) { /* not a correction */
|
||||
if (self->base == fcount)
|
||||
{ /* not a correction */
|
||||
|
||||
/* Determine the optimum cache size. */
|
||||
if (globals.fetch_max % self->rowset_size == 0)
|
||||
@ -392,7 +422,8 @@ QueryInfo qi;
|
||||
self->cache_size = fetch_size;
|
||||
self->fetch_count = 1;
|
||||
}
|
||||
else { /* need to correct */
|
||||
else
|
||||
{ /* need to correct */
|
||||
|
||||
corrected = TRUE;
|
||||
|
||||
@ -407,7 +438,8 @@ QueryInfo qi;
|
||||
|
||||
|
||||
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, self->num_fields * sizeof(TupleField) * self->cache_size);
|
||||
if ( ! self->backend_tuples) {
|
||||
if (!self->backend_tuples)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Out of memory while reading tuples.");
|
||||
return FALSE;
|
||||
@ -421,24 +453,29 @@ QueryInfo qi;
|
||||
qi.result_in = self;
|
||||
qi.cursor = NULL;
|
||||
res = CC_send_query(self->conn, fetch, &qi);
|
||||
if (res == NULL) {
|
||||
if (res == NULL)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Error fetching next group.");
|
||||
return FALSE;
|
||||
}
|
||||
self->inTuples = TRUE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mylog("next_tuple: inTuples = true, falling through: fcount = %d, fetch_count = %d\n", self->fcount, self->fetch_count);
|
||||
/* This is a pre-fetch (fetching rows right after query
|
||||
but before any real SQLFetch() calls. This is done
|
||||
so the field attributes are available.
|
||||
|
||||
/*
|
||||
* This is a pre-fetch (fetching rows right after query but
|
||||
* before any real SQLFetch() calls. This is done so the
|
||||
* field attributes are available.
|
||||
*/
|
||||
self->fetch_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! corrected) {
|
||||
if (!corrected)
|
||||
{
|
||||
self->base = 0;
|
||||
self->fcount = 0;
|
||||
}
|
||||
@ -447,11 +484,13 @@ QueryInfo qi;
|
||||
sock = CC_get_socket(self->conn);
|
||||
self->tupleField = NULL;
|
||||
|
||||
for ( ; ;) {
|
||||
for (;;)
|
||||
{
|
||||
|
||||
id = SOCK_get_char(sock);
|
||||
|
||||
switch (id) {
|
||||
switch (id)
|
||||
{
|
||||
case 'T': /* Tuples within tuples cannot be handled */
|
||||
self->status = PGRES_BAD_RESPONSE;
|
||||
QR_set_message(self, "Tuples within tuples cannot be handled");
|
||||
@ -459,19 +498,23 @@ QueryInfo qi;
|
||||
case 'B': /* Tuples in binary format */
|
||||
case 'D': /* Tuples in ASCII format */
|
||||
|
||||
if ( ! globals.use_declarefetch && self->fcount > 0 && ! (self->fcount % TUPLE_MALLOC_INC)) {
|
||||
if (!globals.use_declarefetch && self->fcount > 0 && !(self->fcount % TUPLE_MALLOC_INC))
|
||||
{
|
||||
size_t old_size = self->fcount * self->num_fields * sizeof(TupleField);
|
||||
|
||||
mylog("REALLOC: old_size = %d\n", old_size);
|
||||
|
||||
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, old_size + (self->num_fields * sizeof(TupleField) * TUPLE_MALLOC_INC));
|
||||
if ( ! self->backend_tuples) {
|
||||
if (!self->backend_tuples)
|
||||
{
|
||||
self->status = PGRES_FATAL_ERROR;
|
||||
QR_set_message(self, "Out of memory while reading tuples.");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! QR_read_tuple(self, (char) (id == 0))) {
|
||||
if (!QR_read_tuple(self, (char) (id == 0)))
|
||||
{
|
||||
self->status = PGRES_BAD_RESPONSE;
|
||||
QR_set_message(self, "Error reading the tuple");
|
||||
return FALSE;
|
||||
@ -488,7 +531,8 @@ QueryInfo qi;
|
||||
mylog("end of tuple list -- setting inUse to false: this = %u\n", self);
|
||||
|
||||
self->inTuples = FALSE;
|
||||
if (self->fcount > 0) {
|
||||
if (self->fcount > 0)
|
||||
{
|
||||
|
||||
qlog(" [ fetched %d rows ]\n", self->fcount);
|
||||
mylog("_next_tuple: 'C' fetch_max && fcount = %d\n", self->fcount);
|
||||
@ -497,7 +541,9 @@ QueryInfo qi;
|
||||
self->tupleField = self->backend_tuples + (offset * self->num_fields);
|
||||
return TRUE;
|
||||
}
|
||||
else { /* We are surely done here (we read 0 tuples) */
|
||||
else
|
||||
{ /* We are surely done here (we read 0
|
||||
* tuples) */
|
||||
qlog(" [ fetched 0 rows ]\n");
|
||||
mylog("_next_tuple: 'C': DONE (fcount == 0)\n");
|
||||
return -1; /* end of tuples */
|
||||
@ -522,7 +568,8 @@ QueryInfo qi;
|
||||
qlog("NOTICE from backend in next_tuple: '%s'\n", msgbuffer);
|
||||
continue;
|
||||
|
||||
default: /* this should only happen if the backend dumped core */
|
||||
default: /* this should only happen if the backend
|
||||
* dumped core */
|
||||
mylog("QR_next_tuple: Unexpected result from backend: id = '%c' (%d)\n", id, id);
|
||||
qlog("QR_next_tuple: Unexpected result from backend: id = '%c' (%d)\n", id, id);
|
||||
QR_set_message(self, "Unexpected result from backend. It probably crashed");
|
||||
@ -539,7 +586,8 @@ QR_read_tuple(QResultClass *self, char binary)
|
||||
{
|
||||
Int2 field_lf;
|
||||
TupleField *this_tuplefield;
|
||||
char bmp, bitmap[MAX_FIELDS]; /* Max. len of the bitmap */
|
||||
char bmp,
|
||||
bitmap[MAX_FIELDS]; /* Max. len of the bitmap */
|
||||
Int2 bitmaplen; /* len of the bitmap in bytes */
|
||||
Int2 bitmap_pos;
|
||||
Int2 bitcnt;
|
||||
@ -558,8 +606,8 @@ ColumnInfoClass *flds;
|
||||
bitmaplen++;
|
||||
|
||||
/*
|
||||
At first the server sends a bitmap that indicates which
|
||||
database fields are null
|
||||
* At first the server sends a bitmap that indicates which database
|
||||
* fields are null
|
||||
*/
|
||||
SOCK_get_n_char(sock, bitmap, bitmaplen);
|
||||
|
||||
@ -567,16 +615,21 @@ ColumnInfoClass *flds;
|
||||
bitcnt = 0;
|
||||
bmp = bitmap[bitmap_pos];
|
||||
|
||||
for(field_lf = 0; field_lf < num_fields; field_lf++) {
|
||||
for (field_lf = 0; field_lf < num_fields; field_lf++)
|
||||
{
|
||||
/* Check if the current field is NULL */
|
||||
if(!(bmp & 0200)) {
|
||||
if (!(bmp & 0200))
|
||||
{
|
||||
/* YES, it is NULL ! */
|
||||
this_tuplefield[field_lf].len = 0;
|
||||
this_tuplefield[field_lf].value = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
NO, the field is not null. so get at first the
|
||||
length of the field (four bytes)
|
||||
* NO, the field is not null. so get at first the length of
|
||||
* the field (four bytes)
|
||||
*/
|
||||
len = SOCK_get_int(sock, VARHDRSZ);
|
||||
if (!binary)
|
||||
@ -591,27 +644,31 @@ ColumnInfoClass *flds;
|
||||
this_tuplefield[field_lf].len = len;
|
||||
this_tuplefield[field_lf].value = buffer;
|
||||
|
||||
/* This can be used to set the longest length of the column for any
|
||||
row in the tuple cache. It would not be accurate for varchar and
|
||||
text fields to use this since a tuple cache is only 100 rows.
|
||||
Bpchar can be handled since the strlen of all rows is fixed,
|
||||
assuming there are not 100 nulls in a row!
|
||||
/*
|
||||
* This can be used to set the longest length of the column
|
||||
* for any row in the tuple cache. It would not be accurate
|
||||
* for varchar and text fields to use this since a tuple cache
|
||||
* is only 100 rows. Bpchar can be handled since the strlen of
|
||||
* all rows is fixed, assuming there are not 100 nulls in a
|
||||
* row!
|
||||
*/
|
||||
|
||||
flds = self->fields;
|
||||
if (flds->display_size[field_lf] < len)
|
||||
flds->display_size[field_lf] = len;
|
||||
}
|
||||
|
||||
/*
|
||||
Now adjust for the next bit to be scanned in the
|
||||
next loop.
|
||||
* Now adjust for the next bit to be scanned in the next loop.
|
||||
*/
|
||||
bitcnt++;
|
||||
if (BYTELEN == bitcnt) {
|
||||
if (BYTELEN == bitcnt)
|
||||
{
|
||||
bitmap_pos++;
|
||||
bmp = bitmap[bitmap_pos];
|
||||
bitcnt = 0;
|
||||
} else
|
||||
}
|
||||
else
|
||||
bmp <<= 1;
|
||||
}
|
||||
self->currTuple++;
|
||||
|
@ -17,7 +17,8 @@
|
||||
#include "psqlodbc.h"
|
||||
#include "tuple.h"
|
||||
|
||||
enum QueryResultCode_ {
|
||||
enum QueryResultCode_
|
||||
{
|
||||
PGRES_EMPTY_QUERY = 0,
|
||||
PGRES_COMMAND_OK, /* a query command that doesn't return */
|
||||
/* anything was executed properly by the backend */
|
||||
@ -26,20 +27,24 @@ enum QueryResultCode_ {
|
||||
/* contains the resulttuples */
|
||||
PGRES_COPY_OUT,
|
||||
PGRES_COPY_IN,
|
||||
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the backend */
|
||||
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from
|
||||
* the backend */
|
||||
PGRES_NONFATAL_ERROR,
|
||||
PGRES_FATAL_ERROR,
|
||||
PGRES_FIELDS_OK, /* field information from a query was successful */
|
||||
PGRES_FIELDS_OK, /* field information from a query was
|
||||
* successful */
|
||||
PGRES_END_TUPLES,
|
||||
PGRES_INTERNAL_ERROR
|
||||
};
|
||||
typedef enum QueryResultCode_ QueryResultCode;
|
||||
|
||||
|
||||
struct QResultClass_ {
|
||||
struct QResultClass_
|
||||
{
|
||||
ColumnInfoClass *fields; /* the Column information */
|
||||
TupleListClass *manual_tuples; /* manual result tuple list */
|
||||
ConnectionClass *conn; /* the connection this result is using (backend) */
|
||||
ConnectionClass *conn; /* the connection this result is using
|
||||
* (backend) */
|
||||
|
||||
/* Stuff for declare/fetch tuples */
|
||||
int fetch_count; /* logical rows read so far */
|
||||
@ -54,14 +59,16 @@ struct QResultClass_ {
|
||||
QueryResultCode status;
|
||||
|
||||
char *message;
|
||||
char *cursor; /* The name of the cursor for select statements */
|
||||
char *cursor; /* The name of the cursor for select
|
||||
* statements */
|
||||
char *command;
|
||||
char *notice;
|
||||
|
||||
TupleField *backend_tuples; /* data from the backend (the tuple cache) */
|
||||
TupleField *tupleField; /* current backend tuple being retrieved */
|
||||
|
||||
char inTuples; /* is a fetch of rows from the backend in progress? */
|
||||
char inTuples; /* is a fetch of rows from the backend in
|
||||
* progress? */
|
||||
};
|
||||
|
||||
#define QR_get_fields(self) (self->fields)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,8 @@ extern GLOBAL_VALUES globals;
|
||||
|
||||
/* Globals ----------------------------------------------------------------- */
|
||||
/* NOTE: All these are used by the dialog procedures */
|
||||
typedef struct tagSETUPDLG {
|
||||
typedef struct tagSETUPDLG
|
||||
{
|
||||
HWND hwndParent; /* Parent window handle */
|
||||
LPCSTR lpszDrvr; /* Driver description */
|
||||
ConnInfo ci;
|
||||
@ -72,7 +73,8 @@ BOOL INTFUNC SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
|
||||
Output : TRUE success, FALSE otherwise
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
BOOL CALLBACK ConfigDSN (HWND hwnd,
|
||||
BOOL CALLBACK
|
||||
ConfigDSN(HWND hwnd,
|
||||
WORD fRequest,
|
||||
LPCSTR lpszDriver,
|
||||
LPCSTR lpszAttributes)
|
||||
@ -99,7 +101,8 @@ LPSETUPDLG lpsetupdlg;
|
||||
lpsetupdlg->szDSN[0] = '\0';
|
||||
|
||||
/* Remove data source */
|
||||
if (ODBC_REMOVE_DSN == fRequest) {
|
||||
if (ODBC_REMOVE_DSN == fRequest)
|
||||
{
|
||||
/* Fail if no data source name was supplied */
|
||||
if (!lpsetupdlg->ci.dsn[0])
|
||||
fSuccess = FALSE;
|
||||
@ -110,15 +113,20 @@ LPSETUPDLG lpsetupdlg;
|
||||
}
|
||||
|
||||
/* Add or Configure data source */
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* Save passed variables for global access (e.g., dialog access) */
|
||||
lpsetupdlg->hwndParent = hwnd;
|
||||
lpsetupdlg->lpszDrvr = lpszDriver;
|
||||
lpsetupdlg->fNewDSN = (ODBC_ADD_DSN == fRequest);
|
||||
lpsetupdlg->fDefault = !lstrcmpi(lpsetupdlg->ci.dsn, INI_DSN);
|
||||
|
||||
/* Display the appropriate dialog (if parent window handle supplied) */
|
||||
if (hwnd) {
|
||||
/*
|
||||
* Display the appropriate dialog (if parent window handle
|
||||
* supplied)
|
||||
*/
|
||||
if (hwnd)
|
||||
{
|
||||
/* Display dialog(s) */
|
||||
fSuccess = (IDOK == DialogBoxParam(s_hModule,
|
||||
MAKEINTRESOURCE(DLG_CONFIG),
|
||||
@ -145,11 +153,15 @@ LPSETUPDLG lpsetupdlg;
|
||||
Input : hdlg -- Dialog window handle
|
||||
Output : None
|
||||
--------------------------------------------------------------------------*/
|
||||
void INTFUNC CenterDialog(HWND hdlg)
|
||||
void INTFUNC
|
||||
CenterDialog(HWND hdlg)
|
||||
{
|
||||
HWND hwndFrame;
|
||||
RECT rcDlg, rcScr, rcFrame;
|
||||
int cx, cy;
|
||||
RECT rcDlg,
|
||||
rcScr,
|
||||
rcFrame;
|
||||
int cx,
|
||||
cy;
|
||||
|
||||
hwndFrame = GetParent(hdlg);
|
||||
|
||||
@ -177,8 +189,10 @@ void INTFUNC CenterDialog(HWND hdlg)
|
||||
rcDlg.left = rcDlg.right - cx;
|
||||
}
|
||||
|
||||
if (rcDlg.left < 0) rcDlg.left = 0;
|
||||
if (rcDlg.top < 0) rcDlg.top = 0;
|
||||
if (rcDlg.left < 0)
|
||||
rcDlg.left = 0;
|
||||
if (rcDlg.top < 0)
|
||||
rcDlg.top = 0;
|
||||
|
||||
MoveWindow(hdlg, rcDlg.left, rcDlg.top, cx, cy, TRUE);
|
||||
return;
|
||||
@ -194,13 +208,15 @@ void INTFUNC CenterDialog(HWND hdlg)
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
int CALLBACK ConfigDlgProc(HWND hdlg,
|
||||
int CALLBACK
|
||||
ConfigDlgProc(HWND hdlg,
|
||||
WORD wMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
|
||||
switch (wMsg) {
|
||||
switch (wMsg)
|
||||
{
|
||||
/* Initialize the dialog */
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
@ -213,7 +229,10 @@ int CALLBACK ConfigDlgProc(HWND hdlg,
|
||||
SetWindowLong(hdlg, DWL_USER, lParam);
|
||||
CenterDialog(hdlg); /* Center dialog */
|
||||
|
||||
/* NOTE: Values supplied in the attribute string will always */
|
||||
/*
|
||||
* NOTE: Values supplied in the attribute string will
|
||||
* always
|
||||
*/
|
||||
/* override settings in ODBC.INI */
|
||||
|
||||
/* Get the rest of the common attributes */
|
||||
@ -227,7 +246,8 @@ int CALLBACK ConfigDlgProc(HWND hdlg,
|
||||
SetDlgStuff(hdlg, ci);
|
||||
|
||||
|
||||
if (lpsetupdlg->fDefault) {
|
||||
if (lpsetupdlg->fDefault)
|
||||
{
|
||||
EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
|
||||
EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
|
||||
}
|
||||
@ -244,8 +264,13 @@ int CALLBACK ConfigDlgProc(HWND hdlg,
|
||||
/* Process buttons */
|
||||
case WM_COMMAND:
|
||||
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
||||
/* Ensure the OK button is enabled only when a data source name */
|
||||
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||
{
|
||||
|
||||
/*
|
||||
* Ensure the OK button is enabled only when a data
|
||||
* source name
|
||||
*/
|
||||
/* is entered */
|
||||
case IDC_DSNAME:
|
||||
if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
|
||||
@ -319,7 +344,8 @@ int CALLBACK ConfigDlgProc(HWND hdlg,
|
||||
Input : lpszAttributes - Pointer to attribute string
|
||||
Output : None (global aAttr normally updated)
|
||||
--------------------------------------------------------------------------*/
|
||||
void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
|
||||
void INTFUNC
|
||||
ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
|
||||
{
|
||||
LPCSTR lpsz;
|
||||
LPCSTR lpszStart;
|
||||
@ -330,7 +356,8 @@ char value[MAXPGPATH];
|
||||
memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
|
||||
|
||||
for (lpsz = lpszAttributes; *lpsz; lpsz++)
|
||||
{ /* Extract key name (e.g., DSN), it must be terminated by an equals */
|
||||
{ /* Extract key name (e.g., DSN), it must
|
||||
* be terminated by an equals */
|
||||
lpszStart = lpsz;
|
||||
for (;; lpsz++)
|
||||
{
|
||||
@ -371,7 +398,8 @@ char value[MAXPGPATH];
|
||||
Output : TRUE if successful, FALSE otherwise
|
||||
--------------------------------------------------------------------------*/
|
||||
|
||||
BOOL INTFUNC SetDSNAttributes(HWND hwndParent, LPSETUPDLG lpsetupdlg)
|
||||
BOOL INTFUNC
|
||||
SetDSNAttributes(HWND hwndParent, LPSETUPDLG lpsetupdlg)
|
||||
{
|
||||
LPCSTR lpszDSN; /* Pointer to data source name */
|
||||
|
||||
@ -404,8 +432,6 @@ LPCSTR lpszDSN; /* Pointer to da
|
||||
|
||||
/* If the data source name has changed, remove the old name */
|
||||
if (lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn))
|
||||
{
|
||||
SQLRemoveDSNFromIni(lpsetupdlg->szDSN);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -49,7 +49,8 @@ SocketClass *rv;
|
||||
|
||||
rv = (SocketClass *) malloc(sizeof(SocketClass));
|
||||
|
||||
if (rv != NULL) {
|
||||
if (rv != NULL)
|
||||
{
|
||||
rv->socket = (SOCKETFD) - 1;
|
||||
rv->buffer_filled_in = 0;
|
||||
rv->buffer_filled_out = 0;
|
||||
@ -75,7 +76,8 @@ SocketClass *rv;
|
||||
void
|
||||
SOCK_Destructor(SocketClass * self)
|
||||
{
|
||||
if (self->socket != -1) {
|
||||
if (self->socket != -1)
|
||||
{
|
||||
if (!shutdown(self->socket, 2)) /* no sends or receives */
|
||||
{
|
||||
SOCK_put_char(self, 'X');
|
||||
@ -102,7 +104,8 @@ struct hostent *host;
|
||||
struct sockaddr_in sadr;
|
||||
unsigned long iaddr;
|
||||
|
||||
if (self->socket != -1) {
|
||||
if (self->socket != -1)
|
||||
{
|
||||
self->errornumber = SOCKET_ALREADY_CONNECTED;
|
||||
self->errormsg = "Socket is already connected";
|
||||
return 0;
|
||||
@ -110,13 +113,15 @@ unsigned long iaddr;
|
||||
|
||||
memset((char *) &sadr, 0, sizeof(sadr));
|
||||
|
||||
/* If it is a valid IP address, use it.
|
||||
Otherwise use hostname lookup.
|
||||
/*
|
||||
* If it is a valid IP address, use it. Otherwise use hostname lookup.
|
||||
*/
|
||||
iaddr = inet_addr(hostname);
|
||||
if (iaddr == INADDR_NONE) {
|
||||
if (iaddr == INADDR_NONE)
|
||||
{
|
||||
host = gethostbyname(hostname);
|
||||
if (host == NULL) {
|
||||
if (host == NULL)
|
||||
{
|
||||
self->errornumber = SOCKET_HOST_NOT_FOUND;
|
||||
self->errormsg = "Could not resolve hostname.";
|
||||
return 0;
|
||||
@ -130,14 +135,16 @@ unsigned long iaddr;
|
||||
sadr.sin_port = htons(port);
|
||||
|
||||
self->socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (self->socket == -1) {
|
||||
if (self->socket == -1)
|
||||
{
|
||||
self->errornumber = SOCKET_COULD_NOT_CREATE_SOCKET;
|
||||
self->errormsg = "Could not create Socket.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (connect(self->socket, (struct sockaddr *) & (sadr),
|
||||
sizeof(sadr)) < 0) {
|
||||
sizeof(sadr)) < 0)
|
||||
{
|
||||
|
||||
self->errornumber = SOCKET_COULD_NOT_CONNECT;
|
||||
self->errormsg = "Could not connect to remote socket.";
|
||||
@ -154,7 +161,8 @@ SOCK_get_n_char(SocketClass *self, char *buffer, int len)
|
||||
{
|
||||
int lf;
|
||||
|
||||
if ( ! buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
||||
self->errormsg = "get_n_char was called with NULL-Pointer";
|
||||
return;
|
||||
@ -170,7 +178,8 @@ SOCK_put_n_char(SocketClass *self, char *buffer, int len)
|
||||
{
|
||||
int lf;
|
||||
|
||||
if ( ! buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
||||
self->errormsg = "put_n_char was called with NULL-Pointer";
|
||||
return;
|
||||
@ -215,7 +224,8 @@ SOCK_get_int(SocketClass *self, short len)
|
||||
{
|
||||
char buf[4];
|
||||
|
||||
switch (len) {
|
||||
switch (len)
|
||||
{
|
||||
case 2:
|
||||
SOCK_get_n_char(self, buf, len);
|
||||
if (self->reverse)
|
||||
@ -243,7 +253,8 @@ SOCK_put_int(SocketClass *self, int value, short len)
|
||||
{
|
||||
unsigned int rv;
|
||||
|
||||
switch (len) {
|
||||
switch (len)
|
||||
{
|
||||
case 2:
|
||||
rv = self->reverse ? value : htons((unsigned short) value);
|
||||
SOCK_put_n_char(self, (char *) &rv, 2);
|
||||
@ -268,7 +279,8 @@ SOCK_flush_output(SocketClass *self)
|
||||
int written;
|
||||
|
||||
written = send(self->socket, (char *) self->buffer_out, self->buffer_filled_out, 0);
|
||||
if (written != self->buffer_filled_out) {
|
||||
if (written != self->buffer_filled_out)
|
||||
{
|
||||
self->errornumber = SOCKET_WRITE_ERROR;
|
||||
self->errormsg = "Could not flush socket buffer.";
|
||||
}
|
||||
@ -279,7 +291,8 @@ unsigned char
|
||||
SOCK_get_next_byte(SocketClass * self)
|
||||
{
|
||||
|
||||
if (self->buffer_read_in >= self->buffer_filled_in) {
|
||||
if (self->buffer_read_in >= self->buffer_filled_in)
|
||||
{
|
||||
/* there are no more bytes left in the buffer -> */
|
||||
/* reload the buffer */
|
||||
|
||||
@ -288,12 +301,14 @@ SOCK_get_next_byte(SocketClass *self)
|
||||
|
||||
mylog("read %d, global_socket_buffersize=%d\n", self->buffer_filled_in, globals.socket_buffersize);
|
||||
|
||||
if (self->buffer_filled_in == -1) {
|
||||
if (self->buffer_filled_in == -1)
|
||||
{
|
||||
self->errornumber = SOCKET_READ_ERROR;
|
||||
self->errormsg = "Error while reading from the socket.";
|
||||
self->buffer_filled_in = 0;
|
||||
}
|
||||
if (self->buffer_filled_in == 0) {
|
||||
if (self->buffer_filled_in == 0)
|
||||
{
|
||||
self->errornumber = SOCKET_CLOSED;
|
||||
self->errormsg = "Socket has been closed.";
|
||||
self->buffer_filled_in = 0;
|
||||
@ -310,10 +325,12 @@ int bytes_sent;
|
||||
|
||||
self->buffer_out[self->buffer_filled_out++] = next_byte;
|
||||
|
||||
if (self->buffer_filled_out == globals.socket_buffersize) {
|
||||
if (self->buffer_filled_out == globals.socket_buffersize)
|
||||
{
|
||||
/* buffer is full, so write it out */
|
||||
bytes_sent = send(self->socket, (char *) self->buffer_out, globals.socket_buffersize, 0);
|
||||
if (bytes_sent != globals.socket_buffersize) {
|
||||
if (bytes_sent != globals.socket_buffersize)
|
||||
{
|
||||
self->errornumber = SOCKET_WRITE_ERROR;
|
||||
self->errormsg = "Error while writing to the socket.";
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#ifndef _IN_ADDR_T
|
||||
#define _IN_ADDR_T
|
||||
typedef unsigned int in_addr_t;
|
||||
|
||||
#endif
|
||||
#define INADDR_NONE ((in_addr_t)-1)
|
||||
#endif
|
||||
@ -52,7 +53,8 @@ typedef unsigned int in_addr_t;
|
||||
#define SOCKET_CLOSED 10
|
||||
|
||||
|
||||
struct SocketClass_ {
|
||||
struct SocketClass_
|
||||
{
|
||||
|
||||
int buffer_filled_in;
|
||||
int buffer_filled_out;
|
||||
@ -65,7 +67,8 @@ struct SocketClass_ {
|
||||
char *errormsg;
|
||||
int errornumber;
|
||||
|
||||
char reverse; /* used to handle Postgres 6.2 protocol (reverse byte order) */
|
||||
char reverse; /* used to handle Postgres 6.2 protocol
|
||||
* (reverse byte order) */
|
||||
|
||||
};
|
||||
|
||||
|
@ -45,24 +45,48 @@ extern GLOBAL_VALUES globals;
|
||||
#define PRN_NULLCHECK
|
||||
|
||||
/* Map sql commands to statement types */
|
||||
static struct {
|
||||
static struct
|
||||
{
|
||||
int type;
|
||||
char *s;
|
||||
} Statement_Type[] = {
|
||||
{ STMT_TYPE_SELECT, "SELECT" },
|
||||
{ STMT_TYPE_INSERT, "INSERT" },
|
||||
{ STMT_TYPE_UPDATE, "UPDATE" },
|
||||
{ STMT_TYPE_DELETE, "DELETE" },
|
||||
{ STMT_TYPE_CREATE, "CREATE" },
|
||||
{ STMT_TYPE_ALTER, "ALTER" },
|
||||
{ STMT_TYPE_DROP, "DROP" },
|
||||
{ STMT_TYPE_GRANT, "GRANT" },
|
||||
{ STMT_TYPE_REVOKE, "REVOKE" },
|
||||
{ 0, NULL }
|
||||
} Statement_Type[] =
|
||||
|
||||
{
|
||||
{
|
||||
STMT_TYPE_SELECT, "SELECT"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_INSERT, "INSERT"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_UPDATE, "UPDATE"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_DELETE, "DELETE"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_CREATE, "CREATE"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_ALTER, "ALTER"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_DROP, "DROP"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_GRANT, "GRANT"
|
||||
},
|
||||
{
|
||||
STMT_TYPE_REVOKE, "REVOKE"
|
||||
},
|
||||
{
|
||||
0, NULL
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
RETCODE SQL_API SQLAllocStmt(HDBC hdbc,
|
||||
RETCODE SQL_API
|
||||
SQLAllocStmt(HDBC hdbc,
|
||||
HSTMT FAR * phstmt)
|
||||
{
|
||||
static char *func = "SQLAllocStmt";
|
||||
@ -71,7 +95,8 @@ StatementClass *stmt;
|
||||
|
||||
mylog("%s: entering...\n", func);
|
||||
|
||||
if( ! conn) {
|
||||
if (!conn)
|
||||
{
|
||||
CC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
@ -80,7 +105,8 @@ StatementClass *stmt;
|
||||
|
||||
mylog("**** SQLAllocStmt: hdbc = %u, stmt = %u\n", hdbc, stmt);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
conn->errornumber = CONN_STMT_ALLOC_ERROR;
|
||||
conn->errormsg = "No more memory to allocate a further SQL-statement";
|
||||
*phstmt = SQL_NULL_HSTMT;
|
||||
@ -88,7 +114,8 @@ StatementClass *stmt;
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
if ( ! CC_add_statement(conn, stmt)) {
|
||||
if (!CC_add_statement(conn, stmt))
|
||||
{
|
||||
conn->errormsg = "Maximum number of connections exceeded.";
|
||||
conn->errornumber = CONN_STMT_ALLOC_ERROR;
|
||||
CC_log_error(func, "", conn);
|
||||
@ -99,7 +126,8 @@ StatementClass *stmt;
|
||||
|
||||
*phstmt = (HSTMT) stmt;
|
||||
|
||||
/* Copy default statement options based from Connection options
|
||||
/*
|
||||
* Copy default statement options based from Connection options
|
||||
*/
|
||||
stmt->options = conn->stmtOptions;
|
||||
|
||||
@ -111,7 +139,8 @@ StatementClass *stmt;
|
||||
}
|
||||
|
||||
|
||||
RETCODE SQL_API SQLFreeStmt(HSTMT hstmt,
|
||||
RETCODE SQL_API
|
||||
SQLFreeStmt(HSTMT hstmt,
|
||||
UWORD fOption)
|
||||
{
|
||||
static char *func = "SQLFreeStmt";
|
||||
@ -119,25 +148,31 @@ StatementClass *stmt = (StatementClass *) hstmt;
|
||||
|
||||
mylog("%s: entering...hstmt=%u, fOption=%d\n", func, hstmt, fOption);
|
||||
|
||||
if ( ! stmt) {
|
||||
if (!stmt)
|
||||
{
|
||||
SC_log_error(func, "", NULL);
|
||||
return SQL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
if (fOption == SQL_DROP) {
|
||||
if (fOption == SQL_DROP)
|
||||
{
|
||||
ConnectionClass *conn = stmt->hdbc;
|
||||
|
||||
/* Remove the statement from the connection's statement list */
|
||||
if ( conn) {
|
||||
if ( ! CC_remove_statement(conn, stmt)) {
|
||||
if (conn)
|
||||
{
|
||||
if (!CC_remove_statement(conn, stmt))
|
||||
{
|
||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||
stmt->errormsg = "Statement is currently executing a transaction.";
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR; /* stmt may be executing a transaction */
|
||||
return SQL_ERROR; /* stmt may be executing a
|
||||
* transaction */
|
||||
}
|
||||
|
||||
/* Free any cursors and discard any result info */
|
||||
if (stmt->result) {
|
||||
if (stmt->result)
|
||||
{
|
||||
QR_Destructor(stmt->result);
|
||||
stmt->result = NULL;
|
||||
}
|
||||
@ -146,22 +181,31 @@ StatementClass *stmt = (StatementClass *) hstmt;
|
||||
/* Destroy the statement and free any results, cursors, etc. */
|
||||
SC_Destructor(stmt);
|
||||
|
||||
} else if (fOption == SQL_UNBIND) {
|
||||
}
|
||||
else if (fOption == SQL_UNBIND)
|
||||
{
|
||||
SC_unbind_cols(stmt);
|
||||
|
||||
} else if (fOption == SQL_CLOSE) {
|
||||
}
|
||||
else if (fOption == SQL_CLOSE)
|
||||
{
|
||||
/* this should discard all the results, but leave the statement */
|
||||
/* itself in place (it can be executed again) */
|
||||
if (!SC_recycle_statement(stmt)) {
|
||||
if (!SC_recycle_statement(stmt))
|
||||
{
|
||||
/* errormsg passed in above */
|
||||
SC_log_error(func, "", stmt);
|
||||
return SQL_ERROR;
|
||||
}
|
||||
|
||||
} else if(fOption == SQL_RESET_PARAMS) {
|
||||
}
|
||||
else if (fOption == SQL_RESET_PARAMS)
|
||||
{
|
||||
SC_free_params(stmt, STMT_FREE_PARAMS_ALL);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt->errormsg = "Invalid option passed to SQLFreeStmt.";
|
||||
stmt->errornumber = STMT_OPTION_OUT_OF_RANGE_ERROR;
|
||||
SC_log_error(func, "", stmt);
|
||||
@ -196,7 +240,8 @@ SC_Constructor(void)
|
||||
StatementClass *rv;
|
||||
|
||||
rv = (StatementClass *) malloc(sizeof(StatementClass));
|
||||
if (rv) {
|
||||
if (rv)
|
||||
{
|
||||
rv->hdbc = NULL; /* no connection associated yet */
|
||||
rv->phstmt = NULL;
|
||||
rv->result = NULL;
|
||||
@ -255,13 +300,15 @@ SC_Destructor(StatementClass *self)
|
||||
{
|
||||
|
||||
mylog("SC_Destructor: self=%u, self->result=%u, self->hdbc=%u\n", self, self->result, self->hdbc);
|
||||
if (STMT_EXECUTING == self->status) {
|
||||
if (STMT_EXECUTING == self->status)
|
||||
{
|
||||
self->errornumber = STMT_SEQUENCE_ERROR;
|
||||
self->errormsg = "Statement is currently executing a transaction.";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (self->result) {
|
||||
if (self->result)
|
||||
{
|
||||
if (!self->hdbc)
|
||||
self->result->conn = NULL; /* prevent any dbase activity */
|
||||
|
||||
@ -273,29 +320,38 @@ SC_Destructor(StatementClass *self)
|
||||
|
||||
SC_free_params(self, STMT_FREE_PARAMS_ALL);
|
||||
|
||||
/* the memory pointed to by the bindings is not deallocated by the driver */
|
||||
/* by by the application that uses that driver, so we don't have to care */
|
||||
/*
|
||||
* the memory pointed to by the bindings is not deallocated by the
|
||||
* driver
|
||||
*/
|
||||
|
||||
/*
|
||||
* by by the application that uses that driver, so we don't have to
|
||||
* care
|
||||
*/
|
||||
/* about that here. */
|
||||
if (self->bindings)
|
||||
free(self->bindings);
|
||||
|
||||
|
||||
/* Free the parsed table information */
|
||||
if (self->ti) {
|
||||
if (self->ti)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < self->ntab; i++) {
|
||||
|
||||
for (i = 0; i < self->ntab; i++)
|
||||
free(self->ti[i]);
|
||||
}
|
||||
|
||||
free(self->ti);
|
||||
}
|
||||
|
||||
/* Free the parsed field information */
|
||||
if (self->fi) {
|
||||
if (self->fi)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < self->nfld; i++) {
|
||||
|
||||
for (i = 0; i < self->nfld; i++)
|
||||
free(self->fi[i]);
|
||||
}
|
||||
free(self->fi);
|
||||
}
|
||||
|
||||
@ -320,15 +376,19 @@ int i;
|
||||
if (!self->parameters)
|
||||
return;
|
||||
|
||||
for (i = 0; i < self->parameters_allocated; i++) {
|
||||
if (self->parameters[i].data_at_exec == TRUE) {
|
||||
for (i = 0; i < self->parameters_allocated; i++)
|
||||
{
|
||||
if (self->parameters[i].data_at_exec == TRUE)
|
||||
{
|
||||
|
||||
if (self->parameters[i].EXEC_used) {
|
||||
if (self->parameters[i].EXEC_used)
|
||||
{
|
||||
free(self->parameters[i].EXEC_used);
|
||||
self->parameters[i].EXEC_used = NULL;
|
||||
}
|
||||
|
||||
if (self->parameters[i].EXEC_buffer) {
|
||||
if (self->parameters[i].EXEC_buffer)
|
||||
{
|
||||
if (self->parameters[i].SQLType != SQL_LONGVARBINARY)
|
||||
free(self->parameters[i].EXEC_buffer);
|
||||
self->parameters[i].EXEC_buffer = NULL;
|
||||
@ -339,7 +399,8 @@ int i;
|
||||
self->current_exec_param = -1;
|
||||
self->put_data = FALSE;
|
||||
|
||||
if (option == STMT_FREE_PARAMS_ALL) {
|
||||
if (option == STMT_FREE_PARAMS_ALL)
|
||||
{
|
||||
free(self->parameters);
|
||||
self->parameters = NULL;
|
||||
self->parameters_allocated = 0;
|
||||
@ -378,7 +439,8 @@ ConnectionClass *conn;
|
||||
mylog("recycle statement: self= %u\n", self);
|
||||
|
||||
/* This would not happen */
|
||||
if (self->status == STMT_EXECUTING) {
|
||||
if (self->status == STMT_EXECUTING)
|
||||
{
|
||||
self->errornumber = STMT_SEQUENCE_ERROR;
|
||||
self->errormsg = "Statement is currently executing a transaction.";
|
||||
return FALSE;
|
||||
@ -388,7 +450,8 @@ mylog("recycle statement: self= %u\n", self);
|
||||
self->errornumber = 0;
|
||||
self->errormsg_created = FALSE;
|
||||
|
||||
switch (self->status) {
|
||||
switch (self->status)
|
||||
{
|
||||
case STMT_ALLOCATED:
|
||||
/* this statement does not need to be recycled */
|
||||
return TRUE;
|
||||
@ -397,11 +460,15 @@ mylog("recycle statement: self= %u\n", self);
|
||||
break;
|
||||
|
||||
case STMT_PREMATURE:
|
||||
/* Premature execution of the statement might have caused the start of a transaction.
|
||||
If so, we have to rollback that transaction.
|
||||
|
||||
/*
|
||||
* Premature execution of the statement might have caused the
|
||||
* start of a transaction. If so, we have to rollback that
|
||||
* transaction.
|
||||
*/
|
||||
conn = SC_get_conn(self);
|
||||
if ( ! CC_is_in_autocommit(conn) && CC_is_in_trans(conn)) {
|
||||
if (!CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
|
||||
{
|
||||
|
||||
CC_send_query(conn, "ABORT", NULL);
|
||||
CC_set_no_trans(conn);
|
||||
@ -418,11 +485,12 @@ mylog("recycle statement: self= %u\n", self);
|
||||
}
|
||||
|
||||
/* Free the parsed table information */
|
||||
if (self->ti) {
|
||||
if (self->ti)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < self->ntab; i++) {
|
||||
|
||||
for (i = 0; i < self->ntab; i++)
|
||||
free(self->ti[i]);
|
||||
}
|
||||
|
||||
free(self->ti);
|
||||
self->ti = NULL;
|
||||
@ -430,11 +498,12 @@ mylog("recycle statement: self= %u\n", self);
|
||||
}
|
||||
|
||||
/* Free the parsed field information */
|
||||
if (self->fi) {
|
||||
if (self->fi)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < self->nfld; i++) {
|
||||
|
||||
for (i = 0; i < self->nfld; i++)
|
||||
free(self->fi[i]);
|
||||
}
|
||||
free(self->fi);
|
||||
self->fi = NULL;
|
||||
self->nfld = 0;
|
||||
@ -442,7 +511,8 @@ mylog("recycle statement: self= %u\n", self);
|
||||
self->parse_status = STMT_PARSE_NONE;
|
||||
|
||||
/* Free any cursors */
|
||||
if (self->result) {
|
||||
if (self->result)
|
||||
{
|
||||
QR_Destructor(self->result);
|
||||
self->result = NULL;
|
||||
}
|
||||
@ -481,12 +551,14 @@ SC_pre_execute(StatementClass *self)
|
||||
|
||||
mylog("SC_pre_execute: status = %d\n", self->status);
|
||||
|
||||
if (self->status == STMT_READY) {
|
||||
if (self->status == STMT_READY)
|
||||
{
|
||||
mylog(" preprocess: status = READY\n");
|
||||
|
||||
SQLExecute(self);
|
||||
|
||||
if (self->status == STMT_FINISHED) {
|
||||
if (self->status == STMT_FINISHED)
|
||||
{
|
||||
mylog(" preprocess: after status = FINISHED, so set PREMATURE\n");
|
||||
self->status = STMT_PREMATURE;
|
||||
}
|
||||
@ -499,7 +571,8 @@ SC_unbind_cols(StatementClass *self)
|
||||
{
|
||||
Int2 lf;
|
||||
|
||||
for(lf = 0; lf < self->bindings_allocated; lf++) {
|
||||
for (lf = 0; lf < self->bindings_allocated; lf++)
|
||||
{
|
||||
self->bindings[lf].data_left = -1;
|
||||
self->bindings[lf].buflen = 0;
|
||||
self->bindings[lf].buffer = NULL;
|
||||
@ -540,15 +613,18 @@ static char msg[4096];
|
||||
else if (self->errormsg)
|
||||
strcpy(msg, self->errormsg);
|
||||
|
||||
if (conn) {
|
||||
if (conn)
|
||||
{
|
||||
SocketClass *sock = conn->sock;
|
||||
|
||||
if (conn->errormsg && conn->errormsg[0] != '\0') {
|
||||
if (conn->errormsg && conn->errormsg[0] != '\0')
|
||||
{
|
||||
pos = strlen(msg);
|
||||
sprintf(&msg[pos], ";\n%s", conn->errormsg);
|
||||
}
|
||||
|
||||
if (sock && sock->errormsg && sock->errormsg[0] != '\0') {
|
||||
if (sock && sock->errormsg && sock->errormsg[0] != '\0')
|
||||
{
|
||||
pos = strlen(msg);
|
||||
sprintf(&msg[pos], ";\n%s", sock->errormsg);
|
||||
}
|
||||
@ -563,12 +639,14 @@ SC_get_error(StatementClass *self, int *number, char **message)
|
||||
char rv;
|
||||
|
||||
/* Create a very informative errormsg if it hasn't been done yet. */
|
||||
if ( ! self->errormsg_created) {
|
||||
if (!self->errormsg_created)
|
||||
{
|
||||
self->errormsg = SC_create_errormsg(self);
|
||||
self->errormsg_created = TRUE;
|
||||
}
|
||||
|
||||
if ( self->errornumber) {
|
||||
if (self->errornumber)
|
||||
{
|
||||
*number = self->errornumber;
|
||||
*message = self->errormsg;
|
||||
self->errormsg = NULL;
|
||||
@ -595,11 +673,14 @@ SC_fetch(StatementClass *self)
|
||||
{
|
||||
static char *func = "SC_fetch";
|
||||
QResultClass *res = self->result;
|
||||
int retval, result;
|
||||
Int2 num_cols, lf;
|
||||
int retval,
|
||||
result;
|
||||
Int2 num_cols,
|
||||
lf;
|
||||
Oid type;
|
||||
char *value;
|
||||
ColumnInfoClass *ci;
|
||||
|
||||
/* TupleField *tupleField; */
|
||||
|
||||
self->last_fetch_count = 0;
|
||||
@ -607,13 +688,16 @@ ColumnInfoClass *ci;
|
||||
|
||||
mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, globals.use_declarefetch);
|
||||
|
||||
if ( self->manual_result || ! globals.use_declarefetch) {
|
||||
if (self->manual_result || !globals.use_declarefetch)
|
||||
{
|
||||
|
||||
if (self->currTuple >= QR_get_num_tuples(res) - 1 ||
|
||||
(self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1)) {
|
||||
(self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1))
|
||||
{
|
||||
|
||||
/* if at the end of the tuples, return "no data found"
|
||||
and set the cursor past the end of the result set
|
||||
/*
|
||||
* if at the end of the tuples, return "no data found" and set
|
||||
* the cursor past the end of the result set
|
||||
*/
|
||||
self->currTuple = QR_get_num_tuples(res);
|
||||
return SQL_NO_DATA_FOUND;
|
||||
@ -622,18 +706,21 @@ ColumnInfoClass *ci;
|
||||
mylog("**** SQLFetch: manual_result\n");
|
||||
(self->currTuple)++;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
|
||||
/* read from the cache or the physical next tuple */
|
||||
retval = QR_next_tuple(res);
|
||||
if (retval < 0) {
|
||||
if (retval < 0)
|
||||
{
|
||||
mylog("**** SQLFetch: end_tuples\n");
|
||||
return SQL_NO_DATA_FOUND;
|
||||
}
|
||||
else if (retval > 0)
|
||||
(self->currTuple)++;/* all is well */
|
||||
|
||||
else {
|
||||
else
|
||||
{
|
||||
mylog("SQLFetch: error\n");
|
||||
self->errornumber = STMT_EXEC_ERROR;
|
||||
self->errormsg = "Error fetching next row";
|
||||
@ -647,12 +734,14 @@ ColumnInfoClass *ci;
|
||||
result = SQL_SUCCESS;
|
||||
self->last_fetch_count = 1;
|
||||
|
||||
/* If the bookmark column was bound then return a bookmark.
|
||||
Since this is used with SQLExtendedFetch, and the rowset size
|
||||
may be greater than 1, and an application can use row or column wise
|
||||
binding, use the code in copy_and_convert_field() to handle that.
|
||||
/*
|
||||
* If the bookmark column was bound then return a bookmark. Since this
|
||||
* is used with SQLExtendedFetch, and the rowset size may be greater
|
||||
* than 1, and an application can use row or column wise binding, use
|
||||
* the code in copy_and_convert_field() to handle that.
|
||||
*/
|
||||
if (self->bookmark.buffer) {
|
||||
if (self->bookmark.buffer)
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
sprintf(buf, "%ld", SC_get_bookmark(self));
|
||||
@ -660,14 +749,16 @@ ColumnInfoClass *ci;
|
||||
SQL_C_ULONG, self->bookmark.buffer, 0, self->bookmark.used);
|
||||
}
|
||||
|
||||
for (lf=0; lf < num_cols; lf++) {
|
||||
for (lf = 0; lf < num_cols; lf++)
|
||||
{
|
||||
|
||||
mylog("fetch: cols=%d, lf=%d, self = %u, self->bindings = %u, buffer[] = %u\n", num_cols, lf, self, self->bindings, self->bindings[lf].buffer);
|
||||
|
||||
/* reset for SQLGetData */
|
||||
self->bindings[lf].data_left = -1;
|
||||
|
||||
if (self->bindings[lf].buffer != NULL) {
|
||||
if (self->bindings[lf].buffer != NULL)
|
||||
{
|
||||
/* this column has a binding */
|
||||
|
||||
/* type = QR_get_field_type(res, lf); */
|
||||
@ -675,15 +766,15 @@ ColumnInfoClass *ci;
|
||||
|
||||
mylog("type = %d\n", type);
|
||||
|
||||
if (self->manual_result) {
|
||||
if (self->manual_result)
|
||||
{
|
||||
value = QR_get_value_manual(res, self->currTuple, lf);
|
||||
mylog("manual_result\n");
|
||||
}
|
||||
else if (globals.use_declarefetch)
|
||||
value = QR_get_value_backend(res, lf);
|
||||
else {
|
||||
else
|
||||
value = QR_get_value_backend_row(res, self->currTuple, lf);
|
||||
}
|
||||
|
||||
mylog("value = '%s'\n", (value == NULL) ? "<NULL>" : value);
|
||||
|
||||
@ -691,7 +782,8 @@ ColumnInfoClass *ci;
|
||||
|
||||
mylog("copy_and_convert: retval = %d\n", retval);
|
||||
|
||||
switch(retval) {
|
||||
switch (retval)
|
||||
{
|
||||
case COPY_OK:
|
||||
break; /* OK, do next bound column */
|
||||
|
||||
@ -715,7 +807,8 @@ ColumnInfoClass *ci;
|
||||
result = SQL_SUCCESS_WITH_INFO;
|
||||
break;
|
||||
|
||||
case COPY_GENERAL_ERROR: /* error msg already filled in */
|
||||
case COPY_GENERAL_ERROR: /* error msg already
|
||||
* filled in */
|
||||
SC_log_error(func, "", self);
|
||||
result = SQL_ERROR;
|
||||
break;
|
||||
@ -738,35 +831,40 @@ ColumnInfoClass *ci;
|
||||
}
|
||||
|
||||
|
||||
RETCODE SC_execute(StatementClass *self)
|
||||
RETCODE
|
||||
SC_execute(StatementClass * self)
|
||||
{
|
||||
static char *func = "SC_execute";
|
||||
ConnectionClass *conn;
|
||||
QResultClass *res;
|
||||
char ok, was_ok, was_nonfatal;
|
||||
Int2 oldstatus, numcols;
|
||||
char ok,
|
||||
was_ok,
|
||||
was_nonfatal;
|
||||
Int2 oldstatus,
|
||||
numcols;
|
||||
QueryInfo qi;
|
||||
|
||||
|
||||
conn = SC_get_conn(self);
|
||||
|
||||
/* Begin a transaction if one is not already in progress */
|
||||
|
||||
/*
|
||||
Basically we don't have to begin a transaction in
|
||||
autocommit mode because Postgres backend runs in
|
||||
autocomit mode.
|
||||
We issue "BEGIN" in the following cases.
|
||||
1) we use declare/fetch and the statement is SELECT
|
||||
(because declare/fetch must be called in a transaction).
|
||||
2) we are not in autocommit state and the statement
|
||||
is of type UPDATE.
|
||||
* Basically we don't have to begin a transaction in autocommit mode
|
||||
* because Postgres backend runs in autocomit mode. We issue "BEGIN"
|
||||
* in the following cases. 1) we use declare/fetch and the statement
|
||||
* is SELECT (because declare/fetch must be called in a transaction).
|
||||
* 2) we are not in autocommit state and the statement is of type
|
||||
* UPDATE.
|
||||
*/
|
||||
if (!self->internal && !CC_is_in_trans(conn) &&
|
||||
((globals.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) || (! CC_is_in_autocommit(conn) && STMT_UPDATE(self)))) {
|
||||
((globals.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) || (!CC_is_in_autocommit(conn) && STMT_UPDATE(self))))
|
||||
{
|
||||
|
||||
mylog(" about to begin a transaction on statement = %u\n", self);
|
||||
res = CC_send_query(conn, "BEGIN", NULL);
|
||||
if ( ! res) {
|
||||
if (!res)
|
||||
{
|
||||
self->errormsg = "Could not begin a transaction";
|
||||
self->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", self);
|
||||
@ -779,7 +877,8 @@ QueryInfo qi;
|
||||
|
||||
QR_Destructor(res);
|
||||
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
self->errormsg = "Could not begin a transaction";
|
||||
self->errornumber = STMT_EXEC_ERROR;
|
||||
SC_log_error(func, "", self);
|
||||
@ -795,9 +894,14 @@ QueryInfo qi;
|
||||
|
||||
|
||||
/* If it's a SELECT statement, use a cursor. */
|
||||
/* Note that the declare cursor has already been prepended to the statement */
|
||||
|
||||
/*
|
||||
* Note that the declare cursor has already been prepended to the
|
||||
* statement
|
||||
*/
|
||||
/* in copy_statement... */
|
||||
if (self->statement_type == STMT_TYPE_SELECT) {
|
||||
if (self->statement_type == STMT_TYPE_SELECT)
|
||||
{
|
||||
|
||||
char fetch[128];
|
||||
|
||||
@ -808,19 +912,25 @@ QueryInfo qi;
|
||||
self->result = CC_send_query(conn, self->stmt_with_params, NULL);
|
||||
|
||||
if (globals.use_declarefetch && self->result != NULL &&
|
||||
QR_command_successful(self->result)) {
|
||||
QR_command_successful(self->result))
|
||||
{
|
||||
|
||||
QR_Destructor(self->result);
|
||||
|
||||
/* That worked, so now send the fetch to start getting data back */
|
||||
/*
|
||||
* That worked, so now send the fetch to start getting data
|
||||
* back
|
||||
*/
|
||||
qi.result_in = NULL;
|
||||
qi.cursor = self->cursor_name;
|
||||
qi.row_size = globals.fetch_max;
|
||||
|
||||
/* Most likely the rowset size will not be set by the application until
|
||||
after the statement is executed, so might as well use the cache size.
|
||||
The qr_next_tuple() function will correct for any discrepancies in
|
||||
sizes and adjust the cache accordingly.
|
||||
/*
|
||||
* Most likely the rowset size will not be set by the
|
||||
* application until after the statement is executed, so might
|
||||
* as well use the cache size. The qr_next_tuple() function
|
||||
* will correct for any discrepancies in sizes and adjust the
|
||||
* cache accordingly.
|
||||
*/
|
||||
|
||||
sprintf(fetch, "fetch %d in %s", qi.row_size, self->cursor_name);
|
||||
@ -829,17 +939,23 @@ QueryInfo qi;
|
||||
}
|
||||
mylog(" done sending the query:\n");
|
||||
}
|
||||
else { /* not a SELECT statement so don't use a cursor */
|
||||
else
|
||||
{ /* not a SELECT statement so don't use a
|
||||
* cursor */
|
||||
mylog(" it's NOT a select statement: stmt=%u\n", self);
|
||||
self->result = CC_send_query(conn, self->stmt_with_params, NULL);
|
||||
|
||||
/* We shouldn't send COMMIT. Postgres backend does the
|
||||
autocommit if neccessary. (Zoltan, 04/26/2000)
|
||||
/*
|
||||
* We shouldn't send COMMIT. Postgres backend does the autocommit
|
||||
* if neccessary. (Zoltan, 04/26/2000)
|
||||
*/
|
||||
/* Even in case of autocommit, started transactions
|
||||
must be committed. (Hiroshi, 09/02/2001)
|
||||
|
||||
/*
|
||||
* Even in case of autocommit, started transactions must be
|
||||
* committed. (Hiroshi, 09/02/2001)
|
||||
*/
|
||||
if ( ! self->internal && CC_is_in_autocommit(conn) && CC_is_in_trans(conn) && STMT_UPDATE(self)) {
|
||||
if (!self->internal && CC_is_in_autocommit(conn) && CC_is_in_trans(conn) && STMT_UPDATE(self))
|
||||
{
|
||||
res = CC_send_query(conn, "COMMIT", NULL);
|
||||
QR_Destructor(res);
|
||||
CC_set_no_trans(conn);
|
||||
@ -850,7 +966,8 @@ QueryInfo qi;
|
||||
self->status = STMT_FINISHED;
|
||||
|
||||
/* Check the status of the result */
|
||||
if (self->result) {
|
||||
if (self->result)
|
||||
{
|
||||
|
||||
was_ok = QR_command_successful(self->result);
|
||||
was_nonfatal = QR_command_nonfatal(self->result);
|
||||
@ -860,7 +977,8 @@ QueryInfo qi;
|
||||
else
|
||||
self->errornumber = was_nonfatal ? STMT_INFO_ONLY : STMT_ERROR_TAKEN_FROM_BACKEND;
|
||||
|
||||
self->currTuple = -1; /* set cursor before the first tuple in the list */
|
||||
self->currTuple = -1; /* set cursor before the first tuple in
|
||||
* the list */
|
||||
self->current_col = -1;
|
||||
self->rowset_start = -1;
|
||||
|
||||
@ -868,9 +986,11 @@ QueryInfo qi;
|
||||
numcols = QR_NumResultCols(self->result);
|
||||
|
||||
/* now allocate the array to hold the binding info */
|
||||
if (numcols > 0) {
|
||||
if (numcols > 0)
|
||||
{
|
||||
extend_bindings(self, numcols);
|
||||
if (self->bindings == NULL) {
|
||||
if (self->bindings == NULL)
|
||||
{
|
||||
self->errornumber = STMT_NO_MEMORY_ERROR;
|
||||
self->errormsg = "Could not get enough free memory to store the binding information";
|
||||
SC_log_error(func, "", self);
|
||||
@ -880,18 +1000,25 @@ QueryInfo qi;
|
||||
/* in autocommit mode declare/fetch error must be aborted */
|
||||
if (!was_ok && !self->internal && CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
|
||||
CC_abort(conn);
|
||||
} else { /* Bad Error -- The error message will be in the Connection */
|
||||
}
|
||||
else
|
||||
{ /* Bad Error -- The error message will be
|
||||
* in the Connection */
|
||||
|
||||
if (self->statement_type == STMT_TYPE_CREATE) {
|
||||
if (self->statement_type == STMT_TYPE_CREATE)
|
||||
{
|
||||
self->errornumber = STMT_CREATE_TABLE_ERROR;
|
||||
self->errormsg = "Error creating the table";
|
||||
/* This would allow the table to already exists, thus appending
|
||||
rows to it. BUT, if the table didn't have the same attributes,
|
||||
it would fail.
|
||||
return SQL_SUCCESS_WITH_INFO;
|
||||
|
||||
/*
|
||||
* This would allow the table to already exists, thus
|
||||
* appending rows to it. BUT, if the table didn't have the
|
||||
* same attributes, it would fail. return
|
||||
* SQL_SUCCESS_WITH_INFO;
|
||||
*/
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
self->errornumber = STMT_EXEC_ERROR;
|
||||
self->errormsg = "Error while executing the query";
|
||||
}
|
||||
@ -903,7 +1030,8 @@ QueryInfo qi;
|
||||
if (self->errornumber == STMT_OK)
|
||||
return SQL_SUCCESS;
|
||||
|
||||
else {
|
||||
else
|
||||
{
|
||||
/* Modified, 2000-04-29, Zoltan */
|
||||
if (self->errornumber == STMT_INFO_ONLY)
|
||||
self->errormsg = "Error while executing the query (non-fatal)";
|
||||
@ -920,7 +1048,8 @@ SC_log_error(char *func, char *desc, StatementClass *self)
|
||||
#ifdef PRN_NULLCHECK
|
||||
#define nullcheck(a) (a ? a : "(NULL)")
|
||||
#endif
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
qlog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
|
||||
mylog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
|
||||
qlog(" ------------------------------------------------------------\n");
|
||||
@ -937,8 +1066,10 @@ SC_log_error(char *func, char *desc, StatementClass *self)
|
||||
|
||||
qlog(" ----------------QResult Info -------------------------------\n");
|
||||
|
||||
if (self->result) {
|
||||
if (self->result)
|
||||
{
|
||||
QResultClass *res = self->result;
|
||||
|
||||
qlog(" fields=%u, manual_tuples=%u, backend_tuples=%u, tupleField=%d, conn=%u\n", res->fields, res->manual_tuples, res->backend_tuples, res->tupleField, res->conn);
|
||||
qlog(" fetch_count=%d, fcount=%d, num_fields=%d, cursor='%s'\n", res->fetch_count, res->fcount, res->num_fields, nullcheck(res->cursor));
|
||||
qlog(" message='%s', command='%s', notice='%s'\n", nullcheck(res->message), nullcheck(res->command), nullcheck(res->notice));
|
||||
|
@ -33,21 +33,28 @@
|
||||
#define TRUE (BOOL)1
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
STMT_ALLOCATED, /* The statement handle is allocated, but not used so far */
|
||||
typedef enum
|
||||
{
|
||||
STMT_ALLOCATED, /* The statement handle is allocated, but
|
||||
* not used so far */
|
||||
STMT_READY, /* the statement is waiting to be executed */
|
||||
STMT_PREMATURE, /* ODBC states that it is legal to call e.g. SQLDescribeCol before
|
||||
a call to SQLExecute, but after SQLPrepare. To get all the necessary
|
||||
information in such a case, we simply execute the query _before_ the
|
||||
actual call to SQLExecute, so that statement is considered to be "premature".
|
||||
*/
|
||||
STMT_PREMATURE, /* ODBC states that it is legal to call
|
||||
* e.g. SQLDescribeCol before a call to
|
||||
* SQLExecute, but after SQLPrepare. To
|
||||
* get all the necessary information in
|
||||
* such a case, we simply execute the
|
||||
* query _before_ the actual call to
|
||||
* SQLExecute, so that statement is
|
||||
* considered to be "premature". */
|
||||
STMT_FINISHED, /* statement execution has finished */
|
||||
STMT_EXECUTING /* statement execution is still going on */
|
||||
} STMT_Status;
|
||||
|
||||
#define STMT_TRUNCATED -2
|
||||
#define STMT_INFO_ONLY -1 /* not an error message, just a notification to be returned by SQLError */
|
||||
#define STMT_OK 0 /* will be interpreted as "no error pending" */
|
||||
#define STMT_INFO_ONLY -1 /* not an error message, just a
|
||||
* notification to be returned by SQLError */
|
||||
#define STMT_OK 0 /* will be interpreted as "no error
|
||||
* pending" */
|
||||
#define STMT_EXEC_ERROR 1
|
||||
#define STMT_STATUS_ERROR 2
|
||||
#define STMT_SEQUENCE_ERROR 3
|
||||
@ -77,7 +84,8 @@ typedef enum {
|
||||
#define STMT_BAD_ERROR 27
|
||||
|
||||
/* statement types */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
STMT_TYPE_UNKNOWN = -2,
|
||||
STMT_TYPE_OTHER = -1,
|
||||
STMT_TYPE_SELECT = 0,
|
||||
@ -95,7 +103,8 @@ enum {
|
||||
|
||||
|
||||
/* Parsing status */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
STMT_PARSE_NONE = 0,
|
||||
STMT_PARSE_COMPLETE,
|
||||
STMT_PARSE_INCOMPLETE,
|
||||
@ -103,19 +112,22 @@ enum {
|
||||
};
|
||||
|
||||
/* Result style */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
STMT_FETCH_NONE = 0,
|
||||
STMT_FETCH_NORMAL,
|
||||
STMT_FETCH_EXTENDED,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
COL_INFO *col_info; /* cached SQLColumns info for this table */
|
||||
char name[MAX_TABLE_LEN + 1];
|
||||
char alias[MAX_TABLE_LEN + 1];
|
||||
} TABLE_INFO;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
TABLE_INFO *ti; /* resolve to explicit table names */
|
||||
int precision;
|
||||
int display_size;
|
||||
@ -134,8 +146,10 @@ typedef struct {
|
||||
|
||||
|
||||
/******** Statement Handle ***********/
|
||||
struct StatementClass_ {
|
||||
ConnectionClass *hdbc; /* pointer to ConnectionClass this statement belongs to */
|
||||
struct StatementClass_
|
||||
{
|
||||
ConnectionClass *hdbc; /* pointer to ConnectionClass this
|
||||
* statement belongs to */
|
||||
QResultClass *result; /* result of the current statement */
|
||||
HSTMT FAR *phstmt;
|
||||
StatementOptions options;
|
||||
@ -153,15 +167,22 @@ struct StatementClass_ {
|
||||
int parameters_allocated;
|
||||
ParameterInfoClass *parameters;
|
||||
|
||||
Int4 currTuple; /* current absolute row number (GetData, SetPos, SQLFetch) */
|
||||
int save_rowset_size; /* saved rowset size in case of change/FETCH_NEXT */
|
||||
int rowset_start; /* start of rowset (an absolute row number) */
|
||||
int bind_row; /* current offset for Multiple row/column binding */
|
||||
int last_fetch_count; /* number of rows retrieved in last fetch/extended fetch */
|
||||
int current_col; /* current column for GetData -- used to handle multiple calls */
|
||||
Int4 currTuple; /* current absolute row number (GetData,
|
||||
* SetPos, SQLFetch) */
|
||||
int save_rowset_size; /* saved rowset size in case of
|
||||
* change/FETCH_NEXT */
|
||||
int rowset_start; /* start of rowset (an absolute row
|
||||
* number) */
|
||||
int bind_row; /* current offset for Multiple row/column
|
||||
* binding */
|
||||
int last_fetch_count; /* number of rows retrieved in
|
||||
* last fetch/extended fetch */
|
||||
int current_col; /* current column for GetData -- used to
|
||||
* handle multiple calls */
|
||||
int lobj_fd; /* fd of the current large object */
|
||||
|
||||
char *statement; /* if non--null pointer to the SQL statement that has been executed */
|
||||
char *statement; /* if non--null pointer to the SQL
|
||||
* statement that has been executed */
|
||||
|
||||
TABLE_INFO **ti;
|
||||
FIELD_INFO **fi;
|
||||
@ -172,19 +193,25 @@ struct StatementClass_ {
|
||||
|
||||
int statement_type; /* According to the defines above */
|
||||
int data_at_exec; /* Number of params needing SQLPutData */
|
||||
int current_exec_param; /* The current parameter for SQLPutData */
|
||||
int current_exec_param; /* The current parameter for
|
||||
* SQLPutData */
|
||||
|
||||
char put_data; /* Has SQLPutData been called yet? */
|
||||
|
||||
char errormsg_created; /* has an informative error msg been created? */
|
||||
char errormsg_created; /* has an informative error msg
|
||||
* been created? */
|
||||
char manual_result; /* Is the statement result manually built? */
|
||||
char prepare; /* is this statement a prepared statement or direct */
|
||||
char prepare; /* is this statement a prepared statement
|
||||
* or direct */
|
||||
|
||||
char internal; /* Is this statement being called internally? */
|
||||
char internal; /* Is this statement being called
|
||||
* internally? */
|
||||
|
||||
char cursor_name[MAX_CURSOR_LEN + 1];
|
||||
|
||||
char stmt_with_params[STD_STATEMENT_LEN]; /* statement after parameter substitution */
|
||||
char stmt_with_params[STD_STATEMENT_LEN]; /* statement after
|
||||
* parameter
|
||||
* substitution */
|
||||
|
||||
};
|
||||
|
||||
|
@ -18,13 +18,15 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void set_tuplefield_null(TupleField *tuple_field)
|
||||
void
|
||||
set_tuplefield_null(TupleField * tuple_field)
|
||||
{
|
||||
tuple_field->len = 0;
|
||||
tuple_field->value = NULL; /* strdup(""); */
|
||||
}
|
||||
|
||||
void set_tuplefield_string(TupleField *tuple_field, char *string)
|
||||
void
|
||||
set_tuplefield_string(TupleField * tuple_field, char *string)
|
||||
{
|
||||
tuple_field->len = strlen(string);
|
||||
tuple_field->value = malloc(strlen(string) + 1);
|
||||
@ -32,7 +34,8 @@ void set_tuplefield_string(TupleField *tuple_field, char *string)
|
||||
}
|
||||
|
||||
|
||||
void set_tuplefield_int2(TupleField *tuple_field, Int2 value)
|
||||
void
|
||||
set_tuplefield_int2(TupleField * tuple_field, Int2 value)
|
||||
{
|
||||
char buffer[10];
|
||||
|
||||
@ -44,7 +47,8 @@ char buffer[10];
|
||||
tuple_field->value = strdup(buffer);
|
||||
}
|
||||
|
||||
void set_tuplefield_int4(TupleField *tuple_field, Int4 value)
|
||||
void
|
||||
set_tuplefield_int4(TupleField * tuple_field, Int4 value)
|
||||
{
|
||||
char buffer[15];
|
||||
|
||||
|
@ -17,14 +17,17 @@
|
||||
#include "psqlodbc.h"
|
||||
|
||||
/* Used by backend data AND manual result sets */
|
||||
struct TupleField_ {
|
||||
struct TupleField_
|
||||
{
|
||||
Int4 len; /* length of the current Tuple */
|
||||
void *value; /* an array representing the value */
|
||||
};
|
||||
|
||||
/* Used ONLY for manual result sets */
|
||||
struct TupleNode_ {
|
||||
struct TupleNode_ *prev, *next;
|
||||
struct TupleNode_
|
||||
{
|
||||
struct TupleNode_ *prev,
|
||||
*next;
|
||||
TupleField tuple[1];
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,8 @@ TupleListClass *rv;
|
||||
mylog("in TL_Constructor\n");
|
||||
|
||||
rv = (TupleListClass *) malloc(sizeof(TupleListClass));
|
||||
if (rv) {
|
||||
if (rv)
|
||||
{
|
||||
|
||||
rv->num_fields = fieldcnt;
|
||||
rv->num_tuples = 0;
|
||||
@ -42,16 +43,17 @@ void
|
||||
TL_Destructor(TupleListClass * self)
|
||||
{
|
||||
int lf;
|
||||
TupleNode *node, *tp;
|
||||
TupleNode *node,
|
||||
*tp;
|
||||
|
||||
mylog("TupleList: in DESTRUCTOR\n");
|
||||
|
||||
node = self->list_start;
|
||||
while(node != NULL) {
|
||||
while (node != NULL)
|
||||
{
|
||||
for (lf = 0; lf < self->num_fields; lf++)
|
||||
if (node->tuple[lf].value != NULL) {
|
||||
if (node->tuple[lf].value != NULL)
|
||||
free(node->tuple[lf].value);
|
||||
}
|
||||
tp = node->next;
|
||||
free(node);
|
||||
node = tp;
|
||||
@ -67,8 +69,10 @@ void *
|
||||
TL_get_fieldval(TupleListClass * self, Int4 tupleno, Int2 fieldno)
|
||||
{
|
||||
Int4 lf;
|
||||
Int4 delta, from_end;
|
||||
char end_is_closer, start_is_closer;
|
||||
Int4 delta,
|
||||
from_end;
|
||||
char end_is_closer,
|
||||
start_is_closer;
|
||||
TupleNode *rv;
|
||||
|
||||
if (self->last_indexed == -1)
|
||||
@ -84,9 +88,10 @@ TupleNode *rv;
|
||||
/* illegel field number range */
|
||||
return NULL;
|
||||
|
||||
/* check if we are accessing the same tuple that was used in
|
||||
the last fetch (e.g: for fetching all the fields one after
|
||||
another. Do this to speed things up
|
||||
/*
|
||||
* check if we are accessing the same tuple that was used in the last
|
||||
* fetch (e.g: for fetching all the fields one after another. Do this
|
||||
* to speed things up
|
||||
*/
|
||||
if (tupleno == self->last_indexed)
|
||||
return self->lastref->tuple[fieldno].value;
|
||||
@ -94,56 +99,76 @@ TupleNode *rv;
|
||||
/* now for the tricky part... */
|
||||
|
||||
/*
|
||||
Since random access is quite inefficient for linked lists we use
|
||||
the lastref pointer that points to the last element referenced
|
||||
by a get_fieldval() call in conjunction with the its index number
|
||||
that is stored in last_indexed. (So we use some locality of
|
||||
reference principle to speed things up)
|
||||
* Since random access is quite inefficient for linked lists we use
|
||||
* the lastref pointer that points to the last element referenced by a
|
||||
* get_fieldval() call in conjunction with the its index number that
|
||||
* is stored in last_indexed. (So we use some locality of reference
|
||||
* principle to speed things up)
|
||||
*/
|
||||
|
||||
delta = tupleno - self->last_indexed;
|
||||
/* if delta is positive, we have to go forward */
|
||||
|
||||
/* now check if we are closer to the start or the end of the list
|
||||
than to our last_indexed pointer
|
||||
/*
|
||||
* now check if we are closer to the start or the end of the list than
|
||||
* to our last_indexed pointer
|
||||
*/
|
||||
from_end = (self->num_tuples - 1) - tupleno;
|
||||
|
||||
start_is_closer = labs(delta) > tupleno;
|
||||
/* true if we are closer to the start of the list than to the
|
||||
last_indexed pointer
|
||||
|
||||
/*
|
||||
* true if we are closer to the start of the list than to the
|
||||
* last_indexed pointer
|
||||
*/
|
||||
|
||||
end_is_closer = labs(delta) > from_end;
|
||||
/* true if we are closer at the end of the list */
|
||||
|
||||
if (end_is_closer) {
|
||||
if (end_is_closer)
|
||||
{
|
||||
/* scanning from the end is the shortest way. so we do that... */
|
||||
rv = self->list_end;
|
||||
for (lf = 0; lf < from_end; lf++)
|
||||
rv = rv->prev;
|
||||
} else if (start_is_closer) {
|
||||
/* the shortest way is to start the search from the head of the list */
|
||||
}
|
||||
else if (start_is_closer)
|
||||
{
|
||||
|
||||
/*
|
||||
* the shortest way is to start the search from the head of the
|
||||
* list
|
||||
*/
|
||||
rv = self->list_start;
|
||||
for (lf = 0; lf < tupleno; lf++)
|
||||
rv = rv->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the closest way is starting from our lastref - pointer */
|
||||
rv = self->lastref;
|
||||
/* at first determine whether we have to search forward or backwards */
|
||||
if (delta < 0) {
|
||||
|
||||
/*
|
||||
* at first determine whether we have to search forward or
|
||||
* backwards
|
||||
*/
|
||||
if (delta < 0)
|
||||
{
|
||||
/* we have to search backwards */
|
||||
for (lf = 0; lf < (-1) * delta; lf++)
|
||||
rv = rv->prev;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ok, we have to search forward... */
|
||||
for (lf = 0; lf < delta; lf++)
|
||||
rv = rv->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* now we have got our return pointer, so update the lastref
|
||||
and the last_indexed values
|
||||
/*
|
||||
* now we have got our return pointer, so update the lastref and the
|
||||
* last_indexed values
|
||||
*/
|
||||
self->lastref = rv;
|
||||
self->last_indexed = tupleno;
|
||||
@ -156,22 +181,29 @@ TupleNode *rv;
|
||||
char
|
||||
TL_add_tuple(TupleListClass * self, TupleNode * new_field)
|
||||
{
|
||||
/* we append the tuple at the end of the doubly linked list
|
||||
of the tuples we have already read in
|
||||
|
||||
/*
|
||||
* we append the tuple at the end of the doubly linked list of the
|
||||
* tuples we have already read in
|
||||
*/
|
||||
|
||||
new_field->prev = NULL;
|
||||
new_field->next = NULL;
|
||||
|
||||
if (self->list_start == NULL) {
|
||||
if (self->list_start == NULL)
|
||||
{
|
||||
/* the list is empty, we have to add the first tuple */
|
||||
self->list_start = new_field;
|
||||
self->list_end = new_field;
|
||||
self->lastref = new_field;
|
||||
self->last_indexed = 0;
|
||||
} else {
|
||||
/* there is already an element in the list, so add the new
|
||||
one at the end of the list
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* there is already an element in the list, so add the new one at
|
||||
* the end of the list
|
||||
*/
|
||||
self->list_end->next = new_field;
|
||||
new_field->prev = self->list_end;
|
||||
@ -182,5 +214,3 @@ TL_add_tuple(TupleListClass *self, TupleNode *new_field)
|
||||
/* this method of building a list cannot fail, so we return 1 */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,10 +15,13 @@
|
||||
|
||||
#include "psqlodbc.h"
|
||||
|
||||
struct TupleListClass_ {
|
||||
struct TupleListClass_
|
||||
{
|
||||
Int4 num_fields;
|
||||
Int4 num_tuples;
|
||||
TupleNode *list_start, *list_end, *lastref;
|
||||
TupleNode *list_start,
|
||||
*list_end,
|
||||
*lastref;
|
||||
Int4 last_indexed;
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@ This can format all PostgreSQL *.c and *.h files, excluding libpq++,
|
||||
|
||||
On 09/06/1997, from the top directory, I ran:
|
||||
|
||||
find . -name '*.[ch]' -type f -print | egrep -v '\+\+|/odbc/|s_lock.h' | xargs -n100 pgindent
|
||||
find . -name '*.[ch]' -type f -print | egrep -v '\+\+|s_lock.h' | xargs -n100 pgindent
|
||||
|
||||
The stock BSD indent has two bugs. First, a comment after the word 'else'
|
||||
causes the rest of the file to be ignored. Second, it silently ignores
|
||||
|
Loading…
x
Reference in New Issue
Block a user