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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:06:26+00:00 2026-06-09T19:06:26+00:00

I am using sqlite3 for my iOS project. When login/logout i want to recreate

  • 0

I am using sqlite3 for my iOS project.
When login/logout i want to recreate the whole db.
(i can do “delete from table;” but there are ~10 tables and when i need a table more i have to be careful about writing the delete code too)
So i searched for deleting the db; but i found that it can not be done with query.
It is said that i have to remove it from filesystem;
my code is;

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *dbPathDB=[appDelegate getDBPath];//dbname.sqlite
//to remove the db
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"dbname.sqlite"];

//both of them works same if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
if(filePath){
    NSLog(@"it is removed now");
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}

//recreating the db
if (sqlite3_open([dbPathDB UTF8String], &database) == SQLITE_OK) {
    NSLog(@"db is created");

}

When i try it on device, when i first login (no removing database yet) everything is ok, when i logout and login again, i got errors about inserting the data (but it can connect to db, that part works, error is about inserting the same row again).

And i stop the device and run it again and login i got no insert errors because the db is clean..
It looks like db file is removed but db is on cache or sth like that? How can i remove and create the same db and then insert the data without errors?

  • 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-09T19:06:27+00:00Added an answer on June 9, 2026 at 7:06 pm

    This one works:

    -(void)removeDB {
        // Check if the SQL database has already been saved to the users phone
        // if not then copy it over
        BOOL success;
        NSError *error;
        NSFileManager *fileManager = [NSFileManager defaultManager];
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        success = [fileManager fileExistsAtPath:[appDelegate getDBPath]];
        if(success) {
            [fileManager removeItemAtPath:[appDelegate getDBPath] error:&error];
            NSLog(@"This one is the error %@",error);
            return;
        }
        //recreating the db
        if (sqlite3_open([[appDelegate getDBPath] UTF8String], &database) == SQLITE_OK) {
            NSLog(@"db is created");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I figure out the column names of a table using sqlite3 from
Using sqlite3, if my query is SELECT * FROM table WHERE title LIKE '%x%'
Right now I am using sqlite within a ios application, and I want to
Can I use Sqlite with IOS using phonegap (with no limitations) ? If you
I'm using FMDatabase as sqlite wrapper for my iOS app, there's one place where
Using sqlite3, I have two tables: products, orders. I want to know how many
Using sqlite3, I have a table that looks like this: +---------+-----------------+----------+-----------+--------+ | ArtId |
I have an app using SQLite3. It's running pretty well, but I would like
I am switching from using SQLite3 to PostgreSQL, and hoped that I could populate
I'm using Core data in an iOS project. I have the data model setup

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.