Reputation: 378
I have an SQLite-based app that works fine on Windows, Android and Java. I am trying to port it to iOS: the device is running iOS 9.3.1.
Everything else works apart from the blob write, which fails on the sqlite_step call with an "unknown error". The code is based on this SE post.
This is a stripped-down version of the low-level SQLite interface: the query comes from the next level up.
NSLog (@"Preparing query {%s}", query);
rc = sqlite3_prepare_v2 (hdb, query, -1, &stmt, &tail);
if (rc == SQLITE_OK) {
NSLog (@"Binding blob: size= %d", (int)[blob length]);
rc = sqlite3_bind_blob (stmt, 1, [blob bytes], (int) [blob length], SQLITE_STATIC);
if (rc == SQLITE_OK) {
rc = sqlite3_step (stmt);
if (rc != SQLITE_OK)
[self sql_error: @"sqlDo" line: __LINE__];
}
if (sqlite3_finalize (stmt) != SQLITE_OK)
[self sql_error: @"sqlEndQuery" line: __LINE__];
}
This is the NSLog output:
Preparing query {INSERT OR REPLACE INTO xxx VALUES (18356, '', ?)}
Binding blob: size= 5388
SQL error at line 157 in sqlDo: query:{INSERT OR REPLACE INTO xxx VALUES (18356, '', ?)} message:{unknown error}
Upvotes: 1
Views: 151
Reputation: 437432
After performing a sqlite3_step
of an INSERT
statement, the result is SQLITE_DONE
, not SQLITE_OK
.
So, you want:
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE)
[self sql_error: @"sqlDo" line: __LINE__];
Upvotes: 1