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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:19:16+00:00 2026-06-07T22:19:16+00:00

I’m working on the following code that is trying to connect to DB, but

  • 0

I’m working on the following code that is trying to connect to DB, but I get stuck on this point:

#import "ToDos.h"
#import "AppDelegate.h"

static sqlite3 *database = nil;

@implementation ToDos
@synthesize todoID, title, descr, isDirty, isDetailViewHydrated;

- (void) dealloc    {

}

+ (void) getInitialDataToDisplay:(NSString *)dbPath {

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

    if (sqlite3_open([dbPath UTF8String], database) == SQLITE_OK) {

//      const char *sql = "select * from todos";
//      sqlite3_stmt *selectstmt;
//      if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
//          
//          while(sqlite3_step(selectstmt) == SQLITE_ROW) {
//              
//              NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
//              ToDos *coffeeObj = [[ToDos alloc] initWithPrimaryKey:primaryKey];
//              coffeeObj.title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
//              
//              coffeeObj.isDirty = NO;
//              
//              [appDelegate.todosArray addObject:coffeeObj];
//              // [coffeeObj release];
//          }
//      }
    }
    else
        sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}

- (id) initWithPrimaryKey:(NSInteger) pk {
    // [super init];
    todoID = pk;

    isDetailViewHydrated = NO;

    return self;
}

@end

The problem seams to be in pointer….

static sqlite3 *database = nil;

and

if (sqlite3_open([dbPath UTF8String], database) == SQLITE_OK) {

but here is the error message while trying to start the app

enter image description here

The same code is in the tutorial an it works 🙂

  • 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-07T22:19:18+00:00Added an answer on June 7, 2026 at 10:19 pm
    1. As La bla bla said, it looks like you haven’t added the sqlite3 library to your project. In Xcode’s project file navigator tree on the left, click on the target (the top of the tree). When looking at the target settings, click on “Build Phases”, go to the “Link Binary With Libraries”, click on the “+” button, and add libsqlite3.0.dylib to your project.

    2. You need sqlite3_open([dbPath UTF8String], &database);. You’re updating your database pointer, so don’t forget that ampersand.

    3. Also, on failure, no point in calling sqlite3_close, because database will presumably still be NULL, possibly causing problems (crash?) if you call sqlite3_close with a NULL database pointer because couldn’t open the database.

    4. In your commented code, you’re doing sqlite3_prepare and sqlite3_step, but you’re not doing the final sqlite3_finalize. It’s not fair to critique commented code, but I just want to make sure you don’t forget that when the time comes. 🙂

    5. By the way, sqlite3_open will create the database for you if it’s not there. If you don’t want to do that (i.e. if you only want it succeed if your previously created database is successfully found), then use sqlite3_open_v2([dbPath UTF8String], &database, SQLITE_OPEN_READWRITE, NULL); instead. Lots of first time users have a database, forget to include it in their target’s “Copy Bundle Resources” list, and are confused when sqlite3_open suggests that they’ve successfully opened their database when in fact it might have just created a new database when it didn’t find the one you intended. If you want the opening of the database to create the database, though, ignore what I just said. But if not, consider sqlite3_open_v2.

    6. Finally, once you’ve successfully opened your database, I encourage you to always check the sqlite3_errmsg command if any of your subsequent commands fail. Too often some random sqlite3 command doesn’t work and the programmer is left scratching their head, but they forget to check the sqlite3_errmsg. I know that’s not the issue here, but just a final piece of counsel for a new sqlite3 programmer.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.