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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:42:13+00:00 2026-05-20T08:42:13+00:00

I have been at this for hours and MUST get this working! It is

  • 0

I have been at this for hours and MUST get this working! It is holding up an iPhone app release… My first time using SQLite. I have followed all the advice and yet my sqlite3_prepare_v2 call gets a SQLITE_ERROR (1) every time!

Here is my code from my controller:

        NSString *query = @"SELECT * FROM QandA ORDER BY random() LIMIT 1";
//  const char *sqlStatement = "SELECT * FROM QandA ORDER BY random() LIMIT 1";
    sqlite3_stmt *compiledStatement;

    // sqlite3_stmt *statement;
    int prepareStatus = sqlite3_prepare_v2(database, [query UTF8String],
                                           -1, &compiledStatement, NULL);
    if (prepareStatus == SQLITE_OK) {...

You’ll note that I’ve tried using a “char *” also to no avail (among other attempts). My database opens fine with:

    databaseName = @"Facts.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
NSLog(@"databasePath = %@", databasePath);

int dbOpenStatus = sqlite3_open_v2([databasePath UTF8String], &database, SQLITE_OPEN_READWRITE, NULL);

From my controller interface:

    NSString *databaseName;
NSString *databasePath;

I’ve checked in the debugger and everything looks good, but the prepare statement fails. I don’t know how to log the statement it is trying to compile… I assume/hope it is just what my SELECT says.

Can anyone help? I’m desperate. Mark

  • 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-20T08:42:14+00:00Added an answer on May 20, 2026 at 8:42 am

    Found the answer here. I had to use this instead for the path to the DB file:

    [[NSBundle mainBundle]pathForResource:@"Facts"extension:@"sqlite"];
    

    This gave a slightly different path (one extra directory) – once I used that it worked! Hope this helps someone else… I spent many hours on this.

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

Sidebar

Related Questions

I have been trying to get this effect for a couple of hours now
I have been asking myself this question for a long time now. Thought of
I have been working on this for the greater part of the day and
I have been trying to get around this error for a day now and
I have been using code similar to this MessageDlg('', mtWarning, [mbOK], 0); throughout my
I have been trying this for hours without success. http://replicaisland.googlecode.com/svn/trunk/ I have added the
I have been at this for hours now and I simply cannot figure it
I have been hearing this term quite a lot. I have a bunch of
I have been playing with this for a while, but the closest I have
I have been trying to tackle this problem , but I am having difficulty

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.