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 6795877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:23:58+00:00 2026-05-26T18:23:58+00:00

I am developing an iPad application. I have an SQLite database in my resource

  • 0

I am developing an iPad application.
I have an SQLite database in my resource folder.
When my application launches, these codes will copy the database to my NSDocumentDirectory.

- (void) copyDatabaseIfNeeded {
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSError *error;
  NSString *dbPath = [self getDBPath];
  BOOL success = [fileManager fileExistsAtPath:dbPath];

  if(!success) {

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

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

- (NSString *) getDBPath {
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
  NSString *documentsDir = [paths objectAtIndex:0];
  return [documentsDir stringByAppendingPathComponent:@"Mydata.sqlite"];
}

In another view of my application, i have these codes to open the database and retrieve some values.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
if(sqlite3_open([[documentsDir stringByAppendingPathComponent:@"Mydata.sqlite"] UTF8String], &db) != SQLITE_OK){
    sqlite3_close(db);
    NSAssert(0, @"Failed to open database.");
}
NSString *sql = [[NSString alloc] initWithFormat:@"SELECT HOMEONE, HOMETWO, HOMETHREE, HOMEFOUR FROM STUDENTS WHERE NAME='%@'",Name];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)== SQLITE_OK)
{
    while(sqlite3_step(statement) == SQLITE_ROW){
        char *one = (char *) sqlite3_column_text(statement,0);
        ActionOne = [[NSString alloc] initWithUTF8String:one];
        char *two = (char *) sqlite3_column_text(statement,1);
        ActionTwo = [[NSString alloc] initWithUTF8String:two];
        char *three = (char *) sqlite3_column_text(statement,2);
        ActionThree = [[NSString alloc] initWithUTF8String:three];
        char *four = (char *) sqlite3_column_text(statement,3);
        ActionFour = [[NSString alloc] initWithUTF8String:four];
    }
    sqlite3_finalize(statement);
}

Yes, with these codes, i’m able to retrieve the values from the database.
But now i need to retrieve more values so i edited my codes.

NSString *sql = [[NSString alloc] initWithFormat:@"SELECT HOMEONE, HOMETWO, HOMETHREE, HOMEFOUR, VOICEONE, VOICETWO, VOICETHREE, VOICEFOUR FROM STUDENTS WHERE NAME='%@'",Name];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)== SQLITE_OK)
{
    while(sqlite3_step(statement) == SQLITE_ROW){
        char *one = (char *) sqlite3_column_text(statement,0);
        ActionOne = [[NSString alloc] initWithUTF8String:one];
        char *two = (char *) sqlite3_column_text(statement,1);
        ActionTwo = [[NSString alloc] initWithUTF8String:two];
        char *three = (char *) sqlite3_column_text(statement,2);
        ActionThree = [[NSString alloc] initWithUTF8String:three];
        char *four = (char *) sqlite3_column_text(statement,3);
        ActionFour = [[NSString alloc] initWithUTF8String:four];

        char *vone = (char *) sqlite3_column_text(statement,4);
        VoiceOne = [[NSString alloc] initWithUTF8String:vone];
        char *vtwo = (char *) sqlite3_column_text(statement,5);
        VoiceTwo = [[NSString alloc] initWithUTF8String:vtwo];
        char *vthree = (char *) sqlite3_column_text(statement,6);
        VoiceThree = [[NSString alloc] initWithUTF8String:vthree];
        char *vfour = (char *) sqlite3_column_text(statement,7);
        VoiceFour = [[NSString alloc] initWithUTF8String:vfour];
    }
    sqlite3_finalize(statement);
}

Now it doesn’t even retrieve the HOMEONE, HOMETWO, HOMETHREE, HOMEFOUR values.
I tried changing my SQL statement to retrieve just the VOICEONE, VOICETWO, VOICETHREE, VOICEFOUR values, it also doesn’t give me any values.

I did some checking and found out that the application didn’t even step into this line:

    if(sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil)== SQLITE_OK)

Which means the sqlite3_prepare_v2 isn’t successful?
I have checked the database field types.
I tried executing the SQL statement in ‘SQLite Database Browser’, and it was able to return the values.

May i know what is the problem with my codes?

  • 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-26T18:23:58+00:00Added an answer on May 26, 2026 at 6:23 pm

    This problem may occur because you may changed your database and copy the new one and forgot to remove app from simulator or device and trying to run the project. What i suggest if you are running it in simulator then plz copy the database path and open it in SQLite Database Browser from this path and try to run your sql statement here and you will find that its not running also here. Please delete app from simulator or device if you copy new database into project.

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

Sidebar

Related Questions

I'm developing this application on an iPad. These codes for a 'Browse' button allows
I am a developing an iPad application in which i have to use CTRunDelegate
I'm developing an iPad application. I have been provided with a PNG image that
i'm developing an application for iPad. I have a mapview with several annotations. I
I am developing for iPad and have created a standard UISplitViewController application using the
I have a PhoneGap application I am developing for iPad that uses video extensively,
I'm currently developing an iPad application that integrates MapKit. But I have a small
I am developing an application for iPad but in reality i don't have the
Ok I have an interesting issue on an iPad application I am developing. When
I am developing an iPad application with SDK4.2. I have a very strange error

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.