+RETCODE SQL_API
+SQLGetConnectOption (
+ HDBC hdbc,
+ UWORD fOption,
+ PTR pvParam)
+{
+ DBC_t FAR *pdbc = (DBC_t FAR *) hdbc;
+ int sqlstat = en_00000;
+ HPROC hproc = SQL_NULL_HPROC;
+ RETCODE retcode;
+
+ if (hdbc == SQL_NULL_HDBC)
+ {
+ return SQL_INVALID_HANDLE;
+ }
+
+ /* check option */
+ if (fOption < SQL_CONN_OPT_MIN ||
+ (fOption > SQL_CONN_OPT_MAX && fOption < SQL_CONNECT_OPT_DRVR_START))
+ {
+ PUSHSQLERR (pdbc->herr, en_S1092);
+
+ return SQL_ERROR;
+ }
+
+ /* check state */
+ switch (pdbc->state)
+ {
+ case en_dbc_allocated:
+ if (fOption != SQL_ACCESS_MODE
+ && fOption != SQL_AUTOCOMMIT
+ && fOption != SQL_LOGIN_TIMEOUT
+ && fOption != SQL_OPT_TRACE
+ && fOption != SQL_OPT_TRACEFILE)
+ {
+ sqlstat = en_08003;
+ }
+ /* MS ODBC SDK document only
+ * allows SQL_ACCESS_MODE
+ * and SQL_AUTOCOMMIT in this
+ * dbc state. We allow another
+ * two options, because they
+ * are only meaningful for driver
+ * manager.
+ */
+ break;
+
+ case en_dbc_needdata:
+ sqlstat = en_S1010;
+ break;
+
+ default:
+ break;
+ }
+
+ if (sqlstat != en_00000)
+ {
+ PUSHSQLERR (pdbc->herr, sqlstat);
+
+ return SQL_ERROR;
+ }
+
+ /* Tracing and tracing file options are only
+ * meaningful for driver manager
+ */
+ if (fOption == SQL_OPT_TRACE)
+ {
+ if (pdbc->trace)
+ *((UDWORD *) pvParam) = (UDWORD) SQL_OPT_TRACE_ON;
+ else
+ *((UDWORD *) pvParam) = (UDWORD) SQL_OPT_TRACE_OFF;
+
+ return SQL_SUCCESS;
+ }
+
+ if (fOption == SQL_OPT_TRACEFILE)
+ {
+ STRCPY (pvParam, pdbc->tfile);
+
+ return SQL_ERROR;
+ }
+
+ if (pdbc->state != en_dbc_allocated)
+ /* if already connected, we will invoke driver's function */
+ {
+ hproc = _iodbcdm_getproc (hdbc, en_GetConnectOption);
+
+ if (hproc == SQL_NULL_HPROC)
+ {
+ PUSHSQLERR (pdbc->herr, en_IM001);
+
+ return SQL_ERROR;
+ }
+
+ CALL_DRIVER (hdbc, retcode, hproc, en_GetConnectOption,
+ (pdbc->dhdbc, fOption, pvParam))
+
+ return retcode;
+ }
+
+ /* We needn't to handle options which are not allowed
+ * to be *get* at a allocated dbc state(and two tracing
+ * options which has been handled and returned). Thus,
+ * there are only two possible cases.
+ */
+ switch (fOption)
+ {
+ case SQL_ACCESS_MODE:
+ *((UDWORD *) pvParam) = pdbc->access_mode;
+ break;
+
+ case SQL_AUTOCOMMIT:
+ *((UDWORD *) pvParam) = pdbc->autocommit;
+ break;
+
+ case SQL_LOGIN_TIMEOUT:
+ *((UDWORD *) pvParam) = pdbc->login_timeout;
+ break;
+
+ default:
+ break;
+ }
+
+ return SQL_SUCCESS;
+}