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