• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cant read second table from same sqlite database iphone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Sun, 11 Apr 2010 11:37:41 -0700

I'm afraid I can't be much more help if you don't have the return codes from each of the SQLite statements.  I do note in the second method, you're asking for column values out of order, which is pretty unusual.

- Ben

On Apr 10, 2010, at 6:42 PM, charisse napeÿfffff1as wrote:

> I was able to successfully retrieve data on the first table. But I can't seem to retrieve from the second table. I know it has data inside it because I used an SQLite Browser to view the data. I also tried performing queries there and it worked fine. Only when I used the queries in the code that it doesn't work.
>
> Below is the code writing the database in the Users/Documents folder for Iphone
>
> - (void) createDatabaseIfNeeded
> {
>     NSError * error;
>
>     //gets access to the file system
>     NSFileManager * fileManager = [NSFileManager defaultManager];
>
>     // gets the complete users document directory path
>     NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
>
>     // gets the first path in the array
>     NSString * documentsDirectory = [paths objectAtIndex:0];
>
>     // create the complete path for the database file
>     NSString * databasePath = [documentsDirectory stringByAppendingString:@"/Database.sql"];
>
>     DebugLog("databasePath = %s\n",[databasePath UTF8String]);
>
>     // check if file exists or not
>     BOOL success = [fileManager fileExistsAtPath:databasePath];
>
>     if (success) return;
>
>     // the database does not exist so copy it in the users documents directory
>     NSString * dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/Database.sql"];
>
>     DebugLog("dbpath is %s\n",[dbPath UTF8String]);
>
>     //copy the database file to ther users docuement directory
>
>     success = [fileManager copyItemAtPath:dbPath toPath:databasePath error:&error];
>
>     if (!success)
>         NSAssert(0,@"Failed to copy Database!\n");
> }
>
>
> From: Ben Trumbull <email@hidden>
> To: email@hidden
> Cc: Cocoa dev <email@hidden>
> Sent: Sunday, April 11, 2010 9:27:46
> Subject: re: Cant read second table from same sqlite database iphone
>
> > 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
>
>
>
>
> New Email names for you!
> Get the Email name you've always wanted on the new @ymail and @rocketmail.
> Hurry before someone else does!


- 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

References: 
 >re: Cant read second table from same sqlite database iphone (From: Ben Trumbull <email@hidden>)
 >Re: Cant read second table from same sqlite database iphone (From: charisse napeÿfffff1as <email@hidden>)

  • Prev by Date: Re: Cocoa scripting support - background helper app
  • Next by Date: Re: nstableview in drawer resetting custom cursor
  • Previous by thread: Re: Cant read second table from same sqlite database iphone
  • Next by thread: QCRenderer.... how do you do that?
  • Index(es):
    • Date
    • Thread