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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:53:50+00:00 2026-05-21T20:53:50+00:00

Hey guys, I’m just playing around with SQLite so this is new for me.

  • 0

Hey guys, I’m just playing around with SQLite so this is new for me. I’ve got a view in which persons data can be both saved and found. The save-function and find-function work perfectly. Now, I’ve got a new view with a tableView in it. I want to get all the persons in the contacts-table and fill the list with it.

Untill now, I’ve got:

-(void)viewWillAppear:(BOOL)animated {
    const char *dbpath = [databasePath UTF8String];
    sqlite3_stmt *statement;

    if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
    {
        NSLog(@"Opened DB");
        NSString *querySQL = [NSString stringWithFormat:@"SELECT name FROM contacts"];

        const char *query_stmt = [querySQL UTF8String];
        NSLog(@"could not prepare statement: %s\n", sqlite3_errmsg(contactDB));

        if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
        //if (sqlite3_step(query_stmt) == SQLITE_DONE)
        {
            //NSLog(@"SQLite OK");
            NSLog(@"SQLite ok");
            //if (sqlite3_step(statement) == SQLITE_ROW)
            //{
                while(sqlite3_step(statement) == SQLITE_ROW) {
                    NSLog(@"SQLite ROW");
                    NSString *person = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
                    [personsList addObject:person];
                }
            //} else {
            //    NSLog(@"Emtpy list");
            //}
            sqlite3_finalize(statement);
        }
        sqlite3_close(contactDB);
    }
    NSLog(@"Calling reload");
    NSLog(@"%@", personsList);
    [tabelView reloadData];
}

This is all in viewWillAppear. When the view is loaded and done, the log says:
2011-05-06 10:45:26.976 database[1412:207] Opened DB

2011-05-06 10:45:26.978 database[1412:207] could not prepare statement: not an error

2011-05-06 10:45:26.979 database[1412:207] Calling reload

2011-05-06 10:45:26.979 database[1412:207] (

)

So it seems the statement isn’t an error, but sqlite3_prepare_v2 isn’t SQL_OK after all. Any help?

EDIT: In the previous view, the statement for creating a person is: @"INSERT INTO CONTACTS (name, address, phone) VALUES (\"%@\", \"%@\", \"%@\")", name.text, address.text, phone.text];

The statement for finding someone is: @"SELECT address, phone FROM contacts WHERE name=\"%@\"", name.text];

These two statements work and the data is displayed.

  • 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-05-21T20:53:51+00:00Added an answer on May 21, 2026 at 8:53 pm

    I used const char *dbpath = [databasePath UTF8String];, but I forgot to put the following code above it:

    // Get the documents directory
        NSString *docsDir;
        NSArray *dirPaths;
        dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
        docsDir = [dirPaths objectAtIndex:0];
        databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"contacts.db"]];
        const char *dbpath = [databasePath UTF8String];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys I'm using python and I was just wondering how we can make
Hey guys can you help me figure this one out!? I'm still researching for
Hey guys was hoping you can help me out. been at this for like
Hey guys I'm tired and can't figure this one out so any help would
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys having this really simple problem but cant seem to figure out have
Hey guys got an issue with Cakephp validation.. I want to know why is
Hey guys I've written this MS SQL script with my awesome MS SQL skills,
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;

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.