Sqlite3 gives the error "no such table" on the iPhone

I created a sqlite3 database, created tables, and inserted some data. I can get a select request using a terminal application.

But when I add this database to my iPhone application resources and try to access the data programmatically, I get an error like "there is no such table: table name"

Why is this happening?

+3
source share
3 answers

sqlite3_open () creates an empty database for you if the database path does not exist. Thus, it is possible that the path you gave it does not lead to the intended file. With an empty database you will get a β€œno such table” a lot.

+8

DB, , iPhone. iPhone.

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                    NSDocumentDirectory, NSUserDomainMask, YES
                 );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [
      documentsDirectory stringByAppendingPathComponent:@"yourdbname.sql"
];
// Open the database. The database was prepared outside the application.
if (sqlite3_open([path UTF8String], &db_handle) != SQLITE_OK) {
    // Even though the open failed, 
    // call close to properly clean up resources.
    sqlite3_close(db_handle);
    NSAssert1(0, 
         @"Failed to open database with message '%s'.", 
         sqlite3_errmsg(db_handle)
    );
}

. , , .

0

I had the same error with sqlite3X C ++ shell. I use this library in my IE plugin. The problem was the inaccessibility of the .sqlite database. The current directory for IE (not the plugin) is "C: \ Documents and Settings \ UserName \ desktop \". When I put my base in this place, the problem was resolved.

0
source

Source: https://habr.com/ru/post/1705169/


All Articles