@@ -721,19 +721,13 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
721
721
const char * sql_script )
722
722
/*[clinic end generated code: output=8fd726dde1c65164 input=1ac0693dc8db02a8]*/
723
723
{
724
- _Py_IDENTIFIER (commit );
725
- sqlite3_stmt * statement ;
726
- int rc ;
727
- size_t sql_len ;
728
- PyObject * result ;
729
-
730
724
if (!check_cursor (self )) {
731
725
return NULL ;
732
726
}
733
727
734
728
self -> reset = 0 ;
735
729
736
- sql_len = strlen (sql_script );
730
+ size_t sql_len = strlen (sql_script );
737
731
int max_length = sqlite3_limit (self -> connection -> db ,
738
732
SQLITE_LIMIT_LENGTH , -1 );
739
733
if (sql_len >= (unsigned )max_length ) {
@@ -742,47 +736,37 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
742
736
return NULL ;
743
737
}
744
738
745
- /* commit first */
746
- result = _PyObject_CallMethodIdNoArgs ((PyObject * )self -> connection , & PyId_commit );
747
- if (!result ) {
748
- goto error ;
749
- }
750
- Py_DECREF (result );
751
-
752
- pysqlite_state * state = self -> connection -> state ;
753
- while (1 ) {
754
- const char * tail ;
739
+ // Commit if needed
740
+ sqlite3 * db = self -> connection -> db ;
741
+ if (!sqlite3_get_autocommit (db )) {
742
+ int rc = SQLITE_OK ;
755
743
756
744
Py_BEGIN_ALLOW_THREADS
757
- rc = sqlite3_prepare_v2 (self -> connection -> db ,
758
- sql_script ,
759
- (int )sql_len + 1 ,
760
- & statement ,
761
- & tail );
745
+ rc = sqlite3_exec (db , "COMMIT" , NULL , NULL , NULL );
762
746
Py_END_ALLOW_THREADS
747
+
763
748
if (rc != SQLITE_OK ) {
764
- _pysqlite_seterror (state , self -> connection -> db );
765
749
goto error ;
766
750
}
751
+ }
767
752
768
- /* execute statement, and ignore results of SELECT statements */
769
- do {
770
- rc = pysqlite_step (statement );
771
- if (PyErr_Occurred ()) {
772
- (void )sqlite3_finalize (statement );
773
- goto error ;
774
- }
775
- } while (rc == SQLITE_ROW );
753
+ while (1 ) {
754
+ int rc ;
755
+ const char * tail ;
776
756
777
- if (rc != SQLITE_DONE ) {
778
- (void )sqlite3_finalize (statement );
779
- _pysqlite_seterror (state , self -> connection -> db );
780
- goto error ;
757
+ Py_BEGIN_ALLOW_THREADS
758
+ sqlite3_stmt * stmt ;
759
+ rc = sqlite3_prepare_v2 (db , sql_script , (int )sql_len + 1 , & stmt ,
760
+ & tail );
761
+ if (rc == SQLITE_OK ) {
762
+ do {
763
+ (void )sqlite3_step (stmt );
764
+ } while (rc == SQLITE_ROW );
765
+ rc = sqlite3_finalize (stmt );
781
766
}
767
+ Py_END_ALLOW_THREADS
782
768
783
- rc = sqlite3_finalize (statement );
784
769
if (rc != SQLITE_OK ) {
785
- _pysqlite_seterror (state , self -> connection -> db );
786
770
goto error ;
787
771
}
788
772
@@ -793,12 +777,11 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
793
777
sql_script = tail ;
794
778
}
795
779
780
+ return Py_NewRef ((PyObject * )self );
781
+
796
782
error :
797
- if (PyErr_Occurred ()) {
798
- return NULL ;
799
- } else {
800
- return Py_NewRef ((PyObject * )self );
801
- }
783
+ _pysqlite_seterror (self -> connection -> state , db );
784
+ return NULL ;
802
785
}
803
786
804
787
static PyObject *
0 commit comments