如何将多个blob参数传递给SQLite语句?

时间:2015-11-13 23:53:53

标签: visual-c++ sqlite

此代码在第二个sqlite3_bind_blob上抛出异常:

sqlite3_stmt* _stmt;
char *sql = sqlite3_mprintf("update logins set password_value=?, possible_usernames=?, form_data=? "
    "where origin_url='%q' and username_element='%q' and username_value='%q' and password_element='%q' and signon_realm='%q'",
    sqlite3_column_text(stmt, 0), sqlite3_column_text(stmt, 1), sqlite3_column_text(stmt, 2), sqlite3_column_text(stmt, 3), sqlite3_column_text(stmt, 4));
sqlite3_prepare(db, sql, -1, &_stmt, 0);
sqlite3_bind_blob(_stmt, 1, DataOut5.pbData, DataOut5.cbData, SQLITE_STATIC);
sqlite3_bind_blob(_stmt, 2, DataOut6.pbData, DataOut6.cbData, SQLITE_STATIC);
sqlite3_bind_blob(_stmt, 3, DataOut7.pbData, DataOut7.cbData, SQLITE_STATIC);
sqlite3_step(_stmt);
sqlite3_finalize(_stmt);
sqlite3_free(sql);

此代码成功完成:

sqlite3_stmt* _stmt;
char *sql = sqlite3_mprintf("update logins set password_value=? "//, possible_usernames=?, form_data=? "
    "where origin_url='%q' and username_element='%q' and username_value='%q' and password_element='%q' and signon_realm='%q'",
    sqlite3_column_text(stmt, 0), sqlite3_column_text(stmt, 1), sqlite3_column_text(stmt, 2), sqlite3_column_text(stmt, 3), sqlite3_column_text(stmt, 4));
sqlite3_prepare(db, sql, -1, &_stmt, 0);
sqlite3_bind_blob(_stmt, 1, DataOut5.pbData, DataOut5.cbData, SQLITE_STATIC);
//sqlite3_bind_blob(_stmt, 2, DataOut6.pbData, DataOut6.cbData, SQLITE_STATIC);
//sqlite3_bind_blob(_stmt, 3, DataOut7.pbData, DataOut7.cbData, SQLITE_STATIC);
sqlite3_step(_stmt);
sqlite3_finalize(_stmt);
sqlite3_free(sql);

为什么?

0 个答案:

没有答案