Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 4 Lib/sqlite3/test/userfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def test_any_arguments(self):
val = cur.fetchone()[0]
self.assertEqual(val, 2)

def test_empty_blob(self):
cur = self.con.execute("select isblob(x'')")
self.assertTrue(cur.fetchone()[0])

# Regarding deterministic functions:
#
# Between 3.8.3 and 3.15.0, deterministic functions were only used to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improve :mod:`sqlite3` error handling: ``sqlite3_value_blob()`` errors that
set ``SQLITE_NOMEM`` now raise :exc:`MemoryError`. Patch by Erlend E.
Aasland.
24 changes: 17 additions & 7 deletions 24 Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc,
sqlite3_value* cur_value;
PyObject* cur_py_value;
const char* val_str;
Py_ssize_t buflen;

args = PyTuple_New(argc);
if (!args) {
Expand All @@ -571,26 +570,37 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc,
cur_py_value = Py_NewRef(Py_None);
}
break;
case SQLITE_BLOB:
buflen = sqlite3_value_bytes(cur_value);
cur_py_value = PyBytes_FromStringAndSize(
sqlite3_value_blob(cur_value), buflen);
case SQLITE_BLOB: {
sqlite3 *db = sqlite3_context_db_handle(context);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it may make sense to see what other core devs think about declaring new variables inside case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's plenty of other such cases in the code base: grep -A1 -rE "\<case\>.*:.*{" Modules

const void *blob = sqlite3_value_blob(cur_value);

if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
PyErr_NoMemory();
goto error;
}

Py_ssize_t size = sqlite3_value_bytes(cur_value);
cur_py_value = PyBytes_FromStringAndSize(blob, size);
break;
}
case SQLITE_NULL:
default:
cur_py_value = Py_NewRef(Py_None);
}

if (!cur_py_value) {
Py_DECREF(args);
return NULL;
goto error;
}

PyTuple_SetItem(args, i, cur_py_value);

}

return args;

error:
Py_DECREF(args);
return NULL;
}

static void
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.