]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/catalog.c
1 /** Catalog functions of iODBC driver manager
3 Copyright (C) 1995 by Ke Jin <kejin@empress.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 #include <../iodbc/iodbc.h>
18 #include <../iodbc/isql.h>
19 #include <../iodbc/isqlext.h>
21 #include <../iodbc/dlproc.h>
23 #include <../iodbc/herr.h>
24 #include <../iodbc/henv.h>
25 #include <../iodbc/hdbc.h>
26 #include <../iodbc/hstmt.h>
28 #include <../iodbc/itrace.h>
30 static RETCODE
_iodbcdm_cata_state_ok (
33 /* check state for executing catalog functions */
35 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
36 int sqlstat
= en_00000
;
38 if( pstmt
->asyn_on
== en_NullProc
)
40 switch( pstmt
->state
)
42 case en_stmt_needdata
:
49 case en_stmt_xfetched
:
57 else if( pstmt
->asyn_on
!= fidx
)
62 if( sqlstat
!= en_00000
)
64 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
72 static RETCODE
_iodbcdm_cata_state_tr(
76 /* state transition for catalog function */
78 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
81 pdbc
= (DBC_t FAR
*)(pstmt
->hdbc
);
83 if( pstmt
->asyn_on
== fidx
)
88 case SQL_SUCCESS_WITH_INFO
:
90 pstmt
->asyn_on
= en_NullProc
;
93 case SQL_STILL_EXECUTING
:
99 if( pstmt
->state
<= en_stmt_executed
)
104 case SQL_SUCCESS_WITH_INFO
:
105 pstmt
->state
= en_stmt_cursoropen
;
109 pstmt
->state
= en_stmt_allocated
;
110 pstmt
->prep_state
= 0;
113 case SQL_STILL_EXECUTING
:
114 pstmt
->asyn_on
= fidx
;
125 RETCODE SQL_API
SQLGetTypeInfo(
129 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
131 int sqlstat
= en_00000
;
134 if( hstmt
== SQL_NULL_HSTMT
135 || pstmt
->hdbc
== SQL_NULL_HDBC
)
137 return SQL_INVALID_HANDLE
;
142 if( fSqlType
> SQL_TYPE_MAX
)
148 if( fSqlType
< SQL_TYPE_MIN
149 && fSqlType
> SQL_TYPE_DRIVER_START
)
150 /* Note: SQL_TYPE_DRIVER_START is a nagtive
151 * number So, we use ">" */
157 retcode
= _iodbcdm_cata_state_ok( hstmt
, en_GetTypeInfo
);
159 if( retcode
!= SQL_SUCCESS
)
164 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_GetTypeInfo
);
166 if( hproc
== SQL_NULL_HPROC
)
173 if( 1 ) /* turn off solaris warning message */
177 if( sqlstat
!= en_00000
)
179 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
184 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
,
185 en_GetTypeInfo
, ( pstmt
->dhstmt
, fSqlType
) )
188 retcode
= hproc ( pstmt
->dhstmt
, fSqlType
);
191 return _iodbcdm_cata_state_tr( hstmt
, en_GetTypeInfo
, retcode
);
194 RETCODE SQL_API
SQLSpecialColumns(
197 UCHAR FAR
* szTableQualifier
,
198 SWORD cbTableQualifier
,
199 UCHAR FAR
* szTableOwner
,
201 UCHAR FAR
* szTableName
,
206 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
209 int sqlstat
= en_00000
;
211 if( hstmt
== SQL_NULL_HSTMT
212 || pstmt
->hdbc
== SQL_NULL_HDBC
)
214 return SQL_INVALID_HANDLE
;
219 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
220 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
221 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
) )
227 if( fColType
!= SQL_BEST_ROWID
228 && fColType
!= SQL_ROWVER
)
234 if( fScope
!= SQL_SCOPE_CURROW
235 && fScope
!= SQL_SCOPE_TRANSACTION
236 && fScope
!= SQL_SCOPE_SESSION
)
242 if( fNullable
!= SQL_NO_NULLS
243 && fNullable
!= SQL_NULLABLE
)
249 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_SpecialColumns
);
251 if( retcode
!= SQL_SUCCESS
)
256 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SpecialColumns
);
258 if( hproc
== SQL_NULL_HPROC
)
265 if( 1 ) /* turn off solaris warning message */
269 if( sqlstat
!= en_00000
)
271 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
276 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SpecialColumns
, (
289 retcode
= hproc(pstmt
->dhstmt
,
301 return _iodbcdm_cata_state_tr( hstmt
, en_SpecialColumns
, retcode
);
304 RETCODE SQL_API
SQLStatistics(
306 UCHAR FAR
* szTableQualifier
,
307 SWORD cbTableQualifier
,
308 UCHAR FAR
* szTableOwner
,
310 UCHAR FAR
* szTableName
,
315 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
318 int sqlstat
= en_00000
;
320 if( hstmt
== SQL_NULL_HSTMT
321 || 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
337 && fUnique
!= SQL_INDEX_ALL
)
343 if( fAccuracy
!= SQL_ENSURE
344 && fAccuracy
!= SQL_QUICK
)
350 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_Statistics
);
352 if( retcode
!= SQL_SUCCESS
)
357 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Statistics
);
359 if( hproc
== SQL_NULL_HPROC
)
367 if( 1 ) /* turn off solaris warning message */
371 if( sqlstat
!= en_00000
)
373 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
378 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Statistics
, (
390 retcode
= hproc(pstmt
->dhstmt
,
401 return _iodbcdm_cata_state_tr( hstmt
, en_Statistics
, retcode
);
404 RETCODE SQL_API
SQLTables(
406 UCHAR FAR
* szTableQualifier
,
407 SWORD cbTableQualifier
,
408 UCHAR FAR
* szTableOwner
,
410 UCHAR FAR
* szTableName
,
412 UCHAR FAR
* szTableType
,
415 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
418 int sqlstat
= en_00000
;
420 if( hstmt
== SQL_NULL_HSTMT
421 || pstmt
->hdbc
== SQL_NULL_HDBC
)
423 return SQL_INVALID_HANDLE
;
428 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
429 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
430 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
)
431 || ( cbTableType
< 0 && cbTableType
!= SQL_NTS
) )
437 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_Tables
);
439 if( retcode
!= SQL_SUCCESS
)
444 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Tables
);
446 if( hproc
== SQL_NULL_HPROC
)
454 if( 1 ) /* turn off solaris warning message */
458 if( sqlstat
!= en_00000
)
460 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
465 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Tables
, (
477 retcode
= hproc(pstmt
->dhstmt
,
488 return _iodbcdm_cata_state_tr( hstmt
, en_Tables
, retcode
);
491 RETCODE SQL_API
SQLColumnPrivileges(
493 UCHAR FAR
* szTableQualifier
,
494 SWORD cbTableQualifier
,
495 UCHAR FAR
* szTableOwner
,
497 UCHAR FAR
* szTableName
,
499 UCHAR FAR
* szColumnName
,
502 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
505 int sqlstat
= en_00000
;
507 if( hstmt
== SQL_NULL_HSTMT
508 || pstmt
->hdbc
== SQL_NULL_HDBC
)
510 return SQL_INVALID_HANDLE
;
515 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
516 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
517 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
)
518 || ( cbColumnName
< 0 && cbColumnName
!= SQL_NTS
) )
524 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_ColumnPrivileges
);
526 if( retcode
!= SQL_SUCCESS
)
531 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ColumnPrivileges
);
533 if( hproc
== SQL_NULL_HPROC
)
541 if( 1 ) /* turn off solaris warning message */
545 if( sqlstat
!= en_00000
)
547 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
552 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ColumnPrivileges
, (
564 retcode
= hproc(pstmt
->dhstmt
,
575 return _iodbcdm_cata_state_tr( hstmt
, en_ColumnPrivileges
, retcode
);
578 RETCODE SQL_API
SQLColumns(
580 UCHAR FAR
* szTableQualifier
,
581 SWORD cbTableQualifier
,
582 UCHAR FAR
* szTableOwner
,
584 UCHAR FAR
* szTableName
,
586 UCHAR FAR
* szColumnName
,
589 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
592 int sqlstat
= en_00000
;
594 if( hstmt
== SQL_NULL_HSTMT
595 || pstmt
->hdbc
== SQL_NULL_HDBC
)
597 return SQL_INVALID_HANDLE
;
602 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
603 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
604 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
)
605 || ( cbColumnName
< 0 && cbColumnName
!= SQL_NTS
) )
611 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_Columns
);
613 if( retcode
!= SQL_SUCCESS
)
618 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Columns
);
620 if( hproc
== SQL_NULL_HPROC
)
628 if( 1 ) /* turn off solaris warning message */
632 if( sqlstat
!= en_00000
)
634 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
639 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Columns
, (
651 retcode
= hproc(pstmt
->dhstmt
,
662 return _iodbcdm_cata_state_tr( hstmt
, en_Columns
, retcode
);
665 RETCODE SQL_API
SQLForeignKeys(
667 UCHAR FAR
* szPkTableQualifier
,
668 SWORD cbPkTableQualifier
,
669 UCHAR FAR
* szPkTableOwner
,
670 SWORD cbPkTableOwner
,
671 UCHAR FAR
* szPkTableName
,
673 UCHAR FAR
* szFkTableQualifier
,
674 SWORD cbFkTableQualifier
,
675 UCHAR FAR
* szFkTableOwner
,
676 SWORD cbFkTableOwner
,
677 UCHAR FAR
* szFkTableName
,
678 SWORD cbFkTableName
)
680 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
683 int sqlstat
= en_00000
;
685 if( hstmt
== SQL_NULL_HSTMT
686 || pstmt
->hdbc
== SQL_NULL_HDBC
)
688 return SQL_INVALID_HANDLE
;
693 if( ( cbPkTableQualifier
< 0 && cbPkTableQualifier
!= SQL_NTS
)
694 || ( cbPkTableOwner
< 0 && cbPkTableOwner
!= SQL_NTS
)
695 || ( cbPkTableName
< 0 && cbPkTableName
!= SQL_NTS
)
696 || ( cbFkTableQualifier
< 0 && cbFkTableQualifier
!= SQL_NTS
)
697 || ( cbFkTableOwner
< 0 && cbFkTableOwner
!= SQL_NTS
)
698 || ( cbFkTableName
< 0 && cbFkTableName
!= SQL_NTS
) )
704 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_ForeignKeys
);
706 if( retcode
!= SQL_SUCCESS
)
711 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ForeignKeys
);
713 if( hproc
== SQL_NULL_HPROC
)
721 if( 1 ) /* turn off solaris warning message */
725 if( sqlstat
!= en_00000
)
727 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
732 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ForeignKeys
, (
748 retcode
= hproc(pstmt
->dhstmt
,
763 return _iodbcdm_cata_state_tr( hstmt
, en_ForeignKeys
, retcode
);
766 RETCODE SQL_API
SQLPrimaryKeys(
768 UCHAR FAR
* szTableQualifier
,
769 SWORD cbTableQualifier
,
770 UCHAR FAR
* szTableOwner
,
772 UCHAR FAR
* szTableName
,
775 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
778 int sqlstat
= en_00000
;
780 if( hstmt
== SQL_NULL_HSTMT
781 || pstmt
->hdbc
== SQL_NULL_HDBC
)
783 return SQL_INVALID_HANDLE
;
788 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
789 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
790 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
) )
796 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_PrimaryKeys
);
798 if( retcode
!= SQL_SUCCESS
)
803 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_PrimaryKeys
);
805 if( hproc
== SQL_NULL_HPROC
)
813 if( 1 ) /* turn off solaris warning message */
817 if( sqlstat
!= en_00000
)
819 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
824 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_PrimaryKeys
, (
834 retcode
= hproc(pstmt
->dhstmt
,
843 return _iodbcdm_cata_state_tr( hstmt
, en_PrimaryKeys
, retcode
);
846 RETCODE SQL_API
SQLProcedureColumns(
848 UCHAR FAR
* szProcQualifier
,
849 SWORD cbProcQualifier
,
850 UCHAR FAR
* szProcOwner
,
852 UCHAR FAR
* szProcName
,
854 UCHAR FAR
* szColumnName
,
857 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
860 int sqlstat
= en_00000
;
862 if( hstmt
== SQL_NULL_HSTMT
863 || pstmt
->hdbc
== SQL_NULL_HDBC
)
865 return SQL_INVALID_HANDLE
;
870 if( ( cbProcQualifier
< 0 && cbProcQualifier
!= SQL_NTS
)
871 || ( cbProcOwner
< 0 && cbProcOwner
!= SQL_NTS
)
872 || ( cbProcName
< 0 && cbProcName
!= SQL_NTS
)
873 || ( cbColumnName
< 0 && cbColumnName
!= SQL_NTS
) )
879 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_ProcedureColumns
);
881 if( retcode
!= SQL_SUCCESS
)
886 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ProcedureColumns
);
888 if( hproc
== SQL_NULL_HPROC
)
896 if( 1 ) /* turn off solaris warning message */
900 if( sqlstat
!= en_00000
)
902 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
907 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ProcedureColumns
, (
919 retcode
= hproc(pstmt
->dhstmt
,
930 return _iodbcdm_cata_state_tr( hstmt
, en_ProcedureColumns
, retcode
);
933 RETCODE SQL_API
SQLProcedures(
935 UCHAR FAR
* szProcQualifier
,
936 SWORD cbProcQualifier
,
937 UCHAR FAR
* szProcOwner
,
939 UCHAR FAR
* szProcName
,
942 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
945 int sqlstat
= en_00000
;
947 if( hstmt
== SQL_NULL_HSTMT
948 || pstmt
->hdbc
== SQL_NULL_HDBC
)
950 return SQL_INVALID_HANDLE
;
955 if( ( cbProcQualifier
< 0 && cbProcQualifier
!= SQL_NTS
)
956 || ( cbProcOwner
< 0 && cbProcOwner
!= SQL_NTS
)
957 || ( cbProcName
< 0 && cbProcName
!= SQL_NTS
) )
963 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_Procedures
);
965 if( retcode
!= SQL_SUCCESS
)
970 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Procedures
);
972 if( hproc
== SQL_NULL_HPROC
)
980 if( 1 ) /* turn off solaris warning message */
984 if( sqlstat
!= en_00000
)
986 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
991 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Procedures
, (
1001 retcode
= hproc(pstmt
->dhstmt
,
1010 return _iodbcdm_cata_state_tr( hstmt
, en_Procedures
, retcode
);
1013 RETCODE SQL_API
SQLTablePrivileges(
1015 UCHAR FAR
* szTableQualifier
,
1016 SWORD cbTableQualifier
,
1017 UCHAR FAR
* szTableOwner
,
1019 UCHAR FAR
* szTableName
,
1023 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
1026 int sqlstat
= en_00000
;
1028 if( hstmt
== SQL_NULL_HSTMT
1029 || pstmt
->hdbc
== SQL_NULL_HDBC
)
1031 return SQL_INVALID_HANDLE
;
1036 if( ( cbTableQualifier
< 0 && cbTableQualifier
!= SQL_NTS
)
1037 || ( cbTableOwner
< 0 && cbTableOwner
!= SQL_NTS
)
1038 || ( cbTableName
< 0 && cbTableName
!= SQL_NTS
) )
1044 retcode
= _iodbcdm_cata_state_ok ( hstmt
, en_TablePrivileges
);
1046 if( retcode
!= SQL_SUCCESS
)
1051 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_TablePrivileges
);
1053 if( hproc
== SQL_NULL_HPROC
)
1061 if( 1 ) /* turn off solaris warning message */
1065 if( sqlstat
!= en_00000
)
1067 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
1072 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_TablePrivileges
, (
1082 retcode
= hproc(pstmt
->dhstmt
,
1091 return _iodbcdm_cata_state_tr( hstmt
, en_TablePrivileges
, retcode
);