@@ -111,8 +111,6 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
111
111
112
112
const char * database = PyBytes_AsString (database_obj );
113
113
114
- self -> initialized = 1 ;
115
-
116
114
self -> begin_statement = NULL ;
117
115
118
116
Py_CLEAR (self -> statement_cache );
@@ -147,7 +145,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
147
145
Py_INCREF (isolation_level );
148
146
}
149
147
Py_CLEAR (self -> isolation_level );
150
- if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) < 0 ) {
148
+ if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) != 0 ) {
151
149
Py_DECREF (isolation_level );
152
150
return -1 ;
153
151
}
@@ -195,6 +193,8 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
195
193
return -1 ;
196
194
}
197
195
196
+ self -> initialized = 1 ;
197
+
198
198
return 0 ;
199
199
}
200
200
@@ -371,6 +371,13 @@ pysqlite_connection_close_impl(pysqlite_Connection *self)
371
371
return NULL ;
372
372
}
373
373
374
+ if (!self -> initialized ) {
375
+ pysqlite_state * state = pysqlite_get_state (NULL );
376
+ PyErr_SetString (state -> ProgrammingError ,
377
+ "Base Connection.__init__ not called." );
378
+ return NULL ;
379
+ }
380
+
374
381
pysqlite_do_all_statements (self , ACTION_FINALIZE , 1 );
375
382
connection_close (self );
376
383
@@ -1258,6 +1265,9 @@ int pysqlite_check_thread(pysqlite_Connection* self)
1258
1265
1259
1266
static PyObject * pysqlite_connection_get_isolation_level (pysqlite_Connection * self , void * unused )
1260
1267
{
1268
+ if (!pysqlite_check_connection (self )) {
1269
+ return NULL ;
1270
+ }
1261
1271
return Py_NewRef (self -> isolation_level );
1262
1272
}
1263
1273
@@ -1289,11 +1299,17 @@ pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* iso
1289
1299
return -1 ;
1290
1300
}
1291
1301
if (isolation_level == Py_None ) {
1292
- PyObject * res = pysqlite_connection_commit (self , NULL );
1293
- if (!res ) {
1294
- return -1 ;
1302
+ /* We might get called during connection init, so we cannot use
1303
+ * pysqlite_connection_commit() here. */
1304
+ if (self -> db && !sqlite3_get_autocommit (self -> db )) {
1305
+ int rc ;
1306
+ Py_BEGIN_ALLOW_THREADS
1307
+ rc = sqlite3_exec (self -> db , "COMMIT" , NULL , NULL , NULL );
1308
+ Py_END_ALLOW_THREADS
1309
+ if (rc != SQLITE_OK ) {
1310
+ return _pysqlite_seterror (self -> db );
1311
+ }
1295
1312
}
1296
- Py_DECREF (res );
1297
1313
1298
1314
self -> begin_statement = NULL ;
1299
1315
} else {
0 commit comments