Commit 0c439e5e authored by Hiroshi Inoue's avatar Hiroshi Inoue

1) Change all internal SQL function calls from

   SQLxxxx() to PGAPI_xxxx().
2) Handle an escaped date/time format as a parameter.
3) Improve the tuple allocation a little.
4) The preparation of ODBC 3.0 a little.
5) Updatable cursors(may be deprecated before long).
parent 58d4f951
...@@ -33,11 +33,12 @@ ...@@ -33,11 +33,12 @@
#include "sql.h" #include "sql.h"
#include "sqlext.h" #include "sqlext.h"
#endif #endif
#include "pgapifunc.h"
/* Bind parameters on a statement handle */ /* Bind parameters on a statement handle */
RETCODE SQL_API RETCODE SQL_API
SQLBindParameter( PGAPI_BindParameter(
HSTMT hstmt, HSTMT hstmt,
UWORD ipar, UWORD ipar,
SWORD fParamType, SWORD fParamType,
...@@ -50,7 +51,7 @@ SQLBindParameter( ...@@ -50,7 +51,7 @@ SQLBindParameter(
SDWORD FAR *pcbValue) SDWORD FAR *pcbValue)
{ {
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
static char *func = "SQLBindParameter"; static char *func = "PGAPI_BindParameter";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -155,7 +156,7 @@ SQLBindParameter( ...@@ -155,7 +156,7 @@ SQLBindParameter(
if (stmt->status == STMT_PREMATURE) if (stmt->status == STMT_PREMATURE)
SC_recycle_statement(stmt); SC_recycle_statement(stmt);
mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue : -777, stmt->parameters[ipar].data_at_exec); mylog("PGAPI_BindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue : -777, stmt->parameters[ipar].data_at_exec);
return SQL_SUCCESS; return SQL_SUCCESS;
} }
...@@ -163,7 +164,7 @@ SQLBindParameter( ...@@ -163,7 +164,7 @@ SQLBindParameter(
/* Associate a user-supplied buffer with a database column. */ /* Associate a user-supplied buffer with a database column. */
RETCODE SQL_API RETCODE SQL_API
SQLBindCol( PGAPI_BindCol(
HSTMT hstmt, HSTMT hstmt,
UWORD icol, UWORD icol,
SWORD fCType, SWORD fCType,
...@@ -172,11 +173,12 @@ SQLBindCol( ...@@ -172,11 +173,12 @@ SQLBindCol(
SDWORD FAR *pcbValue) SDWORD FAR *pcbValue)
{ {
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
static char *func = "SQLBindCol"; static char *func = "PGAPI_BindCol";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol); mylog("**** PGAPI_BindCol: stmt = %u, icol = %d\n", stmt, icol);
mylog("**** : fCType=%d rgb=%x valusMax=%d pcb=%x\n", fCType, rgbValue, cbValueMax, pcbValue);
if (!stmt) if (!stmt)
{ {
...@@ -275,7 +277,7 @@ SQLBindCol( ...@@ -275,7 +277,7 @@ SQLBindCol(
* data type (most likely varchar). * data type (most likely varchar).
*/ */
RETCODE SQL_API RETCODE SQL_API
SQLDescribeParam( PGAPI_DescribeParam(
HSTMT hstmt, HSTMT hstmt,
UWORD ipar, UWORD ipar,
SWORD FAR *pfSqlType, SWORD FAR *pfSqlType,
...@@ -284,7 +286,7 @@ SQLDescribeParam( ...@@ -284,7 +286,7 @@ SQLDescribeParam(
SWORD FAR *pfNullable) SWORD FAR *pfNullable)
{ {
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
static char *func = "SQLDescribeParam"; static char *func = "PGAPI_DescribeParam";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -297,7 +299,7 @@ SQLDescribeParam( ...@@ -297,7 +299,7 @@ SQLDescribeParam(
if ((ipar < 1) || (ipar > stmt->parameters_allocated)) if ((ipar < 1) || (ipar > stmt->parameters_allocated))
{ {
stmt->errormsg = "Invalid parameter number for SQLDescribeParam."; stmt->errormsg = "Invalid parameter number for PGAPI_DescribeParam.";
stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR; stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR;
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
...@@ -328,15 +330,18 @@ SQLDescribeParam( ...@@ -328,15 +330,18 @@ SQLDescribeParam(
/* Sets multiple values (arrays) for the set of parameter markers. */ /* Sets multiple values (arrays) for the set of parameter markers. */
RETCODE SQL_API RETCODE SQL_API
SQLParamOptions( PGAPI_ParamOptions(
HSTMT hstmt, HSTMT hstmt,
UDWORD crow, UDWORD crow,
UDWORD FAR *pirow) UDWORD FAR *pirow)
{ {
static char *func = "SQLParamOptions"; static char *func = "PGAPI_ParamOptions";
StatementClass *stmt = (StatementClass *) hstmt;
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
stmt->errornumber = CONN_UNSUPPORTED_OPTION;
stmt->errormsg = "Function not implemented";
SC_log_error(func, "Function not implemented", (StatementClass *) hstmt); SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -352,14 +357,14 @@ SQLParamOptions( ...@@ -352,14 +357,14 @@ SQLParamOptions(
* If the statement does not have parameters, it should just return 0. * If the statement does not have parameters, it should just return 0.
*/ */
RETCODE SQL_API RETCODE SQL_API
SQLNumParams( PGAPI_NumParams(
HSTMT hstmt, HSTMT hstmt,
SWORD FAR *pcpar) SWORD FAR *pcpar)
{ {
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
char in_quote = FALSE; char in_quote = FALSE;
unsigned int i; unsigned int i;
static char *func = "SQLNumParams"; static char *func = "PGAPI_NumParams";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -382,7 +387,7 @@ SQLNumParams( ...@@ -382,7 +387,7 @@ SQLNumParams(
if (!stmt->statement) if (!stmt->statement)
{ {
/* no statement has been allocated */ /* no statement has been allocated */
stmt->errormsg = "SQLNumParams called with no statement ready."; stmt->errormsg = "PGAPI_NumParams called with no statement ready.";
stmt->errornumber = STMT_SEQUENCE_ERROR; stmt->errornumber = STMT_SEQUENCE_ERROR;
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "socket.h" #include "socket.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "pgapifunc.h"
ColumnInfoClass * ColumnInfoClass *
CI_Constructor() CI_Constructor()
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#ifdef WIN32 #ifdef WIN32
#include <odbcinst.h> #include <odbcinst.h>
#endif #endif
#include "pgapifunc.h"
#define STMT_INCREMENT 16 /* how many statement holders to allocate #define STMT_INCREMENT 16 /* how many statement holders to allocate
* at a time */ * at a time */
...@@ -46,13 +47,13 @@ extern GLOBAL_VALUES globals; ...@@ -46,13 +47,13 @@ extern GLOBAL_VALUES globals;
RETCODE SQL_API RETCODE SQL_API
SQLAllocConnect( PGAPI_AllocConnect(
HENV henv, HENV henv,
HDBC FAR *phdbc) HDBC FAR *phdbc)
{ {
EnvironmentClass *env = (EnvironmentClass *) henv; EnvironmentClass *env = (EnvironmentClass *) henv;
ConnectionClass *conn; ConnectionClass *conn;
static char *func = "SQLAllocConnect"; static char *func = "PGAPI_AllocConnect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -85,7 +86,7 @@ SQLAllocConnect( ...@@ -85,7 +86,7 @@ SQLAllocConnect(
RETCODE SQL_API RETCODE SQL_API
SQLConnect( PGAPI_Connect(
HDBC hdbc, HDBC hdbc,
UCHAR FAR *szDSN, UCHAR FAR *szDSN,
SWORD cbDSN, SWORD cbDSN,
...@@ -96,7 +97,7 @@ SQLConnect( ...@@ -96,7 +97,7 @@ SQLConnect(
{ {
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci; ConnInfo *ci;
static char *func = "SQLConnect"; static char *func = "PGAPI_Connect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -141,7 +142,7 @@ SQLConnect( ...@@ -141,7 +142,7 @@ SQLConnect(
RETCODE SQL_API RETCODE SQL_API
SQLBrowseConnect( PGAPI_BrowseConnect(
HDBC hdbc, HDBC hdbc,
UCHAR FAR *szConnStrIn, UCHAR FAR *szConnStrIn,
SWORD cbConnStrIn, SWORD cbConnStrIn,
...@@ -149,7 +150,7 @@ SQLBrowseConnect( ...@@ -149,7 +150,7 @@ SQLBrowseConnect(
SWORD cbConnStrOutMax, SWORD cbConnStrOutMax,
SWORD FAR *pcbConnStrOut) SWORD FAR *pcbConnStrOut)
{ {
static char *func = "SQLBrowseConnect"; static char *func = "PGAPI_BrowseConnect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -159,11 +160,11 @@ SQLBrowseConnect( ...@@ -159,11 +160,11 @@ SQLBrowseConnect(
/* Drop any hstmts open on hdbc and disconnect from database */ /* Drop any hstmts open on hdbc and disconnect from database */
RETCODE SQL_API RETCODE SQL_API
SQLDisconnect( PGAPI_Disconnect(
HDBC hdbc) HDBC hdbc)
{ {
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
static char *func = "SQLDisconnect"; static char *func = "PGAPI_Disconnect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -197,11 +198,11 @@ SQLDisconnect( ...@@ -197,11 +198,11 @@ SQLDisconnect(
RETCODE SQL_API RETCODE SQL_API
SQLFreeConnect( PGAPI_FreeConnect(
HDBC hdbc) HDBC hdbc)
{ {
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
static char *func = "SQLFreeConnect"; static char *func = "PGAPI_FreeConnect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
mylog("**** in %s: hdbc=%u\n", func, hdbc); mylog("**** in %s: hdbc=%u\n", func, hdbc);
...@@ -272,6 +273,7 @@ CC_Constructor() ...@@ -272,6 +273,7 @@ CC_Constructor()
rv->translation_handle = NULL; rv->translation_handle = NULL;
rv->DataSourceToDriver = NULL; rv->DataSourceToDriver = NULL;
rv->DriverToDataSource = NULL; rv->DriverToDataSource = NULL;
rv->driver_version = ODBCVER;
memset(rv->pg_version, 0, sizeof(rv->pg_version)); memset(rv->pg_version, 0, sizeof(rv->pg_version));
rv->pg_version_number = .0; rv->pg_version_number = .0;
rv->pg_version_major = 0; rv->pg_version_major = 0;
...@@ -1409,7 +1411,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1409,7 +1411,7 @@ CC_send_settings(ConnectionClass *self)
* has not transitioned to "connected" yet. * has not transitioned to "connected" yet.
*/ */
result = SQLAllocStmt(self, &hstmt); result = PGAPI_AllocStmt(self, &hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return FALSE; return FALSE;
stmt = (StatementClass *) hstmt; stmt = (StatementClass *) hstmt;
...@@ -1417,7 +1419,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1417,7 +1419,7 @@ CC_send_settings(ConnectionClass *self)
stmt->internal = TRUE; /* ensure no BEGIN/COMMIT/ABORT stuff */ stmt->internal = TRUE; /* ensure no BEGIN/COMMIT/ABORT stuff */
/* Set the Datestyle to the format the driver expects it to be in */ /* Set the Datestyle to the format the driver expects it to be in */
result = SQLExecDirect(hstmt, "set DateStyle to 'ISO'", SQL_NTS); result = PGAPI_ExecDirect(hstmt, "set DateStyle to 'ISO'", SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
status = FALSE; status = FALSE;
...@@ -1426,7 +1428,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1426,7 +1428,7 @@ CC_send_settings(ConnectionClass *self)
/* Disable genetic optimizer based on global flag */ /* Disable genetic optimizer based on global flag */
if (globals.disable_optimizer) if (globals.disable_optimizer)
{ {
result = SQLExecDirect(hstmt, "set geqo to 'OFF'", SQL_NTS); result = PGAPI_ExecDirect(hstmt, "set geqo to 'OFF'", SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
status = FALSE; status = FALSE;
...@@ -1437,7 +1439,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1437,7 +1439,7 @@ CC_send_settings(ConnectionClass *self)
/* KSQO */ /* KSQO */
if (globals.ksqo) if (globals.ksqo)
{ {
result = SQLExecDirect(hstmt, "set ksqo to 'ON'", SQL_NTS); result = PGAPI_ExecDirect(hstmt, "set ksqo to 'ON'", SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
status = FALSE; status = FALSE;
...@@ -1452,7 +1454,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1452,7 +1454,7 @@ CC_send_settings(ConnectionClass *self)
ptr = strtok(cs, ";"); ptr = strtok(cs, ";");
while (ptr) while (ptr)
{ {
result = SQLExecDirect(hstmt, ptr, SQL_NTS); result = PGAPI_ExecDirect(hstmt, ptr, SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
status = FALSE; status = FALSE;
...@@ -1471,7 +1473,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1471,7 +1473,7 @@ CC_send_settings(ConnectionClass *self)
ptr = strtok(cs, ";"); ptr = strtok(cs, ";");
while (ptr) while (ptr)
{ {
result = SQLExecDirect(hstmt, ptr, SQL_NTS); result = PGAPI_ExecDirect(hstmt, ptr, SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
status = FALSE; status = FALSE;
...@@ -1484,7 +1486,7 @@ CC_send_settings(ConnectionClass *self) ...@@ -1484,7 +1486,7 @@ CC_send_settings(ConnectionClass *self)
} }
SQLFreeStmt(hstmt, SQL_DROP); PGAPI_FreeStmt(hstmt, SQL_DROP);
return status; return status;
} }
...@@ -1509,36 +1511,36 @@ CC_lookup_lo(ConnectionClass *self) ...@@ -1509,36 +1511,36 @@ CC_lookup_lo(ConnectionClass *self)
* This function must use the local odbc API functions since the odbc state * This function must use the local odbc API functions since the odbc state
* has not transitioned to "connected" yet. * has not transitioned to "connected" yet.
*/ */
result = SQLAllocStmt(self, &hstmt); result = PGAPI_AllocStmt(self, &hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return; return;
stmt = (StatementClass *) hstmt; stmt = (StatementClass *) hstmt;
result = SQLExecDirect(hstmt, "select oid from pg_type where typname='" PG_TYPE_LO_NAME "'", SQL_NTS); result = PGAPI_ExecDirect(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); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
result = SQLFetch(hstmt); result = PGAPI_Fetch(hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
{ {
SQLFreeStmt(hstmt, SQL_DROP); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
result = SQLGetData(hstmt, 1, SQL_C_SLONG, &self->lobj_type, sizeof(self->lobj_type), NULL); result = PGAPI_GetData(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); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
mylog("Got the large object oid: %d\n", self->lobj_type); mylog("Got the large object oid: %d\n", self->lobj_type);
qlog(" [ Large Object oid = %d ]\n", self->lobj_type); qlog(" [ Large Object oid = %d ]\n", self->lobj_type);
result = SQLFreeStmt(hstmt, SQL_DROP); result = PGAPI_FreeStmt(hstmt, SQL_DROP);
} }
...@@ -1594,30 +1596,30 @@ CC_lookup_pg_version(ConnectionClass *self) ...@@ -1594,30 +1596,30 @@ CC_lookup_pg_version(ConnectionClass *self)
* This function must use the local odbc API functions since the odbc state * This function must use the local odbc API functions since the odbc state
* has not transitioned to "connected" yet. * has not transitioned to "connected" yet.
*/ */
result = SQLAllocStmt(self, &hstmt); result = PGAPI_AllocStmt(self, &hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return; return;
stmt = (StatementClass *) hstmt; stmt = (StatementClass *) hstmt;
/* get the server's version if possible */ /* get the server's version if possible */
result = SQLExecDirect(hstmt, "select version()", SQL_NTS); result = PGAPI_ExecDirect(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); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
result = SQLFetch(hstmt); result = PGAPI_Fetch(hstmt);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
{ {
SQLFreeStmt(hstmt, SQL_DROP); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
result = SQLGetData(hstmt, 1, SQL_C_CHAR, self->pg_version, MAX_INFO_STRING, NULL); result = PGAPI_GetData(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); PGAPI_FreeStmt(hstmt, SQL_DROP);
return; return;
} }
...@@ -1639,7 +1641,7 @@ CC_lookup_pg_version(ConnectionClass *self) ...@@ -1639,7 +1641,7 @@ CC_lookup_pg_version(ConnectionClass *self)
qlog(" [ PostgreSQL version string = '%s' ]\n", self->pg_version); qlog(" [ PostgreSQL version string = '%s' ]\n", self->pg_version);
qlog(" [ PostgreSQL version number = '%1.1f' ]\n", self->pg_version_number); qlog(" [ PostgreSQL version number = '%1.1f' ]\n", self->pg_version_number);
result = SQLFreeStmt(hstmt, SQL_DROP); result = PGAPI_FreeStmt(hstmt, SQL_DROP);
} }
......
...@@ -264,6 +264,7 @@ struct ConnectionClass_ ...@@ -264,6 +264,7 @@ struct ConnectionClass_
HINSTANCE translation_handle; HINSTANCE translation_handle;
DataSourceToDriverProc DataSourceToDriver; DataSourceToDriverProc DataSourceToDriver;
DriverToDataSourceProc DriverToDataSource; DriverToDataSourceProc DriverToDataSource;
Int2 driver_version; /* prepared for ODBC3.0 */
char transact_status;/* Is a transaction is currently in char transact_status;/* Is a transaction is currently in
* progress */ * progress */
char errormsg_created; /* has an informative error msg char errormsg_created; /* has an informative error msg
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "pgtypes.h" #include "pgtypes.h"
#include "lobj.h" #include "lobj.h"
#include "connection.h" #include "connection.h"
#include "pgapifunc.h"
#ifndef WIN32 #ifndef WIN32
#ifndef HAVE_STRICMP #ifndef HAVE_STRICMP
...@@ -973,6 +974,9 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -973,6 +974,9 @@ copy_statement_with_parameters(StatementClass *stmt)
retval; retval;
BOOL check_select_into = FALSE; /* select into check */ BOOL check_select_into = FALSE; /* select into check */
unsigned int declare_pos; unsigned int declare_pos;
#ifdef DRIVER_CURSOR_IMPLEMENT
BOOL ins_ctrl = FALSE;
#endif /* DRIVER_CURSOR_IMPLEMENT */
if (!old_statement) if (!old_statement)
...@@ -1003,9 +1007,27 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1003,9 +1007,27 @@ copy_statement_with_parameters(StatementClass *stmt)
check_select_into = TRUE; check_select_into = TRUE;
declare_pos = npos; declare_pos = npos;
} }
param_number = -1; param_number = -1;
#ifdef DRIVER_CURSOR_IMPLEMENT
if (stmt->statement_type != STMT_TYPE_SELECT)
{
stmt->options.cursor_type = SQL_CURSOR_FORWARD_ONLY;
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
}
else if (stmt->options.cursor_type == SQL_CURSOR_FORWARD_ONLY)
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
else if (stmt->options.scroll_concurrency != SQL_CONCUR_READ_ONLY)
{
if (stmt->parse_status == STMT_PARSE_NONE)
parse_statement(stmt);
if (stmt->parse_status != STMT_PARSE_COMPLETE)
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
else if (!stmt->ti || stmt->ntab != 1)
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
else ins_ctrl = TRUE;
}
#endif /* DRIVER_CURSOR_IMPLEMENT */
#ifdef MULTIBYTE #ifdef MULTIBYTE
multibyte_init(); multibyte_init();
#endif #endif
...@@ -1136,9 +1158,20 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1136,9 +1158,20 @@ copy_statement_with_parameters(StatementClass *stmt)
into_table_from(&old_statement[opos])) into_table_from(&old_statement[opos]))
{ {
stmt->statement_type = STMT_TYPE_CREATE; stmt->statement_type = STMT_TYPE_CREATE;
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
memmove(new_statement, new_statement + declare_pos, npos - declare_pos); memmove(new_statement, new_statement + declare_pos, npos - declare_pos);
npos -= declare_pos; npos -= declare_pos;
} }
#ifdef DRIVER_CURSOR_IMPLEMENT
else if (ins_ctrl && /* select into check */
opos > 0 &&
isspace((unsigned char) old_statement[opos - 1]) &&
strnicmp(&old_statement[opos], "from", 4) == 0)
{
ins_ctrl = FALSE;
CVT_APPEND_STR(", CTID, OID ");
}
#endif /* DRIVER_CURSOR_IMPLEMENT */
CVT_APPEND_CHAR(oldchar); CVT_APPEND_CHAR(oldchar);
continue; continue;
} }
...@@ -1574,6 +1607,10 @@ copy_statement_with_parameters(StatementClass *stmt) ...@@ -1574,6 +1607,10 @@ copy_statement_with_parameters(StatementClass *stmt)
NULL, 0, NULL); NULL, 0, NULL);
} }
#ifdef DRIVER_CURSOR_IMPLEMENT
if (ins_ctrl)
stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
#endif /* DRIVER_CURSOR_IMPLEMENT */
return SQL_SUCCESS; return SQL_SUCCESS;
} }
...@@ -1715,6 +1752,14 @@ parse_datetime(char *buf, SIMPLE_TIME *st) ...@@ -1715,6 +1752,14 @@ parse_datetime(char *buf, SIMPLE_TIME *st)
y = m = d = hh = mm = ss = 0; y = m = d = hh = mm = ss = 0;
/* escape sequence ? */
if (buf[0] == '{')
{
while (*(++buf) && *buf != '\'');
if (!(*buf))
return FALSE;
buf++;
}
if (buf[4] == '-') /* year first */ if (buf[4] == '-') /* year first */
nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y, &m, &d, &hh, &mm, &ss); nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y, &m, &d, &hh, &mm, &ss);
else else
...@@ -1835,13 +1880,18 @@ convert_special_chars(char *si, char *dst, int used) ...@@ -1835,13 +1880,18 @@ convert_special_chars(char *si, char *dst, int used)
for (i = 0; i < max; i++) for (i = 0; i < max; i++)
{ {
#ifdef MULTIBYTE
if (multibyte_char_check(si[i]) != 0)
{
if (p)
p[out] = si[i];
out++;
continue;
}
#endif
if (si[i] == '\r' && si[i + 1] == '\n') if (si[i] == '\r' && si[i + 1] == '\n')
continue; continue;
#ifdef MULTIBYTE
else if (multibyte_char_check(si[i]) == 0 && (si[i] == '\'' || si[i] == '\\'))
#else
else if (si[i] == '\'' || si[i] == '\\') else if (si[i] == '\'' || si[i] == '\\')
#endif
{ {
if (p) if (p)
p[out++] = '\\'; p[out++] = '\\';
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#ifdef MULTIBYTE #ifdef MULTIBYTE
#include "multibyte.h" #include "multibyte.h"
#endif #endif
#include "pgapifunc.h"
#ifndef BOOL #ifndef BOOL
#define BOOL int #define BOOL int
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <odbcinst.h> #include <odbcinst.h>
#include "resource.h" #include "resource.h"
#endif #endif
#include "pgapifunc.h"
#ifndef TRUE #ifndef TRUE
#define TRUE (BOOL)1 #define TRUE (BOOL)1
...@@ -67,7 +68,7 @@ extern GLOBAL_VALUES globals; ...@@ -67,7 +68,7 @@ extern GLOBAL_VALUES globals;
RETCODE SQL_API RETCODE SQL_API
SQLDriverConnect( PGAPI_DriverConnect(
HDBC hdbc, HDBC hdbc,
HWND hwnd, HWND hwnd,
UCHAR FAR *szConnStrIn, UCHAR FAR *szConnStrIn,
...@@ -77,7 +78,7 @@ SQLDriverConnect( ...@@ -77,7 +78,7 @@ SQLDriverConnect(
SWORD FAR *pcbConnStrOut, SWORD FAR *pcbConnStrOut,
UWORD fDriverCompletion) UWORD fDriverCompletion)
{ {
static char *func = "SQLDriverConnect"; static char *func = "PGAPI_DriverConnect";
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
ConnInfo *ci; ConnInfo *ci;
...@@ -103,8 +104,8 @@ SQLDriverConnect( ...@@ -103,8 +104,8 @@ SQLDriverConnect(
make_string(szConnStrIn, cbConnStrIn, connStrIn); make_string(szConnStrIn, cbConnStrIn, connStrIn);
mylog("**** SQLDriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, connStrIn); mylog("**** PGAPI_DriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, connStrIn);
qlog("conn=%u, SQLDriverConnect( in)='%s', fDriverCompletion=%d\n", conn, connStrIn, fDriverCompletion); qlog("conn=%u, PGAPI_DriverConnect( in)='%s', fDriverCompletion=%d\n", conn, connStrIn, fDriverCompletion);
ci = &(conn->connInfo); ci = &(conn->connInfo);
...@@ -241,10 +242,10 @@ dialog: ...@@ -241,10 +242,10 @@ dialog:
*pcbConnStrOut = len; *pcbConnStrOut = len;
mylog("szConnStrOut = '%s'\n", szConnStrOut); mylog("szConnStrOut = '%s'\n", szConnStrOut);
qlog("conn=%u, SQLDriverConnect(out)='%s'\n", conn, szConnStrOut); qlog("conn=%u, PGAPI_DriverConnect(out)='%s'\n", conn, szConnStrOut);
mylog("SQLDRiverConnect: returning %d\n", result); mylog("PGAPI_DRiverConnect: returning %d\n", result);
return result; return result;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "statement.h" #include "statement.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "pgapifunc.h"
extern GLOBAL_VALUES globals; extern GLOBAL_VALUES globals;
...@@ -27,11 +28,11 @@ ConnectionClass *conns[MAX_CONNECTIONS]; ...@@ -27,11 +28,11 @@ ConnectionClass *conns[MAX_CONNECTIONS];
RETCODE SQL_API RETCODE SQL_API
SQLAllocEnv(HENV FAR *phenv) PGAPI_AllocEnv(HENV FAR *phenv)
{ {
static char *func = "SQLAllocEnv"; static char *func = "PGAPI_AllocEnv";
mylog("**** in SQLAllocEnv ** \n"); mylog("**** in PGAPI_AllocEnv ** \n");
/* /*
* Hack for systems on which none of the constructor-making techniques * Hack for systems on which none of the constructor-making techniques
...@@ -51,18 +52,18 @@ SQLAllocEnv(HENV FAR *phenv) ...@@ -51,18 +52,18 @@ SQLAllocEnv(HENV FAR *phenv)
return SQL_ERROR; return SQL_ERROR;
} }
mylog("** exit SQLAllocEnv: phenv = %u **\n", *phenv); mylog("** exit PGAPI_AllocEnv: phenv = %u **\n", *phenv);
return SQL_SUCCESS; return SQL_SUCCESS;
} }
RETCODE SQL_API RETCODE SQL_API
SQLFreeEnv(HENV henv) PGAPI_FreeEnv(HENV henv)
{ {
static char *func = "SQLFreeEnv"; static char *func = "PGAPI_FreeEnv";
EnvironmentClass *env = (EnvironmentClass *) henv; EnvironmentClass *env = (EnvironmentClass *) henv;
mylog("**** in SQLFreeEnv: env = %u ** \n", env); mylog("**** in PGAPI_FreeEnv: env = %u ** \n", env);
if (env && EN_Destructor(env)) if (env && EN_Destructor(env))
{ {
...@@ -78,7 +79,7 @@ SQLFreeEnv(HENV henv) ...@@ -78,7 +79,7 @@ SQLFreeEnv(HENV henv)
/* Returns the next SQL error information. */ /* Returns the next SQL error information. */
RETCODE SQL_API RETCODE SQL_API
SQLError( PGAPI_Error(
HENV henv, HENV henv,
HDBC hdbc, HDBC hdbc,
HSTMT hstmt, HSTMT hstmt,
...@@ -91,7 +92,7 @@ SQLError( ...@@ -91,7 +92,7 @@ SQLError(
char *msg; char *msg;
int status; int status;
mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u <%d>\n", henv, hdbc, hstmt, cbErrorMsgMax); mylog("**** PGAPI_Error: henv=%u, hdbc=%u, hstmt=%u <%d>\n", henv, hdbc, hstmt, cbErrorMsgMax);
if (cbErrorMsgMax < 0) if (cbErrorMsgMax < 0)
return SQL_ERROR; return SQL_ERROR;
...@@ -140,6 +141,10 @@ SQLError( ...@@ -140,6 +141,10 @@ SQLError(
switch (status) switch (status)
{ {
/* now determine the SQLSTATE to be returned */ /* now determine the SQLSTATE to be returned */
case STMT_ROW_VERSION_CHANGED:
strcpy(szSqlState, "01001");
/* data truncated */
break;
case STMT_TRUNCATED: case STMT_TRUNCATED:
strcpy(szSqlState, "01004"); strcpy(szSqlState, "01004");
/* data truncated */ /* data truncated */
...@@ -211,6 +216,9 @@ SQLError( ...@@ -211,6 +216,9 @@ SQLError(
case STMT_OPTION_VALUE_CHANGED: case STMT_OPTION_VALUE_CHANGED:
strcpy(szSqlState, "01S02"); strcpy(szSqlState, "01S02");
break; break;
case STMT_POS_BEFORE_RECORDSET:
strcpy(szSqlState, "01S06");
break;
case STMT_INVALID_CURSOR_NAME: case STMT_INVALID_CURSOR_NAME:
strcpy(szSqlState, "34000"); strcpy(szSqlState, "34000");
break; break;
...@@ -230,6 +238,9 @@ SQLError( ...@@ -230,6 +238,9 @@ SQLError(
case STMT_OPERATION_INVALID: case STMT_OPERATION_INVALID:
strcpy(szSqlState, "S1011"); strcpy(szSqlState, "S1011");
break; break;
case STMT_INVALID_OPTION_IDENTIFIER:
strcpy(szSqlState, "HY092");
break;
case STMT_EXEC_ERROR: case STMT_EXEC_ERROR:
default: default:
strcpy(szSqlState, "S1000"); strcpy(szSqlState, "S1000");
......
...@@ -36,17 +36,18 @@ ...@@ -36,17 +36,18 @@
#include "bind.h" #include "bind.h"
#include "pgtypes.h" #include "pgtypes.h"
#include "lobj.h" #include "lobj.h"
#include "pgapifunc.h"
extern GLOBAL_VALUES globals; extern GLOBAL_VALUES globals;
/* Perform a Prepare on the SQL statement */ /* Perform a Prepare on the SQL statement */
RETCODE SQL_API RETCODE SQL_API
SQLPrepare(HSTMT hstmt, PGAPI_Prepare(HSTMT hstmt,
UCHAR FAR *szSqlStr, UCHAR FAR *szSqlStr,
SDWORD cbSqlStr) SDWORD cbSqlStr)
{ {
static char *func = "SQLPrepare"; static char *func = "PGAPI_Prepare";
StatementClass *self = (StatementClass *) hstmt; StatementClass *self = (StatementClass *) hstmt;
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -66,31 +67,31 @@ SQLPrepare(HSTMT hstmt, ...@@ -66,31 +67,31 @@ SQLPrepare(HSTMT hstmt,
switch (self->status) switch (self->status)
{ {
case STMT_PREMATURE: case STMT_PREMATURE:
mylog("**** SQLPrepare: STMT_PREMATURE, recycle\n"); mylog("**** PGAPI_Prepare: STMT_PREMATURE, recycle\n");
SC_recycle_statement(self); /* recycle the statement, but do SC_recycle_statement(self); /* recycle the statement, but do
* not remove parameter bindings */ * not remove parameter bindings */
break; break;
case STMT_FINISHED: case STMT_FINISHED:
mylog("**** SQLPrepare: STMT_FINISHED, recycle\n"); mylog("**** PGAPI_Prepare: STMT_FINISHED, recycle\n");
SC_recycle_statement(self); /* recycle the statement, but do SC_recycle_statement(self); /* recycle the statement, but do
* not remove parameter bindings */ * not remove parameter bindings */
break; break;
case STMT_ALLOCATED: case STMT_ALLOCATED:
mylog("**** SQLPrepare: STMT_ALLOCATED, copy\n"); mylog("**** PGAPI_Prepare: STMT_ALLOCATED, copy\n");
self->status = STMT_READY; self->status = STMT_READY;
break; break;
case STMT_READY: case STMT_READY:
mylog("**** SQLPrepare: STMT_READY, change SQL\n"); mylog("**** PGAPI_Prepare: STMT_READY, change SQL\n");
break; break;
case STMT_EXECUTING: case STMT_EXECUTING:
mylog("**** SQLPrepare: STMT_EXECUTING, error!\n"); mylog("**** PGAPI_Prepare: STMT_EXECUTING, error!\n");
self->errornumber = STMT_SEQUENCE_ERROR; self->errornumber = STMT_SEQUENCE_ERROR;
self->errormsg = "SQLPrepare(): The handle does not point to a statement that is ready to be executed"; self->errormsg = "PGAPI_Prepare(): The handle does not point to a statement that is ready to be executed";
SC_log_error(func, "", self); SC_log_error(func, "", self);
return SQL_ERROR; return SQL_ERROR;
...@@ -132,14 +133,14 @@ SQLPrepare(HSTMT hstmt, ...@@ -132,14 +133,14 @@ SQLPrepare(HSTMT hstmt,
/* Performs the equivalent of SQLPrepare, followed by SQLExecute. */ /* Performs the equivalent of SQLPrepare, followed by SQLExecute. */
RETCODE SQL_API RETCODE SQL_API
SQLExecDirect( PGAPI_ExecDirect(
HSTMT hstmt, HSTMT hstmt,
UCHAR FAR *szSqlStr, UCHAR FAR *szSqlStr,
SDWORD cbSqlStr) SDWORD cbSqlStr)
{ {
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
RETCODE result; RETCODE result;
static char *func = "SQLExecDirect"; static char *func = "PGAPI_ExecDirect";
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -188,21 +189,21 @@ SQLExecDirect( ...@@ -188,21 +189,21 @@ SQLExecDirect(
return SQL_ERROR; return SQL_ERROR;
} }
mylog("%s: calling SQLExecute...\n", func); mylog("%s: calling PGAPI_Execute...\n", func);
result = SQLExecute(hstmt); result = PGAPI_Execute(hstmt);
mylog("%s: returned %hd from SQLExecute\n", func, result); mylog("%s: returned %hd from PGAPI_Execute\n", func, result);
return result; return result;
} }
/* Execute a prepared SQL statement */ /* Execute a prepared SQL statement */
RETCODE SQL_API RETCODE SQL_API
SQLExecute( PGAPI_Execute(
HSTMT hstmt) HSTMT hstmt)
{ {
static char *func = "SQLExecute"; static char *func = "PGAPI_Execute";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
ConnectionClass *conn; ConnectionClass *conn;
int i, int i,
...@@ -349,12 +350,12 @@ SQLExecute( ...@@ -349,12 +350,12 @@ SQLExecute(
RETCODE SQL_API RETCODE SQL_API
SQLTransact( PGAPI_Transact(
HENV henv, HENV henv,
HDBC hdbc, HDBC hdbc,
UWORD fType) UWORD fType)
{ {
static char *func = "SQLTransact"; static char *func = "PGAPI_Transact";
extern ConnectionClass *conns[]; extern ConnectionClass *conns[];
ConnectionClass *conn; ConnectionClass *conn;
QResultClass *res; QResultClass *res;
...@@ -381,7 +382,7 @@ SQLTransact( ...@@ -381,7 +382,7 @@ SQLTransact(
conn = conns[lf]; conn = conns[lf];
if (conn && conn->henv == henv) if (conn && conn->henv == henv)
if (SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS) if (PGAPI_Transact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
return SQL_ERROR; return SQL_ERROR;
} }
return SQL_SUCCESS; return SQL_SUCCESS;
...@@ -396,7 +397,7 @@ SQLTransact( ...@@ -396,7 +397,7 @@ SQLTransact(
else else
{ {
conn->errornumber = CONN_INVALID_ARGUMENT_NO; conn->errornumber = CONN_INVALID_ARGUMENT_NO;
conn->errormsg = "SQLTransact can only be called with SQL_COMMIT or SQL_ROLLBACK as parameter"; conn->errormsg = "PGAPI_Transact can only be called with SQL_COMMIT or SQL_ROLLBACK as parameter";
CC_log_error(func, "", conn); CC_log_error(func, "", conn);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -404,7 +405,7 @@ SQLTransact( ...@@ -404,7 +405,7 @@ SQLTransact(
/* If manual commit and in transaction, then proceed. */ /* 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); mylog("PGAPI_Transact: sending on conn %d '%s'\n", conn, stmt_string);
res = CC_send_query(conn, stmt_string, NULL); res = CC_send_query(conn, stmt_string, NULL);
CC_set_no_trans(conn); CC_set_no_trans(conn);
...@@ -430,10 +431,10 @@ SQLTransact( ...@@ -430,10 +431,10 @@ SQLTransact(
RETCODE SQL_API RETCODE SQL_API
SQLCancel( PGAPI_Cancel(
HSTMT hstmt) /* Statement to cancel. */ HSTMT hstmt) /* Statement to cancel. */
{ {
static char *func = "SQLCancel"; static char *func = "PGAPI_Cancel";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
RETCODE result; RETCODE result;
...@@ -476,12 +477,12 @@ SQLCancel( ...@@ -476,12 +477,12 @@ SQLCancel(
result = addr((char *) (stmt->phstmt) - 96, SQL_CLOSE); result = addr((char *) (stmt->phstmt) - 96, SQL_CLOSE);
} }
else else
result = SQLFreeStmt(hstmt, SQL_CLOSE); result = PGAPI_FreeStmt(hstmt, SQL_CLOSE);
#else #else
result = SQLFreeStmt(hstmt, SQL_CLOSE); result = PGAPI_FreeStmt(hstmt, SQL_CLOSE);
#endif #endif
mylog("SQLCancel: SQLFreeStmt returned %d\n", result); mylog("PGAPI_Cancel: PGAPI_FreeStmt returned %d\n", result);
SC_clear_error(hstmt); SC_clear_error(hstmt);
return SQL_SUCCESS; return SQL_SUCCESS;
...@@ -509,7 +510,7 @@ SQLCancel( ...@@ -509,7 +510,7 @@ SQLCancel(
* observing buffer limits and truncation. * observing buffer limits and truncation.
*/ */
RETCODE SQL_API RETCODE SQL_API
SQLNativeSql( PGAPI_NativeSql(
HDBC hdbc, HDBC hdbc,
UCHAR FAR *szSqlStrIn, UCHAR FAR *szSqlStrIn,
SDWORD cbSqlStrIn, SDWORD cbSqlStrIn,
...@@ -517,7 +518,7 @@ SQLNativeSql( ...@@ -517,7 +518,7 @@ SQLNativeSql(
SDWORD cbSqlStrMax, SDWORD cbSqlStrMax,
SDWORD FAR *pcbSqlStr) SDWORD FAR *pcbSqlStr)
{ {
static char *func = "SQLNativeSql"; static char *func = "PGAPI_NativeSql";
int len = 0; int len = 0;
char *ptr; char *ptr;
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
...@@ -552,6 +553,7 @@ SQLNativeSql( ...@@ -552,6 +553,7 @@ SQLNativeSql(
if (pcbSqlStr) if (pcbSqlStr)
*pcbSqlStr = len; *pcbSqlStr = len;
if (cbSqlStrIn)
free(ptr); free(ptr);
return result; return result;
...@@ -563,11 +565,11 @@ SQLNativeSql( ...@@ -563,11 +565,11 @@ SQLNativeSql(
* Used in conjuction with SQLPutData. * Used in conjuction with SQLPutData.
*/ */
RETCODE SQL_API RETCODE SQL_API
SQLParamData( PGAPI_ParamData(
HSTMT hstmt, HSTMT hstmt,
PTR FAR *prgbValue) PTR FAR *prgbValue)
{ {
static char *func = "SQLParamData"; static char *func = "PGAPI_ParamData";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
int i, int i,
retval; retval;
...@@ -672,12 +674,12 @@ SQLParamData( ...@@ -672,12 +674,12 @@ SQLParamData(
* Used in conjunction with SQLParamData. * Used in conjunction with SQLParamData.
*/ */
RETCODE SQL_API RETCODE SQL_API
SQLPutData( PGAPI_PutData(
HSTMT hstmt, HSTMT hstmt,
PTR rgbValue, PTR rgbValue,
SDWORD cbValue) SDWORD cbValue)
{ {
static char *func = "SQLPutData"; static char *func = "PGAPI_PutData";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
int old_pos, int old_pos,
retval; retval;
...@@ -704,7 +706,7 @@ SQLPutData( ...@@ -704,7 +706,7 @@ SQLPutData(
if (!stmt->put_data) if (!stmt->put_data)
{ /* first call */ { /* first call */
mylog("SQLPutData: (1) cbValue = %d\n", cbValue); mylog("PGAPI_PutData: (1) cbValue = %d\n", cbValue);
stmt->put_data = TRUE; stmt->put_data = TRUE;
...@@ -712,7 +714,7 @@ SQLPutData( ...@@ -712,7 +714,7 @@ SQLPutData(
if (!current_param->EXEC_used) if (!current_param->EXEC_used)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (1)"; stmt->errormsg = "Out of memory in PGAPI_PutData (1)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -790,7 +792,7 @@ SQLPutData( ...@@ -790,7 +792,7 @@ SQLPutData(
if (!current_param->EXEC_buffer) if (!current_param->EXEC_buffer)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (2)"; stmt->errormsg = "Out of memory in PGAPI_PutData (2)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -807,7 +809,7 @@ SQLPutData( ...@@ -807,7 +809,7 @@ SQLPutData(
if (!current_param->EXEC_buffer) if (!current_param->EXEC_buffer)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (2)"; stmt->errormsg = "Out of memory in PGAPI_PutData (2)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -822,7 +824,7 @@ SQLPutData( ...@@ -822,7 +824,7 @@ SQLPutData(
if (!current_param->EXEC_buffer) if (!current_param->EXEC_buffer)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (2)"; stmt->errormsg = "Out of memory in PGAPI_PutData (2)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -834,7 +836,7 @@ SQLPutData( ...@@ -834,7 +836,7 @@ SQLPutData(
else else
{ {
/* calling SQLPutData more than once */ /* calling SQLPutData more than once */
mylog("SQLPutData: (>1) cbValue = %d\n", cbValue); mylog("PGAPI_PutData: (>1) cbValue = %d\n", cbValue);
if (current_param->SQLType == SQL_LONGVARBINARY) if (current_param->SQLType == SQL_LONGVARBINARY)
{ {
...@@ -854,7 +856,7 @@ SQLPutData( ...@@ -854,7 +856,7 @@ SQLPutData(
if (!buffer) if (!buffer)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (3)"; stmt->errormsg = "Out of memory in PGAPI_PutData (3)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
...@@ -880,7 +882,7 @@ SQLPutData( ...@@ -880,7 +882,7 @@ SQLPutData(
if (!buffer) if (!buffer)
{ {
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->errormsg = "Out of memory in SQLPutData (3)"; stmt->errormsg = "Out of memory in PGAPI_PutData (3)";
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
} }
......
This diff is collapsed.
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "connection.h" #include "connection.h"
#include "statement.h" #include "statement.h"
#include "qresult.h" #include "qresult.h"
#include "pgapifunc.h"
extern GLOBAL_VALUES globals; extern GLOBAL_VALUES globals;
...@@ -72,35 +73,24 @@ set_statement_option(ConnectionClass *conn, ...@@ -72,35 +73,24 @@ set_statement_option(ConnectionClass *conn,
* positioned update isn't supported so cursor concurrency is * positioned update isn't supported so cursor concurrency is
* read-only * read-only
*/ */
mylog("SetStmtOption(): SQL_CONCURRENCY = %d\n", vParam);
if (globals.lie || vParam == SQL_CONCUR_READ_ONLY || vParam == SQL_CONCUR_ROWVER)
{
if (conn) if (conn)
conn->stmtOptions.scroll_concurrency = vParam; conn->stmtOptions.scroll_concurrency = vParam;
if (stmt) if (stmt)
stmt->options.scroll_concurrency = vParam; stmt->options.scroll_concurrency = vParam;
}
else
{
if (conn)
conn->stmtOptions.scroll_concurrency = SQL_CONCUR_ROWVER;
if (stmt)
stmt->options.scroll_concurrency = SQL_CONCUR_ROWVER;
changed = TRUE;
}
break; 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: case SQL_CURSOR_TYPE:
/* /*
...@@ -296,19 +286,18 @@ set_statement_option(ConnectionClass *conn, ...@@ -296,19 +286,18 @@ set_statement_option(ConnectionClass *conn,
/* Implements only SQL_AUTOCOMMIT */ /* Implements only SQL_AUTOCOMMIT */
RETCODE SQL_API RETCODE SQL_API
SQLSetConnectOption( PGAPI_SetConnectOption(
HDBC hdbc, HDBC hdbc,
UWORD fOption, UWORD fOption,
UDWORD vParam) UDWORD vParam)
{ {
static char *func = "SQLSetConnectOption"; static char *func = "PGAPI_SetConnectOption";
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
char changed = FALSE; char changed = FALSE;
RETCODE retval; RETCODE retval;
int i; int i;
mylog("%s: entering...\n", func); mylog("%s: entering fOption = %d vParam = %d\n", func, fOption, vParam);
if (!conn) if (!conn)
{ {
CC_log_error(func, "", NULL); CC_log_error(func, "", NULL);
...@@ -372,7 +361,7 @@ SQLSetConnectOption( ...@@ -372,7 +361,7 @@ SQLSetConnectOption(
return SQL_ERROR; return SQL_ERROR;
} }
mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam); mylog("PGAPI_SetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
switch (vParam) switch (vParam)
{ {
...@@ -441,12 +430,12 @@ SQLSetConnectOption( ...@@ -441,12 +430,12 @@ SQLSetConnectOption(
/* This function just can tell you whether you are in Autcommit mode or not */ /* This function just can tell you whether you are in Autcommit mode or not */
RETCODE SQL_API RETCODE SQL_API
SQLGetConnectOption( PGAPI_GetConnectOption(
HDBC hdbc, HDBC hdbc,
UWORD fOption, UWORD fOption,
PTR pvParam) PTR pvParam)
{ {
static char *func = "SQLGetConnectOption"; static char *func = "PGAPI_GetConnectOption";
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -517,12 +506,12 @@ SQLGetConnectOption( ...@@ -517,12 +506,12 @@ SQLGetConnectOption(
RETCODE SQL_API RETCODE SQL_API
SQLSetStmtOption( PGAPI_SetStmtOption(
HSTMT hstmt, HSTMT hstmt,
UWORD fOption, UWORD fOption,
UDWORD vParam) UDWORD vParam)
{ {
static char *func = "SQLSetStmtOption"; static char *func = "PGAPI_SetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
mylog("%s: entering...\n", func); mylog("%s: entering...\n", func);
...@@ -543,12 +532,12 @@ SQLSetStmtOption( ...@@ -543,12 +532,12 @@ SQLSetStmtOption(
RETCODE SQL_API RETCODE SQL_API
SQLGetStmtOption( PGAPI_GetStmtOption(
HSTMT hstmt, HSTMT hstmt,
UWORD fOption, UWORD fOption,
PTR pvParam) PTR pvParam)
{ {
static char *func = "SQLGetStmtOption"; static char *func = "PGAPI_GetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *res; QResultClass *res;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "connection.h" #include "connection.h"
#include "qresult.h" #include "qresult.h"
#include "pgtypes.h" #include "pgtypes.h"
#include "pgapifunc.h"
#ifdef MULTIBYTE #ifdef MULTIBYTE
#include "multibyte.h" #include "multibyte.h"
...@@ -75,7 +76,7 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu ...@@ -75,7 +76,7 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
i++; i++;
} }
if (s[0] == '\0') if (s[i] == '\0')
{ {
token[0] = '\0'; token[0] = '\0';
return NULL; return NULL;
...@@ -92,6 +93,13 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu ...@@ -92,6 +93,13 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
while (!isspace((unsigned char) s[i]) && s[i] != ',' && while (!isspace((unsigned char) s[i]) && s[i] != ',' &&
s[i] != '\0' && out != smax) s[i] != '\0' && out != smax)
{ {
#ifdef MULTIBYTE
if (multibyte_char_check(s[i]) != 0)
{
token[out++] = s[i++];
continue;
}
#endif
/* Handle quoted stuff */ /* Handle quoted stuff */
if (out == 0 && (s[i] == '\"' || s[i] == '\'')) if (out == 0 && (s[i] == '\"' || s[i] == '\''))
{ {
...@@ -110,15 +118,17 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu ...@@ -110,15 +118,17 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
i++; /* dont return the quote */ i++; /* dont return the quote */
while (s[i] != '\0' && out != smax) while (s[i] != '\0' && out != smax)
{ {
if (s[i] == qc && !in_escape)
break;
#ifdef MULTIBYTE #ifdef MULTIBYTE
if (multibyte_char_check(s[i]) == 0 && s[i] == '\\' && !in_escape) if (multibyte_char_check(s[i]) != 0)
{ {
#else token[out++] = s[i++];
continue;
}
#endif
if (s[i] == qc && !in_escape)
break;
if (s[i] == '\\' && !in_escape) if (s[i] == '\\' && !in_escape)
{ {
#endif
in_escape = TRUE; in_escape = TRUE;
} }
else else
...@@ -269,11 +279,12 @@ parse_statement(StatementClass *stmt) ...@@ -269,11 +279,12 @@ parse_statement(StatementClass *stmt)
dquote, dquote,
numeric, numeric,
unquoted; unquoted;
char *ptr; char *ptr, *pptr = NULL;
char in_select = FALSE, char in_select = FALSE,
in_distinct = FALSE, in_distinct = FALSE,
in_on = FALSE, in_on = FALSE,
in_from = FALSE, in_from = FALSE,
from_found = FALSE,
in_where = FALSE, in_where = FALSE,
in_table = FALSE; in_table = FALSE;
char in_field = FALSE, char in_field = FALSE,
...@@ -285,6 +296,7 @@ parse_statement(StatementClass *stmt) ...@@ -285,6 +296,7 @@ parse_statement(StatementClass *stmt)
i, i,
k = 0, k = 0,
n, n,
first_where = 0,
blevel = 0; blevel = 0;
FIELD_INFO **fi; FIELD_INFO **fi;
TABLE_INFO **ti; TABLE_INFO **ti;
...@@ -303,47 +315,53 @@ parse_statement(StatementClass *stmt) ...@@ -303,47 +315,53 @@ parse_statement(StatementClass *stmt)
stmt->nfld = 0; stmt->nfld = 0;
stmt->ntab = 0; stmt->ntab = 0;
while ((ptr = getNextToken(ptr, token, sizeof(token), &delim, &quote, &dquote, &numeric)) != NULL) #ifdef MULTIBYTE
multibyte_init();
#endif
while (pptr = ptr, (ptr = getNextToken(pptr, token, sizeof(token), &delim, &quote, &dquote, &numeric)) != NULL)
{ {
unquoted = !(quote || dquote); 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); 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 (in_select && unquoted && blevel == 0)
{ {
in_select = TRUE; if (!stricmp(token, "distinct"))
mylog("SELECT\n");
continue;
}
if (unquoted && in_select && !stricmp(token, "distinct"))
{ {
in_distinct = TRUE; in_distinct = TRUE;
mylog("DISTINCT\n"); mylog("DISTINCT\n");
continue; continue;
} }
if (!stricmp(token, "into"))
if (unquoted && !stricmp(token, "into"))
{ {
in_select = FALSE; in_select = FALSE;
mylog("INTO\n"); mylog("INTO\n");
continue; stmt->statement_type = STMT_TYPE_CREATE;
stmt->parse_status = STMT_PARSE_FATAL;
return FALSE;
} }
if (!stricmp(token, "from"))
if (unquoted && !stricmp(token, "from"))
{ {
in_select = FALSE; in_select = FALSE;
in_from = TRUE; in_from = TRUE;
if (!from_found &&
(!strnicmp(pptr, "from", 4)))
{
mylog("First ");
from_found = TRUE;
}
mylog("FROM\n"); mylog("FROM\n");
continue; continue;
} }
}
if (unquoted && (!stricmp(token, "where") || if (unquoted && blevel == 0)
{
if ((!stricmp(token, "where") ||
!stricmp(token, "union") || !stricmp(token, "union") ||
!stricmp(token, "intersect") ||
!stricmp(token, "except") ||
!stricmp(token, "order") || !stricmp(token, "order") ||
!stricmp(token, "group") || !stricmp(token, "group") ||
!stricmp(token, "having"))) !stricmp(token, "having")))
...@@ -352,46 +370,22 @@ parse_statement(StatementClass *stmt) ...@@ -352,46 +370,22 @@ parse_statement(StatementClass *stmt)
in_from = FALSE; in_from = FALSE;
in_where = TRUE; in_where = TRUE;
if (!first_where &&
(!stricmp(token, "where")))
first_where = ptr - stmt->statement;
mylog("WHERE...\n"); mylog("WHERE...\n");
break; break;
} }
if (in_select)
{
if (in_distinct)
{
mylog("in distinct\n");
if (unquoted && !stricmp(token, "on"))
{
in_on = TRUE;
mylog("got on\n");
continue;
} }
if (in_on) if (in_select && (in_expr || in_func))
{
in_distinct = FALSE;
in_on = FALSE;
continue; /* just skip the unique on field */
}
mylog("done distinct\n");
in_distinct = FALSE;
}
if (in_expr || in_func)
{ {
/* just eat the expression */ /* just eat the expression */
mylog("in_expr=%d or func=%d\n", in_expr, in_func); mylog("in_expr=%d or func=%d\n", in_expr, in_func);
if (quote || dquote) if (!unquoted)
continue; continue;
if (in_expr && blevel == 0 && delim == ',') if (token[0] == '(')
{
mylog("**** in_expr and Got comma\n");
in_expr = FALSE;
in_field = FALSE;
}
else if (token[0] == '(')
{ {
blevel++; blevel++;
mylog("blevel++ = %d\n", blevel); mylog("blevel++ = %d\n", blevel);
...@@ -405,13 +399,51 @@ parse_statement(StatementClass *stmt) ...@@ -405,13 +399,51 @@ parse_statement(StatementClass *stmt)
{ {
if (delim == ',') if (delim == ',')
{ {
mylog("**** Got comma in_expr/func\n");
in_func = FALSE; in_func = FALSE;
in_expr = FALSE; in_expr = FALSE;
in_field = FALSE; in_field = FALSE;
} }
else if (!stricmp(token, "as"))
{
mylog("got AS in_expr\n");
in_func = FALSE;
in_expr = FALSE;
in_as = TRUE;
in_field = TRUE;
}
}
continue;
}
if (unquoted && !stricmp(token, "select"))
{
in_select = TRUE;
mylog("SELECT\n");
continue;
} }
if (in_select)
{
if (in_distinct)
{
mylog("in distinct\n");
if (unquoted && !stricmp(token, "on"))
{
in_on = TRUE;
mylog("got on\n");
continue; continue;
} }
if (in_on)
{
in_distinct = FALSE;
in_on = FALSE;
continue; /* just skip the unique on field */
}
mylog("done distinct\n");
in_distinct = FALSE;
}
if (!in_field) if (!in_field)
{ {
...@@ -447,6 +479,7 @@ parse_statement(StatementClass *stmt) ...@@ -447,6 +479,7 @@ parse_statement(StatementClass *stmt)
if (quote) if (quote)
{ {
fi[stmt->nfld++]->quote = TRUE; fi[stmt->nfld++]->quote = TRUE;
in_expr = TRUE;
continue; continue;
} }
else if (numeric) else if (numeric)
...@@ -619,8 +652,12 @@ parse_statement(StatementClass *stmt) ...@@ -619,8 +652,12 @@ parse_statement(StatementClass *stmt)
else if (fi[i]->quote) else if (fi[i]->quote)
{ /* handle as text */ { /* handle as text */
fi[i]->ti = NULL; fi[i]->ti = NULL;
/*
fi[i]->type = PG_TYPE_TEXT; fi[i]->type = PG_TYPE_TEXT;
fi[i]->precision = 0; fi[i]->precision = 0;
the following may be better */
fi[i]->type = PG_TYPE_UNKNOWN;
fi[i]->precision = 254;
continue; continue;
} }
/* it's a dot, resolve to table or alias */ /* it's a dot, resolve to table or alias */
...@@ -680,12 +717,12 @@ parse_statement(StatementClass *stmt) ...@@ -680,12 +717,12 @@ parse_statement(StatementClass *stmt)
if (!found) if (!found)
{ {
mylog("PARSE: Getting SQLColumns for table[%d]='%s'\n", i, ti[i]->name); mylog("PARSE: Getting PG_Columns for table[%d]='%s'\n", i, ti[i]->name);
result = SQLAllocStmt(stmt->hdbc, &hcol_stmt); result = PGAPI_AllocStmt(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->errormsg = "PGAPI_AllocStmt failed in parse_statement for columns.";
stmt->errornumber = STMT_NO_MEMORY_ERROR; stmt->errornumber = STMT_NO_MEMORY_ERROR;
stmt->parse_status = STMT_PARSE_FATAL; stmt->parse_status = STMT_PARSE_FATAL;
return FALSE; return FALSE;
...@@ -694,10 +731,10 @@ parse_statement(StatementClass *stmt) ...@@ -694,10 +731,10 @@ parse_statement(StatementClass *stmt)
col_stmt = (StatementClass *) hcol_stmt; col_stmt = (StatementClass *) hcol_stmt;
col_stmt->internal = TRUE; col_stmt->internal = TRUE;
result = SQLColumns(hcol_stmt, "", 0, "", 0, result = PGAPI_Columns(hcol_stmt, "", 0, "", 0,
ti[i]->name, (SWORD) strlen(ti[i]->name), "", 0); ti[i]->name, (SWORD) strlen(ti[i]->name), "", 0);
mylog(" Past SQLColumns\n"); mylog(" Past PG_Columns\n");
if (result == SQL_SUCCESS) if (result == SQL_SUCCESS)
{ {
mylog(" Success\n"); mylog(" Success\n");
...@@ -736,12 +773,12 @@ parse_statement(StatementClass *stmt) ...@@ -736,12 +773,12 @@ parse_statement(StatementClass *stmt)
conn->ntables++; conn->ntables++;
SQLFreeStmt(hcol_stmt, SQL_DROP); PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
mylog("Created col_info table='%s', ntables=%d\n", ti[i]->name, conn->ntables); mylog("Created col_info table='%s', ntables=%d\n", ti[i]->name, conn->ntables);
} }
else else
{ {
SQLFreeStmt(hcol_stmt, SQL_DROP); PGAPI_FreeStmt(hcol_stmt, SQL_DROP);
break; break;
} }
} }
...@@ -751,7 +788,7 @@ parse_statement(StatementClass *stmt) ...@@ -751,7 +788,7 @@ parse_statement(StatementClass *stmt)
mylog("associate col_info: i=%d, k=%d\n", i, k); mylog("associate col_info: i=%d, k=%d\n", i, k);
} }
mylog("Done SQLColumns\n"); mylog("Done PG_Columns\n");
/* /*
* Now resolve the fields to point to column info * Now resolve the fields to point to column info
......
...@@ -329,7 +329,8 @@ pgtype_to_name(StatementClass *stmt, Int4 type) ...@@ -329,7 +329,8 @@ pgtype_to_name(StatementClass *stmt, Int4 type)
{ {
switch (type) switch (type)
{ {
case PG_TYPE_CHAR:return "char"; case PG_TYPE_CHAR:
return "char";
case PG_TYPE_CHAR2: case PG_TYPE_CHAR2:
return "char2"; return "char2";
case PG_TYPE_CHAR4: case PG_TYPE_CHAR4:
...@@ -399,7 +400,7 @@ getNumericScale(StatementClass *stmt, Int4 type, int col) ...@@ -399,7 +400,7 @@ getNumericScale(StatementClass *stmt, Int4 type, int col)
QResultClass *result; QResultClass *result;
ColumnInfoClass *flds; ColumnInfoClass *flds;
mylog("getNumericScale: type=%d, col=%d, unknown = %d\n", type, col); mylog("getNumericScale: type=%d, col=%d\n", type, col);
if (col < 0) if (col < 0)
return PG_NUMERIC_MAX_SCALE; return PG_NUMERIC_MAX_SCALE;
...@@ -436,7 +437,7 @@ getNumericPrecision(StatementClass *stmt, Int4 type, int col) ...@@ -436,7 +437,7 @@ getNumericPrecision(StatementClass *stmt, Int4 type, int col)
QResultClass *result; QResultClass *result;
ColumnInfoClass *flds; ColumnInfoClass *flds;
mylog("getNumericPrecision: type=%d, col=%d, unknown = %d\n", type, col); mylog("getNumericPrecision: type=%d, col=%d\n", type, col);
if (col < 0) if (col < 0)
return PG_NUMERIC_MAX_PRECISION; return PG_NUMERIC_MAX_PRECISION;
...@@ -598,7 +599,8 @@ pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si ...@@ -598,7 +599,8 @@ pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
case PG_TYPE_ABSTIME: case PG_TYPE_ABSTIME:
case PG_TYPE_DATETIME: case PG_TYPE_DATETIME:
case PG_TYPE_TIMESTAMP: case PG_TYPE_TIMESTAMP:
return 19; /*return 19;*/
return 21;
case PG_TYPE_BOOL: case PG_TYPE_BOOL:
return 1; return 1;
......
...@@ -53,6 +53,28 @@ SQLSetPos @68 ...@@ -53,6 +53,28 @@ SQLSetPos @68
SQLSetScrollOptions @69 SQLSetScrollOptions @69
SQLTablePrivileges @70 SQLTablePrivileges @70
SQLBindParameter @72 SQLBindParameter @72
SQLAllocHandle @80
SQLBindParam @81
SQLCloseCursor @82
SQLColAttribute @83
SQLCopyDesc @84
SQLEndTran @85
SQLFetchScroll @86
SQLFreeHandle @87
SQLGetDescField @88
SQLGetDescRec @89
SQLGetDiagField @90
SQLGetDiagRec @91
SQLGetEnvAttr @92
SQLGetConnectAttr @93
SQLGetStmtAttr @94
SQLSetConnectAttr @95
SQLSetDescField @96
SQLSetDescRec @97
SQLSetEnvAttr @98
SQLSetStmtAttr @99
SQLDummyOrdinal @199 SQLDummyOrdinal @199
dconn_FDriverConnectProc @200 dconn_FDriverConnectProc @200
DllMain @201 DllMain @201
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Comments: See "notice.txt" for copyright and license information. * Comments: See "notice.txt" for copyright and license information.
* *
* $Id: psqlodbc.h,v 1.44 2001/06/27 07:38:07 inoue Exp $ * $Id: psqlodbc.h,v 1.45 2001/08/18 04:30:47 inoue Exp $
* *
*/ */
...@@ -163,6 +163,9 @@ typedef struct StatementOptions_ ...@@ -163,6 +163,9 @@ typedef struct StatementOptions_
int bind_size; /* size of each structure if using Row int bind_size; /* size of each structure if using Row
* Binding */ * Binding */
int use_bookmarks; int use_bookmarks;
UInt4 *rowsFetched;
UInt2 *rowStatusArray;
void *bookmark_ptr;
} StatementOptions; } StatementOptions;
/* Used to pass extra query info to send_query */ /* Used to pass extra query info to send_query */
......
...@@ -290,6 +290,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor) ...@@ -290,6 +290,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
QR_set_message(self, "Could not get memory for tuple cache."); QR_set_message(self, "Could not get memory for tuple cache.");
return FALSE; return FALSE;
} }
self->count_allocated = tuple_size;
self->inTuples = TRUE; self->inTuples = TRUE;
...@@ -464,6 +465,7 @@ QR_next_tuple(QResultClass *self) ...@@ -464,6 +465,7 @@ QR_next_tuple(QResultClass *self)
self->fetch_count++; self->fetch_count++;
} }
if (self->cache_size > self->count_allocated)
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, self->num_fields * sizeof(TupleField) * self->cache_size); self->backend_tuples = (TupleField *) realloc(self->backend_tuples, self->num_fields * sizeof(TupleField) * self->cache_size);
if (!self->backend_tuples) if (!self->backend_tuples)
{ {
...@@ -524,19 +526,21 @@ QR_next_tuple(QResultClass *self) ...@@ -524,19 +526,21 @@ QR_next_tuple(QResultClass *self)
case 'B': /* Tuples in binary format */ case 'B': /* Tuples in binary format */
case 'D': /* Tuples in ASCII 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 >= self->count_allocated)
{ {
size_t old_size = self->fcount * self->num_fields * sizeof(TupleField); int tuple_size = self->count_allocated;
mylog("REALLOC: old_size = %d\n", old_size); mylog("REALLOC: old_count = %d, size = %d\n", tuple_size, self->num_fields * sizeof(TupleField) * tuple_size);
tuple_size *= 2;
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, old_size + (self->num_fields * sizeof(TupleField) * TUPLE_MALLOC_INC)); self->backend_tuples = (TupleField *) realloc(self->backend_tuples,
tuple_size * self->num_fields * sizeof(TupleField));
if (!self->backend_tuples) if (!self->backend_tuples)
{ {
self->status = PGRES_FATAL_ERROR; self->status = PGRES_FATAL_ERROR;
QR_set_message(self, "Out of memory while reading tuples."); QR_set_message(self, "Out of memory while reading tuples.");
return FALSE; return FALSE;
} }
self->count_allocated = tuple_size;
} }
if (!QR_read_tuple(self, (char) (id == 0))) if (!QR_read_tuple(self, (char) (id == 0)))
......
...@@ -46,6 +46,7 @@ struct QResultClass_ ...@@ -46,6 +46,7 @@ struct QResultClass_
* (backend) */ * (backend) */
/* Stuff for declare/fetch tuples */ /* Stuff for declare/fetch tuples */
int count_allocated; /* m(re)alloced count */
int fetch_count; /* logical rows read so far */ int fetch_count; /* logical rows read so far */
int fcount; /* actual rows read in the fetch */ int fcount; /* actual rows read in the fetch */
int currTuple; int currTuple;
......
This diff is collapsed.
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <windows.h> #include <windows.h>
#include <sql.h> #include <sql.h>
#endif #endif
#include "pgapifunc.h"
extern GLOBAL_VALUES globals; extern GLOBAL_VALUES globals;
...@@ -91,10 +92,10 @@ static struct ...@@ -91,10 +92,10 @@ static struct
RETCODE SQL_API RETCODE SQL_API
SQLAllocStmt(HDBC hdbc, PGAPI_AllocStmt(HDBC hdbc,
HSTMT FAR *phstmt) HSTMT FAR *phstmt)
{ {
static char *func = "SQLAllocStmt"; static char *func = "PGAPI_AllocStmt";
ConnectionClass *conn = (ConnectionClass *) hdbc; ConnectionClass *conn = (ConnectionClass *) hdbc;
StatementClass *stmt; StatementClass *stmt;
...@@ -108,7 +109,7 @@ SQLAllocStmt(HDBC hdbc, ...@@ -108,7 +109,7 @@ SQLAllocStmt(HDBC hdbc,
stmt = SC_Constructor(); stmt = SC_Constructor();
mylog("**** SQLAllocStmt: hdbc = %u, stmt = %u\n", hdbc, stmt); mylog("**** PGAPI_AllocStmt: hdbc = %u, stmt = %u\n", hdbc, stmt);
if (!stmt) if (!stmt)
{ {
...@@ -143,10 +144,10 @@ SQLAllocStmt(HDBC hdbc, ...@@ -143,10 +144,10 @@ SQLAllocStmt(HDBC hdbc,
RETCODE SQL_API RETCODE SQL_API
SQLFreeStmt(HSTMT hstmt, PGAPI_FreeStmt(HSTMT hstmt,
UWORD fOption) UWORD fOption)
{ {
static char *func = "SQLFreeStmt"; static char *func = "PGAPI_FreeStmt";
StatementClass *stmt = (StatementClass *) hstmt; StatementClass *stmt = (StatementClass *) hstmt;
mylog("%s: entering...hstmt=%u, fOption=%d\n", func, hstmt, fOption); mylog("%s: entering...hstmt=%u, fOption=%d\n", func, hstmt, fOption);
...@@ -205,7 +206,7 @@ SQLFreeStmt(HSTMT hstmt, ...@@ -205,7 +206,7 @@ SQLFreeStmt(HSTMT hstmt,
SC_free_params(stmt, STMT_FREE_PARAMS_ALL); SC_free_params(stmt, STMT_FREE_PARAMS_ALL);
else else
{ {
stmt->errormsg = "Invalid option passed to SQLFreeStmt."; stmt->errormsg = "Invalid option passed to PGAPI_FreeStmt.";
stmt->errornumber = STMT_OPTION_OUT_OF_RANGE_ERROR; stmt->errornumber = STMT_OPTION_OUT_OF_RANGE_ERROR;
SC_log_error(func, "", stmt); SC_log_error(func, "", stmt);
return SQL_ERROR; return SQL_ERROR;
...@@ -570,7 +571,7 @@ SC_pre_execute(StatementClass *self) ...@@ -570,7 +571,7 @@ SC_pre_execute(StatementClass *self)
self->pre_executing = TRUE; self->pre_executing = TRUE;
self->inaccurate_result = FALSE; self->inaccurate_result = FALSE;
SQLExecute(self); PGAPI_Execute(self);
self->pre_executing = old_pre_executing; self->pre_executing = old_pre_executing;
...@@ -713,13 +714,13 @@ SC_fetch(StatementClass *self) ...@@ -713,13 +714,13 @@ SC_fetch(StatementClass *self)
static char *func = "SC_fetch"; static char *func = "SC_fetch";
QResultClass *res = self->result; QResultClass *res = self->result;
int retval, int retval,
result; result, updret;
Int2 num_cols, Int2 num_cols,
lf; lf;
Oid type; Oid type;
char *value; char *value;
ColumnInfoClass *ci; ColumnInfoClass *ci;
extern WORD addrow;
/* TupleField *tupleField; */ /* TupleField *tupleField; */
self->last_fetch_count = 0; self->last_fetch_count = 0;
...@@ -741,7 +742,7 @@ SC_fetch(StatementClass *self) ...@@ -741,7 +742,7 @@ SC_fetch(StatementClass *self)
return SQL_NO_DATA_FOUND; return SQL_NO_DATA_FOUND;
} }
mylog("**** SQLFetch: manual_result\n"); mylog("**** SC_fetch: manual_result\n");
(self->currTuple)++; (self->currTuple)++;
} }
else else
...@@ -750,14 +751,14 @@ SC_fetch(StatementClass *self) ...@@ -750,14 +751,14 @@ SC_fetch(StatementClass *self)
retval = QR_next_tuple(res); retval = QR_next_tuple(res);
if (retval < 0) if (retval < 0)
{ {
mylog("**** SQLFetch: end_tuples\n"); mylog("**** SC_fetch: end_tuples\n");
return SQL_NO_DATA_FOUND; return SQL_NO_DATA_FOUND;
} }
else if (retval > 0) else if (retval > 0)
(self->currTuple)++;/* all is well */ (self->currTuple)++;/* all is well */
else else
{ {
mylog("SQLFetch: error\n"); mylog("SC_fetch: error\n");
self->errornumber = STMT_EXEC_ERROR; self->errornumber = STMT_EXEC_ERROR;
self->errormsg = "Error fetching next row"; self->errormsg = "Error fetching next row";
SC_log_error(func, "", self); SC_log_error(func, "", self);
...@@ -785,6 +786,17 @@ SC_fetch(StatementClass *self) ...@@ -785,6 +786,17 @@ SC_fetch(StatementClass *self)
SQL_C_ULONG, self->bookmark.buffer, 0, self->bookmark.used); SQL_C_ULONG, self->bookmark.buffer, 0, self->bookmark.used);
} }
#ifdef DRIVER_CURSOR_IMPLEMENT
updret = 0;
if (self->options.scroll_concurrency != SQL_CONCUR_READ_ONLY)
{
if (!QR_get_value_backend_row(res, self->currTuple, num_cols - 1))
updret = SQL_ROW_DELETED;
num_cols -= 2;
}
if (!self->options.retrieve_data) /* data isn't required */
return updret ? updret + 10 : SQL_SUCCESS;
#endif /* DRIVER_CURSOR_IMPLEMENT */
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); mylog("fetch: cols=%d, lf=%d, self = %u, self->bindings = %u, buffer[] = %u\n", num_cols, lf, self, self->bindings, self->bindings[lf].buffer);
...@@ -865,6 +877,10 @@ SC_fetch(StatementClass *self) ...@@ -865,6 +877,10 @@ SC_fetch(StatementClass *self)
} }
} }
#ifdef DRIVER_CURSOR_IMPLEMENT
if (updret)
result = updret + 10;
#endif /* DRIVER_CURSOR_IMPLEMENT */
return result; return result;
} }
...@@ -910,7 +926,7 @@ SC_execute(StatementClass *self) ...@@ -910,7 +926,7 @@ SC_execute(StatementClass *self)
ok = QR_command_successful(res); ok = QR_command_successful(res);
mylog("SQLExecute: ok = %d, status = %d\n", ok, QR_get_status(res)); mylog("SC_exec: begin ok = %d, status = %d\n", ok, QR_get_status(res));
QR_Destructor(res); QR_Destructor(res);
...@@ -1066,7 +1082,7 @@ SC_execute(StatementClass *self) ...@@ -1066,7 +1082,7 @@ SC_execute(StatementClass *self)
{ /* get the return value of the procedure call */ { /* get the return value of the procedure call */
RETCODE ret; RETCODE ret;
HSTMT hstmt = (HSTMT) self; HSTMT hstmt = (HSTMT) self;
ret = SQLBindCol(hstmt, 1, self->parameters[0].CType, self->parameters[0].buffer, self->parameters[0].buflen, self->parameters[0].used); ret = PGAPI_BindCol(hstmt, 1, self->parameters[0].CType, self->parameters[0].buffer, self->parameters[0].buflen, self->parameters[0].used);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
SC_fetch(hstmt); SC_fetch(hstmt);
else else
...@@ -1075,7 +1091,7 @@ SC_execute(StatementClass *self) ...@@ -1075,7 +1091,7 @@ SC_execute(StatementClass *self)
self->errormsg = "BindCol to Procedure return failed."; self->errormsg = "BindCol to Procedure return failed.";
} }
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
SQLBindCol(hstmt, 1, self->parameters[0].CType, NULL, 0, NULL); PGAPI_BindCol(hstmt, 1, self->parameters[0].CType, NULL, 0, NULL);
else else
{ {
self->errornumber = STMT_EXEC_ERROR; self->errornumber = STMT_EXEC_ERROR;
......
...@@ -49,6 +49,8 @@ typedef enum ...@@ -49,6 +49,8 @@ typedef enum
STMT_EXECUTING /* statement execution is still going on */ STMT_EXECUTING /* statement execution is still going on */
} STMT_Status; } STMT_Status;
#define STMT_ROW_VERSION_CHANGED (-4)
#define STMT_POS_BEFORE_RECORDSET (-3)
#define STMT_TRUNCATED (-2) #define STMT_TRUNCATED (-2)
#define STMT_INFO_ONLY (-1) /* not an error message, #define STMT_INFO_ONLY (-1) /* not an error message,
* just a notification * just a notification
...@@ -83,6 +85,7 @@ typedef enum ...@@ -83,6 +85,7 @@ typedef enum
#define STMT_OPERATION_INVALID 25 #define STMT_OPERATION_INVALID 25
#define STMT_PROGRAM_TYPE_OUT_OF_RANGE 26 #define STMT_PROGRAM_TYPE_OUT_OF_RANGE 26
#define STMT_BAD_ERROR 27 #define STMT_BAD_ERROR 27
#define STMT_INVALID_OPTION_IDENTIFIER 28
/* statement types */ /* statement types */
enum enum
......
...@@ -83,6 +83,8 @@ CLEAN : ...@@ -83,6 +83,8 @@ CLEAN :
-@erase "$(INTDIR)\statement.obj" -@erase "$(INTDIR)\statement.obj"
-@erase "$(INTDIR)\tuple.obj" -@erase "$(INTDIR)\tuple.obj"
-@erase "$(INTDIR)\tuplelist.obj" -@erase "$(INTDIR)\tuplelist.obj"
-@erase "$(INTDIR)\odbcapi.obj"
-@erase "$(INTDIR)\odbcapi30.obj"
-@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\psqlodbc.dll" -@erase "$(OUTDIR)\psqlodbc.dll"
-@erase "$(OUTDIR)\psqlodbc.exp" -@erase "$(OUTDIR)\psqlodbc.exp"
...@@ -166,6 +168,8 @@ LINK32_OBJS= \ ...@@ -166,6 +168,8 @@ LINK32_OBJS= \
"$(INTDIR)\statement.obj" \ "$(INTDIR)\statement.obj" \
"$(INTDIR)\tuple.obj" \ "$(INTDIR)\tuple.obj" \
"$(INTDIR)\tuplelist.obj" \ "$(INTDIR)\tuplelist.obj" \
"$(INTDIR)\odbcapi.obj" \
"$(INTDIR)\odbcapi30.obj" \
"$(INTDIR)\psqlodbc.res" "$(INTDIR)\psqlodbc.res"
"$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) "$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
...@@ -214,6 +218,8 @@ CLEAN : ...@@ -214,6 +218,8 @@ CLEAN :
-@erase "$(INTDIR)\statement.obj" -@erase "$(INTDIR)\statement.obj"
-@erase "$(INTDIR)\tuple.obj" -@erase "$(INTDIR)\tuple.obj"
-@erase "$(INTDIR)\tuplelist.obj" -@erase "$(INTDIR)\tuplelist.obj"
-@erase "$(INTDIR)\odbcapi.obj"
-@erase "$(INTDIR)\odbcapi30.obj"
-@erase "$(INTDIR)\vc60.idb" -@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb" -@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\psqlodbc.dll" -@erase "$(OUTDIR)\psqlodbc.dll"
...@@ -300,6 +306,8 @@ LINK32_OBJS= \ ...@@ -300,6 +306,8 @@ LINK32_OBJS= \
"$(INTDIR)\statement.obj" \ "$(INTDIR)\statement.obj" \
"$(INTDIR)\tuple.obj" \ "$(INTDIR)\tuple.obj" \
"$(INTDIR)\tuplelist.obj" \ "$(INTDIR)\tuplelist.obj" \
"$(INTDIR)\odbcapi.obj" \
"$(INTDIR)\odbcapi30.obj" \
"$(INTDIR)\psqlodbc.res" "$(INTDIR)\psqlodbc.res"
"$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS) "$(OUTDIR)\psqlodbc.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
...@@ -482,5 +490,17 @@ SOURCE=tuplelist.c ...@@ -482,5 +490,17 @@ SOURCE=tuplelist.c
$(CPP) $(CPP_PROJ) $(SOURCE) $(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=odbcapi.c
"$(INTDIR)\odbcapi.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=odbcapi30.c
"$(INTDIR)\odbcapi30.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF !ENDIF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment