File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -278,9 +278,15 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
278
278
converter = Py_None ;
279
279
}
280
280
281
+ /*
282
+ * Note, sqlite3_column_bytes() must come after sqlite3_column_blob()
283
+ * or sqlite3_column_text().
284
+ *
285
+ * See https://sqlite.org/c3ref/column_blob.html for details.
286
+ */
281
287
if (converter != Py_None ) {
282
- nbytes = sqlite3_column_bytes (self -> statement -> st , i );
283
288
val_str = (const char * )sqlite3_column_blob (self -> statement -> st , i );
289
+ nbytes = sqlite3_column_bytes (self -> statement -> st , i );
284
290
if (!val_str ) {
285
291
converted = Py_NewRef (Py_None );
286
292
} else {
@@ -330,9 +336,13 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
330
336
}
331
337
} else {
332
338
/* coltype == SQLITE_BLOB */
333
- nbytes = sqlite3_column_bytes (self -> statement -> st , i );
334
- converted = PyBytes_FromStringAndSize (
335
- sqlite3_column_blob (self -> statement -> st , i ), nbytes );
339
+ const char * blob = sqlite3_column_blob (self -> statement -> st , i );
340
+ if (!blob ) {
341
+ converted = Py_NewRef (Py_None );
342
+ } else {
343
+ nbytes = sqlite3_column_bytes (self -> statement -> st , i );
344
+ converted = PyBytes_FromStringAndSize (blob , nbytes );
345
+ }
336
346
}
337
347
}
338
348
You can’t perform that action at this time.
0 commit comments