描述
此函数用于将数据从打开的BLOB句柄读入调用者提供的缓冲区。的numBytessv从打开的BLOB将数据字节复制到缓冲区szBuffer中,从偏移量n偏移开始。
C / C ++语法
int sqlite3_blob_read( sqlite3_blob *, void *Z, int N, int iOffset ); |
PB语法
FUNCTION sqlite3_blob_read ( _ BYVAL pBlob AS DWORD, BYREF szBuffer AS ANY, _ BYVAL numBytes AS LONG, _ BYVAL nOffset AS LONG _ ) AS LONG |
参数
pBlob
[in]blob句柄。
szBuffer
[in]缓冲区。
numBytes
[in]缓冲区的大小(以字节为单位)。
nOffset
[in]起始位置。如果偏移量n偏移从BLOB结尾小于的numBytessv个字节,则返回SQLITE_ERROR,不会读取数据。如果的numBytessv或n偏移小于零,则返回SQLITE_ERROR,而不会读取任何数据。可以使用sqlite3_blob_bytes函数确定blob的大小(从而numBytes + nOffset的最大值)。
返回值
SQLITE_OK成功;否则返回错误代码或扩展错误代码。
从过期的BLOB句柄中读取的尝试失败,并显示SQLITE_ABORT的错误代码。
备注
此函数仅适用于先前成功调用sqlite3_blob_open而尚未由sqlite3_blob_close关闭的BLOB句柄。将任何其他指针传递到此函数会导致未定义且可能不受欢迎的行为。
C ++实现代码
/*
** Perform a read or write operation on a blob
*/
static int blobReadWrite(
sqlite3_blob *pBlob,
void *z,
int n,
int iOffset,
int (*xCall)(BtCursor*, u32, u32, void*)
){
int rc;
Incrblob *p = (Incrblob *)pBlob;
Vdbe *v;
sqlite3 *db;
if( p==0 ) return SQLITE_MISUSE_BKPT;
db = p->db;
sqlite3_mutex_enter(db->mutex);
v = (Vdbe*)p->pStmt;
if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
/* Request is out of range. Return a transient error. */
rc = SQLITE_ERROR;
sqlite3Error(db, SQLITE_ERROR, 0);
}else if( v==0 ){
/* If there is no statement handle, then the blob-handle has
** already been invalidated. Return SQLITE_ABORT in this case.
*/
rc = SQLITE_ABORT;
}else{
/* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
** returned, clean-up the statement handle.
*/
assert( db == v->db );
sqlite3BtreeEnterCursor(p->pCsr);
rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
sqlite3BtreeLeaveCursor(p->pCsr);
if( rc==SQLITE_ABORT ){
sqlite3VdbeFinalize(v);
p->pStmt = 0;
}else{
db->errCode = rc;
v->rc = rc;
}
}
rc = sqlite3ApiExit(db, rc);
sqlite3_mutex_leave(db->mutex);
return rc;
}
/*
** Read data from a blob handle.
*/
SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
}