4 * Description: This module contains routines related to
5 * preparing and executing an SQL statement.
9 * API functions: SQLAllocConnect, SQLAllocEnv, SQLAllocStmt,
10 SQLBindCol, SQLCancel, SQLColumns, SQLConnect,
11 SQLDataSources, SQLDescribeCol, SQLDisconnect,
12 SQLError, SQLExecDirect, SQLExecute, SQLFetch,
13 SQLFreeConnect, SQLFreeEnv, SQLFreeStmt,
14 SQLGetConnectOption, SQLGetCursorName, SQLGetData,
15 SQLGetFunctions, SQLGetInfo, SQLGetStmtOption,
16 SQLGetTypeInfo, SQLNumResultCols, SQLParamData,
17 SQLPrepare, SQLPutData, SQLRowCount,
18 SQLSetConnectOption, SQLSetCursorName, SQLSetParam,
19 SQLSetStmtOption, SQLSpecialColumns, SQLStatistics,
20 SQLTables, SQLTransact, SQLColAttributes,
21 SQLColumnPrivileges, SQLDescribeParam, SQLExtendedFetch,
22 SQLForeignKeys, SQLMoreResults, SQLNativeSql,
23 SQLNumParams, SQLParamOptions, SQLPrimaryKeys,
24 SQLProcedureColumns, SQLProcedures, SQLSetPos,
25 SQLTablePrivileges, SQLBindParameter
30 #define ODBCVER_REP 0x3000
36 #include "pgapifunc.h"
37 #include "connection.h"
38 #include "statement.h"
41 SQLAllocConnect(HENV EnvironmentHandle,
42 HDBC FAR * ConnectionHandle)
44 mylog("[SQLAllocConnect]");
45 return PGAPI_AllocConnect(EnvironmentHandle, ConnectionHandle);
49 SQLAllocEnv(HENV FAR * EnvironmentHandle)
51 mylog("[SQLAllocEnv]");
52 return PGAPI_AllocEnv(EnvironmentHandle);
56 SQLAllocStmt(HDBC ConnectionHandle,
57 HSTMT *StatementHandle)
59 mylog("[SQLAllocStmt]");
60 return PGAPI_AllocStmt(ConnectionHandle, StatementHandle);
64 SQLBindCol(HSTMT StatementHandle,
65 SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
66 PTR TargetValue, SQLINTEGER BufferLength,
67 SQLINTEGER *StrLen_or_Ind)
69 mylog("[SQLBindCol]");
70 return PGAPI_BindCol(StatementHandle, ColumnNumber,
71 TargetType, TargetValue, BufferLength, StrLen_or_Ind);
75 SQLCancel(HSTMT StatementHandle)
78 return PGAPI_Cancel(StatementHandle);
82 SQLColumns(HSTMT StatementHandle,
83 SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
84 SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
85 SQLCHAR *TableName, SQLSMALLINT NameLength3,
86 SQLCHAR *ColumnName, SQLSMALLINT NameLength4)
88 mylog("[SQLColumns]");
89 return PGAPI_Columns(StatementHandle, CatalogName, NameLength1,
90 SchemaName, NameLength2, TableName, NameLength3,
91 ColumnName, NameLength4);
96 SQLConnect(HDBC ConnectionHandle,
97 SQLCHAR *ServerName, SQLSMALLINT NameLength1,
98 SQLCHAR *UserName, SQLSMALLINT NameLength2,
99 SQLCHAR *Authentication, SQLSMALLINT NameLength3)
101 mylog("[SQLConnect]");
102 return PGAPI_Connect(ConnectionHandle, ServerName, NameLength1,
103 UserName, NameLength2, Authentication, NameLength3);
107 SQLDriverConnect(HDBC hdbc,
109 UCHAR FAR * szConnStrIn,
111 UCHAR FAR * szConnStrOut,
112 SWORD cbConnStrOutMax,
113 SWORD FAR * pcbConnStrOut,
114 UWORD fDriverCompletion)
116 mylog("[SQLDriverConnect]");
117 return PGAPI_DriverConnect(hdbc, hwnd, szConnStrIn, cbConnStrIn,
118 szConnStrOut, cbConnStrOutMax, pcbConnStrOut, fDriverCompletion);
123 SQLCHAR *szConnStrIn,
124 SQLSMALLINT cbConnStrIn,
125 SQLCHAR *szConnStrOut,
126 SQLSMALLINT cbConnStrOutMax,
127 SQLSMALLINT *pcbConnStrOut)
129 mylog("[SQLBrowseConnect]");
130 return PGAPI_BrowseConnect(hdbc, szConnStrIn, cbConnStrIn,
131 szConnStrOut, cbConnStrOutMax, pcbConnStrOut);
135 SQLDataSources(HENV EnvironmentHandle,
136 SQLUSMALLINT Direction, SQLCHAR *ServerName,
137 SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1,
138 SQLCHAR *Description, SQLSMALLINT BufferLength2,
139 SQLSMALLINT *NameLength2)
141 mylog("[SQLDataSources]");
144 * return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
145 * BufferLength1, NameLength1, Description, BufferLength2,
152 SQLDescribeCol(HSTMT StatementHandle,
153 SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
154 SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
155 SQLSMALLINT *DataType, SQLUINTEGER *ColumnSize,
156 SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable)
158 mylog("[SQLDescribeCol]");
159 return PGAPI_DescribeCol(StatementHandle, ColumnNumber,
160 ColumnName, BufferLength, NameLength,
161 DataType, ColumnSize, DecimalDigits, Nullable);
165 SQLDisconnect(HDBC ConnectionHandle)
167 mylog("[SQLDisconnect]");
168 return PGAPI_Disconnect(ConnectionHandle);
172 SQLError(HENV EnvironmentHandle,
173 HDBC ConnectionHandle, HSTMT StatementHandle,
174 SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
175 SQLCHAR *MessageText, SQLSMALLINT BufferLength,
176 SQLSMALLINT *TextLength)
179 return PGAPI_Error(EnvironmentHandle, ConnectionHandle, StatementHandle,
180 Sqlstate, NativeError, MessageText, BufferLength, TextLength);
184 SQLExecDirect(HSTMT StatementHandle,
185 SQLCHAR *StatementText, SQLINTEGER TextLength)
187 mylog("[SQLExecDirect]");
188 return PGAPI_ExecDirect(StatementHandle, StatementText, TextLength);
192 SQLExecute(HSTMT StatementHandle)
194 mylog("[SQLExecute]");
195 return PGAPI_Execute(StatementHandle);
199 SQLFetch(HSTMT StatementHandle)
201 static char *func = "SQLFetch";
203 #if (ODBCVER >= 0x3000)
204 StatementClass *stmt = (StatementClass *) StatementHandle;
205 ConnectionClass *conn = SC_get_conn(stmt);
207 if (conn->driver_version >= 0x0300)
209 SQLUSMALLINT *rowStatusArray = stmt->options.rowStatusArray;
210 SQLINTEGER *pcRow = stmt->options.rowsFetched;
212 mylog("[[%s]]", func);
213 return PGAPI_ExtendedFetch(StatementHandle, SQL_FETCH_NEXT, 0,
214 pcRow, rowStatusArray);
218 return PGAPI_Fetch(StatementHandle);
222 SQLFreeConnect(HDBC ConnectionHandle)
224 mylog("[SQLFreeStmt]");
225 return PGAPI_FreeConnect(ConnectionHandle);
229 SQLFreeEnv(HENV EnvironmentHandle)
231 mylog("[SQLFreeEnv]");
232 return PGAPI_FreeEnv(EnvironmentHandle);
236 SQLFreeStmt(HSTMT StatementHandle,
239 mylog("[SQLFreeStmt]");
240 return PGAPI_FreeStmt(StatementHandle, Option);
244 SQLGetConnectOption(HDBC ConnectionHandle,
245 SQLUSMALLINT Option, PTR Value)
247 mylog("[SQLGetConnectOption]");
248 return PGAPI_GetConnectOption(ConnectionHandle, Option, Value);
251 SQLGetCursorName(HSTMT StatementHandle,
252 SQLCHAR *CursorName, SQLSMALLINT BufferLength,
253 SQLSMALLINT *NameLength)
255 mylog("[SQLGetCursorName]");
256 return PGAPI_GetCursorName(StatementHandle, CursorName, BufferLength,
261 SQLGetData(HSTMT StatementHandle,
262 SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
263 PTR TargetValue, SQLINTEGER BufferLength,
264 SQLINTEGER *StrLen_or_Ind)
266 mylog("[SQLGetData]");
267 return PGAPI_GetData(StatementHandle, ColumnNumber, TargetType,
268 TargetValue, BufferLength, StrLen_or_Ind);
272 SQLGetFunctions(HDBC ConnectionHandle,
273 SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported)
275 mylog("[SQLGetFunctions]");
276 #if (ODBCVER >= 0x3000)
277 if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS)
278 return PGAPI_GetFunctions30(ConnectionHandle, FunctionId, Supported);
280 return PGAPI_GetFunctions(ConnectionHandle, FunctionId, Supported);
283 SQLGetInfo(HDBC ConnectionHandle,
284 SQLUSMALLINT InfoType, PTR InfoValue,
285 SQLSMALLINT BufferLength, SQLSMALLINT *StringLength)
287 #if (ODBCVER >= 0x3000)
290 mylog("[SQLGetInfo(30)]");
291 if ((ret = PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
292 BufferLength, StringLength)) == SQL_ERROR)
294 if (((ConnectionClass *) ConnectionHandle)->driver_version >= 0x3000)
295 return PGAPI_GetInfo30(ConnectionHandle, InfoType, InfoValue,
296 BufferLength, StringLength);
300 mylog("[SQLGetInfo]");
301 return PGAPI_GetInfo(ConnectionHandle, InfoType, InfoValue,
302 BufferLength, StringLength);
307 SQLGetStmtOption(HSTMT StatementHandle,
308 SQLUSMALLINT Option, PTR Value)
310 mylog("[SQLGetStmtOption]");
311 return PGAPI_GetStmtOption(StatementHandle, Option, Value);
315 SQLGetTypeInfo(HSTMT StatementHandle,
316 SQLSMALLINT DataType)
318 mylog("[SQLGetTypeInfo]");
319 return PGAPI_GetTypeInfo(StatementHandle, DataType);
323 SQLNumResultCols(HSTMT StatementHandle,
324 SQLSMALLINT *ColumnCount)
326 mylog("[SQLNumResultCols]");
327 return PGAPI_NumResultCols(StatementHandle, ColumnCount);
331 SQLParamData(HSTMT StatementHandle,
334 mylog("[SQLParamData]");
335 return PGAPI_ParamData(StatementHandle, Value);
339 SQLPrepare(HSTMT StatementHandle,
340 SQLCHAR *StatementText, SQLINTEGER TextLength)
342 mylog("[SQLPrepare]");
343 return PGAPI_Prepare(StatementHandle, StatementText, TextLength);
347 SQLPutData(HSTMT StatementHandle,
348 PTR Data, SQLINTEGER StrLen_or_Ind)
350 mylog("[SQLPutData]");
351 return PGAPI_PutData(StatementHandle, Data, StrLen_or_Ind);
355 SQLRowCount(HSTMT StatementHandle,
356 SQLINTEGER *RowCount)
358 mylog("[SQLRowCount]");
359 return PGAPI_RowCount(StatementHandle, RowCount);
363 SQLSetConnectOption(HDBC ConnectionHandle,
364 SQLUSMALLINT Option, SQLUINTEGER Value)
366 mylog("[SQLSetConnectionOption]");
367 return PGAPI_SetConnectOption(ConnectionHandle, Option, Value);
371 SQLSetCursorName(HSTMT StatementHandle,
372 SQLCHAR *CursorName, SQLSMALLINT NameLength)
374 mylog("[SQLSetCursorName]");
375 return PGAPI_SetCursorName(StatementHandle, CursorName, NameLength);
379 SQLSetParam(HSTMT StatementHandle,
380 SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
381 SQLSMALLINT ParameterType, SQLUINTEGER LengthPrecision,
382 SQLSMALLINT ParameterScale, PTR ParameterValue,
383 SQLINTEGER *StrLen_or_Ind)
385 mylog("[SQLSetParam]");
388 * return PGAPI_SetParam(StatementHandle, ParameterNumber, ValueType,
389 * ParameterType, LengthPrecision, ParameterScale, ParameterValue,
396 SQLSetStmtOption(HSTMT StatementHandle,
397 SQLUSMALLINT Option, SQLUINTEGER Value)
399 mylog("[SQLSetStmtOption]");
400 return PGAPI_SetStmtOption(StatementHandle, Option, Value);
404 SQLSpecialColumns(HSTMT StatementHandle,
405 SQLUSMALLINT IdentifierType, SQLCHAR *CatalogName,
406 SQLSMALLINT NameLength1, SQLCHAR *SchemaName,
407 SQLSMALLINT NameLength2, SQLCHAR *TableName,
408 SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
409 SQLUSMALLINT Nullable)
411 mylog("[SQLSpecialColumns]");
412 return PGAPI_SpecialColumns(StatementHandle, IdentifierType, CatalogName,
413 NameLength1, SchemaName, NameLength2, TableName, NameLength3,
418 SQLStatistics(HSTMT StatementHandle,
419 SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
420 SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
421 SQLCHAR *TableName, SQLSMALLINT NameLength3,
422 SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
424 mylog("[SQLStatistics]");
425 return PGAPI_Statistics(StatementHandle, CatalogName, NameLength1,
426 SchemaName, NameLength2, TableName, NameLength3, Unique,
431 SQLTables(HSTMT StatementHandle,
432 SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
433 SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
434 SQLCHAR *TableName, SQLSMALLINT NameLength3,
435 SQLCHAR *TableType, SQLSMALLINT NameLength4)
437 mylog("[SQLTables]");
438 return PGAPI_Tables(StatementHandle, CatalogName, NameLength1,
439 SchemaName, NameLength2, TableName, NameLength3,
440 TableType, NameLength4);
444 SQLTransact(HENV EnvironmentHandle,
445 HDBC ConnectionHandle, SQLUSMALLINT CompletionType)
447 mylog("[SQLTransact]");
448 return PGAPI_Transact(EnvironmentHandle, ConnectionHandle, CompletionType);
455 SQLUSMALLINT fDescType,
457 SQLSMALLINT cbDescMax,
458 SQLSMALLINT *pcbDesc,
461 mylog("[SQLColAttributes]");
462 return PGAPI_ColAttributes(hstmt, icol, fDescType, rgbDesc,
463 cbDescMax, pcbDesc, pfDesc);
469 SQLCHAR *szCatalogName,
470 SQLSMALLINT cbCatalogName,
471 SQLCHAR *szSchemaName,
472 SQLSMALLINT cbSchemaName,
473 SQLCHAR *szTableName,
474 SQLSMALLINT cbTableName,
475 SQLCHAR *szColumnName,
476 SQLSMALLINT cbColumnName)
478 mylog("[SQLColumnPrivileges]");
479 return PGAPI_ColumnPrivileges(hstmt, szCatalogName, cbCatalogName,
480 szSchemaName, cbSchemaName, szTableName, cbTableName,
481 szColumnName, cbColumnName);
488 SQLSMALLINT *pfSqlType,
489 SQLUINTEGER *pcbParamDef,
490 SQLSMALLINT *pibScale,
491 SQLSMALLINT *pfNullable)
493 mylog("[SQLDescribeParam]");
494 return PGAPI_DescribeParam(hstmt, ipar, pfSqlType, pcbParamDef,
495 pibScale, pfNullable);
501 SQLUSMALLINT fFetchType,
504 SQLUSMALLINT *rgfRowStatus)
506 mylog("[SQLExtendedFetch]");
507 return PGAPI_ExtendedFetch(hstmt, fFetchType, irow, pcrow, rgfRowStatus);
513 SQLCHAR *szPkCatalogName,
514 SQLSMALLINT cbPkCatalogName,
515 SQLCHAR *szPkSchemaName,
516 SQLSMALLINT cbPkSchemaName,
517 SQLCHAR *szPkTableName,
518 SQLSMALLINT cbPkTableName,
519 SQLCHAR *szFkCatalogName,
520 SQLSMALLINT cbFkCatalogName,
521 SQLCHAR *szFkSchemaName,
522 SQLSMALLINT cbFkSchemaName,
523 SQLCHAR *szFkTableName,
524 SQLSMALLINT cbFkTableName)
526 mylog("[SQLForeignKeys]");
527 return PGAPI_ForeignKeys(hstmt, szPkCatalogName, cbPkCatalogName,
528 szPkSchemaName, cbPkSchemaName, szPkTableName,
529 cbPkTableName, szFkCatalogName, cbFkCatalogName,
530 szFkSchemaName, cbFkSchemaName, szFkTableName, cbFkTableName);
534 SQLMoreResults(HSTMT hstmt)
536 mylog("[SQLMoreResults]");
537 return PGAPI_MoreResults(hstmt);
544 SQLINTEGER cbSqlStrIn,
546 SQLINTEGER cbSqlStrMax,
547 SQLINTEGER *pcbSqlStr)
549 mylog("[SQLNativeSql]");
550 return PGAPI_NativeSql(hdbc, szSqlStrIn, cbSqlStrIn, szSqlStr,
551 cbSqlStrMax, pcbSqlStr);
559 mylog("[SQLNumParams]");
560 return PGAPI_NumParams(hstmt, pcpar);
569 mylog("[SQLParamOptions]");
570 return PGAPI_ParamOptions(hstmt, crow, pirow);
576 SQLCHAR *szCatalogName,
577 SQLSMALLINT cbCatalogName,
578 SQLCHAR *szSchemaName,
579 SQLSMALLINT cbSchemaName,
580 SQLCHAR *szTableName,
581 SQLSMALLINT cbTableName)
583 mylog("[SQLPrimaryKeys]");
584 return PGAPI_PrimaryKeys(hstmt, szCatalogName, cbCatalogName,
585 szSchemaName, cbSchemaName, szTableName, cbTableName);
591 SQLCHAR *szCatalogName,
592 SQLSMALLINT cbCatalogName,
593 SQLCHAR *szSchemaName,
594 SQLSMALLINT cbSchemaName,
596 SQLSMALLINT cbProcName,
597 SQLCHAR *szColumnName,
598 SQLSMALLINT cbColumnName)
600 mylog("[SQLProcedureColumns]");
601 return PGAPI_ProcedureColumns(hstmt, szCatalogName, cbCatalogName,
602 szSchemaName, cbSchemaName, szProcName, cbProcName,
603 szColumnName, cbColumnName);
609 SQLCHAR *szCatalogName,
610 SQLSMALLINT cbCatalogName,
611 SQLCHAR *szSchemaName,
612 SQLSMALLINT cbSchemaName,
614 SQLSMALLINT cbProcName)
616 mylog("[SQLProcedures]");
617 return PGAPI_Procedures(hstmt, szCatalogName, cbCatalogName,
618 szSchemaName, cbSchemaName, szProcName, cbProcName);
625 SQLUSMALLINT fOption,
628 mylog("[SQLSetPos]");
629 return PGAPI_SetPos(hstmt, irow, fOption, fLock);
635 SQLCHAR *szCatalogName,
636 SQLSMALLINT cbCatalogName,
637 SQLCHAR *szSchemaName,
638 SQLSMALLINT cbSchemaName,
639 SQLCHAR *szTableName,
640 SQLSMALLINT cbTableName)
642 mylog("[SQLTablePrivileges]");
643 return PGAPI_TablePrivileges(hstmt, szCatalogName, cbCatalogName,
644 szSchemaName, cbSchemaName, szTableName, cbTableName);
651 SQLSMALLINT fParamType,
653 SQLSMALLINT fSqlType,
654 SQLUINTEGER cbColDef,
657 SQLINTEGER cbValueMax,
658 SQLINTEGER *pcbValue)
660 mylog("[SQLBindParameter]");
661 return PGAPI_BindParameter(hstmt, ipar, fParamType, fCType,
662 fSqlType, cbColDef, ibScale, rgbValue, cbValueMax,