Changeset: e48d017e9a10 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e48d017e9a10
Modified Files:
        clients/odbc/driver/ODBCDbc.c
        clients/odbc/driver/ODBCDbc.h
        clients/odbc/driver/SQLConnect.c
        clients/odbc/driver/SQLEndTran.c
        clients/odbc/driver/SQLGetConnectAttr.c
        clients/odbc/driver/SQLSetConnectAttr.c
        sql/odbc/tests/Tests/ODBCconnect.py
Branch: Aug2024
Log Message:

Get rid of sql_attr_autocommit

It's part of the msettings now and shouldn't blindly override those.


diffs (111 lines):

diff --git a/clients/odbc/driver/ODBCDbc.c b/clients/odbc/driver/ODBCDbc.c
--- a/clients/odbc/driver/ODBCDbc.c
+++ b/clients/odbc/driver/ODBCDbc.c
@@ -80,7 +80,6 @@ newODBCDbc(ODBCEnv *env)
        *dbc = (ODBCDbc) {
                .Env = env,
                .settings = settings,
-               .sql_attr_autocommit = SQL_AUTOCOMMIT_ON,       /* default is 
autocommit */
                .sql_attr_metadata_id = SQL_FALSE,
                /* add this dbc to start of the administrative linked dbc list 
*/
                .next = env->FirstDbc,
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
@@ -59,7 +59,6 @@ typedef struct tODBCDRIVERDBC {
        bool allow_hugeint;     /* whether the application deals with HUGEINT */
        bool raw_strings;       /* server uses raw strings */
        int mapToLongVarchar;   /* when > 0 we map WVARCHAR to WLONGVARCHAR, 
default 0 */
-       SQLUINTEGER sql_attr_autocommit;
        SQLUINTEGER sql_attr_metadata_id;
 
        /* MonetDB connection handle & status information */
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
@@ -482,7 +482,6 @@ MNDBConnectSettings(ODBCDbc *dbc, const 
        if (mid) {
                settings = NULL; // will be free'd as part of 'mid' now
                mapi_setclientprefix(mid, "ODBC " MONETDB_VERSION);
-               mapi_setAutocommit(mid, dbc->sql_attr_autocommit == 
SQL_AUTOCOMMIT_ON);
                mapi_set_size_header(mid, true);
                mapi_reconnect(mid);
        }
diff --git a/clients/odbc/driver/SQLEndTran.c b/clients/odbc/driver/SQLEndTran.c
--- a/clients/odbc/driver/SQLEndTran.c
+++ b/clients/odbc/driver/SQLEndTran.c
@@ -119,7 +119,7 @@ MNDBEndTran(SQLSMALLINT HandleType,
 
        assert(HandleType == SQL_HANDLE_DBC);
 
-       if (dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON) {
+       if (msetting_bool(dbc->settings, MP_AUTOCOMMIT)) {
                /* nothing to do if in autocommit mode */
                return SQL_SUCCESS;
        }
diff --git a/clients/odbc/driver/SQLGetConnectAttr.c 
b/clients/odbc/driver/SQLGetConnectAttr.c
--- a/clients/odbc/driver/SQLGetConnectAttr.c
+++ b/clients/odbc/driver/SQLGetConnectAttr.c
@@ -64,7 +64,8 @@ MNDBGetConnectAttr(ODBCDbc *dbc,
                break;
        case SQL_ATTR_AUTOCOMMIT:               /* SQLUINTEGER */
                /* SQL_AUTOCOMMIT */
-               WriteData(ValuePtr, dbc->sql_attr_autocommit, SQLUINTEGER);
+               bool autocommit = msetting_bool(dbc->settings, MP_AUTOCOMMIT);
+               WriteData(ValuePtr, autocommit, SQLUINTEGER);
                break;
        case SQL_ATTR_CONNECTION_DEAD:          /* SQLUINTEGER */
                WriteData(ValuePtr, dbc->mid && mapi_is_connected(dbc->mid) ? 
SQL_CD_FALSE : SQL_CD_TRUE, SQLUINTEGER);
diff --git a/clients/odbc/driver/SQLSetConnectAttr.c 
b/clients/odbc/driver/SQLSetConnectAttr.c
--- a/clients/odbc/driver/SQLSetConnectAttr.c
+++ b/clients/odbc/driver/SQLSetConnectAttr.c
@@ -47,13 +47,12 @@ MNDBSetConnectAttr(ODBCDbc *dbc,
                switch ((SQLUINTEGER) (uintptr_t) ValuePtr) {
                case SQL_AUTOCOMMIT_ON:
                case SQL_AUTOCOMMIT_OFF:
-                       dbc->sql_attr_autocommit = (SQLUINTEGER) (uintptr_t) 
ValuePtr;
+                       bool autocommit = (bool) (SQLUINTEGER) (uintptr_t) 
ValuePtr;
 #ifdef ODBCDEBUG
-                       ODBCLOG("SQLSetConnectAttr set autocommit %s\n",
-                               dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON ? 
"on" : "off");
+                       ODBCLOG("SQLSetConnectAttr set autocommit %s\n", 
autocommit ? "on" : "off");
 #endif
                        if (dbc->mid)
-                               mapi_setAutocommit(dbc->mid, 
dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON);
+                               mapi_setAutocommit(dbc->mid, autocommit);
                        break;
                default:
                        /* Invalid attribute value */
diff --git a/sql/odbc/tests/Tests/ODBCconnect.py 
b/sql/odbc/tests/Tests/ODBCconnect.py
--- a/sql/odbc/tests/Tests/ODBCconnect.py
+++ b/sql/odbc/tests/Tests/ODBCconnect.py
@@ -179,6 +179,29 @@ ex = Execution('-0', '-d', f'DSN={dsn}-W
 ex.expect('OK')
 ex.end()
 
+# test autocommit, default should be On
+ex = Execution('-d', f'DSN={dsn}', '-q', 'ROLLBACK')
+ex.expect('OK')         # connect succeeds
+ex.expect('Error:')     # rollback fails
+ex.expect('2DM30:')     # because 2DM30: not allowed in autocommit mode
+ex.expect_fail()
+ex.end()
+
+# test autocommit, force On
+ex = Execution('-d', f'DSN={dsn};Autocommit=On', '-q', 'ROLLBACK')
+ex.expect('OK')         # connect succeeds
+ex.expect('Error:')     # rollback fails
+ex.expect('2DM30:')     # because 2DM30: not allowed in autocommit mode
+ex.expect_fail()
+ex.end()
+
+# test autocommit, force Off
+ex = Execution('-d', f'DSN={dsn};Autocommit=Off', '-q', 'ROLLBACK')
+ex.expect('OK')         # connect succeeds
+ex.expect('RESULT')     # rollback succeeds
+ex.end()
+
+
 # Test browsing
 
 ex = Execution('-b', 'Driver={MonetDB}')
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to