描述
在SQL语句文本输入到sqlite3_prepare_v2及其变体中,文字可能会被匹配以下模板之一的参数所替代:
?
?NNN
:VVV
@VVV
$VVV
在上面的模板中,NNN表示一个整数,VVV表示一个字母数字标识符。这些参数(也称为“主机参数名称”或“SQL参数”)的值可以使用sqlite3_bind_*函数设置。
C / C ++语法
nt sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
PB语法
FUNCTION sqlite3_bind_zeroblob ( _ BYVAL hStmt AS DWORD, _ BYVAL idx AS LONG, _ BYVAL numBytes AS LONG _ ) AS LONG |
参数
pStmt
[in]语句句柄。
idx
[in]要设置的SQL参数的索引。最左边的SQL参数的索引为1。当使用相同的命名SQL参数多次,第二次和后续出现与第一次出现相同的索引。如果需要,可以使用sqlite3_bind_parameter_indexAPI查询命名参数的索引。“?NNN”参数的索引是NNN的值。NNN值必须介于1和sqlite3_limit参数SQLITE_LIMIT_VARIABLE_NUMBER之间(默认值:999)。
numBytes
[in]字节数。
返回值
SQLITE_OK成功或错误代码如果出现问题。如果参数索引超出范围,则返回SQLITE_RANGE。如果的malloc失败,则返回SQLITE_NOMEM。
备注
sqlite3_bind_zeroblob函数绑定一个长度为的numBytessv的BLOB,填充为零。在处理它时,zeroblob使用固定量的内存(只是一个整数来保持其大小)。Zeroblob旨在作为BLOB的占位符,BLOB的内容随后使用增量BLOB I / O功能编写。zeroblob的负值导致零长度的BLOB。
sqlite3_reset功能不会清除绑定。Unbound参数被解释为NULL。
C ++实现代码
/*
** Bind a text or BLOB value.
*/
static int bindText(
sqlite3_stmt *pStmt, /* The statement to bind against */
int i, /* Index of the parameter to bind */
const void *zData, /* Pointer to the data to be bound */
int nData, /* Number of bytes of data to be bound */
void (*xDel)(void*), /* Destructor for the data */
u8 encoding /* Encoding for the data */
){
Vdbe *p = (Vdbe *)pStmt;
Mem *pVar;
int rc;
rc = vdbeUnbind(p, i);
if( rc==SQLITE_OK ){
if( zData!=0 ){
pVar = &p->aVar[i-1];
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
if( rc==SQLITE_OK && encoding!=0 ){
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
}
sqlite3Error(p->db, rc, 0);
rc = sqlite3ApiExit(p->db, rc);
}
sqlite3_mutex_leave(p->db->mutex);
}else if( xDel!=SQLITE_STATIC && xDel!=SQLITE_TRANSIENT ){
xDel((void*)zData);
}
return rc;
}
/*
** Bind a blob value to an SQL statement variable.
*/
SQLITE_API int sqlite3_bind_blob(
sqlite3_stmt *pStmt,
int i,
const void *zData,
int nData,
void (*xDel)(void*)
){
return bindText(pStmt, i, zData, nData, xDel, 0);
}