@@ -466,6 +466,9 @@ static int check_cursor(pysqlite_Cursor* cur)
466
466
return 0 ;
467
467
}
468
468
469
+ assert (cur -> connection != NULL );
470
+ assert (cur -> connection -> state != NULL );
471
+
469
472
if (cur -> closed ) {
470
473
PyErr_SetString (cur -> connection -> state -> ProgrammingError ,
471
474
"Cannot operate on a closed cursor." );
@@ -562,43 +565,40 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
562
565
switch (paramtype ) {
563
566
case TYPE_LONG : {
564
567
sqlite_int64 value = _pysqlite_long_as_int64 (parameter );
565
- if (value == -1 && PyErr_Occurred ())
566
- rc = -1 ;
567
- else
568
- rc = sqlite3_bind_int64 (self -> st , pos , value );
568
+ rc = (value == -1 && PyErr_Occurred ())
569
+ ? SQLITE_ERROR
570
+ : sqlite3_bind_int64 (self -> st , pos , value );
569
571
break ;
570
572
}
571
573
case TYPE_FLOAT : {
572
574
double value = PyFloat_AsDouble (parameter );
573
- if (value == -1 && PyErr_Occurred ()) {
574
- rc = -1 ;
575
- }
576
- else {
577
- rc = sqlite3_bind_double (self -> st , pos , value );
578
- }
575
+ rc = (value == -1 && PyErr_Occurred ())
576
+ ? SQLITE_ERROR
577
+ : sqlite3_bind_double (self -> st , pos , value );
579
578
break ;
580
579
}
581
580
case TYPE_UNICODE :
582
581
string = PyUnicode_AsUTF8AndSize (parameter , & buflen );
583
- if (string == NULL )
584
- return -1 ;
582
+ if (string == NULL ) {
583
+ return SQLITE_ERROR ;
584
+ }
585
585
if (buflen > INT_MAX ) {
586
586
PyErr_SetString (PyExc_OverflowError ,
587
587
"string longer than INT_MAX bytes" );
588
- return -1 ;
588
+ return SQLITE_ERROR ;
589
589
}
590
590
rc = sqlite3_bind_text (self -> st , pos , string , (int )buflen , SQLITE_TRANSIENT );
591
591
break ;
592
592
case TYPE_BUFFER : {
593
593
Py_buffer view ;
594
594
if (PyObject_GetBuffer (parameter , & view , PyBUF_SIMPLE ) != 0 ) {
595
- return -1 ;
595
+ return SQLITE_ERROR ;
596
596
}
597
597
if (view .len > INT_MAX ) {
598
598
PyErr_SetString (PyExc_OverflowError ,
599
599
"BLOB longer than INT_MAX bytes" );
600
600
PyBuffer_Release (& view );
601
- return -1 ;
601
+ return SQLITE_ERROR ;
602
602
}
603
603
rc = sqlite3_bind_blob (self -> st , pos , view .buf , (int )view .len , SQLITE_TRANSIENT );
604
604
PyBuffer_Release (& view );
@@ -608,7 +608,7 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
608
608
PyErr_Format (state -> ProgrammingError ,
609
609
"Error binding parameter %d: type '%s' is not supported" ,
610
610
pos , Py_TYPE (parameter )-> tp_name );
611
- rc = -1 ;
611
+ rc = SQLITE_ERROR ;
612
612
}
613
613
614
614
final :
@@ -731,14 +731,17 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
731
731
}
732
732
733
733
binding_name ++ ; /* skip first char (the colon) */
734
- PyObject * current_param ;
735
- (void )PyMapping_GetOptionalItemString (parameters , binding_name , & current_param );
736
- if (!current_param ) {
737
- if (!PyErr_Occurred () || PyErr_ExceptionMatches (PyExc_LookupError )) {
738
- PyErr_Format (state -> ProgrammingError ,
739
- "You did not supply a value for binding "
740
- "parameter :%s." , binding_name );
741
- }
734
+ PyObject * current_param = NULL ;
735
+ int found = PyMapping_GetOptionalItemString (parameters ,
736
+ binding_name ,
737
+ & current_param );
738
+ if (found == -1 ) {
739
+ return ;
740
+ }
741
+ else if (found == 0 ) {
742
+ PyErr_Format (state -> ProgrammingError ,
743
+ "You did not supply a value for binding "
744
+ "parameter :%s." , binding_name );
742
745
return ;
743
746
}
744
747
0 commit comments