8 * The iODBC driver manager.
10 * Copyright (C) 1995 by Ke Jin <kejin@empress.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
46 _iodbcdm_cata_state_ok (
49 /* check state for executing catalog functions */
51 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
52 int sqlstat
= en_00000
;
54 if (pstmt
->asyn_on
== en_NullProc
)
58 case en_stmt_needdata
:
65 case en_stmt_xfetched
:
73 else if (pstmt
->asyn_on
!= fidx
)
78 if (sqlstat
!= en_00000
)
80 PUSHSQLERR (pstmt
->herr
, sqlstat
);
90 _iodbcdm_cata_state_tr (
94 /* state transition for catalog function */
96 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
99 pdbc
= (DBC_t FAR
*) (pstmt
->hdbc
);
101 if (pstmt
->asyn_on
== fidx
)
106 case SQL_SUCCESS_WITH_INFO
:
108 pstmt
->asyn_on
= en_NullProc
;
111 case SQL_STILL_EXECUTING
:
117 if (pstmt
->state
<= en_stmt_executed
)
122 case SQL_SUCCESS_WITH_INFO
:
123 pstmt
->state
= en_stmt_cursoropen
;
127 pstmt
->state
= en_stmt_allocated
;
128 pstmt
->prep_state
= 0;
131 case SQL_STILL_EXECUTING
:
132 pstmt
->asyn_on
= fidx
;
149 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
150 HPROC hproc
= SQL_NULL_HPROC
;
151 int sqlstat
= en_00000
;
154 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
156 return SQL_INVALID_HANDLE
;
161 if (fSqlType
> SQL_TYPE_MAX
)
167 /* Note: SQL_TYPE_DRIVER_START is a negative number So, we use ">" */
168 if (fSqlType
< SQL_TYPE_MIN
&& fSqlType
> SQL_TYPE_DRIVER_START
)
174 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_GetTypeInfo
);
176 if (retcode
!= SQL_SUCCESS
)
181 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_GetTypeInfo
);
183 if (hproc
== SQL_NULL_HPROC
)
190 if (1) /* turn off solaris warning message */
194 if (sqlstat
!= en_00000
)
196 PUSHSQLERR (pstmt
->herr
, sqlstat
);
201 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_GetTypeInfo
,
202 (pstmt
->dhstmt
, fSqlType
))
204 return _iodbcdm_cata_state_tr (hstmt
, en_GetTypeInfo
, retcode
);
212 UCHAR FAR
* szTableQualifier
,
213 SWORD cbTableQualifier
,
214 UCHAR FAR
* szTableOwner
,
216 UCHAR FAR
* szTableName
,
221 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
222 HPROC hproc
= SQL_NULL_HPROC
;
224 int sqlstat
= en_00000
;
226 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
228 return SQL_INVALID_HANDLE
;
233 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
234 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
235 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
))
241 if (fColType
!= SQL_BEST_ROWID
&& fColType
!= SQL_ROWVER
)
247 if (fScope
!= SQL_SCOPE_CURROW
248 && fScope
!= SQL_SCOPE_TRANSACTION
249 && fScope
!= SQL_SCOPE_SESSION
)
255 if (fNullable
!= SQL_NO_NULLS
&& fNullable
!= SQL_NULLABLE
)
261 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_SpecialColumns
);
263 if (retcode
!= SQL_SUCCESS
)
268 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_SpecialColumns
);
270 if (hproc
== SQL_NULL_HPROC
)
277 if (1) /* turn off solaris warning message */
281 if (sqlstat
!= en_00000
)
283 PUSHSQLERR (pstmt
->herr
, sqlstat
);
288 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_SpecialColumns
, (
300 return _iodbcdm_cata_state_tr (hstmt
, en_SpecialColumns
, retcode
);
307 UCHAR FAR
* szTableQualifier
,
308 SWORD cbTableQualifier
,
309 UCHAR FAR
* szTableOwner
,
311 UCHAR FAR
* szTableName
,
316 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
317 HPROC hproc
= SQL_NULL_HPROC
;
319 int sqlstat
= en_00000
;
321 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
323 return SQL_INVALID_HANDLE
;
328 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
329 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
330 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
))
336 if (fUnique
!= SQL_INDEX_UNIQUE
&& fUnique
!= SQL_INDEX_ALL
)
342 if (fAccuracy
!= SQL_ENSURE
&& fAccuracy
!= SQL_QUICK
)
348 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_Statistics
);
350 if (retcode
!= SQL_SUCCESS
)
355 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Statistics
);
357 if (hproc
== SQL_NULL_HPROC
)
365 if (1) /* turn off solaris warning message */
369 if (sqlstat
!= en_00000
)
371 PUSHSQLERR (pstmt
->herr
, sqlstat
);
376 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Statistics
, (
387 return _iodbcdm_cata_state_tr (hstmt
, en_Statistics
, retcode
);
394 UCHAR FAR
* szTableQualifier
,
395 SWORD cbTableQualifier
,
396 UCHAR FAR
* szTableOwner
,
398 UCHAR FAR
* szTableName
,
400 UCHAR FAR
* szTableType
,
403 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
404 HPROC hproc
= SQL_NULL_HPROC
;
406 int sqlstat
= en_00000
;
408 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
410 return SQL_INVALID_HANDLE
;
415 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
416 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
417 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
)
418 || (cbTableType
< 0 && cbTableType
!= SQL_NTS
))
424 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_Tables
);
426 if (retcode
!= SQL_SUCCESS
)
431 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Tables
);
433 if (hproc
== SQL_NULL_HPROC
)
441 if (1) /* turn off solaris warning message */
445 if (sqlstat
!= en_00000
)
447 PUSHSQLERR (pstmt
->herr
, sqlstat
);
452 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Tables
, (
463 return _iodbcdm_cata_state_tr (hstmt
, en_Tables
, retcode
);
468 SQLColumnPrivileges (
470 UCHAR FAR
* szTableQualifier
,
471 SWORD cbTableQualifier
,
472 UCHAR FAR
* szTableOwner
,
474 UCHAR FAR
* szTableName
,
476 UCHAR FAR
* szColumnName
,
479 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
480 HPROC hproc
= SQL_NULL_HPROC
;
482 int sqlstat
= en_00000
;
484 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
486 return SQL_INVALID_HANDLE
;
491 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
492 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
493 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
)
494 || (cbColumnName
< 0 && cbColumnName
!= SQL_NTS
))
500 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_ColumnPrivileges
);
502 if (retcode
!= SQL_SUCCESS
)
507 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ColumnPrivileges
);
509 if (hproc
== SQL_NULL_HPROC
)
517 if (1) /* turn off solaris warning message */
521 if (sqlstat
!= en_00000
)
523 PUSHSQLERR (pstmt
->herr
, sqlstat
);
528 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ColumnPrivileges
, (
539 return _iodbcdm_cata_state_tr (hstmt
, en_ColumnPrivileges
, retcode
);
546 UCHAR FAR
* szTableQualifier
,
547 SWORD cbTableQualifier
,
548 UCHAR FAR
* szTableOwner
,
550 UCHAR FAR
* szTableName
,
552 UCHAR FAR
* szColumnName
,
555 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
556 HPROC hproc
= SQL_NULL_HPROC
;
558 int sqlstat
= en_00000
;
560 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
562 return SQL_INVALID_HANDLE
;
567 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
568 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
569 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
)
570 || (cbColumnName
< 0 && cbColumnName
!= SQL_NTS
))
576 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_Columns
);
578 if (retcode
!= SQL_SUCCESS
)
583 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Columns
);
585 if (hproc
== SQL_NULL_HPROC
)
593 if (1) /* turn off solaris warning message */
597 if (sqlstat
!= en_00000
)
599 PUSHSQLERR (pstmt
->herr
, sqlstat
);
604 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Columns
, (
615 return _iodbcdm_cata_state_tr (hstmt
, en_Columns
, retcode
);
622 UCHAR FAR
* szPkTableQualifier
,
623 SWORD cbPkTableQualifier
,
624 UCHAR FAR
* szPkTableOwner
,
625 SWORD cbPkTableOwner
,
626 UCHAR FAR
* szPkTableName
,
628 UCHAR FAR
* szFkTableQualifier
,
629 SWORD cbFkTableQualifier
,
630 UCHAR FAR
* szFkTableOwner
,
631 SWORD cbFkTableOwner
,
632 UCHAR FAR
* szFkTableName
,
635 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
636 HPROC hproc
= SQL_NULL_HPROC
;
638 int sqlstat
= en_00000
;
640 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
642 return SQL_INVALID_HANDLE
;
647 if ((cbPkTableQualifier
< 0 && cbPkTableQualifier
!= SQL_NTS
)
648 || (cbPkTableOwner
< 0 && cbPkTableOwner
!= SQL_NTS
)
649 || (cbPkTableName
< 0 && cbPkTableName
!= SQL_NTS
)
650 || (cbFkTableQualifier
< 0 && cbFkTableQualifier
!= SQL_NTS
)
651 || (cbFkTableOwner
< 0 && cbFkTableOwner
!= SQL_NTS
)
652 || (cbFkTableName
< 0 && cbFkTableName
!= SQL_NTS
))
658 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_ForeignKeys
);
660 if (retcode
!= SQL_SUCCESS
)
665 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ForeignKeys
);
667 if (hproc
== SQL_NULL_HPROC
)
675 if (1) /* turn off solaris warning message */
679 if (sqlstat
!= en_00000
)
681 PUSHSQLERR (pstmt
->herr
, sqlstat
);
686 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ForeignKeys
, (
701 return _iodbcdm_cata_state_tr (hstmt
, en_ForeignKeys
, retcode
);
708 UCHAR FAR
* szTableQualifier
,
709 SWORD cbTableQualifier
,
710 UCHAR FAR
* szTableOwner
,
712 UCHAR FAR
* szTableName
,
715 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
716 HPROC hproc
= SQL_NULL_HPROC
;
718 int sqlstat
= en_00000
;
720 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
722 return SQL_INVALID_HANDLE
;
727 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
728 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
729 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
))
735 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_PrimaryKeys
);
737 if (retcode
!= SQL_SUCCESS
)
742 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_PrimaryKeys
);
744 if (hproc
== SQL_NULL_HPROC
)
752 if (1) /* turn off solaris warning message */
756 if (sqlstat
!= en_00000
)
758 PUSHSQLERR (pstmt
->herr
, sqlstat
);
763 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_PrimaryKeys
, (
772 return _iodbcdm_cata_state_tr (hstmt
, en_PrimaryKeys
, retcode
);
777 SQLProcedureColumns (
779 UCHAR FAR
* szProcQualifier
,
780 SWORD cbProcQualifier
,
781 UCHAR FAR
* szProcOwner
,
783 UCHAR FAR
* szProcName
,
785 UCHAR FAR
* szColumnName
,
788 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
789 HPROC hproc
= SQL_NULL_HPROC
;
791 int sqlstat
= en_00000
;
793 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
795 return SQL_INVALID_HANDLE
;
800 if ((cbProcQualifier
< 0 && cbProcQualifier
!= SQL_NTS
)
801 || (cbProcOwner
< 0 && cbProcOwner
!= SQL_NTS
)
802 || (cbProcName
< 0 && cbProcName
!= SQL_NTS
)
803 || (cbColumnName
< 0 && cbColumnName
!= SQL_NTS
))
809 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_ProcedureColumns
);
811 if (retcode
!= SQL_SUCCESS
)
816 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ProcedureColumns
);
818 if (hproc
== SQL_NULL_HPROC
)
826 if (1) /* turn off solaris warning message */
830 if (sqlstat
!= en_00000
)
832 PUSHSQLERR (pstmt
->herr
, sqlstat
);
837 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ProcedureColumns
, (
848 return _iodbcdm_cata_state_tr (hstmt
, en_ProcedureColumns
, retcode
);
855 UCHAR FAR
* szProcQualifier
,
856 SWORD cbProcQualifier
,
857 UCHAR FAR
* szProcOwner
,
859 UCHAR FAR
* szProcName
,
862 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
863 HPROC hproc
= SQL_NULL_HPROC
;
865 int sqlstat
= en_00000
;
867 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
869 return SQL_INVALID_HANDLE
;
874 if ((cbProcQualifier
< 0 && cbProcQualifier
!= SQL_NTS
)
875 || (cbProcOwner
< 0 && cbProcOwner
!= SQL_NTS
)
876 || (cbProcName
< 0 && cbProcName
!= SQL_NTS
))
882 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_Procedures
);
884 if (retcode
!= SQL_SUCCESS
)
889 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Procedures
);
891 if (hproc
== SQL_NULL_HPROC
)
899 if (1) /* turn off solaris warning message */
903 if (sqlstat
!= en_00000
)
905 PUSHSQLERR (pstmt
->herr
, sqlstat
);
910 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Procedures
, (
919 return _iodbcdm_cata_state_tr (hstmt
, en_Procedures
, retcode
);
926 UCHAR FAR
* szTableQualifier
,
927 SWORD cbTableQualifier
,
928 UCHAR FAR
* szTableOwner
,
930 UCHAR FAR
* szTableName
,
934 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
935 HPROC hproc
= SQL_NULL_HPROC
;
937 int sqlstat
= en_00000
;
939 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
941 return SQL_INVALID_HANDLE
;
946 if ((cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
947 || (cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
948 || (cbTableName
< 0 && cbTableName
!= SQL_NTS
))
954 retcode
= _iodbcdm_cata_state_ok (hstmt
, en_TablePrivileges
);
956 if (retcode
!= SQL_SUCCESS
)
961 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_TablePrivileges
);
963 if (hproc
== SQL_NULL_HPROC
)
971 if (1) /* turn off solaris warning message */
975 if (sqlstat
!= en_00000
)
977 PUSHSQLERR (pstmt
->herr
, sqlstat
);
982 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_TablePrivileges
,
983 (pstmt
->dhstmt
, szTableQualifier
, cbTableQualifier
, szTableOwner
,
984 cbTableOwner
, szTableName
, cbTableName
))
986 return _iodbcdm_cata_state_tr (hstmt
, en_TablePrivileges
, retcode
);