@@ -188,7 +188,7 @@ connection_exec_stmt(pysqlite_Connection *self, const char *sql)
188188    Py_END_ALLOW_THREADS 
189189
190190    if  (rc  !=  SQLITE_OK ) {
191-         ( void ) _pysqlite_seterror (self -> state , self -> db );
191+         set_error_from_db (self -> state , self -> db );
192192        return  -1 ;
193193    }
194194    return  0 ;
@@ -274,7 +274,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
274274
275275    pysqlite_state  * state  =  pysqlite_get_state_by_type (Py_TYPE (self ));
276276    if  (rc  !=  SQLITE_OK ) {
277-         _pysqlite_seterror (state , db );
277+         set_error_from_db (state , db );
278278        goto error ;
279279    }
280280
@@ -607,11 +607,11 @@ blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
607607    Py_END_ALLOW_THREADS 
608608
609609    if  (rc  ==  SQLITE_MISUSE ) {
610-         PyErr_Format (self -> state -> InterfaceError ,  sqlite3_errstr ( rc ) );
610+         set_error_from_code (self -> state ,  rc );
611611        return  NULL ;
612612    }
613613    else  if  (rc  !=  SQLITE_OK ) {
614-         _pysqlite_seterror (self -> state , self -> db );
614+         set_error_from_db (self -> state , self -> db );
615615        return  NULL ;
616616    }
617617
@@ -1307,6 +1307,12 @@ create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
13071307                        "SQLite 3.25.0 or higher" );
13081308        return  NULL ;
13091309    }
1310+     int  limit  =  sqlite3_limit (self -> db , SQLITE_LIMIT_FUNCTION_ARG , -1 );
1311+     if  (num_params  <  -1  ||  num_params  >  limit ) {
1312+         return  PyErr_Format (self -> ProgrammingError ,
1313+                             "'num_params' must be between -1 and %d, not %d" ,
1314+                             limit , num_params );
1315+     }
13101316
13111317    if  (!pysqlite_check_thread (self ) ||  !pysqlite_check_connection (self )) {
13121318        return  NULL ;
@@ -1333,9 +1339,9 @@ create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
13331339    }
13341340
13351341    if  (rc  !=  SQLITE_OK ) {
1336-         //  Errors are not set on the database connection, so we cannot  
1337-         // use _pysqlite_seterror(). 
1338-         PyErr_SetString (self -> ProgrammingError ,  sqlite3_errstr ( rc ) );
1342+         /*  Errors are not set on the database connection; use result code  
1343+          * instead. */  
1344+         set_error_from_code (self -> state ,  rc );
13391345        return  NULL ;
13401346    }
13411347    Py_RETURN_NONE ;
@@ -2090,7 +2096,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
20902096    Py_END_ALLOW_THREADS 
20912097
20922098    if  (bck_handle  ==  NULL) {
2093-         _pysqlite_seterror (self -> state , bck_conn );
2099+         set_error_from_db (self -> state , bck_conn );
20942100        return  NULL ;
20952101    }
20962102
@@ -2128,7 +2134,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
21282134    Py_END_ALLOW_THREADS 
21292135
21302136    if  (rc  !=  SQLITE_OK ) {
2131-         _pysqlite_seterror (self -> state , bck_conn );
2137+         set_error_from_db (self -> state , bck_conn );
21322138        return  NULL ;
21332139    }
21342140
@@ -2186,7 +2192,7 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
21862192        if  (callable  !=  Py_None ) {
21872193            free_callback_context (ctx );
21882194        }
2189-         _pysqlite_seterror (self -> state , self -> db );
2195+         set_error_from_db (self -> state , self -> db );
21902196        return  NULL ;
21912197    }
21922198
@@ -2420,7 +2426,7 @@ deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
24202426    Py_END_ALLOW_THREADS 
24212427
24222428    if  (rc  !=  SQLITE_OK ) {
2423-         ( void ) _pysqlite_seterror (self -> state , self -> db );
2429+         set_error_from_db (self -> state , self -> db );
24242430        return  NULL ;
24252431    }
24262432    Py_RETURN_NONE ;
@@ -2615,7 +2621,7 @@ setconfig_impl(pysqlite_Connection *self, int op, int enable)
26152621    int  actual ;
26162622    int  rc  =  sqlite3_db_config (self -> db , op , enable , & actual );
26172623    if  (rc  !=  SQLITE_OK ) {
2618-         ( void ) _pysqlite_seterror (self -> state , self -> db );
2624+         set_error_from_db (self -> state , self -> db );
26192625        return  NULL ;
26202626    }
26212627    if  (enable  !=  actual ) {
@@ -2650,7 +2656,7 @@ getconfig_impl(pysqlite_Connection *self, int op)
26502656    int  current ;
26512657    int  rc  =  sqlite3_db_config (self -> db , op , -1 , & current );
26522658    if  (rc  !=  SQLITE_OK ) {
2653-         ( void ) _pysqlite_seterror (self -> state , self -> db );
2659+         set_error_from_db (self -> state , self -> db );
26542660        return  -1 ;
26552661    }
26562662    return  current ;
0 commit comments