@@ -102,8 +102,6 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
102
102
103
103
database = PyBytes_AsString (database_obj );
104
104
105
- self -> initialized = 1 ;
106
-
107
105
self -> begin_statement = NULL ;
108
106
109
107
Py_CLEAR (self -> statement_cache );
@@ -149,7 +147,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
149
147
Py_INCREF (isolation_level );
150
148
}
151
149
Py_CLEAR (self -> isolation_level );
152
- if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) < 0 ) {
150
+ if (pysqlite_connection_set_isolation_level (self , isolation_level , NULL ) != 0 ) {
153
151
Py_DECREF (isolation_level );
154
152
return -1 ;
155
153
}
@@ -208,6 +206,8 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
208
206
self -> ProgrammingError = pysqlite_ProgrammingError ;
209
207
self -> NotSupportedError = pysqlite_NotSupportedError ;
210
208
209
+ self -> initialized = 1 ;
210
+
211
211
return 0 ;
212
212
}
213
213
@@ -339,6 +339,12 @@ PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
339
339
return NULL ;
340
340
}
341
341
342
+ if (!self -> initialized ) {
343
+ PyErr_SetString (pysqlite_ProgrammingError ,
344
+ "Base Connection.__init__ not called." );
345
+ return NULL ;
346
+ }
347
+
342
348
pysqlite_do_all_statements (self , ACTION_FINALIZE , 1 );
343
349
344
350
if (self -> db ) {
@@ -1143,6 +1149,9 @@ int pysqlite_check_thread(pysqlite_Connection* self)
1143
1149
1144
1150
static PyObject * pysqlite_connection_get_isolation_level (pysqlite_Connection * self , void * unused )
1145
1151
{
1152
+ if (!pysqlite_check_connection (self )) {
1153
+ return NULL ;
1154
+ }
1146
1155
Py_INCREF (self -> isolation_level );
1147
1156
return self -> isolation_level ;
1148
1157
}
@@ -1175,11 +1184,17 @@ pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* iso
1175
1184
return -1 ;
1176
1185
}
1177
1186
if (isolation_level == Py_None ) {
1178
- PyObject * res = pysqlite_connection_commit (self , NULL );
1179
- if (!res ) {
1180
- return -1 ;
1187
+ /* We might get called during connection init, so we cannot use
1188
+ * pysqlite_connection_commit() here. */
1189
+ if (self -> db && !sqlite3_get_autocommit (self -> db )) {
1190
+ int rc ;
1191
+ Py_BEGIN_ALLOW_THREADS
1192
+ rc = sqlite3_exec (self -> db , "COMMIT" , NULL , NULL , NULL );
1193
+ Py_END_ALLOW_THREADS
1194
+ if (rc != SQLITE_OK ) {
1195
+ return _pysqlite_seterror (self -> db , NULL );
1196
+ }
1181
1197
}
1182
- Py_DECREF (res );
1183
1198
1184
1199
self -> begin_statement = NULL ;
1185
1200
} else {
0 commit comments