Have sqlite3_blob_bytes() return 0 following a failed call to sqlite3_reopen_blob().
FossilOrigin-Name: 476a8b492124d31e0656e61a6183ab55684c0bdf
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 5b67b7a..240a3ba 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -4835,7 +4835,8 @@
** SQLite error code is returned and the blob handle is considered aborted.
** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
-** SQLITE_ABORT.
+** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
+** always returns zero.
**
** ^This function sets the database handle error code and message.
*/
diff --git a/src/vdbeblob.c b/src/vdbeblob.c
index f43fc64..f26cc87 100644
--- a/src/vdbeblob.c
+++ b/src/vdbeblob.c
@@ -419,7 +419,7 @@
*/
int sqlite3_blob_bytes(sqlite3_blob *pBlob){
Incrblob *p = (Incrblob *)pBlob;
- return p ? p->nByte : 0;
+ return (p && p->pStmt) ? p->nByte : 0;
}
/*
@@ -457,6 +457,7 @@
}
rc = sqlite3ApiExit(db, rc);
+ assert( rc==SQLITE_OK || p->pStmt==0 );
sqlite3_mutex_leave(db->mutex);
return rc;
}