0

I'm using Core Data to manage local DB in my iOS app. But then I have a requirement to insert bulk of records to local DB. So I choose FMDB to perform bulk insertion. But when I tried to insert the record I'm getting this DB Error: 1 "no such table: Table Name. But when I cross checked, the local DB exist there with all the tables that I created in xcdatamodel.

- (FMDatabase *)dbInMainThread{

    if (_dbInMainThread) {
         return _dbInMainThread;
    }

    NSURL *storeURL = [[[CoreDataManager manager] applicationLibraryDirectory] URLByAppendingPathComponent:[DATABASE_NAME stringByAppendingString:@".sqlite"]];
    [self checkDB:[storeURL relativePath]];

    _dbInMainThread = [FMDatabase databaseWithPath:[storeURL relativePath]];
    return _dbInMainThread;
}

-(void) checkDB:(NSString *)dbpath{

    BOOL success;
    NSFileManager * fm = [NSFileManager defaultManager];
    success = [fm fileExistsAtPath:dbpath];

    if (success) return;


    }

Success bool in the above code snippet is always returning true.

I followed the steps in this SO answer. Since I am using Core Data, I don't need to add the DB file to the project. I uninstalled the app, resets the simulator and verified the DB file was in the correct folder before starting insertion. But nothing helps.

What am I missing here

Thanks

Community
  • 1
  • 1
  • there may be a connection problem between app and DB ..have you properly installed fmdb cocoapods .. – vaibhav Aug 22 '16 at 07:02
  • Thanks. Is it possible for FMDB to access DB file created by Core Data ? – Aravind Bhuvanendran Aug 22 '16 at 07:10
  • @vaibhav Yes I installed the FMDB without any issue. Can you specify what exactly is the connection issue ?. It worked well with Core Data before. – Aravind Bhuvanendran Aug 22 '16 at 07:12
  • if it is reused by sqlite so it can be in fmdb have a look of [link](http://stackoverflow.com/questions/9901694/does-core-data-create-a-sqlite-database-file-automatically) and [this one](http://stackoverflow.com/questions/3348206/creating-sqlite-file-from-core-data-store) may gives any solution for .. – vaibhav Aug 22 '16 at 07:25
  • if the table exists inside db and worked well with core data so probably its a connection prob in which unable to find table.. change your ques header may gets attn – vaibhav Aug 22 '16 at 07:36

0 Answers0