I am trying to open a sqlite db in the viewDidLoad routine and trying to send a sql query through to the db, but the sqlite_step() fails every time. I am not sure what\'s wrong
Have you verified that the statement compiles OK? You have the success = sqlite3_prepare_v2(...);
line, but never do anything if success
is not SQLITE_OK
. Have you verified that it is SQLITE_OK
?
On the other hand, if you were to use a wrapper like FMDB, you could replace all of your code above with:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *dbname = @"name.sqlite";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:dbname];
FMDatabase * database = [FMDatabase databaseWithPath:path];
[database executeUpdate:@"insert into name(nid, name) values(?, ?)", [NSNumber numberWithInt:6], @"testname"];
[database close];
}
This, IMO, is much easier to debug.