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
@ -1,14 +1,14 @@
|
|||||||
/* Module: bind.c
|
/* Module: bind.c
|
||||||
*
|
*
|
||||||
* Description: This module contains routines related to binding
|
* Description: This module contains routines related to binding
|
||||||
* columns and parameters.
|
* columns and parameters.
|
||||||
*
|
*
|
||||||
* Classes: BindInfoClass, ParameterInfoClass
|
* Classes: BindInfoClass, ParameterInfoClass
|
||||||
*
|
*
|
||||||
* API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
|
* API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
|
||||||
* SQLParamOptions(NI)
|
* SQLParamOptions(NI)
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -33,39 +33,44 @@
|
|||||||
#include "sqlext.h"
|
#include "sqlext.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Bind parameters on a statement handle */
|
/* Bind parameters on a statement handle */
|
||||||
|
|
||||||
RETCODE SQL_API SQLBindParameter(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLBindParameter(
|
||||||
UWORD ipar,
|
HSTMT hstmt,
|
||||||
SWORD fParamType,
|
UWORD ipar,
|
||||||
SWORD fCType,
|
SWORD fParamType,
|
||||||
SWORD fSqlType,
|
SWORD fCType,
|
||||||
UDWORD cbColDef,
|
SWORD fSqlType,
|
||||||
SWORD ibScale,
|
UDWORD cbColDef,
|
||||||
PTR rgbValue,
|
SWORD ibScale,
|
||||||
SDWORD cbValueMax,
|
PTR rgbValue,
|
||||||
SDWORD FAR *pcbValue)
|
SDWORD cbValueMax,
|
||||||
|
SDWORD FAR * pcbValue)
|
||||||
{
|
{
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
static char *func="SQLBindParameter";
|
static char *func = "SQLBindParameter";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stmt->parameters_allocated < ipar) {
|
if (stmt->parameters_allocated < ipar)
|
||||||
|
{
|
||||||
ParameterInfoClass *old_parameters;
|
ParameterInfoClass *old_parameters;
|
||||||
int i, old_parameters_allocated;
|
int i,
|
||||||
|
old_parameters_allocated;
|
||||||
|
|
||||||
old_parameters = stmt->parameters;
|
old_parameters = stmt->parameters;
|
||||||
old_parameters_allocated = stmt->parameters_allocated;
|
old_parameters_allocated = stmt->parameters_allocated;
|
||||||
|
|
||||||
stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass)*(ipar));
|
stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass) * (ipar));
|
||||||
if ( ! stmt->parameters) {
|
if (!stmt->parameters)
|
||||||
|
{
|
||||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||||
stmt->errormsg = "Could not allocate memory for statement parameters";
|
stmt->errormsg = "Could not allocate memory for statement parameters";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -75,18 +80,23 @@ static char *func="SQLBindParameter";
|
|||||||
stmt->parameters_allocated = ipar;
|
stmt->parameters_allocated = ipar;
|
||||||
|
|
||||||
/* copy the old parameters over */
|
/* 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 */
|
/* a structure copy should work */
|
||||||
stmt->parameters[i] = old_parameters[i];
|
stmt->parameters[i] = old_parameters[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get rid of the old parameters, if there were any */
|
/* get rid of the old parameters, if there were any */
|
||||||
if(old_parameters)
|
if (old_parameters)
|
||||||
free(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) */
|
/* 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].buflen = 0;
|
||||||
stmt->parameters[i].buffer = 0;
|
stmt->parameters[i].buffer = 0;
|
||||||
stmt->parameters[i].used = 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 */
|
/* store the given info */
|
||||||
stmt->parameters[ipar].buflen = cbValueMax;
|
stmt->parameters[ipar].buflen = cbValueMax;
|
||||||
@ -114,50 +125,55 @@ static char *func="SQLBindParameter";
|
|||||||
stmt->parameters[ipar].precision = cbColDef;
|
stmt->parameters[ipar].precision = cbColDef;
|
||||||
stmt->parameters[ipar].scale = ibScale;
|
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);
|
free(stmt->parameters[ipar].EXEC_used);
|
||||||
stmt->parameters[ipar].EXEC_used = NULL;
|
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)
|
if (stmt->parameters[ipar].SQLType != SQL_LONGVARBINARY)
|
||||||
free(stmt->parameters[ipar].EXEC_buffer);
|
free(stmt->parameters[ipar].EXEC_buffer);
|
||||||
stmt->parameters[ipar].EXEC_buffer = NULL;
|
stmt->parameters[ipar].EXEC_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data at exec macro only valid for C char/binary data */
|
/* Data at exec macro only valid for C char/binary data */
|
||||||
if ((fSqlType == SQL_LONGVARBINARY || fSqlType == SQL_LONGVARCHAR) && pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
|
if ((fSqlType == SQL_LONGVARBINARY || fSqlType == SQL_LONGVARCHAR) && pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
|
||||||
stmt->parameters[ipar].data_at_exec = TRUE;
|
stmt->parameters[ipar].data_at_exec = TRUE;
|
||||||
else
|
else
|
||||||
stmt->parameters[ipar].data_at_exec = FALSE;
|
stmt->parameters[ipar].data_at_exec = FALSE;
|
||||||
|
|
||||||
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("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);
|
||||||
|
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Associate a user-supplied buffer with a database column. */
|
/* Associate a user-supplied buffer with a database column. */
|
||||||
RETCODE SQL_API SQLBindCol(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLBindCol(
|
||||||
UWORD icol,
|
HSTMT hstmt,
|
||||||
SWORD fCType,
|
UWORD icol,
|
||||||
PTR rgbValue,
|
SWORD fCType,
|
||||||
SDWORD cbValueMax,
|
PTR rgbValue,
|
||||||
SDWORD FAR *pcbValue)
|
SDWORD cbValueMax,
|
||||||
|
SDWORD FAR * pcbValue)
|
||||||
{
|
{
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
static char *func="SQLBindCol";
|
static char *func = "SQLBindCol";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
||||||
|
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
@ -165,23 +181,28 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
|||||||
|
|
||||||
SC_clear_error(stmt);
|
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->errormsg = "Can't bind columns while statement is still executing.";
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the bookmark column is being bound, then just save it */
|
/* 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.buffer = NULL;
|
||||||
stmt->bookmark.used = NULL;
|
stmt->bookmark.used = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
/* Make sure it is the bookmark data type */
|
{
|
||||||
if ( fCType != SQL_C_BOOKMARK) {
|
/* Make sure it is the bookmark data type */
|
||||||
|
if (fCType != SQL_C_BOOKMARK)
|
||||||
|
{
|
||||||
stmt->errormsg = "Column 0 is not of type SQL_C_BOOKMARK";
|
stmt->errormsg = "Column 0 is not of type SQL_C_BOOKMARK";
|
||||||
stmt->errornumber = STMT_PROGRAM_TYPE_OUT_OF_RANGE;
|
stmt->errornumber = STMT_PROGRAM_TYPE_OUT_OF_RANGE;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -194,37 +215,42 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate enough bindings if not already done */
|
/* allocate enough bindings if not already done */
|
||||||
/* Most likely, execution of a statement would have setup the */
|
/* Most likely, execution of a statement would have setup the */
|
||||||
/* necessary bindings. But some apps call BindCol before any */
|
/* necessary bindings. But some apps call BindCol before any */
|
||||||
/* statement is executed. */
|
/* statement is executed. */
|
||||||
if ( icol > stmt->bindings_allocated)
|
if (icol > stmt->bindings_allocated)
|
||||||
extend_bindings(stmt, icol);
|
extend_bindings(stmt, icol);
|
||||||
|
|
||||||
/* check to see if the bindings were allocated */
|
/* check to see if the bindings were allocated */
|
||||||
if ( ! stmt->bindings) {
|
if (!stmt->bindings)
|
||||||
|
{
|
||||||
stmt->errormsg = "Could not allocate memory for bindings.";
|
stmt->errormsg = "Could not allocate memory for bindings.";
|
||||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
icol--; /* use zero based col numbers from here out */
|
icol--; /* use zero based col numbers from here
|
||||||
|
* out */
|
||||||
|
|
||||||
/* Reset for SQLGetData */
|
/* Reset for SQLGetData */
|
||||||
stmt->bindings[icol].data_left = -1;
|
stmt->bindings[icol].data_left = -1;
|
||||||
|
|
||||||
if (rgbValue == NULL) {
|
if (rgbValue == NULL)
|
||||||
|
{
|
||||||
/* we have to unbind the column */
|
/* we have to unbind the column */
|
||||||
stmt->bindings[icol].buflen = 0;
|
stmt->bindings[icol].buflen = 0;
|
||||||
stmt->bindings[icol].buffer = NULL;
|
stmt->bindings[icol].buffer = NULL;
|
||||||
stmt->bindings[icol].used = NULL;
|
stmt->bindings[icol].used = NULL;
|
||||||
stmt->bindings[icol].returntype = SQL_C_CHAR;
|
stmt->bindings[icol].returntype = SQL_C_CHAR;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* ok, bind that column */
|
/* ok, bind that column */
|
||||||
stmt->bindings[icol].buflen = cbValueMax;
|
stmt->bindings[icol].buflen = cbValueMax;
|
||||||
stmt->bindings[icol].buffer = rgbValue;
|
stmt->bindings[icol].buffer = rgbValue;
|
||||||
stmt->bindings[icol].used = pcbValue;
|
stmt->bindings[icol].used = pcbValue;
|
||||||
stmt->bindings[icol].returntype = fCType;
|
stmt->bindings[icol].returntype = fCType;
|
||||||
|
|
||||||
mylog(" bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
|
mylog(" bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
|
||||||
@ -233,34 +259,37 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Returns the description of a parameter marker. */
|
/* Returns the description of a parameter marker. */
|
||||||
/* This function is listed as not being supported by SQLGetFunctions() because it is */
|
/* This function is listed as not being supported by SQLGetFunctions() because it is */
|
||||||
/* used to describe "parameter markers" (not bound parameters), in which case, */
|
/* used to describe "parameter markers" (not bound parameters), in which case, */
|
||||||
/* the dbms should return info on the markers. Since Postgres doesn't support that, */
|
/* the dbms should return info on the markers. Since Postgres doesn't support that, */
|
||||||
/* it is best to say this function is not supported and let the application assume a */
|
/* it is best to say this function is not supported and let the application assume a */
|
||||||
/* data type (most likely varchar). */
|
/* data type (most likely varchar). */
|
||||||
|
|
||||||
RETCODE SQL_API SQLDescribeParam(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLDescribeParam(
|
||||||
UWORD ipar,
|
HSTMT hstmt,
|
||||||
SWORD FAR *pfSqlType,
|
UWORD ipar,
|
||||||
UDWORD FAR *pcbColDef,
|
SWORD FAR * pfSqlType,
|
||||||
SWORD FAR *pibScale,
|
UDWORD FAR * pcbColDef,
|
||||||
SWORD FAR *pfNullable)
|
SWORD FAR * pibScale,
|
||||||
|
SWORD FAR * pfNullable)
|
||||||
{
|
{
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
static char *func = "SQLDescribeParam";
|
static char *func = "SQLDescribeParam";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
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->errormsg = "Invalid parameter number for SQLDescribeParam.";
|
||||||
stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR;
|
stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -269,41 +298,45 @@ static char *func = "SQLDescribeParam";
|
|||||||
|
|
||||||
ipar--;
|
ipar--;
|
||||||
|
|
||||||
/* This implementation is not very good, since it is supposed to describe */
|
/*
|
||||||
/* parameter markers, not bound parameters. */
|
* This implementation is not very good, since it is supposed to
|
||||||
if(pfSqlType)
|
* describe
|
||||||
|
*/
|
||||||
|
/* parameter markers, not bound parameters. */
|
||||||
|
if (pfSqlType)
|
||||||
*pfSqlType = stmt->parameters[ipar].SQLType;
|
*pfSqlType = stmt->parameters[ipar].SQLType;
|
||||||
|
|
||||||
if(pcbColDef)
|
if (pcbColDef)
|
||||||
*pcbColDef = stmt->parameters[ipar].precision;
|
*pcbColDef = stmt->parameters[ipar].precision;
|
||||||
|
|
||||||
if(pibScale)
|
if (pibScale)
|
||||||
*pibScale = stmt->parameters[ipar].scale;
|
*pibScale = stmt->parameters[ipar].scale;
|
||||||
|
|
||||||
if(pfNullable)
|
if (pfNullable)
|
||||||
*pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
|
*pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
|
||||||
|
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Sets multiple values (arrays) for the set of parameter markers. */
|
/* Sets multiple values (arrays) for the set of parameter markers. */
|
||||||
|
|
||||||
RETCODE SQL_API SQLParamOptions(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLParamOptions(
|
||||||
UDWORD crow,
|
HSTMT hstmt,
|
||||||
UDWORD FAR *pirow)
|
UDWORD crow,
|
||||||
|
UDWORD FAR * pirow)
|
||||||
{
|
{
|
||||||
static char *func = "SQLParamOptions";
|
static char *func = "SQLParamOptions";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
|
SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* This function should really talk to the dbms to determine the number of */
|
/* This function should really talk to the dbms to determine the number of */
|
||||||
/* "parameter markers" (not bound parameters) in the statement. But, since */
|
/* "parameter markers" (not bound parameters) in the statement. But, since */
|
||||||
@ -312,43 +345,51 @@ static char *func = "SQLParamOptions";
|
|||||||
/* like it does for SQLDescribeParam is that some applications don't care and try */
|
/* like it does for SQLDescribeParam is that some applications don't care and try */
|
||||||
/* to call it anyway. */
|
/* to call it anyway. */
|
||||||
/* 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 SQLNumParams(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLNumParams(
|
||||||
SWORD FAR *pcpar)
|
HSTMT hstmt,
|
||||||
|
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 = "SQLNumParams";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if(!stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pcpar)
|
if (pcpar)
|
||||||
*pcpar = 0;
|
*pcpar = 0;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
SC_log_error(func, "pcpar was null", stmt);
|
SC_log_error(func, "pcpar was null", stmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 = "SQLNumParams 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;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
for(i=0; i < strlen(stmt->statement); i++) {
|
for (i = 0; i < strlen(stmt->statement); i++)
|
||||||
|
{
|
||||||
|
|
||||||
if(stmt->statement[i] == '?' && !in_quote)
|
if (stmt->statement[i] == '?' && !in_quote)
|
||||||
(*pcpar)++;
|
(*pcpar)++;
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
if (stmt->statement[i] == '\'')
|
if (stmt->statement[i] == '\'')
|
||||||
in_quote = (in_quote ? FALSE : TRUE);
|
in_quote = (in_quote ? FALSE : TRUE);
|
||||||
}
|
}
|
||||||
@ -359,20 +400,20 @@ static char *func = "SQLNumParams";
|
|||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
* Bindings Implementation
|
* Bindings Implementation
|
||||||
*/
|
*/
|
||||||
BindInfoClass *
|
BindInfoClass *
|
||||||
create_empty_bindings(int num_columns)
|
create_empty_bindings(int num_columns)
|
||||||
{
|
{
|
||||||
BindInfoClass *new_bindings;
|
BindInfoClass *new_bindings;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
new_bindings = (BindInfoClass *)malloc(num_columns * sizeof(BindInfoClass));
|
new_bindings = (BindInfoClass *) malloc(num_columns * sizeof(BindInfoClass));
|
||||||
if(!new_bindings) {
|
if (!new_bindings)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i < num_columns; i++) {
|
for (i = 0; i < num_columns; i++)
|
||||||
|
{
|
||||||
new_bindings[i].buflen = 0;
|
new_bindings[i].buflen = 0;
|
||||||
new_bindings[i].buffer = NULL;
|
new_bindings[i].buffer = NULL;
|
||||||
new_bindings[i].used = NULL;
|
new_bindings[i].used = NULL;
|
||||||
@ -383,23 +424,26 @@ int i;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
extend_bindings(StatementClass *stmt, int num_columns)
|
extend_bindings(StatementClass * stmt, int num_columns)
|
||||||
{
|
{
|
||||||
static char *func="extend_bindings";
|
static char *func = "extend_bindings";
|
||||||
BindInfoClass *new_bindings;
|
BindInfoClass *new_bindings;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
|
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
|
||||||
|
|
||||||
/* if we have too few, allocate room for more, and copy the old */
|
/* if we have too few, allocate room for more, and copy the old */
|
||||||
/* entries into the new structure */
|
/* entries into the new structure */
|
||||||
if(stmt->bindings_allocated < num_columns) {
|
if (stmt->bindings_allocated < num_columns)
|
||||||
|
{
|
||||||
|
|
||||||
new_bindings = create_empty_bindings(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);
|
{
|
||||||
|
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);
|
free(stmt->bindings);
|
||||||
stmt->bindings = NULL;
|
stmt->bindings = NULL;
|
||||||
}
|
}
|
||||||
@ -407,8 +451,9 @@ mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stmt->bindings) {
|
if (stmt->bindings)
|
||||||
for(i=0; i<stmt->bindings_allocated; i++)
|
{
|
||||||
|
for (i = 0; i < stmt->bindings_allocated; i++)
|
||||||
new_bindings[i] = stmt->bindings[i];
|
new_bindings[i] = stmt->bindings[i];
|
||||||
|
|
||||||
free(stmt->bindings);
|
free(stmt->bindings);
|
||||||
@ -417,14 +462,14 @@ mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func,
|
|||||||
stmt->bindings = new_bindings;
|
stmt->bindings = new_bindings;
|
||||||
stmt->bindings_allocated = num_columns;
|
stmt->bindings_allocated = num_columns;
|
||||||
|
|
||||||
}
|
}
|
||||||
/* There is no reason to zero out extra bindings if there are */
|
/* There is no reason to zero out extra bindings if there are */
|
||||||
/* more than needed. If an app has allocated extra bindings, */
|
/* more than needed. If an app has allocated extra bindings, */
|
||||||
/* let it worry about it by unbinding those columns. */
|
/* let it worry about it by unbinding those columns. */
|
||||||
|
|
||||||
/* SQLBindCol(1..) ... SQLBindCol(10...) # got 10 bindings */
|
/* SQLBindCol(1..) ... SQLBindCol(10...) # got 10 bindings */
|
||||||
/* SQLExecDirect(...) # returns 5 cols */
|
/* SQLExecDirect(...) # returns 5 cols */
|
||||||
/* SQLExecDirect(...) # returns 10 cols (now OK) */
|
/* SQLExecDirect(...) # returns 10 cols (now OK) */
|
||||||
|
|
||||||
mylog("exit extend_bindings\n");
|
mylog("exit extend_bindings\n");
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: bind.h
|
/* File: bind.h
|
||||||
*
|
*
|
||||||
* Description: See "bind.c"
|
* Description: See "bind.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -15,33 +15,40 @@
|
|||||||
/*
|
/*
|
||||||
* BindInfoClass -- stores information about a bound column
|
* 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 buflen; /* size of buffer */
|
||||||
char *buffer; /* pointer to the buffer */
|
Int4 data_left; /* amount of data left to read
|
||||||
Int4 *used; /* used space in the buffer (for strings not counting the '\0') */
|
* (SQLGetData) */
|
||||||
Int2 returntype; /* kind of conversion to be applied when returning (SQL_C_DEFAULT, SQL_C_CHAR...) */
|
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...) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ParameterInfoClass -- stores information about a bound parameter
|
* ParameterInfoClass -- stores information about a bound parameter
|
||||||
*/
|
*/
|
||||||
struct ParameterInfoClass_ {
|
struct ParameterInfoClass_
|
||||||
Int4 buflen;
|
{
|
||||||
char *buffer;
|
Int4 buflen;
|
||||||
Int4 *used;
|
char *buffer;
|
||||||
Int2 paramType;
|
Int4 *used;
|
||||||
Int2 CType;
|
Int2 paramType;
|
||||||
Int2 SQLType;
|
Int2 CType;
|
||||||
UInt4 precision;
|
Int2 SQLType;
|
||||||
Int2 scale;
|
UInt4 precision;
|
||||||
Oid lobj_oid;
|
Int2 scale;
|
||||||
Int4 *EXEC_used; /* amount of data OR the oid of the large object */
|
Oid lobj_oid;
|
||||||
char *EXEC_buffer; /* the data or the FD of the large object */
|
Int4 *EXEC_used; /* amount of data OR the oid of the large
|
||||||
char data_at_exec;
|
* object */
|
||||||
|
char *EXEC_buffer; /* the data or the FD of the large object */
|
||||||
|
char data_at_exec;
|
||||||
};
|
};
|
||||||
|
|
||||||
BindInfoClass *create_empty_bindings(int num_columns);
|
BindInfoClass *create_empty_bindings(int num_columns);
|
||||||
void extend_bindings(StatementClass *stmt, int num_columns);
|
void extend_bindings(StatementClass * stmt, int num_columns);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* Module: columninfo.c
|
/* Module: columninfo.c
|
||||||
*
|
*
|
||||||
* Description: This module contains routines related to
|
* Description: This module contains routines related to
|
||||||
* reading and storing the field information from a query.
|
* reading and storing the field information from a query.
|
||||||
*
|
*
|
||||||
* Classes: ColumnInfoClass (Functions prefix: "CI_")
|
* Classes: ColumnInfoClass (Functions prefix: "CI_")
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -20,11 +20,12 @@
|
|||||||
ColumnInfoClass *
|
ColumnInfoClass *
|
||||||
CI_Constructor()
|
CI_Constructor()
|
||||||
{
|
{
|
||||||
ColumnInfoClass *rv;
|
ColumnInfoClass *rv;
|
||||||
|
|
||||||
rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
|
rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
|
||||||
|
|
||||||
if (rv) {
|
if (rv)
|
||||||
|
{
|
||||||
rv->num_fields = 0;
|
rv->num_fields = 0;
|
||||||
rv->name = NULL;
|
rv->name = NULL;
|
||||||
rv->adtid = NULL;
|
rv->adtid = NULL;
|
||||||
@ -37,28 +38,28 @@ ColumnInfoClass *rv;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CI_Destructor(ColumnInfoClass *self)
|
CI_Destructor(ColumnInfoClass * self)
|
||||||
{
|
{
|
||||||
CI_free_memory(self);
|
CI_free_memory(self);
|
||||||
|
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read in field descriptions.
|
/* Read in field descriptions.
|
||||||
If self is not null, then also store the information.
|
If self is not null, then also store the information.
|
||||||
If self is null, then just read, don't store.
|
If self is null, then just read, don't store.
|
||||||
*/
|
*/
|
||||||
char
|
char
|
||||||
CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
|
CI_read_fields(ColumnInfoClass * self, ConnectionClass * conn)
|
||||||
{
|
{
|
||||||
Int2 lf;
|
Int2 lf;
|
||||||
int new_num_fields;
|
int new_num_fields;
|
||||||
Oid new_adtid;
|
Oid new_adtid;
|
||||||
Int2 new_adtsize;
|
Int2 new_adtsize;
|
||||||
Int4 new_atttypmod = -1;
|
Int4 new_atttypmod = -1;
|
||||||
char new_field_name[MAX_MESSAGE_LEN+1];
|
char new_field_name[MAX_MESSAGE_LEN + 1];
|
||||||
SocketClass *sock;
|
SocketClass *sock;
|
||||||
ConnInfo *ci;
|
ConnInfo *ci;
|
||||||
|
|
||||||
sock = CC_get_socket(conn);
|
sock = CC_get_socket(conn);
|
||||||
ci = &conn->connInfo;
|
ci = &conn->connInfo;
|
||||||
@ -68,24 +69,27 @@ ConnInfo *ci;
|
|||||||
|
|
||||||
mylog("num_fields = %d\n", new_num_fields);
|
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);
|
CI_set_num_fields(self, new_num_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now read in the descriptions */
|
/* 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);
|
SOCK_get_string(sock, new_field_name, MAX_MESSAGE_LEN);
|
||||||
new_adtid = (Oid) SOCK_get_int(sock, 4);
|
new_adtid = (Oid) SOCK_get_int(sock, 4);
|
||||||
new_adtsize = (Int2) SOCK_get_int(sock, 2);
|
new_adtsize = (Int2) SOCK_get_int(sock, 2);
|
||||||
|
|
||||||
/* If 6.4 protocol, then read the atttypmod field */
|
/* 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");
|
mylog("READING ATTTYPMOD\n");
|
||||||
new_atttypmod = (Int4) SOCK_get_int(sock, 4);
|
new_atttypmod = (Int4) SOCK_get_int(sock, 4);
|
||||||
|
|
||||||
/* Subtract the header length */
|
/* Subtract the header length */
|
||||||
new_atttypmod -= 4;
|
new_atttypmod -= 4;
|
||||||
if (new_atttypmod < 0)
|
if (new_atttypmod < 0)
|
||||||
new_atttypmod = -1;
|
new_atttypmod = -1;
|
||||||
@ -104,17 +108,18 @@ ConnInfo *ci;
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CI_free_memory(ColumnInfoClass *self)
|
CI_free_memory(ColumnInfoClass * self)
|
||||||
{
|
{
|
||||||
register Int2 lf;
|
register Int2 lf;
|
||||||
int num_fields = self->num_fields;
|
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]);
|
if (self->name[lf])
|
||||||
|
free(self->name[lf]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Safe to call even if null */
|
/* Safe to call even if null */
|
||||||
free(self->name);
|
free(self->name);
|
||||||
free(self->adtid);
|
free(self->adtid);
|
||||||
free(self->adtsize);
|
free(self->adtsize);
|
||||||
@ -124,28 +129,27 @@ int num_fields = self->num_fields;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
|
CI_set_num_fields(ColumnInfoClass * self, int new_num_fields)
|
||||||
{
|
{
|
||||||
CI_free_memory(self); /* always safe to call */
|
CI_free_memory(self); /* always safe to call */
|
||||||
|
|
||||||
self->num_fields = new_num_fields;
|
self->num_fields = new_num_fields;
|
||||||
|
|
||||||
self->name = (char **) malloc (sizeof(char *) * self->num_fields);
|
self->name = (char **) malloc(sizeof(char *) * self->num_fields);
|
||||||
self->adtid = (Oid *) malloc (sizeof(Oid) * self->num_fields);
|
self->adtid = (Oid *) malloc(sizeof(Oid) * self->num_fields);
|
||||||
self->adtsize = (Int2 *) malloc (sizeof(Int2) * self->num_fields);
|
self->adtsize = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
|
||||||
self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
|
self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
|
||||||
self->atttypmod = (Int4 *) malloc(sizeof(Int4) * self->num_fields);
|
self->atttypmod = (Int4 *) malloc(sizeof(Int4) * self->num_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
|
CI_set_field_info(ColumnInfoClass * self, int field_num, char *new_name,
|
||||||
Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
|
Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* check bounds */
|
/* check bounds */
|
||||||
if((field_num < 0) || (field_num >= self->num_fields)) {
|
if ((field_num < 0) || (field_num >= self->num_fields))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* store the info */
|
/* store the info */
|
||||||
self->name[field_num] = strdup(new_name);
|
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;
|
self->display_size[field_num] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: columninfo.h
|
/* File: columninfo.h
|
||||||
*
|
*
|
||||||
* Description: See "columninfo.c"
|
* Description: See "columninfo.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -12,13 +12,14 @@
|
|||||||
|
|
||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
|
|
||||||
struct ColumnInfoClass_ {
|
struct ColumnInfoClass_
|
||||||
Int2 num_fields;
|
{
|
||||||
char **name; /* list of type names */
|
Int2 num_fields;
|
||||||
Oid *adtid; /* list of type ids */
|
char **name; /* list of type names */
|
||||||
Int2 *adtsize; /* list type sizes */
|
Oid *adtid; /* list of type ids */
|
||||||
Int2 *display_size; /* the display size (longest row) */
|
Int2 *adtsize; /* list type sizes */
|
||||||
Int4 *atttypmod; /* the length of bpchar/varchar */
|
Int2 *display_size; /* the display size (longest row) */
|
||||||
|
Int4 *atttypmod; /* the length of bpchar/varchar */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CI_get_num_fields(self) (self->num_fields)
|
#define CI_get_num_fields(self) (self->num_fields)
|
||||||
@ -29,15 +30,15 @@ struct ColumnInfoClass_ {
|
|||||||
#define CI_get_atttypmod(self, col) (self->atttypmod[col])
|
#define CI_get_atttypmod(self, col) (self->atttypmod[col])
|
||||||
|
|
||||||
ColumnInfoClass *CI_Constructor(void);
|
ColumnInfoClass *CI_Constructor(void);
|
||||||
void CI_Destructor(ColumnInfoClass *self);
|
void CI_Destructor(ColumnInfoClass * self);
|
||||||
void CI_free_memory(ColumnInfoClass *self);
|
void CI_free_memory(ColumnInfoClass * self);
|
||||||
char CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn);
|
char CI_read_fields(ColumnInfoClass * self, ConnectionClass * conn);
|
||||||
|
|
||||||
/* functions for setting up the fields from within the program, */
|
/* functions for setting up the fields from within the program, */
|
||||||
/* without reading from a socket */
|
/* without reading from a socket */
|
||||||
void CI_set_num_fields(ColumnInfoClass *self, int new_num_fields);
|
void CI_set_num_fields(ColumnInfoClass * self, int new_num_fields);
|
||||||
void CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
|
void CI_set_field_info(ColumnInfoClass * self, int field_num, char *new_name,
|
||||||
Oid new_adtid, Int2 new_adtsize, Int4 atttypmod);
|
Oid new_adtid, Int2 new_adtsize, Int4 atttypmod);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: connection.h
|
/* File: connection.h
|
||||||
*
|
*
|
||||||
* Description: See "connection.c"
|
* Description: See "connection.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -27,12 +27,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
CONN_NOT_CONNECTED, /* Connection has not been established */
|
{
|
||||||
CONN_CONNECTED, /* Connection is up and has been established */
|
CONN_NOT_CONNECTED, /* Connection has not been established */
|
||||||
CONN_DOWN, /* Connection is broken */
|
CONN_CONNECTED, /* Connection is up and has been
|
||||||
CONN_EXECUTING /* the connection is currently executing a statement */
|
* established */
|
||||||
} CONN_Status;
|
CONN_DOWN, /* Connection is broken */
|
||||||
|
CONN_EXECUTING /* the connection is currently executing a
|
||||||
|
* statement */
|
||||||
|
} CONN_Status;
|
||||||
|
|
||||||
/* These errors have general sql error state */
|
/* These errors have general sql error state */
|
||||||
#define CONNECTION_SERVER_NOT_REACHED 101
|
#define CONNECTION_SERVER_NOT_REACHED 101
|
||||||
@ -110,38 +113,39 @@ typedef unsigned int ProtocolVersion;
|
|||||||
/* This startup packet is to support latest Postgres protocol */
|
/* This startup packet is to support latest Postgres protocol */
|
||||||
typedef struct _StartupPacket
|
typedef struct _StartupPacket
|
||||||
{
|
{
|
||||||
ProtocolVersion protoVersion;
|
ProtocolVersion protoVersion;
|
||||||
char database[SM_DATABASE];
|
char database[SM_DATABASE];
|
||||||
char user[SM_USER];
|
char user[SM_USER];
|
||||||
char options[SM_OPTIONS];
|
char options[SM_OPTIONS];
|
||||||
char unused[SM_UNUSED];
|
char unused[SM_UNUSED];
|
||||||
char tty[SM_TTY];
|
char tty[SM_TTY];
|
||||||
} StartupPacket;
|
} StartupPacket;
|
||||||
|
|
||||||
|
|
||||||
/* Structure to hold all the connection attributes for a specific
|
/* Structure to hold all the connection attributes for a specific
|
||||||
connection (used for both registry and file, DSN and DRIVER)
|
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 dsn[MEDIUM_REGISTRY_LEN];
|
||||||
char driver[MEDIUM_REGISTRY_LEN];
|
char desc[MEDIUM_REGISTRY_LEN];
|
||||||
char server[MEDIUM_REGISTRY_LEN];
|
char driver[MEDIUM_REGISTRY_LEN];
|
||||||
char database[MEDIUM_REGISTRY_LEN];
|
char server[MEDIUM_REGISTRY_LEN];
|
||||||
char username[MEDIUM_REGISTRY_LEN];
|
char database[MEDIUM_REGISTRY_LEN];
|
||||||
char password[MEDIUM_REGISTRY_LEN];
|
char username[MEDIUM_REGISTRY_LEN];
|
||||||
char conn_settings[LARGE_REGISTRY_LEN];
|
char password[MEDIUM_REGISTRY_LEN];
|
||||||
char protocol[SMALL_REGISTRY_LEN];
|
char conn_settings[LARGE_REGISTRY_LEN];
|
||||||
char port[SMALL_REGISTRY_LEN];
|
char protocol[SMALL_REGISTRY_LEN];
|
||||||
char onlyread[SMALL_REGISTRY_LEN];
|
char port[SMALL_REGISTRY_LEN];
|
||||||
char fake_oid_index[SMALL_REGISTRY_LEN];
|
char onlyread[SMALL_REGISTRY_LEN];
|
||||||
char show_oid_column[SMALL_REGISTRY_LEN];
|
char fake_oid_index[SMALL_REGISTRY_LEN];
|
||||||
char row_versioning[SMALL_REGISTRY_LEN];
|
char show_oid_column[SMALL_REGISTRY_LEN];
|
||||||
char show_system_tables[SMALL_REGISTRY_LEN];
|
char row_versioning[SMALL_REGISTRY_LEN];
|
||||||
char translation_dll[MEDIUM_REGISTRY_LEN];
|
char show_system_tables[SMALL_REGISTRY_LEN];
|
||||||
char translation_option[SMALL_REGISTRY_LEN];
|
char translation_dll[MEDIUM_REGISTRY_LEN];
|
||||||
char focus_password;
|
char translation_option[SMALL_REGISTRY_LEN];
|
||||||
} ConnInfo;
|
char focus_password;
|
||||||
|
} ConnInfo;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macros to compare the server's version with a specified version
|
* Macros to compare the server's version with a specified version
|
||||||
@ -160,15 +164,15 @@ typedef struct {
|
|||||||
#define SERVER_VERSION_LE(conn, major, minor) (! SERVER_VERSION_GT(conn, major, minor))
|
#define SERVER_VERSION_LE(conn, major, minor) (! SERVER_VERSION_GT(conn, major, minor))
|
||||||
#define SERVER_VERSION_LT(conn, major, minor) (! SERVER_VERSION_GE(conn, major, minor))
|
#define SERVER_VERSION_LT(conn, major, minor) (! SERVER_VERSION_GE(conn, major, minor))
|
||||||
/*#if ! defined(HAVE_CONFIG_H) || defined(HAVE_STRINGIZE)*/
|
/*#if ! defined(HAVE_CONFIG_H) || defined(HAVE_STRINGIZE)*/
|
||||||
#define STRING_AFTER_DOT(string) (strchr(#string, '.') + 1)
|
#define STRING_AFTER_DOT(string) (strchr(#string, '.') + 1)
|
||||||
/*#else
|
/*#else
|
||||||
#define STRING_AFTER_DOT(str) (strchr("str", '.') + 1)
|
#define STRING_AFTER_DOT(str) (strchr("str", '.') + 1)
|
||||||
#endif*/
|
#endif*/
|
||||||
/*
|
/*
|
||||||
* Simplified macros to compare the server's version with a
|
* Simplified macros to compare the server's version with a
|
||||||
* specified version
|
* specified version
|
||||||
* Note: Never pass a variable as the second parameter.
|
* Note: Never pass a variable as the second parameter.
|
||||||
* It must be a decimal constant of the form %d.%d .
|
* It must be a decimal constant of the form %d.%d .
|
||||||
*/
|
*/
|
||||||
#define PG_VERSION_GT(conn, ver) \
|
#define PG_VERSION_GT(conn, ver) \
|
||||||
(SERVER_VERSION_GT(conn, (int) ver, atoi(STRING_AFTER_DOT(ver))))
|
(SERVER_VERSION_GT(conn, (int) ver, atoi(STRING_AFTER_DOT(ver))))
|
||||||
@ -180,9 +184,10 @@ typedef struct {
|
|||||||
#define PG_VERSION_LT(conn, ver) (! PG_VERSION_GE(conn, ver))
|
#define PG_VERSION_LT(conn, ver) (! PG_VERSION_GE(conn, ver))
|
||||||
|
|
||||||
/* This is used to store cached table information in the connection */
|
/* 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];
|
QResultClass *result;
|
||||||
|
char name[MAX_TABLE_LEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Translation DLL entry points */
|
/* Translation DLL entry points */
|
||||||
@ -194,52 +199,58 @@ struct col_info {
|
|||||||
#define HINSTANCE void *
|
#define HINSTANCE void *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef BOOL (FAR WINAPI *DataSourceToDriverProc) (UDWORD,
|
typedef BOOL(FAR WINAPI * DataSourceToDriverProc) (UDWORD,
|
||||||
SWORD,
|
SWORD,
|
||||||
PTR,
|
PTR,
|
||||||
SDWORD,
|
SDWORD,
|
||||||
PTR,
|
PTR,
|
||||||
SDWORD,
|
SDWORD,
|
||||||
SDWORD FAR *,
|
SDWORD FAR *,
|
||||||
UCHAR FAR *,
|
UCHAR FAR *,
|
||||||
SWORD,
|
SWORD,
|
||||||
SWORD FAR *);
|
SWORD FAR *);
|
||||||
|
|
||||||
typedef BOOL (FAR WINAPI *DriverToDataSourceProc) (UDWORD,
|
typedef BOOL(FAR WINAPI * DriverToDataSourceProc) (UDWORD,
|
||||||
SWORD,
|
SWORD,
|
||||||
PTR,
|
PTR,
|
||||||
SDWORD,
|
SDWORD,
|
||||||
PTR,
|
PTR,
|
||||||
SDWORD,
|
SDWORD,
|
||||||
SDWORD FAR *,
|
SDWORD FAR *,
|
||||||
UCHAR FAR *,
|
UCHAR FAR *,
|
||||||
SWORD,
|
SWORD,
|
||||||
SWORD FAR *);
|
SWORD FAR *);
|
||||||
|
|
||||||
/******* The Connection handle ************/
|
/******* The Connection handle ************/
|
||||||
struct ConnectionClass_ {
|
struct ConnectionClass_
|
||||||
HENV henv; /* environment this connection was created on */
|
{
|
||||||
|
HENV henv; /* environment this connection was created
|
||||||
|
* on */
|
||||||
StatementOptions stmtOptions;
|
StatementOptions stmtOptions;
|
||||||
char *errormsg;
|
char *errormsg;
|
||||||
int errornumber;
|
int errornumber;
|
||||||
CONN_Status status;
|
CONN_Status status;
|
||||||
ConnInfo connInfo;
|
ConnInfo connInfo;
|
||||||
StatementClass **stmts;
|
StatementClass **stmts;
|
||||||
int num_stmts;
|
int num_stmts;
|
||||||
SocketClass *sock;
|
SocketClass *sock;
|
||||||
int lobj_type;
|
int lobj_type;
|
||||||
int ntables;
|
int ntables;
|
||||||
COL_INFO **col_info;
|
COL_INFO **col_info;
|
||||||
long translation_option;
|
long translation_option;
|
||||||
HINSTANCE translation_handle;
|
HINSTANCE translation_handle;
|
||||||
DataSourceToDriverProc DataSourceToDriver;
|
DataSourceToDriverProc DataSourceToDriver;
|
||||||
DriverToDataSourceProc DriverToDataSource;
|
DriverToDataSourceProc DriverToDataSource;
|
||||||
char transact_status; /* Is a transaction is currently in progress */
|
char transact_status;/* Is a transaction is currently in
|
||||||
char errormsg_created; /* has an informative error msg been created? */
|
* progress */
|
||||||
char pg_version[MAX_INFO_STRING]; /* Version of PostgreSQL we're connected to - DJP 25-1-2001 */
|
char errormsg_created; /* has an informative error msg
|
||||||
float pg_version_number;
|
* been created? */
|
||||||
Int2 pg_version_major;
|
char pg_version[MAX_INFO_STRING]; /* Version of PostgreSQL
|
||||||
Int2 pg_version_minor;
|
* we're connected to -
|
||||||
|
* DJP 25-1-2001 */
|
||||||
|
float pg_version_number;
|
||||||
|
Int2 pg_version_major;
|
||||||
|
Int2 pg_version_minor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -252,31 +263,31 @@ struct ConnectionClass_ {
|
|||||||
#define CC_is_onlyread(x) (x->connInfo.onlyread[0] == '1')
|
#define CC_is_onlyread(x) (x->connInfo.onlyread[0] == '1')
|
||||||
|
|
||||||
|
|
||||||
/* for CC_DSN_info */
|
/* for CC_DSN_info */
|
||||||
#define CONN_DONT_OVERWRITE 0
|
#define CONN_DONT_OVERWRITE 0
|
||||||
#define CONN_OVERWRITE 1
|
#define CONN_OVERWRITE 1
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
ConnectionClass *CC_Constructor(void);
|
ConnectionClass *CC_Constructor(void);
|
||||||
char CC_Destructor(ConnectionClass *self);
|
char CC_Destructor(ConnectionClass * self);
|
||||||
int CC_cursor_count(ConnectionClass *self);
|
int CC_cursor_count(ConnectionClass * self);
|
||||||
char CC_cleanup(ConnectionClass *self);
|
char CC_cleanup(ConnectionClass * self);
|
||||||
char CC_abort(ConnectionClass *self);
|
char CC_abort(ConnectionClass * self);
|
||||||
int CC_set_translation (ConnectionClass *self);
|
int CC_set_translation(ConnectionClass * self);
|
||||||
char CC_connect(ConnectionClass *self, char do_password);
|
char CC_connect(ConnectionClass * self, char do_password);
|
||||||
char CC_add_statement(ConnectionClass *self, StatementClass *stmt);
|
char CC_add_statement(ConnectionClass * self, StatementClass * stmt);
|
||||||
char CC_remove_statement(ConnectionClass *self, StatementClass *stmt);
|
char CC_remove_statement(ConnectionClass * self, StatementClass * stmt);
|
||||||
char CC_get_error(ConnectionClass *self, int *number, char **message);
|
char CC_get_error(ConnectionClass * self, int *number, char **message);
|
||||||
QResultClass *CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi);
|
QResultClass *CC_send_query(ConnectionClass * self, char *query, QueryInfo * qi);
|
||||||
void CC_clear_error(ConnectionClass *self);
|
void CC_clear_error(ConnectionClass * self);
|
||||||
char *CC_create_errormsg(ConnectionClass *self);
|
char *CC_create_errormsg(ConnectionClass * self);
|
||||||
int CC_send_function(ConnectionClass *conn, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
|
int CC_send_function(ConnectionClass * conn, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG * argv, int nargs);
|
||||||
char CC_send_settings(ConnectionClass *self);
|
char CC_send_settings(ConnectionClass * self);
|
||||||
void CC_lookup_lo(ConnectionClass *conn);
|
void CC_lookup_lo(ConnectionClass * conn);
|
||||||
void CC_lookup_pg_version(ConnectionClass *conn);
|
void CC_lookup_pg_version(ConnectionClass * conn);
|
||||||
void CC_initialize_pg_version(ConnectionClass *conn);
|
void CC_initialize_pg_version(ConnectionClass * conn);
|
||||||
void CC_log_error(char *func, char *desc, ConnectionClass *self);
|
void CC_log_error(char *func, char *desc, ConnectionClass * self);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: convert.h
|
/* File: convert.h
|
||||||
*
|
*
|
||||||
* Description: See "convert.c"
|
* Description: See "convert.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,39 +13,40 @@
|
|||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
|
|
||||||
/* copy_and_convert results */
|
/* copy_and_convert results */
|
||||||
#define COPY_OK 0
|
#define COPY_OK 0
|
||||||
#define COPY_UNSUPPORTED_TYPE 1
|
#define COPY_UNSUPPORTED_TYPE 1
|
||||||
#define COPY_UNSUPPORTED_CONVERSION 2
|
#define COPY_UNSUPPORTED_CONVERSION 2
|
||||||
#define COPY_RESULT_TRUNCATED 3
|
#define COPY_RESULT_TRUNCATED 3
|
||||||
#define COPY_GENERAL_ERROR 4
|
#define COPY_GENERAL_ERROR 4
|
||||||
#define COPY_NO_DATA_FOUND 5
|
#define COPY_NO_DATA_FOUND 5
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
int m;
|
{
|
||||||
int d;
|
int m;
|
||||||
int y;
|
int d;
|
||||||
int hh;
|
int y;
|
||||||
int mm;
|
int hh;
|
||||||
int ss;
|
int mm;
|
||||||
} SIMPLE_TIME;
|
int ss;
|
||||||
|
} SIMPLE_TIME;
|
||||||
|
|
||||||
int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
|
int copy_and_convert_field_bindinfo(StatementClass * stmt, Int4 field_type, void *value, int col);
|
||||||
int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
|
int copy_and_convert_field(StatementClass * stmt, Int4 field_type, void *value, Int2 fCType,
|
||||||
PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue);
|
PTR rgbValue, SDWORD cbValueMax, SDWORD * pcbValue);
|
||||||
|
|
||||||
int copy_statement_with_parameters(StatementClass *stmt);
|
int copy_statement_with_parameters(StatementClass * stmt);
|
||||||
char *convert_escape(char *value);
|
char *convert_escape(char *value);
|
||||||
char *convert_money(char *s);
|
char *convert_money(char *s);
|
||||||
char parse_datetime(char *buf, SIMPLE_TIME *st);
|
char parse_datetime(char *buf, SIMPLE_TIME * st);
|
||||||
int convert_linefeeds(char *s, char *dst, size_t max);
|
int convert_linefeeds(char *s, char *dst, size_t max);
|
||||||
char *convert_special_chars(char *si, char *dst, int used);
|
char *convert_special_chars(char *si, char *dst, int used);
|
||||||
|
|
||||||
int convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax);
|
int convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax);
|
||||||
int convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax);
|
int convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax);
|
||||||
int convert_to_pgbinary(unsigned char *in, char *out, int len);
|
int convert_to_pgbinary(unsigned char *in, char *out, int len);
|
||||||
void encode(char *in, char *out);
|
void encode(char *in, char *out);
|
||||||
void decode(char *in, char *out);
|
void decode(char *in, char *out);
|
||||||
int convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
|
int convert_lo(StatementClass * stmt, void *value, Int2 fCType, PTR rgbValue,
|
||||||
SDWORD cbValueMax, SDWORD *pcbValue);
|
SDWORD cbValueMax, SDWORD * pcbValue);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: dlg_specific.h
|
/* File: dlg_specific.h
|
||||||
*
|
*
|
||||||
* Description: See "dlg_specific.c"
|
* Description: See "dlg_specific.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -31,41 +31,49 @@
|
|||||||
|
|
||||||
/* INI File Stuff */
|
/* INI File Stuff */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
# define ODBC_INI ".odbc.ini"
|
#define ODBC_INI ".odbc.ini"
|
||||||
# ifdef ODBCINSTDIR
|
#ifdef ODBCINSTDIR
|
||||||
# define ODBCINST_INI ODBCINSTDIR "/odbcinst.ini"
|
#define ODBCINST_INI ODBCINSTDIR "/odbcinst.ini"
|
||||||
# else
|
#else
|
||||||
# define ODBCINST_INI "/etc/odbcinst.ini"
|
#define ODBCINST_INI "/etc/odbcinst.ini"
|
||||||
# warning "location of odbcinst.ini file defaulted to /etc"
|
#warning "location of odbcinst.ini file defaulted to /etc"
|
||||||
# endif
|
#endif
|
||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
# define ODBC_INI "ODBC.INI" /* ODBC initialization file */
|
#define ODBC_INI "ODBC.INI" /* ODBC initialization file */
|
||||||
# define ODBCINST_INI "ODBCINST.INI" /* ODBC Installation file */
|
#define ODBCINST_INI "ODBCINST.INI" /* ODBC Installation file */
|
||||||
#endif /* WIN32 */
|
#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
|
||||||
#define INI_KDESC "Description" /* Data source description */
|
* ini file (not used?) */
|
||||||
#define INI_SERVER "Servername" /* Name of Server running the Postgres service */
|
#define INI_KDESC "Description" /* Data source description */
|
||||||
#define INI_PORT "Port" /* Port on which the Postmaster is listening */
|
#define INI_SERVER "Servername" /* Name of Server running the
|
||||||
#define INI_DATABASE "Database" /* Database Name */
|
* Postgres service */
|
||||||
#define INI_USER "Username" /* Default User Name */
|
#define INI_PORT "Port"/* Port on which the Postmaster is
|
||||||
#define INI_PASSWORD "Password" /* Default Password */
|
* listening */
|
||||||
#define INI_DEBUG "Debug" /* Debug flag */
|
#define INI_DATABASE "Database" /* Database Name */
|
||||||
#define INI_FETCH "Fetch" /* Fetch Max Count */
|
#define INI_USER "Username" /* Default User Name */
|
||||||
#define INI_SOCKET "Socket" /* Socket buffer size */
|
#define INI_PASSWORD "Password" /* Default Password */
|
||||||
#define INI_READONLY "ReadOnly" /* Database is read only */
|
#define INI_DEBUG "Debug" /* Debug flag */
|
||||||
#define INI_COMMLOG "CommLog" /* Communication to backend logging */
|
#define INI_FETCH "Fetch" /* Fetch Max Count */
|
||||||
#define INI_PROTOCOL "Protocol" /* What protocol (6.2) */
|
#define INI_SOCKET "Socket" /* Socket buffer size */
|
||||||
#define INI_OPTIMIZER "Optimizer" /* Use backend genetic optimizer */
|
#define INI_READONLY "ReadOnly" /* Database is read only */
|
||||||
#define INI_KSQO "Ksqo" /* Keyset query optimization */
|
#define INI_COMMLOG "CommLog" /* Communication to backend
|
||||||
#define INI_CONNSETTINGS "ConnSettings" /* Anything to send to backend on successful connection */
|
* logging */
|
||||||
#define INI_UNIQUEINDEX "UniqueIndex" /* Recognize unique indexes */
|
#define INI_PROTOCOL "Protocol" /* What protocol (6.2) */
|
||||||
#define INI_UNKNOWNSIZES "UnknownSizes" /* How to handle unknown result set sizes */
|
#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_UNIQUEINDEX "UniqueIndex" /* Recognize unique indexes */
|
||||||
|
#define INI_UNKNOWNSIZES "UnknownSizes" /* How to handle unknown
|
||||||
|
* result set sizes */
|
||||||
|
|
||||||
#define INI_CANCELASFREESTMT "CancelAsFreeStmt"
|
#define INI_CANCELASFREESTMT "CancelAsFreeStmt"
|
||||||
|
|
||||||
#define INI_USEDECLAREFETCH "UseDeclareFetch" /* Use Declare/Fetch cursors */
|
#define INI_USEDECLAREFETCH "UseDeclareFetch" /* Use Declare/Fetch
|
||||||
|
* cursors */
|
||||||
|
|
||||||
/* More ini stuff */
|
/* More ini stuff */
|
||||||
#define INI_TEXTASLONGVARCHAR "TextAsLongVarchar"
|
#define INI_TEXTASLONGVARCHAR "TextAsLongVarchar"
|
||||||
@ -82,15 +90,16 @@
|
|||||||
#define INI_PARSE "Parse"
|
#define INI_PARSE "Parse"
|
||||||
#define INI_EXTRASYSTABLEPREFIXES "ExtraSysTablePrefixes"
|
#define INI_EXTRASYSTABLEPREFIXES "ExtraSysTablePrefixes"
|
||||||
|
|
||||||
#define INI_TRANSLATIONNAME "TranslationName"
|
#define INI_TRANSLATIONNAME "TranslationName"
|
||||||
#define INI_TRANSLATIONDLL "TranslationDLL"
|
#define INI_TRANSLATIONDLL "TranslationDLL"
|
||||||
#define INI_TRANSLATIONOPTION "TranslationOption"
|
#define INI_TRANSLATIONOPTION "TranslationOption"
|
||||||
|
|
||||||
|
|
||||||
/* Connection Defaults */
|
/* Connection Defaults */
|
||||||
#define DEFAULT_PORT "5432"
|
#define DEFAULT_PORT "5432"
|
||||||
#define DEFAULT_READONLY 1
|
#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_USEDECLAREFETCH 0
|
||||||
#define DEFAULT_TEXTASLONGVARCHAR 1
|
#define DEFAULT_TEXTASLONGVARCHAR 1
|
||||||
#define DEFAULT_UNKNOWNSASLONGVARCHAR 0
|
#define DEFAULT_UNKNOWNSASLONGVARCHAR 0
|
||||||
@ -114,29 +123,30 @@
|
|||||||
|
|
||||||
#define DEFAULT_EXTRASYSTABLEPREFIXES "dd_;"
|
#define DEFAULT_EXTRASYSTABLEPREFIXES "dd_;"
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
void getGlobalDefaults(char *section, char *filename, char override);
|
void getGlobalDefaults(char *section, char *filename, char override);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
void SetDlgStuff(HWND hdlg, ConnInfo *ci);
|
void SetDlgStuff(HWND hdlg, ConnInfo * ci);
|
||||||
void GetDlgStuff(HWND hdlg, ConnInfo *ci);
|
void GetDlgStuff(HWND hdlg, ConnInfo * ci);
|
||||||
|
|
||||||
int CALLBACK driver_optionsProc(HWND hdlg,
|
int CALLBACK driver_optionsProc(HWND hdlg,
|
||||||
WORD wMsg,
|
WORD wMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam);
|
LPARAM lParam);
|
||||||
int CALLBACK ds_optionsProc(HWND hdlg,
|
int CALLBACK ds_optionsProc(HWND hdlg,
|
||||||
WORD wMsg,
|
WORD wMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam);
|
LPARAM lParam);
|
||||||
#endif /* WIN32 */
|
|
||||||
|
|
||||||
void updateGlobals(void);
|
#endif /* WIN32 */
|
||||||
void writeDSNinfo(ConnInfo *ci);
|
|
||||||
void getDSNdefaults(ConnInfo *ci);
|
void updateGlobals(void);
|
||||||
void getDSNinfo(ConnInfo *ci, char overwrite);
|
void writeDSNinfo(ConnInfo * ci);
|
||||||
void makeConnectString(char *connect_string, ConnInfo *ci);
|
void getDSNdefaults(ConnInfo * ci);
|
||||||
void copyAttributes(ConnInfo *ci, char *attribute, char *value);
|
void getDSNinfo(ConnInfo * ci, char overwrite);
|
||||||
|
void makeConnectString(char *connect_string, ConnInfo * ci);
|
||||||
|
void copyAttributes(ConnInfo * ci, char *attribute, char *value);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* Module: drvconn.c
|
/* Module: drvconn.c
|
||||||
*
|
*
|
||||||
* Description: This module contains only routines related to
|
* Description: This module contains only routines related to
|
||||||
* implementing SQLDriverConnect.
|
* implementing SQLDriverConnect.
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: SQLDriverConnect
|
* API functions: SQLDriverConnect
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -52,45 +52,50 @@
|
|||||||
#include "dlg_specific.h"
|
#include "dlg_specific.h"
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
|
void dconn_get_connect_attributes(UCHAR FAR * connect_string, ConnInfo * ci);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
|
BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
|
||||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
|
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo * ci);
|
||||||
|
|
||||||
|
extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
|
||||||
|
|
||||||
extern HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
|
|
||||||
|
|
||||||
RETCODE SQL_API SQLDriverConnect(
|
RETCODE SQL_API
|
||||||
HDBC hdbc,
|
SQLDriverConnect(
|
||||||
HWND hwnd,
|
HDBC hdbc,
|
||||||
UCHAR FAR *szConnStrIn,
|
HWND hwnd,
|
||||||
SWORD cbConnStrIn,
|
UCHAR FAR * szConnStrIn,
|
||||||
UCHAR FAR *szConnStrOut,
|
SWORD cbConnStrIn,
|
||||||
SWORD cbConnStrOutMax,
|
UCHAR FAR * szConnStrOut,
|
||||||
SWORD FAR *pcbConnStrOut,
|
SWORD cbConnStrOutMax,
|
||||||
UWORD fDriverCompletion)
|
SWORD FAR * pcbConnStrOut,
|
||||||
|
UWORD fDriverCompletion)
|
||||||
{
|
{
|
||||||
static char *func = "SQLDriverConnect";
|
static char *func = "SQLDriverConnect";
|
||||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||||
ConnInfo *ci;
|
ConnInfo *ci;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
RETCODE dialog_result;
|
RETCODE dialog_result;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
RETCODE result;
|
RETCODE result;
|
||||||
char connStrIn[MAX_CONNECT_STRING];
|
char connStrIn[MAX_CONNECT_STRING];
|
||||||
char connStrOut[MAX_CONNECT_STRING];
|
char connStrOut[MAX_CONNECT_STRING];
|
||||||
int retval;
|
int retval;
|
||||||
char password_required = FALSE;
|
char password_required = FALSE;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|
||||||
mylog("%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! conn) {
|
if (!conn)
|
||||||
|
{
|
||||||
CC_log_error(func, "", NULL);
|
CC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
@ -102,17 +107,17 @@ int len = 0;
|
|||||||
|
|
||||||
ci = &(conn->connInfo);
|
ci = &(conn->connInfo);
|
||||||
|
|
||||||
/* Parse the connect string and fill in conninfo for this hdbc. */
|
/* Parse the connect string and fill in conninfo for this hdbc. */
|
||||||
dconn_get_connect_attributes(connStrIn, ci);
|
dconn_get_connect_attributes(connStrIn, ci);
|
||||||
|
|
||||||
/* If the ConnInfo in the hdbc is missing anything, */
|
/* If the ConnInfo in the hdbc is missing anything, */
|
||||||
/* this function will fill them in from the registry (assuming */
|
/* this function will fill them in from the registry (assuming */
|
||||||
/* of course there is a DSN given -- if not, it does nothing!) */
|
/* of course there is a DSN given -- if not, it does nothing!) */
|
||||||
getDSNinfo(ci, CONN_DONT_OVERWRITE);
|
getDSNinfo(ci, CONN_DONT_OVERWRITE);
|
||||||
|
|
||||||
/* Fill in any default parameters if they are not there. */
|
/* Fill in any default parameters if they are not there. */
|
||||||
getDSNdefaults(ci);
|
getDSNdefaults(ci);
|
||||||
/* initialize pg_version */
|
/* initialize pg_version */
|
||||||
CC_initialize_pg_version(conn);
|
CC_initialize_pg_version(conn);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -120,51 +125,54 @@ dialog:
|
|||||||
#endif
|
#endif
|
||||||
ci->focus_password = password_required;
|
ci->focus_password = password_required;
|
||||||
|
|
||||||
switch(fDriverCompletion) {
|
switch (fDriverCompletion)
|
||||||
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
case SQL_DRIVER_PROMPT:
|
case SQL_DRIVER_PROMPT:
|
||||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
|
||||||
if(dialog_result != SQL_SUCCESS) {
|
|
||||||
return dialog_result;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
|
||||||
|
|
||||||
/* Fall through */
|
|
||||||
|
|
||||||
case SQL_DRIVER_COMPLETE:
|
|
||||||
|
|
||||||
/* Password is not a required parameter. */
|
|
||||||
if( ci->username[0] == '\0' ||
|
|
||||||
ci->server[0] == '\0' ||
|
|
||||||
ci->database[0] == '\0' ||
|
|
||||||
ci->port[0] == '\0' ||
|
|
||||||
password_required) {
|
|
||||||
|
|
||||||
dialog_result = dconn_DoDialog(hwnd, ci);
|
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||||
if(dialog_result != SQL_SUCCESS) {
|
if (dialog_result != SQL_SUCCESS)
|
||||||
return dialog_result;
|
return dialog_result;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||||
|
|
||||||
|
/* Fall through */
|
||||||
|
|
||||||
|
case SQL_DRIVER_COMPLETE:
|
||||||
|
|
||||||
|
/* Password is not a required parameter. */
|
||||||
|
if (ci->username[0] == '\0' ||
|
||||||
|
ci->server[0] == '\0' ||
|
||||||
|
ci->database[0] == '\0' ||
|
||||||
|
ci->port[0] == '\0' ||
|
||||||
|
password_required)
|
||||||
|
{
|
||||||
|
|
||||||
|
dialog_result = dconn_DoDialog(hwnd, ci);
|
||||||
|
if (dialog_result != SQL_SUCCESS)
|
||||||
|
return dialog_result;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
#else
|
#else
|
||||||
case SQL_DRIVER_PROMPT:
|
case SQL_DRIVER_PROMPT:
|
||||||
case SQL_DRIVER_COMPLETE:
|
case SQL_DRIVER_COMPLETE:
|
||||||
case SQL_DRIVER_COMPLETE_REQUIRED:
|
case SQL_DRIVER_COMPLETE_REQUIRED:
|
||||||
#endif
|
#endif
|
||||||
case SQL_DRIVER_NOPROMPT:
|
case SQL_DRIVER_NOPROMPT:
|
||||||
break;
|
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
|
* Password is not a required parameter unless authentication asks for
|
||||||
a password is entered (the user can always hit Cancel to get out)
|
* 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
|
||||||
if( ci->username[0] == '\0' ||
|
* Cancel to get out)
|
||||||
|
*/
|
||||||
|
if (ci->username[0] == '\0' ||
|
||||||
ci->server[0] == '\0' ||
|
ci->server[0] == '\0' ||
|
||||||
ci->database[0] == '\0' ||
|
ci->database[0] == '\0' ||
|
||||||
ci->port[0] == '\0') {
|
ci->port[0] == '\0')
|
||||||
|
{
|
||||||
/* (password_required && ci->password[0] == '\0')) */
|
/* (password_required && ci->password[0] == '\0')) */
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
@ -173,12 +181,16 @@ dialog:
|
|||||||
|
|
||||||
/* do the actual connect */
|
/* do the actual connect */
|
||||||
retval = CC_connect(conn, password_required);
|
retval = CC_connect(conn, password_required);
|
||||||
if (retval < 0) { /* need a password */
|
if (retval < 0)
|
||||||
if (fDriverCompletion == SQL_DRIVER_NOPROMPT) {
|
{ /* need a password */
|
||||||
|
if (fDriverCompletion == SQL_DRIVER_NOPROMPT)
|
||||||
|
{
|
||||||
CC_log_error(func, "Need password but Driver_NoPrompt", conn);
|
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
|
#ifdef WIN32
|
||||||
password_required = TRUE;
|
password_required = TRUE;
|
||||||
goto dialog;
|
goto dialog;
|
||||||
@ -187,39 +199,44 @@ dialog:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (retval == 0) {
|
else if (retval == 0)
|
||||||
/* error msg filled in above */
|
{
|
||||||
|
/* error msg filled in above */
|
||||||
CC_log_error(func, "Error from CC_Connect", conn);
|
CC_log_error(func, "Error from CC_Connect", conn);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
/* Create the Output Connection String */
|
/* Create the Output Connection String */
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
result = SQL_SUCCESS;
|
result = SQL_SUCCESS;
|
||||||
|
|
||||||
makeConnectString(connStrOut, ci);
|
makeConnectString(connStrOut, ci);
|
||||||
len = strlen(connStrOut);
|
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,
|
* Return the completed string to the caller. The correct method
|
||||||
it should just copy the connection input string to the output.
|
* is to only construct the connect string if a dialog was put up,
|
||||||
However, it seems ok to just always construct an output string. There
|
* otherwise, it should just copy the connection input string to
|
||||||
are possible bad side effects on working applications (Access) by
|
* the output. However, it seems ok to just always construct an
|
||||||
implementing the correct behavior, anyway.
|
* output string. There are possible bad side effects on working
|
||||||
*/
|
* applications (Access) by implementing the correct behavior,
|
||||||
|
* anyway.
|
||||||
|
*/
|
||||||
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
|
strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
|
||||||
|
|
||||||
if (len >= cbConnStrOutMax) {
|
if (len >= cbConnStrOutMax)
|
||||||
|
{
|
||||||
result = SQL_SUCCESS_WITH_INFO;
|
result = SQL_SUCCESS_WITH_INFO;
|
||||||
conn->errornumber = CONN_TRUNCATED;
|
conn->errornumber = CONN_TRUNCATED;
|
||||||
conn->errormsg = "The buffer was too small for the result.";
|
conn->errormsg = "The buffer was too small for the result.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pcbConnStrOut)
|
if (pcbConnStrOut)
|
||||||
*pcbConnStrOut = len;
|
*pcbConnStrOut = len;
|
||||||
|
|
||||||
mylog("szConnStrOut = '%s'\n", szConnStrOut);
|
mylog("szConnStrOut = '%s'\n", szConnStrOut);
|
||||||
@ -231,108 +248,117 @@ dialog:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci)
|
RETCODE
|
||||||
|
dconn_DoDialog(HWND hwnd, ConnInfo * ci)
|
||||||
{
|
{
|
||||||
int dialog_result;
|
int dialog_result;
|
||||||
|
|
||||||
mylog("dconn_DoDialog: ci = %u\n", ci);
|
mylog("dconn_DoDialog: ci = %u\n", ci);
|
||||||
|
|
||||||
if(hwnd) {
|
if (hwnd)
|
||||||
|
{
|
||||||
dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
|
dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
|
||||||
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
|
hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
|
||||||
if(!dialog_result || (dialog_result == -1)) {
|
if (!dialog_result || (dialog_result == -1))
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
} else {
|
else
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL FAR PASCAL dconn_FDriverConnectProc(
|
BOOL FAR PASCAL
|
||||||
HWND hdlg,
|
dconn_FDriverConnectProc(
|
||||||
UINT wMsg,
|
HWND hdlg,
|
||||||
WPARAM wParam,
|
UINT wMsg,
|
||||||
LPARAM lParam)
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
ConnInfo *ci;
|
ConnInfo *ci;
|
||||||
|
|
||||||
switch (wMsg) {
|
switch (wMsg)
|
||||||
case WM_INITDIALOG:
|
{
|
||||||
ci = (ConnInfo *) lParam;
|
case WM_INITDIALOG:
|
||||||
|
ci = (ConnInfo *) lParam;
|
||||||
|
|
||||||
/* Change the caption for the setup dialog */
|
/* Change the caption for the setup dialog */
|
||||||
SetWindowText(hdlg, "PostgreSQL Connection");
|
SetWindowText(hdlg, "PostgreSQL Connection");
|
||||||
|
|
||||||
SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
|
SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
|
||||||
|
|
||||||
/* Hide the DSN and description fields */
|
/* Hide the DSN and description fields */
|
||||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
|
ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
|
||||||
ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
|
ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
|
||||||
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
|
ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
|
||||||
ShowWindow(GetDlgItem(hdlg, IDC_DESC), 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);
|
SetDlgStuff(hdlg, ci);
|
||||||
|
|
||||||
if (ci->database[0] == '\0')
|
if (ci->database[0] == '\0')
|
||||||
; /* default focus */
|
; /* default focus */
|
||||||
else if (ci->server[0] == '\0')
|
else if (ci->server[0] == '\0')
|
||||||
SetFocus(GetDlgItem(hdlg, IDC_SERVER));
|
SetFocus(GetDlgItem(hdlg, IDC_SERVER));
|
||||||
else if (ci->port[0] == '\0')
|
else if (ci->port[0] == '\0')
|
||||||
SetFocus(GetDlgItem(hdlg, IDC_PORT));
|
SetFocus(GetDlgItem(hdlg, IDC_PORT));
|
||||||
else if (ci->username[0] == '\0')
|
else if (ci->username[0] == '\0')
|
||||||
SetFocus(GetDlgItem(hdlg, IDC_USER));
|
SetFocus(GetDlgItem(hdlg, IDC_USER));
|
||||||
else if (ci->focus_password)
|
else if (ci->focus_password)
|
||||||
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
|
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
|
||||||
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
|
|
||||||
case IDOK:
|
|
||||||
|
|
||||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
|
||||||
|
|
||||||
GetDlgStuff(hdlg, ci);
|
|
||||||
|
|
||||||
|
|
||||||
case IDCANCEL:
|
|
||||||
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case IDC_DRIVER:
|
|
||||||
|
|
||||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
|
||||||
hdlg, driver_optionsProc, (LPARAM) NULL);
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_DATASOURCE:
|
case WM_COMMAND:
|
||||||
|
switch (GET_WM_COMMAND_ID(wParam, lParam))
|
||||||
|
{
|
||||||
|
case IDOK:
|
||||||
|
|
||||||
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
|
||||||
hdlg, ds_optionsProc, (LPARAM) ci);
|
|
||||||
|
|
||||||
break;
|
GetDlgStuff(hdlg, ci);
|
||||||
}
|
|
||||||
|
|
||||||
|
case IDCANCEL:
|
||||||
|
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
case IDC_DRIVER:
|
||||||
|
|
||||||
|
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
||||||
|
hdlg, driver_optionsProc, (LPARAM) NULL);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IDC_DATASOURCE:
|
||||||
|
|
||||||
|
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
|
||||||
|
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
||||||
|
hdlg, ds_optionsProc, (LPARAM) ci);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#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 *our_connect_string;
|
||||||
char *pair, *attribute, *value, *equals;
|
char *pair,
|
||||||
char *strtok_arg;
|
*attribute,
|
||||||
|
*value,
|
||||||
|
*equals;
|
||||||
|
char *strtok_arg;
|
||||||
|
|
||||||
memset(ci, 0, sizeof(ConnInfo));
|
memset(ci, 0, sizeof(ConnInfo));
|
||||||
|
|
||||||
@ -341,29 +367,28 @@ char *strtok_arg;
|
|||||||
|
|
||||||
mylog("our_connect_string = '%s'\n", our_connect_string);
|
mylog("our_connect_string = '%s'\n", our_connect_string);
|
||||||
|
|
||||||
while(1) {
|
while (1)
|
||||||
|
{
|
||||||
pair = strtok(strtok_arg, ";");
|
pair = strtok(strtok_arg, ";");
|
||||||
if(strtok_arg) {
|
if (strtok_arg)
|
||||||
strtok_arg = 0;
|
strtok_arg = 0;
|
||||||
}
|
if (!pair)
|
||||||
if(!pair) {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
equals = strchr(pair, '=');
|
equals = strchr(pair, '=');
|
||||||
if ( ! equals)
|
if (!equals)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
*equals = '\0';
|
*equals = '\0';
|
||||||
attribute = pair; /* ex. DSN */
|
attribute = pair; /* ex. DSN */
|
||||||
value = equals + 1; /* ex. 'CEO co1' */
|
value = equals + 1; /* ex. 'CEO co1' */
|
||||||
|
|
||||||
mylog("attribute = '%s', value = '%s'\n", attribute, value);
|
mylog("attribute = '%s', value = '%s'\n", attribute, value);
|
||||||
|
|
||||||
if( !attribute || !value)
|
if (!attribute || !value)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Copy the appropriate value to the conninfo */
|
/* Copy the appropriate value to the conninfo */
|
||||||
copyAttributes(ci, attribute, value);
|
copyAttributes(ci, attribute, value);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -371,4 +396,3 @@ char *strtok_arg;
|
|||||||
|
|
||||||
free(our_connect_string);
|
free(our_connect_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/* Module: environ.c
|
/* Module: environ.c
|
||||||
*
|
*
|
||||||
* Description: This module contains routines related to
|
* Description: This module contains routines related to
|
||||||
* the environment, such as storing connection handles,
|
* the environment, such as storing connection handles,
|
||||||
* and returning errors.
|
* and returning errors.
|
||||||
*
|
*
|
||||||
* Classes: EnvironmentClass (Functions prefix: "EN_")
|
* Classes: EnvironmentClass (Functions prefix: "EN_")
|
||||||
*
|
*
|
||||||
* API functions: SQLAllocEnv, SQLFreeEnv, SQLError
|
* API functions: SQLAllocEnv, SQLFreeEnv, SQLError
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -22,14 +22,16 @@
|
|||||||
ConnectionClass *conns[MAX_CONNECTIONS];
|
ConnectionClass *conns[MAX_CONNECTIONS];
|
||||||
|
|
||||||
|
|
||||||
RETCODE SQL_API SQLAllocEnv(HENV FAR *phenv)
|
RETCODE SQL_API
|
||||||
|
SQLAllocEnv(HENV FAR * phenv)
|
||||||
{
|
{
|
||||||
static char *func = "SQLAllocEnv";
|
static char *func = "SQLAllocEnv";
|
||||||
|
|
||||||
mylog("**** in SQLAllocEnv ** \n");
|
mylog("**** in SQLAllocEnv ** \n");
|
||||||
|
|
||||||
*phenv = (HENV) EN_Constructor();
|
*phenv = (HENV) EN_Constructor();
|
||||||
if ( ! *phenv) {
|
if (!*phenv)
|
||||||
|
{
|
||||||
*phenv = SQL_NULL_HENV;
|
*phenv = SQL_NULL_HENV;
|
||||||
EN_log_error(func, "Error allocating environment", NULL);
|
EN_log_error(func, "Error allocating environment", NULL);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
@ -39,14 +41,16 @@ mylog("**** in SQLAllocEnv ** \n");
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETCODE SQL_API SQLFreeEnv(HENV henv)
|
RETCODE SQL_API
|
||||||
|
SQLFreeEnv(HENV henv)
|
||||||
{
|
{
|
||||||
static char *func = "SQLFreeEnv";
|
static char *func = "SQLFreeEnv";
|
||||||
EnvironmentClass *env = (EnvironmentClass *) henv;
|
EnvironmentClass *env = (EnvironmentClass *) henv;
|
||||||
|
|
||||||
mylog("**** in SQLFreeEnv: env = %u ** \n", env);
|
mylog("**** in SQLFreeEnv: env = %u ** \n", env);
|
||||||
|
|
||||||
if (env && EN_Destructor(env)) {
|
if (env && EN_Destructor(env))
|
||||||
|
{
|
||||||
mylog(" ok\n");
|
mylog(" ok\n");
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -56,321 +60,349 @@ mylog("**** in SQLFreeEnv: env = %u ** \n", env);
|
|||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the next SQL error information. */
|
/* Returns the next SQL error information. */
|
||||||
|
|
||||||
RETCODE SQL_API SQLError(
|
RETCODE SQL_API
|
||||||
HENV henv,
|
SQLError(
|
||||||
HDBC hdbc,
|
HENV henv,
|
||||||
HSTMT hstmt,
|
HDBC hdbc,
|
||||||
UCHAR FAR *szSqlState,
|
HSTMT hstmt,
|
||||||
SDWORD FAR *pfNativeError,
|
UCHAR FAR * szSqlState,
|
||||||
UCHAR FAR *szErrorMsg,
|
SDWORD FAR * pfNativeError,
|
||||||
SWORD cbErrorMsgMax,
|
UCHAR FAR * szErrorMsg,
|
||||||
SWORD FAR *pcbErrorMsg)
|
SWORD cbErrorMsgMax,
|
||||||
|
SWORD FAR * pcbErrorMsg)
|
||||||
{
|
{
|
||||||
char *msg;
|
char *msg;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u\n", henv, hdbc, hstmt);
|
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;
|
/* 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);
|
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 != szSqlState)
|
||||||
if (NULL != pcbErrorMsg)
|
strcpy(szSqlState, "00000");
|
||||||
*pcbErrorMsg = 0;
|
if (NULL != pcbErrorMsg)
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
*pcbErrorMsg = 0;
|
||||||
szErrorMsg[0] = '\0';
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != pcbErrorMsg)
|
||||||
*pcbErrorMsg = (SWORD)strlen(msg);
|
*pcbErrorMsg = (SWORD) strlen(msg);
|
||||||
|
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
||||||
|
|
||||||
if (NULL != pfNativeError)
|
if (NULL != pfNativeError)
|
||||||
*pfNativeError = status;
|
*pfNativeError = status;
|
||||||
|
|
||||||
if (NULL != szSqlState)
|
if (NULL != szSqlState)
|
||||||
|
|
||||||
switch (status) {
|
switch (status)
|
||||||
/* now determine the SQLSTATE to be returned */
|
{
|
||||||
case STMT_TRUNCATED:
|
/* now determine the SQLSTATE to be returned */
|
||||||
strcpy(szSqlState, "01004");
|
case STMT_TRUNCATED:
|
||||||
/* data truncated */
|
strcpy(szSqlState, "01004");
|
||||||
break;
|
/* data truncated */
|
||||||
case STMT_INFO_ONLY:
|
break;
|
||||||
strcpy(szSqlState, "00000");
|
case STMT_INFO_ONLY:
|
||||||
/* just information that is returned, no error */
|
strcpy(szSqlState, "00000");
|
||||||
break;
|
/* just information that is returned, no error */
|
||||||
case STMT_BAD_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "08S01");
|
case STMT_BAD_ERROR:
|
||||||
/* communication link failure */
|
strcpy(szSqlState, "08S01");
|
||||||
break;
|
/* communication link failure */
|
||||||
case STMT_CREATE_TABLE_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S0001");
|
case STMT_CREATE_TABLE_ERROR:
|
||||||
/* table already exists */
|
strcpy(szSqlState, "S0001");
|
||||||
break;
|
/* table already exists */
|
||||||
case STMT_STATUS_ERROR:
|
break;
|
||||||
case STMT_SEQUENCE_ERROR:
|
case STMT_STATUS_ERROR:
|
||||||
strcpy(szSqlState, "S1010");
|
case STMT_SEQUENCE_ERROR:
|
||||||
/* Function sequence error */
|
strcpy(szSqlState, "S1010");
|
||||||
break;
|
/* Function sequence error */
|
||||||
case STMT_NO_MEMORY_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1001");
|
case STMT_NO_MEMORY_ERROR:
|
||||||
/* memory allocation failure */
|
strcpy(szSqlState, "S1001");
|
||||||
break;
|
/* memory allocation failure */
|
||||||
case STMT_COLNUM_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1002");
|
case STMT_COLNUM_ERROR:
|
||||||
/* invalid column number */
|
strcpy(szSqlState, "S1002");
|
||||||
break;
|
/* invalid column number */
|
||||||
case STMT_NO_STMTSTRING:
|
break;
|
||||||
strcpy(szSqlState, "S1001");
|
case STMT_NO_STMTSTRING:
|
||||||
/* having no stmtstring is also a malloc problem */
|
strcpy(szSqlState, "S1001");
|
||||||
break;
|
/* having no stmtstring is also a malloc problem */
|
||||||
case STMT_ERROR_TAKEN_FROM_BACKEND:
|
break;
|
||||||
strcpy(szSqlState, "S1000");
|
case STMT_ERROR_TAKEN_FROM_BACKEND:
|
||||||
/* general error */
|
strcpy(szSqlState, "S1000");
|
||||||
break;
|
/* general error */
|
||||||
case STMT_INTERNAL_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1000");
|
case STMT_INTERNAL_ERROR:
|
||||||
/* general error */
|
strcpy(szSqlState, "S1000");
|
||||||
break;
|
/* general error */
|
||||||
case STMT_ROW_OUT_OF_RANGE:
|
break;
|
||||||
strcpy(szSqlState, "S1107");
|
case STMT_ROW_OUT_OF_RANGE:
|
||||||
break;
|
strcpy(szSqlState, "S1107");
|
||||||
|
break;
|
||||||
|
|
||||||
case STMT_OPERATION_CANCELLED:
|
case STMT_OPERATION_CANCELLED:
|
||||||
strcpy(szSqlState, "S1008");
|
strcpy(szSqlState, "S1008");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STMT_NOT_IMPLEMENTED_ERROR:
|
case STMT_NOT_IMPLEMENTED_ERROR:
|
||||||
strcpy(szSqlState, "S1C00"); /* == 'driver not capable' */
|
strcpy(szSqlState, "S1C00"); /* == 'driver not
|
||||||
break;
|
* capable' */
|
||||||
case STMT_OPTION_OUT_OF_RANGE_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1092");
|
case STMT_OPTION_OUT_OF_RANGE_ERROR:
|
||||||
break;
|
strcpy(szSqlState, "S1092");
|
||||||
case STMT_BAD_PARAMETER_NUMBER_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1093");
|
case STMT_BAD_PARAMETER_NUMBER_ERROR:
|
||||||
break;
|
strcpy(szSqlState, "S1093");
|
||||||
case STMT_INVALID_COLUMN_NUMBER_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1002");
|
case STMT_INVALID_COLUMN_NUMBER_ERROR:
|
||||||
break;
|
strcpy(szSqlState, "S1002");
|
||||||
case STMT_RESTRICTED_DATA_TYPE_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "07006");
|
case STMT_RESTRICTED_DATA_TYPE_ERROR:
|
||||||
break;
|
strcpy(szSqlState, "07006");
|
||||||
case STMT_INVALID_CURSOR_STATE_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "24000");
|
case STMT_INVALID_CURSOR_STATE_ERROR:
|
||||||
break;
|
strcpy(szSqlState, "24000");
|
||||||
case STMT_OPTION_VALUE_CHANGED:
|
break;
|
||||||
strcpy(szSqlState, "01S02");
|
case STMT_OPTION_VALUE_CHANGED:
|
||||||
break;
|
strcpy(szSqlState, "01S02");
|
||||||
case STMT_INVALID_CURSOR_NAME:
|
break;
|
||||||
strcpy(szSqlState, "34000");
|
case STMT_INVALID_CURSOR_NAME:
|
||||||
break;
|
strcpy(szSqlState, "34000");
|
||||||
case STMT_NO_CURSOR_NAME:
|
break;
|
||||||
strcpy(szSqlState, "S1015");
|
case STMT_NO_CURSOR_NAME:
|
||||||
break;
|
strcpy(szSqlState, "S1015");
|
||||||
case STMT_INVALID_ARGUMENT_NO:
|
break;
|
||||||
strcpy(szSqlState, "S1009");
|
case STMT_INVALID_ARGUMENT_NO:
|
||||||
/* invalid argument value */
|
strcpy(szSqlState, "S1009");
|
||||||
break;
|
/* invalid argument value */
|
||||||
case STMT_INVALID_CURSOR_POSITION:
|
break;
|
||||||
strcpy(szSqlState, "S1109");
|
case STMT_INVALID_CURSOR_POSITION:
|
||||||
break;
|
strcpy(szSqlState, "S1109");
|
||||||
|
break;
|
||||||
|
|
||||||
case STMT_VALUE_OUT_OF_RANGE:
|
case STMT_VALUE_OUT_OF_RANGE:
|
||||||
strcpy(szSqlState, "22003");
|
strcpy(szSqlState, "22003");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STMT_OPERATION_INVALID:
|
case STMT_OPERATION_INVALID:
|
||||||
strcpy(szSqlState, "S1011");
|
strcpy(szSqlState, "S1011");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STMT_EXEC_ERROR:
|
case STMT_EXEC_ERROR:
|
||||||
default:
|
default:
|
||||||
strcpy(szSqlState, "S1000");
|
strcpy(szSqlState, "S1000");
|
||||||
/* also a general error */
|
/* also a general error */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mylog(" szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
|
mylog(" szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
|
||||||
|
|
||||||
} else {
|
}
|
||||||
if (NULL != szSqlState)
|
else
|
||||||
strcpy(szSqlState, "00000");
|
{
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != szSqlState)
|
||||||
*pcbErrorMsg = 0;
|
strcpy(szSqlState, "00000");
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if (NULL != pcbErrorMsg)
|
||||||
szErrorMsg[0] = '\0';
|
*pcbErrorMsg = 0;
|
||||||
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
mylog(" returning NO_DATA_FOUND\n");
|
mylog(" returning NO_DATA_FOUND\n");
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
|
|
||||||
} else if (SQL_NULL_HDBC != hdbc) {
|
}
|
||||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
else if (SQL_NULL_HDBC != hdbc)
|
||||||
|
{
|
||||||
|
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||||
|
|
||||||
mylog("calling CC_get_error\n");
|
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);
|
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 != szSqlState)
|
||||||
if (NULL != pcbErrorMsg)
|
strcpy(szSqlState, "00000");
|
||||||
*pcbErrorMsg = 0;
|
if (NULL != pcbErrorMsg)
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
*pcbErrorMsg = 0;
|
||||||
szErrorMsg[0] = '\0';
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != pcbErrorMsg)
|
||||||
*pcbErrorMsg = (SWORD)strlen(msg);
|
*pcbErrorMsg = (SWORD) strlen(msg);
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
||||||
if (NULL != pfNativeError)
|
if (NULL != pfNativeError)
|
||||||
*pfNativeError = status;
|
*pfNativeError = status;
|
||||||
|
|
||||||
if (NULL != szSqlState)
|
if (NULL != szSqlState)
|
||||||
switch(status) {
|
switch (status)
|
||||||
case STMT_OPTION_VALUE_CHANGED:
|
{
|
||||||
case CONN_OPTION_VALUE_CHANGED:
|
case STMT_OPTION_VALUE_CHANGED:
|
||||||
strcpy(szSqlState, "01S02");
|
case CONN_OPTION_VALUE_CHANGED:
|
||||||
break;
|
strcpy(szSqlState, "01S02");
|
||||||
case STMT_TRUNCATED:
|
break;
|
||||||
case CONN_TRUNCATED:
|
case STMT_TRUNCATED:
|
||||||
strcpy(szSqlState, "01004");
|
case CONN_TRUNCATED:
|
||||||
/* data truncated */
|
strcpy(szSqlState, "01004");
|
||||||
break;
|
/* data truncated */
|
||||||
case CONN_INIREAD_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "IM002");
|
case CONN_INIREAD_ERROR:
|
||||||
/* data source not found */
|
strcpy(szSqlState, "IM002");
|
||||||
break;
|
/* data source not found */
|
||||||
case CONN_OPENDB_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "08001");
|
case CONN_OPENDB_ERROR:
|
||||||
/* unable to connect to data source */
|
strcpy(szSqlState, "08001");
|
||||||
break;
|
/* unable to connect to data source */
|
||||||
case CONN_INVALID_AUTHENTICATION:
|
break;
|
||||||
case CONN_AUTH_TYPE_UNSUPPORTED:
|
case CONN_INVALID_AUTHENTICATION:
|
||||||
strcpy(szSqlState, "28000");
|
case CONN_AUTH_TYPE_UNSUPPORTED:
|
||||||
break;
|
strcpy(szSqlState, "28000");
|
||||||
case CONN_STMT_ALLOC_ERROR:
|
break;
|
||||||
strcpy(szSqlState, "S1001");
|
case CONN_STMT_ALLOC_ERROR:
|
||||||
/* memory allocation failure */
|
strcpy(szSqlState, "S1001");
|
||||||
break;
|
/* memory allocation failure */
|
||||||
case CONN_IN_USE:
|
break;
|
||||||
strcpy(szSqlState, "S1000");
|
case CONN_IN_USE:
|
||||||
/* general error */
|
strcpy(szSqlState, "S1000");
|
||||||
break;
|
/* general error */
|
||||||
case CONN_UNSUPPORTED_OPTION:
|
break;
|
||||||
strcpy(szSqlState, "IM001");
|
case CONN_UNSUPPORTED_OPTION:
|
||||||
/* driver does not support this function */
|
strcpy(szSqlState, "IM001");
|
||||||
case CONN_INVALID_ARGUMENT_NO:
|
/* driver does not support this function */
|
||||||
strcpy(szSqlState, "S1009");
|
case CONN_INVALID_ARGUMENT_NO:
|
||||||
/* invalid argument value */
|
strcpy(szSqlState, "S1009");
|
||||||
break;
|
/* invalid argument value */
|
||||||
case CONN_TRANSACT_IN_PROGRES:
|
break;
|
||||||
strcpy(szSqlState, "S1010");
|
case CONN_TRANSACT_IN_PROGRES:
|
||||||
/* when the user tries to switch commit mode in a transaction */
|
strcpy(szSqlState, "S1010");
|
||||||
/* -> function sequence error */
|
|
||||||
break;
|
|
||||||
case CONN_NO_MEMORY_ERROR:
|
|
||||||
strcpy(szSqlState, "S1001");
|
|
||||||
break;
|
|
||||||
case CONN_NOT_IMPLEMENTED_ERROR:
|
|
||||||
case STMT_NOT_IMPLEMENTED_ERROR:
|
|
||||||
strcpy(szSqlState, "S1C00");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CONN_VALUE_OUT_OF_RANGE:
|
/*
|
||||||
case STMT_VALUE_OUT_OF_RANGE:
|
* when the user tries to switch commit mode in a
|
||||||
strcpy(szSqlState, "22003");
|
* transaction
|
||||||
break;
|
*/
|
||||||
|
/* -> function sequence error */
|
||||||
|
break;
|
||||||
|
case CONN_NO_MEMORY_ERROR:
|
||||||
|
strcpy(szSqlState, "S1001");
|
||||||
|
break;
|
||||||
|
case CONN_NOT_IMPLEMENTED_ERROR:
|
||||||
|
case STMT_NOT_IMPLEMENTED_ERROR:
|
||||||
|
strcpy(szSqlState, "S1C00");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
case CONN_VALUE_OUT_OF_RANGE:
|
||||||
strcpy(szSqlState, "S1000");
|
case STMT_VALUE_OUT_OF_RANGE:
|
||||||
/* general error */
|
strcpy(szSqlState, "22003");
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
default:
|
||||||
|
strcpy(szSqlState, "S1000");
|
||||||
|
/* general error */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
mylog("CC_Get_error returned nothing.\n");
|
mylog("CC_Get_error returned nothing.\n");
|
||||||
if (NULL != szSqlState)
|
if (NULL != szSqlState)
|
||||||
strcpy(szSqlState, "00000");
|
strcpy(szSqlState, "00000");
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != pcbErrorMsg)
|
||||||
*pcbErrorMsg = 0;
|
*pcbErrorMsg = 0;
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
szErrorMsg[0] = '\0';
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
|
|
||||||
} else if (SQL_NULL_HENV != henv) {
|
}
|
||||||
EnvironmentClass *env = (EnvironmentClass *)henv;
|
else if (SQL_NULL_HENV != henv)
|
||||||
if(EN_get_error(env, &status, &msg)) {
|
{
|
||||||
|
EnvironmentClass *env = (EnvironmentClass *) henv;
|
||||||
|
|
||||||
|
if (EN_get_error(env, &status, &msg))
|
||||||
|
{
|
||||||
mylog("EN_get_error: status = %d, msg = #%s#\n", 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 != szSqlState)
|
||||||
if (NULL != pcbErrorMsg)
|
strcpy(szSqlState, "00000");
|
||||||
*pcbErrorMsg = 0;
|
if (NULL != pcbErrorMsg)
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
*pcbErrorMsg = 0;
|
||||||
szErrorMsg[0] = '\0';
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != pcbErrorMsg)
|
||||||
*pcbErrorMsg = (SWORD)strlen(msg);
|
*pcbErrorMsg = (SWORD) strlen(msg);
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
||||||
if (NULL != pfNativeError)
|
if (NULL != pfNativeError)
|
||||||
*pfNativeError = status;
|
*pfNativeError = status;
|
||||||
|
|
||||||
if(szSqlState) {
|
if (szSqlState)
|
||||||
switch(status) {
|
{
|
||||||
case ENV_ALLOC_ERROR:
|
switch (status)
|
||||||
/* memory allocation failure */
|
{
|
||||||
strcpy(szSqlState, "S1001");
|
case ENV_ALLOC_ERROR:
|
||||||
break;
|
/* memory allocation failure */
|
||||||
default:
|
strcpy(szSqlState, "S1001");
|
||||||
strcpy(szSqlState, "S1000");
|
break;
|
||||||
/* general error */
|
default:
|
||||||
break;
|
strcpy(szSqlState, "S1000");
|
||||||
}
|
/* general error */
|
||||||
}
|
break;
|
||||||
} else {
|
}
|
||||||
if (NULL != szSqlState)
|
}
|
||||||
strcpy(szSqlState, "00000");
|
}
|
||||||
if (NULL != pcbErrorMsg)
|
else
|
||||||
*pcbErrorMsg = 0;
|
{
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if (NULL != szSqlState)
|
||||||
szErrorMsg[0] = '\0';
|
strcpy(szSqlState, "00000");
|
||||||
|
if (NULL != pcbErrorMsg)
|
||||||
|
*pcbErrorMsg = 0;
|
||||||
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != szSqlState)
|
if (NULL != szSqlState)
|
||||||
strcpy(szSqlState, "00000");
|
strcpy(szSqlState, "00000");
|
||||||
if (NULL != pcbErrorMsg)
|
if (NULL != pcbErrorMsg)
|
||||||
*pcbErrorMsg = 0;
|
*pcbErrorMsg = 0;
|
||||||
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
szErrorMsg[0] = '\0';
|
szErrorMsg[0] = '\0';
|
||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -382,25 +414,26 @@ int status;
|
|||||||
|
|
||||||
|
|
||||||
EnvironmentClass
|
EnvironmentClass
|
||||||
*EN_Constructor(void)
|
* EN_Constructor(void)
|
||||||
{
|
{
|
||||||
EnvironmentClass *rv;
|
EnvironmentClass *rv;
|
||||||
|
|
||||||
rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
|
rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
|
||||||
if( rv) {
|
if (rv)
|
||||||
|
{
|
||||||
rv->errormsg = 0;
|
rv->errormsg = 0;
|
||||||
rv->errornumber = 0;
|
rv->errornumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char
|
char
|
||||||
EN_Destructor(EnvironmentClass *self)
|
EN_Destructor(EnvironmentClass * self)
|
||||||
{
|
{
|
||||||
int lf;
|
int lf;
|
||||||
char rv = 1;
|
char rv = 1;
|
||||||
|
|
||||||
mylog("in EN_Destructor, self=%u\n", self);
|
mylog("in EN_Destructor, self=%u\n", self);
|
||||||
|
|
||||||
@ -408,7 +441,8 @@ char rv = 1;
|
|||||||
/* the source--they should not be freed */
|
/* the source--they should not be freed */
|
||||||
|
|
||||||
/* Free any connections belonging to this environment */
|
/* 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)
|
if (conns[lf] && conns[lf]->henv == self)
|
||||||
rv = rv && CC_Destructor(conns[lf]);
|
rv = rv && CC_Destructor(conns[lf]);
|
||||||
}
|
}
|
||||||
@ -418,28 +452,31 @@ char rv = 1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
char
|
char
|
||||||
EN_get_error(EnvironmentClass *self, int *number, char **message)
|
EN_get_error(EnvironmentClass * self, int *number, char **message)
|
||||||
{
|
{
|
||||||
if(self && self->errormsg && self->errornumber) {
|
if (self && self->errormsg && self->errornumber)
|
||||||
|
{
|
||||||
*message = self->errormsg;
|
*message = self->errormsg;
|
||||||
*number = self->errornumber;
|
*number = self->errornumber;
|
||||||
self->errormsg = 0;
|
self->errormsg = 0;
|
||||||
self->errornumber = 0;
|
self->errornumber = 0;
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char
|
char
|
||||||
EN_add_connection(EnvironmentClass *self, ConnectionClass *conn)
|
EN_add_connection(EnvironmentClass * self, ConnectionClass * conn)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
|
mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
|
||||||
|
|
||||||
for (i = 0; i < MAX_CONNECTIONS; i++) {
|
for (i = 0; i < MAX_CONNECTIONS; i++)
|
||||||
if ( ! conns[i]) {
|
{
|
||||||
|
if (!conns[i])
|
||||||
|
{
|
||||||
conn->henv = self;
|
conn->henv = self;
|
||||||
conns[i] = conn;
|
conns[i] = conn;
|
||||||
|
|
||||||
@ -453,12 +490,13 @@ mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
|
|||||||
}
|
}
|
||||||
|
|
||||||
char
|
char
|
||||||
EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
|
EN_remove_connection(EnvironmentClass * self, ConnectionClass * conn)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_CONNECTIONS; 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;
|
conns[i] = NULL;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -467,11 +505,10 @@ int i;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EN_log_error(char *func, char *desc, EnvironmentClass *self)
|
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);
|
qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
|
qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: environ.h
|
/* File: environ.h
|
||||||
*
|
*
|
||||||
* Description: See "environ.c"
|
* Description: See "environ.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -29,17 +29,18 @@
|
|||||||
#define ENV_ALLOC_ERROR 1
|
#define ENV_ALLOC_ERROR 1
|
||||||
|
|
||||||
/********** Environment Handle *************/
|
/********** Environment Handle *************/
|
||||||
struct EnvironmentClass_ {
|
struct EnvironmentClass_
|
||||||
char *errormsg;
|
{
|
||||||
int errornumber;
|
char *errormsg;
|
||||||
|
int errornumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Environment prototypes */
|
/* Environment prototypes */
|
||||||
EnvironmentClass *EN_Constructor(void);
|
EnvironmentClass *EN_Constructor(void);
|
||||||
char EN_Destructor(EnvironmentClass *self);
|
char EN_Destructor(EnvironmentClass * self);
|
||||||
char EN_get_error(EnvironmentClass *self, int *number, char **message);
|
char EN_get_error(EnvironmentClass * self, int *number, char **message);
|
||||||
char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn);
|
char EN_add_connection(EnvironmentClass * self, ConnectionClass * conn);
|
||||||
char EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn);
|
char EN_remove_connection(EnvironmentClass * self, ConnectionClass * conn);
|
||||||
void EN_log_error(char *func, char *desc, EnvironmentClass *self);
|
void EN_log_error(char *func, char *desc, EnvironmentClass * self);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/* Module: execute.c
|
/* Module: execute.c
|
||||||
*
|
*
|
||||||
* Description: This module contains routines related to
|
* Description: This module contains routines related to
|
||||||
* preparing and executing an SQL statement.
|
* preparing and executing an SQL statement.
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: SQLPrepare, SQLExecute, SQLExecDirect, SQLTransact,
|
* API functions: SQLPrepare, SQLExecute, SQLExecDirect, SQLTransact,
|
||||||
* SQLCancel, SQLNativeSql, SQLParamData, SQLPutData
|
* SQLCancel, SQLNativeSql, SQLParamData, SQLPutData
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -38,66 +38,74 @@
|
|||||||
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 SQLPrepare(HSTMT hstmt,
|
RETCODE SQL_API
|
||||||
UCHAR FAR *szSqlStr,
|
SQLPrepare(HSTMT hstmt,
|
||||||
SDWORD cbSqlStr)
|
UCHAR FAR * szSqlStr,
|
||||||
|
SDWORD cbSqlStr)
|
||||||
{
|
{
|
||||||
static char *func = "SQLPrepare";
|
static char *func = "SQLPrepare";
|
||||||
StatementClass *self = (StatementClass *) hstmt;
|
StatementClass *self = (StatementClass *) hstmt;
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! self) {
|
if (!self)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
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");
|
case STMT_PREMATURE:
|
||||||
SC_recycle_statement(self); /* recycle the statement, but do not remove parameter bindings */
|
mylog("**** SQLPrepare: STMT_PREMATURE, recycle\n");
|
||||||
break;
|
SC_recycle_statement(self); /* recycle the statement, but do
|
||||||
|
* not remove parameter bindings */
|
||||||
|
break;
|
||||||
|
|
||||||
case STMT_FINISHED:
|
case STMT_FINISHED:
|
||||||
mylog("**** SQLPrepare: STMT_FINISHED, recycle\n");
|
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
|
||||||
break;
|
* not remove parameter bindings */
|
||||||
|
break;
|
||||||
|
|
||||||
case STMT_ALLOCATED:
|
case STMT_ALLOCATED:
|
||||||
mylog("**** SQLPrepare: STMT_ALLOCATED, copy\n");
|
mylog("**** SQLPrepare: 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("**** SQLPrepare: STMT_READY, change SQL\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STMT_EXECUTING:
|
case STMT_EXECUTING:
|
||||||
mylog("**** SQLPrepare: STMT_EXECUTING, error!\n");
|
mylog("**** SQLPrepare: 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 = "SQLPrepare(): 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;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
self->errornumber = STMT_INTERNAL_ERROR;
|
self->errornumber = STMT_INTERNAL_ERROR;
|
||||||
self->errormsg = "An Internal Error has occured -- Unknown statement status.";
|
self->errormsg = "An Internal Error has occured -- Unknown statement status.";
|
||||||
SC_log_error(func, "", self);
|
SC_log_error(func, "", self);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->statement)
|
if (self->statement)
|
||||||
free(self->statement);
|
free(self->statement);
|
||||||
|
|
||||||
self->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
self->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
||||||
if ( ! self->statement) {
|
if (!self->statement)
|
||||||
|
{
|
||||||
self->errornumber = STMT_NO_MEMORY_ERROR;
|
self->errornumber = STMT_NO_MEMORY_ERROR;
|
||||||
self->errormsg = "No memory available to store statement";
|
self->errormsg = "No memory available to store statement";
|
||||||
SC_log_error(func, "", self);
|
SC_log_error(func, "", self);
|
||||||
@ -107,8 +115,9 @@ StatementClass *self = (StatementClass *) hstmt;
|
|||||||
self->prepare = TRUE;
|
self->prepare = TRUE;
|
||||||
self->statement_type = statement_type(self->statement);
|
self->statement_type = statement_type(self->statement);
|
||||||
|
|
||||||
/* Check if connection is onlyread (only selects are allowed) */
|
/* 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->errornumber = STMT_EXEC_ERROR;
|
||||||
self->errormsg = "Connection is readonly, only select statements are allowed.";
|
self->errormsg = "Connection is readonly, only select statements are allowed.";
|
||||||
SC_log_error(func, "", self);
|
SC_log_error(func, "", self);
|
||||||
@ -120,22 +129,24 @@ StatementClass *self = (StatementClass *) hstmt;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Performs the equivalent of SQLPrepare, followed by SQLExecute. */
|
/* Performs the equivalent of SQLPrepare, followed by SQLExecute. */
|
||||||
|
|
||||||
RETCODE SQL_API SQLExecDirect(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLExecDirect(
|
||||||
UCHAR FAR *szSqlStr,
|
HSTMT hstmt,
|
||||||
SDWORD cbSqlStr)
|
UCHAR FAR * szSqlStr,
|
||||||
|
SDWORD cbSqlStr)
|
||||||
{
|
{
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
RETCODE result;
|
RETCODE result;
|
||||||
static char *func = "SQLExecDirect";
|
static char *func = "SQLExecDirect";
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
@ -146,7 +157,8 @@ static char *func = "SQLExecDirect";
|
|||||||
/* keep a copy of the un-parametrized statement, in case */
|
/* keep a copy of the un-parametrized statement, in case */
|
||||||
/* they try to execute this statement again */
|
/* they try to execute this statement again */
|
||||||
stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
|
||||||
if ( ! stmt->statement) {
|
if (!stmt->statement)
|
||||||
|
{
|
||||||
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
stmt->errornumber = STMT_NO_MEMORY_ERROR;
|
||||||
stmt->errormsg = "No memory available to store statement";
|
stmt->errormsg = "No memory available to store statement";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -160,13 +172,14 @@ static char *func = "SQLExecDirect";
|
|||||||
/* If an SQLPrepare was performed prior to this, but was left in */
|
/* If an SQLPrepare was performed prior to this, but was left in */
|
||||||
/* the premature state because an error occurred prior to SQLExecute */
|
/* the premature state because an error occurred prior to SQLExecute */
|
||||||
/* then set the statement to finished so it can be recycled. */
|
/* then set the statement to finished so it can be recycled. */
|
||||||
if ( stmt->status == STMT_PREMATURE )
|
if (stmt->status == STMT_PREMATURE)
|
||||||
stmt->status = STMT_FINISHED;
|
stmt->status = STMT_FINISHED;
|
||||||
|
|
||||||
stmt->statement_type = statement_type(stmt->statement);
|
stmt->statement_type = statement_type(stmt->statement);
|
||||||
|
|
||||||
/* Check if connection is onlyread (only selects are allowed) */
|
/* 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->errornumber = STMT_EXEC_ERROR;
|
||||||
stmt->errormsg = "Connection is readonly, only select statements are allowed.";
|
stmt->errormsg = "Connection is readonly, only select statements are allowed.";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -181,35 +194,42 @@ static char *func = "SQLExecDirect";
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute a prepared SQL statement */
|
/* Execute a prepared SQL statement */
|
||||||
RETCODE SQL_API SQLExecute(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt)
|
SQLExecute(
|
||||||
|
HSTMT hstmt)
|
||||||
{
|
{
|
||||||
static char *func="SQLExecute";
|
static char *func = "SQLExecute";
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
ConnectionClass *conn;
|
ConnectionClass *conn;
|
||||||
int i, retval;
|
int i,
|
||||||
|
retval;
|
||||||
|
|
||||||
|
|
||||||
mylog("%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
mylog("%s: NULL statement so return SQL_INVALID_HANDLE\n", func);
|
mylog("%s: NULL statement so return SQL_INVALID_HANDLE\n", func);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the statement is premature, it means we already executed
|
/*
|
||||||
it from an SQLPrepare/SQLDescribeCol type of scenario. So
|
* If the statement is premature, it means we already executed it from
|
||||||
just return success.
|
* 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;
|
stmt->status = STMT_FINISHED;
|
||||||
if (stmt->errormsg == NULL) {
|
if (stmt->errormsg == NULL)
|
||||||
|
{
|
||||||
mylog("%s: premature statement but return SQL_SUCCESS\n", func);
|
mylog("%s: premature statement but return SQL_SUCCESS\n", func);
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
mylog("%s: premature statement so return SQL_ERROR\n", func);
|
mylog("%s: premature statement so return SQL_ERROR\n", func);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
@ -221,7 +241,8 @@ int i, retval;
|
|||||||
SC_clear_error(stmt);
|
SC_clear_error(stmt);
|
||||||
|
|
||||||
conn = SC_get_conn(stmt);
|
conn = SC_get_conn(stmt);
|
||||||
if (conn->status == CONN_EXECUTING) {
|
if (conn->status == CONN_EXECUTING)
|
||||||
|
{
|
||||||
stmt->errormsg = "Connection is already in use.";
|
stmt->errormsg = "Connection is already in use.";
|
||||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -229,7 +250,8 @@ int i, retval;
|
|||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! stmt->statement) {
|
if (!stmt->statement)
|
||||||
|
{
|
||||||
stmt->errornumber = STMT_NO_STMTSTRING;
|
stmt->errornumber = STMT_NO_STMTSTRING;
|
||||||
stmt->errormsg = "This handle does not have a SQL statement stored in it";
|
stmt->errormsg = "This handle does not have a SQL statement stored in it";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -237,18 +259,21 @@ int i, retval;
|
|||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If SQLExecute is being called again, recycle the statement.
|
/*
|
||||||
Note this should have been done by the application in a call
|
* If SQLExecute is being called again, recycle the statement. Note
|
||||||
to SQLFreeStmt(SQL_CLOSE) or SQLCancel.
|
* 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);
|
mylog("%s: recycling statement (should have been done by app)...\n", func);
|
||||||
SC_recycle_statement(stmt);
|
SC_recycle_statement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the statement is in the correct state */
|
/* Check if the statement is in the correct state */
|
||||||
if ((stmt->prepare && stmt->status != STMT_READY) ||
|
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->errornumber = STMT_STATUS_ERROR;
|
||||||
stmt->errormsg = "The handle does not point to a statement that is ready to be executed";
|
stmt->errormsg = "The handle does not point to a statement that is ready to be executed";
|
||||||
@ -258,30 +283,37 @@ 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;
|
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) {
|
/* Check for data at execution parameters */
|
||||||
|
if (stmt->parameters[i].data_at_exec == TRUE)
|
||||||
|
{
|
||||||
if (stmt->data_at_exec < 0)
|
if (stmt->data_at_exec < 0)
|
||||||
stmt->data_at_exec = 1;
|
stmt->data_at_exec = 1;
|
||||||
else
|
else
|
||||||
stmt->data_at_exec++;
|
stmt->data_at_exec++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If there are some data at execution parameters, return need data */
|
/* 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)
|
if (stmt->data_at_exec > 0)
|
||||||
return SQL_NEED_DATA;
|
return SQL_NEED_DATA;
|
||||||
|
|
||||||
|
|
||||||
mylog("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n", func, conn->transact_status, strlen(stmt->statement), stmt->statement);
|
mylog("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n", func, conn->transact_status, strlen(stmt->statement), stmt->statement);
|
||||||
|
|
||||||
/* Create the statement with parameters substituted. */
|
/* Create the statement with parameters substituted. */
|
||||||
retval = copy_statement_with_parameters(stmt);
|
retval = copy_statement_with_parameters(stmt);
|
||||||
if( retval != SQL_SUCCESS)
|
if (retval != SQL_SUCCESS)
|
||||||
/* error msg passed from above */
|
/* error msg passed from above */
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
@ -295,35 +327,41 @@ int i, retval;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
RETCODE SQL_API SQLTransact(
|
RETCODE SQL_API
|
||||||
HENV henv,
|
SQLTransact(
|
||||||
HDBC hdbc,
|
HENV henv,
|
||||||
UWORD fType)
|
HDBC hdbc,
|
||||||
|
UWORD fType)
|
||||||
{
|
{
|
||||||
static char *func = "SQLTransact";
|
static char *func = "SQLTransact";
|
||||||
extern ConnectionClass *conns[];
|
extern ConnectionClass *conns[];
|
||||||
ConnectionClass *conn;
|
ConnectionClass *conn;
|
||||||
QResultClass *res;
|
QResultClass *res;
|
||||||
char ok, *stmt_string;
|
char ok,
|
||||||
int lf;
|
*stmt_string;
|
||||||
|
int lf;
|
||||||
|
|
||||||
mylog("entering %s: hdbc=%u, henv=%u\n", func, hdbc, henv);
|
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);
|
CC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
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];
|
conn = conns[lf];
|
||||||
|
|
||||||
if (conn && conn->henv == henv)
|
if (conn && conn->henv == henv)
|
||||||
if ( SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
|
if (SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -332,29 +370,36 @@ int lf;
|
|||||||
|
|
||||||
conn = (ConnectionClass *) hdbc;
|
conn = (ConnectionClass *) hdbc;
|
||||||
|
|
||||||
if (fType == SQL_COMMIT) {
|
if (fType == SQL_COMMIT)
|
||||||
|
{
|
||||||
stmt_string = "COMMIT";
|
stmt_string = "COMMIT";
|
||||||
|
|
||||||
} else if (fType == SQL_ROLLBACK) {
|
}
|
||||||
|
else if (fType == SQL_ROLLBACK)
|
||||||
|
{
|
||||||
stmt_string = "ROLLBACK";
|
stmt_string = "ROLLBACK";
|
||||||
|
|
||||||
} 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 = "SQLTransact 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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("SQLTransact: 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);
|
||||||
|
|
||||||
if ( ! res) {
|
if (!res)
|
||||||
/* error msg will be in the connection */
|
{
|
||||||
|
/* error msg will be in the connection */
|
||||||
CC_log_error(func, "", conn);
|
CC_log_error(func, "", conn);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
@ -362,7 +407,8 @@ int lf;
|
|||||||
ok = QR_command_successful(res);
|
ok = QR_command_successful(res);
|
||||||
QR_Destructor(res);
|
QR_Destructor(res);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
|
{
|
||||||
CC_log_error(func, "", conn);
|
CC_log_error(func, "", conn);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
@ -370,50 +416,59 @@ int lf;
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
RETCODE SQL_API SQLCancel(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt) /* Statement to cancel. */
|
SQLCancel(
|
||||||
|
HSTMT hstmt) /* Statement to cancel. */
|
||||||
{
|
{
|
||||||
static char *func="SQLCancel";
|
static char *func = "SQLCancel";
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
RETCODE result;
|
RETCODE result;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HMODULE hmodule;
|
HMODULE hmodule;
|
||||||
FARPROC addr;
|
FARPROC addr;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
/* Check if this can handle canceling in the middle of a SQLPutData? */
|
/* Check if this can handle canceling in the middle of a SQLPutData? */
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
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,
|
* MAJOR HACK for Windows to reset the driver manager's cursor
|
||||||
SQLCancel does not act like a SQLFreeStmt(CLOSE), as many
|
* state: Because of what seems like a bug in the Odbc driver
|
||||||
applications depend on this behavior. So, this
|
* manager, SQLCancel does not act like a SQLFreeStmt(CLOSE), as
|
||||||
brute force method calls the driver manager's function on
|
* many applications depend on this behavior. So, this brute
|
||||||
behalf of the application.
|
* force method calls the driver manager's function on behalf of
|
||||||
*/
|
* the application.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (globals.cancel_as_freestmt) {
|
if (globals.cancel_as_freestmt)
|
||||||
|
{
|
||||||
hmodule = GetModuleHandle("ODBC32");
|
hmodule = GetModuleHandle("ODBC32");
|
||||||
addr = GetProcAddress(hmodule, "SQLFreeStmt");
|
addr = GetProcAddress(hmodule, "SQLFreeStmt");
|
||||||
result = addr( (char *) (stmt->phstmt) - 96, SQL_CLOSE);
|
result = addr((char *) (stmt->phstmt) - 96, SQL_CLOSE);
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = SQLFreeStmt( hstmt, SQL_CLOSE);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
result = SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
#else
|
#else
|
||||||
result = SQLFreeStmt( hstmt, SQL_CLOSE);
|
result = SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mylog("SQLCancel: SQLFreeStmt returned %d\n", result);
|
mylog("SQLCancel: SQLFreeStmt returned %d\n", result);
|
||||||
@ -422,9 +477,13 @@ FARPROC addr;
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In the middle of SQLParamData/SQLPutData, so cancel that. */
|
/* In the middle of SQLParamData/SQLPutData, so cancel that. */
|
||||||
/* Note, any previous data-at-exec buffers will be freed in the recycle */
|
|
||||||
/* if they call SQLExecDirect or SQLExecute again. */
|
/*
|
||||||
|
* 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;
|
stmt->data_at_exec = -1;
|
||||||
stmt->current_exec_param = -1;
|
stmt->current_exec_param = -1;
|
||||||
@ -434,29 +493,31 @@ FARPROC addr;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Returns the SQL string as modified by the driver. */
|
/* Returns the SQL string as modified by the driver. */
|
||||||
/* Currently, just copy the input string without modification */
|
/* Currently, just copy the input string without modification */
|
||||||
/* observing buffer limits and truncation. */
|
/* observing buffer limits and truncation. */
|
||||||
RETCODE SQL_API SQLNativeSql(
|
RETCODE SQL_API
|
||||||
HDBC hdbc,
|
SQLNativeSql(
|
||||||
UCHAR FAR *szSqlStrIn,
|
HDBC hdbc,
|
||||||
SDWORD cbSqlStrIn,
|
UCHAR FAR * szSqlStrIn,
|
||||||
UCHAR FAR *szSqlStr,
|
SDWORD cbSqlStrIn,
|
||||||
SDWORD cbSqlStrMax,
|
UCHAR FAR * szSqlStr,
|
||||||
SDWORD FAR *pcbSqlStr)
|
SDWORD cbSqlStrMax,
|
||||||
|
SDWORD FAR * pcbSqlStr)
|
||||||
{
|
{
|
||||||
static char *func="SQLNativeSql";
|
static char *func = "SQLNativeSql";
|
||||||
int len = 0;
|
int len = 0;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
ConnectionClass *conn = (ConnectionClass *) hdbc;
|
||||||
RETCODE result;
|
RETCODE result;
|
||||||
|
|
||||||
mylog( "%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
|
mylog("%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
|
||||||
|
|
||||||
ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL);
|
ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL);
|
||||||
if ( ! ptr) {
|
if (!ptr)
|
||||||
|
{
|
||||||
conn->errornumber = CONN_NO_MEMORY_ERROR;
|
conn->errornumber = CONN_NO_MEMORY_ERROR;
|
||||||
conn->errormsg = "No memory available to store native sql string";
|
conn->errormsg = "No memory available to store native sql string";
|
||||||
CC_log_error(func, "", conn);
|
CC_log_error(func, "", conn);
|
||||||
@ -466,10 +527,12 @@ RETCODE result;
|
|||||||
result = SQL_SUCCESS;
|
result = SQL_SUCCESS;
|
||||||
len = strlen(ptr);
|
len = strlen(ptr);
|
||||||
|
|
||||||
if (szSqlStr) {
|
if (szSqlStr)
|
||||||
|
{
|
||||||
strncpy_null(szSqlStr, ptr, cbSqlStrMax);
|
strncpy_null(szSqlStr, ptr, cbSqlStrMax);
|
||||||
|
|
||||||
if (len >= cbSqlStrMax) {
|
if (len >= cbSqlStrMax)
|
||||||
|
{
|
||||||
result = SQL_SUCCESS_WITH_INFO;
|
result = SQL_SUCCESS_WITH_INFO;
|
||||||
conn->errornumber = STMT_TRUNCATED;
|
conn->errornumber = STMT_TRUNCATED;
|
||||||
conn->errormsg = "The buffer was too small for the result.";
|
conn->errormsg = "The buffer was too small for the result.";
|
||||||
@ -481,39 +544,44 @@ RETCODE result;
|
|||||||
|
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Supplies parameter data at execution time. Used in conjuction with */
|
/* Supplies parameter data at execution time. Used in conjuction with */
|
||||||
/* SQLPutData. */
|
/* SQLPutData. */
|
||||||
|
|
||||||
RETCODE SQL_API SQLParamData(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLParamData(
|
||||||
PTR FAR *prgbValue)
|
HSTMT hstmt,
|
||||||
|
PTR FAR * prgbValue)
|
||||||
{
|
{
|
||||||
static char *func = "SQLParamData";
|
static char *func = "SQLParamData";
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
int i, retval;
|
int i,
|
||||||
|
retval;
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mylog("%s: data_at_exec=%d, params_alloc=%d\n", func, stmt->data_at_exec, stmt->parameters_allocated);
|
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->errornumber = STMT_SEQUENCE_ERROR;
|
||||||
stmt->errormsg = "No execution-time parameters for this statement";
|
stmt->errormsg = "No execution-time parameters for this statement";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
return SQL_ERROR;
|
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->errornumber = STMT_SEQUENCE_ERROR;
|
||||||
stmt->errormsg = "Too many execution-time parameters were present";
|
stmt->errormsg = "Too many execution-time parameters were present";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -521,16 +589,19 @@ int i, retval;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* close the large object */
|
/* close the large object */
|
||||||
if ( stmt->lobj_fd >= 0) {
|
if (stmt->lobj_fd >= 0)
|
||||||
|
{
|
||||||
lo_close(stmt->hdbc, stmt->lobj_fd);
|
lo_close(stmt->hdbc, stmt->lobj_fd);
|
||||||
|
|
||||||
/* commit transaction if needed */
|
/* 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;
|
QResultClass *res;
|
||||||
char ok;
|
char ok;
|
||||||
|
|
||||||
res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
|
res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
|
||||||
if (!res) {
|
if (!res)
|
||||||
|
{
|
||||||
stmt->errormsg = "Could not commit (in-line) a transaction";
|
stmt->errormsg = "Could not commit (in-line) a transaction";
|
||||||
stmt->errornumber = STMT_EXEC_ERROR;
|
stmt->errornumber = STMT_EXEC_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -538,7 +609,8 @@ int i, retval;
|
|||||||
}
|
}
|
||||||
ok = QR_command_successful(res);
|
ok = QR_command_successful(res);
|
||||||
QR_Destructor(res);
|
QR_Destructor(res);
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
|
{
|
||||||
stmt->errormsg = "Could not commit (in-line) a transaction";
|
stmt->errormsg = "Could not commit (in-line) a transaction";
|
||||||
stmt->errornumber = STMT_EXEC_ERROR;
|
stmt->errornumber = STMT_EXEC_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -552,8 +624,9 @@ int i, retval;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Done, now copy the params and then execute the statement */
|
/* 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);
|
retval = copy_statement_with_parameters(stmt);
|
||||||
if (retval != SQL_SUCCESS)
|
if (retval != SQL_SUCCESS)
|
||||||
return retval;
|
return retval;
|
||||||
@ -563,14 +636,17 @@ int i, retval;
|
|||||||
return SC_execute(stmt);
|
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;
|
*/
|
||||||
|
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 */
|
/* At least 1 data at execution parameter, so Fill in the token value */
|
||||||
for ( ; i < stmt->parameters_allocated; i++) {
|
for (; i < stmt->parameters_allocated; i++)
|
||||||
if (stmt->parameters[i].data_at_exec == TRUE) {
|
{
|
||||||
|
if (stmt->parameters[i].data_at_exec == TRUE)
|
||||||
|
{
|
||||||
stmt->data_at_exec--;
|
stmt->data_at_exec--;
|
||||||
stmt->current_exec_param = i;
|
stmt->current_exec_param = i;
|
||||||
stmt->put_data = FALSE;
|
stmt->put_data = FALSE;
|
||||||
@ -582,31 +658,35 @@ int i, retval;
|
|||||||
return SQL_NEED_DATA;
|
return SQL_NEED_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - */
|
/* - - - - - - - - - */
|
||||||
|
|
||||||
/* Supplies parameter data at execution time. Used in conjunction with */
|
/* Supplies parameter data at execution time. Used in conjunction with */
|
||||||
/* SQLParamData. */
|
/* SQLParamData. */
|
||||||
|
|
||||||
RETCODE SQL_API SQLPutData(
|
RETCODE SQL_API
|
||||||
HSTMT hstmt,
|
SQLPutData(
|
||||||
PTR rgbValue,
|
HSTMT hstmt,
|
||||||
SDWORD cbValue)
|
PTR rgbValue,
|
||||||
|
SDWORD cbValue)
|
||||||
{
|
{
|
||||||
static char *func = "SQLPutData";
|
static char *func = "SQLPutData";
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
int old_pos, retval;
|
int old_pos,
|
||||||
ParameterInfoClass *current_param;
|
retval;
|
||||||
char *buffer;
|
ParameterInfoClass *current_param;
|
||||||
|
char *buffer;
|
||||||
|
|
||||||
mylog( "%s: entering...\n", func);
|
mylog("%s: entering...\n", func);
|
||||||
|
|
||||||
if ( ! stmt) {
|
if (!stmt)
|
||||||
|
{
|
||||||
SC_log_error(func, "", NULL);
|
SC_log_error(func, "", NULL);
|
||||||
return SQL_INVALID_HANDLE;
|
return SQL_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (stmt->current_exec_param < 0) {
|
if (stmt->current_exec_param < 0)
|
||||||
|
{
|
||||||
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
stmt->errornumber = STMT_SEQUENCE_ERROR;
|
||||||
stmt->errormsg = "Previous call was not SQLPutData or SQLParamData";
|
stmt->errormsg = "Previous call was not SQLPutData or SQLParamData";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -615,14 +695,16 @@ char *buffer;
|
|||||||
|
|
||||||
current_param = &(stmt->parameters[stmt->current_exec_param]);
|
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);
|
mylog("SQLPutData: (1) cbValue = %d\n", cbValue);
|
||||||
|
|
||||||
stmt->put_data = TRUE;
|
stmt->put_data = TRUE;
|
||||||
|
|
||||||
current_param->EXEC_used = (SDWORD *) malloc(sizeof(SDWORD));
|
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->errornumber = STMT_NO_MEMORY_ERROR;
|
||||||
stmt->errormsg = "Out of memory in SQLPutData (1)";
|
stmt->errormsg = "Out of memory in SQLPutData (1)";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -635,16 +717,19 @@ char *buffer;
|
|||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
|
|
||||||
|
|
||||||
/* Handle Long Var Binary with Large Objects */
|
/* Handle Long Var Binary with Large Objects */
|
||||||
if ( current_param->SQLType == SQL_LONGVARBINARY) {
|
if (current_param->SQLType == SQL_LONGVARBINARY)
|
||||||
|
{
|
||||||
|
|
||||||
/* begin transaction if needed */
|
/* begin transaction if needed */
|
||||||
if(!CC_is_in_trans(stmt->hdbc)) {
|
if (!CC_is_in_trans(stmt->hdbc))
|
||||||
|
{
|
||||||
QResultClass *res;
|
QResultClass *res;
|
||||||
char ok;
|
char ok;
|
||||||
|
|
||||||
res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
|
res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
|
||||||
if (!res) {
|
if (!res)
|
||||||
|
{
|
||||||
stmt->errormsg = "Could not begin (in-line) a transaction";
|
stmt->errormsg = "Could not begin (in-line) a transaction";
|
||||||
stmt->errornumber = STMT_EXEC_ERROR;
|
stmt->errornumber = STMT_EXEC_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -652,7 +737,8 @@ char *buffer;
|
|||||||
}
|
}
|
||||||
ok = QR_command_successful(res);
|
ok = QR_command_successful(res);
|
||||||
QR_Destructor(res);
|
QR_Destructor(res);
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
|
{
|
||||||
stmt->errormsg = "Could not begin (in-line) a transaction";
|
stmt->errormsg = "Could not begin (in-line) a transaction";
|
||||||
stmt->errornumber = STMT_EXEC_ERROR;
|
stmt->errornumber = STMT_EXEC_ERROR;
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -662,22 +748,24 @@ char *buffer;
|
|||||||
CC_set_in_trans(stmt->hdbc);
|
CC_set_in_trans(stmt->hdbc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store the oid */
|
/* store the oid */
|
||||||
current_param->lobj_oid = lo_creat(stmt->hdbc, INV_READ | INV_WRITE);
|
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->errornumber = STMT_EXEC_ERROR;
|
||||||
stmt->errormsg = "Couldnt create large object.";
|
stmt->errormsg = "Couldnt create large object.";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* major hack -- to allow convert to see somethings there */
|
/* major hack -- to allow convert to see somethings there */
|
||||||
/* have to modify convert to handle this better */
|
/* have to modify convert to handle this better */
|
||||||
current_param->EXEC_buffer = (char *) ¤t_param->lobj_oid;
|
current_param->EXEC_buffer = (char *) ¤t_param->lobj_oid;
|
||||||
|
|
||||||
/* store the fd */
|
/* store the fd */
|
||||||
stmt->lobj_fd = lo_open(stmt->hdbc, current_param->lobj_oid, INV_WRITE);
|
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->errornumber = STMT_EXEC_ERROR;
|
||||||
stmt->errormsg = "Couldnt open large object for writing.";
|
stmt->errormsg = "Couldnt open large object for writing.";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -688,20 +776,26 @@ char *buffer;
|
|||||||
mylog("lo_write: cbValue=%d, wrote %d bytes\n", cbValue, retval);
|
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);
|
current_param->EXEC_buffer = strdup(rgbValue);
|
||||||
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 SQLPutData (2)";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
current_param->EXEC_buffer = malloc(cbValue + 1);
|
current_param->EXEC_buffer = malloc(cbValue + 1);
|
||||||
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 SQLPutData (2)";
|
||||||
SC_log_error(func, "", stmt);
|
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);
|
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 */
|
/* the large object fd is in EXEC_buffer */
|
||||||
retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
|
retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
|
||||||
@ -725,13 +821,17 @@ char *buffer;
|
|||||||
|
|
||||||
*current_param->EXEC_used += cbValue;
|
*current_param->EXEC_used += cbValue;
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
buffer = current_param->EXEC_buffer;
|
buffer = current_param->EXEC_buffer;
|
||||||
|
|
||||||
if (cbValue == SQL_NTS) {
|
if (cbValue == SQL_NTS)
|
||||||
|
{
|
||||||
buffer = realloc(buffer, strlen(buffer) + strlen(rgbValue) + 1);
|
buffer = realloc(buffer, strlen(buffer) + strlen(rgbValue) + 1);
|
||||||
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 SQLPutData (3)";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -743,11 +843,12 @@ char *buffer;
|
|||||||
|
|
||||||
*current_param->EXEC_used = cbValue;
|
*current_param->EXEC_used = cbValue;
|
||||||
|
|
||||||
/* reassign buffer incase realloc moved it */
|
/* reassign buffer incase realloc moved it */
|
||||||
current_param->EXEC_buffer = buffer;
|
current_param->EXEC_buffer = buffer;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (cbValue > 0) {
|
else if (cbValue > 0)
|
||||||
|
{
|
||||||
|
|
||||||
old_pos = *current_param->EXEC_used;
|
old_pos = *current_param->EXEC_used;
|
||||||
|
|
||||||
@ -757,7 +858,8 @@ char *buffer;
|
|||||||
|
|
||||||
/* dont lose the old pointer in case out of memory */
|
/* dont lose the old pointer in case out of memory */
|
||||||
buffer = realloc(current_param->EXEC_buffer, *current_param->EXEC_used + 1);
|
buffer = realloc(current_param->EXEC_buffer, *current_param->EXEC_used + 1);
|
||||||
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 SQLPutData (3)";
|
||||||
SC_log_error(func, "", stmt);
|
SC_log_error(func, "", stmt);
|
||||||
@ -767,11 +869,12 @@ char *buffer;
|
|||||||
memcpy(&buffer[old_pos], rgbValue, cbValue);
|
memcpy(&buffer[old_pos], rgbValue, cbValue);
|
||||||
buffer[*current_param->EXEC_used] = '\0';
|
buffer[*current_param->EXEC_used] = '\0';
|
||||||
|
|
||||||
/* reassign buffer incase realloc moved it */
|
/* reassign buffer incase realloc moved it */
|
||||||
current_param->EXEC_buffer = buffer;
|
current_param->EXEC_buffer = buffer;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
SC_log_error(func, "bad cbValue", stmt);
|
SC_log_error(func, "bad cbValue", stmt);
|
||||||
return SQL_ERROR;
|
return SQL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
#if HAVE_CONFIG_H
|
||||||
#include "config.h" /* produced by configure */
|
#include "config.h" /* produced by configure */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -38,83 +38,87 @@
|
|||||||
|
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
GetPrivateProfileString(char *theSection, /* section name */
|
GetPrivateProfileString(char *theSection, /* section name */
|
||||||
char *theKey, /* search key name */
|
char *theKey, /* search key name */
|
||||||
char *theDefault, /* default value if not found */
|
char *theDefault, /* default value if not
|
||||||
char *theReturnBuffer, /* return value stored here */
|
* found */
|
||||||
size_t theReturnBufferLength, /* byte length of return buffer */
|
char *theReturnBuffer, /* return value stored
|
||||||
char *theIniFileName) /* pathname of ini file to search */
|
* here */
|
||||||
|
size_t theReturnBufferLength, /* byte length of return
|
||||||
|
* buffer */
|
||||||
|
char *theIniFileName) /* pathname of ini file to
|
||||||
|
* search */
|
||||||
{
|
{
|
||||||
char buf[MAXPGPATH];
|
char buf[MAXPGPATH];
|
||||||
char* ptr = 0;
|
char *ptr = 0;
|
||||||
FILE* aFile = 0;
|
FILE *aFile = 0;
|
||||||
size_t aLength;
|
size_t aLength;
|
||||||
char aLine[2048];
|
char aLine[2048];
|
||||||
char *aValue;
|
char *aValue;
|
||||||
char *aStart;
|
char *aStart;
|
||||||
char *aString;
|
char *aString;
|
||||||
size_t aLineLength;
|
size_t aLineLength;
|
||||||
size_t aReturnLength = 0;
|
size_t aReturnLength = 0;
|
||||||
|
|
||||||
BOOL aSectionFound = FALSE;
|
BOOL aSectionFound = FALSE;
|
||||||
BOOL aKeyFound = FALSE;
|
BOOL aKeyFound = FALSE;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
j = strlen(theIniFileName) + 1;
|
j = strlen(theIniFileName) + 1;
|
||||||
ptr = (char*)getpwuid(getuid()); /* get user info */
|
ptr = (char *) getpwuid(getuid()); /* get user info */
|
||||||
|
|
||||||
if( ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
if( MAXPGPATH-1 < j )
|
if (MAXPGPATH - 1 < j)
|
||||||
theIniFileName[MAXPGPATH-1] = '\0';
|
theIniFileName[MAXPGPATH - 1] = '\0';
|
||||||
|
|
||||||
sprintf(buf,"%s",theIniFileName);
|
sprintf(buf, "%s", theIniFileName);
|
||||||
}
|
}
|
||||||
ptr = ((struct passwd*)ptr)->pw_dir; /* get user home dir */
|
ptr = ((struct passwd *) ptr)->pw_dir; /* get user home dir */
|
||||||
if( ptr == NULL || *ptr == '\0' )
|
if (ptr == NULL || *ptr == '\0')
|
||||||
ptr = "/home";
|
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
|
* This doesn't make it so we find an ini file but allows normal
|
||||||
* the file won't be found and thus the default value will be
|
* processing to continue further on down. The likelihood is that the
|
||||||
* returned.
|
* file won't be found and thus the default value will be returned.
|
||||||
*/
|
*/
|
||||||
if( MAXPGPATH-1 < strlen(ptr) + j )
|
if (MAXPGPATH - 1 < strlen(ptr) + j)
|
||||||
{
|
{
|
||||||
if( MAXPGPATH-1 < strlen(ptr) )
|
if (MAXPGPATH - 1 < strlen(ptr))
|
||||||
ptr[MAXPGPATH-1] = '\0';
|
ptr[MAXPGPATH - 1] = '\0';
|
||||||
else
|
else
|
||||||
theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
|
theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf( buf, "%s/%s",ptr,theIniFileName );
|
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) {
|
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
|
||||||
sprintf(buf,"%s",theIniFileName);
|
if (!aFile)
|
||||||
aFile = (FILE*)(buf ? fopen(buf, PG_BINARY_R) : NULL);
|
{
|
||||||
|
sprintf(buf, "%s", theIniFileName);
|
||||||
|
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
aLength = (theDefault == NULL) ? 0 : strlen(theDefault);
|
aLength = (theDefault == NULL) ? 0 : strlen(theDefault);
|
||||||
|
|
||||||
if(theReturnBufferLength == 0 || theReturnBuffer == NULL)
|
if (theReturnBufferLength == 0 || theReturnBuffer == NULL)
|
||||||
{
|
{
|
||||||
if(aFile)
|
if (aFile)
|
||||||
{
|
|
||||||
fclose(aFile);
|
fclose(aFile);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aFile == NULL)
|
if (aFile == NULL)
|
||||||
{
|
{
|
||||||
/* no ini file specified, return the default */
|
/* no ini file specified, return the default */
|
||||||
|
|
||||||
++aLength; /* room for NULL char */
|
++aLength; /* room for NULL char */
|
||||||
aLength = theReturnBufferLength < aLength ?
|
aLength = theReturnBufferLength < aLength ?
|
||||||
theReturnBufferLength : aLength;
|
theReturnBufferLength : aLength;
|
||||||
strncpy(theReturnBuffer, theDefault, aLength);
|
strncpy(theReturnBuffer, theDefault, aLength);
|
||||||
@ -123,86 +127,77 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while(fgets(aLine, sizeof(aLine), aFile) != NULL)
|
while (fgets(aLine, sizeof(aLine), aFile) != NULL)
|
||||||
{
|
{
|
||||||
aLineLength = strlen(aLine);
|
aLineLength = strlen(aLine);
|
||||||
/* strip final '\n' */
|
/* strip final '\n' */
|
||||||
if(aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
||||||
{
|
|
||||||
aLine[aLineLength - 1] = '\0';
|
aLine[aLineLength - 1] = '\0';
|
||||||
}
|
switch (*aLine)
|
||||||
switch(*aLine)
|
|
||||||
{
|
{
|
||||||
case ' ': /* blank line */
|
case ' ': /* blank line */
|
||||||
case ';': /* comment line */
|
case ';': /* comment line */
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': /* section marker */
|
case '[': /* section marker */
|
||||||
|
|
||||||
if( (aString = strchr(aLine, ']')) )
|
if ((aString = strchr(aLine, ']')))
|
||||||
{
|
{
|
||||||
aStart = aLine + 1;
|
aStart = aLine + 1;
|
||||||
aString--;
|
aString--;
|
||||||
while (isspace((unsigned char) *aStart)) aStart++;
|
while (isspace((unsigned char) *aStart))
|
||||||
while (isspace((unsigned char) *aString)) aString--;
|
aStart++;
|
||||||
*(aString+1) = '\0';
|
while (isspace((unsigned char) *aString))
|
||||||
|
aString--;
|
||||||
|
*(aString + 1) = '\0';
|
||||||
|
|
||||||
/* accept as matched if NULL key or exact match */
|
/* accept as matched if NULL key or exact match */
|
||||||
|
|
||||||
if(!theSection || !strcmp(aStart, theSection))
|
if (!theSection || !strcmp(aStart, theSection))
|
||||||
{
|
|
||||||
aSectionFound = TRUE;
|
aSectionFound = TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
/* try to match value keys if in proper section */
|
/* try to match value keys if in proper section */
|
||||||
|
|
||||||
if(aSectionFound)
|
if (aSectionFound)
|
||||||
{
|
{
|
||||||
/* try to match requested key */
|
/* try to match requested key */
|
||||||
|
|
||||||
if( (aString = aValue = strchr(aLine, '=')) )
|
if ((aString = aValue = strchr(aLine, '=')))
|
||||||
{
|
{
|
||||||
*aValue = '\0';
|
*aValue = '\0';
|
||||||
++aValue;
|
++aValue;
|
||||||
|
|
||||||
/* strip leading blanks in value field */
|
/* strip leading blanks in value field */
|
||||||
|
|
||||||
while(*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
||||||
{
|
|
||||||
*aValue++ = '\0';
|
*aValue++ = '\0';
|
||||||
}
|
if (aValue >= aLine + sizeof(aLine))
|
||||||
if(aValue >= aLine + sizeof(aLine))
|
|
||||||
{
|
|
||||||
aValue = "";
|
aValue = "";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
aValue = "";
|
aValue = "";
|
||||||
}
|
|
||||||
|
|
||||||
aStart = aLine;
|
aStart = aLine;
|
||||||
while (isspace((unsigned char) *aStart)) aStart++;
|
while (isspace((unsigned char) *aStart))
|
||||||
|
aStart++;
|
||||||
|
|
||||||
/* strip trailing blanks from key */
|
/* strip trailing blanks from key */
|
||||||
|
|
||||||
if(aString)
|
if (aString)
|
||||||
{
|
{
|
||||||
while(--aString >= aStart && *aString == ' ')
|
while (--aString >= aStart && *aString == ' ')
|
||||||
{
|
|
||||||
*aString = '\0';
|
*aString = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see if key is matched */
|
/* see if key is matched */
|
||||||
|
|
||||||
if(theKey == NULL || !strcmp(theKey, aStart))
|
if (theKey == NULL || !strcmp(theKey, aStart))
|
||||||
{
|
{
|
||||||
/* matched -- first, terminate value part */
|
/* matched -- first, terminate value part */
|
||||||
|
|
||||||
@ -213,7 +208,7 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
|
|
||||||
aString = aValue + aLength - 1;
|
aString = aValue + aLength - 1;
|
||||||
|
|
||||||
while(--aString > aValue && *aString == ' ')
|
while (--aString > aValue && *aString == ' ')
|
||||||
{
|
{
|
||||||
*aString = '\0';
|
*aString = '\0';
|
||||||
--aLength;
|
--aLength;
|
||||||
@ -221,7 +216,7 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
|
|
||||||
/* unquote value if quoted */
|
/* unquote value if quoted */
|
||||||
|
|
||||||
if(aLength >= 2 && aValue[0] == '"' &&
|
if (aLength >= 2 && aValue[0] == '"' &&
|
||||||
aValue[aLength - 1] == '"')
|
aValue[aLength - 1] == '"')
|
||||||
{
|
{
|
||||||
/* string quoted with double quotes */
|
/* string quoted with double quotes */
|
||||||
@ -234,7 +229,7 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
{
|
{
|
||||||
/* single quotes allowed also... */
|
/* single quotes allowed also... */
|
||||||
|
|
||||||
if(aLength >= 2 && aValue[0] == '\'' &&
|
if (aLength >= 2 && aValue[0] == '\'' &&
|
||||||
aValue[aLength - 1] == '\'')
|
aValue[aLength - 1] == '\'')
|
||||||
{
|
{
|
||||||
aValue[aLength - 1] = '\0';
|
aValue[aLength - 1] = '\0';
|
||||||
@ -246,23 +241,23 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
/* compute maximum length copyable */
|
/* compute maximum length copyable */
|
||||||
|
|
||||||
aLineLength = (aLength <
|
aLineLength = (aLength <
|
||||||
theReturnBufferLength - aReturnLength) ? aLength :
|
theReturnBufferLength - aReturnLength) ? aLength :
|
||||||
theReturnBufferLength - aReturnLength;
|
theReturnBufferLength - aReturnLength;
|
||||||
|
|
||||||
/* do the copy to return buffer */
|
/* do the copy to return buffer */
|
||||||
|
|
||||||
if(aLineLength)
|
if (aLineLength)
|
||||||
{
|
{
|
||||||
strncpy(&theReturnBuffer[aReturnLength],
|
strncpy(&theReturnBuffer[aReturnLength],
|
||||||
aValue, aLineLength);
|
aValue, aLineLength);
|
||||||
aReturnLength += aLineLength;
|
aReturnLength += aLineLength;
|
||||||
if(aReturnLength < theReturnBufferLength)
|
if (aReturnLength < theReturnBufferLength)
|
||||||
{
|
{
|
||||||
theReturnBuffer[aReturnLength] = '\0';
|
theReturnBuffer[aReturnLength] = '\0';
|
||||||
++aReturnLength;
|
++aReturnLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(aFile)
|
if (aFile)
|
||||||
{
|
{
|
||||||
fclose(aFile);
|
fclose(aFile);
|
||||||
aFile = NULL;
|
aFile = NULL;
|
||||||
@ -272,17 +267,16 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aFile)
|
if (aFile)
|
||||||
{
|
|
||||||
fclose(aFile);
|
fclose(aFile);
|
||||||
}
|
|
||||||
|
|
||||||
if(!aKeyFound) { /* key wasn't found return default */
|
if (!aKeyFound)
|
||||||
++aLength; /* room for NULL char */
|
{ /* key wasn't found return default */
|
||||||
|
++aLength; /* room for NULL char */
|
||||||
aLength = theReturnBufferLength < aLength ?
|
aLength = theReturnBufferLength < aLength ?
|
||||||
theReturnBufferLength : aLength;
|
theReturnBufferLength : aLength;
|
||||||
strncpy(theReturnBuffer, theDefault, aLength);
|
strncpy(theReturnBuffer, theDefault, aLength);
|
||||||
@ -293,10 +287,11 @@ GetPrivateProfileString(char *theSection, /* section name */
|
|||||||
}
|
}
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
WritePrivateProfileString(char *theSection, /* section name */
|
WritePrivateProfileString(char *theSection, /* section name */
|
||||||
char *theKey, /* write key name */
|
char *theKey, /* write key name */
|
||||||
char *theBuffer, /* input buffer */
|
char *theBuffer, /* input buffer */
|
||||||
char *theIniFileName) /* pathname of ini file to write */
|
char *theIniFileName) /* pathname of ini file to
|
||||||
|
* write */
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -307,69 +302,74 @@ WritePrivateProfileString(char *theSection, /* section name */
|
|||||||
* I find out different.
|
* I find out different.
|
||||||
*/
|
*/
|
||||||
DWORD
|
DWORD
|
||||||
WritePrivateProfileString(char *theSection, /* section name */
|
WritePrivateProfileString(char *theSection, /* section name */
|
||||||
char *theKey, /* write key name */
|
char *theKey, /* write key name */
|
||||||
char *theBuffer, /* input buffer */
|
char *theBuffer, /* input buffer */
|
||||||
char *theIniFileName) /* pathname of ini file to write */
|
char *theIniFileName) /* pathname of ini file to
|
||||||
|
* write */
|
||||||
{
|
{
|
||||||
char buf[MAXPGPATH];
|
char buf[MAXPGPATH];
|
||||||
char* ptr = 0;
|
char *ptr = 0;
|
||||||
FILE* aFile = 0;
|
FILE *aFile = 0;
|
||||||
size_t aLength;
|
size_t aLength;
|
||||||
char aLine[2048];
|
char aLine[2048];
|
||||||
char *aValue;
|
char *aValue;
|
||||||
char *aString;
|
char *aString;
|
||||||
size_t aLineLength;
|
size_t aLineLength;
|
||||||
size_t aReturnLength = 0;
|
size_t aReturnLength = 0;
|
||||||
|
|
||||||
BOOL aSectionFound = FALSE;
|
BOOL aSectionFound = FALSE;
|
||||||
BOOL keyFound = FALSE;
|
BOOL keyFound = FALSE;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
/* If this isn't correct processing we'll change it later */
|
/* If this isn't correct processing we'll change it later */
|
||||||
if(theSection == NULL || theKey == NULL || theBuffer == NULL ||
|
if (theSection == NULL || theKey == NULL || theBuffer == NULL ||
|
||||||
theIniFileName == NULL) return 0;
|
theIniFileName == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
aLength = strlen(theBuffer);
|
aLength = strlen(theBuffer);
|
||||||
if(aLength == 0) return 0;
|
if (aLength == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
j = strlen(theIniFileName) + 1;
|
j = strlen(theIniFileName) + 1;
|
||||||
ptr = (char*)getpwuid(getuid()); /* get user info */
|
ptr = (char *) getpwuid(getuid()); /* get user info */
|
||||||
|
|
||||||
if( ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
if( MAXPGPATH-1 < j )
|
if (MAXPGPATH - 1 < j)
|
||||||
theIniFileName[MAXPGPATH-1] = '\0';
|
theIniFileName[MAXPGPATH - 1] = '\0';
|
||||||
|
|
||||||
sprintf(buf,"%s",theIniFileName);
|
sprintf(buf, "%s", theIniFileName);
|
||||||
}
|
}
|
||||||
ptr = ((struct passwd*)ptr)->pw_dir; /* get user home dir */
|
ptr = ((struct passwd *) ptr)->pw_dir; /* get user home dir */
|
||||||
if( ptr == NULL || *ptr == '\0' )
|
if (ptr == NULL || *ptr == '\0')
|
||||||
ptr = "/home";
|
ptr = "/home";
|
||||||
|
|
||||||
/* This doesn't make it so we find an ini file but allows normal */
|
/* This doesn't make it so we find an ini file but allows normal */
|
||||||
/* processing to continue further on down. The likelihood is that */
|
/* processing to continue further on down. The likelihood is that */
|
||||||
/* the file won't be found and thus the default value will be */
|
/* the file won't be found and thus the default value will be */
|
||||||
/* returned. */
|
/* returned. */
|
||||||
/* */
|
/* */
|
||||||
if( MAXPGPATH-1 < strlen(ptr) + j )
|
if (MAXPGPATH - 1 < strlen(ptr) + j)
|
||||||
{
|
{
|
||||||
if( MAXPGPATH-1 < strlen(ptr) )
|
if (MAXPGPATH - 1 < strlen(ptr))
|
||||||
ptr[MAXPGPATH-1] = '\0';
|
ptr[MAXPGPATH - 1] = '\0';
|
||||||
else
|
else
|
||||||
theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
|
theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf( buf, "%s/%s",ptr,theIniFileName );
|
sprintf(buf, "%s/%s", ptr, theIniFileName);
|
||||||
|
|
||||||
/* This code makes it so that a file in the users home dir */
|
/* This code makes it so that a file in the users home dir */
|
||||||
/* overrides a the "default" file as passed in */
|
/* overrides a the "default" file as passed in */
|
||||||
/* */
|
/* */
|
||||||
aFile = (FILE*)(buf ? fopen(buf, "r+") : NULL);
|
aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
|
||||||
if(!aFile) {
|
if (!aFile)
|
||||||
sprintf(buf,"%s",theIniFileName);
|
{
|
||||||
aFile = (FILE*)(buf ? fopen(buf, "r+") : NULL);
|
sprintf(buf, "%s", theIniFileName);
|
||||||
if(!aFile) return 0;
|
aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
|
||||||
|
if (!aFile)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -379,104 +379,92 @@ WritePrivateProfileString(char *theSection, /* section name */
|
|||||||
/* exists we have to overwrite it. If it doesn't exist */
|
/* exists we have to overwrite it. If it doesn't exist */
|
||||||
/* we just write a new line to the file. */
|
/* we just write a new line to the file. */
|
||||||
/* */
|
/* */
|
||||||
while(fgets(aLine, sizeof(aLine), aFile) != NULL)
|
while (fgets(aLine, sizeof(aLine), aFile) != NULL)
|
||||||
{
|
{
|
||||||
aLineLength = strlen(aLine);
|
aLineLength = strlen(aLine);
|
||||||
/* strip final '\n' */
|
/* strip final '\n' */
|
||||||
if(aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
|
||||||
{
|
|
||||||
aLine[aLineLength - 1] = '\0';
|
aLine[aLineLength - 1] = '\0';
|
||||||
}
|
switch (*aLine)
|
||||||
switch(*aLine)
|
|
||||||
{
|
{
|
||||||
case ' ': /* blank line */
|
case ' ': /* blank line */
|
||||||
case ';': /* comment line */
|
case ';': /* comment line */
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': /* section marker */
|
case '[': /* section marker */
|
||||||
|
|
||||||
if( (aString = strchr(aLine, ']')) )
|
if ((aString = strchr(aLine, ']')))
|
||||||
{
|
{
|
||||||
*aString = '\0';
|
*aString = '\0';
|
||||||
|
|
||||||
/* accept as matched if key exact match */
|
/* accept as matched if key exact match */
|
||||||
|
|
||||||
if(!strcmp(aLine + 1, theSection))
|
if (!strcmp(aLine + 1, theSection))
|
||||||
{
|
|
||||||
aSectionFound = TRUE;
|
aSectionFound = TRUE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
/* try to match value keys if in proper section */
|
/* try to match value keys if in proper section */
|
||||||
|
|
||||||
if(aSectionFound)
|
if (aSectionFound)
|
||||||
{
|
{
|
||||||
/* try to match requested key */
|
/* try to match requested key */
|
||||||
|
|
||||||
if( (aString = aValue = strchr(aLine, '=')) )
|
if ((aString = aValue = strchr(aLine, '=')))
|
||||||
{
|
{
|
||||||
*aValue = '\0';
|
*aValue = '\0';
|
||||||
++aValue;
|
++aValue;
|
||||||
|
|
||||||
/* strip leading blanks in value field */
|
/* strip leading blanks in value field */
|
||||||
|
|
||||||
while(*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
|
||||||
{
|
|
||||||
*aValue++ = '\0';
|
*aValue++ = '\0';
|
||||||
}
|
if (aValue >= aLine + sizeof(aLine))
|
||||||
if(aValue >= aLine + sizeof(aLine))
|
|
||||||
{
|
|
||||||
aValue = "";
|
aValue = "";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
aValue = "";
|
aValue = "";
|
||||||
}
|
|
||||||
|
|
||||||
/* strip trailing blanks from key */
|
/* strip trailing blanks from key */
|
||||||
|
|
||||||
if(aString)
|
if (aString)
|
||||||
{
|
{
|
||||||
while(--aString >= aLine && *aString == ' ')
|
while (--aString >= aLine && *aString == ' ')
|
||||||
{
|
|
||||||
*aString = '\0';
|
*aString = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see if key is matched */
|
/* see if key is matched */
|
||||||
|
|
||||||
if(!strcmp(theKey, aLine))
|
if (!strcmp(theKey, aLine))
|
||||||
{
|
{
|
||||||
keyFound = TRUE;
|
keyFound = TRUE;
|
||||||
/* matched -- first, terminate value part */
|
/* matched -- first, terminate value part */
|
||||||
|
|
||||||
/* overwrite current value */
|
/* overwrite current value */
|
||||||
fseek(aFile,-aLineLength,SEEK_CUR);
|
fseek(aFile, -aLineLength, SEEK_CUR);
|
||||||
/* overwrite key and value */
|
/* overwrite key and value */
|
||||||
sprintf(aLine,"%s = %s\n",theKey,theBuffer);
|
sprintf(aLine, "%s = %s\n", theKey, theBuffer);
|
||||||
fputs(aLine,aFile);
|
fputs(aLine, aFile);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(!keyFound) { /* theKey wasn't in file so */
|
break;
|
||||||
if(aFile)
|
|
||||||
{
|
|
||||||
fclose(aFile);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keyFound)
|
||||||
|
{ /* theKey wasn't in file so */
|
||||||
|
if (aFile)
|
||||||
|
fclose(aFile);
|
||||||
|
|
||||||
return aReturnLength > 0 ? aReturnLength - 1 : 0;
|
return aReturnLength > 0 ? aReturnLength - 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,25 +13,32 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
GetPrivateProfileString(char *theSection, /* section name */
|
GetPrivateProfileString(char *theSection, /* section name */
|
||||||
char *theKey, /* search key name */
|
char *theKey, /* search key name */
|
||||||
char *theDefault, /* default value if not found */
|
char *theDefault, /* default value if not
|
||||||
char *theReturnBuffer, /* return valuse stored here */
|
* found */
|
||||||
size_t theBufferLength, /* byte length of return buffer */
|
char *theReturnBuffer, /* return valuse stored
|
||||||
char *theIniFileName); /* pathname of ini file to search */
|
* here */
|
||||||
|
size_t theBufferLength, /* byte length of return
|
||||||
|
* buffer */
|
||||||
|
char *theIniFileName); /* pathname of ini file
|
||||||
|
* to search */
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
WritePrivateProfileString(char *theSection, /* section name */
|
WritePrivateProfileString(char *theSection, /* section name */
|
||||||
char *theKey, /* write key name */
|
char *theKey, /* write key name */
|
||||||
char *theBuffer, /* input buffer */
|
char *theBuffer, /* input buffer */
|
||||||
char *theIniFileName); /* pathname of ini file to write */
|
char *theIniFileName); /* pathname of ini file
|
||||||
|
* to write */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,66 +1,66 @@
|
|||||||
#ifndef _IODBC_H
|
#ifndef _IODBC_H
|
||||||
#define _IODBC_H
|
#define _IODBC_H
|
||||||
|
|
||||||
# if !defined(WIN32) && !defined(WIN32_SYSTEM)
|
#if !defined(WIN32) && !defined(WIN32_SYSTEM)
|
||||||
# define _UNIX_
|
#define _UNIX_
|
||||||
|
|
||||||
# include <stdlib.h>
|
#include <stdlib.h>
|
||||||
# include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
# define MEM_ALLOC(size) (malloc((size_t)(size)))
|
#define MEM_ALLOC(size) (malloc((size_t)(size)))
|
||||||
# define MEM_FREE(ptr) {if(ptr) free(ptr);}
|
#define MEM_FREE(ptr) {if(ptr) free(ptr);}
|
||||||
|
|
||||||
# define STRCPY(t, s) (strcpy((char*)(t), (char*)(s)))
|
#define STRCPY(t, s) (strcpy((char*)(t), (char*)(s)))
|
||||||
# define STRNCPY(t,s,n) (strncpy((char*)(t), (char*)(s), (size_t)(n)))
|
#define STRNCPY(t,s,n) (strncpy((char*)(t), (char*)(s), (size_t)(n)))
|
||||||
# define STRCAT(t, s) (strcat((char*)(t), (char*)(s)))
|
#define STRCAT(t, s) (strcat((char*)(t), (char*)(s)))
|
||||||
# define STRNCAT(t,s,n) (strncat((char*)(t), (char*)(s), (size_t)(n)))
|
#define STRNCAT(t,s,n) (strncat((char*)(t), (char*)(s), (size_t)(n)))
|
||||||
# define STREQ(a, b) (strcmp((char*)(a), (char*)(b)) == 0)
|
#define STREQ(a, b) (strcmp((char*)(a), (char*)(b)) == 0)
|
||||||
# define STRLEN(str) ((str)? strlen((char*)(str)):0)
|
#define STRLEN(str) ((str)? strlen((char*)(str)):0)
|
||||||
|
|
||||||
# define EXPORT
|
#define EXPORT
|
||||||
# define CALLBACK
|
#define CALLBACK
|
||||||
# define FAR
|
#define FAR
|
||||||
|
|
||||||
typedef signed short SSHOR;
|
typedef signed short SSHOR;
|
||||||
typedef short WORD;
|
typedef short WORD;
|
||||||
typedef long DWORD;
|
typedef long DWORD;
|
||||||
|
|
||||||
typedef WORD WPARAM;
|
typedef WORD WPARAM;
|
||||||
typedef DWORD LPARAM;
|
typedef DWORD LPARAM;
|
||||||
typedef void* HWND;
|
typedef void *HWND;
|
||||||
typedef int BOOL;
|
typedef int BOOL;
|
||||||
|
|
||||||
# endif /* _UNIX_ */
|
#endif /* _UNIX_ */
|
||||||
|
|
||||||
# if defined(WIN32) || defined(WIN32_SYSTEM)
|
#if defined(WIN32) || defined(WIN32_SYSTEM)
|
||||||
|
|
||||||
# include <windows.h>
|
#include <windows.h>
|
||||||
# include <windowsx.h>
|
#include <windowsx.h>
|
||||||
|
|
||||||
# ifdef _MSVC_
|
#ifdef _MSVC_
|
||||||
# define MEM_ALLOC(size) (fmalloc((size_t)(size)))
|
#define MEM_ALLOC(size) (fmalloc((size_t)(size)))
|
||||||
# define MEM_FREE(ptr) ((ptr)? ffree((PTR)(ptr)):0))
|
#define MEM_FREE(ptr) ((ptr)? ffree((PTR)(ptr)):0))
|
||||||
# define STRCPY(t, s) (fstrcpy((char FAR*)(t), (char FAR*)(s)))
|
#define STRCPY(t, s) (fstrcpy((char FAR*)(t), (char FAR*)(s)))
|
||||||
# define STRNCPY(t,s,n) (fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
|
#define STRNCPY(t,s,n) (fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
|
||||||
# define STRLEN(str) ((str)? fstrlen((char FAR*)(str)):0)
|
#define STRLEN(str) ((str)? fstrlen((char FAR*)(str)):0)
|
||||||
# define STREQ(a, b) (fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
|
#define STREQ(a, b) (fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# ifdef _BORLAND_
|
#ifdef _BORLAND_
|
||||||
# define MEM_ALLOC(size) (farmalloc((unsigned long)(size))
|
#define MEM_ALLOC(size) (farmalloc((unsigned long)(size))
|
||||||
# define MEM_FREE(ptr) ((ptr)? farfree((void far*)(ptr)):0)
|
#define MEM_FREE(ptr) ((ptr)? farfree((void far*)(ptr)):0)
|
||||||
# define STRCPY(t, s) (_fstrcpy((char FAR*)(t), (char FAR*)(s)))
|
#define STRCPY(t, s) (_fstrcpy((char FAR*)(t), (char FAR*)(s)))
|
||||||
# define STRNCPY(t,s,n) (_fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
|
#define STRNCPY(t,s,n) (_fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
|
||||||
# define STRLEN(str) ((str)? _fstrlen((char FAR*)(str)):0)
|
#define STRLEN(str) ((str)? _fstrlen((char FAR*)(str)):0)
|
||||||
# define STREQ(a, b) (_fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
|
#define STREQ(a, b) (_fstrcmp((char FAR*)(a), (char FAR*)(b) == 0)
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
# define SYSERR (-1)
|
#define SYSERR (-1)
|
||||||
|
|
||||||
# ifndef NULL
|
#ifndef NULL
|
||||||
# define NULL ((void FAR*)0UL)
|
#define NULL ((void FAR*)0UL)
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,97 +2,97 @@
|
|||||||
* include path to be used to create ODBC compliant applications.
|
* include path to be used to create ODBC compliant applications.
|
||||||
*/
|
*/
|
||||||
#ifndef _INTRINSIC_SQL_H
|
#ifndef _INTRINSIC_SQL_H
|
||||||
# define _INTRINSIC_SQL_H
|
#define _INTRINSIC_SQL_H
|
||||||
|
|
||||||
typedef unsigned char UCHAR;
|
typedef unsigned char UCHAR;
|
||||||
typedef long int SDWORD;
|
typedef long int SDWORD;
|
||||||
typedef short int SWORD;
|
typedef short int SWORD;
|
||||||
typedef unsigned long int UDWORD;
|
typedef unsigned long int UDWORD;
|
||||||
typedef unsigned short int UWORD;
|
typedef unsigned short int UWORD;
|
||||||
|
|
||||||
typedef void FAR* PTR;
|
typedef void FAR *PTR;
|
||||||
|
|
||||||
typedef void FAR* HENV;
|
typedef void FAR *HENV;
|
||||||
typedef void FAR* HDBC;
|
typedef void FAR *HDBC;
|
||||||
typedef void FAR* HSTMT;
|
typedef void FAR *HSTMT;
|
||||||
|
|
||||||
typedef signed short RETCODE;
|
typedef signed short RETCODE;
|
||||||
|
|
||||||
# ifdef WIN32
|
#ifdef WIN32
|
||||||
# define SQL_API __stdcall
|
#define SQL_API __stdcall
|
||||||
# else
|
#else
|
||||||
# define SQL_API EXPORT CALLBACK
|
#define SQL_API EXPORT CALLBACK
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# define ODBCVER 0x0250
|
#define ODBCVER 0x0250
|
||||||
|
|
||||||
# define SQL_MAX_MESSAGE_LENGTH 512
|
#define SQL_MAX_MESSAGE_LENGTH 512
|
||||||
# define SQL_MAX_DSN_LENGTH 32
|
#define SQL_MAX_DSN_LENGTH 32
|
||||||
|
|
||||||
/* return code */
|
/* return code */
|
||||||
# define SQL_INVALID_HANDLE (-2)
|
#define SQL_INVALID_HANDLE (-2)
|
||||||
# define SQL_ERROR (-1)
|
#define SQL_ERROR (-1)
|
||||||
# define SQL_SUCCESS 0
|
#define SQL_SUCCESS 0
|
||||||
# define SQL_SUCCESS_WITH_INFO 1
|
#define SQL_SUCCESS_WITH_INFO 1
|
||||||
# define SQL_NO_DATA_FOUND 100
|
#define SQL_NO_DATA_FOUND 100
|
||||||
|
|
||||||
/* standard SQL datatypes (agree with ANSI type numbering) */
|
/* standard SQL datatypes (agree with ANSI type numbering) */
|
||||||
# define SQL_CHAR 1
|
#define SQL_CHAR 1
|
||||||
# define SQL_NUMERIC 2
|
#define SQL_NUMERIC 2
|
||||||
# define SQL_DECIMAL 3
|
#define SQL_DECIMAL 3
|
||||||
# define SQL_INTEGER 4
|
#define SQL_INTEGER 4
|
||||||
# define SQL_SMALLINT 5
|
#define SQL_SMALLINT 5
|
||||||
# define SQL_FLOAT 6
|
#define SQL_FLOAT 6
|
||||||
# define SQL_REAL 7
|
#define SQL_REAL 7
|
||||||
# define SQL_DOUBLE 8
|
#define SQL_DOUBLE 8
|
||||||
# define SQL_VARCHAR 12
|
#define SQL_VARCHAR 12
|
||||||
|
|
||||||
# define SQL_TYPE_MIN SQL_CHAR
|
#define SQL_TYPE_MIN SQL_CHAR
|
||||||
# define SQL_TYPE_NULL 0
|
#define SQL_TYPE_NULL 0
|
||||||
# define SQL_TYPE_MAX SQL_VARCHAR
|
#define SQL_TYPE_MAX SQL_VARCHAR
|
||||||
|
|
||||||
/* C to SQL datatype mapping */
|
/* C to SQL datatype mapping */
|
||||||
# define SQL_C_CHAR SQL_CHAR
|
#define SQL_C_CHAR SQL_CHAR
|
||||||
# define SQL_C_LONG SQL_INTEGER
|
#define SQL_C_LONG SQL_INTEGER
|
||||||
# define SQL_C_SHORT SQL_SMALLINT
|
#define SQL_C_SHORT SQL_SMALLINT
|
||||||
# define SQL_C_FLOAT SQL_REAL
|
#define SQL_C_FLOAT SQL_REAL
|
||||||
# define SQL_C_DOUBLE SQL_DOUBLE
|
#define SQL_C_DOUBLE SQL_DOUBLE
|
||||||
# define SQL_C_DEFAULT 99
|
#define SQL_C_DEFAULT 99
|
||||||
|
|
||||||
# define SQL_NO_NULLS 0
|
#define SQL_NO_NULLS 0
|
||||||
# define SQL_NULLABLE 1
|
#define SQL_NULLABLE 1
|
||||||
# define SQL_NULLABLE_UNKNOWN 2
|
#define SQL_NULLABLE_UNKNOWN 2
|
||||||
|
|
||||||
/* some special length values */
|
/* some special length values */
|
||||||
# define SQL_NULL_DATA (-1)
|
#define SQL_NULL_DATA (-1)
|
||||||
# define SQL_DATA_AT_EXEC (-2)
|
#define SQL_DATA_AT_EXEC (-2)
|
||||||
# define SQL_NTS (-3)
|
#define SQL_NTS (-3)
|
||||||
|
|
||||||
/* SQLFreeStmt flag values */
|
/* SQLFreeStmt flag values */
|
||||||
# define SQL_CLOSE 0
|
#define SQL_CLOSE 0
|
||||||
# define SQL_DROP 1
|
#define SQL_DROP 1
|
||||||
# define SQL_UNBIND 2
|
#define SQL_UNBIND 2
|
||||||
# define SQL_RESET_PARAMS 3
|
#define SQL_RESET_PARAMS 3
|
||||||
|
|
||||||
/* SQLTransact flag values */
|
/* SQLTransact flag values */
|
||||||
# define SQL_COMMIT 0
|
#define SQL_COMMIT 0
|
||||||
# define SQL_ROLLBACK 1
|
#define SQL_ROLLBACK 1
|
||||||
|
|
||||||
/* SQLColAttributes flag values */
|
/* SQLColAttributes flag values */
|
||||||
# define SQL_COLUMN_COUNT 0
|
#define SQL_COLUMN_COUNT 0
|
||||||
# define SQL_COLUMN_LABEL 18
|
#define SQL_COLUMN_LABEL 18
|
||||||
# define SQL_COLATT_OPT_MAX SQL_COLUMN_LABEL
|
#define SQL_COLATT_OPT_MAX SQL_COLUMN_LABEL
|
||||||
# define SQL_COLUMN_DRIVER_START 1000
|
#define SQL_COLUMN_DRIVER_START 1000
|
||||||
|
|
||||||
# define SQL_COLATT_OPT_MIN SQL_COLUMN_COUNT
|
#define SQL_COLATT_OPT_MIN SQL_COLUMN_COUNT
|
||||||
|
|
||||||
/* Null handles */
|
/* Null handles */
|
||||||
# define SQL_NULL_HENV 0
|
#define SQL_NULL_HENV 0
|
||||||
# define SQL_NULL_HDBC 0
|
#define SQL_NULL_HDBC 0
|
||||||
# define SQL_NULL_HSTMT 0
|
#define SQL_NULL_HSTMT 0
|
||||||
|
|
||||||
/* All code below has been added to the original isql.h coming from iodbc */
|
/* All code below has been added to the original isql.h coming from iodbc */
|
||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
|
|
||||||
/* More SQLColAttributes flag values */
|
/* More SQLColAttributes flag values */
|
||||||
#define SQL_COLUMN_NAME 1
|
#define SQL_COLUMN_NAME 1
|
||||||
@ -116,9 +116,9 @@ typedef unsigned char BYTE;
|
|||||||
/* SQLColAttributes Searchable flags */
|
/* SQLColAttributes Searchable flags */
|
||||||
#define SQL_UNSEARCHABLE 0
|
#define SQL_UNSEARCHABLE 0
|
||||||
#define SQL_LIKE_ONLY 1
|
#define SQL_LIKE_ONLY 1
|
||||||
#define SQL_ALL_EXCEPT_LIKE 2
|
#define SQL_ALL_EXCEPT_LIKE 2
|
||||||
#define SQL_SEARCHABLE 3
|
#define SQL_SEARCHABLE 3
|
||||||
#define SQL_PRED_SEARCHABLE SQL_SEARCHABLE
|
#define SQL_PRED_SEARCHABLE SQL_SEARCHABLE
|
||||||
|
|
||||||
/* SQLColAttributes Updateable flags */
|
/* SQLColAttributes Updateable flags */
|
||||||
#define SQL_ATTR_READONLY 0
|
#define SQL_ATTR_READONLY 0
|
||||||
@ -126,112 +126,113 @@ typedef unsigned char BYTE;
|
|||||||
#define SQL_ATTR_READWRITE_UNKNOWN 2
|
#define SQL_ATTR_READWRITE_UNKNOWN 2
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* function prototypes previously not contained in isql.h
|
* function prototypes previously not contained in isql.h
|
||||||
*/
|
*/
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RETCODE SQL_API SQLAllocConnect (HENV henv,
|
RETCODE SQL_API SQLAllocConnect(HENV henv,
|
||||||
HDBC FAR * phdbc);
|
HDBC FAR * phdbc);
|
||||||
RETCODE SQL_API SQLAllocEnv (HENV FAR * phenv);
|
RETCODE SQL_API SQLAllocEnv(HENV FAR * phenv);
|
||||||
RETCODE SQL_API SQLAllocStmt (HDBC hdbc,
|
RETCODE SQL_API SQLAllocStmt(HDBC hdbc,
|
||||||
HSTMT FAR * phstmt);
|
HSTMT FAR * phstmt);
|
||||||
RETCODE SQL_API SQLBindCol (HSTMT hstmt,
|
RETCODE SQL_API SQLBindCol(HSTMT hstmt,
|
||||||
UWORD icol,
|
UWORD icol,
|
||||||
SWORD fCType,
|
SWORD fCType,
|
||||||
PTR rgbValue,
|
PTR rgbValue,
|
||||||
SDWORD cbValueMax,
|
SDWORD cbValueMax,
|
||||||
SDWORD FAR * pcbValue);
|
SDWORD FAR * pcbValue);
|
||||||
|
|
||||||
RETCODE SQL_API SQLCancel (HSTMT hstmt);
|
RETCODE SQL_API SQLCancel(HSTMT hstmt);
|
||||||
|
|
||||||
RETCODE SQL_API SQLColAttributes (HSTMT hstmt,
|
RETCODE SQL_API SQLColAttributes(HSTMT hstmt,
|
||||||
UWORD icol,
|
UWORD icol,
|
||||||
UWORD fDescType,
|
UWORD fDescType,
|
||||||
PTR rgbDesc,
|
PTR rgbDesc,
|
||||||
SWORD cbDescMax,
|
SWORD cbDescMax,
|
||||||
SWORD FAR * pcbDesc,
|
SWORD FAR * pcbDesc,
|
||||||
SDWORD FAR * pfDesc);
|
SDWORD FAR * pfDesc);
|
||||||
|
|
||||||
RETCODE SQL_API SQLConnect (HDBC hdbc,
|
RETCODE SQL_API SQLConnect(HDBC hdbc,
|
||||||
UCHAR FAR * szDSN,
|
UCHAR FAR * szDSN,
|
||||||
SWORD cbDSN,
|
SWORD cbDSN,
|
||||||
UCHAR FAR * szUID,
|
UCHAR FAR * szUID,
|
||||||
SWORD cbUID,
|
SWORD cbUID,
|
||||||
UCHAR FAR * szAuthStr,
|
UCHAR FAR * szAuthStr,
|
||||||
SWORD cbAuthStr);
|
SWORD cbAuthStr);
|
||||||
|
|
||||||
RETCODE SQL_API SQLDescribeCol (HSTMT hstmt,
|
RETCODE SQL_API SQLDescribeCol(HSTMT hstmt,
|
||||||
UWORD icol,
|
UWORD icol,
|
||||||
UCHAR FAR * szColName,
|
UCHAR FAR * szColName,
|
||||||
SWORD cbColNameMax,
|
SWORD cbColNameMax,
|
||||||
SWORD FAR * pcbColName,
|
SWORD FAR * pcbColName,
|
||||||
SWORD FAR * pfSqlType,
|
SWORD FAR * pfSqlType,
|
||||||
UDWORD FAR * pcbColDef,
|
UDWORD FAR * pcbColDef,
|
||||||
SWORD FAR * pibScale,
|
SWORD FAR * pibScale,
|
||||||
SWORD FAR * pfNullable);
|
SWORD FAR * pfNullable);
|
||||||
|
|
||||||
RETCODE SQL_API SQLDisconnect (HDBC hdbc);
|
RETCODE SQL_API SQLDisconnect(HDBC hdbc);
|
||||||
|
|
||||||
RETCODE SQL_API SQLError (HENV henv,
|
RETCODE SQL_API SQLError(HENV henv,
|
||||||
HDBC hdbc,
|
HDBC hdbc,
|
||||||
HSTMT hstmt,
|
HSTMT hstmt,
|
||||||
UCHAR FAR * szSqlState,
|
UCHAR FAR * szSqlState,
|
||||||
SDWORD FAR * pfNativeError,
|
SDWORD FAR * pfNativeError,
|
||||||
UCHAR FAR * szErrorMsg,
|
UCHAR FAR * szErrorMsg,
|
||||||
SWORD cbErrorMsgMax,
|
SWORD cbErrorMsgMax,
|
||||||
SWORD FAR * pcbErrorMsg);
|
SWORD FAR * pcbErrorMsg);
|
||||||
|
|
||||||
RETCODE SQL_API SQLExecDirect (HSTMT hstmt,
|
RETCODE SQL_API SQLExecDirect(HSTMT hstmt,
|
||||||
UCHAR FAR * szSqlStr,
|
UCHAR FAR * szSqlStr,
|
||||||
SDWORD cbSqlStr);
|
SDWORD cbSqlStr);
|
||||||
|
|
||||||
RETCODE SQL_API SQLExecute (HSTMT hstmt);
|
RETCODE SQL_API SQLExecute(HSTMT hstmt);
|
||||||
|
|
||||||
RETCODE SQL_API SQLFetch (HSTMT hstmt);
|
RETCODE SQL_API SQLFetch(HSTMT hstmt);
|
||||||
|
|
||||||
RETCODE SQL_API SQLFreeConnect (HDBC hdbc);
|
RETCODE SQL_API SQLFreeConnect(HDBC hdbc);
|
||||||
|
|
||||||
RETCODE SQL_API SQLFreeEnv (HENV henv);
|
RETCODE SQL_API SQLFreeEnv(HENV henv);
|
||||||
|
|
||||||
RETCODE SQL_API SQLFreeStmt (HSTMT hstmt,
|
RETCODE SQL_API SQLFreeStmt(HSTMT hstmt,
|
||||||
UWORD fOption);
|
UWORD fOption);
|
||||||
|
|
||||||
RETCODE SQL_API SQLGetCursorName (HSTMT hstmt,
|
RETCODE SQL_API SQLGetCursorName(HSTMT hstmt,
|
||||||
UCHAR FAR * szCursor,
|
UCHAR FAR * szCursor,
|
||||||
SWORD cbCursorMax,
|
SWORD cbCursorMax,
|
||||||
SWORD FAR * pcbCursor);
|
SWORD FAR * pcbCursor);
|
||||||
|
|
||||||
RETCODE SQL_API SQLNumResultCols (HSTMT hstmt,
|
RETCODE SQL_API SQLNumResultCols(HSTMT hstmt,
|
||||||
SWORD FAR * pccol);
|
SWORD FAR * pccol);
|
||||||
|
|
||||||
RETCODE SQL_API SQLPrepare (HSTMT hstmt,
|
RETCODE SQL_API SQLPrepare(HSTMT hstmt,
|
||||||
UCHAR FAR * szSqlStr,
|
UCHAR FAR * szSqlStr,
|
||||||
SDWORD cbSqlStr);
|
SDWORD cbSqlStr);
|
||||||
|
|
||||||
RETCODE SQL_API SQLRowCount (HSTMT hstmt,
|
RETCODE SQL_API SQLRowCount(HSTMT hstmt,
|
||||||
SDWORD FAR * pcrow);
|
SDWORD FAR * pcrow);
|
||||||
|
|
||||||
RETCODE SQL_API SQLSetCursorName (HSTMT hstmt,
|
RETCODE SQL_API SQLSetCursorName(HSTMT hstmt,
|
||||||
UCHAR FAR * szCursor,
|
UCHAR FAR * szCursor,
|
||||||
SWORD cbCursor);
|
SWORD cbCursor);
|
||||||
|
|
||||||
RETCODE SQL_API SQLTransact (HENV henv,
|
RETCODE SQL_API SQLTransact(HENV henv,
|
||||||
HDBC hdbc,
|
HDBC hdbc,
|
||||||
UWORD fType);
|
UWORD fType);
|
||||||
|
|
||||||
RETCODE SQL_API SQLSetParam (HSTMT hstmt,
|
RETCODE SQL_API SQLSetParam(HSTMT hstmt,
|
||||||
UWORD ipar,
|
UWORD ipar,
|
||||||
SWORD fCType,
|
SWORD fCType,
|
||||||
SWORD fSqlType,
|
SWORD fSqlType,
|
||||||
UDWORD cbColDef,
|
UDWORD cbColDef,
|
||||||
SWORD ibScale,
|
SWORD ibScale,
|
||||||
PTR rgbValue,
|
PTR rgbValue,
|
||||||
SDWORD FAR * pcbValue);
|
SDWORD FAR * pcbValue);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,13 @@
|
|||||||
/* Module: lobj.c
|
/* Module: lobj.c
|
||||||
*
|
*
|
||||||
* Description: This module contains routines related to manipulating
|
* Description: This module contains routines related to manipulating
|
||||||
* large objects.
|
* large objects.
|
||||||
*
|
*
|
||||||
* Classes: none
|
* Classes: none
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -16,17 +16,18 @@
|
|||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
|
||||||
Oid
|
Oid
|
||||||
lo_creat(ConnectionClass *conn, int mode)
|
lo_creat(ConnectionClass * conn, int mode)
|
||||||
{
|
{
|
||||||
LO_ARG argv[1];
|
LO_ARG argv[1];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
argv[0].len = 4;
|
argv[0].len = 4;
|
||||||
argv[0].u.integer = mode;
|
argv[0].u.integer = mode;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_CREAT, &retval, &result_len, 1, argv, 1))
|
if (!CC_send_function(conn, LO_CREAT, &retval, &result_len, 1, argv, 1))
|
||||||
return 0; /* invalid oid */
|
return 0; /* invalid oid */
|
||||||
else
|
else
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
@ -34,11 +35,11 @@ int retval, result_len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_open(ConnectionClass *conn, int lobjId, int mode)
|
lo_open(ConnectionClass * conn, int lobjId, int mode)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int result_len;
|
int result_len;
|
||||||
LO_ARG argv[2];
|
LO_ARG argv[2];
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
@ -49,7 +50,7 @@ LO_ARG argv[2];
|
|||||||
argv[1].len = 4;
|
argv[1].len = 4;
|
||||||
argv[1].u.integer = mode;
|
argv[1].u.integer = mode;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_OPEN, &fd, &result_len, 1, argv, 2))
|
if (!CC_send_function(conn, LO_OPEN, &fd, &result_len, 1, argv, 2))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (fd >= 0 && lo_lseek(conn, fd, 0L, SEEK_SET) < 0)
|
if (fd >= 0 && lo_lseek(conn, fd, 0L, SEEK_SET) < 0)
|
||||||
@ -59,17 +60,18 @@ LO_ARG argv[2];
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_close(ConnectionClass *conn, int fd)
|
lo_close(ConnectionClass * conn, int fd)
|
||||||
{
|
{
|
||||||
LO_ARG argv[1];
|
LO_ARG argv[1];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
argv[0].len = 4;
|
argv[0].len = 4;
|
||||||
argv[0].u.integer = fd;
|
argv[0].u.integer = fd;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_CLOSE, &retval, &result_len, 1, argv, 1))
|
if (!CC_send_function(conn, LO_CLOSE, &retval, &result_len, 1, argv, 1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -79,10 +81,10 @@ int retval, result_len;
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_read(ConnectionClass *conn, int fd, char *buf, int len)
|
lo_read(ConnectionClass * conn, int fd, char *buf, int len)
|
||||||
{
|
{
|
||||||
LO_ARG argv[2];
|
LO_ARG argv[2];
|
||||||
int result_len;
|
int result_len;
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
@ -93,7 +95,7 @@ int result_len;
|
|||||||
argv[1].len = 4;
|
argv[1].len = 4;
|
||||||
argv[1].u.integer = len;
|
argv[1].u.integer = len;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_READ, (int *) buf, &result_len, 0, argv, 2))
|
if (!CC_send_function(conn, LO_READ, (int *) buf, &result_len, 0, argv, 2))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -101,10 +103,11 @@ int result_len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_write(ConnectionClass *conn, int fd, char *buf, int len)
|
lo_write(ConnectionClass * conn, int fd, char *buf, int len)
|
||||||
{
|
{
|
||||||
LO_ARG argv[2];
|
LO_ARG argv[2];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
@ -118,7 +121,7 @@ int retval, result_len;
|
|||||||
argv[1].len = len;
|
argv[1].len = len;
|
||||||
argv[1].u.ptr = (char *) buf;
|
argv[1].u.ptr = (char *) buf;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_WRITE, &retval, &result_len, 1, argv, 2))
|
if (!CC_send_function(conn, LO_WRITE, &retval, &result_len, 1, argv, 2))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -126,10 +129,11 @@ int retval, result_len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_lseek(ConnectionClass *conn, int fd, int offset, int whence)
|
lo_lseek(ConnectionClass * conn, int fd, int offset, int whence)
|
||||||
{
|
{
|
||||||
LO_ARG argv[3];
|
LO_ARG argv[3];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
@ -144,7 +148,7 @@ int retval, result_len;
|
|||||||
argv[2].len = 4;
|
argv[2].len = 4;
|
||||||
argv[2].u.integer = whence;
|
argv[2].u.integer = whence;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_LSEEK, &retval, &result_len, 1, argv, 3))
|
if (!CC_send_function(conn, LO_LSEEK, &retval, &result_len, 1, argv, 3))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -152,17 +156,18 @@ int retval, result_len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_tell(ConnectionClass *conn, int fd)
|
lo_tell(ConnectionClass * conn, int fd)
|
||||||
{
|
{
|
||||||
LO_ARG argv[1];
|
LO_ARG argv[1];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
argv[0].len = 4;
|
argv[0].len = 4;
|
||||||
argv[0].u.integer = fd;
|
argv[0].u.integer = fd;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_TELL, &retval, &result_len, 1, argv, 1))
|
if (!CC_send_function(conn, LO_TELL, &retval, &result_len, 1, argv, 1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -170,27 +175,20 @@ int retval, result_len;
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lo_unlink(ConnectionClass *conn, Oid lobjId)
|
lo_unlink(ConnectionClass * conn, Oid lobjId)
|
||||||
{
|
{
|
||||||
LO_ARG argv[1];
|
LO_ARG argv[1];
|
||||||
int retval, result_len;
|
int retval,
|
||||||
|
result_len;
|
||||||
|
|
||||||
|
|
||||||
argv[0].isint = 1;
|
argv[0].isint = 1;
|
||||||
argv[0].len = 4;
|
argv[0].len = 4;
|
||||||
argv[0].u.integer = lobjId;
|
argv[0].u.integer = lobjId;
|
||||||
|
|
||||||
if ( ! CC_send_function(conn, LO_UNLINK, &retval, &result_len, 1, argv, 1))
|
if (!CC_send_function(conn, LO_UNLINK, &retval, &result_len, 1, argv, 1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: lobj.h
|
/* File: lobj.h
|
||||||
*
|
*
|
||||||
* Description: See "lobj.c"
|
* Description: See "lobj.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,14 +13,15 @@
|
|||||||
|
|
||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
|
|
||||||
struct lo_arg {
|
struct lo_arg
|
||||||
int isint;
|
{
|
||||||
int len;
|
int isint;
|
||||||
|
int len;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int integer;
|
int integer;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LO_CREAT 957
|
#define LO_CREAT 957
|
||||||
@ -35,14 +36,13 @@ struct lo_arg {
|
|||||||
#define INV_WRITE 0x00020000
|
#define INV_WRITE 0x00020000
|
||||||
#define INV_READ 0x00040000
|
#define INV_READ 0x00040000
|
||||||
|
|
||||||
Oid lo_creat(ConnectionClass *conn, int mode);
|
Oid lo_creat(ConnectionClass * conn, int mode);
|
||||||
int lo_open(ConnectionClass *conn, int lobjId, int mode);
|
int lo_open(ConnectionClass * conn, int lobjId, int mode);
|
||||||
int lo_close(ConnectionClass *conn, int fd);
|
int lo_close(ConnectionClass * conn, int fd);
|
||||||
int lo_read(ConnectionClass *conn, int fd, char *buf, int len);
|
int lo_read(ConnectionClass * conn, int fd, char *buf, int len);
|
||||||
int lo_write(ConnectionClass *conn, int fd, char *buf, int len);
|
int lo_write(ConnectionClass * conn, int fd, char *buf, int len);
|
||||||
int lo_lseek(ConnectionClass *conn, int fd, int offset, int len);
|
int lo_lseek(ConnectionClass * conn, int fd, int offset, int len);
|
||||||
int lo_tell(ConnectionClass *conn, int fd);
|
int lo_tell(ConnectionClass * conn, int fd);
|
||||||
int lo_unlink(ConnectionClass *conn, Oid lobjId);
|
int lo_unlink(ConnectionClass * conn, Oid lobjId);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* Module: misc.c
|
/* Module: misc.c
|
||||||
*
|
*
|
||||||
* Description: This module contains miscellaneous routines
|
* Description: This module contains miscellaneous routines
|
||||||
* such as for debugging/logging and string functions.
|
* such as for debugging/logging and string functions.
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -24,49 +24,54 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
void generate_filename(char*,char*,char*);
|
void generate_filename(char *, char *, char *);
|
||||||
|
|
||||||
void
|
void
|
||||||
generate_filename(char* dirname,char* prefix,char* filename)
|
generate_filename(char *dirname, char *prefix, char *filename)
|
||||||
{
|
{
|
||||||
int pid = 0;
|
int pid = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
struct passwd *ptr = 0;
|
struct passwd *ptr = 0;
|
||||||
|
|
||||||
ptr = getpwuid(getuid());
|
ptr = getpwuid(getuid());
|
||||||
#endif
|
#endif
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
if(dirname == 0 || filename == 0)
|
if (dirname == 0 || filename == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strcpy(filename,dirname);
|
strcpy(filename, dirname);
|
||||||
strcat(filename,DIRSEPARATOR);
|
strcat(filename, DIRSEPARATOR);
|
||||||
if(prefix != 0)
|
if (prefix != 0)
|
||||||
strcat(filename,prefix);
|
strcat(filename, prefix);
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
strcat(filename,ptr->pw_name);
|
strcat(filename, ptr->pw_name);
|
||||||
#endif
|
#endif
|
||||||
sprintf(filename,"%s%u%s",filename,pid,".log");
|
sprintf(filename, "%s%u%s", filename, pid, ".log");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MY_LOG
|
#ifdef MY_LOG
|
||||||
|
|
||||||
void
|
void
|
||||||
mylog(char * fmt, ...)
|
mylog(char *fmt,...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char filebuf[80];
|
char filebuf[80];
|
||||||
FILE* LOGFP = globals.mylogFP;
|
FILE *LOGFP = globals.mylogFP;
|
||||||
|
|
||||||
if ( globals.debug) {
|
if (globals.debug)
|
||||||
|
{
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
if (! LOGFP) {
|
if (!LOGFP)
|
||||||
generate_filename(MYLOGDIR,MYLOGFILE,filebuf);
|
{
|
||||||
|
generate_filename(MYLOGDIR, MYLOGFILE, filebuf);
|
||||||
LOGFP = fopen(filebuf, PG_BINARY_W);
|
LOGFP = fopen(filebuf, PG_BINARY_W);
|
||||||
globals.mylogFP = LOGFP;
|
globals.mylogFP = LOGFP;
|
||||||
setbuf(LOGFP, NULL);
|
setbuf(LOGFP, NULL);
|
||||||
@ -78,23 +83,26 @@ mylog(char * fmt, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef Q_LOG
|
#ifdef Q_LOG
|
||||||
|
|
||||||
void
|
void
|
||||||
qlog(char * fmt, ...)
|
qlog(char *fmt,...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char filebuf[80];
|
char filebuf[80];
|
||||||
FILE* LOGFP = globals.qlogFP;
|
FILE *LOGFP = globals.qlogFP;
|
||||||
|
|
||||||
if ( globals.commlog) {
|
if (globals.commlog)
|
||||||
|
{
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
if (! LOGFP) {
|
if (!LOGFP)
|
||||||
generate_filename(QLOGDIR,QLOGFILE,filebuf);
|
{
|
||||||
|
generate_filename(QLOGDIR, QLOGFILE, filebuf);
|
||||||
LOGFP = fopen(filebuf, PG_BINARY_W);
|
LOGFP = fopen(filebuf, PG_BINARY_W);
|
||||||
globals.qlogFP = LOGFP;
|
globals.qlogFP = LOGFP;
|
||||||
setbuf(LOGFP, NULL);
|
setbuf(LOGFP, NULL);
|
||||||
@ -106,9 +114,10 @@ qlog(char * fmt, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Undefine these because windows.h will redefine and cause a warning */
|
/* Undefine these because windows.h will redefine and cause a warning */
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -135,7 +144,8 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
|||||||
if (dst_len <= 0)
|
if (dst_len <= 0)
|
||||||
return STRCPY_FAIL;
|
return STRCPY_FAIL;
|
||||||
|
|
||||||
if (src_len == SQL_NULL_DATA) {
|
if (src_len == SQL_NULL_DATA)
|
||||||
|
{
|
||||||
dst[0] = '\0';
|
dst[0] = '\0';
|
||||||
return STRCPY_NULL;
|
return STRCPY_NULL;
|
||||||
}
|
}
|
||||||
@ -145,14 +155,17 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
|||||||
if (src_len <= 0)
|
if (src_len <= 0)
|
||||||
return STRCPY_FAIL;
|
return STRCPY_FAIL;
|
||||||
|
|
||||||
else {
|
else
|
||||||
if (src_len < dst_len) {
|
{
|
||||||
|
if (src_len < dst_len)
|
||||||
|
{
|
||||||
memcpy(dst, src, src_len);
|
memcpy(dst, src, src_len);
|
||||||
dst[src_len] = '\0';
|
dst[src_len] = '\0';
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
memcpy(dst, src, dst_len-1);
|
{
|
||||||
dst[dst_len-1] = '\0'; /* truncated */
|
memcpy(dst, src, dst_len - 1);
|
||||||
|
dst[dst_len - 1] = '\0'; /* truncated */
|
||||||
return STRCPY_TRUNCATED;
|
return STRCPY_TRUNCATED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,28 +177,29 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
|
|||||||
/* the destination string if src has len characters or more. */
|
/* the destination string if src has len characters or more. */
|
||||||
/* instead, I want it to copy up to len-1 characters and always */
|
/* instead, I want it to copy up to len-1 characters and always */
|
||||||
/* terminate the destination string. */
|
/* 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;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
if (NULL != dst) {
|
if (NULL != dst)
|
||||||
|
{
|
||||||
|
|
||||||
/* Just in case, check for special lengths */
|
/* Just in case, check for special lengths */
|
||||||
if (len == SQL_NULL_DATA) {
|
if (len == SQL_NULL_DATA)
|
||||||
|
{
|
||||||
dst[0] = '\0';
|
dst[0] = '\0';
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (len == SQL_NTS)
|
else if (len == SQL_NTS)
|
||||||
len = strlen(src) + 1;
|
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];
|
dst[i] = src[i];
|
||||||
}
|
|
||||||
|
|
||||||
if(len > 0) {
|
if (len > 0)
|
||||||
dst[i] = '\0';
|
dst[i] = '\0';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
@ -196,22 +210,24 @@ int i;
|
|||||||
char *
|
char *
|
||||||
make_string(char *s, int len, char *buf)
|
make_string(char *s, int len, char *buf)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
char *str;
|
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);
|
length = (len > 0) ? len : strlen(s);
|
||||||
|
|
||||||
if (buf) {
|
if (buf)
|
||||||
strncpy_null(buf, s, length+1);
|
{
|
||||||
|
strncpy_null(buf, s, length + 1);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = malloc(length + 1);
|
str = malloc(length + 1);
|
||||||
if ( ! str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
strncpy_null(str, s, length+1);
|
strncpy_null(str, s, length + 1);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,10 +242,11 @@ char *
|
|||||||
my_strcat(char *buf, char *fmt, char *s, int len)
|
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 length = (len > 0) ? len : strlen(s);
|
||||||
|
|
||||||
int pos = strlen(buf);
|
int pos = strlen(buf);
|
||||||
|
|
||||||
sprintf(&buf[pos], fmt, length, s);
|
sprintf(&buf[pos], fmt, length, s);
|
||||||
return buf;
|
return buf;
|
||||||
@ -237,24 +254,26 @@ my_strcat(char *buf, char *fmt, char *s, int len)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_newlines(char *string)
|
void
|
||||||
|
remove_newlines(char *string)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for(i=0; i < strlen(string); i++) {
|
for (i = 0; i < strlen(string); i++)
|
||||||
if((string[i] == '\n') ||
|
{
|
||||||
(string[i] == '\r')) {
|
if ((string[i] == '\n') ||
|
||||||
|
(string[i] == '\r'))
|
||||||
string[i] = ' ';
|
string[i] = ' ';
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
trim(char *s)
|
trim(char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = strlen(s) - 1; i >= 0; i--) {
|
for (i = strlen(s) - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
if (s[i] == ' ')
|
if (s[i] == ' ')
|
||||||
s[i] = '\0';
|
s[i] = '\0';
|
||||||
else
|
else
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: misc.h
|
/* File: misc.h
|
||||||
*
|
*
|
||||||
* Description: See "misc.c"
|
* Description: See "misc.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -39,35 +39,37 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifdef MY_LOG
|
#ifdef MY_LOG
|
||||||
#define MYLOGFILE "mylog_"
|
#define MYLOGFILE "mylog_"
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#define MYLOGDIR "/tmp"
|
#define MYLOGDIR "/tmp"
|
||||||
#else
|
|
||||||
#define MYLOGDIR "c:"
|
|
||||||
#endif
|
|
||||||
extern void mylog(char * fmt, ...);
|
|
||||||
#else
|
#else
|
||||||
#ifndef WIN32
|
#define MYLOGDIR "c:"
|
||||||
#define mylog(args...) /* GNU convention for variable arguments */
|
#endif
|
||||||
#else
|
extern void mylog(char *fmt,...);
|
||||||
#define mylog /* mylog */
|
|
||||||
#endif
|
#else
|
||||||
|
#ifndef WIN32
|
||||||
|
#define mylog(args...) /* GNU convention for variable arguments */
|
||||||
|
#else
|
||||||
|
#define mylog /* mylog */
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_LOG
|
#ifdef Q_LOG
|
||||||
#define QLOGFILE "psqlodbc_"
|
#define QLOGFILE "psqlodbc_"
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#define QLOGDIR "/tmp"
|
#define QLOGDIR "/tmp"
|
||||||
#else
|
|
||||||
#define QLOGDIR "c:"
|
|
||||||
#endif
|
|
||||||
extern void qlog(char * fmt, ...);
|
|
||||||
#else
|
#else
|
||||||
#ifndef WIN32
|
#define QLOGDIR "c:"
|
||||||
#define qlog(args...) /* GNU convention for variable arguments */
|
#endif
|
||||||
#else
|
extern void qlog(char *fmt,...);
|
||||||
#define qlog /* qlog */
|
|
||||||
#endif
|
#else
|
||||||
|
#ifndef WIN32
|
||||||
|
#define qlog(args...) /* GNU convention for variable arguments */
|
||||||
|
#else
|
||||||
|
#define qlog /* qlog */
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@ -78,20 +80,20 @@
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define PG_BINARY O_BINARY
|
#define PG_BINARY O_BINARY
|
||||||
#define PG_BINARY_R "rb"
|
#define PG_BINARY_R "rb"
|
||||||
#define PG_BINARY_W "wb"
|
#define PG_BINARY_W "wb"
|
||||||
#else
|
#else
|
||||||
#define PG_BINARY 0
|
#define PG_BINARY 0
|
||||||
#define PG_BINARY_R "r"
|
#define PG_BINARY_R "r"
|
||||||
#define PG_BINARY_W "w"
|
#define PG_BINARY_W "w"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void remove_newlines(char *string);
|
void remove_newlines(char *string);
|
||||||
char *strncpy_null(char *dst, const char *src, int len);
|
char *strncpy_null(char *dst, const char *src, int len);
|
||||||
char *trim(char *string);
|
char *trim(char *string);
|
||||||
char *make_string(char *s, int len, char *buf);
|
char *make_string(char *s, int len, char *buf);
|
||||||
char *my_strcat(char *buf, char *fmt, char *s, int len);
|
char *my_strcat(char *buf, char *fmt, char *s, int len);
|
||||||
|
|
||||||
/* defines for return value of my_strcpy */
|
/* defines for return value of my_strcpy */
|
||||||
#define STRCPY_SUCCESS 1
|
#define STRCPY_SUCCESS 1
|
||||||
@ -99,6 +101,6 @@ char *my_strcat(char *buf, char *fmt, char *s, int len);
|
|||||||
#define STRCPY_TRUNCATED -1
|
#define STRCPY_TRUNCATED -1
|
||||||
#define STRCPY_NULL -2
|
#define STRCPY_NULL -2
|
||||||
|
|
||||||
int my_strcpy(char *dst, int dst_len, char *src, int src_len);
|
int my_strcpy(char *dst, int dst_len, char *src, int src_len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: pgtypes.h
|
/* File: pgtypes.h
|
||||||
*
|
*
|
||||||
* Description: See "pgtypes.c"
|
* Description: See "pgtypes.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -17,48 +17,48 @@
|
|||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define PG_TYPE_LO ???? /* waiting for permanent type */
|
#define PG_TYPE_LO ????/* waiting for permanent type */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PG_TYPE_BOOL 16
|
#define PG_TYPE_BOOL 16
|
||||||
#define PG_TYPE_BYTEA 17
|
#define PG_TYPE_BYTEA 17
|
||||||
#define PG_TYPE_CHAR 18
|
#define PG_TYPE_CHAR 18
|
||||||
#define PG_TYPE_NAME 19
|
#define PG_TYPE_NAME 19
|
||||||
#define PG_TYPE_INT8 20
|
#define PG_TYPE_INT8 20
|
||||||
#define PG_TYPE_INT2 21
|
#define PG_TYPE_INT2 21
|
||||||
#define PG_TYPE_INT2VECTOR 22
|
#define PG_TYPE_INT2VECTOR 22
|
||||||
#define PG_TYPE_INT4 23
|
#define PG_TYPE_INT4 23
|
||||||
#define PG_TYPE_REGPROC 24
|
#define PG_TYPE_REGPROC 24
|
||||||
#define PG_TYPE_TEXT 25
|
#define PG_TYPE_TEXT 25
|
||||||
#define PG_TYPE_OID 26
|
#define PG_TYPE_OID 26
|
||||||
#define PG_TYPE_TID 27
|
#define PG_TYPE_TID 27
|
||||||
#define PG_TYPE_XID 28
|
#define PG_TYPE_XID 28
|
||||||
#define PG_TYPE_CID 29
|
#define PG_TYPE_CID 29
|
||||||
#define PG_TYPE_OIDVECTOR 30
|
#define PG_TYPE_OIDVECTOR 30
|
||||||
#define PG_TYPE_SET 32
|
#define PG_TYPE_SET 32
|
||||||
#define PG_TYPE_CHAR2 409
|
#define PG_TYPE_CHAR2 409
|
||||||
#define PG_TYPE_CHAR4 410
|
#define PG_TYPE_CHAR4 410
|
||||||
#define PG_TYPE_CHAR8 411
|
#define PG_TYPE_CHAR8 411
|
||||||
#define PG_TYPE_POINT 600
|
#define PG_TYPE_POINT 600
|
||||||
#define PG_TYPE_LSEG 601
|
#define PG_TYPE_LSEG 601
|
||||||
#define PG_TYPE_PATH 602
|
#define PG_TYPE_PATH 602
|
||||||
#define PG_TYPE_BOX 603
|
#define PG_TYPE_BOX 603
|
||||||
#define PG_TYPE_POLYGON 604
|
#define PG_TYPE_POLYGON 604
|
||||||
#define PG_TYPE_FILENAME 605
|
#define PG_TYPE_FILENAME 605
|
||||||
#define PG_TYPE_FLOAT4 700
|
#define PG_TYPE_FLOAT4 700
|
||||||
#define PG_TYPE_FLOAT8 701
|
#define PG_TYPE_FLOAT8 701
|
||||||
#define PG_TYPE_ABSTIME 702
|
#define PG_TYPE_ABSTIME 702
|
||||||
#define PG_TYPE_RELTIME 703
|
#define PG_TYPE_RELTIME 703
|
||||||
#define PG_TYPE_TINTERVAL 704
|
#define PG_TYPE_TINTERVAL 704
|
||||||
#define PG_TYPE_UNKNOWN 705
|
#define PG_TYPE_UNKNOWN 705
|
||||||
#define PG_TYPE_MONEY 790
|
#define PG_TYPE_MONEY 790
|
||||||
#define PG_TYPE_OIDINT2 810
|
#define PG_TYPE_OIDINT2 810
|
||||||
#define PG_TYPE_OIDINT4 910
|
#define PG_TYPE_OIDINT4 910
|
||||||
#define PG_TYPE_OIDNAME 911
|
#define PG_TYPE_OIDNAME 911
|
||||||
#define PG_TYPE_BPCHAR 1042
|
#define PG_TYPE_BPCHAR 1042
|
||||||
#define PG_TYPE_VARCHAR 1043
|
#define PG_TYPE_VARCHAR 1043
|
||||||
#define PG_TYPE_DATE 1082
|
#define PG_TYPE_DATE 1082
|
||||||
#define PG_TYPE_TIME 1083
|
#define PG_TYPE_TIME 1083
|
||||||
#define PG_TYPE_DATETIME 1184
|
#define PG_TYPE_DATETIME 1184
|
||||||
#define PG_TYPE_TIMESTAMP 1296
|
#define PG_TYPE_TIMESTAMP 1296
|
||||||
#define PG_TYPE_NUMERIC 1700
|
#define PG_TYPE_NUMERIC 1700
|
||||||
@ -69,30 +69,29 @@ extern Int2 sqlTypes[];
|
|||||||
/* Defines for pgtype_precision */
|
/* Defines for pgtype_precision */
|
||||||
#define PG_STATIC -1
|
#define PG_STATIC -1
|
||||||
|
|
||||||
Int4 sqltype_to_pgtype(Int2 fSqlType);
|
Int4 sqltype_to_pgtype(Int2 fSqlType);
|
||||||
|
|
||||||
Int2 pgtype_to_sqltype(StatementClass *stmt, Int4 type);
|
Int2 pgtype_to_sqltype(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_to_ctype(StatementClass *stmt, Int4 type);
|
Int2 pgtype_to_ctype(StatementClass * stmt, Int4 type);
|
||||||
char *pgtype_to_name(StatementClass *stmt, Int4 type);
|
char *pgtype_to_name(StatementClass * stmt, Int4 type);
|
||||||
|
|
||||||
/* These functions can use static numbers or result sets(col parameter) */
|
/* These functions can use static numbers or result sets(col parameter) */
|
||||||
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);
|
||||||
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);
|
||||||
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);
|
||||||
|
|
||||||
Int2 pgtype_scale(StatementClass *stmt, Int4 type, int col);
|
Int2 pgtype_scale(StatementClass * stmt, Int4 type, int col);
|
||||||
Int2 pgtype_radix(StatementClass *stmt, Int4 type);
|
Int2 pgtype_radix(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_nullable(StatementClass *stmt, Int4 type);
|
Int2 pgtype_nullable(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_auto_increment(StatementClass *stmt, Int4 type);
|
Int2 pgtype_auto_increment(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_case_sensitive(StatementClass *stmt, Int4 type);
|
Int2 pgtype_case_sensitive(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_money(StatementClass *stmt, Int4 type);
|
Int2 pgtype_money(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_searchable(StatementClass *stmt, Int4 type);
|
Int2 pgtype_searchable(StatementClass * stmt, Int4 type);
|
||||||
Int2 pgtype_unsigned(StatementClass *stmt, Int4 type);
|
Int2 pgtype_unsigned(StatementClass * stmt, Int4 type);
|
||||||
char *pgtype_literal_prefix(StatementClass *stmt, Int4 type);
|
char *pgtype_literal_prefix(StatementClass * stmt, Int4 type);
|
||||||
char *pgtype_literal_suffix(StatementClass *stmt, Int4 type);
|
char *pgtype_literal_suffix(StatementClass * stmt, Int4 type);
|
||||||
char *pgtype_create_params(StatementClass *stmt, Int4 type);
|
char *pgtype_create_params(StatementClass * stmt, Int4 type);
|
||||||
|
|
||||||
Int2 sqltype_to_default_ctype(Int2 sqltype);
|
Int2 sqltype_to_default_ctype(Int2 sqltype);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/* Module: psqlodbc.c
|
/* Module: psqlodbc.c
|
||||||
*
|
*
|
||||||
* Description: This module contains the main entry point (DllMain) for the library.
|
* Description: This module contains the main entry point (DllMain) for the library.
|
||||||
* It also contains functions to get and set global variables for the
|
* It also contains functions to get and set global variables for the
|
||||||
* driver in the registry.
|
* driver in the registry.
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -35,49 +35,52 @@ GLOBAL_VALUES globals;
|
|||||||
RETCODE SQL_API SQLDummyOrdinal(void);
|
RETCODE SQL_API SQLDummyOrdinal(void);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
||||||
|
|
||||||
/* This is where the Driver Manager attaches to this Driver */
|
/* 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;
|
WORD wVersionRequested;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
|
|
||||||
switch (ul_reason_for_call) {
|
switch (ul_reason_for_call)
|
||||||
case DLL_PROCESS_ATTACH:
|
{
|
||||||
s_hModule = hInst; /* Save for dialog boxes */
|
case DLL_PROCESS_ATTACH:
|
||||||
|
s_hModule = hInst; /* Save for dialog boxes */
|
||||||
|
|
||||||
/* Load the WinSock Library */
|
/* Load the WinSock Library */
|
||||||
wVersionRequested = MAKEWORD(1, 1);
|
wVersionRequested = MAKEWORD(1, 1);
|
||||||
|
|
||||||
if ( WSAStartup(wVersionRequested, &wsaData))
|
if (WSAStartup(wVersionRequested, &wsaData))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Verify that this is the minimum version of WinSock */
|
/* Verify that this is the minimum version of WinSock */
|
||||||
if ( LOBYTE( wsaData.wVersion ) != 1 ||
|
if (LOBYTE(wsaData.wVersion) != 1 ||
|
||||||
HIBYTE( wsaData.wVersion ) != 1 ) {
|
HIBYTE(wsaData.wVersion) != 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
WSACleanup();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DLL_THREAD_ATTACH:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
|
return TRUE;
|
||||||
break;
|
|
||||||
|
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_DETACH:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
default:
|
||||||
|
break;
|
||||||
WSACleanup();
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case DLL_THREAD_DETACH:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -85,7 +88,7 @@ WSADATA wsaData;
|
|||||||
UNREFERENCED_PARAMETER(lpReserved);
|
UNREFERENCED_PARAMETER(lpReserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* not WIN32 */
|
#else /* not WIN32 */
|
||||||
|
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
#define TRUE (BOOL)1
|
#define TRUE (BOOL)1
|
||||||
@ -96,7 +99,7 @@ WSADATA wsaData;
|
|||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
|
||||||
/* This function is called at library initialization time. */
|
/* This function is called at library initialization time. */
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
@ -106,7 +109,7 @@ init(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* not __GNUC__ */
|
#else /* not __GNUC__ */
|
||||||
|
|
||||||
/* These two functions do shared library initialziation on UNIX, well at least
|
/* These two functions do shared library initialziation on UNIX, well at least
|
||||||
* on Linux. I don't know about other systems.
|
* on Linux. I don't know about other systems.
|
||||||
@ -124,9 +127,9 @@ _fini(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* not __GNUC__ */
|
#endif /* not __GNUC__ */
|
||||||
|
|
||||||
#endif /* not WIN32 */
|
#endif /* not WIN32 */
|
||||||
|
|
||||||
/* This function is used to cause the Driver Manager to
|
/* This function is used to cause the Driver Manager to
|
||||||
call functions by number rather than name, which is faster.
|
call functions by number rather than name, which is faster.
|
||||||
@ -134,8 +137,8 @@ _fini(void)
|
|||||||
Driver Manager do this. Also, the ordinal values of the
|
Driver Manager do this. Also, the ordinal values of the
|
||||||
functions must match the value of fFunction in SQLGetFunctions()
|
functions must match the value of fFunction in SQLGetFunctions()
|
||||||
*/
|
*/
|
||||||
RETCODE SQL_API SQLDummyOrdinal(void)
|
RETCODE SQL_API
|
||||||
|
SQLDummyOrdinal(void)
|
||||||
{
|
{
|
||||||
return SQL_SUCCESS;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
/* File: psqlodbc.h
|
/* File: psqlodbc.h
|
||||||
*
|
*
|
||||||
* Description: This file contains defines and declarations that are related to
|
* Description: This file contains defines and declarations that are related to
|
||||||
* the entire driver.
|
* the entire driver.
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* 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__
|
#ifndef __PSQLODBC_H__
|
||||||
@ -16,7 +16,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */
|
#include <stdio.h> /* for FILE* pointers: see GLOBAL_VALUES */
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#define Int4 long int
|
#define Int4 long int
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#define UInt2 unsigned short
|
#define UInt2 unsigned short
|
||||||
typedef float SFLOAT;
|
typedef float SFLOAT;
|
||||||
typedef double SDOUBLE;
|
typedef double SDOUBLE;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define Int4 int
|
#define Int4 int
|
||||||
#define UInt4 unsigned int
|
#define UInt4 unsigned int
|
||||||
@ -38,8 +39,8 @@ typedef UInt4 Oid;
|
|||||||
#define ODBCVER 0x0250
|
#define ODBCVER 0x0250
|
||||||
#define DRIVER_ODBC_VER "02.50"
|
#define DRIVER_ODBC_VER "02.50"
|
||||||
|
|
||||||
#define DRIVERNAME "PostgreSQL ODBC"
|
#define DRIVERNAME "PostgreSQL ODBC"
|
||||||
#define DBMS_NAME "PostgreSQL"
|
#define DBMS_NAME "PostgreSQL"
|
||||||
|
|
||||||
#define POSTGRESDRIVERVERSION "07.01.0002"
|
#define POSTGRESDRIVERVERSION "07.01.0002"
|
||||||
|
|
||||||
@ -51,17 +52,21 @@ typedef UInt4 Oid;
|
|||||||
|
|
||||||
/* Limits */
|
/* Limits */
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define BLCKSZ 4096
|
#define BLCKSZ 4096
|
||||||
#endif
|
#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
|
||||||
/* see an easy way round this - DJP 24-1-2001 */
|
* query size but I don't */
|
||||||
|
/* see an easy way round this - DJP 24-1-2001 */
|
||||||
#define MAX_CONNECT_STRING 4096
|
#define MAX_CONNECT_STRING 4096
|
||||||
#define ERROR_MSG_LENGTH 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 TUPLE_MALLOC_INC 100
|
||||||
#define SOCK_BUFFER_SIZE 4096 /* default socket buffer size */
|
#define SOCK_BUFFER_SIZE 4096 /* default socket buffer
|
||||||
#define MAX_CONNECTIONS 128 /* conns per environment (arbitrary) */
|
* size */
|
||||||
|
#define MAX_CONNECTIONS 128 /* conns per environment
|
||||||
|
* (arbitrary) */
|
||||||
#define MAX_FIELDS 512
|
#define MAX_FIELDS 512
|
||||||
#define BYTELEN 8
|
#define BYTELEN 8
|
||||||
#define VARHDRSZ sizeof(Int4)
|
#define VARHDRSZ sizeof(Int4)
|
||||||
@ -71,21 +76,24 @@ typedef UInt4 Oid;
|
|||||||
#define MAX_CURSOR_LEN 32
|
#define MAX_CURSOR_LEN 32
|
||||||
|
|
||||||
/* Registry length limits */
|
/* Registry length limits */
|
||||||
#define LARGE_REGISTRY_LEN 4096 /* used for special cases */
|
#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
|
||||||
#define SMALL_REGISTRY_LEN 10 /* for 1/0 settings */
|
* user,database,etc. */
|
||||||
|
#define SMALL_REGISTRY_LEN 10 /* for 1/0 settings */
|
||||||
|
|
||||||
|
|
||||||
/* These prefixes denote system tables */
|
/* These prefixes denote system tables */
|
||||||
#define POSTGRES_SYS_PREFIX "pg_"
|
#define POSTGRES_SYS_PREFIX "pg_"
|
||||||
#define KEYS_TABLE "dd_fkey"
|
#define KEYS_TABLE "dd_fkey"
|
||||||
|
|
||||||
/* Info limits */
|
/* Info limits */
|
||||||
#define MAX_INFO_STRING 128
|
#define MAX_INFO_STRING 128
|
||||||
#define MAX_KEYPARTS 20
|
#define MAX_KEYPARTS 20
|
||||||
#define MAX_KEYLEN 512 /* max key of the form "date+outlet+invoice" */
|
#define MAX_KEYLEN 512 /* max key of the form
|
||||||
#define MAX_ROW_SIZE 0 /* Unlimited rowsize with the Tuple Toaster */
|
* "date+outlet+invoice" */
|
||||||
#define MAX_STATEMENT_LEN 0 /* Unlimited statement size with 7.0 */
|
#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 */
|
/* Previously, numerous query strings were defined of length MAX_STATEMENT_LEN */
|
||||||
/* Now that's 0, lets use this instead. DJP 24-1-2001 */
|
/* Now that's 0, lets use this instead. DJP 24-1-2001 */
|
||||||
@ -110,62 +118,72 @@ typedef struct lo_arg LO_ARG;
|
|||||||
|
|
||||||
typedef struct GlobalValues_
|
typedef struct GlobalValues_
|
||||||
{
|
{
|
||||||
int fetch_max;
|
int fetch_max;
|
||||||
int socket_buffersize;
|
int socket_buffersize;
|
||||||
int unknown_sizes;
|
int unknown_sizes;
|
||||||
int max_varchar_size;
|
int max_varchar_size;
|
||||||
int max_longvarchar_size;
|
int max_longvarchar_size;
|
||||||
char debug;
|
char debug;
|
||||||
char commlog;
|
char commlog;
|
||||||
char disable_optimizer;
|
char disable_optimizer;
|
||||||
char ksqo;
|
char ksqo;
|
||||||
char unique_index;
|
char unique_index;
|
||||||
char onlyread; /* readonly is reserved on Digital C++ compiler */
|
char onlyread; /* readonly is reserved on Digital C++
|
||||||
char use_declarefetch;
|
* compiler */
|
||||||
char text_as_longvarchar;
|
char use_declarefetch;
|
||||||
char unknowns_as_longvarchar;
|
char text_as_longvarchar;
|
||||||
char bools_as_char;
|
char unknowns_as_longvarchar;
|
||||||
char lie;
|
char bools_as_char;
|
||||||
char parse;
|
char lie;
|
||||||
char cancel_as_freestmt;
|
char parse;
|
||||||
char extra_systable_prefixes[MEDIUM_REGISTRY_LEN];
|
char cancel_as_freestmt;
|
||||||
char conn_settings[LARGE_REGISTRY_LEN];
|
char extra_systable_prefixes[MEDIUM_REGISTRY_LEN];
|
||||||
/* Protocol is not used anymore, but kept in case
|
char conn_settings[LARGE_REGISTRY_LEN];
|
||||||
* it is useful in the future. bjm 2001-02-10
|
|
||||||
*/
|
|
||||||
char protocol[SMALL_REGISTRY_LEN];
|
|
||||||
FILE* mylogFP;
|
|
||||||
FILE* qlogFP;
|
|
||||||
} GLOBAL_VALUES;
|
|
||||||
|
|
||||||
typedef struct StatementOptions_ {
|
/*
|
||||||
int maxRows;
|
* Protocol is not used anymore, but kept in case it is useful in the
|
||||||
int maxLength;
|
* future. bjm 2001-02-10
|
||||||
int rowset_size;
|
*/
|
||||||
int keyset_size;
|
char protocol[SMALL_REGISTRY_LEN];
|
||||||
int cursor_type;
|
FILE *mylogFP;
|
||||||
int scroll_concurrency;
|
FILE *qlogFP;
|
||||||
int retrieve_data;
|
} GLOBAL_VALUES;
|
||||||
int bind_size; /* size of each structure if using Row Binding */
|
|
||||||
int use_bookmarks;
|
typedef struct StatementOptions_
|
||||||
} StatementOptions;
|
{
|
||||||
|
int maxRows;
|
||||||
|
int maxLength;
|
||||||
|
int rowset_size;
|
||||||
|
int keyset_size;
|
||||||
|
int cursor_type;
|
||||||
|
int scroll_concurrency;
|
||||||
|
int retrieve_data;
|
||||||
|
int bind_size; /* size of each structure if using Row
|
||||||
|
* Binding */
|
||||||
|
int use_bookmarks;
|
||||||
|
} StatementOptions;
|
||||||
|
|
||||||
/* Used to pass extra query info to send_query */
|
/* Used to pass extra query info to send_query */
|
||||||
typedef struct QueryInfo_ {
|
typedef struct QueryInfo_
|
||||||
int row_size;
|
{
|
||||||
QResultClass *result_in;
|
int row_size;
|
||||||
char *cursor;
|
QResultClass *result_in;
|
||||||
} QueryInfo;
|
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 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 */
|
/* 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 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_PRECISION 1000
|
||||||
#define PG_NUMERIC_MAX_SCALE 1000
|
#define PG_NUMERIC_MAX_SCALE 1000
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* Module: qresult.c
|
/* Module: qresult.c
|
||||||
*
|
*
|
||||||
* Description: This module contains functions related to
|
* Description: This module contains functions related to
|
||||||
* managing result information (i.e, fetching rows from the backend,
|
* managing result information (i.e, fetching rows from the backend,
|
||||||
* managing the tuple cache, etc.) and retrieving it.
|
* managing the tuple cache, etc.) and retrieving it.
|
||||||
* Depending on the situation, a QResultClass will hold either data
|
* Depending on the situation, a QResultClass will hold either data
|
||||||
* from the backend or a manually built result (see "qresult.h" to
|
* from the backend or a manually built result (see "qresult.h" to
|
||||||
* see which functions/macros are for manual or backend results.
|
* see which functions/macros are for manual or backend results.
|
||||||
* For manually built results, the QResultClass simply points to
|
* For manually built results, the QResultClass simply points to
|
||||||
* TupleList and ColumnInfo structures, which actually hold the data.
|
* TupleList and ColumnInfo structures, which actually hold the data.
|
||||||
*
|
*
|
||||||
* Classes: QResultClass (Functions prefix: "QR_")
|
* Classes: QResultClass (Functions prefix: "QR_")
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -31,63 +31,65 @@
|
|||||||
|
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
|
|
||||||
/* Used for building a Manual Result only */
|
/* Used for building a Manual Result only */
|
||||||
/* All info functions call this function to create the manual result set. */
|
/* All info functions call this function to create the manual result set. */
|
||||||
void
|
void
|
||||||
QR_set_num_fields(QResultClass *self, int new_num_fields)
|
QR_set_num_fields(QResultClass * self, int new_num_fields)
|
||||||
{
|
{
|
||||||
mylog("in QR_set_num_fields\n");
|
mylog("in QR_set_num_fields\n");
|
||||||
|
|
||||||
CI_set_num_fields(self->fields, new_num_fields);
|
CI_set_num_fields(self->fields, new_num_fields);
|
||||||
if(self->manual_tuples)
|
if (self->manual_tuples)
|
||||||
TL_Destructor(self->manual_tuples);
|
TL_Destructor(self->manual_tuples);
|
||||||
|
|
||||||
self->manual_tuples = TL_Constructor(new_num_fields);
|
self->manual_tuples = TL_Constructor(new_num_fields);
|
||||||
|
|
||||||
mylog("exit QR_set_num_fields\n");
|
mylog("exit QR_set_num_fields\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_set_position(QResultClass *self, int pos)
|
QR_set_position(QResultClass * self, int pos)
|
||||||
{
|
{
|
||||||
self->tupleField = self->backend_tuples + ((self->base + pos) * self->num_fields);
|
self->tupleField = self->backend_tuples + ((self->base + pos) * self->num_fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_set_cache_size(QResultClass *self, int cache_size)
|
QR_set_cache_size(QResultClass * self, int cache_size)
|
||||||
{
|
{
|
||||||
self->cache_size = cache_size;
|
self->cache_size = cache_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_set_rowset_size(QResultClass *self, int rowset_size)
|
QR_set_rowset_size(QResultClass * self, int rowset_size)
|
||||||
{
|
{
|
||||||
self->rowset_size = rowset_size;
|
self->rowset_size = rowset_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_inc_base(QResultClass *self, int base_inc)
|
QR_inc_base(QResultClass * self, int base_inc)
|
||||||
{
|
{
|
||||||
self->base += base_inc;
|
self->base += base_inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/* CLASS QResult */
|
/* CLASS QResult */
|
||||||
/************************************/
|
/************************************/
|
||||||
|
|
||||||
QResultClass *
|
QResultClass *
|
||||||
QR_Constructor(void)
|
QR_Constructor(void)
|
||||||
{
|
{
|
||||||
QResultClass *rv;
|
QResultClass *rv;
|
||||||
|
|
||||||
mylog("in QR_Constructor\n");
|
mylog("in QR_Constructor\n");
|
||||||
rv = (QResultClass *) malloc(sizeof(QResultClass));
|
rv = (QResultClass *) malloc(sizeof(QResultClass));
|
||||||
|
|
||||||
if (rv != NULL) {
|
if (rv != NULL)
|
||||||
|
{
|
||||||
rv->status = PGRES_EMPTY_QUERY;
|
rv->status = PGRES_EMPTY_QUERY;
|
||||||
|
|
||||||
/* construct the column info */
|
/* construct the column info */
|
||||||
if ( ! (rv->fields = CI_Constructor())) {
|
if (!(rv->fields = CI_Constructor()))
|
||||||
|
{
|
||||||
free(rv);
|
free(rv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -116,7 +118,7 @@ QResultClass *rv;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_Destructor(QResultClass *self)
|
QR_Destructor(QResultClass * self)
|
||||||
{
|
{
|
||||||
mylog("QResult: in DESTRUCTOR\n");
|
mylog("QResult: in DESTRUCTOR\n");
|
||||||
|
|
||||||
@ -124,26 +126,26 @@ QR_Destructor(QResultClass *self)
|
|||||||
if (self->manual_tuples)
|
if (self->manual_tuples)
|
||||||
TL_Destructor(self->manual_tuples);
|
TL_Destructor(self->manual_tuples);
|
||||||
|
|
||||||
/* If conn is defined, then we may have used "backend_tuples", */
|
/* If conn is defined, then we may have used "backend_tuples", */
|
||||||
/* so in case we need to, free it up. Also, close the cursor. */
|
/* so in case we need to, free it up. Also, close the cursor. */
|
||||||
if (self->conn && self->conn->sock && CC_is_in_trans(self->conn))
|
if (self->conn && self->conn->sock && CC_is_in_trans(self->conn))
|
||||||
QR_close(self); /* close the cursor if there is one */
|
QR_close(self); /* close the cursor if there is one */
|
||||||
|
|
||||||
QR_free_memory(self); /* safe to call anyway */
|
QR_free_memory(self); /* safe to call anyway */
|
||||||
|
|
||||||
/* Should have been freed in the close() but just in case... */
|
/* Should have been freed in the close() but just in case... */
|
||||||
if (self->cursor)
|
if (self->cursor)
|
||||||
free(self->cursor);
|
free(self->cursor);
|
||||||
|
|
||||||
/* Free up column info */
|
/* Free up column info */
|
||||||
if (self->fields)
|
if (self->fields)
|
||||||
CI_Destructor(self->fields);
|
CI_Destructor(self->fields);
|
||||||
|
|
||||||
/* Free command info (this is from strdup()) */
|
/* Free command info (this is from strdup()) */
|
||||||
if (self->command)
|
if (self->command)
|
||||||
free(self->command);
|
free(self->command);
|
||||||
|
|
||||||
/* Free notice info (this is from strdup()) */
|
/* Free notice info (this is from strdup()) */
|
||||||
if (self->notice)
|
if (self->notice)
|
||||||
free(self->notice);
|
free(self->notice);
|
||||||
|
|
||||||
@ -154,7 +156,7 @@ QR_Destructor(QResultClass *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_set_command(QResultClass *self, char *msg)
|
QR_set_command(QResultClass * self, char *msg)
|
||||||
{
|
{
|
||||||
if (self->command)
|
if (self->command)
|
||||||
free(self->command);
|
free(self->command);
|
||||||
@ -163,7 +165,7 @@ QR_set_command(QResultClass *self, char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_set_notice(QResultClass *self, char *msg)
|
QR_set_notice(QResultClass * self, char *msg)
|
||||||
{
|
{
|
||||||
if (self->notice)
|
if (self->notice)
|
||||||
free(self->notice);
|
free(self->notice);
|
||||||
@ -172,26 +174,31 @@ QR_set_notice(QResultClass *self, char *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QR_free_memory(QResultClass *self)
|
QR_free_memory(QResultClass * self)
|
||||||
{
|
{
|
||||||
register int lf, row;
|
register int lf,
|
||||||
register TupleField *tuple = self->backend_tuples;
|
row;
|
||||||
int fcount = self->fcount;
|
register TupleField *tuple = self->backend_tuples;
|
||||||
int num_fields = self->num_fields;
|
int fcount = self->fcount;
|
||||||
|
int num_fields = self->num_fields;
|
||||||
|
|
||||||
mylog("QResult: free memory in, fcount=%d\n", fcount);
|
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);
|
mylog("row = %d, num_fields = %d\n", row, num_fields);
|
||||||
for (lf=0; lf < num_fields; lf++) {
|
for (lf = 0; lf < num_fields; lf++)
|
||||||
if (tuple[lf].value != NULL) {
|
{
|
||||||
|
if (tuple[lf].value != NULL)
|
||||||
|
{
|
||||||
mylog("free [lf=%d] %u\n", lf, tuple[lf].value);
|
mylog("free [lf=%d] %u\n", lf, tuple[lf].value);
|
||||||
free(tuple[lf].value);
|
free(tuple[lf].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tuple += num_fields; /* next row */
|
tuple += num_fields;/* next row */
|
||||||
}
|
}
|
||||||
|
|
||||||
free(self->backend_tuples);
|
free(self->backend_tuples);
|
||||||
@ -205,25 +212,28 @@ int num_fields = self->num_fields;
|
|||||||
|
|
||||||
/* This function is called by send_query() */
|
/* This function is called by send_query() */
|
||||||
char
|
char
|
||||||
QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
|
QR_fetch_tuples(QResultClass * self, ConnectionClass * conn, char *cursor)
|
||||||
{
|
{
|
||||||
int tuple_size;
|
int tuple_size;
|
||||||
|
|
||||||
/* If called from send_query the first time (conn != NULL), */
|
/* If called from send_query the first time (conn != NULL), */
|
||||||
/* then set the inTuples state, */
|
/* then set the inTuples state, */
|
||||||
/* and read the tuples. If conn is NULL, */
|
/* and read the tuples. If conn is NULL, */
|
||||||
/* it implies that we are being called from next_tuple(), */
|
/* it implies that we are being called from next_tuple(), */
|
||||||
/* like to get more rows so don't call next_tuple again! */
|
/* like to get more rows so don't call next_tuple again! */
|
||||||
if (conn != NULL) {
|
if (conn != NULL)
|
||||||
|
{
|
||||||
self->conn = conn;
|
self->conn = conn;
|
||||||
|
|
||||||
mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor==NULL)?"":cursor, self->cursor);
|
mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor == NULL) ? "" : cursor, self->cursor);
|
||||||
|
|
||||||
if (self->cursor)
|
if (self->cursor)
|
||||||
free(self->cursor);
|
free(self->cursor);
|
||||||
|
|
||||||
if ( globals.use_declarefetch) {
|
if (globals.use_declarefetch)
|
||||||
if (! cursor || cursor[0] == '\0') {
|
{
|
||||||
|
if (!cursor || cursor[0] == '\0')
|
||||||
|
{
|
||||||
self->status = PGRES_INTERNAL_ERROR;
|
self->status = PGRES_INTERNAL_ERROR;
|
||||||
QR_set_message(self, "Internal Error -- no cursor for fetch");
|
QR_set_message(self, "Internal Error -- no cursor for fetch");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -231,13 +241,15 @@ int tuple_size;
|
|||||||
self->cursor = strdup(cursor);
|
self->cursor = strdup(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the field attributes. */
|
/* Read the field attributes. */
|
||||||
/* $$$$ Should do some error control HERE! $$$$ */
|
/* $$$$ 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->status = PGRES_FIELDS_OK;
|
||||||
self->num_fields = CI_get_num_fields(self->fields);
|
self->num_fields = CI_get_num_fields(self->fields);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
self->status = PGRES_BAD_RESPONSE;
|
self->status = PGRES_BAD_RESPONSE;
|
||||||
QR_set_message(self, "Error reading field information");
|
QR_set_message(self, "Error reading field information");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -253,7 +265,8 @@ int tuple_size;
|
|||||||
/* allocate memory for the tuple cache */
|
/* allocate memory for the tuple cache */
|
||||||
mylog("MALLOC: tuple_size = %d, size = %d\n", tuple_size, self->num_fields * sizeof(TupleField) * tuple_size);
|
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);
|
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;
|
self->status = PGRES_FATAL_ERROR;
|
||||||
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;
|
||||||
@ -262,19 +275,21 @@ int tuple_size;
|
|||||||
self->inTuples = TRUE;
|
self->inTuples = TRUE;
|
||||||
|
|
||||||
|
|
||||||
/* Force a read to occur in next_tuple */
|
/* Force a read to occur in next_tuple */
|
||||||
self->fcount = tuple_size+1;
|
self->fcount = tuple_size + 1;
|
||||||
self->fetch_count = tuple_size+1;
|
self->fetch_count = tuple_size + 1;
|
||||||
self->base = 0;
|
self->base = 0;
|
||||||
|
|
||||||
return QR_next_tuple(self);
|
return QR_next_tuple(self);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
|
|
||||||
/* Always have to read the field attributes. */
|
/* Always have to read the field attributes. */
|
||||||
/* But we dont have to reallocate memory for them! */
|
/* 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;
|
self->status = PGRES_BAD_RESPONSE;
|
||||||
QR_set_message(self, "Error reading field information");
|
QR_set_message(self, "Error reading field information");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -286,12 +301,13 @@ int tuple_size;
|
|||||||
/* Close the cursor and end the transaction (if no cursors left) */
|
/* Close the cursor and end the transaction (if no cursors left) */
|
||||||
/* We only close cursor/end the transaction if a cursor was used. */
|
/* We only close cursor/end the transaction if a cursor was used. */
|
||||||
int
|
int
|
||||||
QR_close(QResultClass *self)
|
QR_close(QResultClass * self)
|
||||||
{
|
{
|
||||||
QResultClass *res;
|
QResultClass *res;
|
||||||
|
|
||||||
if (globals.use_declarefetch && self->conn && self->cursor) {
|
if (globals.use_declarefetch && self->conn && self->cursor)
|
||||||
char buf[64];
|
{
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
sprintf(buf, "close %s", self->cursor);
|
sprintf(buf, "close %s", self->cursor);
|
||||||
mylog("QResult: closing cursor: '%s'\n", buf);
|
mylog("QResult: closing cursor: '%s'\n", buf);
|
||||||
@ -304,21 +320,24 @@ QResultClass *res;
|
|||||||
free(self->cursor);
|
free(self->cursor);
|
||||||
self->cursor = NULL;
|
self->cursor = NULL;
|
||||||
|
|
||||||
if (res == NULL) {
|
if (res == NULL)
|
||||||
|
{
|
||||||
self->status = PGRES_FATAL_ERROR;
|
self->status = PGRES_FATAL_ERROR;
|
||||||
QR_set_message(self, "Error closing cursor.");
|
QR_set_message(self, "Error closing cursor.");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End the transaction if there are no cursors left on this conn */
|
/* 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);
|
mylog("QResult: END transaction on conn=%u\n", self->conn);
|
||||||
|
|
||||||
res = CC_send_query(self->conn, "END", NULL);
|
res = CC_send_query(self->conn, "END", NULL);
|
||||||
|
|
||||||
CC_set_no_trans(self->conn);
|
CC_set_no_trans(self->conn);
|
||||||
|
|
||||||
if (res == NULL) {
|
if (res == NULL)
|
||||||
|
{
|
||||||
self->status = PGRES_FATAL_ERROR;
|
self->status = PGRES_FATAL_ERROR;
|
||||||
QR_set_message(self, "Error ending transaction.");
|
QR_set_message(self, "Error ending transaction.");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -332,56 +351,67 @@ QResultClass *res;
|
|||||||
|
|
||||||
/* This function is called by fetch_tuples() AND SQLFetch() */
|
/* This function is called by fetch_tuples() AND SQLFetch() */
|
||||||
int
|
int
|
||||||
QR_next_tuple(QResultClass *self)
|
QR_next_tuple(QResultClass * self)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
QResultClass *res;
|
QResultClass *res;
|
||||||
SocketClass *sock;
|
SocketClass *sock;
|
||||||
/* Speed up access */
|
|
||||||
int fetch_count = self->fetch_count;
|
|
||||||
int fcount = self->fcount;
|
|
||||||
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 fetch[128];
|
|
||||||
QueryInfo qi;
|
|
||||||
|
|
||||||
if (fetch_count < fcount) { /* return a row from cache */
|
/* Speed up access */
|
||||||
|
int fetch_count = self->fetch_count;
|
||||||
|
int fcount = self->fcount;
|
||||||
|
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 fetch[128];
|
||||||
|
QueryInfo qi;
|
||||||
|
|
||||||
|
if (fetch_count < fcount)
|
||||||
|
{ /* return a row from cache */
|
||||||
mylog("next_tuple: fetch_count < fcount: returning tuple %d, fcount = %d\n", fetch_count, fcount);
|
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->tupleField = the_tuples + (fetch_count * self->num_fields); /* next row */
|
||||||
self->fetch_count++;
|
self->fetch_count++;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if (self->fcount < self->cache_size) { /* last row from cache */
|
else if (self->fcount < self->cache_size)
|
||||||
/* We are done because we didn't even get CACHE_SIZE tuples */
|
{ /* last row from cache */
|
||||||
mylog("next_tuple: fcount < CACHE_SIZE: fcount = %d, fetch_count = %d\n", fcount, fetch_count);
|
/* We are done because we didn't even get CACHE_SIZE tuples */
|
||||||
self->tupleField = NULL;
|
mylog("next_tuple: fcount < CACHE_SIZE: fcount = %d, fetch_count = %d\n", fcount, fetch_count);
|
||||||
self->status = PGRES_END_TUPLES;
|
self->tupleField = NULL;
|
||||||
return -1; /* end of tuples */
|
self->status = PGRES_END_TUPLES;
|
||||||
|
return -1; /* end of tuples */
|
||||||
}
|
}
|
||||||
else {
|
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.
|
* 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;
|
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);
|
mylog("next_tuple: ALL_ROWS: done, fcount = %d, fetch_count = %d\n", fcount, fetch_count);
|
||||||
self->tupleField = NULL;
|
self->tupleField = NULL;
|
||||||
self->status = PGRES_END_TUPLES;
|
self->status = PGRES_END_TUPLES;
|
||||||
return -1; /* end of 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. */
|
/* Determine the optimum cache size. */
|
||||||
if (globals.fetch_max % self->rowset_size == 0)
|
if (globals.fetch_max % self->rowset_size == 0)
|
||||||
fetch_size = globals.fetch_max;
|
fetch_size = globals.fetch_max;
|
||||||
else if (self->rowset_size < globals.fetch_max)
|
else if (self->rowset_size < globals.fetch_max)
|
||||||
@ -392,7 +422,8 @@ QueryInfo qi;
|
|||||||
self->cache_size = fetch_size;
|
self->cache_size = fetch_size;
|
||||||
self->fetch_count = 1;
|
self->fetch_count = 1;
|
||||||
}
|
}
|
||||||
else { /* need to correct */
|
else
|
||||||
|
{ /* need to correct */
|
||||||
|
|
||||||
corrected = TRUE;
|
corrected = TRUE;
|
||||||
|
|
||||||
@ -407,7 +438,8 @@ QueryInfo qi;
|
|||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
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;
|
||||||
@ -416,29 +448,34 @@ QueryInfo qi;
|
|||||||
|
|
||||||
mylog("next_tuple: sending actual fetch (%d) query '%s'\n", fetch_size, fetch);
|
mylog("next_tuple: sending actual fetch (%d) query '%s'\n", fetch_size, fetch);
|
||||||
|
|
||||||
/* don't read ahead for the next tuple (self) ! */
|
/* don't read ahead for the next tuple (self) ! */
|
||||||
qi.row_size = self->cache_size;
|
qi.row_size = self->cache_size;
|
||||||
qi.result_in = self;
|
qi.result_in = self;
|
||||||
qi.cursor = NULL;
|
qi.cursor = NULL;
|
||||||
res = CC_send_query(self->conn, fetch, &qi);
|
res = CC_send_query(self->conn, fetch, &qi);
|
||||||
if (res == NULL) {
|
if (res == NULL)
|
||||||
|
{
|
||||||
self->status = PGRES_FATAL_ERROR;
|
self->status = PGRES_FATAL_ERROR;
|
||||||
QR_set_message(self, "Error fetching next group.");
|
QR_set_message(self, "Error fetching next group.");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
self->inTuples = TRUE;
|
self->inTuples = TRUE;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
mylog("next_tuple: inTuples = true, falling through: fcount = %d, fetch_count = %d\n", self->fcount, self->fetch_count);
|
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;
|
self->fetch_count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! corrected) {
|
if (!corrected)
|
||||||
|
{
|
||||||
self->base = 0;
|
self->base = 0;
|
||||||
self->fcount = 0;
|
self->fcount = 0;
|
||||||
}
|
}
|
||||||
@ -447,107 +484,118 @@ QueryInfo qi;
|
|||||||
sock = CC_get_socket(self->conn);
|
sock = CC_get_socket(self->conn);
|
||||||
self->tupleField = NULL;
|
self->tupleField = NULL;
|
||||||
|
|
||||||
for ( ; ;) {
|
for (;;)
|
||||||
|
{
|
||||||
|
|
||||||
id = SOCK_get_char(sock);
|
id = SOCK_get_char(sock);
|
||||||
|
|
||||||
switch (id) {
|
switch (id)
|
||||||
case 'T': /* Tuples within tuples cannot be handled */
|
{
|
||||||
self->status = PGRES_BAD_RESPONSE;
|
case 'T': /* Tuples within tuples cannot be handled */
|
||||||
QR_set_message(self, "Tuples within tuples cannot be handled");
|
self->status = PGRES_BAD_RESPONSE;
|
||||||
return FALSE;
|
QR_set_message(self, "Tuples within tuples cannot be handled");
|
||||||
case 'B': /* Tuples in binary format */
|
return FALSE;
|
||||||
case 'D': /* Tuples in ASCII format */
|
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);
|
size_t old_size = self->fcount * self->num_fields * sizeof(TupleField);
|
||||||
|
|
||||||
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, old_size + (self->num_fields * sizeof(TupleField) * TUPLE_MALLOC_INC));
|
mylog("REALLOC: old_size = %d\n", old_size);
|
||||||
if ( ! self->backend_tuples) {
|
|
||||||
self->status = PGRES_FATAL_ERROR;
|
self->backend_tuples = (TupleField *) realloc(self->backend_tuples, old_size + (self->num_fields * sizeof(TupleField) * TUPLE_MALLOC_INC));
|
||||||
QR_set_message(self, "Out of memory while reading 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)))
|
||||||
|
{
|
||||||
|
self->status = PGRES_BAD_RESPONSE;
|
||||||
|
QR_set_message(self, "Error reading the tuple");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! QR_read_tuple(self, (char) (id == 0))) {
|
self->fcount++;
|
||||||
self->status = PGRES_BAD_RESPONSE;
|
break; /* continue reading */
|
||||||
QR_set_message(self, "Error reading the tuple");
|
|
||||||
|
|
||||||
|
case 'C': /* End of tuple list */
|
||||||
|
SOCK_get_string(sock, cmdbuffer, MAX_MESSAGE_LEN);
|
||||||
|
QR_set_command(self, cmdbuffer);
|
||||||
|
|
||||||
|
mylog("end of tuple list -- setting inUse to false: this = %u\n", self);
|
||||||
|
|
||||||
|
self->inTuples = FALSE;
|
||||||
|
if (self->fcount > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
qlog(" [ fetched %d rows ]\n", self->fcount);
|
||||||
|
mylog("_next_tuple: 'C' fetch_max && fcount = %d\n", self->fcount);
|
||||||
|
|
||||||
|
/* set to first row */
|
||||||
|
self->tupleField = self->backend_tuples + (offset * self->num_fields);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'E': /* Error */
|
||||||
|
SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
|
||||||
|
QR_set_message(self, msgbuffer);
|
||||||
|
self->status = PGRES_FATAL_ERROR;
|
||||||
|
|
||||||
|
if (!strncmp(msgbuffer, "FATAL", 5))
|
||||||
|
CC_set_no_trans(self->conn);
|
||||||
|
|
||||||
|
qlog("ERROR from backend in next_tuple: '%s'\n", msgbuffer);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
self->fcount++;
|
case 'N': /* Notice */
|
||||||
break; /* continue reading */
|
SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
|
||||||
|
QR_set_message(self, msgbuffer);
|
||||||
|
self->status = PGRES_NONFATAL_ERROR;
|
||||||
|
qlog("NOTICE from backend in next_tuple: '%s'\n", msgbuffer);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
default: /* this should only happen if the backend
|
||||||
case 'C': /* End of tuple list */
|
* dumped core */
|
||||||
SOCK_get_string(sock, cmdbuffer, MAX_MESSAGE_LEN);
|
mylog("QR_next_tuple: Unexpected result from backend: id = '%c' (%d)\n", id, id);
|
||||||
QR_set_command(self, cmdbuffer);
|
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");
|
||||||
mylog("end of tuple list -- setting inUse to false: this = %u\n", self);
|
self->status = PGRES_FATAL_ERROR;
|
||||||
|
|
||||||
self->inTuples = FALSE;
|
|
||||||
if (self->fcount > 0) {
|
|
||||||
|
|
||||||
qlog(" [ fetched %d rows ]\n", self->fcount);
|
|
||||||
mylog("_next_tuple: 'C' fetch_max && fcount = %d\n", self->fcount);
|
|
||||||
|
|
||||||
/* set to first row */
|
|
||||||
self->tupleField = self->backend_tuples + (offset * self->num_fields);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'E': /* Error */
|
|
||||||
SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
|
|
||||||
QR_set_message(self, msgbuffer);
|
|
||||||
self->status = PGRES_FATAL_ERROR;
|
|
||||||
|
|
||||||
if ( ! strncmp(msgbuffer, "FATAL", 5))
|
|
||||||
CC_set_no_trans(self->conn);
|
CC_set_no_trans(self->conn);
|
||||||
|
return FALSE;
|
||||||
qlog("ERROR from backend in next_tuple: '%s'\n", msgbuffer);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
case 'N': /* Notice */
|
|
||||||
SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
|
|
||||||
QR_set_message(self, msgbuffer);
|
|
||||||
self->status = PGRES_NONFATAL_ERROR;
|
|
||||||
qlog("NOTICE from backend in next_tuple: '%s'\n", msgbuffer);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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");
|
|
||||||
self->status = PGRES_FATAL_ERROR;
|
|
||||||
CC_set_no_trans(self->conn);
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char
|
char
|
||||||
QR_read_tuple(QResultClass *self, char binary)
|
QR_read_tuple(QResultClass * self, char binary)
|
||||||
{
|
{
|
||||||
Int2 field_lf;
|
Int2 field_lf;
|
||||||
TupleField *this_tuplefield;
|
TupleField *this_tuplefield;
|
||||||
char bmp, bitmap[MAX_FIELDS]; /* Max. len of the bitmap */
|
char bmp,
|
||||||
Int2 bitmaplen; /* len of the bitmap in bytes */
|
bitmap[MAX_FIELDS]; /* Max. len of the bitmap */
|
||||||
Int2 bitmap_pos;
|
Int2 bitmaplen; /* len of the bitmap in bytes */
|
||||||
Int2 bitcnt;
|
Int2 bitmap_pos;
|
||||||
Int4 len;
|
Int2 bitcnt;
|
||||||
char *buffer;
|
Int4 len;
|
||||||
int num_fields = self->num_fields; /* speed up access */
|
char *buffer;
|
||||||
SocketClass *sock = CC_get_socket(self->conn);
|
int num_fields = self->num_fields; /* speed up access */
|
||||||
ColumnInfoClass *flds;
|
SocketClass *sock = CC_get_socket(self->conn);
|
||||||
|
ColumnInfoClass *flds;
|
||||||
|
|
||||||
|
|
||||||
/* set the current row to read the fields into */
|
/* set the current row to read the fields into */
|
||||||
@ -558,31 +606,36 @@ ColumnInfoClass *flds;
|
|||||||
bitmaplen++;
|
bitmaplen++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
At first the server sends a bitmap that indicates which
|
* At first the server sends a bitmap that indicates which database
|
||||||
database fields are null
|
* fields are null
|
||||||
*/
|
*/
|
||||||
SOCK_get_n_char(sock, bitmap, bitmaplen);
|
SOCK_get_n_char(sock, bitmap, bitmaplen);
|
||||||
|
|
||||||
bitmap_pos = 0;
|
bitmap_pos = 0;
|
||||||
bitcnt = 0;
|
bitcnt = 0;
|
||||||
bmp = bitmap[bitmap_pos];
|
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 */
|
/* Check if the current field is NULL */
|
||||||
if(!(bmp & 0200)) {
|
if (!(bmp & 0200))
|
||||||
|
{
|
||||||
/* YES, it is NULL ! */
|
/* YES, it is NULL ! */
|
||||||
this_tuplefield[field_lf].len = 0;
|
this_tuplefield[field_lf].len = 0;
|
||||||
this_tuplefield[field_lf].value = 0;
|
this_tuplefield[field_lf].value = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NO, the field is not null. so get at first the
|
* NO, the field is not null. so get at first the length of
|
||||||
length of the field (four bytes)
|
* the field (four bytes)
|
||||||
*/
|
*/
|
||||||
len = SOCK_get_int(sock, VARHDRSZ);
|
len = SOCK_get_int(sock, VARHDRSZ);
|
||||||
if (!binary)
|
if (!binary)
|
||||||
len -= VARHDRSZ;
|
len -= VARHDRSZ;
|
||||||
|
|
||||||
buffer = (char *)malloc(len+1);
|
buffer = (char *) malloc(len + 1);
|
||||||
SOCK_get_n_char(sock, buffer, len);
|
SOCK_get_n_char(sock, buffer, len);
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
|
|
||||||
@ -591,27 +644,31 @@ ColumnInfoClass *flds;
|
|||||||
this_tuplefield[field_lf].len = len;
|
this_tuplefield[field_lf].len = len;
|
||||||
this_tuplefield[field_lf].value = buffer;
|
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
|
* This can be used to set the longest length of the column
|
||||||
text fields to use this since a tuple cache is only 100 rows.
|
* for any row in the tuple cache. It would not be accurate
|
||||||
Bpchar can be handled since the strlen of all rows is fixed,
|
* for varchar and text fields to use this since a tuple cache
|
||||||
assuming there are not 100 nulls in a row!
|
* 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;
|
flds = self->fields;
|
||||||
if (flds->display_size[field_lf] < len)
|
if (flds->display_size[field_lf] < len)
|
||||||
flds->display_size[field_lf] = len;
|
flds->display_size[field_lf] = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Now adjust for the next bit to be scanned in the
|
* Now adjust for the next bit to be scanned in the next loop.
|
||||||
next loop.
|
*/
|
||||||
*/
|
|
||||||
bitcnt++;
|
bitcnt++;
|
||||||
if (BYTELEN == bitcnt) {
|
if (BYTELEN == bitcnt)
|
||||||
|
{
|
||||||
bitmap_pos++;
|
bitmap_pos++;
|
||||||
bmp = bitmap[bitmap_pos];
|
bmp = bitmap[bitmap_pos];
|
||||||
bitcnt = 0;
|
bitcnt = 0;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
bmp <<= 1;
|
bmp <<= 1;
|
||||||
}
|
}
|
||||||
self->currTuple++;
|
self->currTuple++;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: qresult.h
|
/* File: qresult.h
|
||||||
*
|
*
|
||||||
* Description: See "qresult.c"
|
* Description: See "qresult.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -17,58 +17,65 @@
|
|||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
#include "tuple.h"
|
#include "tuple.h"
|
||||||
|
|
||||||
enum QueryResultCode_ {
|
enum QueryResultCode_
|
||||||
PGRES_EMPTY_QUERY = 0,
|
{
|
||||||
PGRES_COMMAND_OK, /* a query command that doesn't return */
|
PGRES_EMPTY_QUERY = 0,
|
||||||
/* anything was executed properly by the backend */
|
PGRES_COMMAND_OK, /* a query command that doesn't return */
|
||||||
PGRES_TUPLES_OK, /* a query command that returns tuples */
|
/* anything was executed properly by the backend */
|
||||||
/* was executed properly by the backend, PGresult */
|
PGRES_TUPLES_OK, /* a query command that returns tuples */
|
||||||
/* contains the resulttuples */
|
/* was executed properly by the backend, PGresult */
|
||||||
PGRES_COPY_OUT,
|
/* contains the resulttuples */
|
||||||
PGRES_COPY_IN,
|
PGRES_COPY_OUT,
|
||||||
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the backend */
|
PGRES_COPY_IN,
|
||||||
PGRES_NONFATAL_ERROR,
|
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from
|
||||||
PGRES_FATAL_ERROR,
|
* the backend */
|
||||||
PGRES_FIELDS_OK, /* field information from a query was successful */
|
PGRES_NONFATAL_ERROR,
|
||||||
PGRES_END_TUPLES,
|
PGRES_FATAL_ERROR,
|
||||||
PGRES_INTERNAL_ERROR
|
PGRES_FIELDS_OK, /* field information from a query was
|
||||||
|
* successful */
|
||||||
|
PGRES_END_TUPLES,
|
||||||
|
PGRES_INTERNAL_ERROR
|
||||||
};
|
};
|
||||||
typedef enum QueryResultCode_ QueryResultCode;
|
typedef enum QueryResultCode_ QueryResultCode;
|
||||||
|
|
||||||
|
|
||||||
struct QResultClass_ {
|
struct QResultClass_
|
||||||
ColumnInfoClass *fields; /* the Column information */
|
{
|
||||||
TupleListClass *manual_tuples; /* manual result tuple list */
|
ColumnInfoClass *fields; /* the Column information */
|
||||||
ConnectionClass *conn; /* the connection this result is using (backend) */
|
TupleListClass *manual_tuples; /* manual result tuple list */
|
||||||
|
ConnectionClass *conn; /* the connection this result is using
|
||||||
|
* (backend) */
|
||||||
|
|
||||||
/* Stuff for declare/fetch tuples */
|
/* Stuff for declare/fetch tuples */
|
||||||
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;
|
||||||
int base;
|
int base;
|
||||||
|
|
||||||
int num_fields; /* number of fields in the result */
|
int num_fields; /* number of fields in the result */
|
||||||
int cache_size;
|
int cache_size;
|
||||||
int rowset_size;
|
int rowset_size;
|
||||||
|
|
||||||
QueryResultCode status;
|
QueryResultCode status;
|
||||||
|
|
||||||
char *message;
|
char *message;
|
||||||
char *cursor; /* The name of the cursor for select statements */
|
char *cursor; /* The name of the cursor for select
|
||||||
char *command;
|
* statements */
|
||||||
char *notice;
|
char *command;
|
||||||
|
char *notice;
|
||||||
|
|
||||||
TupleField *backend_tuples; /* data from the backend (the tuple cache) */
|
TupleField *backend_tuples; /* data from the backend (the tuple cache) */
|
||||||
TupleField *tupleField; /* current backend tuple being retrieved */
|
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)
|
#define QR_get_fields(self) (self->fields)
|
||||||
|
|
||||||
|
|
||||||
/* These functions are for retrieving data from the qresult */
|
/* These functions are for retrieving data from the qresult */
|
||||||
#define QR_get_value_manual(self, tupleno, fieldno) (TL_get_fieldval(self->manual_tuples, tupleno, fieldno))
|
#define QR_get_value_manual(self, tupleno, fieldno) (TL_get_fieldval(self->manual_tuples, tupleno, fieldno))
|
||||||
#define QR_get_value_backend(self, fieldno) (self->tupleField[fieldno].value)
|
#define QR_get_value_backend(self, fieldno) (self->tupleField[fieldno].value)
|
||||||
#define QR_get_value_backend_row(self, tupleno, fieldno) ((self->backend_tuples + (tupleno * self->num_fields))[fieldno].value)
|
#define QR_get_value_backend_row(self, tupleno, fieldno) ((self->backend_tuples + (tupleno * self->num_fields))[fieldno].value)
|
||||||
|
|
||||||
@ -76,9 +83,9 @@ struct QResultClass_ {
|
|||||||
#define QR_NumResultCols(self) (CI_get_num_fields(self->fields))
|
#define QR_NumResultCols(self) (CI_get_num_fields(self->fields))
|
||||||
#define QR_get_fieldname(self, fieldno_) (CI_get_fieldname(self->fields, fieldno_))
|
#define QR_get_fieldname(self, fieldno_) (CI_get_fieldname(self->fields, fieldno_))
|
||||||
#define QR_get_fieldsize(self, fieldno_) (CI_get_fieldsize(self->fields, fieldno_))
|
#define QR_get_fieldsize(self, fieldno_) (CI_get_fieldsize(self->fields, fieldno_))
|
||||||
#define QR_get_display_size(self, fieldno_) (CI_get_display_size(self->fields, fieldno_))
|
#define QR_get_display_size(self, fieldno_) (CI_get_display_size(self->fields, fieldno_))
|
||||||
#define QR_get_atttypmod(self, fieldno_) (CI_get_atttypmod(self->fields, fieldno_))
|
#define QR_get_atttypmod(self, fieldno_) (CI_get_atttypmod(self->fields, fieldno_))
|
||||||
#define QR_get_field_type(self, fieldno_) (CI_get_oid(self->fields, fieldno_))
|
#define QR_get_field_type(self, fieldno_) (CI_get_oid(self->fields, fieldno_))
|
||||||
|
|
||||||
/* These functions are used only for manual result sets */
|
/* These functions are used only for manual result sets */
|
||||||
#define QR_get_num_tuples(self) (self->manual_tuples ? TL_get_num_tuples(self->manual_tuples) : self->fcount)
|
#define QR_get_num_tuples(self) (self->manual_tuples ? TL_get_num_tuples(self->manual_tuples) : self->fcount)
|
||||||
@ -99,20 +106,20 @@ struct QResultClass_ {
|
|||||||
|
|
||||||
/* Core Functions */
|
/* Core Functions */
|
||||||
QResultClass *QR_Constructor(void);
|
QResultClass *QR_Constructor(void);
|
||||||
void QR_Destructor(QResultClass *self);
|
void QR_Destructor(QResultClass * self);
|
||||||
char QR_read_tuple(QResultClass *self, char binary);
|
char QR_read_tuple(QResultClass * self, char binary);
|
||||||
int QR_next_tuple(QResultClass *self);
|
int QR_next_tuple(QResultClass * self);
|
||||||
int QR_close(QResultClass *self);
|
int QR_close(QResultClass * self);
|
||||||
char QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor);
|
char QR_fetch_tuples(QResultClass * self, ConnectionClass * conn, char *cursor);
|
||||||
void QR_free_memory(QResultClass *self);
|
void QR_free_memory(QResultClass * self);
|
||||||
void QR_set_command(QResultClass *self, char *msg);
|
void QR_set_command(QResultClass * self, char *msg);
|
||||||
void QR_set_notice(QResultClass *self, char *msg);
|
void QR_set_notice(QResultClass * self, char *msg);
|
||||||
|
|
||||||
void QR_set_num_fields(QResultClass *self, int new_num_fields); /* manual result only */
|
void QR_set_num_fields(QResultClass * self, int new_num_fields); /* manual result only */
|
||||||
|
|
||||||
void QR_inc_base(QResultClass *self, int base_inc);
|
void QR_inc_base(QResultClass * self, int base_inc);
|
||||||
void QR_set_cache_size(QResultClass *self, int cache_size);
|
void QR_set_cache_size(QResultClass * self, int cache_size);
|
||||||
void QR_set_rowset_size(QResultClass *self, int rowset_size);
|
void QR_set_rowset_size(QResultClass * self, int rowset_size);
|
||||||
void QR_set_position(QResultClass *self, int pos);
|
void QR_set_position(QResultClass * self, int pos);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,59 +2,59 @@
|
|||||||
/* Microsoft Developer Studio generated include file. */
|
/* Microsoft Developer Studio generated include file. */
|
||||||
/* Used by psqlodbc.rc */
|
/* Used by psqlodbc.rc */
|
||||||
|
|
||||||
#define IDS_BADDSN 1
|
#define IDS_BADDSN 1
|
||||||
#define IDS_MSGTITLE 2
|
#define IDS_MSGTITLE 2
|
||||||
#define DLG_OPTIONS_DRV 102
|
#define DLG_OPTIONS_DRV 102
|
||||||
#define DLG_OPTIONS_DS 103
|
#define DLG_OPTIONS_DS 103
|
||||||
#define IDC_DSNAME 400
|
#define IDC_DSNAME 400
|
||||||
#define IDC_DSNAMETEXT 401
|
#define IDC_DSNAMETEXT 401
|
||||||
#define IDC_DESC 404
|
#define IDC_DESC 404
|
||||||
#define IDC_SERVER 407
|
#define IDC_SERVER 407
|
||||||
#define IDC_DATABASE 408
|
#define IDC_DATABASE 408
|
||||||
#define DLG_CONFIG 1001
|
#define DLG_CONFIG 1001
|
||||||
#define IDC_PORT 1002
|
#define IDC_PORT 1002
|
||||||
#define IDC_USER 1006
|
#define IDC_USER 1006
|
||||||
#define IDC_PASSWORD 1009
|
#define IDC_PASSWORD 1009
|
||||||
#define DS_READONLY 1011
|
#define DS_READONLY 1011
|
||||||
#define DS_SHOWOIDCOLUMN 1012
|
#define DS_SHOWOIDCOLUMN 1012
|
||||||
#define DS_FAKEOIDINDEX 1013
|
#define DS_FAKEOIDINDEX 1013
|
||||||
#define DRV_COMMLOG 1014
|
#define DRV_COMMLOG 1014
|
||||||
#define IDC_DATASOURCE 1018
|
#define IDC_DATASOURCE 1018
|
||||||
#define DRV_OPTIMIZER 1019
|
#define DRV_OPTIMIZER 1019
|
||||||
#define DS_CONNSETTINGS 1020
|
#define DS_CONNSETTINGS 1020
|
||||||
#define IDC_DRIVER 1021
|
#define IDC_DRIVER 1021
|
||||||
#define DRV_CONNSETTINGS 1031
|
#define DRV_CONNSETTINGS 1031
|
||||||
#define DRV_UNIQUEINDEX 1032
|
#define DRV_UNIQUEINDEX 1032
|
||||||
#define DRV_UNKNOWN_MAX 1035
|
#define DRV_UNKNOWN_MAX 1035
|
||||||
#define DRV_UNKNOWN_DONTKNOW 1036
|
#define DRV_UNKNOWN_DONTKNOW 1036
|
||||||
#define DRV_READONLY 1037
|
#define DRV_READONLY 1037
|
||||||
#define IDC_DESCTEXT 1039
|
#define IDC_DESCTEXT 1039
|
||||||
#define DRV_MSG_LABEL 1040
|
#define DRV_MSG_LABEL 1040
|
||||||
#define DRV_UNKNOWN_LONGEST 1041
|
#define DRV_UNKNOWN_LONGEST 1041
|
||||||
#define DRV_TEXT_LONGVARCHAR 1043
|
#define DRV_TEXT_LONGVARCHAR 1043
|
||||||
#define DRV_UNKNOWNS_LONGVARCHAR 1044
|
#define DRV_UNKNOWNS_LONGVARCHAR 1044
|
||||||
#define DRV_CACHE_SIZE 1045
|
#define DRV_CACHE_SIZE 1045
|
||||||
#define DRV_VARCHAR_SIZE 1046
|
#define DRV_VARCHAR_SIZE 1046
|
||||||
#define DRV_LONGVARCHAR_SIZE 1047
|
#define DRV_LONGVARCHAR_SIZE 1047
|
||||||
#define IDDEFAULTS 1048
|
#define IDDEFAULTS 1048
|
||||||
#define DRV_USEDECLAREFETCH 1049
|
#define DRV_USEDECLAREFETCH 1049
|
||||||
#define DRV_BOOLS_CHAR 1050
|
#define DRV_BOOLS_CHAR 1050
|
||||||
#define DS_SHOWSYSTEMTABLES 1051
|
#define DS_SHOWSYSTEMTABLES 1051
|
||||||
#define DRV_EXTRASYSTABLEPREFIXES 1051
|
#define DRV_EXTRASYSTABLEPREFIXES 1051
|
||||||
#define DS_ROWVERSIONING 1052
|
#define DS_ROWVERSIONING 1052
|
||||||
#define DRV_PARSE 1052
|
#define DRV_PARSE 1052
|
||||||
#define DRV_CANCELASFREESTMT 1053
|
#define DRV_CANCELASFREESTMT 1053
|
||||||
#define IDC_OPTIONS 1054
|
#define IDC_OPTIONS 1054
|
||||||
#define DRV_KSQO 1055
|
#define DRV_KSQO 1055
|
||||||
#define DS_PG64 1057
|
#define DS_PG64 1057
|
||||||
|
|
||||||
/* Next default values for new objects */
|
/* Next default values for new objects */
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 104
|
#define _APS_NEXT_RESOURCE_VALUE 104
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1060
|
#define _APS_NEXT_CONTROL_VALUE 1060
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,14 @@
|
|||||||
/* Module: setup.c
|
/* Module: setup.c
|
||||||
*
|
*
|
||||||
* Description: This module contains the setup functions for
|
* Description: This module contains the setup functions for
|
||||||
* adding/modifying a Data Source in the ODBC.INI portion
|
* adding/modifying a Data Source in the ODBC.INI portion
|
||||||
* of the registry.
|
* of the registry.
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: ConfigDSN
|
* API functions: ConfigDSN
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
|
|
||||||
@ -25,288 +25,313 @@
|
|||||||
|
|
||||||
#define INTFUNC __stdcall
|
#define INTFUNC __stdcall
|
||||||
|
|
||||||
extern HINSTANCE NEAR s_hModule; /* Saved module handle. */
|
extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
|
|
||||||
/* Constants --------------------------------------------------------------- */
|
/* Constants --------------------------------------------------------------- */
|
||||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define MAXPGPATH (255+1)
|
#define MAXPGPATH (255+1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAXKEYLEN (15+1) /* Max keyword length */
|
#define MAXKEYLEN (15+1) /* Max keyword length */
|
||||||
#define MAXDESC (255+1) /* Max description length */
|
#define MAXDESC (255+1) /* Max description length */
|
||||||
#define MAXDSNAME (32+1) /* Max data source name length */
|
#define MAXDSNAME (32+1) /* Max data source name length */
|
||||||
|
|
||||||
|
|
||||||
/* Globals ----------------------------------------------------------------- */
|
/* Globals ----------------------------------------------------------------- */
|
||||||
/* NOTE: All these are used by the dialog procedures */
|
/* NOTE: All these are used by the dialog procedures */
|
||||||
typedef struct tagSETUPDLG {
|
typedef struct tagSETUPDLG
|
||||||
HWND hwndParent; /* Parent window handle */
|
{
|
||||||
LPCSTR lpszDrvr; /* Driver description */
|
HWND hwndParent; /* Parent window handle */
|
||||||
ConnInfo ci;
|
LPCSTR lpszDrvr; /* Driver description */
|
||||||
char szDSN[MAXDSNAME]; /* Original data source name */
|
ConnInfo ci;
|
||||||
BOOL fNewDSN; /* New data source flag */
|
char szDSN[MAXDSNAME]; /* Original data source name */
|
||||||
BOOL fDefault; /* Default data source flag */
|
BOOL fNewDSN; /* New data source flag */
|
||||||
|
BOOL fDefault; /* Default data source flag */
|
||||||
|
|
||||||
} SETUPDLG, FAR *LPSETUPDLG;
|
} SETUPDLG, FAR * LPSETUPDLG;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Prototypes -------------------------------------------------------------- */
|
/* Prototypes -------------------------------------------------------------- */
|
||||||
void INTFUNC CenterDialog(HWND hdlg);
|
void INTFUNC CenterDialog(HWND hdlg);
|
||||||
int CALLBACK ConfigDlgProc(HWND hdlg, WORD wMsg, WPARAM wParam, LPARAM lParam);
|
int CALLBACK ConfigDlgProc(HWND hdlg, WORD wMsg, WPARAM wParam, LPARAM lParam);
|
||||||
void INTFUNC ParseAttributes (LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg);
|
void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg);
|
||||||
BOOL INTFUNC SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
|
BOOL INTFUNC SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
|
||||||
|
|
||||||
|
|
||||||
/* ConfigDSN ---------------------------------------------------------------
|
/* ConfigDSN ---------------------------------------------------------------
|
||||||
Description: ODBC Setup entry point
|
Description: ODBC Setup entry point
|
||||||
This entry point is called by the ODBC Installer
|
This entry point is called by the ODBC Installer
|
||||||
(see file header for more details)
|
(see file header for more details)
|
||||||
Input : hwnd ----------- Parent window handle
|
Input : hwnd ----------- Parent window handle
|
||||||
fRequest ------- Request type (i.e., add, config, or remove)
|
fRequest ------- Request type (i.e., add, config, or remove)
|
||||||
lpszDriver ----- Driver name
|
lpszDriver ----- Driver name
|
||||||
lpszAttributes - data source attribute string
|
lpszAttributes - data source attribute string
|
||||||
Output : TRUE success, FALSE otherwise
|
Output : TRUE success, FALSE otherwise
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
BOOL CALLBACK ConfigDSN (HWND hwnd,
|
BOOL CALLBACK
|
||||||
WORD fRequest,
|
ConfigDSN(HWND hwnd,
|
||||||
LPCSTR lpszDriver,
|
WORD fRequest,
|
||||||
LPCSTR lpszAttributes)
|
LPCSTR lpszDriver,
|
||||||
|
LPCSTR lpszAttributes)
|
||||||
{
|
{
|
||||||
BOOL fSuccess; /* Success/fail flag */
|
BOOL fSuccess; /* Success/fail flag */
|
||||||
GLOBALHANDLE hglbAttr;
|
GLOBALHANDLE hglbAttr;
|
||||||
LPSETUPDLG lpsetupdlg;
|
LPSETUPDLG lpsetupdlg;
|
||||||
|
|
||||||
|
|
||||||
/* Allocate attribute array */
|
/* Allocate attribute array */
|
||||||
hglbAttr = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(SETUPDLG));
|
hglbAttr = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(SETUPDLG));
|
||||||
if (!hglbAttr)
|
if (!hglbAttr)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
lpsetupdlg = (LPSETUPDLG)GlobalLock(hglbAttr);
|
lpsetupdlg = (LPSETUPDLG) GlobalLock(hglbAttr);
|
||||||
|
|
||||||
/* Parse attribute string */
|
/* Parse attribute string */
|
||||||
if (lpszAttributes)
|
if (lpszAttributes)
|
||||||
ParseAttributes(lpszAttributes, lpsetupdlg);
|
ParseAttributes(lpszAttributes, lpsetupdlg);
|
||||||
|
|
||||||
/* Save original data source name */
|
/* Save original data source name */
|
||||||
if (lpsetupdlg->ci.dsn[0])
|
if (lpsetupdlg->ci.dsn[0])
|
||||||
lstrcpy(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn);
|
lstrcpy(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn);
|
||||||
else
|
else
|
||||||
lpsetupdlg->szDSN[0] = '\0';
|
lpsetupdlg->szDSN[0] = '\0';
|
||||||
|
|
||||||
/* Remove data source */
|
/* Remove data source */
|
||||||
if (ODBC_REMOVE_DSN == fRequest) {
|
if (ODBC_REMOVE_DSN == fRequest)
|
||||||
|
{
|
||||||
/* Fail if no data source name was supplied */
|
/* Fail if no data source name was supplied */
|
||||||
if (!lpsetupdlg->ci.dsn[0])
|
if (!lpsetupdlg->ci.dsn[0])
|
||||||
fSuccess = FALSE;
|
fSuccess = FALSE;
|
||||||
|
|
||||||
/* Otherwise remove data source from ODBC.INI */
|
/* Otherwise remove data source from ODBC.INI */
|
||||||
else
|
else
|
||||||
fSuccess = SQLRemoveDSNFromIni(lpsetupdlg->ci.dsn);
|
fSuccess = SQLRemoveDSNFromIni(lpsetupdlg->ci.dsn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add or Configure data source */
|
/* Add or Configure data source */
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
/* Save passed variables for global access (e.g., dialog access) */
|
/* Save passed variables for global access (e.g., dialog access) */
|
||||||
lpsetupdlg->hwndParent = hwnd;
|
lpsetupdlg->hwndParent = hwnd;
|
||||||
lpsetupdlg->lpszDrvr = lpszDriver;
|
lpsetupdlg->lpszDrvr = lpszDriver;
|
||||||
lpsetupdlg->fNewDSN = (ODBC_ADD_DSN == fRequest);
|
lpsetupdlg->fNewDSN = (ODBC_ADD_DSN == fRequest);
|
||||||
lpsetupdlg->fDefault = !lstrcmpi(lpsetupdlg->ci.dsn, INI_DSN);
|
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
|
||||||
/* Display dialog(s) */
|
* supplied)
|
||||||
fSuccess = (IDOK == DialogBoxParam(s_hModule,
|
*/
|
||||||
MAKEINTRESOURCE(DLG_CONFIG),
|
if (hwnd)
|
||||||
hwnd,
|
{
|
||||||
ConfigDlgProc,
|
/* Display dialog(s) */
|
||||||
(LONG)(LPSTR)lpsetupdlg));
|
fSuccess = (IDOK == DialogBoxParam(s_hModule,
|
||||||
}
|
MAKEINTRESOURCE(DLG_CONFIG),
|
||||||
|
hwnd,
|
||||||
|
ConfigDlgProc,
|
||||||
|
(LONG) (LPSTR) lpsetupdlg));
|
||||||
|
}
|
||||||
|
|
||||||
else if (lpsetupdlg->ci.dsn[0])
|
else if (lpsetupdlg->ci.dsn[0])
|
||||||
fSuccess = SetDSNAttributes(hwnd, lpsetupdlg);
|
fSuccess = SetDSNAttributes(hwnd, lpsetupdlg);
|
||||||
else
|
else
|
||||||
fSuccess = FALSE;
|
fSuccess = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalUnlock(hglbAttr);
|
GlobalUnlock(hglbAttr);
|
||||||
GlobalFree(hglbAttr);
|
GlobalFree(hglbAttr);
|
||||||
|
|
||||||
return fSuccess;
|
return fSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CenterDialog ------------------------------------------------------------
|
/* CenterDialog ------------------------------------------------------------
|
||||||
Description: Center the dialog over the frame window
|
Description: Center the dialog over the frame window
|
||||||
Input : hdlg -- Dialog window handle
|
Input : hdlg -- Dialog window handle
|
||||||
Output : None
|
Output : None
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
void INTFUNC CenterDialog(HWND hdlg)
|
void INTFUNC
|
||||||
|
CenterDialog(HWND hdlg)
|
||||||
{
|
{
|
||||||
HWND hwndFrame;
|
HWND hwndFrame;
|
||||||
RECT rcDlg, rcScr, rcFrame;
|
RECT rcDlg,
|
||||||
int cx, cy;
|
rcScr,
|
||||||
|
rcFrame;
|
||||||
|
int cx,
|
||||||
|
cy;
|
||||||
|
|
||||||
hwndFrame = GetParent(hdlg);
|
hwndFrame = GetParent(hdlg);
|
||||||
|
|
||||||
GetWindowRect(hdlg, &rcDlg);
|
GetWindowRect(hdlg, &rcDlg);
|
||||||
cx = rcDlg.right - rcDlg.left;
|
cx = rcDlg.right - rcDlg.left;
|
||||||
cy = rcDlg.bottom - rcDlg.top;
|
cy = rcDlg.bottom - rcDlg.top;
|
||||||
|
|
||||||
GetClientRect(hwndFrame, &rcFrame);
|
GetClientRect(hwndFrame, &rcFrame);
|
||||||
ClientToScreen(hwndFrame, (LPPOINT)(&rcFrame.left));
|
ClientToScreen(hwndFrame, (LPPOINT) (&rcFrame.left));
|
||||||
ClientToScreen(hwndFrame, (LPPOINT)(&rcFrame.right));
|
ClientToScreen(hwndFrame, (LPPOINT) (&rcFrame.right));
|
||||||
rcDlg.top = rcFrame.top + (((rcFrame.bottom - rcFrame.top) - cy) >> 1);
|
rcDlg.top = rcFrame.top + (((rcFrame.bottom - rcFrame.top) - cy) >> 1);
|
||||||
rcDlg.left = rcFrame.left + (((rcFrame.right - rcFrame.left) - cx) >> 1);
|
rcDlg.left = rcFrame.left + (((rcFrame.right - rcFrame.left) - cx) >> 1);
|
||||||
rcDlg.bottom = rcDlg.top + cy;
|
rcDlg.bottom = rcDlg.top + cy;
|
||||||
rcDlg.right = rcDlg.left + cx;
|
rcDlg.right = rcDlg.left + cx;
|
||||||
|
|
||||||
GetWindowRect(GetDesktopWindow(), &rcScr);
|
GetWindowRect(GetDesktopWindow(), &rcScr);
|
||||||
if (rcDlg.bottom > rcScr.bottom)
|
if (rcDlg.bottom > rcScr.bottom)
|
||||||
{
|
{
|
||||||
rcDlg.bottom = rcScr.bottom;
|
rcDlg.bottom = rcScr.bottom;
|
||||||
rcDlg.top = rcDlg.bottom - cy;
|
rcDlg.top = rcDlg.bottom - cy;
|
||||||
}
|
}
|
||||||
if (rcDlg.right > rcScr.right)
|
if (rcDlg.right > rcScr.right)
|
||||||
{
|
{
|
||||||
rcDlg.right = rcScr.right;
|
rcDlg.right = rcScr.right;
|
||||||
rcDlg.left = rcDlg.right - cx;
|
rcDlg.left = rcDlg.right - cx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rcDlg.left < 0) rcDlg.left = 0;
|
if (rcDlg.left < 0)
|
||||||
if (rcDlg.top < 0) rcDlg.top = 0;
|
rcDlg.left = 0;
|
||||||
|
if (rcDlg.top < 0)
|
||||||
|
rcDlg.top = 0;
|
||||||
|
|
||||||
MoveWindow(hdlg, rcDlg.left, rcDlg.top, cx, cy, TRUE);
|
MoveWindow(hdlg, rcDlg.left, rcDlg.top, cx, cy, TRUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ConfigDlgProc -----------------------------------------------------------
|
/* ConfigDlgProc -----------------------------------------------------------
|
||||||
Description: Manage add data source name dialog
|
Description: Manage add data source name dialog
|
||||||
Input : hdlg --- Dialog window handle
|
Input : hdlg --- Dialog window handle
|
||||||
wMsg --- Message
|
wMsg --- Message
|
||||||
wParam - Message parameter
|
wParam - Message parameter
|
||||||
lParam - Message parameter
|
lParam - Message parameter
|
||||||
Output : TRUE if message processed, FALSE otherwise
|
Output : TRUE if message processed, FALSE otherwise
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
int CALLBACK ConfigDlgProc(HWND hdlg,
|
int CALLBACK
|
||||||
WORD wMsg,
|
ConfigDlgProc(HWND hdlg,
|
||||||
WPARAM wParam,
|
WORD wMsg,
|
||||||
LPARAM lParam)
|
WPARAM wParam,
|
||||||
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (wMsg) {
|
switch (wMsg)
|
||||||
/* Initialize the dialog */
|
|
||||||
case WM_INITDIALOG:
|
|
||||||
{
|
{
|
||||||
LPSETUPDLG lpsetupdlg = (LPSETUPDLG) lParam;
|
/* Initialize the dialog */
|
||||||
ConnInfo *ci = &lpsetupdlg->ci;
|
case WM_INITDIALOG:
|
||||||
|
|
||||||
/* Hide the driver connect message */
|
|
||||||
ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE);
|
|
||||||
|
|
||||||
SetWindowLong(hdlg, DWL_USER, lParam);
|
|
||||||
CenterDialog(hdlg); /* Center dialog */
|
|
||||||
|
|
||||||
/* NOTE: Values supplied in the attribute string will always */
|
|
||||||
/* override settings in ODBC.INI */
|
|
||||||
|
|
||||||
/* Get the rest of the common attributes */
|
|
||||||
getDSNinfo(ci, CONN_DONT_OVERWRITE);
|
|
||||||
|
|
||||||
/* Fill in any defaults */
|
|
||||||
getDSNdefaults(ci);
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialize dialog fields */
|
|
||||||
SetDlgStuff(hdlg, ci);
|
|
||||||
|
|
||||||
|
|
||||||
if (lpsetupdlg->fDefault) {
|
|
||||||
EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
|
|
||||||
EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
SendDlgItemMessage(hdlg, IDC_DSNAME,
|
|
||||||
EM_LIMITTEXT, (WPARAM)(MAXDSNAME-1), 0L);
|
|
||||||
|
|
||||||
SendDlgItemMessage(hdlg, IDC_DESC,
|
|
||||||
EM_LIMITTEXT, (WPARAM)(MAXDESC-1), 0L);
|
|
||||||
return TRUE; /* Focus was not set */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Process buttons */
|
|
||||||
case WM_COMMAND:
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
char szItem[MAXDSNAME]; /* Edit control text */
|
LPSETUPDLG lpsetupdlg = (LPSETUPDLG) lParam;
|
||||||
|
ConnInfo *ci = &lpsetupdlg->ci;
|
||||||
|
|
||||||
/* Enable/disable the OK button */
|
/* Hide the driver connect message */
|
||||||
EnableWindow(GetDlgItem(hdlg, IDOK),
|
ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE);
|
||||||
GetDlgItemText(hdlg, IDC_DSNAME,
|
|
||||||
szItem, sizeof(szItem)));
|
|
||||||
|
|
||||||
return TRUE;
|
SetWindowLong(hdlg, DWL_USER, lParam);
|
||||||
|
CenterDialog(hdlg); /* Center dialog */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: Values supplied in the attribute string will
|
||||||
|
* always
|
||||||
|
*/
|
||||||
|
/* override settings in ODBC.INI */
|
||||||
|
|
||||||
|
/* Get the rest of the common attributes */
|
||||||
|
getDSNinfo(ci, CONN_DONT_OVERWRITE);
|
||||||
|
|
||||||
|
/* Fill in any defaults */
|
||||||
|
getDSNdefaults(ci);
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize dialog fields */
|
||||||
|
SetDlgStuff(hdlg, ci);
|
||||||
|
|
||||||
|
|
||||||
|
if (lpsetupdlg->fDefault)
|
||||||
|
{
|
||||||
|
EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
|
||||||
|
EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendDlgItemMessage(hdlg, IDC_DSNAME,
|
||||||
|
EM_LIMITTEXT, (WPARAM) (MAXDSNAME - 1), 0L);
|
||||||
|
|
||||||
|
SendDlgItemMessage(hdlg, IDC_DESC,
|
||||||
|
EM_LIMITTEXT, (WPARAM) (MAXDESC - 1), 0L);
|
||||||
|
return TRUE; /* Focus was not set */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Process buttons */
|
||||||
|
case WM_COMMAND:
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
char szItem[MAXDSNAME]; /* Edit control text */
|
||||||
|
|
||||||
|
/* Enable/disable the OK button */
|
||||||
|
EnableWindow(GetDlgItem(hdlg, IDOK),
|
||||||
|
GetDlgItemText(hdlg, IDC_DSNAME,
|
||||||
|
szItem, sizeof(szItem)));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Accept results */
|
||||||
|
case IDOK:
|
||||||
|
{
|
||||||
|
LPSETUPDLG lpsetupdlg;
|
||||||
|
|
||||||
|
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
|
||||||
|
/* Retrieve dialog values */
|
||||||
|
if (!lpsetupdlg->fDefault)
|
||||||
|
GetDlgItemText(hdlg, IDC_DSNAME,
|
||||||
|
lpsetupdlg->ci.dsn,
|
||||||
|
sizeof(lpsetupdlg->ci.dsn));
|
||||||
|
|
||||||
|
|
||||||
|
/* Get Dialog Values */
|
||||||
|
GetDlgStuff(hdlg, &lpsetupdlg->ci);
|
||||||
|
|
||||||
|
/* Update ODBC.INI */
|
||||||
|
SetDSNAttributes(hdlg, lpsetupdlg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return to caller */
|
||||||
|
case IDCANCEL:
|
||||||
|
EndDialog(hdlg, wParam);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
case IDC_DRIVER:
|
||||||
|
|
||||||
|
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
||||||
|
hdlg, driver_optionsProc, (LPARAM) NULL);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
case IDC_DATASOURCE:
|
||||||
|
{
|
||||||
|
LPSETUPDLG lpsetupdlg;
|
||||||
|
|
||||||
|
lpsetupdlg = (LPSETUPDLG) GetWindowLong(hdlg, DWL_USER);
|
||||||
|
|
||||||
|
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
||||||
|
hdlg, ds_optionsProc, (LPARAM) & lpsetupdlg->ci);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Accept results */
|
|
||||||
case IDOK:
|
|
||||||
{
|
|
||||||
LPSETUPDLG lpsetupdlg;
|
|
||||||
|
|
||||||
lpsetupdlg = (LPSETUPDLG)GetWindowLong(hdlg, DWL_USER);
|
|
||||||
/* Retrieve dialog values */
|
|
||||||
if (!lpsetupdlg->fDefault)
|
|
||||||
GetDlgItemText(hdlg, IDC_DSNAME,
|
|
||||||
lpsetupdlg->ci.dsn,
|
|
||||||
sizeof(lpsetupdlg->ci.dsn));
|
|
||||||
|
|
||||||
|
|
||||||
/* Get Dialog Values */
|
|
||||||
GetDlgStuff(hdlg, &lpsetupdlg->ci);
|
|
||||||
|
|
||||||
/* Update ODBC.INI */
|
|
||||||
SetDSNAttributes(hdlg, lpsetupdlg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return to caller */
|
|
||||||
case IDCANCEL:
|
|
||||||
EndDialog(hdlg, wParam);
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case IDC_DRIVER:
|
|
||||||
|
|
||||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
|
|
||||||
hdlg, driver_optionsProc, (LPARAM) NULL);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
case IDC_DATASOURCE:
|
|
||||||
{
|
|
||||||
LPSETUPDLG lpsetupdlg;
|
|
||||||
|
|
||||||
lpsetupdlg = (LPSETUPDLG)GetWindowLong(hdlg, DWL_USER);
|
|
||||||
|
|
||||||
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
|
|
||||||
hdlg, ds_optionsProc, (LPARAM) &lpsetupdlg->ci);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Message not processed */
|
/* Message not processed */
|
||||||
@ -315,97 +340,98 @@ int CALLBACK ConfigDlgProc(HWND hdlg,
|
|||||||
|
|
||||||
|
|
||||||
/* ParseAttributes ---------------------------------------------------------
|
/* ParseAttributes ---------------------------------------------------------
|
||||||
Description: Parse attribute string moving values into the aAttr array
|
Description: Parse attribute string moving values into the aAttr array
|
||||||
Input : lpszAttributes - Pointer to attribute string
|
Input : lpszAttributes - Pointer to attribute string
|
||||||
Output : None (global aAttr normally updated)
|
Output : None (global aAttr normally updated)
|
||||||
--------------------------------------------------------------------------*/
|
--------------------------------------------------------------------------*/
|
||||||
void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
|
void INTFUNC
|
||||||
|
ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
|
||||||
{
|
{
|
||||||
LPCSTR lpsz;
|
LPCSTR lpsz;
|
||||||
LPCSTR lpszStart;
|
LPCSTR lpszStart;
|
||||||
char aszKey[MAXKEYLEN];
|
char aszKey[MAXKEYLEN];
|
||||||
int cbKey;
|
int cbKey;
|
||||||
char value[MAXPGPATH];
|
char value[MAXPGPATH];
|
||||||
|
|
||||||
memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
|
memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
|
||||||
|
|
||||||
for (lpsz=lpszAttributes; *lpsz; lpsz++)
|
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
|
||||||
lpszStart = lpsz;
|
* be terminated by an equals */
|
||||||
for (;; lpsz++)
|
lpszStart = lpsz;
|
||||||
{
|
for (;; lpsz++)
|
||||||
if (!*lpsz)
|
{
|
||||||
return; /* No key was found */
|
if (!*lpsz)
|
||||||
else if (*lpsz == '=')
|
return; /* No key was found */
|
||||||
break; /* Valid key found */
|
else if (*lpsz == '=')
|
||||||
}
|
break; /* Valid key found */
|
||||||
/* Determine the key's index in the key table (-1 if not found) */
|
}
|
||||||
cbKey = lpsz - lpszStart;
|
/* Determine the key's index in the key table (-1 if not found) */
|
||||||
if (cbKey < sizeof(aszKey))
|
cbKey = lpsz - lpszStart;
|
||||||
{
|
if (cbKey < sizeof(aszKey))
|
||||||
|
{
|
||||||
|
|
||||||
_fmemcpy(aszKey, lpszStart, cbKey);
|
_fmemcpy(aszKey, lpszStart, cbKey);
|
||||||
aszKey[cbKey] = '\0';
|
aszKey[cbKey] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Locate end of key value */
|
/* Locate end of key value */
|
||||||
lpszStart = ++lpsz;
|
lpszStart = ++lpsz;
|
||||||
for (; *lpsz; lpsz++);
|
for (; *lpsz; lpsz++);
|
||||||
|
|
||||||
|
|
||||||
/* lpsetupdlg->aAttr[iElement].fSupplied = TRUE; */
|
/* lpsetupdlg->aAttr[iElement].fSupplied = TRUE; */
|
||||||
_fmemcpy(value, lpszStart, MIN(lpsz-lpszStart+1, MAXPGPATH));
|
_fmemcpy(value, lpszStart, MIN(lpsz - lpszStart + 1, MAXPGPATH));
|
||||||
|
|
||||||
mylog("aszKey='%s', value='%s'\n", aszKey, value);
|
mylog("aszKey='%s', value='%s'\n", aszKey, value);
|
||||||
|
|
||||||
/* Copy the appropriate value to the conninfo */
|
/* Copy the appropriate value to the conninfo */
|
||||||
copyAttributes(&lpsetupdlg->ci, aszKey, value);
|
copyAttributes(&lpsetupdlg->ci, aszKey, value);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* SetDSNAttributes --------------------------------------------------------
|
/* SetDSNAttributes --------------------------------------------------------
|
||||||
Description: Write data source attributes to ODBC.INI
|
Description: Write data source attributes to ODBC.INI
|
||||||
Input : hwnd - Parent window handle (plus globals)
|
Input : hwnd - Parent window handle (plus globals)
|
||||||
Output : TRUE if successful, FALSE otherwise
|
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 */
|
LPCSTR lpszDSN; /* Pointer to data source name */
|
||||||
|
|
||||||
lpszDSN = lpsetupdlg->ci.dsn;
|
lpszDSN = lpsetupdlg->ci.dsn;
|
||||||
|
|
||||||
/* Validate arguments */
|
/* Validate arguments */
|
||||||
if (lpsetupdlg->fNewDSN && !*lpsetupdlg->ci.dsn)
|
if (lpsetupdlg->fNewDSN && !*lpsetupdlg->ci.dsn)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Write the data source name */
|
/* Write the data source name */
|
||||||
if (!SQLWriteDSNToIni(lpszDSN, lpsetupdlg->lpszDrvr))
|
if (!SQLWriteDSNToIni(lpszDSN, lpsetupdlg->lpszDrvr))
|
||||||
{
|
{
|
||||||
if (hwndParent)
|
if (hwndParent)
|
||||||
{
|
{
|
||||||
char szBuf[MAXPGPATH];
|
char szBuf[MAXPGPATH];
|
||||||
char szMsg[MAXPGPATH];
|
char szMsg[MAXPGPATH];
|
||||||
|
|
||||||
LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf));
|
LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf));
|
||||||
wsprintf(szMsg, szBuf, lpszDSN);
|
wsprintf(szMsg, szBuf, lpszDSN);
|
||||||
LoadString(s_hModule, IDS_MSGTITLE, szBuf, sizeof(szBuf));
|
LoadString(s_hModule, IDS_MSGTITLE, szBuf, sizeof(szBuf));
|
||||||
MessageBox(hwndParent, szMsg, szBuf, MB_ICONEXCLAMATION | MB_OK);
|
MessageBox(hwndParent, szMsg, szBuf, MB_ICONEXCLAMATION | MB_OK);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Update ODBC.INI */
|
/* Update ODBC.INI */
|
||||||
writeDSNinfo(&lpsetupdlg->ci);
|
writeDSNinfo(&lpsetupdlg->ci);
|
||||||
|
|
||||||
|
|
||||||
/* If the data source name has changed, remove the old name */
|
/* If the data source name has changed, remove the old name */
|
||||||
if (lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn))
|
if (lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn))
|
||||||
{
|
SQLRemoveDSNFromIni(lpsetupdlg->szDSN);
|
||||||
SQLRemoveDSNFromIni(lpsetupdlg->szDSN);
|
return TRUE;
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* Module: socket.c
|
/* Module: socket.c
|
||||||
*
|
*
|
||||||
* Description: This module contains functions for low level socket
|
* Description: This module contains functions for low level socket
|
||||||
* operations (connecting/reading/writing to the backend)
|
* operations (connecting/reading/writing to the backend)
|
||||||
*
|
*
|
||||||
* Classes: SocketClass (Functions prefix: "SOCK_")
|
* Classes: SocketClass (Functions prefix: "SOCK_")
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h> /* for memset */
|
#include <string.h> /* for memset */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern GLOBAL_VALUES globals;
|
extern GLOBAL_VALUES globals;
|
||||||
@ -36,7 +36,7 @@ extern GLOBAL_VALUES globals;
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_clear_error(SocketClass *self)
|
SOCK_clear_error(SocketClass * self)
|
||||||
{
|
{
|
||||||
self->errornumber = 0;
|
self->errornumber = 0;
|
||||||
self->errormsg = NULL;
|
self->errormsg = NULL;
|
||||||
@ -45,38 +45,40 @@ SOCK_clear_error(SocketClass *self)
|
|||||||
SocketClass *
|
SocketClass *
|
||||||
SOCK_Constructor()
|
SOCK_Constructor()
|
||||||
{
|
{
|
||||||
SocketClass *rv;
|
SocketClass *rv;
|
||||||
|
|
||||||
rv = (SocketClass *) malloc(sizeof(SocketClass));
|
rv = (SocketClass *) malloc(sizeof(SocketClass));
|
||||||
|
|
||||||
if (rv != NULL) {
|
if (rv != NULL)
|
||||||
rv->socket = (SOCKETFD) -1;
|
{
|
||||||
|
rv->socket = (SOCKETFD) - 1;
|
||||||
rv->buffer_filled_in = 0;
|
rv->buffer_filled_in = 0;
|
||||||
rv->buffer_filled_out = 0;
|
rv->buffer_filled_out = 0;
|
||||||
rv->buffer_read_in = 0;
|
rv->buffer_read_in = 0;
|
||||||
|
|
||||||
rv->buffer_in = (unsigned char *) malloc(globals.socket_buffersize);
|
rv->buffer_in = (unsigned char *) malloc(globals.socket_buffersize);
|
||||||
if ( ! rv->buffer_in)
|
if (!rv->buffer_in)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
rv->buffer_out = (unsigned char *) malloc(globals.socket_buffersize);
|
rv->buffer_out = (unsigned char *) malloc(globals.socket_buffersize);
|
||||||
if ( ! rv->buffer_out)
|
if (!rv->buffer_out)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
rv->errormsg = NULL;
|
rv->errormsg = NULL;
|
||||||
rv->errornumber = 0;
|
rv->errornumber = 0;
|
||||||
|
|
||||||
rv->reverse = FALSE;
|
rv->reverse = FALSE;
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_Destructor(SocketClass *self)
|
SOCK_Destructor(SocketClass * self)
|
||||||
{
|
{
|
||||||
if (self->socket != -1) {
|
if (self->socket != -1)
|
||||||
if ( ! shutdown(self->socket, 2)) /* no sends or receives */
|
{
|
||||||
|
if (!shutdown(self->socket, 2)) /* no sends or receives */
|
||||||
{
|
{
|
||||||
SOCK_put_char(self, 'X');
|
SOCK_put_char(self, 'X');
|
||||||
SOCK_flush_output(self);
|
SOCK_flush_output(self);
|
||||||
@ -96,27 +98,30 @@ SOCK_Destructor(SocketClass *self)
|
|||||||
|
|
||||||
|
|
||||||
char
|
char
|
||||||
SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname)
|
SOCK_connect_to(SocketClass * self, unsigned short port, char *hostname)
|
||||||
{
|
{
|
||||||
struct hostent *host;
|
struct hostent *host;
|
||||||
struct sockaddr_in sadr;
|
struct sockaddr_in sadr;
|
||||||
unsigned long iaddr;
|
unsigned long iaddr;
|
||||||
|
|
||||||
if (self->socket != -1) {
|
if (self->socket != -1)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_ALREADY_CONNECTED;
|
self->errornumber = SOCKET_ALREADY_CONNECTED;
|
||||||
self->errormsg = "Socket is already connected";
|
self->errormsg = "Socket is already connected";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset((char *)&sadr, 0, sizeof(sadr));
|
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);
|
iaddr = inet_addr(hostname);
|
||||||
if (iaddr == INADDR_NONE) {
|
if (iaddr == INADDR_NONE)
|
||||||
|
{
|
||||||
host = gethostbyname(hostname);
|
host = gethostbyname(hostname);
|
||||||
if (host == NULL) {
|
if (host == NULL)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_HOST_NOT_FOUND;
|
self->errornumber = SOCKET_HOST_NOT_FOUND;
|
||||||
self->errormsg = "Could not resolve hostname.";
|
self->errormsg = "Could not resolve hostname.";
|
||||||
return 0;
|
return 0;
|
||||||
@ -124,25 +129,27 @@ unsigned long iaddr;
|
|||||||
memcpy(&(sadr.sin_addr), host->h_addr, host->h_length);
|
memcpy(&(sadr.sin_addr), host->h_addr, host->h_length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
memcpy(&(sadr.sin_addr), (struct in_addr *) &iaddr, sizeof(iaddr));
|
memcpy(&(sadr.sin_addr), (struct in_addr *) & iaddr, sizeof(iaddr));
|
||||||
|
|
||||||
sadr.sin_family = AF_INET;
|
sadr.sin_family = AF_INET;
|
||||||
sadr.sin_port = htons(port);
|
sadr.sin_port = htons(port);
|
||||||
|
|
||||||
self->socket = socket(AF_INET, SOCK_STREAM, 0);
|
self->socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (self->socket == -1) {
|
if (self->socket == -1)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_COULD_NOT_CREATE_SOCKET;
|
self->errornumber = SOCKET_COULD_NOT_CREATE_SOCKET;
|
||||||
self->errormsg = "Could not create Socket.";
|
self->errormsg = "Could not create Socket.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( connect(self->socket, (struct sockaddr *)&(sadr),
|
if (connect(self->socket, (struct sockaddr *) & (sadr),
|
||||||
sizeof(sadr)) < 0) {
|
sizeof(sadr)) < 0)
|
||||||
|
{
|
||||||
|
|
||||||
self->errornumber = SOCKET_COULD_NOT_CONNECT;
|
self->errornumber = SOCKET_COULD_NOT_CONNECT;
|
||||||
self->errormsg = "Could not connect to remote socket.";
|
self->errormsg = "Could not connect to remote socket.";
|
||||||
closesocket(self->socket);
|
closesocket(self->socket);
|
||||||
self->socket = (SOCKETFD) -1;
|
self->socket = (SOCKETFD) - 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -150,125 +157,130 @@ unsigned long iaddr;
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_get_n_char(SocketClass *self, char *buffer, int len)
|
SOCK_get_n_char(SocketClass * self, char *buffer, int len)
|
||||||
{
|
{
|
||||||
int lf;
|
int lf;
|
||||||
|
|
||||||
if ( ! buffer) {
|
if (!buffer)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
||||||
self->errormsg = "get_n_char was called with NULL-Pointer";
|
self->errormsg = "get_n_char was called with NULL-Pointer";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(lf=0; lf < len; lf++)
|
for (lf = 0; lf < len; lf++)
|
||||||
buffer[lf] = SOCK_get_next_byte(self);
|
buffer[lf] = SOCK_get_next_byte(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_put_n_char(SocketClass *self, char *buffer, int len)
|
SOCK_put_n_char(SocketClass * self, char *buffer, int len)
|
||||||
{
|
{
|
||||||
int lf;
|
int lf;
|
||||||
|
|
||||||
if ( ! buffer) {
|
if (!buffer)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
self->errornumber = SOCKET_NULLPOINTER_PARAMETER;
|
||||||
self->errormsg = "put_n_char was called with NULL-Pointer";
|
self->errormsg = "put_n_char was called with NULL-Pointer";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(lf=0; lf < len; lf++)
|
for (lf = 0; lf < len; lf++)
|
||||||
SOCK_put_next_byte(self, (unsigned char)buffer[lf]);
|
SOCK_put_next_byte(self, (unsigned char) buffer[lf]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* bufsize must include room for the null terminator
|
/* bufsize must include room for the null terminator
|
||||||
will read at most bufsize-1 characters + null.
|
will read at most bufsize-1 characters + null.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
SOCK_get_string(SocketClass *self, char *buffer, int bufsize)
|
SOCK_get_string(SocketClass * self, char *buffer, int bufsize)
|
||||||
{
|
{
|
||||||
register int lf = 0;
|
register int lf = 0;
|
||||||
|
|
||||||
for (lf = 0; lf < bufsize; lf++)
|
for (lf = 0; lf < bufsize; lf++)
|
||||||
if ( ! (buffer[lf] = SOCK_get_next_byte(self)))
|
if (!(buffer[lf] = SOCK_get_next_byte(self)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buffer[bufsize-1] = '\0';
|
buffer[bufsize - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_put_string(SocketClass *self, char *string)
|
SOCK_put_string(SocketClass * self, char *string)
|
||||||
{
|
{
|
||||||
register int lf;
|
register int lf;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = strlen(string)+1;
|
len = strlen(string) + 1;
|
||||||
|
|
||||||
for(lf = 0; lf < len; lf++)
|
for (lf = 0; lf < len; lf++)
|
||||||
SOCK_put_next_byte(self, (unsigned char)string[lf]);
|
SOCK_put_next_byte(self, (unsigned char) string[lf]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
SOCK_get_int(SocketClass *self, short len)
|
SOCK_get_int(SocketClass * self, short len)
|
||||||
{
|
{
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
|
||||||
switch (len) {
|
switch (len)
|
||||||
case 2:
|
{
|
||||||
SOCK_get_n_char(self, buf, len);
|
case 2:
|
||||||
if (self->reverse)
|
SOCK_get_n_char(self, buf, len);
|
||||||
return *((unsigned short *) buf);
|
if (self->reverse)
|
||||||
else
|
return *((unsigned short *) buf);
|
||||||
return ntohs( *((unsigned short *) buf) );
|
else
|
||||||
|
return ntohs(*((unsigned short *) buf));
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
SOCK_get_n_char(self, buf, len);
|
SOCK_get_n_char(self, buf, len);
|
||||||
if (self->reverse)
|
if (self->reverse)
|
||||||
return *((unsigned int *) buf);
|
return *((unsigned int *) buf);
|
||||||
else
|
else
|
||||||
return ntohl( *((unsigned int *) buf) );
|
return ntohl(*((unsigned int *) buf));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
self->errornumber = SOCKET_GET_INT_WRONG_LENGTH;
|
self->errornumber = SOCKET_GET_INT_WRONG_LENGTH;
|
||||||
self->errormsg = "Cannot read ints of that length";
|
self->errormsg = "Cannot read ints of that length";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_put_int(SocketClass *self, int value, short len)
|
SOCK_put_int(SocketClass * self, int value, short len)
|
||||||
{
|
{
|
||||||
unsigned int rv;
|
unsigned int rv;
|
||||||
|
|
||||||
switch (len) {
|
switch (len)
|
||||||
case 2:
|
{
|
||||||
rv = self->reverse ? value : htons( (unsigned short) value);
|
case 2:
|
||||||
SOCK_put_n_char(self, (char *) &rv, 2);
|
rv = self->reverse ? value : htons((unsigned short) value);
|
||||||
return;
|
SOCK_put_n_char(self, (char *) &rv, 2);
|
||||||
|
return;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
rv = self->reverse ? value : htonl( (unsigned int) value);
|
rv = self->reverse ? value : htonl((unsigned int) value);
|
||||||
SOCK_put_n_char(self, (char *) &rv, 4);
|
SOCK_put_n_char(self, (char *) &rv, 4);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
self->errornumber = SOCKET_PUT_INT_WRONG_LENGTH;
|
self->errornumber = SOCKET_PUT_INT_WRONG_LENGTH;
|
||||||
self->errormsg = "Cannot write ints of that length";
|
self->errormsg = "Cannot write ints of that length";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_flush_output(SocketClass *self)
|
SOCK_flush_output(SocketClass * self)
|
||||||
{
|
{
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
written = send(self->socket, (char *)self->buffer_out, self->buffer_filled_out, 0);
|
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->errornumber = SOCKET_WRITE_ERROR;
|
||||||
self->errormsg = "Could not flush socket buffer.";
|
self->errormsg = "Could not flush socket buffer.";
|
||||||
}
|
}
|
||||||
@ -276,24 +288,27 @@ int written;
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char
|
unsigned char
|
||||||
SOCK_get_next_byte(SocketClass *self)
|
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 -> */
|
/* there are no more bytes left in the buffer -> */
|
||||||
/* reload the buffer */
|
/* reload the buffer */
|
||||||
|
|
||||||
self->buffer_read_in = 0;
|
self->buffer_read_in = 0;
|
||||||
self->buffer_filled_in = recv(self->socket, (char *)self->buffer_in, globals.socket_buffersize, 0);
|
self->buffer_filled_in = recv(self->socket, (char *) self->buffer_in, globals.socket_buffersize, 0);
|
||||||
|
|
||||||
mylog("read %d, global_socket_buffersize=%d\n", self->buffer_filled_in, globals.socket_buffersize);
|
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->errornumber = SOCKET_READ_ERROR;
|
||||||
self->errormsg = "Error while reading from the socket.";
|
self->errormsg = "Error while reading from the socket.";
|
||||||
self->buffer_filled_in = 0;
|
self->buffer_filled_in = 0;
|
||||||
}
|
}
|
||||||
if (self->buffer_filled_in == 0) {
|
if (self->buffer_filled_in == 0)
|
||||||
|
{
|
||||||
self->errornumber = SOCKET_CLOSED;
|
self->errornumber = SOCKET_CLOSED;
|
||||||
self->errormsg = "Socket has been closed.";
|
self->errormsg = "Socket has been closed.";
|
||||||
self->buffer_filled_in = 0;
|
self->buffer_filled_in = 0;
|
||||||
@ -304,16 +319,18 @@ SOCK_get_next_byte(SocketClass *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SOCK_put_next_byte(SocketClass *self, unsigned char next_byte)
|
SOCK_put_next_byte(SocketClass * self, unsigned char next_byte)
|
||||||
{
|
{
|
||||||
int bytes_sent;
|
int bytes_sent;
|
||||||
|
|
||||||
self->buffer_out[self->buffer_filled_out++] = next_byte;
|
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 */
|
/* buffer is full, so write it out */
|
||||||
bytes_sent = send(self->socket, (char *)self->buffer_out, globals.socket_buffersize, 0);
|
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->errornumber = SOCKET_WRITE_ERROR;
|
||||||
self->errormsg = "Error while writing to the socket.";
|
self->errormsg = "Error while writing to the socket.";
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: socket.h
|
/* File: socket.h
|
||||||
*
|
*
|
||||||
* Description: See "socket.c"
|
* Description: See "socket.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -25,10 +25,11 @@
|
|||||||
#define closesocket(xxx) close(xxx)
|
#define closesocket(xxx) close(xxx)
|
||||||
#define SOCKETFD int
|
#define SOCKETFD int
|
||||||
|
|
||||||
#ifndef INADDR_NONE
|
#ifndef INADDR_NONE
|
||||||
#ifndef _IN_ADDR_T
|
#ifndef _IN_ADDR_T
|
||||||
#define _IN_ADDR_T
|
#define _IN_ADDR_T
|
||||||
typedef unsigned int in_addr_t;
|
typedef unsigned int in_addr_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#define INADDR_NONE ((in_addr_t)-1)
|
#define INADDR_NONE ((in_addr_t)-1)
|
||||||
#endif
|
#endif
|
||||||
@ -52,20 +53,22 @@ typedef unsigned int in_addr_t;
|
|||||||
#define SOCKET_CLOSED 10
|
#define SOCKET_CLOSED 10
|
||||||
|
|
||||||
|
|
||||||
struct SocketClass_ {
|
struct SocketClass_
|
||||||
|
{
|
||||||
|
|
||||||
int buffer_filled_in;
|
int buffer_filled_in;
|
||||||
int buffer_filled_out;
|
int buffer_filled_out;
|
||||||
int buffer_read_in;
|
int buffer_read_in;
|
||||||
unsigned char *buffer_in;
|
unsigned char *buffer_in;
|
||||||
unsigned char *buffer_out;
|
unsigned char *buffer_out;
|
||||||
|
|
||||||
SOCKETFD socket;
|
SOCKETFD socket;
|
||||||
|
|
||||||
char *errormsg;
|
char *errormsg;
|
||||||
int errornumber;
|
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) */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,17 +83,17 @@ struct SocketClass_ {
|
|||||||
|
|
||||||
/* Socket prototypes */
|
/* Socket prototypes */
|
||||||
SocketClass *SOCK_Constructor(void);
|
SocketClass *SOCK_Constructor(void);
|
||||||
void SOCK_Destructor(SocketClass *self);
|
void SOCK_Destructor(SocketClass * self);
|
||||||
char SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname);
|
char SOCK_connect_to(SocketClass * self, unsigned short port, char *hostname);
|
||||||
void SOCK_get_n_char(SocketClass *self, char *buffer, int len);
|
void SOCK_get_n_char(SocketClass * self, char *buffer, int len);
|
||||||
void SOCK_put_n_char(SocketClass *self, char *buffer, int len);
|
void SOCK_put_n_char(SocketClass * self, char *buffer, int len);
|
||||||
void SOCK_get_string(SocketClass *self, char *buffer, int bufsize);
|
void SOCK_get_string(SocketClass * self, char *buffer, int bufsize);
|
||||||
void SOCK_put_string(SocketClass *self, char *string);
|
void SOCK_put_string(SocketClass * self, char *string);
|
||||||
int SOCK_get_int(SocketClass *self, short len);
|
int SOCK_get_int(SocketClass * self, short len);
|
||||||
void SOCK_put_int(SocketClass *self, int value, short len);
|
void SOCK_put_int(SocketClass * self, int value, short len);
|
||||||
void SOCK_flush_output(SocketClass *self);
|
void SOCK_flush_output(SocketClass * self);
|
||||||
unsigned char SOCK_get_next_byte(SocketClass *self);
|
unsigned char SOCK_get_next_byte(SocketClass * self);
|
||||||
void SOCK_put_next_byte(SocketClass *self, unsigned char next_byte);
|
void SOCK_put_next_byte(SocketClass * self, unsigned char next_byte);
|
||||||
void SOCK_clear_error(SocketClass *self);
|
void SOCK_clear_error(SocketClass * self);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
/* File: statement.h
|
/* File: statement.h
|
||||||
*
|
*
|
||||||
* Description: See "statement.c"
|
* Description: See "statement.c"
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -33,21 +33,28 @@
|
|||||||
#define TRUE (BOOL)1
|
#define TRUE (BOOL)1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
STMT_ALLOCATED, /* The statement handle is allocated, but not used so far */
|
{
|
||||||
STMT_READY, /* the statement is waiting to be executed */
|
STMT_ALLOCATED, /* The statement handle is allocated, but
|
||||||
STMT_PREMATURE, /* ODBC states that it is legal to call e.g. SQLDescribeCol before
|
* not used so far */
|
||||||
a call to SQLExecute, but after SQLPrepare. To get all the necessary
|
STMT_READY, /* the statement is waiting to be executed */
|
||||||
information in such a case, we simply execute the query _before_ the
|
STMT_PREMATURE, /* ODBC states that it is legal to call
|
||||||
actual call to SQLExecute, so that statement is considered to be "premature".
|
* e.g. SQLDescribeCol before a call to
|
||||||
*/
|
* SQLExecute, but after SQLPrepare. To
|
||||||
STMT_FINISHED, /* statement execution has finished */
|
* get all the necessary information in
|
||||||
STMT_EXECUTING /* statement execution is still going on */
|
* such a case, we simply execute the
|
||||||
} STMT_Status;
|
* 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_TRUNCATED -2
|
||||||
#define STMT_INFO_ONLY -1 /* not an error message, just a notification to be returned by SQLError */
|
#define STMT_INFO_ONLY -1 /* not an error message, just a
|
||||||
#define STMT_OK 0 /* will be interpreted as "no error pending" */
|
* notification to be returned by SQLError */
|
||||||
|
#define STMT_OK 0 /* will be interpreted as "no error
|
||||||
|
* pending" */
|
||||||
#define STMT_EXEC_ERROR 1
|
#define STMT_EXEC_ERROR 1
|
||||||
#define STMT_STATUS_ERROR 2
|
#define STMT_STATUS_ERROR 2
|
||||||
#define STMT_SEQUENCE_ERROR 3
|
#define STMT_SEQUENCE_ERROR 3
|
||||||
@ -77,7 +84,8 @@ typedef enum {
|
|||||||
#define STMT_BAD_ERROR 27
|
#define STMT_BAD_ERROR 27
|
||||||
|
|
||||||
/* statement types */
|
/* statement types */
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
STMT_TYPE_UNKNOWN = -2,
|
STMT_TYPE_UNKNOWN = -2,
|
||||||
STMT_TYPE_OTHER = -1,
|
STMT_TYPE_OTHER = -1,
|
||||||
STMT_TYPE_SELECT = 0,
|
STMT_TYPE_SELECT = 0,
|
||||||
@ -95,7 +103,8 @@ enum {
|
|||||||
|
|
||||||
|
|
||||||
/* Parsing status */
|
/* Parsing status */
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
STMT_PARSE_NONE = 0,
|
STMT_PARSE_NONE = 0,
|
||||||
STMT_PARSE_COMPLETE,
|
STMT_PARSE_COMPLETE,
|
||||||
STMT_PARSE_INCOMPLETE,
|
STMT_PARSE_INCOMPLETE,
|
||||||
@ -103,92 +112,110 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Result style */
|
/* Result style */
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
STMT_FETCH_NONE = 0,
|
STMT_FETCH_NONE = 0,
|
||||||
STMT_FETCH_NORMAL,
|
STMT_FETCH_NORMAL,
|
||||||
STMT_FETCH_EXTENDED,
|
STMT_FETCH_EXTENDED,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
COL_INFO *col_info; /* cached SQLColumns info for this table */
|
{
|
||||||
char name[MAX_TABLE_LEN+1];
|
COL_INFO *col_info; /* cached SQLColumns info for this table */
|
||||||
char alias[MAX_TABLE_LEN+1];
|
char name[MAX_TABLE_LEN + 1];
|
||||||
} TABLE_INFO;
|
char alias[MAX_TABLE_LEN + 1];
|
||||||
|
} TABLE_INFO;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
TABLE_INFO *ti; /* resolve to explicit table names */
|
{
|
||||||
int precision;
|
TABLE_INFO *ti; /* resolve to explicit table names */
|
||||||
int display_size;
|
int precision;
|
||||||
int length;
|
int display_size;
|
||||||
int type;
|
int length;
|
||||||
char nullable;
|
int type;
|
||||||
char func;
|
char nullable;
|
||||||
char expr;
|
char func;
|
||||||
char quote;
|
char expr;
|
||||||
char dquote;
|
char quote;
|
||||||
char numeric;
|
char dquote;
|
||||||
char dot[MAX_TABLE_LEN+1];
|
char numeric;
|
||||||
char name[MAX_COLUMN_LEN+1];
|
char dot[MAX_TABLE_LEN + 1];
|
||||||
char alias[MAX_COLUMN_LEN+1];
|
char name[MAX_COLUMN_LEN + 1];
|
||||||
} FIELD_INFO;
|
char alias[MAX_COLUMN_LEN + 1];
|
||||||
|
} FIELD_INFO;
|
||||||
|
|
||||||
|
|
||||||
/******** Statement Handle ***********/
|
/******** Statement Handle ***********/
|
||||||
struct StatementClass_ {
|
struct StatementClass_
|
||||||
ConnectionClass *hdbc; /* pointer to ConnectionClass this statement belongs to */
|
{
|
||||||
QResultClass *result; /* result of the current statement */
|
ConnectionClass *hdbc; /* pointer to ConnectionClass this
|
||||||
HSTMT FAR *phstmt;
|
* statement belongs to */
|
||||||
|
QResultClass *result; /* result of the current statement */
|
||||||
|
HSTMT FAR *phstmt;
|
||||||
StatementOptions options;
|
StatementOptions options;
|
||||||
|
|
||||||
STMT_Status status;
|
STMT_Status status;
|
||||||
char *errormsg;
|
char *errormsg;
|
||||||
int errornumber;
|
int errornumber;
|
||||||
|
|
||||||
/* information on bindings */
|
/* information on bindings */
|
||||||
BindInfoClass *bindings; /* array to store the binding information */
|
BindInfoClass *bindings; /* array to store the binding information */
|
||||||
BindInfoClass bookmark;
|
BindInfoClass bookmark;
|
||||||
int bindings_allocated;
|
int bindings_allocated;
|
||||||
|
|
||||||
/* information on statement parameters */
|
/* information on statement parameters */
|
||||||
int parameters_allocated;
|
int parameters_allocated;
|
||||||
ParameterInfoClass *parameters;
|
ParameterInfoClass *parameters;
|
||||||
|
|
||||||
Int4 currTuple; /* current absolute row number (GetData, SetPos, SQLFetch) */
|
Int4 currTuple; /* current absolute row number (GetData,
|
||||||
int save_rowset_size; /* saved rowset size in case of change/FETCH_NEXT */
|
* SetPos, SQLFetch) */
|
||||||
int rowset_start; /* start of rowset (an absolute row number) */
|
int save_rowset_size; /* saved rowset size in case of
|
||||||
int bind_row; /* current offset for Multiple row/column binding */
|
* change/FETCH_NEXT */
|
||||||
int last_fetch_count; /* number of rows retrieved in last fetch/extended fetch */
|
int rowset_start; /* start of rowset (an absolute row
|
||||||
int current_col; /* current column for GetData -- used to handle multiple calls */
|
* number) */
|
||||||
int lobj_fd; /* fd of the current large object */
|
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;
|
TABLE_INFO **ti;
|
||||||
FIELD_INFO **fi;
|
FIELD_INFO **fi;
|
||||||
int nfld;
|
int nfld;
|
||||||
int ntab;
|
int ntab;
|
||||||
|
|
||||||
int parse_status;
|
int parse_status;
|
||||||
|
|
||||||
int statement_type; /* According to the defines above */
|
int statement_type; /* According to the defines above */
|
||||||
int data_at_exec; /* Number of params needing SQLPutData */
|
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 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
|
||||||
char manual_result; /* Is the statement result manually built? */
|
* been created? */
|
||||||
char prepare; /* is this statement a prepared statement or direct */
|
char manual_result; /* Is the statement result manually built? */
|
||||||
|
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 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 */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SC_get_conn(a) (a->hdbc)
|
#define SC_get_conn(a) (a->hdbc)
|
||||||
#define SC_get_Result(a) (a->result);
|
#define SC_get_Result(a) (a->result);
|
||||||
|
|
||||||
/* options for SC_free_params() */
|
/* options for SC_free_params() */
|
||||||
@ -197,22 +224,22 @@ struct StatementClass_ {
|
|||||||
|
|
||||||
/* Statement prototypes */
|
/* Statement prototypes */
|
||||||
StatementClass *SC_Constructor(void);
|
StatementClass *SC_Constructor(void);
|
||||||
void InitializeStatementOptions(StatementOptions *opt);
|
void InitializeStatementOptions(StatementOptions * opt);
|
||||||
char SC_Destructor(StatementClass *self);
|
char SC_Destructor(StatementClass * self);
|
||||||
int statement_type(char *statement);
|
int statement_type(char *statement);
|
||||||
char parse_statement(StatementClass *stmt);
|
char parse_statement(StatementClass * stmt);
|
||||||
void SC_pre_execute(StatementClass *self);
|
void SC_pre_execute(StatementClass * self);
|
||||||
char SC_unbind_cols(StatementClass *self);
|
char SC_unbind_cols(StatementClass * self);
|
||||||
char SC_recycle_statement(StatementClass *self);
|
char SC_recycle_statement(StatementClass * self);
|
||||||
|
|
||||||
void SC_clear_error(StatementClass *self);
|
void SC_clear_error(StatementClass * self);
|
||||||
char SC_get_error(StatementClass *self, int *number, char **message);
|
char SC_get_error(StatementClass * self, int *number, char **message);
|
||||||
char *SC_create_errormsg(StatementClass *self);
|
char *SC_create_errormsg(StatementClass * self);
|
||||||
RETCODE SC_execute(StatementClass *self);
|
RETCODE SC_execute(StatementClass * self);
|
||||||
RETCODE SC_fetch(StatementClass *self);
|
RETCODE SC_fetch(StatementClass * self);
|
||||||
void SC_free_params(StatementClass *self, char option);
|
void SC_free_params(StatementClass * self, char option);
|
||||||
void SC_log_error(char *func, char *desc, StatementClass *self);
|
void SC_log_error(char *func, char *desc, StatementClass * self);
|
||||||
unsigned long SC_get_bookmark(StatementClass *self);
|
unsigned long SC_get_bookmark(StatementClass * self);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/* Module: tuple.c
|
/* Module: tuple.c
|
||||||
*
|
*
|
||||||
* Description: This module contains functions for setting the data for individual
|
* Description: This module contains functions for setting the data for individual
|
||||||
* fields (TupleField structure) of a manual result set.
|
* fields (TupleField structure) of a manual result set.
|
||||||
*
|
*
|
||||||
* Important Note: These functions are ONLY used in building manual result sets for
|
* Important Note: These functions are ONLY used in building manual result sets for
|
||||||
* info functions (SQLTables, SQLColumns, etc.)
|
* info functions (SQLTables, SQLColumns, etc.)
|
||||||
*
|
*
|
||||||
* Classes: n/a
|
* Classes: n/a
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -18,39 +18,43 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void set_tuplefield_null(TupleField *tuple_field)
|
void
|
||||||
|
set_tuplefield_null(TupleField * tuple_field)
|
||||||
{
|
{
|
||||||
tuple_field->len = 0;
|
tuple_field->len = 0;
|
||||||
tuple_field->value = NULL; /* strdup(""); */
|
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->len = strlen(string);
|
||||||
tuple_field->value = malloc(strlen(string)+1);
|
tuple_field->value = malloc(strlen(string) + 1);
|
||||||
strcpy(tuple_field->value, string);
|
strcpy(tuple_field->value, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void set_tuplefield_int2(TupleField *tuple_field, Int2 value)
|
void
|
||||||
|
set_tuplefield_int2(TupleField * tuple_field, Int2 value)
|
||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
|
|
||||||
|
|
||||||
sprintf(buffer,"%d", value);
|
sprintf(buffer, "%d", value);
|
||||||
|
|
||||||
tuple_field->len = strlen(buffer)+1;
|
tuple_field->len = strlen(buffer) + 1;
|
||||||
/* +1 ... is this correct (better be on the save side-...) */
|
/* +1 ... is this correct (better be on the save side-...) */
|
||||||
tuple_field->value = strdup(buffer);
|
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];
|
char buffer[15];
|
||||||
|
|
||||||
sprintf(buffer,"%ld", value);
|
sprintf(buffer, "%ld", value);
|
||||||
|
|
||||||
tuple_field->len = strlen(buffer)+1;
|
tuple_field->len = strlen(buffer) + 1;
|
||||||
/* +1 ... is this correct (better be on the save side-...) */
|
/* +1 ... is this correct (better be on the save side-...) */
|
||||||
tuple_field->value = strdup(buffer);
|
tuple_field->value = strdup(buffer);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
/* File: tuple.h
|
/* File: tuple.h
|
||||||
*
|
*
|
||||||
* Description: See "tuple.c"
|
* Description: See "tuple.c"
|
||||||
*
|
*
|
||||||
* Important NOTE: The TupleField structure is used both to hold backend data and
|
* Important NOTE: The TupleField structure is used both to hold backend data and
|
||||||
* manual result set data. The "set_" functions and the TupleNode
|
* manual result set data. The "set_" functions and the TupleNode
|
||||||
* structure are only used for manual result sets by info routines.
|
* structure are only used for manual result sets by info routines.
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -17,15 +17,18 @@
|
|||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
|
|
||||||
/* Used by backend data AND manual result sets */
|
/* 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 */
|
Int4 len; /* length of the current Tuple */
|
||||||
|
void *value; /* an array representing the value */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Used ONLY for manual result sets */
|
/* Used ONLY for manual result sets */
|
||||||
struct TupleNode_ {
|
struct TupleNode_
|
||||||
struct TupleNode_ *prev, *next;
|
{
|
||||||
TupleField tuple[1];
|
struct TupleNode_ *prev,
|
||||||
|
*next;
|
||||||
|
TupleField tuple[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* These macros are wrappers for the corresponding set_tuplefield functions
|
/* These macros are wrappers for the corresponding set_tuplefield functions
|
||||||
@ -36,9 +39,9 @@ struct TupleNode_ {
|
|||||||
#define set_nullfield_int2(FLD, VAL) ((VAL) != -1 ? set_tuplefield_int2(FLD, (VAL)) : set_tuplefield_null(FLD))
|
#define set_nullfield_int2(FLD, VAL) ((VAL) != -1 ? set_tuplefield_int2(FLD, (VAL)) : set_tuplefield_null(FLD))
|
||||||
#define set_nullfield_int4(FLD, VAL) ((VAL) != -1 ? set_tuplefield_int4(FLD, (VAL)) : set_tuplefield_null(FLD))
|
#define set_nullfield_int4(FLD, VAL) ((VAL) != -1 ? set_tuplefield_int4(FLD, (VAL)) : set_tuplefield_null(FLD))
|
||||||
|
|
||||||
void set_tuplefield_null(TupleField *tuple_field);
|
void set_tuplefield_null(TupleField * tuple_field);
|
||||||
void set_tuplefield_string(TupleField *tuple_field, char *string);
|
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);
|
||||||
void set_tuplefield_int4(TupleField *tuple_field, Int4 value);
|
void set_tuplefield_int4(TupleField * tuple_field, Int4 value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/* Module: tuplelist.c
|
/* Module: tuplelist.c
|
||||||
*
|
*
|
||||||
* Description: This module contains functions for creating a manual result set
|
* Description: This module contains functions for creating a manual result set
|
||||||
* (the TupleList) and retrieving data from it for a specific row/column.
|
* (the TupleList) and retrieving data from it for a specific row/column.
|
||||||
*
|
*
|
||||||
* Classes: TupleListClass (Functions prefix: "TL_")
|
* Classes: TupleListClass (Functions prefix: "TL_")
|
||||||
*
|
*
|
||||||
* API functions: none
|
* API functions: none
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -18,19 +18,20 @@
|
|||||||
TupleListClass *
|
TupleListClass *
|
||||||
TL_Constructor(UInt4 fieldcnt)
|
TL_Constructor(UInt4 fieldcnt)
|
||||||
{
|
{
|
||||||
TupleListClass *rv;
|
TupleListClass *rv;
|
||||||
|
|
||||||
mylog("in TL_Constructor\n");
|
mylog("in TL_Constructor\n");
|
||||||
|
|
||||||
rv = (TupleListClass *) malloc(sizeof(TupleListClass));
|
rv = (TupleListClass *) malloc(sizeof(TupleListClass));
|
||||||
if (rv) {
|
if (rv)
|
||||||
|
{
|
||||||
|
|
||||||
rv->num_fields = fieldcnt;
|
rv->num_fields = fieldcnt;
|
||||||
rv->num_tuples = 0;
|
rv->num_tuples = 0;
|
||||||
rv->list_start = NULL;
|
rv->list_start = NULL;
|
||||||
rv->list_end = NULL;
|
rv->list_end = NULL;
|
||||||
rv->lastref = NULL;
|
rv->lastref = NULL;
|
||||||
rv->last_indexed = -1;
|
rv->last_indexed = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mylog("exit TL_Constructor\n");
|
mylog("exit TL_Constructor\n");
|
||||||
@ -39,23 +40,24 @@ TupleListClass *rv;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TL_Destructor(TupleListClass *self)
|
TL_Destructor(TupleListClass * self)
|
||||||
{
|
{
|
||||||
int lf;
|
int lf;
|
||||||
TupleNode *node, *tp;
|
TupleNode *node,
|
||||||
|
*tp;
|
||||||
|
|
||||||
mylog("TupleList: in DESTRUCTOR\n");
|
mylog("TupleList: in DESTRUCTOR\n");
|
||||||
|
|
||||||
node = self->list_start;
|
node = self->list_start;
|
||||||
while(node != NULL) {
|
while (node != NULL)
|
||||||
for (lf=0; lf < self->num_fields; lf++)
|
{
|
||||||
if (node->tuple[lf].value != NULL) {
|
for (lf = 0; lf < self->num_fields; lf++)
|
||||||
free(node->tuple[lf].value);
|
if (node->tuple[lf].value != NULL)
|
||||||
}
|
free(node->tuple[lf].value);
|
||||||
tp = node->next;
|
tp = node->next;
|
||||||
free(node);
|
free(node);
|
||||||
node = tp;
|
node = tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(self);
|
free(self);
|
||||||
|
|
||||||
@ -64,12 +66,14 @@ TupleNode *node, *tp;
|
|||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
TL_get_fieldval(TupleListClass *self, Int4 tupleno, Int2 fieldno)
|
TL_get_fieldval(TupleListClass * self, Int4 tupleno, Int2 fieldno)
|
||||||
{
|
{
|
||||||
Int4 lf;
|
Int4 lf;
|
||||||
Int4 delta, from_end;
|
Int4 delta,
|
||||||
char end_is_closer, start_is_closer;
|
from_end;
|
||||||
TupleNode *rv;
|
char end_is_closer,
|
||||||
|
start_is_closer;
|
||||||
|
TupleNode *rv;
|
||||||
|
|
||||||
if (self->last_indexed == -1)
|
if (self->last_indexed == -1)
|
||||||
/* we have an empty tuple list */
|
/* we have an empty tuple list */
|
||||||
@ -84,67 +88,88 @@ TupleNode *rv;
|
|||||||
/* illegel field number range */
|
/* illegel field number range */
|
||||||
return NULL;
|
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
|
* check if we are accessing the same tuple that was used in the last
|
||||||
another. Do this to speed things up
|
* fetch (e.g: for fetching all the fields one after another. Do this
|
||||||
*/
|
* to speed things up
|
||||||
|
*/
|
||||||
if (tupleno == self->last_indexed)
|
if (tupleno == self->last_indexed)
|
||||||
return self->lastref->tuple[fieldno].value;
|
return self->lastref->tuple[fieldno].value;
|
||||||
|
|
||||||
/* now for the tricky part... */
|
/* now for the tricky part... */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Since random access is quite inefficient for linked lists we use
|
* Since random access is quite inefficient for linked lists we use
|
||||||
the lastref pointer that points to the last element referenced
|
* the lastref pointer that points to the last element referenced by a
|
||||||
by a get_fieldval() call in conjunction with the its index number
|
* get_fieldval() call in conjunction with the its index number that
|
||||||
that is stored in last_indexed. (So we use some locality of
|
* is stored in last_indexed. (So we use some locality of reference
|
||||||
reference principle to speed things up)
|
* principle to speed things up)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
delta = tupleno - self->last_indexed;
|
delta = tupleno - self->last_indexed;
|
||||||
/* if delta is positive, we have to go forward */
|
/* 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;
|
from_end = (self->num_tuples - 1) - tupleno;
|
||||||
|
|
||||||
start_is_closer = labs(delta) > 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;
|
end_is_closer = labs(delta) > from_end;
|
||||||
/* true if we are closer at the end of the list */
|
/* 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... */
|
/* scanning from the end is the shortest way. so we do that... */
|
||||||
rv = self->list_end;
|
rv = self->list_end;
|
||||||
for (lf=0; lf < from_end; lf++)
|
for (lf = 0; lf < from_end; lf++)
|
||||||
rv = rv->prev;
|
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;
|
rv = self->list_start;
|
||||||
for (lf=0; lf < tupleno; lf++)
|
for (lf = 0; lf < tupleno; lf++)
|
||||||
rv = rv->next;
|
rv = rv->next;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* the closest way is starting from our lastref - pointer */
|
/* the closest way is starting from our lastref - pointer */
|
||||||
rv = self->lastref;
|
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 */
|
/* we have to search backwards */
|
||||||
for(lf=0; lf < (-1)*delta; lf++)
|
for (lf = 0; lf < (-1) * delta; lf++)
|
||||||
rv = rv->prev;
|
rv = rv->prev;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* ok, we have to search forward... */
|
/* ok, we have to search forward... */
|
||||||
for (lf=0; lf < delta; lf++)
|
for (lf = 0; lf < delta; lf++)
|
||||||
rv = rv->next;
|
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->lastref = rv;
|
||||||
self->last_indexed = tupleno;
|
self->last_indexed = tupleno;
|
||||||
|
|
||||||
@ -154,25 +179,32 @@ TupleNode *rv;
|
|||||||
|
|
||||||
|
|
||||||
char
|
char
|
||||||
TL_add_tuple(TupleListClass *self, TupleNode *new_field)
|
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->prev = NULL;
|
||||||
new_field->next = 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 */
|
/* the list is empty, we have to add the first tuple */
|
||||||
self->list_start = new_field;
|
self->list_start = new_field;
|
||||||
self->list_end = new_field;
|
self->list_end = new_field;
|
||||||
self->lastref = new_field;
|
self->lastref = new_field;
|
||||||
self->last_indexed = 0;
|
self->last_indexed = 0;
|
||||||
} else {
|
}
|
||||||
/* there is already an element in the list, so add the new
|
else
|
||||||
one at the end of the list
|
{
|
||||||
*/
|
|
||||||
|
/*
|
||||||
|
* 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;
|
self->list_end->next = new_field;
|
||||||
new_field->prev = self->list_end;
|
new_field->prev = self->list_end;
|
||||||
self->list_end = new_field;
|
self->list_end = new_field;
|
||||||
@ -182,5 +214,3 @@ TL_add_tuple(TupleListClass *self, TupleNode *new_field)
|
|||||||
/* this method of building a list cannot fail, so we return 1 */
|
/* this method of building a list cannot fail, so we return 1 */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
/* File: tuplelist.h
|
/* File: tuplelist.h
|
||||||
*
|
*
|
||||||
* Description: See "tuplelist.c"
|
* Description: See "tuplelist.c"
|
||||||
*
|
*
|
||||||
* Important Note: This structure and its functions are ONLY used in building manual result
|
* Important Note: This structure and its functions are ONLY used in building manual result
|
||||||
* sets for info functions (SQLTables, SQLColumns, etc.)
|
* sets for info functions (SQLTables, SQLColumns, etc.)
|
||||||
*
|
*
|
||||||
* Comments: See "notice.txt" for copyright and license information.
|
* Comments: See "notice.txt" for copyright and license information.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -15,19 +15,22 @@
|
|||||||
|
|
||||||
#include "psqlodbc.h"
|
#include "psqlodbc.h"
|
||||||
|
|
||||||
struct TupleListClass_ {
|
struct TupleListClass_
|
||||||
Int4 num_fields;
|
{
|
||||||
Int4 num_tuples;
|
Int4 num_fields;
|
||||||
TupleNode *list_start, *list_end, *lastref;
|
Int4 num_tuples;
|
||||||
Int4 last_indexed;
|
TupleNode *list_start,
|
||||||
|
*list_end,
|
||||||
|
*lastref;
|
||||||
|
Int4 last_indexed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TL_get_num_tuples(x) (x->num_tuples)
|
#define TL_get_num_tuples(x) (x->num_tuples)
|
||||||
|
|
||||||
/* Create a TupleList. Each tuple consits of fieldcnt columns */
|
/* Create a TupleList. Each tuple consits of fieldcnt columns */
|
||||||
TupleListClass *TL_Constructor(UInt4 fieldcnt);
|
TupleListClass *TL_Constructor(UInt4 fieldcnt);
|
||||||
void TL_Destructor(TupleListClass *self);
|
void TL_Destructor(TupleListClass * self);
|
||||||
void *TL_get_fieldval(TupleListClass *self, Int4 tupleno, Int2 fieldno);
|
void *TL_get_fieldval(TupleListClass * self, Int4 tupleno, Int2 fieldno);
|
||||||
char TL_add_tuple(TupleListClass *self, TupleNode *new_field);
|
char TL_add_tuple(TupleListClass * self, TupleNode * new_field);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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:
|
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'
|
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
|
causes the rest of the file to be ignored. Second, it silently ignores
|
||||||
|
Loading…
x
Reference in New Issue
Block a user