I try to use sqlite on iPhone. But I have the following problem:
NSData * image = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:image_url]];
NSString * query = @"INSERT INTO PHOTOS( image_url, image ) VALUES (?, ?)";
NSInteger result = -1;
sqlite3_stmt * pStm;
do {
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &pStm, NULL) == SQLITE_OK) {
sqlite3_bind_text(pStm, 1, [image_url UTF8String], -1, SQLITE_STATIC);
int err = sqlite3_bind_blob(pStm, 2, [image bytes], [image length], NULL);
if (sqlite3_step(pStm) != SQLITE_ROW) {
NSString * strerr = [NSString stringWithCString:sqlite3_errmsg(database)];
NSLog(@"%@", strerr);
}
else {
result = sqlite3_column_int(pStm, 1);
}
}
else {
NSAssert(0, @"Error while prepare");
}
} while (sqlite3_finalize(pStm) == SQLITE_SCHEMA);
When executed, this code function sqlite3_step returns an error SQLITE_ERROR with description "Unknown error" . Did anybody have same problem and maybe somebody solved it?