iosobjective-csqlitefmdbsqlitemanager

FMDB error : No Such table


I created new DB in Documents using SQLite Manager. Created a table there too with a sample row. This code I am using for db path :

  +(ModelManager *) getInstance
{

    if(!instance)
    {
        instance=[[ModelManager alloc]init];
        instance.database=[FMDatabase databaseWithPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Inventorydb.sqlite"]];
    }
    return instance;
}

Now when I am using function to display data; it shows : DB Error: 1 "no such table: inventorydata" Code for Display data is like this :

-(void) displayData
{
    [instance.database open];
    FMResultSet *resultSet=[instance.database executeQuery:@"SELECT * FROM inventorydata"];
    if(resultSet)
    {
        while([resultSet next])
        NSLog(@"UPC : %@    Name : %@",[resultSet stringForColumn:@"upc"],[resultSet stringForColumn:@"name"]);
    }
    [instance.database close];
}

Image Showing Created table in sqlite manager.

Whats the issue here.


Solution

  • I missed to copy DB file inside App Delegate file.

        [Util copyFile:@"Inventorydb.sqlite"];