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

  • SEARCH
  • Home
  • 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 8965293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:46:33+00:00 2026-06-15T16:46:33+00:00

I am really new in ios development. What I try to do now is

  • 0

I am really new in ios development. What I try to do now is open an existing sqlite database and select data from there. I debug my source and see that I open the database success (I think I success since the *database pointer is not nil). but when I use sqlite3_prepare_v2() to initialize the select query, I always receive the error: “No such table People”. I have checked at the path:

~/Library/Application Support/iphone simulator/6.0/Application//.

The database was copied successful, I can open it a see the data there.

Here is my code to copy the database and open it:

- (NSString*) getDatabasePath{
    //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:@"data.sqlite"];
}

- (void)copyDatabaseToDocument {
    //Using NSFileManager we can perform many file system operations.
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSString *dbPath = [self getDatabasePath];
    BOOL success = [fileManager fileExistsAtPath:dbPath];

    if(!success) {

        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"data.sqlite"];
        success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];

        if (!success)
            NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

- (sqlite3*)openDatabaseConnection {
    sqlite3 *database;
    NSString * path = [self getDatabasePath];

    if (sqlite3_open([path UTF8String], &database) != SQLITE_OK) {
        sqlite3_close(database);
        NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    }
    return database;
}

And here is my code to select data. The error occurs at line: sqlite3_prepare_v2(database, query, -1, &selectStatement, NULL)

- (People*) getPeople{
    sqlite3 *database = [[[DBConnector alloc] init] openDatabaseConnection];
    if(database == nil)
        return nil;
    sqlite3_stmt *selectStatement;
    NSString *rawquery      = @"select * from people";
    const char *query       = [rawquery UTF8String];
    NSMutableArray* result = [[NSMutableArray alloc] init];

    if (sqlite3_prepare_v2(database, query, -1, &selectStatement, NULL) == SQLITE_OK) {
        while (sqlite3_step(selectStatement) == SQLITE_ROW) {

            //Parse the data by calling a private method:
            People *people = [self parsePeopleWithStatement:selectStatement];

            [result addObject:people];
        }
    }else{
        NSAssert1(0, @"Error: '%s'.", sqlite3_errmsg(database));
    }
    sqlite3_finalize(selectStatement);
    return result;

}

Please tell me if you know what the mistake I have.

Thanks.

  • 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-06-15T16:46:34+00:00Added an answer on June 15, 2026 at 4:46 pm

    I have resolved the problem by myself. When I debug the app, I see that It didn’t call applicationDidFinishLaunching method, It calls applicationDidFinishLaunchingWithOptions method. I just place the code to call the copyDatabaseToDocument at the applicationDidFinishLaunchingWithOptions method and It works.
    Here is the code of my Delegate class:

    //THIS METHOD WAS NOT CALLED
    - (void)applicationDidFinishLaunching:(UIApplication *)application{
        DBConnector *connector = [[DBConnector alloc] init];
        [connector copyDatabaseToDocument];
    }
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
           self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
           //SHOW MY SCREEN
            (...)
    
           self.window.backgroundColor = [UIColor whiteColor];
           [self.window makeKeyAndVisible];
           return YES;
    }
    

    By the way, I think this is not a real answer sync I don’t know why my App didn’t start at the applicationDidFinishLaunching(). If you know, please give me a description.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really new to iOS development, and I'm looking for docs on it. However,
I'm really new to iOS development and I'm trying to create a simple table
I'm really to new to iOS development. I've read through a couple of beginners
I'm pretty new to iOS development, and I want to figure out if there's
Obviously, I'm new to iOS development, but I could really use somebody's help. I
First off, I am completely new to iOS development, so I hope there is
The new iOS websocket library, SocketRocket , looks really awesome, and the chat example
I'm new to iOS development and I have being able to solve most of
I'm working with the new UIDocument features in iOS 5.0. I have an existing
i am new to iOS development i am working on an app which is

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.