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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:38:57+00:00 2026-06-07T03:38:57+00:00

How can i replace the database (with the one i am working on) in

  • 0

How can i replace the database (with the one i am working on) in my app on each simulator run? (Still adding data and want to check that it looks good)

I tried this but it doesn’t seem to be working, still using the old database:

- (void)viewDidLoad
{
    dbname = @"animaldatabase.sql";
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    dbpath = [documentsDir stringByAppendingPathComponent:dbname];

    [self checkAndCreateDatabase];
    [self readAnimalsFromDatabase];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    mylabel.text = [NSString stringWithFormat:@"%d", [animals count]];
}

- (void) checkAndCreateDatabase{
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    success = [fileManager fileExistsAtPath:dbpath];
    if (success) {
     //return;
        [fileManager removeItemAtPath:dbpath error:nil];
    }

    NSString *dbPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:dbname];
    [fileManager copyItemAtPath:dbPathFromApp toPath:dbpath error:nil];
}

Also where is the location for the iphone database? When my app copies the database into the iphone, where does it end up?

UPDATE

Added the loading code as well.

Senthilkumar:

I fail to see how this should solve the problem? Doesn’t this just skip the copying or my database if it already exists?

What i want is to delete the database in my iphone app. Import the new database and then run it.

  • 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-07T03:38:59+00:00Added an answer on June 7, 2026 at 3:38 am

    use the following code instead of that.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
     databaseName=@"yourfileName.sqlite";
     NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *documentsDir = [documentPaths objectAtIndex:0];
     databasePath = [documentsDir stringByAppendingPathComponent:databaseName]; 
    [self checkAndCreateDatabase]; 
    
    }
    -(void) checkAndCreateDatabase {
    
    BOOL success;
    
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    success = [fileManager fileExistsAtPath:databasePath];
    
    if(success) return;
    else
        printf("NO File found");
    
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
    
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can replace values as array by replace in javascript. I want done replace
How can replace arabic number with latin number as that doesn't change number into
I was wondering if there is any way that I can replace substrings within
Say I have a database that stores table data by year using an identical
I'm still working on this database for a small retail store (a scenario, thankfully!)
I am working on an old software that uses a .mdb database. I have
I have to migrate data from one database to another. As preparation we have
I'm working on a project that involves a SQLite database and a bunch of
How i can replace any character except 0-9 a-z and and array of some
so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim

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.