Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase not being found... iOS/SQLite
    primarykey
    data
    text
    <p>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.</p> <p>Code:</p> <pre><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], &amp;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, &amp;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... } </code></pre> <p>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". </p> <p>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.</p> <p>Any help or input would be greatly appreciated. Thanks!</p> <p>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:</p> <p>"Incompatible pointer types passing 'const char *' to parameter of type 'sqlite3_stmt *' (aka 'struct sqlite3_stmt *')"</p> <p>This warning appears on the following lines of code:</p> <pre><code>if (sqlite3_prepare_v2(database, sql, -1, &amp;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); </code></pre> <p>It's got something to do with "sql", but I'm unsure of what. Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload