re: Cant read second table from same sqlite database iphone
re: Cant read second table from same sqlite database iphone
- Subject: re: Cant read second table from same sqlite database iphone
- From: Ben Trumbull <email@hidden>
- Date: Sat, 10 Apr 2010 18:27:46 -0700
> Hello All,
>
> I am having trouble reading the second table from my database because it returns nothing even if there is data inside it.
How do you know it has data inside it ? A common mistake is to try to write to databases in the read only part of an application's sandbox on the iphone. Where in the sandbox is the database ?
> - (NSMutableArray*) getProvinces
> {
> NSMutableArray * data = [[NSMutableArray alloc] init];
> const char * sql = "SELECT * FROM Provinces";
> sqlite3_stmt * statement;
>
> //prepare the select statement
> int returnValue = sqlite3_prepare_v2(mDatabase, sql, -1, &statement, NULL);
>
> DebugLog("return value = %d\n",returnValue);
>
> if (returnValue == SQLITE_OK)
> {
> //sqlite3_bind_int(statement, 1, regionID);
> //loop all the rows returned by the query
> while (sqlite3_step(statement) == SQLITE_ROW)
> {
You don't check the return codes here properly. sqlite3_prepare_v2() can return SQLITE_BUSY, or SQLITE_SCHEMA, or SQLITE_MISUSE. More importantly, you don't check if sqlite3_step() returns SQLITE_DONE which would indicate that you have 0 rows in this table.
- Ben
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden