c - insert blob into sqlite 3 with C
问题描述
So I'm trying to save onto a database a blob but it doesn't insert anything. I checked the return errors and I always get "error 0: not an error"
I'm using the sqlite3.org example for blob management: https://www.sqlite.org/cvstrac/wiki?p=BlobExample
Anyway here is the exact code, maybe I'm forgetting something.
int Database::insertToDatabase(
const int zKey, /*Id of row */
const unsigned char *zBlob, /* Pointer to blob of data */
int nBlob, /* Length of data pointed to by zBlob */
){
char zSql[kMaxSqlFunctionSize];
snprintf(zSql, kMaxSqlFunctionSize, "INSERT INTO RECTS(ID,DATA)VALUES(%d,?)",zKey);
sqlite3_stmt *pStmt;
int rc;
do {
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, NULL);
if( rc!=SQLITE_OK ){
return rc;
}
sqlite3_bind_blob(pStmt, 1, zBlob, nBlob, SQLITE_STATIC);
rc = sqlite3_step(pStmt);
assert( rc!=SQLITE_ROW );
rc = sqlite3_finalize(pStmt);
} while( rc==SQLITE_SCHEMA );
return rc;
}
I use sqlite_open_v2 to open the database and the tables are created correctly (checked with sqlite studio), but idk why I can't get this insert to work. (the data I'm trying to insert isn't more than 1k). Thanks in advance.
解决方案
推荐阅读
- django - psycopg2.errors.InvalidTextRepresentation 用于 Django 迁移到 PositiveSmallIntegerField
- javascript - 我在 discord.js v12.5.3 静音命令上收到错误
- cassandra - 提示文件夹中存在 Cassandra 旧提示文件
- javascript - 防止滚动处理程序不必要地触发
- scala - 如何在 Scala 中过滤地图列表
- next.js - Next.js 静态站点生成自定义文件路径
- javascript - 调用API时如何访问数组中对象的空间属性?
- r - 如何选择使用 GLM 在 R 中创建模型要省略的因子水平
- python - django/wagtail - 当管理面板另有说明时,对象属性显示无?
- javascript - 如何拆分具有多个元素的数组以获取 JavaScript 中的最后一项?