Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:10:00+00:00 2026-05-31T22:10:00+00:00

I am having issues with the following code which loads an SQLite database. –

  • 0

I am having issues with the following code which loads an SQLite database.

- (NSArray *)getDatabase {

NSLog(@"Get Database Called");

    NSMutableArray *retval = [[[NSMutableArray alloc] init] autorelease];
    NSString *query = @"SELECT Description, UniqueID, HexCoords, NoHexCoords, NoAnnots, AnnotText, DescriptionFormatting, HexCoordsPortrait FROM MainTable";
    sqlite3_stmt *statement;
    if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil) 
        == SQLITE_OK) {
        while (sqlite3_step(statement) == SQLITE_ROW) {

            char *nameChars = (char *) sqlite3_column_text(statement, 0);
            char *desChars = (char *) sqlite3_column_text(statement, 1);
            int uniqueID = sqlite3_column_int(statement, 2);

From using breakpoints I can see that the problem is with the if statement and that the code never gets past this if statement. Can anyone spot what might be wrong ? The code was working a few months ago and I have recently upgraded to xCode 4.3 so might this be the problem ?

Thank in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:10:01+00:00Added an answer on May 31, 2026 at 10:10 pm

    Yeah i agree With Joachim. there is a problem sometimes the DB doesnot really connect. what i do is a couple of things. First i add following Code in my Application App Delegate.

    - (void) copyDatabaseIfNeeded {
    
        //Using NSFileManager we can perform many file system operations.
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSString *dbPath = [self getDBPath];
        BOOL success = [fileManager fileExistsAtPath:dbPath]; 
    
        if(success) {
    
            NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MyDB.sqlite"];
            success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
    
            if (!success) 
                NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
        }   
    }
    

    Call This Function in ApplicationDidFinishLaunching.

    Now remove the data base that is in ur bundle currently. (MAKE SURE U HAD BACKUP OF IT). And (if Possible Delete All the project From Iphone Simulator Folder) Coz sometimes the previous Database is attached.
    Clean Your project, Add the Data Base in ur bundle. Compile it..

    Let Me know if it worked

    the Get Path Function

    - (NSString *) getDBPath {
            //Search for standard documents using NSSearchPathForDirectoriesInDomains
            //First Param = Searching the documents directory
            //Second Param = Searching the Users directory and not the System
            //Expand any tildes and identify home directories.
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
            NSString *documentsDir = [paths objectAtIndex:0];
            return [documentsDir stringByAppendingPathComponent:@"MYDB.sqlite"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having the following code which is spitting 'Root Element Missing' during doc.Load() .
I have the following code, which loops to get all images in a table
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
I'm having an issue with rails involving javascript. Basically, I have the following code:
I believe I am having a memory issue using numpy arrays. The following code
Ok. I'm having an issue with the following bit of code: StreamReader arrComputer =
Hi I am having issues with the following and it crashes the iPhone simulator,
Following on from my earlier question , I am still having issues with loading
I am trying to run an existing python code, and having issues with it.
This seems like a simple problem, but somehow I'm having issues with this code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.