2 * Description: This module contains routines related to
3 * preparing and executing an SQL statement.
11 #include "connection.h"
12 #include "statement.h"
16 SQLBindCol(HSTMT StatementHandle
,
17 SQLUSMALLINT ColumnNumber
, SQLSMALLINT TargetType
,
18 PTR TargetValue
, SQLLEN BufferLength
, SQLLEN
* StrLen_or_Ind
)
21 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
26 StartRollbackState(stmt
);
27 ret
= PGAPI_BindCol(StatementHandle
, ColumnNumber
,
28 TargetType
, TargetValue
, BufferLength
,
30 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
35 RETCODE SQL_API
SQLCancel(HSTMT StatementHandle
)
38 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
41 /* Not that neither ENTER_STMT_CS nor StartRollbackState is called */
42 /* SC_clear_error((StatementClass *) StatementHandle); maybe this neither */
43 ret
= PGAPI_Cancel(StatementHandle
);
44 return DiscardStatementSvp(stmt
, ret
, FALSE
);
48 SQLColumns(HSTMT StatementHandle
,
49 SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
50 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
,
51 SQLCHAR
* TableName
, SQLSMALLINT NameLength3
,
52 SQLCHAR
* ColumnName
, SQLSMALLINT NameLength4
)
54 CSTR func
= "SQLColumns";
56 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
57 SQLCHAR
*ctName
= CatalogName
, *scName
= SchemaName
,
58 *tbName
= TableName
, *clName
= ColumnName
;
59 UWORD flag
= PODBC_SEARCH_PUBLIC_SCHEMA
;
64 StartRollbackState(stmt
);
65 if (stmt
->options
.metadata_id
)
66 flag
|= PODBC_NOT_SEARCH_PATTERN
;
67 if (SC_opencheck(stmt
, func
))
70 ret
= PGAPI_Columns(StatementHandle
, ctName
, NameLength1
,
71 scName
, NameLength2
, tbName
, NameLength3
,
72 clName
, NameLength4
, flag
, 0, 0);
73 if (SQL_SUCCESS
== ret
74 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
76 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
77 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
, *newCl
= NULL
;
78 ConnectionClass
*conn
= SC_get_conn(stmt
);
80 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
83 make_lstring_ifneeded(conn
, CatalogName
, NameLength1
,
84 ifallupper
), NULL
!= newCt
)
86 ctName
= (UCHAR
*)newCt
;
90 make_lstring_ifneeded(conn
, SchemaName
, NameLength2
,
91 ifallupper
), NULL
!= newSc
)
93 scName
= (UCHAR
*)newSc
;
97 make_lstring_ifneeded(conn
, TableName
, NameLength3
,
98 ifallupper
), NULL
!= newTb
)
100 tbName
= (UCHAR
*)newTb
;
104 make_lstring_ifneeded(conn
, ColumnName
, NameLength4
,
105 ifallupper
), NULL
!= newCl
)
107 clName
= (UCHAR
*)newCl
;
112 ret
= PGAPI_Columns(StatementHandle
, ctName
, NameLength1
,
113 scName
, NameLength2
, tbName
,
114 NameLength3
, clName
, NameLength4
, flag
,
126 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
133 SQLConnect(HDBC ConnectionHandle
,
134 SQLCHAR
* ServerName
, SQLSMALLINT NameLength1
,
135 SQLCHAR
* UserName
, SQLSMALLINT NameLength2
,
136 SQLCHAR
* Authentication
, SQLSMALLINT NameLength3
)
139 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
143 CC_clear_error(conn
);
144 ret
= PGAPI_Connect(ConnectionHandle
, ServerName
, NameLength1
,
145 UserName
, NameLength2
, Authentication
,
152 SQLDriverConnect(HDBC hdbc
,
154 SQLCHAR FAR
* szConnStrIn
,
155 SQLSMALLINT cbConnStrIn
,
156 SQLCHAR FAR
* szConnStrOut
,
157 SQLSMALLINT cbConnStrOutMax
,
158 SQLSMALLINT FAR
* pcbConnStrOut
,
159 SQLUSMALLINT fDriverCompletion
)
162 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
166 CC_clear_error(conn
);
167 ret
= PGAPI_DriverConnect(hdbc
, hwnd
, szConnStrIn
, cbConnStrIn
,
168 szConnStrOut
, cbConnStrOutMax
,
169 pcbConnStrOut
, fDriverCompletion
);
175 SQLBrowseConnect(HDBC hdbc
,
176 SQLCHAR
* szConnStrIn
,
177 SQLSMALLINT cbConnStrIn
,
178 SQLCHAR
* szConnStrOut
,
179 SQLSMALLINT cbConnStrOutMax
,
180 SQLSMALLINT
* pcbConnStrOut
)
183 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
187 CC_clear_error(conn
);
188 ret
= PGAPI_BrowseConnect(hdbc
, szConnStrIn
, cbConnStrIn
,
189 szConnStrOut
, cbConnStrOutMax
,
196 SQLDataSources(HENV EnvironmentHandle
,
197 SQLUSMALLINT Direction
, SQLCHAR
* ServerName
,
198 SQLSMALLINT BufferLength1
, SQLSMALLINT
* NameLength1
,
199 SQLCHAR
* Description
, SQLSMALLINT BufferLength2
,
200 SQLSMALLINT
* NameLength2
)
203 mylog("Not implemented!\n");
206 * return PGAPI_DataSources(EnvironmentHandle, Direction, ServerName,
207 * BufferLength1, NameLength1, Description, BufferLength2,
214 SQLDescribeCol(HSTMT StatementHandle
,
215 SQLUSMALLINT ColumnNumber
, SQLCHAR
* ColumnName
,
216 SQLSMALLINT BufferLength
, SQLSMALLINT
* NameLength
,
217 SQLSMALLINT
* DataType
, SQLULEN
* ColumnSize
,
218 SQLSMALLINT
* DecimalDigits
, SQLSMALLINT
* Nullable
)
221 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
225 SC_clear_error(stmt
);
226 StartRollbackState(stmt
);
227 ret
= PGAPI_DescribeCol(StatementHandle
, ColumnNumber
,
228 ColumnName
, BufferLength
, NameLength
,
229 DataType
, ColumnSize
, DecimalDigits
,
231 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
236 RETCODE SQL_API
SQLDisconnect(HDBC ConnectionHandle
)
239 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
242 #ifdef _HANDLE_ENLIST_IN_DTC_
243 CALL_DtcOnDisconnect(conn
); /* must be called without holding the connection lock */
244 #endif /* _HANDLE_ENLIST_IN_DTC_ */
246 CC_clear_error(conn
);
247 ret
= PGAPI_Disconnect(ConnectionHandle
);
254 SQLExecDirect(HSTMT StatementHandle
,
255 SQLCHAR
* StatementText
, SQLINTEGER TextLength
)
257 CSTR func
= "SQLExecDirect";
259 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
264 SC_clear_error(stmt
);
265 if (PG_VERSION_GE(SC_get_conn(stmt
), 7.4))
266 flag
|= PODBC_WITH_HOLD
;
267 if (SC_opencheck(stmt
, func
))
271 StartRollbackState(stmt
);
273 PGAPI_ExecDirect_Vx(StatementHandle
, StatementText
, TextLength
,
275 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
281 RETCODE SQL_API
SQLExecute(HSTMT StatementHandle
)
283 CSTR func
= "SQLExecute";
285 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
290 SC_clear_error(stmt
);
291 if (PG_VERSION_GE(SC_get_conn(stmt
), 7.4))
292 flag
|= PODBC_WITH_HOLD
;
293 if (SC_opencheck(stmt
, func
))
297 StartRollbackState(stmt
);
298 ret
= PGAPI_Execute_Vx(StatementHandle
, flag
);
299 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
305 RETCODE SQL_API
SQLFetch(HSTMT StatementHandle
)
308 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
312 SC_clear_error(stmt
);
313 StartRollbackState(stmt
);
314 if (SC_get_conn(stmt
)->driver_version
>= 0x0300)
316 IRDFields
*irdopts
= SC_get_IRDF(stmt
);
317 ARDFields
*ardopts
= SC_get_ARDF(stmt
);
318 SQLUSMALLINT
*rowStatusArray
= irdopts
->rowStatusArray
;
319 SQLUINTEGER
*pcRow
= irdopts
->rowsFetched
;
321 ret
= PGAPI_ExtendedFetch(StatementHandle
, SQL_FETCH_NEXT
, 0,
322 pcRow
, rowStatusArray
, 0,
323 ardopts
->size_of_rowset
);
324 stmt
->transition_status
= 6;
327 ret
= PGAPI_Fetch(StatementHandle
);
328 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
334 RETCODE SQL_API
SQLFreeStmt(HSTMT StatementHandle
, SQLUSMALLINT Option
)
339 ret
= PGAPI_FreeStmt(StatementHandle
, Option
);
345 SQLGetCursorName(HSTMT StatementHandle
,
346 SQLCHAR
* CursorName
, SQLSMALLINT BufferLength
,
347 SQLSMALLINT
* NameLength
)
350 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
354 SC_clear_error(stmt
);
355 StartRollbackState(stmt
);
356 ret
= PGAPI_GetCursorName(StatementHandle
, CursorName
, BufferLength
,
358 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
364 SQLGetData(HSTMT StatementHandle
,
365 SQLUSMALLINT ColumnNumber
, SQLSMALLINT TargetType
,
366 PTR TargetValue
, SQLLEN BufferLength
, SQLLEN
* StrLen_or_Ind
)
369 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
373 SC_clear_error(stmt
);
374 StartRollbackState(stmt
);
375 ret
= PGAPI_GetData(StatementHandle
, ColumnNumber
, TargetType
,
376 TargetValue
, BufferLength
, StrLen_or_Ind
);
377 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
383 SQLGetFunctions(HDBC ConnectionHandle
,
384 SQLUSMALLINT FunctionId
, SQLUSMALLINT
* Supported
)
387 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
391 CC_clear_error(conn
);
392 if (FunctionId
== SQL_API_ODBC3_ALL_FUNCTIONS
)
394 PGAPI_GetFunctions30(ConnectionHandle
, FunctionId
,
399 PGAPI_GetFunctions(ConnectionHandle
, FunctionId
, Supported
);
406 SQLGetInfo(HDBC ConnectionHandle
,
407 SQLUSMALLINT InfoType
, PTR InfoValue
,
408 SQLSMALLINT BufferLength
, SQLSMALLINT
* StringLength
)
411 ConnectionClass
*conn
= (ConnectionClass
*) ConnectionHandle
;
415 CC_clear_error(conn
);
416 if ((ret
= PGAPI_GetInfo(ConnectionHandle
, InfoType
, InfoValue
,
417 BufferLength
, StringLength
)) == SQL_ERROR
)
419 if (conn
->driver_version
>= 0x0300)
421 CC_clear_error(conn
);
422 ret
= PGAPI_GetInfo30(ConnectionHandle
, InfoType
, InfoValue
,
423 BufferLength
, StringLength
);
427 if (SQL_ERROR
== ret
)
428 CC_log_error("SQLGetInfo(30)", "", conn
);
436 SQLGetTypeInfo(HSTMT StatementHandle
, SQLSMALLINT DataType
)
438 CSTR func
= "SQLGetTypeInfo";
440 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
444 SC_clear_error(stmt
);
445 if (SC_opencheck(stmt
, func
))
449 StartRollbackState(stmt
);
450 ret
= PGAPI_GetTypeInfo(StatementHandle
, DataType
);
451 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
458 SQLNumResultCols(HSTMT StatementHandle
, SQLSMALLINT
* ColumnCount
)
461 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
465 SC_clear_error(stmt
);
466 StartRollbackState(stmt
);
467 ret
= PGAPI_NumResultCols(StatementHandle
, ColumnCount
);
468 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
473 RETCODE SQL_API
SQLParamData(HSTMT StatementHandle
, PTR
* Value
)
476 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
480 SC_clear_error(stmt
);
481 ret
= PGAPI_ParamData(StatementHandle
, Value
);
482 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
488 SQLPrepare(HSTMT StatementHandle
,
489 SQLCHAR
* StatementText
, SQLINTEGER TextLength
)
492 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
496 SC_clear_error(stmt
);
497 StartRollbackState(stmt
);
498 ret
= PGAPI_Prepare(StatementHandle
, StatementText
, TextLength
);
499 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
505 SQLPutData(HSTMT StatementHandle
, PTR Data
, SQLLEN StrLen_or_Ind
)
508 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
512 SC_clear_error(stmt
);
513 ret
= PGAPI_PutData(StatementHandle
, Data
, StrLen_or_Ind
);
514 ret
= DiscardStatementSvp(stmt
, ret
, TRUE
);
519 RETCODE SQL_API
SQLRowCount(HSTMT StatementHandle
, SQLLEN
* RowCount
)
522 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
526 SC_clear_error(stmt
);
527 StartRollbackState(stmt
);
528 ret
= PGAPI_RowCount(StatementHandle
, RowCount
);
529 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
536 SQLSetCursorName(HSTMT StatementHandle
,
537 SQLCHAR
* CursorName
, SQLSMALLINT NameLength
)
540 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
544 SC_clear_error(stmt
);
545 StartRollbackState(stmt
);
546 ret
= PGAPI_SetCursorName(StatementHandle
, CursorName
, NameLength
);
547 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
553 SQLSetParam(HSTMT StatementHandle
,
554 SQLUSMALLINT ParameterNumber
, SQLSMALLINT ValueType
,
555 SQLSMALLINT ParameterType
, SQLULEN LengthPrecision
,
556 SQLSMALLINT ParameterScale
, PTR ParameterValue
,
557 SQLLEN
* StrLen_or_Ind
)
560 SC_clear_error((StatementClass
*) StatementHandle
);
563 * return PGAPI_SetParam(StatementHandle, ParameterNumber, ValueType,
564 * ParameterType, LengthPrecision, ParameterScale, ParameterValue,
572 SQLSpecialColumns(HSTMT StatementHandle
,
573 SQLUSMALLINT IdentifierType
, SQLCHAR
* CatalogName
,
574 SQLSMALLINT NameLength1
, SQLCHAR
* SchemaName
,
575 SQLSMALLINT NameLength2
, SQLCHAR
* TableName
,
576 SQLSMALLINT NameLength3
, SQLUSMALLINT Scope
,
577 SQLUSMALLINT Nullable
)
579 CSTR func
= "SQLSpecialColumns";
581 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
582 SQLCHAR
*ctName
= CatalogName
, *scName
= SchemaName
, *tbName
=
587 SC_clear_error(stmt
);
588 StartRollbackState(stmt
);
589 if (SC_opencheck(stmt
, func
))
593 PGAPI_SpecialColumns(StatementHandle
, IdentifierType
,
594 ctName
, NameLength1
, scName
,
595 NameLength2
, tbName
, NameLength3
,
597 if (SQL_SUCCESS
== ret
598 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
600 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
601 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
;
602 ConnectionClass
*conn
= SC_get_conn(stmt
);
604 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
607 make_lstring_ifneeded(conn
, CatalogName
, NameLength1
,
608 ifallupper
), NULL
!= newCt
)
610 ctName
= (UCHAR
*)newCt
;
614 make_lstring_ifneeded(conn
, SchemaName
, NameLength2
,
615 ifallupper
), NULL
!= newSc
)
617 scName
= (UCHAR
*)newSc
;
621 make_lstring_ifneeded(conn
, TableName
, NameLength3
,
622 ifallupper
), NULL
!= newTb
)
624 tbName
= (UCHAR
*)newTb
;
630 PGAPI_SpecialColumns(StatementHandle
, IdentifierType
,
631 ctName
, NameLength1
, scName
,
632 NameLength2
, tbName
, NameLength3
,
642 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
648 SQLStatistics(HSTMT StatementHandle
,
649 SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
650 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
,
651 SQLCHAR
* TableName
, SQLSMALLINT NameLength3
,
652 SQLUSMALLINT Unique
, SQLUSMALLINT Reserved
)
654 CSTR func
= "SQLStatistics";
656 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
657 SQLCHAR
*ctName
= CatalogName
, *scName
= SchemaName
, *tbName
=
662 SC_clear_error(stmt
);
663 StartRollbackState(stmt
);
664 if (SC_opencheck(stmt
, func
))
667 ret
= PGAPI_Statistics(StatementHandle
, ctName
, NameLength1
,
668 scName
, NameLength2
, tbName
, NameLength3
,
670 if (SQL_SUCCESS
== ret
671 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
673 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
674 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
;
675 ConnectionClass
*conn
= SC_get_conn(stmt
);
677 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
680 make_lstring_ifneeded(conn
, CatalogName
, NameLength1
,
681 ifallupper
), NULL
!= newCt
)
683 ctName
= (UCHAR
*)newCt
;
687 make_lstring_ifneeded(conn
, SchemaName
, NameLength2
,
688 ifallupper
), NULL
!= newSc
)
690 scName
= (UCHAR
*)newSc
;
694 make_lstring_ifneeded(conn
, TableName
, NameLength3
,
695 ifallupper
), NULL
!= newTb
)
697 tbName
= (UCHAR
*)newTb
;
702 ret
= PGAPI_Statistics(StatementHandle
, ctName
, NameLength1
,
703 scName
, NameLength2
, tbName
,
704 NameLength3
, Unique
, Reserved
);
713 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
719 SQLTables(HSTMT StatementHandle
,
720 SQLCHAR
* CatalogName
, SQLSMALLINT NameLength1
,
721 SQLCHAR
* SchemaName
, SQLSMALLINT NameLength2
,
722 SQLCHAR
* TableName
, SQLSMALLINT NameLength3
,
723 SQLCHAR
* TableType
, SQLSMALLINT NameLength4
)
725 CSTR func
= "SQLTables";
727 StatementClass
*stmt
= (StatementClass
*) StatementHandle
;
728 SQLCHAR
*ctName
= CatalogName
, *scName
= SchemaName
, *tbName
=
734 SC_clear_error(stmt
);
735 StartRollbackState(stmt
);
736 if (stmt
->options
.metadata_id
)
737 flag
|= PODBC_NOT_SEARCH_PATTERN
;
738 if (SC_opencheck(stmt
, func
))
741 ret
= PGAPI_Tables(StatementHandle
, ctName
, NameLength1
,
742 scName
, NameLength2
, tbName
, NameLength3
,
743 TableType
, NameLength4
, flag
);
744 if (SQL_SUCCESS
== ret
745 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
747 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
748 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
;
749 ConnectionClass
*conn
= SC_get_conn(stmt
);
751 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
754 make_lstring_ifneeded(conn
, CatalogName
, NameLength1
,
755 ifallupper
), NULL
!= newCt
)
757 ctName
= (UCHAR
*)newCt
;
761 make_lstring_ifneeded(conn
, SchemaName
, NameLength2
,
762 ifallupper
), NULL
!= newSc
)
764 scName
= (UCHAR
*)newSc
;
768 make_lstring_ifneeded(conn
, TableName
, NameLength3
,
769 ifallupper
), NULL
!= newTb
)
771 tbName
= (UCHAR
*)newTb
;
776 ret
= PGAPI_Tables(StatementHandle
, ctName
, NameLength1
,
777 scName
, NameLength2
, tbName
, NameLength3
,
778 TableType
, NameLength4
, flag
);
787 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
794 SQLColumnPrivileges(HSTMT hstmt
,
795 SQLCHAR
* szCatalogName
,
796 SQLSMALLINT cbCatalogName
,
797 SQLCHAR
* szSchemaName
,
798 SQLSMALLINT cbSchemaName
,
799 SQLCHAR
* szTableName
,
800 SQLSMALLINT cbTableName
,
801 SQLCHAR
* szColumnName
, SQLSMALLINT cbColumnName
)
803 CSTR func
= "SQLColumnPrivileges";
805 StatementClass
*stmt
= (StatementClass
*) hstmt
;
806 SQLCHAR
*ctName
= szCatalogName
, *scName
= szSchemaName
,
807 *tbName
= szTableName
, *clName
= szColumnName
;
812 SC_clear_error(stmt
);
813 StartRollbackState(stmt
);
814 if (stmt
->options
.metadata_id
)
815 flag
|= PODBC_NOT_SEARCH_PATTERN
;
816 if (SC_opencheck(stmt
, func
))
819 ret
= PGAPI_ColumnPrivileges(hstmt
, ctName
, cbCatalogName
,
820 scName
, cbSchemaName
, tbName
,
821 cbTableName
, clName
, cbColumnName
,
823 if (SQL_SUCCESS
== ret
824 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
826 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
827 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
, *newCl
= NULL
;
828 ConnectionClass
*conn
= SC_get_conn(stmt
);
830 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
833 make_lstring_ifneeded(conn
, szCatalogName
, cbCatalogName
,
834 ifallupper
), NULL
!= newCt
)
836 ctName
= (UCHAR
*)newCt
;
840 make_lstring_ifneeded(conn
, szSchemaName
, cbSchemaName
,
841 ifallupper
), NULL
!= newSc
)
843 scName
= (UCHAR
*)newSc
;
847 make_lstring_ifneeded(conn
, szTableName
, cbTableName
,
848 ifallupper
), NULL
!= newTb
)
850 tbName
= (UCHAR
*)newTb
;
854 make_lstring_ifneeded(conn
, szColumnName
, cbColumnName
,
855 ifallupper
), NULL
!= newCl
)
857 clName
= (UCHAR
*)newCl
;
862 ret
= PGAPI_ColumnPrivileges(hstmt
, ctName
, cbCatalogName
,
863 scName
, cbSchemaName
, tbName
,
876 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
882 SQLDescribeParam(HSTMT hstmt
,
884 SQLSMALLINT
* pfSqlType
,
885 SQLULEN
* pcbParamDef
,
886 SQLSMALLINT
* pibScale
, SQLSMALLINT
* pfNullable
)
889 StatementClass
*stmt
= (StatementClass
*) hstmt
;
893 SC_clear_error(stmt
);
894 StartRollbackState(stmt
);
895 ret
= PGAPI_DescribeParam(hstmt
, ipar
, pfSqlType
, pcbParamDef
,
896 pibScale
, pfNullable
);
897 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
903 SQLExtendedFetch(HSTMT hstmt
, SQLUSMALLINT fFetchType
, SQLLEN irow
,
905 SQLROWSETSIZE
* pcrow
,
908 #endif /* WITH_UNIXODBC */
909 SQLUSMALLINT
* rgfRowStatus
)
912 StatementClass
*stmt
= (StatementClass
*) hstmt
;
916 SC_clear_error(stmt
);
917 StartRollbackState(stmt
);
923 PGAPI_ExtendedFetch(hstmt
, fFetchType
, irow
, &retrieved
,
926 size_of_rowset_odbc2
);
932 PGAPI_ExtendedFetch(hstmt
, fFetchType
, irow
, pcrow
,
934 SC_get_ARDF(stmt
)->size_of_rowset_odbc2
);
935 #endif /* WITH_UNIXODBC */
936 stmt
->transition_status
= 7;
937 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
943 SQLForeignKeys(HSTMT hstmt
,
944 SQLCHAR
* szPkCatalogName
,
945 SQLSMALLINT cbPkCatalogName
,
946 SQLCHAR
* szPkSchemaName
,
947 SQLSMALLINT cbPkSchemaName
,
948 SQLCHAR
* szPkTableName
,
949 SQLSMALLINT cbPkTableName
,
950 SQLCHAR
* szFkCatalogName
,
951 SQLSMALLINT cbFkCatalogName
,
952 SQLCHAR
* szFkSchemaName
,
953 SQLSMALLINT cbFkSchemaName
,
954 SQLCHAR
* szFkTableName
, SQLSMALLINT cbFkTableName
)
956 CSTR func
= "SQLForeignKeys";
958 StatementClass
*stmt
= (StatementClass
*) hstmt
;
959 SQLCHAR
*pkctName
= szPkCatalogName
, *pkscName
= szPkSchemaName
,
960 *pktbName
= szPkTableName
, *fkctName
= szFkCatalogName
,
961 *fkscName
= szFkSchemaName
, *fktbName
= szFkTableName
;
965 SC_clear_error(stmt
);
966 StartRollbackState(stmt
);
967 if (SC_opencheck(stmt
, func
))
970 ret
= PGAPI_ForeignKeys(hstmt
, pkctName
, cbPkCatalogName
,
971 pkscName
, cbPkSchemaName
, pktbName
,
972 cbPkTableName
, fkctName
,
973 cbFkCatalogName
, fkscName
,
974 cbFkSchemaName
, fktbName
,
976 if (SQL_SUCCESS
== ret
977 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
979 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
980 char *newPkct
= NULL
, *newPksc
= NULL
, *newPktb
= NULL
,
981 *newFkct
= NULL
, *newFksc
= NULL
, *newFktb
= NULL
;
982 ConnectionClass
*conn
= SC_get_conn(stmt
);
984 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
987 make_lstring_ifneeded(conn
, szPkCatalogName
,
988 cbPkCatalogName
, ifallupper
),
991 pkctName
= (UCHAR
*)newPkct
;
995 make_lstring_ifneeded(conn
, szPkSchemaName
, cbPkSchemaName
,
996 ifallupper
), NULL
!= newPksc
)
998 pkscName
= (UCHAR
*)newPksc
;
1002 make_lstring_ifneeded(conn
, szPkTableName
, cbPkTableName
,
1003 ifallupper
), NULL
!= newPktb
)
1005 pktbName
= (UCHAR
*)newPktb
;
1009 make_lstring_ifneeded(conn
, szFkCatalogName
,
1010 cbFkCatalogName
, ifallupper
),
1013 fkctName
= (UCHAR
*)newFkct
;
1017 make_lstring_ifneeded(conn
, szFkSchemaName
, cbFkSchemaName
,
1018 ifallupper
), NULL
!= newFksc
)
1020 fkscName
= (UCHAR
*)newFksc
;
1024 make_lstring_ifneeded(conn
, szFkTableName
, cbFkTableName
,
1025 ifallupper
), NULL
!= newFktb
)
1027 fktbName
= (UCHAR
*)newFktb
;
1032 ret
= PGAPI_ForeignKeys(hstmt
, pkctName
, cbPkCatalogName
,
1033 pkscName
, cbPkSchemaName
, pktbName
,
1034 cbPkTableName
, fkctName
,
1035 cbFkCatalogName
, fkscName
,
1036 cbFkSchemaName
, fktbName
,
1052 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1053 LEAVE_STMT_CS(stmt
);
1057 RETCODE SQL_API
SQLMoreResults(HSTMT hstmt
)
1060 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1063 ENTER_STMT_CS(stmt
);
1064 SC_clear_error(stmt
);
1065 StartRollbackState(stmt
);
1066 ret
= PGAPI_MoreResults(hstmt
);
1067 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1068 LEAVE_STMT_CS(stmt
);
1073 SQLNativeSql(HDBC hdbc
,
1074 SQLCHAR
* szSqlStrIn
,
1075 SQLINTEGER cbSqlStrIn
,
1077 SQLINTEGER cbSqlStrMax
, SQLINTEGER
* pcbSqlStr
)
1080 ConnectionClass
*conn
= (ConnectionClass
*) hdbc
;
1083 ENTER_CONN_CS(conn
);
1084 CC_clear_error(conn
);
1085 ret
= PGAPI_NativeSql(hdbc
, szSqlStrIn
, cbSqlStrIn
, szSqlStr
,
1086 cbSqlStrMax
, pcbSqlStr
);
1087 LEAVE_CONN_CS(conn
);
1091 RETCODE SQL_API
SQLNumParams(HSTMT hstmt
, SQLSMALLINT
* pcpar
)
1094 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1097 ENTER_STMT_CS(stmt
);
1098 SC_clear_error(stmt
);
1099 StartRollbackState(stmt
);
1100 ret
= PGAPI_NumParams(hstmt
, pcpar
);
1101 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1102 LEAVE_STMT_CS(stmt
);
1108 SQLPrimaryKeys(HSTMT hstmt
,
1109 SQLCHAR
* szCatalogName
,
1110 SQLSMALLINT cbCatalogName
,
1111 SQLCHAR
* szSchemaName
,
1112 SQLSMALLINT cbSchemaName
,
1113 SQLCHAR
* szTableName
, SQLSMALLINT cbTableName
)
1115 CSTR func
= "SQLPrimaryKeys";
1117 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1118 SQLCHAR
*ctName
= szCatalogName
, *scName
= szSchemaName
,
1119 *tbName
= szTableName
;
1122 ENTER_STMT_CS(stmt
);
1123 SC_clear_error(stmt
);
1124 StartRollbackState(stmt
);
1125 if (SC_opencheck(stmt
, func
))
1128 ret
= PGAPI_PrimaryKeys(hstmt
, ctName
, cbCatalogName
,
1129 scName
, cbSchemaName
, tbName
,
1131 if (SQL_SUCCESS
== ret
1132 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
1134 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
1135 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
;
1136 ConnectionClass
*conn
= SC_get_conn(stmt
);
1138 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
1141 make_lstring_ifneeded(conn
, szCatalogName
, cbCatalogName
,
1142 ifallupper
), NULL
!= newCt
)
1144 ctName
= (UCHAR
*)newCt
;
1148 make_lstring_ifneeded(conn
, szSchemaName
, cbSchemaName
,
1149 ifallupper
), NULL
!= newSc
)
1151 scName
= (UCHAR
*)newSc
;
1155 make_lstring_ifneeded(conn
, szTableName
, cbTableName
,
1156 ifallupper
), NULL
!= newTb
)
1158 tbName
= (UCHAR
*)newTb
;
1163 ret
= PGAPI_PrimaryKeys(hstmt
, ctName
, cbCatalogName
,
1164 scName
, cbSchemaName
, tbName
,
1174 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1175 LEAVE_STMT_CS(stmt
);
1180 SQLProcedureColumns(HSTMT hstmt
,
1181 SQLCHAR
* szCatalogName
,
1182 SQLSMALLINT cbCatalogName
,
1183 SQLCHAR
* szSchemaName
,
1184 SQLSMALLINT cbSchemaName
,
1185 SQLCHAR
* szProcName
,
1186 SQLSMALLINT cbProcName
,
1187 SQLCHAR
* szColumnName
, SQLSMALLINT cbColumnName
)
1189 CSTR func
= "SQLProcedureColumns";
1191 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1192 SQLCHAR
*ctName
= szCatalogName
, *scName
= szSchemaName
,
1193 *prName
= szProcName
, *clName
= szColumnName
;
1197 ENTER_STMT_CS(stmt
);
1198 SC_clear_error(stmt
);
1199 StartRollbackState(stmt
);
1200 if (stmt
->options
.metadata_id
)
1201 flag
|= PODBC_NOT_SEARCH_PATTERN
;
1202 if (SC_opencheck(stmt
, func
))
1205 ret
= PGAPI_ProcedureColumns(hstmt
, ctName
, cbCatalogName
,
1206 scName
, cbSchemaName
, prName
,
1207 cbProcName
, clName
, cbColumnName
,
1209 if (SQL_SUCCESS
== ret
1210 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
1212 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
1213 char *newCt
= NULL
, *newSc
= NULL
, *newPr
= NULL
, *newCl
= NULL
;
1214 ConnectionClass
*conn
= SC_get_conn(stmt
);
1216 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
1219 make_lstring_ifneeded(conn
, szCatalogName
, cbCatalogName
,
1220 ifallupper
), NULL
!= newCt
)
1222 ctName
= (UCHAR
*)newCt
;
1226 make_lstring_ifneeded(conn
, szSchemaName
, cbSchemaName
,
1227 ifallupper
), NULL
!= newSc
)
1229 scName
= (UCHAR
*)newSc
;
1233 make_lstring_ifneeded(conn
, szProcName
, cbProcName
,
1234 ifallupper
), NULL
!= newPr
)
1236 prName
= (UCHAR
*)newPr
;
1240 make_lstring_ifneeded(conn
, szColumnName
, cbColumnName
,
1241 ifallupper
), NULL
!= newCl
)
1243 clName
= (UCHAR
*)newCl
;
1248 ret
= PGAPI_ProcedureColumns(hstmt
, ctName
, cbCatalogName
,
1249 scName
, cbSchemaName
, prName
,
1251 cbColumnName
, flag
);
1262 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1263 LEAVE_STMT_CS(stmt
);
1268 SQLProcedures(HSTMT hstmt
,
1269 SQLCHAR
* szCatalogName
,
1270 SQLSMALLINT cbCatalogName
,
1271 SQLCHAR
* szSchemaName
,
1272 SQLSMALLINT cbSchemaName
,
1273 SQLCHAR
* szProcName
, SQLSMALLINT cbProcName
)
1275 CSTR func
= "SQLProcedures";
1277 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1278 SQLCHAR
*ctName
= szCatalogName
, *scName
= szSchemaName
,
1279 *prName
= szProcName
;
1283 ENTER_STMT_CS(stmt
);
1284 SC_clear_error(stmt
);
1285 StartRollbackState(stmt
);
1286 if (stmt
->options
.metadata_id
)
1287 flag
|= PODBC_NOT_SEARCH_PATTERN
;
1288 if (SC_opencheck(stmt
, func
))
1291 ret
= PGAPI_Procedures(hstmt
, ctName
, cbCatalogName
,
1292 scName
, cbSchemaName
, prName
,
1294 if (SQL_SUCCESS
== ret
1295 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
1297 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
1298 char *newCt
= NULL
, *newSc
= NULL
, *newPr
= NULL
;
1299 ConnectionClass
*conn
= SC_get_conn(stmt
);
1301 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
1304 make_lstring_ifneeded(conn
, szCatalogName
, cbCatalogName
,
1305 ifallupper
), NULL
!= newCt
)
1307 ctName
= (UCHAR
*)newCt
;
1311 make_lstring_ifneeded(conn
, szSchemaName
, cbSchemaName
,
1312 ifallupper
), NULL
!= newSc
)
1314 scName
= (UCHAR
*)newSc
;
1318 make_lstring_ifneeded(conn
, szProcName
, cbProcName
,
1319 ifallupper
), NULL
!= newPr
)
1321 prName
= (UCHAR
*)newPr
;
1326 ret
= PGAPI_Procedures(hstmt
, ctName
, cbCatalogName
,
1327 scName
, cbSchemaName
, prName
,
1337 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1338 LEAVE_STMT_CS(stmt
);
1343 SQLSetPos(HSTMT hstmt
,
1344 SQLSETPOSIROW irow
, SQLUSMALLINT fOption
, SQLUSMALLINT fLock
)
1347 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1350 ENTER_STMT_CS(stmt
);
1351 SC_clear_error(stmt
);
1352 StartRollbackState(stmt
);
1353 ret
= PGAPI_SetPos(hstmt
, irow
, fOption
, fLock
);
1354 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1355 LEAVE_STMT_CS(stmt
);
1360 SQLTablePrivileges(HSTMT hstmt
,
1361 SQLCHAR
* szCatalogName
,
1362 SQLSMALLINT cbCatalogName
,
1363 SQLCHAR
* szSchemaName
,
1364 SQLSMALLINT cbSchemaName
,
1365 SQLCHAR
* szTableName
, SQLSMALLINT cbTableName
)
1367 CSTR func
= "SQLTablePrivileges";
1369 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1370 SQLCHAR
*ctName
= szCatalogName
, *scName
= szSchemaName
,
1371 *tbName
= szTableName
;
1375 ENTER_STMT_CS(stmt
);
1376 SC_clear_error(stmt
);
1377 StartRollbackState(stmt
);
1378 if (stmt
->options
.metadata_id
)
1379 flag
|= PODBC_NOT_SEARCH_PATTERN
;
1380 if (SC_opencheck(stmt
, func
))
1383 ret
= PGAPI_TablePrivileges(hstmt
, ctName
, cbCatalogName
,
1384 scName
, cbSchemaName
, tbName
,
1386 if (SQL_SUCCESS
== ret
1387 && 0 == QR_get_num_total_tuples(SC_get_Result(stmt
)))
1389 BOOL ifallupper
= TRUE
, reexec
= FALSE
;
1390 char *newCt
= NULL
, *newSc
= NULL
, *newTb
= NULL
;
1391 ConnectionClass
*conn
= SC_get_conn(stmt
);
1393 if (SC_is_lower_case(stmt
, conn
)) /* case-insensitive identifier */
1396 make_lstring_ifneeded(conn
, szCatalogName
, cbCatalogName
,
1397 ifallupper
), NULL
!= newCt
)
1399 ctName
= (UCHAR
*)newCt
;
1403 make_lstring_ifneeded(conn
, szSchemaName
, cbSchemaName
,
1404 ifallupper
), NULL
!= newSc
)
1406 scName
= (UCHAR
*)newSc
;
1410 make_lstring_ifneeded(conn
, szTableName
, cbTableName
,
1411 ifallupper
), NULL
!= newTb
)
1413 tbName
= (UCHAR
*)newTb
;
1418 ret
= PGAPI_TablePrivileges(hstmt
, ctName
, cbCatalogName
,
1419 scName
, cbSchemaName
, tbName
,
1429 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1430 LEAVE_STMT_CS(stmt
);
1435 SQLBindParameter(HSTMT hstmt
,
1437 SQLSMALLINT fParamType
,
1439 SQLSMALLINT fSqlType
,
1441 SQLSMALLINT ibScale
,
1442 PTR rgbValue
, SQLLEN cbValueMax
, SQLLEN
* pcbValue
)
1445 StatementClass
*stmt
= (StatementClass
*) hstmt
;
1448 ENTER_STMT_CS(stmt
);
1449 SC_clear_error(stmt
);
1450 StartRollbackState(stmt
);
1451 ret
= PGAPI_BindParameter(hstmt
, ipar
, fParamType
, fCType
,
1452 fSqlType
, cbColDef
, ibScale
, rgbValue
,
1453 cbValueMax
, pcbValue
);
1454 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
1455 LEAVE_STMT_CS(stmt
);