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
sqlite3_value* cur_value;
PyObject* cur_py_value;
const char* val_str;
- Py_ssize_t buflen;
args = PyTuple_New(argc);
if (!args) {
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);
+ 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