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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:21:31+00:00 2026-06-11T21:21:31+00:00

I have created a dictionary application with several data bases , everything works fine

  • 0

I have created a dictionary application with several data bases , everything works fine except saving columns in bookmark ! , I know , it’s not possible change files in NSBundle but I don’t know how can I fix it . I would be grateful if you help me out here is the code :

- (NSString *) getDBPath {
    NSString *path;

    if ( [[[NSUserDefaults standardUserDefaults] stringForKey:@"Bv"] intValue] == 2)
    {
        path = [[NSBundle mainBundle]pathForResource:@"pr-eng" ofType:@"sqlite"];

    } else {

        path = [[NSBundle mainBundle]pathForResource:@"eg-pr" ofType:@"sqlite"];
    }

    if ( [[[NSUserDefaults standardUserDefaults] stringForKey:@"Bv"] intValue] == 3)
    {
        path = [[NSBundle mainBundle]pathForResource:@"german" ofType:@"sqlite"];
    }

    return path;    
}

Here is bookmarking function :

-(void) setBookMark:(NSInteger)oid {

sqlite3_stmt    *statement;

const char *dbpath = [[self getDBPath] UTF8String];

if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
    NSString *SetFavSQL = [NSString stringWithFormat: @"UPDATE DIC SET bookmark=1 WHERE id=\"%d\"", oid];
    //      NSLog(@"%@",SetFavSQL);
    const char *SetFav_stmt = [SetFavSQL UTF8String];

    sqlite3_prepare_v2(database, SetFav_stmt, -1, &statement, NULL);
    if (sqlite3_step(statement) != SQLITE_DONE)
    {

    }
    sqlite3_finalize(statement);
    sqlite3_close(database);
}
}

Reading database :

-(void) read_Database{

NSMutableArray *DB_Array = [[NSMutableArray alloc] init];
NSMutableArray *word_Array = [[NSMutableArray alloc] init];

if(sqlite3_open([[self getDBPath]UTF8String], &database) == SQLITE_OK) {

    NSString *sql =@"SELECT * FROM DIC";

    //        NSLog(@"%@",sql);

    sqlite3_stmt *compiledStatement;

    if(sqlite3_prepare_v2(database, [sql UTF8String] , -1, &compiledStatement, NULL) == SQLITE_OK) {
        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {


            NSInteger oid = sqlite3_column_int(compiledStatement, 0);

            const char* f1 = (const char*)sqlite3_column_text(compiledStatement, 1);
            NSString *oName = f1 == NULL ? nil : [[NSString alloc] initWithUTF8String:f1];

            const char* f2 = (const char*)sqlite3_column_text(compiledStatement, 2);
            NSString *oMean = f2 == NULL ? nil : [[NSString alloc] initWithUTF8String:f2];


            const char* f3 = (const char*)sqlite3_column_text(compiledStatement, 3);
            NSString *oPron = f3 == NULL ? nil : [[NSString alloc] initWithUTF8String:f3];

            NSInteger bm = sqlite3_column_int(compiledStatement, 5);

            readerClass = [[Reader alloc]initWithReadDB:oid Name:oName Mean:oMean Pron:oPron bookMark:bm];

            [DB_Array addObject:readerClass];
        }
    }
    sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);


AppDelegate *appDelegateClass = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegateClass.wordList removeAllObjects];
appDelegateClass.wordList=[word_Array mutableCopy];


[appDelegateClass.dictionaryArray removeAllObjects];
appDelegateClass.dictionaryArray=[DB_Array mutableCopy];
}
  • 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-11T21:21:32+00:00Added an answer on June 11, 2026 at 9:21 pm

    For further improvement in @H2CO3’s answer and for more clarification I post my answer 🙂

    Here is what I do to save data to database on iPhone or iPad (iOS). All data is been kept in device locally. So if app is uninstalled all data will lost, if user hasn’t take backup of the app and restored if from backup.

    NSFileManager *fileMgr;
    NSString *homeDir;
    

    These are the ivar I use in below functions all functions are in my .m file which is contains all my db related functions like update, insert, select, delete.

    -(void)CopyDbToDocumentsFolder
    {
        NSError *err=nil;
        fileMgr = [NSFileManager defaultManager];
        NSString *dbpath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"res_in_mil.sqlite"];
        NSString *copydbpath = [self.GetDocumentDirectory stringByAppendingPathComponent:@"res_in_mil.sqlite"];
        [fileMgr removeItemAtPath:copydbpath error:&err];
        if(![fileMgr copyItemAtPath:dbpath toPath:copydbpath error:&err])
        {
            UIAlertView *tellErr = [[UIAlertView alloc] initWithTitle:title message:@"Unable to copy database." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [tellErr show];
    
        }
    }
    -(NSString *) GetDocumentDirectory
    {
        fileMgr = [NSFileManager defaultManager];
        homeDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        return homeDir;
    }
    

    As the name is self-explains there is no need to explain what these functions are for.

    And in appDelegate.m I use the below code to copy my DB to the specified location where I can edit my DB. This code is in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.

    NSFileManager *fileMgr;
    myDB *dbObj = [[myDB alloc]init];
    fileMgr = [NSFileManager defaultManager];
    NSString *dbPath = [[dbObj GetDocumentDirectory] stringByAppendingPathComponent:@"res_in_mil.sqlite"];
    BOOL success = [fileMgr fileExistsAtPath:dbPath];
    if(!success)
        [dbObj CopyDbToDocumentsFolder]; 
    

    I use this for one DB as I have only one DB. But I think you can extend these functions to copy more then one DB.

    Even you can make one function to identify that the required DB is in DocumentDirectory or not using the code of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method given above.

    And for insert, update, delete, select operation I use the below code to open the DB for any access.

    fileMgr = [NSFileManager defaultManager];
    NSString *dbPath = [[self GetDocumentDirectory] stringByAppendingPathComponent:@"res_in_mil.sqlite"];
    BOOL success = [fileMgr fileExistsAtPath:dbPath];
    
    if(!success)
        {
            NSLog(@"Cannot locate database file '%@'",dbPath);
            [self CopyDbToDocumentsFolder];
        }
    

    Happy Coding 🙂

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

Sidebar

Related Questions

I have created a Dictionary in Application scope, but I'm not sure how to
I have created a dictionary in Class A and would like to return the
I am trying to implement vectorization of a text file...I have created a dictionary
I have a Dictionary of objects I have created in smalltalk, which I am
I have defined a class Listener and created a dictionary of Listener objects. Each
all: I have 2 Dictionary objects d1 and d2. They are created separately at
I have created two dictionaries in the user defaults of my application to represent
I have a dictionary of 10000 Product/Colour/Size combinations which I have created with something
dont know whats wrong with my table view, I have a dictionary(this dictionary is
I have an application that will store and track visitors. These visitors are created

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.