@@ -130,7 +130,8 @@ cursor_dealloc(pysqlite_Cursor *self)
130
130
}
131
131
132
132
static PyObject *
133
- _pysqlite_get_converter (const char * keystr , Py_ssize_t keylen )
133
+ _pysqlite_get_converter (pysqlite_state * state , const char * keystr ,
134
+ Py_ssize_t keylen )
134
135
{
135
136
PyObject * key ;
136
137
PyObject * upcase_key ;
@@ -147,7 +148,6 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen)
147
148
return NULL ;
148
149
}
149
150
150
- pysqlite_state * state = pysqlite_get_state (NULL );
151
151
retval = PyDict_GetItemWithError (state -> converters , upcase_key );
152
152
Py_DECREF (upcase_key );
153
153
@@ -187,7 +187,9 @@ pysqlite_build_row_cast_map(pysqlite_Cursor* self)
187
187
type_start = pos + 1 ;
188
188
}
189
189
else if (* pos == ']' && type_start != NULL ) {
190
- converter = _pysqlite_get_converter (type_start , pos - type_start );
190
+ pysqlite_state * state = self -> connection -> state ;
191
+ converter = _pysqlite_get_converter (state , type_start ,
192
+ pos - type_start );
191
193
if (!converter && PyErr_Occurred ()) {
192
194
Py_CLEAR (self -> row_cast_map );
193
195
return -1 ;
@@ -206,7 +208,9 @@ pysqlite_build_row_cast_map(pysqlite_Cursor* self)
206
208
* 'NUMBER(10)' to be treated as 'NUMBER', for example.
207
209
* In other words, it will work as people expect it to work.*/
208
210
if (* pos == ' ' || * pos == '(' || * pos == 0 ) {
209
- converter = _pysqlite_get_converter (decltype , pos - decltype );
211
+ pysqlite_state * state = self -> connection -> state ;
212
+ converter = _pysqlite_get_converter (state , decltype ,
213
+ pos - decltype );
210
214
if (!converter && PyErr_Occurred ()) {
211
215
Py_CLEAR (self -> row_cast_map );
212
216
return -1 ;
@@ -404,22 +408,21 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
404
408
*/
405
409
static int check_cursor (pysqlite_Cursor * cur )
406
410
{
407
- pysqlite_state * state = pysqlite_get_state (NULL );
408
-
409
411
if (!cur -> initialized ) {
412
+ pysqlite_state * state = pysqlite_get_state_by_type (Py_TYPE (cur ));
410
413
PyErr_SetString (state -> ProgrammingError ,
411
414
"Base Cursor.__init__ not called." );
412
415
return 0 ;
413
416
}
414
417
415
418
if (cur -> closed ) {
416
- PyErr_SetString (state -> ProgrammingError ,
419
+ PyErr_SetString (cur -> connection -> state -> ProgrammingError ,
417
420
"Cannot operate on a closed cursor." );
418
421
return 0 ;
419
422
}
420
423
421
424
if (cur -> locked ) {
422
- PyErr_SetString (state -> ProgrammingError ,
425
+ PyErr_SetString (cur -> connection -> state -> ProgrammingError ,
423
426
"Recursive use of cursors not allowed." );
424
427
return 0 ;
425
428
}
@@ -439,7 +442,7 @@ begin_transaction(pysqlite_Connection *self)
439
442
Py_END_ALLOW_THREADS
440
443
441
444
if (rc != SQLITE_OK ) {
442
- _pysqlite_seterror (self -> db );
445
+ _pysqlite_seterror (self -> state , self -> db );
443
446
goto error ;
444
447
}
445
448
@@ -449,7 +452,7 @@ begin_transaction(pysqlite_Connection *self)
449
452
Py_END_ALLOW_THREADS
450
453
451
454
if (rc != SQLITE_OK && !PyErr_Occurred ()) {
452
- _pysqlite_seterror (self -> db );
455
+ _pysqlite_seterror (self -> state , self -> db );
453
456
}
454
457
455
458
error :
@@ -470,7 +473,6 @@ get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
470
473
static PyObject *
471
474
_pysqlite_query_execute (pysqlite_Cursor * self , int multiple , PyObject * operation , PyObject * second_argument )
472
475
{
473
- pysqlite_state * state = pysqlite_get_state (NULL );
474
476
PyObject * parameters_list = NULL ;
475
477
PyObject * parameters_iter = NULL ;
476
478
PyObject * parameters = NULL ;
@@ -568,6 +570,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
568
570
}
569
571
}
570
572
573
+ pysqlite_state * state = self -> connection -> state ;
571
574
while (1 ) {
572
575
parameters = PyIter_Next (parameters_iter );
573
576
if (!parameters ) {
@@ -576,7 +579,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
576
579
577
580
pysqlite_statement_mark_dirty (self -> statement );
578
581
579
- pysqlite_statement_bind_parameters (self -> statement , parameters );
582
+ pysqlite_statement_bind_parameters (state , self -> statement , parameters );
580
583
if (PyErr_Occurred ()) {
581
584
goto error ;
582
585
}
@@ -592,12 +595,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
592
595
}
593
596
}
594
597
(void )pysqlite_statement_reset (self -> statement );
595
- _pysqlite_seterror (self -> connection -> db );
598
+ _pysqlite_seterror (state , self -> connection -> db );
596
599
goto error ;
597
600
}
598
601
599
602
if (pysqlite_build_row_cast_map (self ) != 0 ) {
600
- _PyErr_FormatFromCause (self -> connection -> OperationalError ,
603
+ _PyErr_FormatFromCause (state -> OperationalError ,
601
604
"Error while building row_cast_map" );
602
605
goto error ;
603
606
}
@@ -651,7 +654,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
651
654
652
655
if (rc == SQLITE_ROW ) {
653
656
if (multiple ) {
654
- PyErr_SetString (self -> connection -> ProgrammingError ,
657
+ PyErr_SetString (state -> ProgrammingError ,
655
658
"executemany() can only execute DML "
656
659
"statements." );
657
660
goto error ;
@@ -773,6 +776,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
773
776
}
774
777
Py_DECREF (result );
775
778
779
+ pysqlite_state * state = self -> connection -> state ;
776
780
while (1 ) {
777
781
const char * tail ;
778
782
@@ -784,7 +788,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
784
788
& tail );
785
789
Py_END_ALLOW_THREADS
786
790
if (rc != SQLITE_OK ) {
787
- _pysqlite_seterror (self -> connection -> db );
791
+ _pysqlite_seterror (state , self -> connection -> db );
788
792
goto error ;
789
793
}
790
794
@@ -799,13 +803,13 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
799
803
800
804
if (rc != SQLITE_DONE ) {
801
805
(void )sqlite3_finalize (statement );
802
- _pysqlite_seterror (self -> connection -> db );
806
+ _pysqlite_seterror (state , self -> connection -> db );
803
807
goto error ;
804
808
}
805
809
806
810
rc = sqlite3_finalize (statement );
807
811
if (rc != SQLITE_OK ) {
808
- _pysqlite_seterror (self -> connection -> db );
812
+ _pysqlite_seterror (state , self -> connection -> db );
809
813
goto error ;
810
814
}
811
815
@@ -874,7 +878,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
874
878
if (rc != SQLITE_DONE && rc != SQLITE_ROW ) {
875
879
(void )pysqlite_statement_reset (self -> statement );
876
880
Py_DECREF (next_row );
877
- _pysqlite_seterror (self -> connection -> db );
881
+ _pysqlite_seterror (self -> connection -> state , self -> connection -> db );
878
882
return NULL ;
879
883
}
880
884
@@ -1023,15 +1027,17 @@ pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
1023
1027
/*[clinic input]
1024
1028
_sqlite3.Cursor.close as pysqlite_cursor_close
1025
1029
1030
+ cls: defining_class
1031
+
1026
1032
Closes the cursor.
1027
1033
[clinic start generated code]*/
1028
1034
1029
1035
static PyObject *
1030
- pysqlite_cursor_close_impl (pysqlite_Cursor * self )
1031
- /*[clinic end generated code: output=b6055e4ec6fe63b6 input=08b36552dbb9a986 ]*/
1036
+ pysqlite_cursor_close_impl (pysqlite_Cursor * self , PyTypeObject * cls )
1037
+ /*[clinic end generated code: output=a08ab3d772f45438 input=28ba9b532ab46ba0 ]*/
1032
1038
{
1033
1039
if (!self -> connection ) {
1034
- pysqlite_state * state = pysqlite_get_state ( NULL );
1040
+ pysqlite_state * state = pysqlite_get_state_by_cls ( cls );
1035
1041
PyErr_SetString (state -> ProgrammingError ,
1036
1042
"Base Cursor.__init__ not called." );
1037
1043
return NULL ;
0 commit comments