blob_seterror(pysqlite_Blob *self, int rc)
{
assert(self->connection != NULL);
- _pysqlite_seterror(self->connection->state, self->connection->db);
+ set_error_from_db(self->connection->state, self->connection->db);
}
static PyObject *
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
- (void)_pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return -1;
}
return 0;
pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(self));
if (rc != SQLITE_OK) {
- _pysqlite_seterror(state, db);
+ set_error_from_db(state, db);
goto error;
}
Py_END_ALLOW_THREADS
if (rc == SQLITE_MISUSE) {
- PyErr_Format(self->state->InterfaceError, sqlite3_errstr(rc));
+ set_error_from_code(self->state, rc);
return NULL;
}
else if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return NULL;
}
}
if (rc != SQLITE_OK) {
- // Errors are not set on the database connection, so we cannot
- // use _pysqlite_seterror().
- PyErr_SetString(self->ProgrammingError, sqlite3_errstr(rc));
+ /* Errors are not set on the database connection; use result code
+ * instead. */
+ set_error_from_code(self->state, rc);
return NULL;
}
Py_RETURN_NONE;
Py_END_ALLOW_THREADS
if (bck_handle == NULL) {
- _pysqlite_seterror(self->state, bck_conn);
+ set_error_from_db(self->state, bck_conn);
return NULL;
}
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->state, bck_conn);
+ set_error_from_db(self->state, bck_conn);
return NULL;
}
if (callable != Py_None) {
free_callback_context(ctx);
}
- _pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return NULL;
}
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
- (void)_pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return NULL;
}
Py_RETURN_NONE;
int actual;
int rc = sqlite3_db_config(self->db, op, enable, &actual);
if (rc != SQLITE_OK) {
- (void)_pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return NULL;
}
if (enable != actual) {
int current;
int rc = sqlite3_db_config(self->db, op, -1, ¤t);
if (rc != SQLITE_OK) {
- (void)_pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return -1;
}
return current;
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
- (void)_pysqlite_seterror(self->state, self->db);
+ set_error_from_db(self->state, self->db);
return -1;
}
if (rc != SQLITE_OK) {
PyObject *exc = PyErr_GetRaisedException();
sqlite3 *db = sqlite3_db_handle(self->st);
- _pysqlite_seterror(state, db);
+ set_error_from_db(state, db);
_PyErr_ChainExceptions1(exc);
return;
}
if (rc != SQLITE_OK) {
PyObject *exc = PyErr_GetRaisedException();
sqlite3 *db = sqlite3_db_handle(self->st);
- _pysqlite_seterror(state, db);
+ set_error_from_db(state, db);
_PyErr_ChainExceptions1(exc);
return;
}
PyErr_Clear();
}
}
- _pysqlite_seterror(state, self->connection->db);
+ set_error_from_db(state, self->connection->db);
goto error;
}
return Py_NewRef((PyObject *)self);
error:
- _pysqlite_seterror(self->connection->state, db);
+ set_error_from_db(self->connection->state, db);
return NULL;
}
Py_CLEAR(self->statement);
}
else if (rc != SQLITE_ROW) {
- (void)_pysqlite_seterror(self->connection->state,
- self->connection->db);
+ set_error_from_db(self->connection->state, self->connection->db);
(void)stmt_reset(self->statement);
Py_CLEAR(self->statement);
Py_DECREF(row);
Py_END_ALLOW_THREADS
if (rc != SQLITE_OK) {
- _pysqlite_seterror(state, db);
+ set_error_from_db(state, db);
return NULL;
}
Py_XDECREF(exc);
}
+void
+set_error_from_code(pysqlite_state *state, int code)
+{
+ PyObject *exc_class = get_exception_class(state, code);
+ if (exc_class == NULL) {
+ // No new exception need be raised.
+ return;
+ }
+
+ const char *errmsg = sqlite3_errstr(code);
+ assert(errmsg != NULL);
+ raise_exception(exc_class, code, errmsg);
+}
+
/**
* Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occurred).
*/
-int
-_pysqlite_seterror(pysqlite_state *state, sqlite3 *db)
+void
+set_error_from_db(pysqlite_state *state, sqlite3 *db)
{
int errorcode = sqlite3_errcode(db);
PyObject *exc_class = get_exception_class(state, errorcode);
if (exc_class == NULL) {
- // No new exception need be raised; just pass the error code
- return errorcode;
+ // No new exception need be raised.
+ return;
}
/* Create and set the exception. */
// sqlite3_errmsg() always returns an UTF-8 encoded message
const char *errmsg = sqlite3_errmsg(db);
raise_exception(exc_class, extended_errcode, errmsg);
- return extended_errcode;
}
#ifdef WORDS_BIGENDIAN
/**
* Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occurred).
*/
-int _pysqlite_seterror(pysqlite_state *state, sqlite3 *db);
+void set_error_from_db(pysqlite_state *state, sqlite3 *db);
+void set_error_from_code(pysqlite_state *state, int code);
sqlite_int64 _pysqlite_long_as_int64(PyObject * value);