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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:08:44+00:00 2026-06-12T10:08:44+00:00

I have this sqlite3 table used in an iOS 6 app for iPad: CREATE

  • 0

I have this sqlite3 table used in an iOS 6 app for iPad:

CREATE TABLE notes(id INTEGER PRIMARY KEY, note TEXT, noteDate TEXT, wasUploaded INTEGER);

from the sqlite3 command line this query works:

sqlite> Select `id`,`note`,`noteDate`,`wasUploaded` FROM `notes` WHERE `wasUploaded`=0;

1|Well|2012-10-04 22:46:23|0

On iOS iPad 6.0 Simulator each of these queries returns the exact same data as above:

const char *sqlStatement = "Select `id`,`note`,`noteDate`,`wasUploaded` FROM `notes` WHERE `id`=1";

const char *sqlStatement = "Select `id`,`note`,`noteDate`,`wasUploaded` FROM `notes` WHERE `note`='Well'";

const char *sqlStatement = "Select `id`,`note`,`noteDate`,`wasUploaded` FROM `notes` WHERE `noteDate`='2012-10-04 22:46:23'";

But this query which worked fine on the command line now returns no data:

const char *sqlStatement = "Select `id`,`note`,`noteDate`,`wasUploaded` FROM `notes` WHERE `wasUploaded`=0";

Has me baffled. Why is that last query not working? Do I need to make that column an index or something? The other two non-indexed columns work but not this.

No errors. The last query that returns no data gives a normal return code of 101 (sqlite3_step() has finished executing) and a query without the where clause returns the same data as for the other three queries.

Edit: here is the complete code

