Add new files for the preparation.

This commit is contained in:
Hiroshi Inoue 2001-08-10 01:24:15 +00:00
parent 9c90a2b045
commit a9d67d0fa7
3 changed files with 1528 additions and 0 deletions

View file

@ -0,0 +1,602 @@
/*-------
* Module: odbcapi.c
*
* Description: This module contains routines related to
* preparing and executing an SQL statement.
*
* Classes: n/a
*
* API functions: SQLAllocConnect, SQLAllocEnv, SQLAllocStmt,
SQLBindCol, SQLCancel, SQLColumns, SQLConnect,
SQLDataSources, SQLDescribeCol, SQLDisconnect,
SQLError, SQLExecDirect, SQLExecute, SQLFetch,
SQLFreeConnect, SQLFreeEnv, SQLFreeStmt,
SQLGetConnectOption, SQLGetCursorName, SQLGetData,
SQLGetFunctions, SQLGetInfo, SQLGetStmtOption,
SQLGetTypeInfo, SQLNumResultCols, SQLParamData,
SQLPrepare, SQLPutData, SQLRowCount,
SQLSetConnectOption, SQLSetCursorName, SQLSetParam,
SQLSetStmtOption, SQLSpecialColumns, SQLStatistics,
SQLTables, SQLTransact, SQLColAttributes,
SQLColumnPrivileges, SQLDescribeParam, SQLExtendedFetch,
SQLForeignKeys, SQLMoreResults, SQLNativeSql,
SQLNumParams, SQLParamOptions, SQLPrimaryKeys,
SQLProcedureColumns, SQLProcedures, SQLSetPos,
SQLTablePrivileges, SQLBindParameter
*-------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "psqlodbc.h"
#undef ODBCVER
#define ODBCVER 0x3000
#include <stdio.h>
#include <string.h>
#ifndef WIN32
#include "iodbc.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sqlext.h>
#endif
#include "pgapifunc.h"
#include "connection.h"
#include "statement.h"
SQLRETURN SQL_API SQLAllocConnect(SQLHENV EnvironmentHandle,
SQLHDBC *ConnectionHandle)
{
mylog("[SQLAllocConnect]");
return PGAPI_AllocConnect(EnvironmentHandle, ConnectionHandle);
}
SQLRETURN SQL_API SQLAllocEnv(SQLHENV *EnvironmentHandle)
{
mylog("[SQLAllocEnv]");
return PGAPI_AllocEnv(EnvironmentHandle);
}
SQLRETURN SQL_API SQLAllocStmt(SQLHDBC ConnectionHandle,
SQLHSTMT *StatementHandle)
{
mylog("[SQLAllocStmt]");
return PGAPI_AllocStmt(ConnectionHandle, StatementHandle);
}
SQLRETURN SQL_API SQLBindCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
SQLPOINTER TargetValue, SQLINTEGER BufferLength,
SQLINTEGER *StrLen_or_Ind)
{
mylog("[SQLBindCol]");
return PGAPI_BindCol(StatementHandle, ColumnNumber,
TargetType, TargetValue, BufferLength, StrLen_or_Ind);
}
SQLRETURN SQL_API SQLCancel(SQLHSTMT StatementHandle)
{
mylog("[SQLCancel]");
return PGAPI_Cancel(StatementHandle);
}
SQLRETURN SQL_API SQLColumns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLCHAR *ColumnName, SQLSMALLINT NameLength4)
{
mylog("[SQLColumns]");
return PGAPI_Columns(StatementHandle, CatalogName, NameLength1,
SchemaName, NameLength2, TableName, NameLength3,
ColumnName, NameLength4);
}
SQLRETURN SQL_API SQLConnect(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName, SQLSMALLINT NameLength1,
SQLCHAR *UserName, SQLSMALLINT NameLength2,
SQLCHAR *Authentication, SQLSMALLINT NameLength3)
{
mylog("[SQLConnect]");
return PGAPI_Connect(ConnectionHandle, ServerName, NameLength1,
UserName, NameLength2, Authentication, NameLength3);
}
SQLRETURN SQL_API SQLDriverConnect(HDBC hdbc,
HWND hwnd,
UCHAR FAR *szConnStrIn,
SWORD cbConnStrIn,
UCHAR FAR *szConnStrOut,
SWORD cbConnStrOutMax,
SWORD FAR *pcbConnStrOut,
UWORD fDriverCompletion)
{
mylog("[SQLDriverConnect]");
return PGAPI_DriverConnect(hdbc, hwnd, szConnStrIn, cbConnStrIn,
szConnStrOut, cbConnStrOutMax, pcbConnStrOut, fDriverCompletion);
}
SQLRETURN SQL_API SQLBrowseConnect(
SQLHDBC hdbc,
SQLCHAR *szConnStrIn,
SQLSMALLINT cbConnStrIn,
SQLCHAR *szConnStrOut,
SQLSMALLINT cbConnStrOutMax,
SQLSMALLINT *pcbConnStrOut)
{
mylog("[SQLBrowseConnect]");
return PGAPI_BrowseConnect(hdbc, szConnStrIn, cbConnStrIn,
szConnStrOut, cbConnStrOutMax, pcbConnStrOut);
}
SQLRETURN SQL_API SQLDataSources(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction, SQLCHAR *ServerName,
SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1,
SQLCHAR *Description, SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2)
{
mylog("[SQLDataSources]");
/*
return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
BufferLength1, NameLength1, Description, BufferLength2,
NameLength2);
*/
return SQL_ERROR;
}
SQLRETURN SQL_API SQLDescribeCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
SQLSMALLINT *DataType, SQLUINTEGER *ColumnSize,
SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
{
mylog("[SQLDescribeCol]");
return PGAPI_DescribeCol(StatementHandle, ColumnNumber,
ColumnName, BufferLength, NameLength,
DataType, ColumnSize, DecimalDigits, Nullable);
}
SQLRETURN SQL_API SQLDisconnect(SQLHDBC ConnectionHandle)
{
mylog("[SQLDisconnect]");
return PGAPI_Disconnect(ConnectionHandle);
}
SQLRETURN SQL_API SQLError(SQLHENV EnvironmentHandle,
SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength)
{
mylog("[SQLError]");
return PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
Sqlstate, NativeError, MessageText, BufferLength, TextLength);
}
SQLRETURN SQL_API SQLExecDirect(SQLHSTMT StatementHandle,
SQLCHAR *StatementText, SQLINTEGER TextLength)
{
mylog("[SQLExecDirect]");
return PGAPI_ExecDirect(StatementHandle, StatementText, TextLength);
}
SQLRETURN SQL_API SQLExecute(SQLHSTMT StatementHandle)
{
mylog("[SQLExecute]");
return PGAPI_Execute(StatementHandle);
}
SQLRETURN SQL_API SQLFetch(SQLHSTMT StatementHandle)
{
static char *func = "SQLFetch";
#if (ODBCVER >= 0x3000)
StatementClass *stmt = (StatementClass *) StatementHandle;
ConnectionClass *conn = SC_get_conn(stmt);
if (conn->driver_version >= 0x0300)
{
SQLUSMALLINT *rowStatusArray = stmt->options.rowStatusArray;
SQLINTEGER *pcRow = stmt->options.rowsFetched;
mylog("[[%s]]", func);
return PGAPI_ExtendedFetch(StatementHandle, SQL_FETCH_NEXT, 0,
pcRow, rowStatusArray);
}
#endif
mylog("[%s]", func);
return PGAPI_Fetch(StatementHandle);
}
SQLRETURN SQL_API SQLFreeConnect(SQLHDBC ConnectionHandle)
{
mylog("[SQLFreeStmt]");
return PGAPI_FreeConnect(ConnectionHandle);
}
SQLRETURN SQL_API SQLFreeEnv(SQLHENV EnvironmentHandle)
{
mylog("[SQLFreeEnv]");
return PGAPI_FreeEnv(EnvironmentHandle);
}
SQLRETURN SQL_API SQLFreeStmt(SQLHSTMT StatementHandle,
SQLUSMALLINT Option)
{
mylog("[SQLFreeStmt]");
return PGAPI_FreeStmt(StatementHandle, Option);
}
SQLRETURN SQL_API SQLGetConnectOption(SQLHDBC ConnectionHandle,
SQLUSMALLINT Option, SQLPOINTER Value)
{
mylog("[SQLGetConnectOption]");
return PGAPI_GetConnectOption(ConnectionHandle, Option, Value);
}
SQLRETURN SQL_API SQLGetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName, SQLSMALLINT BufferLength,
SQLSMALLINT *NameLength)
{
mylog("[SQLGetCursorName]");
return PGAPI_GetCursorName(StatementHandle, CursorName, BufferLength,
NameLength);
}
SQLRETURN SQL_API SQLGetData(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
SQLPOINTER TargetValue, SQLINTEGER BufferLength,
SQLINTEGER *StrLen_or_Ind)
{
mylog("[SQLGetData]");
return PGAPI_GetData(StatementHandle, ColumnNumber, TargetType,
TargetValue, BufferLength, StrLen_or_Ind);
}
SQLRETURN SQL_API SQLGetFunctions(SQLHDBC ConnectionHandle,
SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported)
{
mylog("[SQLGetFunctions");
#if (ODBCVER >= 0x3000)
if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS)
return PGAPI_GetFunctions30(ConnectionHandle, FunctionId, Supported);
#endif
return PGAPI_GetFunctions(ConnectionHandle, FunctionId, Supported);
}
SQLRETURN SQL_API SQLGetInfo(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType, SQLPOINTER InfoValue,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
{
mylog("[SQLGetInfo]");
return PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
BufferLength, StringLength);
}
SQLRETURN SQL_API SQLGetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLPOINTER Value)
{
mylog("[SQLGetStmtOption]");
return PGAPI_GetStmtOption(StatementHandle, Option, Value);
}
SQLRETURN SQL_API SQLGetTypeInfo(SQLHSTMT StatementHandle,
SQLSMALLINT DataType)
{
mylog("[SQLGetTypeInfo]");
return PGAPI_GetTypeInfo(StatementHandle,DataType);
}
SQLRETURN SQL_API SQLNumResultCols(SQLHSTMT StatementHandle,
SQLSMALLINT *ColumnCount)
{
mylog("[SQLNumResultCols]");
return PGAPI_NumResultCols(StatementHandle, ColumnCount);
}
SQLRETURN SQL_API SQLParamData(SQLHSTMT StatementHandle,
SQLPOINTER *Value)
{
mylog("[SQLParamData]");
return PGAPI_ParamData(StatementHandle, Value);
}
SQLRETURN SQL_API SQLPrepare(SQLHSTMT StatementHandle,
SQLCHAR *StatementText, SQLINTEGER TextLength)
{
mylog("[SQLPrepare]");
return PGAPI_Prepare(StatementHandle, StatementText, TextLength);
}
SQLRETURN SQL_API SQLPutData(SQLHSTMT StatementHandle,
SQLPOINTER Data, SQLINTEGER StrLen_or_Ind)
{
mylog("[SQLPutData]");
return PGAPI_PutData(StatementHandle, Data, StrLen_or_Ind);
}
SQLRETURN SQL_API SQLRowCount(SQLHSTMT StatementHandle,
SQLINTEGER *RowCount)
{
mylog("[SQLRowCount]");
return PGAPI_RowCount(StatementHandle, RowCount);
}
SQLRETURN SQL_API SQLSetConnectOption(SQLHDBC ConnectionHandle,
SQLUSMALLINT Option, SQLUINTEGER Value)
{
mylog("[SQLSetConnectionOption]");
return PGAPI_SetConnectOption(ConnectionHandle, Option, Value);
}
SQLRETURN SQL_API SQLSetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName, SQLSMALLINT NameLength)
{
mylog("[SQLSetCursorName]");
return PGAPI_SetCursorName(StatementHandle, CursorName, NameLength);
}
SQLRETURN SQL_API SQLSetParam(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
SQLSMALLINT ParameterType, SQLUINTEGER LengthPrecision,
SQLSMALLINT ParameterScale, SQLPOINTER ParameterValue,
SQLINTEGER *StrLen_or_Ind)
{
mylog("[SQLSetParam]");
/*
return PGAPI_SetParam(StatementHandle, ParameterNumber, ValueType,
ParameterType, LengthPrecision, ParameterScale, ParameterValue,
StrLen_or_Ind);
*/
return SQL_ERROR;
}
SQLRETURN SQL_API SQLSetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLUINTEGER Value)
{
mylog("[SQLSetStmtOption]");
return PGAPI_SetStmtOption(StatementHandle, Option, Value);
}
SQLRETURN SQL_API SQLSpecialColumns(SQLHSTMT StatementHandle,
SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName,
SQLSMALLINT NameLength1, SQLCHAR *SchemaName,
SQLSMALLINT NameLength2, SQLCHAR *TableName,
SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
SQLUSMALLINT Nullable)
{
mylog("[SQLSpecialColumns]");
return PGAPI_SpecialColumns(StatementHandle, IdentifierType, CatalogName,
NameLength1, SchemaName, NameLength2, TableName, NameLength3,
Scope, Nullable);
}
SQLRETURN SQL_API SQLStatistics(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
{
mylog("[SQLStatistics]");
return PGAPI_Statistics(StatementHandle, CatalogName, NameLength1,
SchemaName, NameLength2, TableName, NameLength3, Unique,
Reserved);
}
SQLRETURN SQL_API SQLTables(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLCHAR *TableType, SQLSMALLINT NameLength4)
{
mylog("[SQLTables]");
return PGAPI_Tables(StatementHandle, CatalogName, NameLength1,
SchemaName, NameLength2, TableName, NameLength3,
TableType, NameLength4);
}
SQLRETURN SQL_API SQLTransact(SQLHENV EnvironmentHandle,
SQLHDBC ConnectionHandle, SQLUSMALLINT CompletionType)
{
mylog("[SQLTransact]");
return PGAPI_Transact(EnvironmentHandle, ConnectionHandle, CompletionType);
}
SQLRETURN SQL_API SQLColAttributes(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT *pcbDesc,
SQLINTEGER *pfDesc)
{
mylog("[SQLColAttributes]");
return PGAPI_ColAttributes(hstmt, icol, fDescType, rgbDesc,
cbDescMax, pcbDesc, pfDesc);
}
SQLRETURN SQL_API SQLColumnPrivileges(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName,
SQLCHAR *szColumnName,
SQLSMALLINT cbColumnName)
{
mylog("[SQLColumnPrivileges]");
return PGAPI_ColumnPrivileges(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szTableName, cbTableName,
szColumnName, cbColumnName);
}
SQLRETURN SQL_API SQLDescribeParam(
SQLHSTMT hstmt,
SQLUSMALLINT ipar,
SQLSMALLINT *pfSqlType,
SQLUINTEGER *pcbParamDef,
SQLSMALLINT *pibScale,
SQLSMALLINT *pfNullable)
{
mylog("[SQLDescribeParam]");
return PGAPI_DescribeParam(hstmt, ipar, pfSqlType, pcbParamDef,
pibScale, pfNullable);
}
SQLRETURN SQL_API SQLExtendedFetch(
SQLHSTMT hstmt,
SQLUSMALLINT fFetchType,
SQLINTEGER irow,
SQLUINTEGER *pcrow,
SQLUSMALLINT *rgfRowStatus)
{
mylog("[SQLExtendedFetch]");
return PGAPI_ExtendedFetch(hstmt, fFetchType, irow, pcrow, rgfRowStatus);
}
SQLRETURN SQL_API SQLForeignKeys(
SQLHSTMT hstmt,
SQLCHAR *szPkCatalogName,
SQLSMALLINT cbPkCatalogName,
SQLCHAR *szPkSchemaName,
SQLSMALLINT cbPkSchemaName,
SQLCHAR *szPkTableName,
SQLSMALLINT cbPkTableName,
SQLCHAR *szFkCatalogName,
SQLSMALLINT cbFkCatalogName,
SQLCHAR *szFkSchemaName,
SQLSMALLINT cbFkSchemaName,
SQLCHAR *szFkTableName,
SQLSMALLINT cbFkTableName)
{
mylog("[SQLForeignKeys]");
return PGAPI_ForeignKeys(hstmt, szPkCatalogName, cbPkCatalogName,
szPkSchemaName, cbPkSchemaName, szPkTableName,
cbPkTableName, szFkCatalogName, cbFkCatalogName,
szFkSchemaName, cbFkSchemaName, szFkTableName, cbFkTableName);
}
SQLRETURN SQL_API SQLMoreResults(SQLHSTMT hstmt)
{
mylog("[SQLMoreResults]");
return PGAPI_MoreResults(hstmt);
}
SQLRETURN SQL_API SQLNativeSql(
SQLHDBC hdbc,
SQLCHAR *szSqlStrIn,
SQLINTEGER cbSqlStrIn,
SQLCHAR *szSqlStr,
SQLINTEGER cbSqlStrMax,
SQLINTEGER *pcbSqlStr)
{
mylog("[SQLNativeSql]");
return PGAPI_NativeSql(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr,
cbSqlStrMax, pcbSqlStr);
}
SQLRETURN SQL_API SQLNumParams(
SQLHSTMT hstmt,
SQLSMALLINT *pcpar)
{
mylog("[SQLNumParams]");
return PGAPI_NumParams(hstmt, pcpar);
}
SQLRETURN SQL_API SQLParamOptions(
SQLHSTMT hstmt,
SQLUINTEGER crow,
SQLUINTEGER *pirow)
{
mylog("[SQLParamOptions]");
return PGAPI_ParamOptions(hstmt, crow, pirow);
}
SQLRETURN SQL_API SQLPrimaryKeys(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName)
{
mylog("[SQLPrimaryKeys]");
return PGAPI_PrimaryKeys(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szTableName, cbTableName);
}
SQLRETURN SQL_API SQLProcedureColumns(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szProcName,
SQLSMALLINT cbProcName,
SQLCHAR *szColumnName,
SQLSMALLINT cbColumnName)
{
mylog("[SQLProcedureColumns]");
return PGAPI_ProcedureColumns(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szProcName, cbProcName,
szColumnName, cbColumnName);
}
SQLRETURN SQL_API SQLProcedures(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szProcName,
SQLSMALLINT cbProcName)
{
mylog("[SQLProcedures]");
return PGAPI_Procedures(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szProcName, cbProcName);
}
SQLRETURN SQL_API SQLSetPos(
SQLHSTMT hstmt,
SQLUSMALLINT irow,
SQLUSMALLINT fOption,
SQLUSMALLINT fLock)
{
mylog("[SQLSetPos]");
return PGAPI_SetPos(hstmt, irow, fOption, fLock);
}
SQLRETURN SQL_API SQLTablePrivileges(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName)
{
mylog("[SQLTablePrivileges]");
return PGAPI_TablePrivileges(hstmt, szCatalogName, cbCatalogName,
szSchemaName, cbSchemaName, szTableName, cbTableName);
}
SQLRETURN SQL_API SQLBindParameter(
SQLHSTMT hstmt,
SQLUSMALLINT ipar,
SQLSMALLINT fParamType,
SQLSMALLINT fCType,
SQLSMALLINT fSqlType,
SQLUINTEGER cbColDef,
SQLSMALLINT ibScale,
SQLPOINTER rgbValue,
SQLINTEGER cbValueMax,
SQLINTEGER *pcbValue)
{
mylog("[SQLBindParameter]");
return PGAPI_BindParameter(hstmt, ipar, fParamType, fCType,
fSqlType, cbColDef, ibScale, rgbValue, cbValueMax,
pcbValue);
}

View file

@ -0,0 +1,678 @@
/*-------
* Module: odbcapi30.c
*
* Description: This module contains routines related to ODBC 3.0
* most of their implementations are temporary
* and must be rewritten properly.
* 2001/07/23 inoue
*
* Classes: n/a
*
* API functions: SQLAllocHandle, SQLBindParam, SQLCloseCursor,
SQLColAttribute, SQLCopyDesc, SQLEndTran,
SQLFetchScroll, SQLFreeHandle, SQLGetDescField,
SQLGetDescRec, SQLGetDiagField, SQLGetDiagRec,
SQLGetEnvAttr, SQLGetConnectAttr, SQLGetStmtAttr,
SQLSetConnectAttr, SQLSetDescField, SQLSetDescRec,
SQLSetEnvAttr, SQLSetStmtAttr, SQLBulkOperations
*-------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "psqlodbc.h"
#undef ODBCVER
#define ODBCVER 0x0300
#include <stdio.h>
#include <string.h>
#ifndef WIN32
#include "iodbc.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sqlext.h>
#endif
#include "environ.h"
#include "connection.h"
#include "statement.h"
#include "pgapifunc.h"
/* SQLAllocConnect/SQLAllocEnv/SQLAllocStmt -> SQLAllocHandle */
SQLRETURN SQL_API SQLAllocHandle(SQLSMALLINT HandleType,
SQLHANDLE InputHandle, SQLHANDLE *OutputHandle)
{
mylog("[[SQLAllocHandle]]");
switch (HandleType)
{
case SQL_HANDLE_ENV:
return PGAPI_AllocEnv(OutputHandle);
case SQL_HANDLE_DBC:
return PGAPI_AllocConnect(InputHandle, OutputHandle);
case SQL_HANDLE_STMT:
return PGAPI_AllocStmt(InputHandle, OutputHandle);
default: break;
}
return SQL_ERROR;
}
/* SQLBindParameter/SQLSetParam -> SQLBindParam */
SQLRETURN SQL_API SQLBindParam(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
SQLSMALLINT ParameterType, SQLUINTEGER LengthPrecision,
SQLSMALLINT ParameterScale, SQLPOINTER ParameterValue,
SQLINTEGER *StrLen_or_Ind)
{
int BufferLength = 512; /* Is it OK ? */
mylog("[[SQLBindParam]]");
return PGAPI_BindParameter(StatementHandle, ParameterNumber, SQL_PARAM_INPUT, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, BufferLength, StrLen_or_Ind);
}
/* New function */
SQLRETURN SQL_API SQLCloseCursor(SQLHSTMT StatementHandle)
{
mylog("[[SQLCloseCursor]]");
return PGAPI_FreeStmt(StatementHandle, SQL_CLOSE);
}
/* SQLColAttributes -> SQLColAttribute */
SQLRETURN SQL_API SQLColAttribute (SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLUSMALLINT FieldIdentifier,
SQLPOINTER CharacterAttribute, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength, SQLPOINTER NumericAttribute)
{
mylog("[[SQLColAttribute]]");
return PGAPI_ColAttributes(StatementHandle, ColumnNumber,
FieldIdentifier, CharacterAttribute, BufferLength,
StringLength, NumericAttribute);
}
/* new function */
SQLRETURN SQL_API SQLCopyDesc(SQLHDESC SourceDescHandle,
SQLHDESC TargetDescHandle)
{
mylog("[[SQLCopyDesc]]\n");
return SQL_ERROR;
}
/* SQLTransact -> SQLEndTran */
SQLRETURN SQL_API SQLEndTran(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT CompletionType)
{
mylog("[[SQLEndTran]]");
switch (HandleType)
{
case SQL_HANDLE_ENV:
return PGAPI_Transact(Handle, SQL_NULL_HDBC, CompletionType);
case SQL_HANDLE_DBC:
return PGAPI_Transact(SQL_NULL_HENV, Handle, CompletionType);
default:break;
}
return SQL_ERROR; /* SQLSTATE HY092 ("Invalid attribute/option identifier")*/
}
/* SQLExtendedFetch -> SQLFetchScroll */
SQLRETURN SQL_API SQLFetchScroll(SQLHSTMT StatementHandle,
SQLSMALLINT FetchOrientation, SQLINTEGER FetchOffset)
{
static char *func = "SQLFetchScroll";
StatementClass *stmt = (StatementClass *) StatementHandle;
SQLRETURN ret;
SQLUSMALLINT *rowStatusArray = stmt->options.rowStatusArray;
SQLINTEGER *pcRow = stmt->options.rowsFetched;
mylog("[[%s]] %d,%d\n", func, FetchOrientation, FetchOffset);
if (FetchOrientation == SQL_FETCH_BOOKMARK)
{
if (stmt->options.bookmark_ptr)
FetchOffset += *((Int4 *) stmt->options.bookmark_ptr);
else
{
stmt->errornumber = STMT_SEQUENCE_ERROR;
stmt->errormsg = "Bookmark isn't specifed yet";
SC_log_error(func, "", stmt);
return SQL_ERROR;
}
}
ret = PGAPI_ExtendedFetch(StatementHandle, FetchOrientation, FetchOffset,
pcRow, rowStatusArray);
if (ret != SQL_SUCCESS)
mylog("%s return = %d\n", func, ret);
return ret;
}
/* SQLFree(Connect/Env/Stmt) -> SQLFreeHandle */
SQLRETURN SQL_API SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
{
mylog("[[SQLFreeHandle]]");
switch (HandleType)
{
case SQL_HANDLE_ENV:
return PGAPI_FreeEnv(Handle);
case SQL_HANDLE_DBC:
return PGAPI_FreeConnect(Handle);
case SQL_HANDLE_STMT:
return PGAPI_FreeStmt(Handle, SQL_DROP);
default: break;
}
return SQL_ERROR;
}
/* new function */
SQLRETURN SQL_API SQLGetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
SQLPOINTER Value, SQLINTEGER BufferLength,
SQLINTEGER *StringLength)
{
mylog("[[SQLGetDescField]]\n");
return SQL_ERROR;
}
/* new function */
SQLRETURN SQL_API SQLGetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLCHAR *Name,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength,
SQLSMALLINT *Type, SQLSMALLINT *SubType,
SQLINTEGER *Length, SQLSMALLINT *Precision,
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
{
mylog("[[SQLGetDescRec]]\n");
return SQL_ERROR;
}
/* new function */
SQLRETURN SQL_API SQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
SQLPOINTER DiagInfo, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLength)
{
mylog("[[SQLGetDiagField]]\n");
return SQL_ERROR;
}
/* SQLError -> SQLDiagRec */
SQLRETURN SQL_API SQLGetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,
SQLSMALLINT RecNumber, SQLCHAR *Sqlstate,
SQLINTEGER *NativeError, SQLCHAR *MessageText,
SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
{
SQLRETURN ret;
mylog("[[SQLGetDiagRec]]\n");
switch (HandleType)
{
case SQL_HANDLE_ENV:
ret = PGAPI_Error(Handle, NULL, NULL, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
break;
case SQL_HANDLE_DBC:
ret = PGAPI_Error(NULL, Handle, NULL, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
break;
case SQL_HANDLE_STMT:
ret = PGAPI_Error(NULL, NULL, Handle, Sqlstate, NativeError,
MessageText, BufferLength, TextLength);
break;
default:
ret = SQL_ERROR;
}
if (ret == SQL_SUCCESS_WITH_INFO &&
BufferLength == 0 &&
*TextLength)
{
SQLSMALLINT BufferLength = *TextLength + 4;
SQLCHAR *MessageText = malloc(BufferLength);
ret = SQLGetDiagRec(HandleType, Handle, RecNumber, Sqlstate,
NativeError, MessageText, BufferLength,
TextLength);
free(MessageText);
}
return ret;
}
/* new function */
SQLRETURN SQL_API SQLGetEnvAttr(SQLHENV EnvironmentHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength)
{
EnvironmentClass *env = (EnvironmentClass *) EnvironmentHandle;
mylog("[[SQLGetEnvAttr]] %d\n", Attribute);
switch (Attribute)
{
case SQL_ATTR_CONNECTION_POOLING:
*((unsigned int *) Value) = SQL_CP_OFF;
break;
case SQL_ATTR_CP_MATCH:
*((unsigned int *) Value) = SQL_CP_RELAXED_MATCH;
break;
case SQL_ATTR_ODBC_VERSION:
*((unsigned int *) Value) = SQL_OV_ODBC3;
break;
case SQL_ATTR_OUTPUT_NTS:
*((unsigned int *) Value) = SQL_TRUE;
break;
default:
env->errornumber = CONN_INVALID_ARGUMENT_NO;
return SQL_ERROR;
}
return SQL_SUCCESS;
}
/* SQLGetConnectOption -> SQLGetconnectAttr */
SQLRETURN SQL_API SQLGetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength)
{
ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
mylog("[[SQLGetConnectAttr]] %d\n", Attribute);
switch (Attribute)
{
case SQL_ATTR_ASYNC_ENABLE:
case SQL_ATTR_AUTO_IPD:
case SQL_ATTR_CONNECTION_DEAD:
case SQL_ATTR_CONNECTION_TIMEOUT:
case SQL_ATTR_METADATA_ID:
conn->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
conn->errormsg = "Unsupported connection option (Set)";
return SQL_ERROR;
}
return PGAPI_GetConnectOption (ConnectionHandle, (UWORD) Attribute, Value);
}
/* SQLGetStmtOption -> SQLGetStmtAttr */
SQLRETURN SQL_API SQLGetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER BufferLength, SQLINTEGER *StringLength)
{
static char *func = "SQLGetStmtAttr";
StatementClass *stmt = (StatementClass *) StatementHandle;
SQLRETURN ret = SQL_SUCCESS;
int len = 0;
mylog("[[%s]] %d\n", func, Attribute);
switch (Attribute)
{
case SQL_ATTR_FETCH_BOOKMARK_PTR: /* 16 */
Value = stmt->options.bookmark_ptr;
len = 4;
break;
case SQL_ATTR_ROW_STATUS_PTR: /* 25 */
Value = stmt->options.rowStatusArray;
len = 4;
break;
case SQL_ATTR_ROWS_FETCHED_PTR: /* 26 */
Value = stmt->options.rowsFetched;
len = 4;
break;
case SQL_ATTR_ROW_ARRAY_SIZE: /* 27 */
*((SQLUINTEGER *) Value) = stmt->options.rowset_size;
len = 4;
break;
case SQL_ATTR_APP_ROW_DESC: /* 10010 */
*((SQLHSTMT *) Value) = StatementHandle; /* this is useless */
len = 4;
break;
case SQL_ATTR_APP_PARAM_DESC: /* 10011 */
*((SQLHSTMT *) Value) = StatementHandle; /* this is useless */
len = 4;
break;
case SQL_ATTR_IMP_ROW_DESC: /* 10012 */
*((SQLHSTMT *) Value) = StatementHandle; /* this is useless */
len = 4;
break;
case SQL_ATTR_IMP_PARAM_DESC: /* 10013 */
*((SQLHSTMT *) Value) = StatementHandle; /* this is useless */
len = 4;
break;
case SQL_ATTR_AUTO_IPD: /* 10001 */
case SQL_ATTR_ROW_BIND_TYPE: /* == SQL_BIND_TYPE */
case SQL_ATTR_PARAMSET_SIZE: /* 22 */
case SQL_ATTR_PARAM_STATUS_PTR: /* 20 */
case SQL_ATTR_PARAMS_PROCESSED_PTR: /* 21 */
case SQL_ATTR_CURSOR_SCROLLABLE: /* -1 */
case SQL_ATTR_CURSOR_SENSITIVITY: /* -2 */
case SQL_ATTR_ENABLE_AUTO_IPD: /* 15 */
case SQL_ATTR_METADATA_ID: /* 10014 */
/* case SQL_ATTR_PREDICATE_PTR:
case SQL_ATTR_PREDICATE_OCTET_LENGTH_PTR: */
case SQL_ATTR_PARAM_BIND_OFFSET_PTR: /* 17 */
case SQL_ATTR_PARAM_BIND_TYPE: /* 18 */
case SQL_ATTR_PARAM_OPERATION_PTR: /* 19 */
case SQL_ATTR_ROW_BIND_OFFSET_PTR: /* 23 */
case SQL_ATTR_ROW_OPERATION_PTR: /* 24 */
stmt->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
stmt->errormsg = "Unsupported statement option (Get)";
SC_log_error(func, "", stmt);
return SQL_ERROR;
default:
len = 4;
ret = PGAPI_GetStmtOption(StatementHandle, (UWORD) Attribute, Value);
}
if (ret == SQL_SUCCESS && StringLength)
*StringLength = len;
return ret;
}
/* SQLSetConnectOption -> SQLSetConnectAttr */
SQLRETURN SQL_API SQLSetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER StringLength)
{
ConnectionClass *conn = (ConnectionClass *) ConnectionHandle;
mylog("[[SQLSetConnectAttr]] %d\n", Attribute);
switch (Attribute)
{
case SQL_ATTR_ASYNC_ENABLE:
case SQL_ATTR_AUTO_IPD:
case SQL_ATTR_CONNECTION_DEAD:
case SQL_ATTR_CONNECTION_TIMEOUT:
case SQL_ATTR_METADATA_ID:
conn->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
conn->errormsg = "Unsupported connection option (Set)";
return SQL_ERROR;
}
return PGAPI_SetConnectOption(ConnectionHandle, (UWORD) Attribute, (UDWORD) Value);
}
/* new function */
SQLRETURN SQL_API SQLSetDescField(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
SQLPOINTER Value, SQLINTEGER BufferLength)
{
mylog("[[SQLSetDescField]]\n");
return SQL_ERROR;
}
/* new fucntion */
SQLRETURN SQL_API SQLSetDescRec(SQLHDESC DescriptorHandle,
SQLSMALLINT RecNumber, SQLSMALLINT Type,
SQLSMALLINT SubType, SQLINTEGER Length,
SQLSMALLINT Precision, SQLSMALLINT Scale,
SQLPOINTER Data, SQLINTEGER *StringLength,
SQLINTEGER *Indicator)
{
mylog("[[SQLsetDescRec]]\n");
return SQL_ERROR;
}
/* new function */
SQLRETURN SQL_API SQLSetEnvAttr(SQLHENV EnvironmentHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER StringLength)
{
EnvironmentClass *env = (EnvironmentClass *) EnvironmentHandle;
mylog("[[SQLSetEnvAttr]] att=%d,%u\n", Attribute, Value);
switch (Attribute)
{
case SQL_ATTR_CONNECTION_POOLING:
if ((SQLUINTEGER) Value == SQL_CP_OFF)
return SQL_SUCCESS;
break;
case SQL_ATTR_CP_MATCH:
/* *((unsigned int *) Value) = SQL_CP_RELAXED_MATCH; */
return SQL_SUCCESS;
case SQL_ATTR_ODBC_VERSION:
if ((SQLUINTEGER) Value == SQL_OV_ODBC3)
return SQL_SUCCESS;
break;
case SQL_ATTR_OUTPUT_NTS:
if ((SQLUINTEGER) Value == SQL_TRUE)
return SQL_SUCCESS;
break;
default:
env->errornumber = CONN_INVALID_ARGUMENT_NO;
return SQL_ERROR;
}
env->errornumber = CONN_OPTION_VALUE_CHANGED;
env->errormsg = "SetEnv changed to ";
return SQL_SUCCESS_WITH_INFO;
}
/* SQLSet(Param/Scroll/Stmt)Option -> SQLSetStmtAttr */
SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
SQLINTEGER Attribute, SQLPOINTER Value,
SQLINTEGER StringLength)
{
static char *func = "SQLSetStmtAttr";
StatementClass *stmt = (StatementClass *) StatementHandle;
UDWORD rowcount;
mylog("[[%s]] %d,%u\n", func, Attribute, Value);
switch (Attribute)
{
case SQL_ATTR_PARAMSET_SIZE: /* 22 */
return PGAPI_ParamOptions(StatementHandle, (UWORD) Value, &rowcount);
case SQL_ATTR_PARAM_STATUS_PTR: /* 20 */
case SQL_ATTR_PARAMS_PROCESSED_PTR: /* 21 */
case SQL_ATTR_CURSOR_SCROLLABLE: /* -1 */
case SQL_ATTR_CURSOR_SENSITIVITY: /* -2 */
case SQL_ATTR_ENABLE_AUTO_IPD: /* 15 */
case SQL_ATTR_APP_ROW_DESC: /* 10010 */
case SQL_ATTR_APP_PARAM_DESC: /* 10011 */
case SQL_ATTR_AUTO_IPD: /* 10001 */
/*case SQL_ATTR_ROW_BIND_TYPE:*/ /* == SQL_BIND_TYPE */
case SQL_ATTR_IMP_ROW_DESC: /* 10012 */
case SQL_ATTR_IMP_PARAM_DESC: /* 10013 */
case SQL_ATTR_METADATA_ID: /* 10014 */
/* case SQL_ATTR_PREDICATE_PTR:
case SQL_ATTR_PREDICATE_OCTET_LENGTH_PTR: */
case SQL_ATTR_PARAM_BIND_OFFSET_PTR: /* 17 */
case SQL_ATTR_PARAM_BIND_TYPE: /* 18 */
case SQL_ATTR_PARAM_OPERATION_PTR: /* 19 */
case SQL_ATTR_ROW_BIND_OFFSET_PTR: /* 23 */
case SQL_ATTR_ROW_OPERATION_PTR: /* 24 */
stmt->errornumber = STMT_INVALID_OPTION_IDENTIFIER;
stmt->errormsg = "Unsupported statement option (Set)";
SC_log_error(func, "", stmt);
return SQL_ERROR;
case SQL_ATTR_FETCH_BOOKMARK_PTR: /* 16 */
stmt->options.bookmark_ptr = Value;
break;
case SQL_ATTR_ROW_STATUS_PTR: /* 25 */
stmt->options.rowStatusArray = (SQLUSMALLINT *) Value;
break;
case SQL_ATTR_ROWS_FETCHED_PTR: /* 26 */
stmt->options.rowsFetched = (SQLUINTEGER *) Value;
break;
case SQL_ATTR_ROW_ARRAY_SIZE: /* 27 */
stmt->options.rowset_size = (SQLUINTEGER) Value;
break;
default:
return PGAPI_SetStmtOption(StatementHandle, (UWORD) Attribute, (UDWORD) Value);
}
return SQL_SUCCESS;
}
#define SQL_FUNC_ESET(pfExists, uwAPI) \
(*(((UWORD*) (pfExists)) + ((uwAPI) >> 4)) \
|= (1 << ((uwAPI) & 0x000F)) \
)
RETCODE SQL_API
PGAPI_GetFunctions30(HDBC hdbc, UWORD fFunction, UWORD FAR *pfExists)
{
if (fFunction != SQL_API_ODBC3_ALL_FUNCTIONS)
return SQL_ERROR;
memset(pfExists, 0, sizeof(UWORD) * 250);
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLALLOCCONNECT); 1 deprecated */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLALLOCENV); 2 deprecated */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLALLOCSTMT); 3 deprecated */
/* for (i = SQL_API_SQLBINDCOL; i <= 23; i++)
SQL_FUNC_ESET(pfExists, i); */
SQL_FUNC_ESET(pfExists, SQL_API_SQLBINDCOL); /* 4 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCANCEL); /* 5 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLATTRIBUTE); /* 6 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCONNECT); /* 7 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLDESCRIBECOL); /* 8 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLDISCONNECT); /* 9 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLERROR); 10 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLEXECDIRECT); /* 11 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLEXECUTE); /* 12 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLFETCH); /* 13 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLFREECONNECT); 14 deprecated */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLFREEENV); 15 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLFREESTMT); /* 16 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCURSORNAME); /* 17 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLNUMRESULTCOLS); /* 18 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPREPARE); /* 19 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLROWCOUNT); /* 20 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCURSORNAME); /* 21 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLSETPARAM); 22 deprecated */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLTRANSACT); 23 deprecated */
/*for (i = 40; i < SQL_API_SQLEXTENDEDFETCH; i++)
SQL_FUNC_ESET(pfExists, i);*/
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNS); /* 40 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLDRIVERCONNECT); /* 41 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTOPTION); 42 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDATA); /* 43 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETFUNCTIONS); /* 44 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETINFO); /* 45 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLGETSTMTOPTION); 46 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETTYPEINFO); /* 47 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPARAMDATA); /* 48 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPUTDATA); /* 49 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTIONOPTION); 50 deprecated */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSTMTOPTION); 51 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSPECIALCOLUMNS); /* 52 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSTATISTICS); /* 53 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLES); /* 54 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLBROWSECONNECT); /* 55 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOLUMNPRIVILEGES); /* 56 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLDATASOURCES); /* 57 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLDESCRIBEPARAM); /* 58 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLEXTENDEDFETCH); 59 deprecated */
/*for (++i; i < SQL_API_SQLBINDPARAMETER; i++)
SQL_FUNC_ESET(pfExists, i);*/
SQL_FUNC_ESET(pfExists, SQL_API_SQLFOREIGNKEYS); /* 60 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLMORERESULTS); /* 61 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLNATIVESQL); /* 62 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLNUMPARAMS); /* 63 */
/* SQL_FUNC_ESET(pfExists, SQL_API_SQLPARAMOPTIONS); 64 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPRIMARYKEYS); /* 65 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPROCEDURECOLUMNS); /* 66 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLPROCEDURES); /* 67 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETPOS); /* 68 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSCROLLOPTIONS); /* 69 deprecated */
SQL_FUNC_ESET(pfExists, SQL_API_SQLTABLEPRIVILEGES); /* 70 */
/*SQL_FUNC_ESET(pfExists, SQL_API_SQLDRIVERS);*/ /* 71 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLBINDPARAMETER); /* 72 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLALLOCHANDLE); /* 1001 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLBINDPARAM); /* 1002 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCLOSECURSOR); /* 1003 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLCOPYDESC);/* 1004 not implemented yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLENDTRAN); /* 1005 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLFREEHANDLE); /* 1006 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTATTR); /* 1007 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCFIELD);/* 1008 not implemented yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC);/* 1009 not implemented yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGFIELD);/* 1010 not implemented yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGREC); /* 1011 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETENVATTR); /* 1012 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETSTMTATTR); /* 1014 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTATTR); /* 1016 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCFIELD); /* 1017 not implemeted yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 not implemented yet */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETENVATTR); /* 1019 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSTMTATTR); /* 1020 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLFETCHSCROLL); /* 1021 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLBULKOPERATIONS);/* 24 not implemented yet */
return SQL_SUCCESS;
}
SQLRETURN SQL_API
PGAPI_GetInfo30(HDBC hdbc, UWORD fInfoType, PTR rgbInfoValue,
SWORD cbInfoValueMax, SWORD FAR *pcbInfoValue)
{
static char *func = "PGAPI_GetInfo30";
ConnectionClass *conn = (ConnectionClass *) hdbc;
char *p = NULL;
int len = 0, value = 0;
SQLRETURN result;
switch (fInfoType)
{
case SQL_DYNAMIC_CURSOR_ATTRIBUTES1:
len = 4;
value = 0;
break;
case SQL_DYNAMIC_CURSOR_ATTRIBUTES2:
len = 4;
value = 0;
break;
case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE |
SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK;
break;
case SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2:
len = 4;
value = 0;
break;
case SQL_KEYSET_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE
| SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK
| SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION
| SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE
| SQL_CA1_POS_REFRESH
| SQL_CA1_BULK_ADD
| SQL_CA1_BULK_UPDATE_BY_BOOKMARK
| SQL_CA1_BULK_DELETE_BY_BOOKMARK
| SQL_CA1_BULK_FETCH_BY_BOOKMARK
;
break;
case SQL_KEYSET_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY |
SQL_CA2_SENSITIVITY_ADDITIONS |
SQL_CA2_SENSITIVITY_DELETIONS |
SQL_CA2_SENSITIVITY_UPDATES;
break;
case SQL_STATIC_CURSOR_ATTRIBUTES1:
len = 4;
value = SQL_CA1_NEXT | SQL_CA1_ABSOLUTE |
SQL_CA1_RELATIVE | SQL_CA1_BOOKMARK |
SQL_CA1_LOCK_NO_CHANGE | SQL_CA1_POS_POSITION |
SQL_CA1_POS_UPDATE | SQL_CA1_POS_DELETE |
SQL_CA1_POS_REFRESH;
break;
case SQL_STATIC_CURSOR_ATTRIBUTES2:
len = 4;
value = SQL_CA2_OPT_ROWVER_CONCURRENCY |
SQL_CA2_SENSITIVITY_ADDITIONS |
SQL_CA2_SENSITIVITY_DELETIONS |
SQL_CA2_SENSITIVITY_UPDATES;
break;
default:
/* unrecognized key */
conn->errormsg = "Unrecognized key passed to SQLGetInfo.";
conn->errornumber = CONN_NOT_IMPLEMENTED_ERROR;
CC_log_error(func, "", conn);
return SQL_ERROR;
}
result = SQL_SUCCESS;
if (p)
{
/* char/binary data */
len = strlen(p);
if (rgbInfoValue)
{
strncpy_null((char *) rgbInfoValue, p, (size_t) cbInfoValueMax);
if (len >= cbInfoValueMax)
{
result = SQL_SUCCESS_WITH_INFO;
conn->errornumber = STMT_TRUNCATED;
conn->errormsg = "The buffer was too small for tthe InfoValue.";
}
}
}
else
{
/* numeric data */
if (rgbInfoValue)
{
if (len == 2)
*((WORD *) rgbInfoValue) = (WORD) value;
else if (len == 4)
*((DWORD *) rgbInfoValue) = (DWORD) value;
}
}
if (pcbInfoValue)
*pcbInfoValue = len;
return result;
}

