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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:17:06+00:00 2026-06-10T08:17:06+00:00

I am trying to read from a database file (performing a simple select all

  • 0

I am trying to read from a database file (performing a simple select all functions).

I am using FMDB.

Here’s how i created the DB;

Pro:~ dd$ sqlite3 db.db
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table cus(id integer primary key, firstname varchar(30));
sqlite> inser into cus(firstname)values('f');
Error: near "inser": syntax error
sqlite> insert into cus(firstname)values('f');
sqlite> select * from cus;
1|f
sqlite> 

I copied the file (db.db) to my resource folder in xCode. changed the name of the db file to db.db in the app delegate. Code for my program is exactly yhe same as this tutorial.

Here’s the code ;

-(NSMutableArray *) getCustomers
{
    NSMutableArray *customers = [[NSMutableArray alloc] init];


    NSString * path = [(AppDelegate*)[[UIApplication sharedApplication]delegate]databasePath];
    NSLog(@"DB path %@ ",path);
    FMDatabase *db = [FMDatabase databaseWithPath:path];

    [db open];

    FMResultSet *results = [db executeQuery:@"SELECT * FROM cus"];
     NSLog(@"result %@ ",results);
    while([results next]) 
    {
        NSLog(@"result %@ ",results);
        Customer *customer = [[Customer alloc] init];

        customer.customerId = [results intForColumn:@"id"];
        customer.firstName = [results stringForColumn:@"firstname"];

        [customers addObject:customer];

    }

    [db close];

    return customers; 

}

My problem;

Eventhough there is 1 record in the DB, the result of the Select statement is NULL. Why is this and how can i correct 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-10T08:17:08+00:00Added an answer on June 10, 2026 at 8:17 am

    Assuming that the database was created and imported into the project successfully, try the following:

    -(NSMutableArray *) getCustomers
    {
     NSMutableArray *customers = [[NSMutableArray alloc] init];
     NSString * path = [(AppDelegate*)[[UIApplication sharedApplication]delegate]databasePath];
     NSLog(@"DB path %@ ",path);
     FMDatabase *db = [FMDatabase databaseWithPath:path];
    
     if(![db open])
     {
       NSLog(@"Could not open DB, try again");
       return nil;
     }
    
     FMResultSet *results = nil;
     results = [db executeQuery:@"SELECT * FROM cus"];
     NSLog(@"result %@ ",results);
     while([results next]) 
     {
       Customer *customer = [[Customer alloc] init];
    
       customer.customerId = [results intForColumn:@"id"];
       customer.firstName = [results stringForColumn:@"firstname"];
    
       NSLog(@"Customer object %@", customer);
       [customers addObject:customer];
       [customer release];
     }
    
     [db close];
    
     return customers; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from SQL Server database using Perl and the DBI
I am trying to read from a file and encrypt the data using AES
I am trying to read from a file on the local machine using Ajax.The
I am trying to read binary from database and write as a file in
I'm trying to create a tab-delimited file using data retrieved from the database. The
I am trying to read data from a sqlite database in an ios app.
I am trying to read data from a sqlite database and display it in
I am trying to read in values from the SQLite database and I have
I'm trying to find how to read data from my database in my iphone
I am trying to read from file: The file is multiline and basically i

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.