- (NSString *)getNotesToBeUploaded {
sqlite3 *stuDb;
NSString *thisNote;
NSMutableString *notes = [[NSMutableString alloc]init];

if (self.filePath == @"empty") {
    [self setDatabaseFilePath];
}

if (sqlite3_open([self.filePath UTF8String], &stuDb) == SQLITE_OK)
{
    // this is the query line that get changed to show stackoverflow the different results:
    const char *sqlStatement = "Select `id`,`note`,`noteDate` FROM notes WHERE `wasUploaded`=0";
    sqlite3_stmt *compiledStatement;
    int nResult = sqlite3_prepare_v2(stuDb, sqlStatement, -1, &compiledStatement, NULL);
    if ( nResult == SQLITE_OK)
    {
        int nret; // diagnostic used to watch return vaues when single stepping
        while ((nret = sqlite3_step(compiledStatement)) == SQLITE_ROW)
        {
            int id =  sqlite3_column_int(compiledStatement, 0);
            const unsigned char *note =  sqlite3_column_text(compiledStatement, 1);
            const unsigned char *noteDate =  sqlite3_column_text(compiledStatement, 2);
            int wu =  sqlite3_column_int(compiledStatement, 4);
            if (strlen((const char *)note) > 0 && strlen((const char *)noteDate) > 0)
            {
                thisNote = [NSString stringWithFormat:@"%d,%s,%s,%d\n",id, noteDate, note, wu];
                [notes appendString:thisNote];
            }
        }
    } else {
        sqlite3_finalize(compiledStatement);// prevent small memory leaks
        sqlite3_close(stuDb);
        thisNote =
        [NSString stringWithFormat:@"prepare failed with status:%d in %s at line %d path was %@,0,0\n",nResult,__FILE__,__LINE__,self.filePath];
        [notes appendString:thisNote];
        [notes appendString:@"\n"];
        return (NSString *)notes;
    }
    sqlite3_finalize(compiledStatement);
    sqlite3_close(stuDb);
}
  • 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-12T10:08:46+00:00Added an answer on June 12, 2026 at 10:08 am

    Are you checking the return codes from your sqlite3 calls? And, if you’re not getting SQLITE_OK or SQLITE_ROW, as appropriate, you should check the sqlite3_errmsg results to diagnose what’s going on. You really should share your code if you want us to help you.
    But the most common problems in the first-time iOS SQLite apps are

    • Failing to include the database in your app’s bundle. Check your Target settings and make sure you’ve included the database in the Build Phases. You can also confirm this by looking at your app’s bundle in the simulator in the ~/Library/Application Support/iPhone Simulator folder. If you want to do that, you may want to unhide your ~/Library folder if you haven’t by typing in chflags no hidden ~/Library in the Terminal command line interface.

    • If you’re planning on updating your database from the app, failing to first copy the database from the bundle to the Documents folder before you try to start using it.

    • Using sqlite3_open and interpreting a successful return code as evidence that the database was opened successfully … but if it didn’t find the database, the sqlite3_open function annoyingly will create a new blank database … I always suggest that people use sqlite3_open_v2 instead, in which you can omit the parameter to create a blank database if it’s not found if that’s not what you want.

    Certainly, there can be a ton of code-related issues (order that the functions are called, failing to check return codes, etc.), too. It’s impossible to comment further without seeing the code.

    And I feel obliged to share my final SQLite programming advice that it’s worth checking out FMDB Objective-C SQLite wrapper library, which greatly simplifies SQLite programming in iOS.


    Update:

    Having looked at your code, it looks fine. I just ran it (only tweaked to just NSLog rather than appending notes):

    - (void)test2
    {
        sqlite3 *stuDb;
        NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *databaseName = [documentsDirectory stringByAppendingPathComponent:@"test.db"];
    
        if (sqlite3_open([databaseName UTF8String], &stuDb) == SQLITE_OK)
        {
            // this is the query line that get changed to show stackoverflow the different results:
            const char *sqlStatement = "Select `id`,`note`,`noteDate` FROM notes WHERE `wasUploaded`=0";
            sqlite3_stmt *compiledStatement;
            int nResult = sqlite3_prepare_v2(stuDb, sqlStatement, -1, &compiledStatement, NULL);
            if ( nResult == SQLITE_OK)
            {
                int nret; // diagnostic used to watch return vaues when single stepping
                while ((nret = sqlite3_step(compiledStatement)) == SQLITE_ROW)
                {
                    int id =  sqlite3_column_int(compiledStatement, 0);
                    const unsigned char *note =  sqlite3_column_text(compiledStatement, 1);
                    const unsigned char *noteDate =  sqlite3_column_text(compiledStatement, 2);
                    int wu =  sqlite3_column_int(compiledStatement, 4);
                    if (strlen((const char *)note) > 0 && strlen((const char *)noteDate) > 0)
                    {
                        // thisNote = [NSString stringWithFormat:@"%d,%s,%s,%d\n",id, noteDate, note, wu];
                        // [notes appendString:thisNote];
                        NSLog(@"%d,%s,%s,%d\n",id, noteDate, note, wu);
                    }
                }
            } else {
                //sqlite3_finalize(compiledStatement);// prevent small memory leaks, not needed if the prepare failed
                sqlite3_close(stuDb);
                NSLog(@"prepare failed with error %s", sqlite3_errmsg(stuDb));
                return;
            }
            sqlite3_finalize(compiledStatement);
            sqlite3_close(stuDb);
        }
    }
    

    And I got results:

    2012-10-05 15:44:06.075 test8[1574:c07] 1,2012-10-05 19:43:37,ABC,0
    2012-10-05 15:44:06.076 test8[1574:c07] 2,2012-10-05 19:43:46,XYZ,0
    

    So the problem must be in the database itself. Judging from your last comment, it sounds like rebuilding the database did it for you. That’s great.

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

Sidebar

Related Questions

Using sqlite3, I have a table that looks like this: +---------+-----------------+----------+-----------+--------+ | ArtId |
In this example we have 3 related tables on a SQLite database: CREATE TABLE
I have an iOS app that uses sqlite3 databases extensively. I need to add
I have this code in my viewWillAppear method: sqlite3 *database; if (sqlite3_open([[self dataFilePath] UTF8String],
I have created a file named MyFile.db using SQLite3 from my C#.net application. This
I have an application where i used to display the data on table view
I have an iPhone (iOS) app that keeps data in a local SQLite database
I am updating an old iOS app which used sqlite database. I changed the
I have created an sqlite table using the following statement: CREATE TABLE IF NOT
My application has multiple SQLite tables(around 20 with different fields). This I have created

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.