View file

@ -0,0 +1,248 @@
/*-------
* Module: pgapifunc.h
*
*-------
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "psqlodbc.h"
#include <stdio.h>
#include <string.h>
#ifndef WIN32
#include "iodbc.h"
#include "isqlext.h"
#else
#include <windows.h>
#include <sqlext.h>
#endif
SQLRETURN SQL_API PGAPI_AllocConnect(SQLHENV EnvironmentHandle,
SQLHDBC *ConnectionHandle);
SQLRETURN SQL_API PGAPI_AllocEnv(SQLHENV *EnvironmentHandle);
SQLRETURN SQL_API PGAPI_AllocStmt(SQLHDBC ConnectionHandle,
SQLHSTMT *StatementHandle);
SQLRETURN SQL_API PGAPI_BindCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
SQLPOINTER TargetValue, SQLINTEGER BufferLength,
SQLINTEGER *StrLen_or_Ind);
SQLRETURN SQL_API PGAPI_Cancel(SQLHSTMT StatementHandle);
SQLRETURN SQL_API PGAPI_Columns(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLCHAR *ColumnName, SQLSMALLINT NameLength4);
SQLRETURN SQL_API PGAPI_Connect(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName, SQLSMALLINT NameLength1,
SQLCHAR *UserName, SQLSMALLINT NameLength2,
SQLCHAR *Authentication, SQLSMALLINT NameLength3);
SQLRETURN SQL_API PGAPI_DriverConnect(HDBC hdbc, HWND hwnd,
UCHAR FAR *szConnStrIn, SWORD cbConnStrIn,
UCHAR FAR *szConnStrOut, SWORD cbConnStrOutMax,
SWORD FAR *pcbConnStrOut, UWORD fDriverCompletion);
SQLRETURN SQL_API PGAPI_BrowseConnect(SQLHDBC hdbc,
SQLCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn,
SQLCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax,
SQLSMALLINT *pcbConnStrOut);
SQLRETURN SQL_API PGAPI_DataSources(SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction, SQLCHAR *ServerName,
SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1,
SQLCHAR *Description, SQLSMALLINT BufferLength2,
SQLSMALLINT *NameLength2);
SQLRETURN SQL_API PGAPI_DescribeCol(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
SQLSMALLINT *DataType, SQLUINTEGER *ColumnSize,
SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable);
SQLRETURN SQL_API PGAPI_Disconnect(SQLHDBC ConnectionHandle);
SQLRETURN SQL_API PGAPI_Error(SQLHENV EnvironmentHandle,
SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle,
SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
SQLCHAR *MessageText, SQLSMALLINT BufferLength,
SQLSMALLINT *TextLength);
SQLRETURN SQL_API PGAPI_ExecDirect(SQLHSTMT StatementHandle,
SQLCHAR *StatementText, SQLINTEGER TextLength);
SQLRETURN SQL_API PGAPI_Execute(SQLHSTMT StatementHandle);
SQLRETURN SQL_API PGAPI_Fetch(SQLHSTMT StatementHandle);
SQLRETURN SQL_API PGAPI_FreeConnect(SQLHDBC ConnectionHandle);
SQLRETURN SQL_API PGAPI_FreeEnv(SQLHENV EnvironmentHandle);
SQLRETURN SQL_API PGAPI_FreeStmt(SQLHSTMT StatementHandle,
SQLUSMALLINT Option);
SQLRETURN SQL_API PGAPI_GetConnectOption(SQLHDBC ConnectionHandle,
SQLUSMALLINT Option, SQLPOINTER Value);
SQLRETURN SQL_API PGAPI_GetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName, SQLSMALLINT BufferLength,
SQLSMALLINT *NameLength);
SQLRETURN SQL_API PGAPI_GetData(SQLHSTMT StatementHandle,
SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
SQLPOINTER TargetValue, SQLINTEGER BufferLength,
SQLINTEGER *StrLen_or_Ind);
SQLRETURN SQL_API PGAPI_GetFunctions(SQLHDBC ConnectionHandle,
SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported);
SQLRETURN SQL_API PGAPI_GetFunctions30(SQLHDBC ConnectionHandle,
SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported);
SQLRETURN SQL_API PGAPI_GetInfo(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType, SQLPOINTER InfoValue,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength);
SQLRETURN SQL_API PGAPI_GetInfo30(SQLHDBC ConnectionHandle,
SQLUSMALLINT InfoType, SQLPOINTER InfoValue,
SQLSMALLINT BufferLength, SQLSMALLINT *StringLength);
SQLRETURN SQL_API PGAPI_GetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLPOINTER Value);
SQLRETURN SQL_API PGAPI_GetTypeInfo(SQLHSTMT StatementHandle,
SQLSMALLINT DataType);
SQLRETURN SQL_API PGAPI_NumResultCols(SQLHSTMT StatementHandle,
SQLSMALLINT *ColumnCount);
SQLRETURN SQL_API PGAPI_ParamData(SQLHSTMT StatementHandle,
SQLPOINTER *Value);
SQLRETURN SQL_API PGAPI_Prepare(SQLHSTMT StatementHandle,
SQLCHAR *StatementText, SQLINTEGER TextLength);
SQLRETURN SQL_API PGAPI_PutData(SQLHSTMT StatementHandle,
SQLPOINTER Data, SQLINTEGER StrLen_or_Ind);
SQLRETURN SQL_API PGAPI_RowCount(SQLHSTMT StatementHandle,
SQLINTEGER *RowCount);
SQLRETURN SQL_API PGAPI_SetConnectOption(SQLHDBC ConnectionHandle,
SQLUSMALLINT Option, SQLUINTEGER Value);
SQLRETURN SQL_API PGAPI_SetCursorName(SQLHSTMT StatementHandle,
SQLCHAR *CursorName, SQLSMALLINT NameLength);
SQLRETURN SQL_API PGAPI_SetParam(SQLHSTMT StatementHandle,
SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
SQLSMALLINT ParameterType, SQLUINTEGER LengthPrecision,
SQLSMALLINT ParameterScale, SQLPOINTER ParameterValue,
SQLINTEGER *StrLen_or_Ind);
SQLRETURN SQL_API PGAPI_SetStmtOption(SQLHSTMT StatementHandle,
SQLUSMALLINT Option, SQLUINTEGER Value);
SQLRETURN SQL_API PGAPI_SpecialColumns(SQLHSTMT StatementHandle,
SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName,
SQLSMALLINT NameLength1, SQLCHAR *SchemaName,
SQLSMALLINT NameLength2, SQLCHAR *TableName,
SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
SQLUSMALLINT Nullable);
SQLRETURN SQL_API PGAPI_Statistics(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLUSMALLINT Unique, SQLUSMALLINT Reserved);
SQLRETURN SQL_API PGAPI_Tables(SQLHSTMT StatementHandle,
SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
SQLCHAR *TableName, SQLSMALLINT NameLength3,
SQLCHAR *TableType, SQLSMALLINT NameLength4);
SQLRETURN SQL_API PGAPI_Transact(SQLHENV EnvironmentHandle,
SQLHDBC ConnectionHandle, SQLUSMALLINT CompletionType);
SQLRETURN SQL_API PGAPI_ColAttributes(
SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLUSMALLINT fDescType,
SQLPOINTER rgbDesc,
SQLSMALLINT cbDescMax,
SQLSMALLINT *pcbDesc,
SQLINTEGER *pfDesc);
SQLRETURN SQL_API PGAPI_ColumnPrivileges(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName,
SQLCHAR *szColumnName,
SQLSMALLINT cbColumnName);
SQLRETURN SQL_API PGAPI_DescribeParam(
SQLHSTMT hstmt,
SQLUSMALLINT ipar,
SQLSMALLINT *pfSqlType,
SQLUINTEGER *pcbParamDef,
SQLSMALLINT *pibScale,
SQLSMALLINT *pfNullable);
SQLRETURN SQL_API PGAPI_ExtendedFetch(
SQLHSTMT hstmt,
SQLUSMALLINT fFetchType,
SQLINTEGER irow,
SQLUINTEGER *pcrow,
SQLUSMALLINT *rgfRowStatus);
SQLRETURN SQL_API PGAPI_ForeignKeys(
SQLHSTMT hstmt,
SQLCHAR *szPkCatalogName,
SQLSMALLINT cbPkCatalogName,
SQLCHAR *szPkSchemaName,
SQLSMALLINT cbPkSchemaName,
SQLCHAR *szPkTableName,
SQLSMALLINT cbPkTableName,
SQLCHAR *szFkCatalogName,
SQLSMALLINT cbFkCatalogName,
SQLCHAR *szFkSchemaName,
SQLSMALLINT cbFkSchemaName,
SQLCHAR *szFkTableName,
SQLSMALLINT cbFkTableName);
SQLRETURN SQL_API PGAPI_MoreResults(
SQLHSTMT hstmt);
SQLRETURN SQL_API PGAPI_NativeSql(
SQLHDBC hdbc,
SQLCHAR *szSqlStrIn,
SQLINTEGER cbSqlStrIn,
SQLCHAR *szSqlStr,
SQLINTEGER cbSqlStrMax,
SQLINTEGER *pcbSqlStr);
SQLRETURN SQL_API PGAPI_NumParams(
SQLHSTMT hstmt,
SQLSMALLINT *pcpar);
SQLRETURN SQL_API PGAPI_ParamOptions(
SQLHSTMT hstmt,
SQLUINTEGER crow,
SQLUINTEGER *pirow);
SQLRETURN SQL_API PGAPI_PrimaryKeys(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName);
SQLRETURN SQL_API PGAPI_ProcedureColumns(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szProcName,
SQLSMALLINT cbProcName,
SQLCHAR *szColumnName,
SQLSMALLINT cbColumnName);
SQLRETURN SQL_API PGAPI_Procedures(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szProcName,
SQLSMALLINT cbProcName);
SQLRETURN SQL_API PGAPI_SetPos(
SQLHSTMT hstmt,
SQLUSMALLINT irow,
SQLUSMALLINT fOption,
SQLUSMALLINT fLock);
SQLRETURN SQL_API PGAPI_TablePrivileges(
SQLHSTMT hstmt,
SQLCHAR *szCatalogName,
SQLSMALLINT cbCatalogName,
SQLCHAR *szSchemaName,
SQLSMALLINT cbSchemaName,
SQLCHAR *szTableName,
SQLSMALLINT cbTableName);
SQLRETURN SQL_API PGAPI_BindParameter(
SQLHSTMT hstmt,
SQLUSMALLINT ipar,
SQLSMALLINT fParamType,
SQLSMALLINT fCType,
SQLSMALLINT fSqlType,
SQLUINTEGER cbColDef,
SQLSMALLINT ibScale,
SQLPOINTER rgbValue,
SQLINTEGER cbValueMax,
SQLINTEGER *pcbValue);
/* #include "pg_converr_check.h" */