@@ -523,6 +523,40 @@ _sqlite3.Connection.cursor as pysqlite_connection_cursor
523523
524524Return a cursor for the connection.
525525[clinic start generated code]*/
526+
527+ static PyObject *
528+ pysqlite_connection_cursor_impl (pysqlite_Connection * self , PyObject * factory )
529+ /*[clinic end generated code: output=562432a9e6af2aa1 input=4127345aa091b650]*/
530+ {
531+ PyObject * cursor ;
532+
533+ if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
534+ return NULL ;
535+ }
536+
537+ if (factory == NULL ) {
538+ factory = (PyObject * )self -> state -> CursorType ;
539+ }
540+
541+ cursor = PyObject_CallOneArg (factory , (PyObject * )self );
542+ if (cursor == NULL )
543+ return NULL ;
544+ if (!PyObject_TypeCheck (cursor , self -> state -> CursorType )) {
545+ PyErr_Format (PyExc_TypeError ,
546+ "factory must return a cursor, not %.100s" ,
547+ Py_TYPE (cursor )-> tp_name );
548+ Py_DECREF (cursor );
549+ return NULL ;
550+ }
551+
552+ if (cursor && self -> row_factory != Py_None ) {
553+ Py_INCREF (self -> row_factory );
554+ Py_XSETREF (((pysqlite_Cursor * )cursor )-> row_factory , self -> row_factory );
555+ }
556+
557+ return cursor ;
558+ }
559+
526560static PyObject *
527561connection_get_row_factory (pysqlite_Connection * self , void * closure )
528562{
@@ -533,7 +567,7 @@ static int
533567connection_set_row_factory (pysqlite_Connection * self , PyObject * value , void * closure )
534568{
535569 if (value == NULL ) {
536- PyErr_SetString (PyExc_AttributeError ,
570+ PyErr_SetString (PyExc_AttributeError ,
537571 "cannot delete row_factory attribute" );
538572 return -1 ;
539573 }
@@ -551,46 +585,14 @@ static int
551585connection_set_text_factory (pysqlite_Connection * self , PyObject * value , void * closure )
552586{
553587 if (value == NULL ) {
554- PyErr_SetString (PyExc_AttributeError ,
588+ PyErr_SetString (PyExc_AttributeError ,
555589 "cannot delete text_factory attribute" );
556590 return -1 ;
557591 }
558592 Py_XSETREF (self -> text_factory , Py_NewRef (value ));
559593 return 0 ;
560594}
561595
562- static PyObject *
563- pysqlite_connection_cursor_impl (pysqlite_Connection * self , PyObject * factory )
564- /*[clinic end generated code: output=562432a9e6af2aa1 input=4127345aa091b650]*/
565- {
566- PyObject * cursor ;
567-
568- if (!pysqlite_check_thread (self ) || !pysqlite_check_connection (self )) {
569- return NULL ;
570- }
571-
572- if (factory == NULL ) {
573- factory = (PyObject * )self -> state -> CursorType ;
574- }
575-
576- cursor = PyObject_CallOneArg (factory , (PyObject * )self );
577- if (cursor == NULL )
578- return NULL ;
579- if (!PyObject_TypeCheck (cursor , self -> state -> CursorType )) {
580- PyErr_Format (PyExc_TypeError ,
581- "factory must return a cursor, not %.100s" ,
582- Py_TYPE (cursor )-> tp_name );
583- Py_DECREF (cursor );
584- return NULL ;
585- }
586-
587- if (cursor && self -> row_factory && self -> row_factory != Py_None ) {
588- Py_INCREF (self -> row_factory );
589- Py_XSETREF (((pysqlite_Cursor * )cursor )-> row_factory , self -> row_factory );
590- }
591-
592- return cursor ;
593- }
594596
595597/*[clinic input]
596598_sqlite3.Connection.blobopen as blobopen
@@ -2655,9 +2657,9 @@ static PyGetSetDef connection_getset[] = {
26552657 {"in_transaction" , pysqlite_connection_get_in_transaction , NULL },
26562658 {"autocommit" , get_autocommit , set_autocommit },
26572659 {"__text_signature__" , get_sig , NULL },
2658- {"row_factory" , (getter )connection_get_row_factory ,
2660+ {"row_factory" , (getter )connection_get_row_factory ,
26592661 (setter )connection_set_row_factory },
2660- {"text_factory" , (getter )connection_get_text_factory ,
2662+ {"text_factory" , (getter )connection_get_text_factory ,
26612663 (setter )connection_set_text_factory },
26622664 {NULL }
26632665};
0 commit comments