0

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.

kalpesh satasiya
  • 799
  • 8
  • 18
Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37
  • Please provide a MCVE (https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query), to prove that all tables you mention do exist. E.g. inventorydata. – Yunnosch Jan 12 '18 at 08:15
  • did you create the Table? with that code you only have created the DataBase – Reinier Melian Jan 12 '18 at 08:16
  • I created Table and db from sqlite manager GUI. @ReinierMelian – Shivam Tripathi Jan 12 '18 at 08:28

1 Answers1

0

I missed to copy DB file inside App Delegate file.

    [Util copyFile:@"Inventorydb.sqlite"];
Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37