SQLite - library routine called out of sequence

832 views
Skip to first unread message

Bob

unread,
Feb 9, 2009, 11:36:19 PM2/9/09
to iPhone SDK Development
Im getting this error 'Failed to prepare DB - library routine called
out of sequence' when I run the following code. I know the open works
just fine and the only other thought
I had was that the query was bad, but if I open sqlite3 on my own on
that db file
the query works just fine. Any ideas? Thanks

char *errMsg;
int res = sqlite3_open([[self dataFilePath] UTF8String], &database);
if (res != SQLITE_OK)
{
sqlite3_close(database);
NSLog(@"Failed to open database - %s", errMsg);
NSAssert(0, @"FAILED to open database");
}

NSString *query = @"SELECT * FROM mytable";
sqlite3_stmt *statement;

if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement,
nil) != SQLITE_OK)
{
sqlite3_close(database);
NSLog(@"Failed to prepare DB - %s", sqlite3_errmsg(database));
NSAssert(0, @"FAILED to prepare database");
}


Bob

unread,
Feb 10, 2009, 7:03:08 PM2/10/09
to iPhone SDK Development
Ok I found the issue(s). The first was that I did a close on the
database
before I got the error, which gave me the wrong error message. Once
that
was fixed, it said 'no such table <tablename>'. Turns out it will say
that
if it cant find the database to open, which to me seems dumb, it
should
bail on the open call, NOT later.
Reply all
Reply to author
Forward
0 new messages