@@ -466,6 +466,9 @@ static int check_cursor(pysqlite_Cursor* cur)
466466 return 0 ;
467467 }
468468
469+ assert (cur -> connection != NULL );
470+ assert (cur -> connection -> state != NULL );
471+
469472 if (cur -> closed ) {
470473 PyErr_SetString (cur -> connection -> state -> ProgrammingError ,
471474 "Cannot operate on a closed cursor." );
@@ -562,43 +565,40 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
562565 switch (paramtype ) {
563566 case TYPE_LONG : {
564567 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 );
569571 break ;
570572 }
571573 case TYPE_FLOAT : {
572574 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 );
579578 break ;
580579 }
581580 case TYPE_UNICODE :
582581 string = PyUnicode_AsUTF8AndSize (parameter , & buflen );
583- if (string == NULL )
584- return -1 ;
582+ if (string == NULL ) {
583+ return SQLITE_ERROR ;
584+ }
585585 if (buflen > INT_MAX ) {
586586 PyErr_SetString (PyExc_OverflowError ,
587587 "string longer than INT_MAX bytes" );
588- return -1 ;
588+ return SQLITE_ERROR ;
589589 }
590590 rc = sqlite3_bind_text (self -> st , pos , string , (int )buflen , SQLITE_TRANSIENT );
591591 break ;
592592 case TYPE_BUFFER : {
593593 Py_buffer view ;
594594 if (PyObject_GetBuffer (parameter , & view , PyBUF_SIMPLE ) != 0 ) {
595- return -1 ;
595+ return SQLITE_ERROR ;
596596 }
597597 if (view .len > INT_MAX ) {
598598 PyErr_SetString (PyExc_OverflowError ,
599599 "BLOB longer than INT_MAX bytes" );
600600 PyBuffer_Release (& view );
601- return -1 ;
601+ return SQLITE_ERROR ;
602602 }
603603 rc = sqlite3_bind_blob (self -> st , pos , view .buf , (int )view .len , SQLITE_TRANSIENT );
604604 PyBuffer_Release (& view );
@@ -608,7 +608,7 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
608608 PyErr_Format (state -> ProgrammingError ,
609609 "Error binding parameter %d: type '%s' is not supported" ,
610610 pos , Py_TYPE (parameter )-> tp_name );
611- rc = -1 ;
611+ rc = SQLITE_ERROR ;
612612 }
613613
614614final :
@@ -731,14 +731,17 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
731731 }
732732
733733 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 );
742745 return ;
743746 }
744747
0 commit comments