【问题标题】:How can I insert many blobs with sqlite3 C API?如何使用 sqlite3 C API 插入许多 blob?
【发布时间】:2013-06-02 15:56:46
【问题描述】:

这是我正在使用的表的架构

CREATE TABLE clauses(id INTEGER PRIMARY KEY, content BLOB)

我想在该表中插入大量记录。我在想类似的东西

void insert_records(sqlite3* db) {
    int clause[CLAUSE_SIZE];
    char sql[] = "INSERT INTO clauses(content) VALUES(?)";
    sqlite3_stmt* stmt = NULL;

    if (sqlite3_prepare(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
        fprintf(stderr, "error in prepare : %s\n", sqlite3_errmsg(db));
        exit(1);
    }

    if (sqlite3_bind_blob(stmt, 1, clause, sizeof(clause), SQLITE_STATIC) != SQLITE_OK) {
        fprintf(stderr, "error in bind : %s\n", sqlite3_errmsg(db));
        exit(1);
    }

    for (int i = 0 ; i < nb_clauses ; i++) {
       gen_clause(clause);

       if (sqlite3_step(stmt) != SQLITE_DONE) {
           fprintf(stderr, "error in step : %s\n", sqlite3_errmsg(db));
           exit(1);
       }
    }

    sqlite3_finalize(stmt);
 }

但这不起作用:只插入第一项,并且在第二次迭代中,程序因“步骤错误:未知错误”而死。

有什么问题?

【问题讨论】:

    标签: c sqlite blob


    【解决方案1】:

    您必须先调用sqlite3_reset,然后才能重新执行准备好的语句。

    【讨论】:

      猜你喜欢
      • 2013-07-09
      • 2010-12-10
      • 2010-09-29
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 2017-03-10
      • 2015-08-06
      相关资源
      最近更新 更多