I am using the following code to open database in SQLite and execute an insert query.
// Open the database and store the handle as a data member
if (sqlite3_open([databaseFile UTF8String], &databaseHandle) == SQLITE_OK)
{
const char *sqlStatement = [insertStmt cStringUsingEncoding:NSUTF8StringEncoding];
char *error;
if (sqlite3_exec(databaseHandle, sqlStatement, NULL, NULL, &error) == SQLITE_OK)
{
NSLog(@"Config table values inserted.");
registration_done = YES;
}
else
{
NSLog(@"Error: %s", error);
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
if (sqlite3_exec(databaseHandle, sqlStatement, NULL, NULL, &error) == SQLITE_OK) {
NSLog(@"Config table values inserted 2.");
registration_done = YES;
}
else {
NSLog(@"Error: %s", error);
}
}
}
else{
sqlite3_close(databaseHandle);
}
sqlite3_close(databaseHandle);
But I am getting following error and the app is terminating after that:
-[__NSCFType UTF8String]: unrecognized selector sent to instance 0x15d9a0
Database files and tables are created in the /Caches/ directory as I am using Phonegap(2.1.0). Phonegap is properly executing query prior to above Objective-C code being called, which means that tables are getting created successfully in the /Caches/ directory.
Just use