Changeset: fbaffdac9bf4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fbaffdac9bf4
Modified Files:
clients/odbc/driver/ODBCDbc.h
clients/odbc/driver/SQLConnect.c
Branch: odbc-tls
Log Message:
Extract MNDBConnectSettings
diffs (127 lines):
diff --git a/clients/odbc/driver/ODBCDbc.h b/clients/odbc/driver/ODBCDbc.h
--- a/clients/odbc/driver/ODBCDbc.h
+++ b/clients/odbc/driver/ODBCDbc.h
@@ -169,4 +169,7 @@ SQLRETURN MNDBSetConnectAttr(ODBCDbc *db
*/
extern char *ODBCTranslateSQL(ODBCDbc *dbc, const SQLCHAR *query, size_t
length, SQLULEN noscan);
+extern SQLRETURN MNDBConnectSettings(ODBCDbc *dbc, msettings *settings);
+
+
#endif
diff --git a/clients/odbc/driver/SQLConnect.c b/clients/odbc/driver/SQLConnect.c
--- a/clients/odbc/driver/SQLConnect.c
+++ b/clients/odbc/driver/SQLConnect.c
@@ -373,6 +373,10 @@ MNDBConnect(ODBCDbc *dbc,
goto failure;
}
+ error_explanation = msetting_set_long(settings, MP_MAPTOLONGVARCHAR,
mapToLongVarchar);
+ if (error_explanation)
+ goto failure;
+
#ifdef ODBCDEBUG
{
free(scratch);
@@ -381,38 +385,16 @@ MNDBConnect(ODBCDbc *dbc,
}
#endif
- // Create mid and execute a bunch of commands before checking for
errors.
- mid = mapi_settings(settings);
- if (mid) {
- settings = NULL; // it has moved into 'mid' and must not be
freed.
- mapi_setAutocommit(mid, dbc->sql_attr_autocommit ==
SQL_AUTOCOMMIT_ON);
- mapi_set_size_header(mid, true);
- mapi_reconnect(mid);
- }
- if (mid == NULL || mapi_error(mid)) {
- error_state = "08001";
- error_explanation = mid ? mapi_error_str(mid) : NULL;
- goto failure;
+ assert(error_state == NULL);
+ assert(error_explanation == NULL);
+
+ SQLRETURN ret;
+
+ ret = MNDBConnectSettings(dbc, settings);
+ if (SQL_SUCCEEDED(ret)) {
+ settings = NULL; // must not be free'd now
}
- /* store internal information and clean up buffers */
- dbc->Connected = true;
- dbc->mapToLongVarchar = mapToLongVarchar;
-
- // Move strings into the dbc struct, clearing whatever was there
- // and leaving the original location NULL so they don't accidentally
- // get free'd.
- if (dbc->mid)
- mapi_destroy(dbc->mid);
- dbc->mid = mid;
- mid = NULL; // it has moved into 'dbc' and must not be freed.
-
- get_serverinfo(dbc);
- /* set timeout after we're connected */
- mapi_timeout(dbc->mid, dbc->sql_attr_connection_timeout * 1000);
-
- assert(error_state == NULL);
- assert(error_explanation == NULL);
goto end;
failure:
@@ -423,8 +405,9 @@ failure:
error_state = "HY009"; // invalid argument
}
addDbcError(dbc, error_state, error_explanation, 0);
+ ret = SQL_ERROR;
+
// fallthrough
-
end:
free(dsn);
free(scratch);
@@ -432,9 +415,42 @@ end:
mapi_destroy(mid);
msettings_destroy(settings);
- return error_state == NULL ? SQL_SUCCESS : SQL_ERROR;
+ return ret;
}
+SQLRETURN
+MNDBConnectSettings(ODBCDbc *dbc, msettings *settings)
+{
+ Mapi mid = mapi_settings(settings);
+ if (mid) {
+ mapi_setAutocommit(mid, dbc->sql_attr_autocommit ==
SQL_AUTOCOMMIT_ON);
+ mapi_set_size_header(mid, true);
+ mapi_reconnect(mid);
+ }
+ if (mid == NULL || mapi_error(mid)) {
+ const char *error_state = "08001";
+ const char *error_explanation = mid ? mapi_error_str(mid) :
NULL;
+ addDbcError(dbc, error_state, error_explanation, 0);
+ return SQL_ERROR;
+ }
+
+ dbc->Connected = true;
+ dbc->mapToLongVarchar = msetting_long(settings, MP_MAPTOLONGVARCHAR);
+
+ if (dbc->mid)
+ mapi_destroy(dbc->mid);
+ dbc->mid = mid;
+
+ get_serverinfo(dbc);
+ /* set timeout after we're connected */
+ mapi_timeout(dbc->mid, dbc->sql_attr_connection_timeout * 1000);
+
+ return SQL_SUCCESS;
+}
+
+
+
+
SQLRETURN SQL_API
SQLConnect(SQLHDBC ConnectionHandle,
SQLCHAR *ServerName,
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]