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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:34:47+00:00 2026-05-25T21:34:47+00:00

I’ve been working on incorporating a sqlite db in my iPhone app. The database

  • 0

I’ve been working on incorporating a sqlite db in my iPhone app. The database has been created, and I have successfully inserted elements into the database. Now, when I try to select from the db, my prepare statement is not meeting the requirement of SQLITE_OK. Here is the code where I create the database:

const char *sql_stmt = "CREATE TABLE IF NOT EXISTS EXPENSES (id integer primary key autoincrement, unix_date integer, date_time text, purpose text, start_mile text, end_mile text, distance text, fees text, party_id integer)";

and here is the code I am using to extract the data:

    const char *dbpath = [databasePath UTF8String];
sqlite3_stmt    *statement;
printf("in getExpense\n");
//expenses = [[NSMutableArray alloc] init];

if (sqlite3_open(dbpath, &expenseDB) == SQLITE_OK)
{
    NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM EXPENSES"];

    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(expenseDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {

        printf("right before the while loop\n");
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            printf("in the while loop\n");
            VehicleExpense *expense = [[VehicleExpense alloc] init];

            NSInteger *newTimeStamp = sqlite3_column_int(statement, 1);

            NSString *newDate = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];

            NSString *newPurpose = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)];

            NSString *newStart = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)];
            NSString *newEnd = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 5)];
            NSString *newDistance = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 6)];
            NSString *newFees = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 7)];
            NSInteger *newPartyId = sqlite3_column_int(statement, 8);

            expense.unix_date = newTimeStamp;
            expense.date = newDate;
            expense.purpose = newPurpose;
            expense.start_mile = newStart;
            expense.end_mile = newEnd;
            expense.distance = newDistance;
            expense.fees = newFees;
            expense.party_id = newPartyId;

            [expenses addObject: expense];
            printf("expense add");

            [newDate release];
            [newPurpose release];
            [newStart release];
            [newEnd release];
            [newDistance release];
            [newFees release];

            [expense release];

            expense_count++;

        }
        sqlite3_finalize(statement);
    }else{
        printf("the prepare statement is not ok\n");
    }
    sqlite3_close(expenseDB);
}else{
    printf("couldn't open the db\n");
}

The second if-statement keeps failing for some reason?

Any ideas?

  • 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-25T21:34:48+00:00Added an answer on May 25, 2026 at 9:34 pm

    printf("the prepare statement is not ok\n"); is not really helpful at all. Try something like

    NSLog(@"prepare failed (%s)", sqlite3_errmsg(expenseDB));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.