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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:54:38+00:00 2026-05-15T15:54:38+00:00

Trying to return whether a record exists in SQLite on the iPhone except I

  • 0

Trying to return whether a record exists in SQLite on the iPhone except I keep getting an ‘unknown error’.

selectStmt is static sqlite3_stmt *selectStmt = nil; used here if(selectStmt) sqlite3_finalize(selectStmt); which only gets executed if the application terminates. This functionality works fine with delete statements and insert statements so I’m guessing it’s something wrong with the below logic?

- (BOOL) doesBookExist {

    if(selectStmt == nil) {
        const char *sql = "select count(*) from books where isbn = ?";

        if(sqlite3_prepare_v2(database, sql, -1, &selectStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating select statement. '%s'", sqlite3_errmsg(database));
    }

    //When binding parameters, index starts from 1 and not zero.
    int count = sqlite3_bind_text(selectStmt, 1, [isbn UTF8String], -1, SQLITE_TRANSIENT);

    if (SQLITE_DONE != sqlite3_step(selectStmt)) 
        NSAssert1(0, @"Error while selecting. '%s'", sqlite3_errmsg(database));

    sqlite3_reset(selectStmt);

    return (count > 0);
}
  • 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-15T15:54:39+00:00Added an answer on May 15, 2026 at 3:54 pm

    sqlite3_bind_text returns a success/error code, not the result of any query. And step should return SQLITE_ROW, since you have one row of result data (regardless of whether the count is 0 or more). There seemed to be an error, because you were expecting SQLITE_DONE when the correct value was SQLITE_ROW. Then, to get the count, you need to use sqlite3_column_int after executing step. So something like:

    int bind_res = sqlite3_bind_text(selectStmt, 1, [isbn UTF8String], -1, SQLITE_TRANSIENT);
    
    if (SQLITE_OK != bind_res)
    {
      // log error, return...
    }
    
    // One row of result data, so step should return SQLITE_ROW
    if (SQLITE_ROW != sqlite3_step(selectStmt)) 
    {
      NSAssert1(0, @"Error while selecting. '%s'", sqlite3_errmsg(database));
      // log error, return
    }
    
    int count = sqlite3_column_int(selectStmt, 0); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error return whether I try LsaQueryInformationPolicy() on the local host or
I'm trying to write a method to return true or false whether a product
Especially getting the function return type(and if possible whether its a pointer type). (I'm
I'm trying to return the first message between two users, whether I sent that
I'm trying to decide whether it is better to use static methods for loading/saving
The program is supposed to find a file and return whether it exists on
Im trying to return the value that a $ajax call returns, from a function
Im trying to return a SimpleQuery list that queries a single table and uses
Am trying to return the sum of each day of a week in mysql
I'm trying to return the most common elements in a list (statistical mode). Unfortunately

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.