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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:13:33+00:00 2026-06-02T16:13:33+00:00

I am using fmdb but i am not knowing where to add the db

  • 0

I am using fmdb but i am not knowing where to add the db file.
I found this old answer that i think it doesn’t fit for xcode 4.2 (since we dont have ‘Resources’ folder anymore).

I created a database in ‘Lita’, added the extension .sqlite and added the db file as follows :

dbsqlite

then tried to use the following

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"db.sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:path];
[database open];
FMResultSet *results = [database executeQuery:@"select * from tbl"];
printf("hi");
while([results next]) {
    printf("hi2");
NSString *name = [results stringForColumn:@"clm1"];
NSString *text  = [results stringForColumn:@"clm2"];        
NSLog(@"test: %@ - %@",name, text);
}
printf("done");

i am getting the ‘hi’ ‘done’ but never ‘hi2’…

anyone can help?

  • 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-02T16:13:35+00:00Added an answer on June 2, 2026 at 4:13 pm

    You want to add the (compiled) database to the project as a resource, and then copy it into the documents folder of the app on first start-up.

    Here is an example method that does the work, call it from the applicationDidFinishLaunching and use the resultant FMDatabase * for all you queries.

    - (FMDatabase *)openDatabase
    {
        NSFileManager *fm = [NSFileManager defaultManager];
        NSString *documents_dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *db_path = [documents_dir stringByAppendingPathComponent:[NSString stringWithFormat:@"database.s3db"]];
        NSString *template_path = [[NSBundle mainBundle] pathForResource:@"template_db" ofType:@"s3db"];
    
        if (![fm fileExistsAtPath:db_path])
            [fm copyItemAtPath:template_path toPath:db_path error:nil];
        FMDatabase *db = [FMDatabase databaseWithPath:db_path];
        if (![db open])
            NSLog(@"Failed to open database!");
        return db;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app that is using sqlite 3.6 (not with FMDB) to
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I'm trying to get data from a database using FMDB but having tried with
i am using FMDB wrapper i used this code - (BOOL)update:(NSString *) Body fromValue:(NSString
I know that there are a few postings on this, but just want to
I have an iPad app that is using a sqlite database using FMDB as
I'm using FMDB for my iPhone App database and i want to create the
I am having trouble UPDATING my database using FMDB . Here's my SQL BOOL
Using CI for the first time and i'm smashing my head with this seemingly

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.