6 * Connect (load) driver
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.
41 extern char* _iodbcdm_getkeyvalbydsn();
42 extern char* _iodbcdm_getkeyvalinstr();
43 extern RETCODE
_iodbcdm_driverunload();
46 * Following id string is a copyright mark. Removing(i.e. use
47 * souce code of this package without it or make it not appear
48 * in the final object file) or modifing it without permission
49 * from original author(kejin@empress.com) are copyright
53 = "@(#)iODBC driver manager 2.5, Copyright(c) 1995 by Ke Jin";
55 /* - Load driver share library( or increase its reference count
56 * if it has already been loaded by another active connection)
57 * - Call driver's SQLAllocEnv() (for the first reference only)
58 * - Call driver's SQLAllocConnect()
59 * - Call driver's SQLSetConnectOption() (set login time out)
60 * - Increase the bookkeeping reference count
67 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
69 ENV_t FAR
*penv
= NULL
;
72 RETCODE retcode
= SQL_SUCCESS
;
73 int sqlstat
= en_00000
;
75 if (path
== NULL
|| path
[0] == '\0')
77 PUSHSQLERR (pdbc
->herr
, en_IM002
);
82 if (hdbc
== SQL_NULL_HDBC
|| pdbc
->genv
== SQL_NULL_HENV
)
84 return SQL_INVALID_HANDLE
;
87 genv
= (GENV_t FAR
*) pdbc
->genv
;
89 /* This will either load the driver dll or increase its reference count */
90 hdll
= _iodbcdm_dllopen ((char FAR
*) path
);
92 if (hdll
== SQL_NULL_HDLL
)
94 PUSHSYSERR (pdbc
->herr
, _iodbcdm_dllerror ());
95 PUSHSQLERR (pdbc
->herr
, en_IM003
);
99 penv
= (ENV_t FAR
*) (pdbc
->henv
);
103 if (penv
->hdll
!= hdll
)
105 _iodbcdm_driverunload (hdbc
);
110 * this will not unload the driver but only decrease its internal
113 _iodbcdm_dllclose (hdll
);
120 * find out whether this dll has already been loaded on another
123 for (penv
= (ENV_t FAR
*) genv
->henv
;
125 penv
= (ENV_t FAR
*) penv
->next
)
127 if (penv
->hdll
== hdll
)
130 * this will not unload the driver but only decrease its internal
133 _iodbcdm_dllclose (hdll
);
139 /* no connection attaching with this dll */
143 /* create a new dll env instance */
144 penv
= (ENV_t FAR
*) MEM_ALLOC (sizeof (ENV_t
));
148 _iodbcdm_dllclose (hdll
);
150 PUSHSQLERR (pdbc
->herr
, en_S1001
);
155 for (i
= 0; i
< SQL_EXT_API_LAST
+ 1; i
++)
157 (penv
->dllproc_tab
)[i
] = SQL_NULL_HPROC
;
163 /* call driver's SQLAllocHandle() or SQLAllocEnv() */
165 #if (ODBCVER >= 0x0300)
166 hproc
= _iodbcdm_getproc (hdbc
, en_AllocHandle
);
170 CALL_DRIVER (hdbc
, retcode
, hproc
, en_AllocHandle
,
171 (SQL_HANDLE_ENV
, SQL_NULL_HANDLE
, &(penv
->dhenv
)))
173 else /* try driver's SQLAllocEnv() */
176 hproc
= _iodbcdm_getproc (hdbc
, en_AllocEnv
);
178 if (hproc
== SQL_NULL_HPROC
)
184 CALL_DRIVER (hdbc
, retcode
, hproc
,
185 en_AllocEnv
, (&(penv
->dhenv
)))
189 if (retcode
== SQL_ERROR
)
194 if (sqlstat
!= en_00000
)
196 _iodbcdm_dllclose (hdll
);
198 PUSHSQLERR (pdbc
->herr
, en_IM004
);
203 /* insert into dll env list */
204 penv
->next
= (ENV_t FAR
*) genv
->henv
;
207 /* initiate this new env entry */
208 penv
->refcount
= 0; /* we will increase it after
209 * driver's SQLAllocConnect()
216 if (pdbc
->dhdbc
== SQL_NULL_HDBC
)
219 #if (ODBCVER >= 0x0300)
220 hproc
= _iodbcdm_getproc (hdbc
, en_AllocHandle
);
224 CALL_DRIVER (hdbc
, retcode
, hproc
, en_AllocHandle
,
225 (SQL_HANDLE_DBC
, penv
->dhenv
, &(pdbc
->dhdbc
)))
231 hproc
= _iodbcdm_getproc (hdbc
, en_AllocConnect
);
233 if (hproc
== SQL_NULL_HPROC
)
239 CALL_DRIVER (hdbc
, retcode
, hproc
,
240 en_AllocConnect
, (penv
->dhenv
, &(pdbc
->dhdbc
)))
244 if (retcode
== SQL_ERROR
)
249 if (sqlstat
!= en_00000
)
251 _iodbcdm_driverunload (hdbc
);
253 pdbc
->dhdbc
= SQL_NULL_HDBC
;
254 PUSHSQLERR (pdbc
->herr
, en_IM005
);
261 penv
->refcount
++; /* bookkeeping reference count on this driver */
264 /* driver's login timeout option must been set before
265 * its SQLConnect() call */
266 if (pdbc
->login_timeout
!= 0UL)
268 hproc
= _iodbcdm_getproc (hdbc
, en_SetConnectOption
);
270 if (hproc
== SQL_NULL_HPROC
)
276 CALL_DRIVER (hdbc
, retcode
, hproc
,
277 en_SetConnectOption
, (
280 pdbc
->login_timeout
))
282 if (retcode
== SQL_ERROR
)
284 PUSHSQLERR (pdbc
->herr
, en_IM006
);
286 return SQL_SUCCESS_WITH_INFO
;
295 /* - Call driver's SQLFreeConnect()
296 * - Call driver's SQLFreeEnv() ( for the last reference only)
297 * - Unload the share library( or decrease its reference
298 * count if it is not the last referenct )
299 * - decrease bookkeeping reference count
300 * - state transition to allocated
303 _iodbcdm_driverunload (HDBC hdbc
)
305 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
310 RETCODE retcode
= SQL_SUCCESS
;
311 int sqlstat
= en_00000
;
313 if (hdbc
== SQL_NULL_HDBC
)
315 return SQL_INVALID_HANDLE
;
318 /* no pointer check will be performed in this function */
319 penv
= (ENV_t FAR
*) pdbc
->henv
;
320 genv
= (GENV_t FAR
*) pdbc
->genv
;
322 if (penv
== NULL
|| penv
->hdll
== SQL_NULL_HDLL
)
327 #if (ODBCVER >= 0x0300)
328 hproc
= _iodbcdm_getproc (hdbc
, en_FreeHandle
);
332 CALL_DRIVER (hdbc
, retcode
, hproc
, en_FreeHandle
,
333 (SQL_HANDLE_DBC
, pdbc
->dhdbc
))
339 hproc
= _iodbcdm_getproc (hdbc
, en_FreeConnect
);
341 if (hproc
!= SQL_NULL_HPROC
)
343 CALL_DRIVER (hdbc
, retcode
, hproc
,
344 en_FreeConnect
, (pdbc
->dhdbc
))
346 pdbc
->dhdbc
= SQL_NULL_HDBC
;
353 /* no other connections still attaching with this driver */
356 #if (ODBCVER >= 0x0300)
357 hproc
= _iodbcdm_getproc (hdbc
, en_FreeHandle
);
361 CALL_DRIVER (hdbc
, retcode
, hproc
, en_FreeHandle
,
362 (SQL_HANDLE_ENV
, penv
->dhenv
))
368 hproc
= _iodbcdm_getproc (hdbc
, en_FreeEnv
);
370 if (hproc
!= SQL_NULL_HPROC
)
372 CALL_DRIVER (hdbc
, retcode
, hproc
, en_FreeEnv
,
375 penv
->dhenv
= SQL_NULL_HENV
;
379 _iodbcdm_dllclose (penv
->hdll
);
381 penv
->hdll
= SQL_NULL_HDLL
;
383 for (tpenv
= (ENV_t FAR
*) genv
->henv
;
385 tpenv
= (ENV_t FAR
*) penv
->next
)
389 genv
->henv
= penv
->next
;
393 if (tpenv
->next
== penv
)
395 tpenv
->next
= penv
->next
;
403 pdbc
->henv
= SQL_NULL_HENV
;
404 pdbc
->hstmt
= SQL_NULL_HSTMT
;
405 /* pdbc->herr = SQL_NULL_HERR;
406 -- delay to DM's SQLFreeConnect() */
407 pdbc
->dhdbc
= SQL_NULL_HDBC
;
408 pdbc
->state
= en_dbc_allocated
;
410 /* set connect options to default values */
412 pdbc->access_mode = SQL_MODE_DEFAULT;
413 pdbc->autocommit = SQL_AUTOCOMMIT_DEFAULT;
414 pdbc->login_timeout = 0UL;
416 pdbc
->odbc_cursors
= SQL_CUR_DEFAULT
;
417 pdbc
->packet_size
= 0UL;
418 pdbc
->quiet_mode
= (UDWORD
) NULL
;
419 pdbc
->txn_isolation
= SQL_TXN_READ_UNCOMMITTED
;
421 if (pdbc
->current_qualifier
!= NULL
)
423 MEM_FREE (pdbc
->current_qualifier
);
424 pdbc
->current_qualifier
= NULL
;
432 _iodbcdm_dbcdelayset (HDBC hdbc
)
434 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
437 RETCODE retcode
= SQL_SUCCESS
;
442 hproc
= _iodbcdm_getproc (hdbc
, en_SetConnectOption
);
444 if (hproc
== SQL_NULL_HPROC
)
446 PUSHSQLERR (pdbc
->herr
, en_IM006
);
448 return SQL_SUCCESS_WITH_INFO
;
451 if (pdbc
->access_mode
!= SQL_MODE_DEFAULT
)
453 CALL_DRIVER (hdbc
, ret
, hproc
,
454 en_SetConnectOption
, (
461 if (pdbc
->autocommit
!= SQL_AUTOCOMMIT_DEFAULT
)
463 CALL_DRIVER (hdbc
, ret
, hproc
,
464 en_SetConnectOption
, (
472 if (pdbc
->current_qualifier
!= NULL
)
474 CALL_DRIVER (hdbc
, ret
, hproc
,
475 en_SetConnectOption
, (
477 SQL_CURRENT_QUALIFIER
,
478 pdbc
->current_qualifier
))
483 if (pdbc
->packet_size
!= 0UL)
485 CALL_DRIVER (hdbc
, ret
, hproc
,
486 en_SetConnectOption
, (
494 if (pdbc
->quiet_mode
!= (UDWORD
) NULL
)
496 CALL_DRIVER (hdbc
, ret
, hproc
,
497 en_SetConnectOption
, (
505 if (pdbc
->txn_isolation
!= SQL_TXN_READ_UNCOMMITTED
)
507 CALL_DRIVER (hdbc
, ret
, hproc
,
508 en_SetConnectOption
, (
511 pdbc
->txn_isolation
))
514 /* check error code for driver's SQLSetConnectOption() call */
515 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
517 PUSHSQLERR (pdbc
->herr
, en_IM006
);
522 /* get cursor behavior on transaction commit or rollback */
523 hproc
= _iodbcdm_getproc (hdbc
, en_GetInfo
);
525 if (hproc
== SQL_NULL_HPROC
)
527 PUSHSQLERR (pdbc
->herr
, en_01000
);
532 CALL_DRIVER (hdbc
, ret
, hproc
,
535 SQL_CURSOR_COMMIT_BEHAVIOR
,
536 (PTR
) & (pdbc
->cb_commit
),
537 sizeof (pdbc
->cb_commit
),
542 CALL_DRIVER (hdbc
, ret
, hproc
,
545 SQL_CURSOR_ROLLBACK_BEHAVIOR
,
546 (PTR
) & (pdbc
->cb_rollback
),
547 sizeof (pdbc
->cb_rollback
),
552 if (retcode
!= SQL_SUCCESS
553 && retcode
!= SQL_SUCCESS_WITH_INFO
)
563 _iodbcdm_settracing (HDBC hdbc
, char *dsn
, int dsnlen
)
567 RETCODE setopterr
= SQL_SUCCESS
;
569 /* Get Driver's DLL path from specificed or default dsn section */
570 ptr
= _iodbcdm_getkeyvalbydsn (dsn
, dsnlen
, "TraceFile",
571 (char FAR
*) buf
, sizeof (buf
));
573 if (ptr
== NULL
|| ptr
[0] == '\0')
575 ptr
= (char FAR
*) (SQL_OPT_TRACE_FILE_DEFAULT
);
578 setopterr
|= SQLSetConnectOption (hdbc
, SQL_OPT_TRACEFILE
, (UDWORD
) (ptr
));
580 ptr
= _iodbcdm_getkeyvalbydsn (dsn
, dsnlen
, "Trace",
581 (char FAR
*) buf
, sizeof (buf
));
585 UDWORD opt
= (UDWORD
) (-1L);
587 if (STREQ (ptr
, "ON")
592 opt
= SQL_OPT_TRACE_ON
;
595 if (STREQ (ptr
, "OFF")
596 || STREQ (ptr
, "Off")
597 || STREQ (ptr
, "off")
600 opt
= SQL_OPT_TRACE_OFF
;
603 if (opt
!= (UDWORD
) (-1L))
605 setopterr
|= SQLSetConnectOption (hdbc
,
621 UCHAR FAR
* szAuthStr
,
624 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
625 RETCODE retcode
= SQL_SUCCESS
;
626 RETCODE setopterr
= SQL_SUCCESS
;
627 char driver
[1024] = {'\0'}; /* MS SDK Guide
634 if (hdbc
== SQL_NULL_HDBC
)
636 return SQL_INVALID_HANDLE
;
639 /* check arguments */
640 if ((cbDSN
< 0 && cbDSN
!= SQL_NTS
)
641 || (cbUID
< 0 && cbUID
!= SQL_NTS
)
642 || (cbAuthStr
< 0 && cbAuthStr
!= SQL_NTS
)
643 || (cbDSN
> SQL_MAX_DSN_LENGTH
))
645 PUSHSQLERR (pdbc
->herr
, en_S1090
);
650 if (szDSN
== NULL
|| cbDSN
== 0)
652 PUSHSQLERR (pdbc
->herr
, en_IM002
);
658 if (pdbc
->state
!= en_dbc_allocated
)
660 PUSHSQLERR (pdbc
->herr
, en_08002
);
665 setopterr
|= _iodbcdm_settracing (hdbc
,
666 (char *) szDSN
, cbDSN
);
668 ptr
= _iodbcdm_getkeyvalbydsn (szDSN
, cbDSN
, "Driver",
669 (char FAR
*) driver
, sizeof (driver
));
672 /* No specified or default dsn section or
673 * no driver specification in this dsn section */
675 PUSHSQLERR (pdbc
->herr
, en_IM002
);
680 retcode
= _iodbcdm_driverload (driver
, hdbc
);
687 case SQL_SUCCESS_WITH_INFO
:
688 setopterr
= SQL_ERROR
;
689 /* unsuccessed in calling driver's
690 * SQLSetConnectOption() to set login
699 hproc
= _iodbcdm_getproc (hdbc
, en_Connect
);
701 if (hproc
== SQL_NULL_HPROC
)
703 _iodbcdm_driverunload (hdbc
);
705 PUSHSQLERR (pdbc
->herr
, en_IM001
);
710 CALL_DRIVER (hdbc
, retcode
, hproc
, en_Connect
, (
714 szAuthStr
, cbAuthStr
))
716 if (retcode
!= SQL_SUCCESS
717 && retcode
!= SQL_SUCCESS_WITH_INFO
)
719 /* not unload driver for retrive error
720 * messge from driver */
722 _iodbcdm_driverunload( hdbc );
728 /* state transition */
729 pdbc
->state
= en_dbc_connected
;
731 /* do delaid option setting */
732 setopterr
|= _iodbcdm_dbcdelayset (hdbc
);
734 if (setopterr
!= SQL_SUCCESS
)
736 return SQL_SUCCESS_WITH_INFO
;
747 UCHAR FAR
* szConnStrIn
,
749 UCHAR FAR
* szConnStrOut
,
750 SWORD cbConnStrOutMax
,
751 SWORD FAR
* pcbConnStrOut
,
752 UWORD fDriverCompletion
)
754 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
759 char dsnbuf
[SQL_MAX_DSN_LENGTH
+ 1];
760 UCHAR cnstr2drv
[1024];
765 int sqlstat
= en_00000
;
766 RETCODE retcode
= SQL_SUCCESS
;
767 RETCODE setopterr
= SQL_SUCCESS
;
769 if (hdbc
== SQL_NULL_HDBC
)
771 return SQL_INVALID_HANDLE
;
774 /* check arguments */
775 if ((cbConnStrIn
< 0 && cbConnStrIn
!= SQL_NTS
)
776 || cbConnStrOutMax
< 0)
778 PUSHSQLERR (pdbc
->herr
, en_S1090
);
784 if (pdbc
->state
!= en_dbc_allocated
)
786 PUSHSQLERR (pdbc
->herr
, en_08002
);
791 drv
= _iodbcdm_getkeyvalinstr (szConnStrIn
, cbConnStrIn
,
792 "DRIVER", drvbuf
, sizeof (drvbuf
));
794 dsn
= _iodbcdm_getkeyvalinstr (szConnStrIn
, cbConnStrIn
,
795 "DSN", dsnbuf
, sizeof (dsnbuf
));
797 switch (fDriverCompletion
)
799 case SQL_DRIVER_NOPROMPT
:
802 case SQL_DRIVER_COMPLETE
:
803 case SQL_DRIVER_COMPLETE_REQUIRED
:
804 if (dsn
!= NULL
|| drv
!= NULL
)
808 /* fall to next case */
809 case SQL_DRIVER_PROMPT
:
810 /* Get data source dialog box function from
811 * current executable */
812 hdll
= _iodbcdm_dllopen ((char FAR
*) NULL
);
813 dialproc
= _iodbcdm_dllproc (hdll
,
814 "_iodbcdm_drvconn_dialbox");
816 if (dialproc
== SQL_NULL_HPROC
)
823 hwnd
, /* window or display handle */
824 dsnbuf
, /* input/output dsn buf */
825 sizeof (dsnbuf
), /* buf size */
826 &sqlstat
); /* error code */
828 if (retcode
!= SQL_SUCCESS
)
833 if (cbConnStrIn
== SQL_NTS
)
835 cbConnStrIn
= STRLEN (szConnStrIn
);
845 if (cbConnStrIn
> sizeof (cnstr2drv
)
846 - STRLEN (dsn
) - STRLEN ("DSN=;") - 1)
848 sqlstat
= en_S1001
; /* a lazy way to avoid
849 * using heap memory */
853 sprintf (cnstr2drv
, "DSN=%s;", dsn
);
854 cbConnStrIn
+= STRLEN (cnstr2drv
);
855 STRNCAT (cnstr2drv
, szConnStrIn
, cbConnStrIn
);
856 szConnStrIn
= cnstr2drv
;
864 if (sqlstat
!= en_00000
)
866 PUSHSQLERR (pdbc
->herr
, sqlstat
);
871 if (dsn
== NULL
|| dsn
[0] == '\0')
876 /* if you want tracing, you must use a DSN */
878 setopterr
|= _iodbcdm_settracing (hdbc
,
879 (char *) dsn
, SQL_NTS
);
882 if (drv
== NULL
|| drv
[0] == '\0')
884 drv
= _iodbcdm_getkeyvalbydsn (dsn
, SQL_NTS
, "Driver",
885 drvbuf
, sizeof (drvbuf
));
890 PUSHSQLERR (pdbc
->herr
, en_IM002
);
895 retcode
= _iodbcdm_driverload (drv
, hdbc
);
902 case SQL_SUCCESS_WITH_INFO
:
903 setopterr
= SQL_ERROR
;
904 /* unsuccessed in calling driver's
905 * SQLSetConnectOption() to set login
914 hproc
= _iodbcdm_getproc (hdbc
, en_DriverConnect
);
916 if (hproc
== SQL_NULL_HPROC
)
918 _iodbcdm_driverunload (hdbc
);
920 PUSHSQLERR (pdbc
->herr
, en_IM001
);
925 CALL_DRIVER (hdbc
, retcode
, hproc
, en_DriverConnect
, (
927 szConnStrIn
, cbConnStrIn
,
928 szConnStrOut
, cbConnStrOutMax
,
929 pcbConnStrOut
, fDriverCompletion
))
931 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
933 /* don't unload driver here for retrive
934 * error message from driver */
936 _iodbcdm_driverunload( hdbc );
942 /* state transition */
943 pdbc
->state
= en_dbc_connected
;
945 /* do delaid option setting */
946 setopterr
|= _iodbcdm_dbcdelayset (hdbc
);
948 if (setopterr
!= SQL_SUCCESS
)
950 return SQL_SUCCESS_WITH_INFO
;
960 UCHAR FAR
* szConnStrIn
,
962 UCHAR FAR
* szConnStrOut
,
963 SWORD cbConnStrOutMax
,
964 SWORD FAR
* pcbConnStrOut
)
966 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
971 char dsnbuf
[SQL_MAX_DSN_LENGTH
+ 1];
972 UCHAR cnstr2drv
[1024];
977 int sqlstat
= en_00000
;
978 RETCODE retcode
= SQL_SUCCESS
;
979 RETCODE setopterr
= SQL_SUCCESS
;
981 if (hdbc
== SQL_NULL_HDBC
)
983 return SQL_INVALID_HANDLE
;
986 /* check arguments */
987 if ((cbConnStrIn
< 0 && cbConnStrIn
!= SQL_NTS
) || cbConnStrOutMax
< 0)
989 PUSHSQLERR (pdbc
->herr
, en_S1090
);
994 if (pdbc
->state
== en_dbc_allocated
)
996 drv
= _iodbcdm_getkeyvalinstr (szConnStrIn
, cbConnStrIn
,
997 "DRIVER", drvbuf
, sizeof (drvbuf
));
999 dsn
= _iodbcdm_getkeyvalinstr (szConnStrIn
, cbConnStrIn
,
1000 "DSN", dsnbuf
, sizeof (dsnbuf
));
1002 if (dsn
== NULL
|| dsn
[0] == '\0')
1007 /* if you want tracing, you must use a DSN */
1009 setopterr
|= _iodbcdm_settracing (hdbc
,
1010 (char *) dsn
, SQL_NTS
);
1013 if (drv
== NULL
|| drv
[0] == '\0')
1015 drv
= _iodbcdm_getkeyvalbydsn (dsn
, SQL_NTS
, "Driver",
1016 drvbuf
, sizeof (drvbuf
));
1021 PUSHSQLERR (pdbc
->herr
, en_IM002
);
1026 retcode
= _iodbcdm_driverload (drv
, hdbc
);
1033 case SQL_SUCCESS_WITH_INFO
:
1034 setopterr
= SQL_ERROR
;
1035 /* unsuccessed in calling driver's
1036 * SQLSetConnectOption() to set login
1045 else if (pdbc
->state
!= en_dbc_needdata
)
1047 PUSHSQLERR (pdbc
->herr
, en_08002
);
1052 hproc
= _iodbcdm_getproc (hdbc
, en_BrowseConnect
);
1054 if (hproc
== SQL_NULL_HPROC
)
1056 _iodbcdm_driverunload (hdbc
);
1058 pdbc
->state
= en_dbc_allocated
;
1060 PUSHSQLERR (pdbc
->herr
, en_IM001
);
1065 CALL_DRIVER (hdbc
, retcode
, hproc
, en_BrowseConnect
, (
1067 szConnStrIn
, cbConnStrIn
,
1068 szConnStrOut
, cbConnStrOutMax
,
1074 case SQL_SUCCESS_WITH_INFO
:
1075 pdbc
->state
= en_dbc_connected
;
1076 setopterr
|= _iodbcdm_dbcdelayset (hdbc
);
1077 if (setopterr
!= SQL_SUCCESS
)
1079 retcode
= SQL_SUCCESS_WITH_INFO
;
1084 pdbc
->state
= en_dbc_needdata
;
1088 pdbc
->state
= en_dbc_allocated
;
1089 /* but the driver will not unloaded
1090 * to allow application retrive err
1091 * message from driver
1104 SQLDisconnect (HDBC hdbc
)
1106 DBC_t FAR
*pdbc
= (DBC_t
*) hdbc
;
1111 int sqlstat
= en_00000
;
1113 if (hdbc
== SQL_NULL_HDBC
)
1115 return SQL_INVALID_HANDLE
;
1118 /* check hdbc state */
1119 if (pdbc
->state
== en_dbc_allocated
)
1124 /* check stmt(s) state */
1125 for (pstmt
= (STMT_t FAR
*) pdbc
->hstmt
;
1126 pstmt
!= NULL
&& sqlstat
== en_00000
;
1127 pstmt
= (STMT_t FAR
*) pstmt
->next
)
1129 if (pstmt
->state
>= en_stmt_needdata
1130 || pstmt
->asyn_on
!= en_NullProc
)
1131 /* In this case one need to call
1132 * SQLCancel() first */
1138 if (sqlstat
== en_00000
)
1140 hproc
= _iodbcdm_getproc (hdbc
, en_Disconnect
);
1142 if (hproc
== SQL_NULL_HPROC
)
1148 if (sqlstat
!= en_00000
)
1150 PUSHSQLERR (pdbc
->herr
, sqlstat
);
1155 CALL_DRIVER (hdbc
, retcode
, hproc
, en_Disconnect
, (
1158 if (retcode
== SQL_SUCCESS
|| retcode
== SQL_SUCCESS_WITH_INFO
)
1160 /* diff from MS specs. We disallow
1161 * driver SQLDisconnect() return
1162 * SQL_SUCCESS_WITH_INFO and post
1165 retcode
= SQL_SUCCESS
;
1172 /* free all statement handle(s) on this connection */
1173 for (; pdbc
->hstmt
;)
1175 _iodbcdm_dropstmt (pdbc
->hstmt
);
1178 /* state transition */
1179 if (retcode
== SQL_SUCCESS
)
1181 pdbc
->state
= en_dbc_allocated
;
1191 UCHAR FAR
* szSqlStrIn
,
1193 UCHAR FAR
* szSqlStr
,
1195 SDWORD FAR
* pcbSqlStr
)
1197 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
1199 int sqlstat
= en_00000
;
1202 if (hdbc
== SQL_NULL_HDBC
)
1204 return SQL_INVALID_HANDLE
;
1207 /* check argument */
1208 if (szSqlStrIn
== NULL
)
1212 else if (cbSqlStrIn
< 0 && cbSqlStrIn
!= SQL_NTS
)
1217 if (sqlstat
!= en_00000
)
1219 PUSHSQLERR (pdbc
->herr
, sqlstat
);
1225 if (pdbc
->state
<= en_dbc_needdata
)
1227 PUSHSQLERR (pdbc
->herr
, en_08003
);
1233 hproc
= _iodbcdm_getproc (hdbc
, en_NativeSql
);
1235 if (hproc
== SQL_NULL_HPROC
)
1237 PUSHSQLERR (pdbc
->herr
, en_IM001
);
1242 CALL_DRIVER (hdbc
, retcode
, hproc
, en_NativeSql
,
1243 (pdbc
->dhdbc
, szSqlStrIn
, cbSqlStrIn
, szSqlStr
, cbSqlStrMax
, pcbSqlStr
))