@@ -37,44 +37,6 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self);
37
37
38
38
static char * errmsg_fetch_across_rollback = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from." ;
39
39
40
- static pysqlite_StatementKind detect_statement_type (char * statement )
41
- {
42
- char buf [20 ];
43
- char * src ;
44
- char * dst ;
45
-
46
- src = statement ;
47
- /* skip over whitepace */
48
- while (* src == '\r' || * src == '\n' || * src == ' ' || * src == '\t' ) {
49
- src ++ ;
50
- }
51
-
52
- if (* src == 0 )
53
- return STATEMENT_INVALID ;
54
-
55
- dst = buf ;
56
- * dst = 0 ;
57
- while (Py_ISALPHA (* src ) && dst - buf < sizeof (buf ) - 2 ) {
58
- * dst ++ = Py_TOLOWER (* src ++ );
59
- }
60
-
61
- * dst = 0 ;
62
-
63
- if (!strcmp (buf , "select" )) {
64
- return STATEMENT_SELECT ;
65
- } else if (!strcmp (buf , "insert" )) {
66
- return STATEMENT_INSERT ;
67
- } else if (!strcmp (buf , "update" )) {
68
- return STATEMENT_UPDATE ;
69
- } else if (!strcmp (buf , "delete" )) {
70
- return STATEMENT_DELETE ;
71
- } else if (!strcmp (buf , "replace" )) {
72
- return STATEMENT_REPLACE ;
73
- } else {
74
- return STATEMENT_OTHER ;
75
- }
76
- }
77
-
78
40
static int pysqlite_cursor_init (pysqlite_Cursor * self , PyObject * args , PyObject * kwargs )
79
41
{
80
42
pysqlite_Connection * connection ;
@@ -454,7 +416,6 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
454
416
PyObject * func_args ;
455
417
PyObject * result ;
456
418
int numcols ;
457
- int statement_type ;
458
419
PyObject * descriptor ;
459
420
PyObject * second_argument = NULL ;
460
421
int allow_8bit_chars ;
@@ -550,7 +511,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
550
511
Py_DECREF (self -> description );
551
512
Py_INCREF (Py_None );
552
513
self -> description = Py_None ;
553
- self -> rowcount = -1L ;
514
+ self -> rowcount = 0L ;
554
515
555
516
func_args = PyTuple_New (1 );
556
517
if (!func_args ) {
@@ -589,39 +550,13 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
589
550
pysqlite_statement_reset (self -> statement );
590
551
pysqlite_statement_mark_dirty (self -> statement );
591
552
592
- statement_type = detect_statement_type (operation_cstr );
593
- if (self -> connection -> begin_statement ) {
594
- switch (statement_type ) {
595
- case STATEMENT_UPDATE :
596
- case STATEMENT_DELETE :
597
- case STATEMENT_INSERT :
598
- case STATEMENT_REPLACE :
599
- if (sqlite3_get_autocommit (self -> connection -> db )) {
600
- result = _pysqlite_connection_begin (self -> connection );
601
- if (!result ) {
602
- goto error ;
603
- }
604
- Py_DECREF (result );
605
- }
606
- break ;
607
- case STATEMENT_OTHER :
608
- /* it's a DDL statement or something similar
609
- - we better COMMIT first so it works for all cases */
610
- if (!sqlite3_get_autocommit (self -> connection -> db )) {
611
- result = pysqlite_connection_commit (self -> connection , NULL );
612
- if (!result ) {
613
- goto error ;
614
- }
615
- Py_DECREF (result );
616
- }
617
- break ;
618
- case STATEMENT_SELECT :
619
- if (multiple ) {
620
- PyErr_SetString (pysqlite_ProgrammingError ,
621
- "You cannot execute SELECT statements in executemany()." );
622
- goto error ;
623
- }
624
- break ;
553
+ if (self -> connection -> begin_statement && !sqlite3_stmt_readonly (self -> statement -> st )) {
554
+ if (sqlite3_get_autocommit (self -> connection -> db )) {
555
+ result = _pysqlite_connection_begin (self -> connection );
556
+ if (!result ) {
557
+ goto error ;
558
+ }
559
+ Py_DECREF (result );
625
560
}
626
561
}
627
562
@@ -658,7 +593,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
658
593
goto error ;
659
594
}
660
595
661
- if (rc == SQLITE_ROW || ( rc == SQLITE_DONE && statement_type == STATEMENT_SELECT ) ) {
596
+ if (rc == SQLITE_ROW || rc == SQLITE_DONE ) {
662
597
if (self -> description == Py_None ) {
663
598
Py_BEGIN_ALLOW_THREADS
664
599
numcols = sqlite3_column_count (self -> statement -> st );
@@ -686,6 +621,21 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
686
621
}
687
622
}
688
623
624
+ if (!sqlite3_stmt_readonly (self -> statement -> st )) {
625
+ self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
626
+ } else {
627
+ self -> rowcount = -1 ;
628
+ }
629
+
630
+ Py_DECREF (self -> lastrowid );
631
+ if (!multiple ) {
632
+ sqlite_int64 lastrowid ;
633
+ Py_BEGIN_ALLOW_THREADS
634
+ lastrowid = sqlite3_last_insert_rowid (self -> connection -> db );
635
+ Py_END_ALLOW_THREADS
636
+ self -> lastrowid = _pysqlite_long_from_int64 (lastrowid );
637
+ }
638
+
689
639
if (rc == SQLITE_ROW ) {
690
640
if (multiple ) {
691
641
PyErr_SetString (pysqlite_ProgrammingError , "executemany() can only execute DML statements." );
@@ -698,29 +648,6 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
698
648
Py_CLEAR (self -> statement );
699
649
}
700
650
701
- switch (statement_type ) {
702
- case STATEMENT_UPDATE :
703
- case STATEMENT_DELETE :
704
- case STATEMENT_INSERT :
705
- case STATEMENT_REPLACE :
706
- if (self -> rowcount == -1L ) {
707
- self -> rowcount = 0L ;
708
- }
709
- self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
710
- }
711
-
712
- Py_DECREF (self -> lastrowid );
713
- if (!multiple && statement_type == STATEMENT_INSERT ) {
714
- sqlite_int64 lastrowid ;
715
- Py_BEGIN_ALLOW_THREADS
716
- lastrowid = sqlite3_last_insert_rowid (self -> connection -> db );
717
- Py_END_ALLOW_THREADS
718
- self -> lastrowid = _pysqlite_long_from_int64 (lastrowid );
719
- } else {
720
- Py_INCREF (Py_None );
721
- self -> lastrowid = Py_None ;
722
- }
723
-
724
651
if (multiple ) {
725
652
rc = pysqlite_statement_reset (self -> statement );
726
653
}
0 commit comments