@@ -92,8 +92,6 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
92
92
93
93
database = PyBytes_AsString (database_obj );
94
94
95
- self -> initialized = 1 ;
96
-
97
95
self -> begin_statement = NULL ;
98
96
99
97
Py_CLEAR (self -> statement_cache );
@@ -128,7 +126,7 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
128
126
Py_INCREF (isolation_level );
129
127
}
130
128
Py_CLEAR (self -> isolation_level );
131
- if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) < 0 ) {
129
+ if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) != 0 ) {
132
130
Py_DECREF (isolation_level );
133
131
return -1 ;
134
132
}
@@ -187,6 +185,8 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
187
185
return -1 ;
188
186
}
189
187
188
+ self -> initialized = 1 ;
189
+
190
190
return 0 ;
191
191
}
192
192
@@ -359,6 +359,12 @@ pysqlite_connection_close_impl(pysqlite_Connection *self)
359
359
return NULL ;
360
360
}
361
361
362
+ if (!self -> initialized ) {
363
+ PyErr_SetString (pysqlite_ProgrammingError ,
364
+ "Base Connection.__init__ not called." );
365
+ return NULL ;
366
+ }
367
+
362
368
pysqlite_do_all_statements (self , ACTION_FINALIZE , 1 );
363
369
364
370
if (self -> db ) {
@@ -1264,6 +1270,9 @@ int pysqlite_check_thread(pysqlite_Connection* self)
1264
1270
1265
1271
static PyObject * pysqlite_connection_get_isolation_level (pysqlite_Connection * self , void * unused )
1266
1272
{
1273
+ if (!pysqlite_check_connection (self )) {
1274
+ return NULL ;
1275
+ }
1267
1276
return Py_NewRef (self -> isolation_level );
1268
1277
}
1269
1278
@@ -1295,11 +1304,17 @@ pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* iso
1295
1304
return -1 ;
1296
1305
}
1297
1306
if (isolation_level == Py_None ) {
1298
- PyObject * res = pysqlite_connection_commit (self , NULL );
1299
- if (!res ) {
1300
- return -1 ;
1307
+ /* We might get called during connection init, so we cannot use
1308
+ * pysqlite_connection_commit() here. */
1309
+ if (self -> db && !sqlite3_get_autocommit (self -> db )) {
1310
+ int rc ;
1311
+ Py_BEGIN_ALLOW_THREADS
1312
+ rc = sqlite3_exec (self -> db , "COMMIT" , NULL , NULL , NULL );
1313
+ Py_END_ALLOW_THREADS
1314
+ if (rc != SQLITE_OK ) {
1315
+ return _pysqlite_seterror (self -> db , NULL );
1316
+ }
1301
1317
}
1302
- Py_DECREF (res );
1303
1318
1304
1319
self -> begin_statement = NULL ;
1305
1320
} else {
0 commit comments