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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:06:15+00:00 2026-06-03T06:06:15+00:00

I working on an app that takes input from a text field and puts

  • 0

I working on an app that takes input from a text field and puts it into a string. I have a table with a field in it that I want to check the value of the string from the input against the value in the field in the database. I’m new to iOS and fairly new to SQLite.

Code:

-(IBAction)setInput:(id)sender
{
NSString *strStoreNumber;
NSString *strRegNumber;

strStoreNumber = StoreNumber.text;
strRegNumber = RegNumber.text;
lblStoreNumber.text = strStoreNumber;
lblRegNumber.text = strRegNumber;

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSString* documentsDirectory = [paths lastObject];
//    NSString* databasePath = [documentsDirectory stringByAppendingPathComponent:@"tblStore.sqlite"];
NSString* databasePath = [[NSBundle mainBundle] pathForResource:@"tblStore" ofType:@"sqlite"];

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

    NSLog(@"Opened sqlite database at %@", databasePath);

    //...stuff
} 
else 
{
    NSLog(@"Failed to open database at %@ with error %s", databasePath, sqlite3_errmsg(database));
    sqlite3_close (database);
}

NSString *querystring;

// create your statement
querystring = [NSString stringWithFormat:@"SELECT strStore FROM tblStore WHERE strStore = %@;", strStoreNumber];  

const char *sql = [querystring UTF8String];

NSString *szStore = nil;
NSString *szReg = nil;


if (sqlite3_prepare_v2(database, sql, -1, &databasePath, NULL)!=SQLITE_OK) //queryString = Statement
{
    NSLog(@"sql problem occured with: %s", sql);
    NSLog(@"%s", sqlite3_errmsg(database));
}
else
{
    // you could handle multiple rows here

    while (sqlite3_step(databasePath) == SQLITE_ROW) // queryString = statement
    {            
        szStore = [NSString stringWithUTF8String:(char*)sqlite3_column_text(databasePath, 0)];
        szReg = [NSString stringWithUTF8String:(char*)sqlite3_column_text(databasePath, 1)];
    } // while        

}

sqlite3_finalize(databasePath);

// Do something with data...  
}

It gets to the line “NSLog(@”Opened sqlite database at %@”, databasePath);”, so it appears as though it has access to the database. However, when I run the app, I get the “NSLog(@”sql problem occured with: %s”, sql);” error, which I can see in the console. Additionally, in the console, it says “No such table: tblStore”.

I created the table using the Firefox add-on SQLite Manager. I added the sqlite3 library to the project. I dragged and dropped the database table I created in SQLite manager into my project, above my two AppDelegate files and my two ViewController files.

Any help or input would be greatly appreciated. Thanks!

EDIT: I have properly added the file to the project, and it appears as though the table is found now. Now I have some strange warnings, though:

“Incompatible pointer types passing ‘const char *’ to parameter of type ‘sqlite3_stmt *’ (aka ‘struct sqlite3_stmt *’)”

This warning appears on the following lines of code:

if (sqlite3_prepare_v2(database, sql, -1, &databasePath, NULL)!=SQLITE_OK)

while (sqlite3_step(sql) == SQLITE_ROW)

szStore = [NSString stringWithUTF8String:(char*)sqlite3_column_text(sql, 0)];

szReg = [NSString stringWithUTF8String:(char*)sqlite3_column_text(sql, 1)];

sqlite3_finalize(sql);

It’s got something to do with “sql”, but I’m unsure of what. Any suggestions?

  • 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-03T06:06:17+00:00Added an answer on June 3, 2026 at 6:06 am

    Your code seems ok – did you copy the db to the ressource folder of your project?

    EDIT

    Make sure you access your db file with something like that:

        - (void) initializeDB {
    
            // Get the database from the application bundle
            NSString* path = [[NSBundle mainBundle] pathForResource:@"tblStore" ofType:@"sqlite"];
    
            if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) 
            {
                NSLog(@"Opening Database"); 
            }
            else
            {
                // Call close to properly clean up
                sqlite3_close(database);
    
                NSAssert1(0, @"Error: failed to open database: '%s'.", 
                          sqlite3_errmsg(database));
            }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an app that takes URLs from RSS feeds and opens them
I'm working with an open-source .NET app that takes a long time to startup
I'm working on an app that needs to accept a RegEx from the user,
I'm working on an app that plays audio continuously using the waveOut... API from
I'm working on an app that needs to retrieve some data from a server.
Im building an app that takes a photo of the user, its working fine
i'm working on creating an app that streams mp3s from a server. i'm using
I am working on an app where a string is taken as an input
Working on iPhone app that takes a photo and then uploads it to a
I'm working on an app (Rails 3.2, Mongoid) that takes all (by all I

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.