-3

Here is my code, and error is visible also:

enter image description here

In SQLite Manager from Mozzila Firefox - all queries work fine which means that DB is correct

Maybe someone can piont me out what is wrong with my code?

EDIT:

My code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"stories_db.sqlite"];

FMDatabase *db = [FMDatabase databaseWithPath:path];
//[db open];
if ([db open]==true)
{
    FMResultSet *resultsFavorite = [db executeQuery:@"SELECT count(*) from favorites"];
    while ([resultsFavorite next])
    {
        Pasaka *pasaka = [[Pasaka alloc]init];
        pasaka.title = [resultsFavorite stringForColumn:@"story_name"];
        pasaka.image = [resultsFavorite stringForColumn:@"image_path"];
        pasaka.movie = [resultsFavorite stringForColumn:@"video_path"];
        [favoriteMovieList addObject:pasaka];
    }

}

EDIT 2:

When i do this query:

FMResultSet *results = [db executeQuery:@"SELECT count(*) FROM sqlite_master"];

it doesn't show any errors.

Cheese
  • 3,865
  • 5
  • 29
  • 58

4 Answers4

0

Reset iOS Simulator or if you are testing on device delete app,

Clean project and run again..

Toseef Khilji
  • 16,458
  • 10
  • 78
  • 115
0

Just go to your document that you have got in the dbpath. seems like you your table is not present there . Just delete your app from device or simulator and manually copy the database at dbpath or copy it using NSFileManager and run your code again .

V-Xtreme
  • 6,775
  • 6
  • 33
  • 76
0

You need to copy your database to your document folder first (also check if your sqlite file was properly added in the Copy Bundle Resources in Build Phases of your project setting):

//Where your original database file is
bundleDatabasePath = [[NSBundle mainBundle] pathForResource:@"stories_db" ofType:@"sqlite"];
//Where you will copy it in order to be used
documentDatabasePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingString:@"/stories_db.sqlite"];

//Using the default file manager
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;

//Copy empty database into document folder
if (![fileManager copyItemAtPath:bundleDatabasePath toPath:databasePath error:&error]) {
    //Error
    NSLog(@"Could not copy the database into document folder. Error:%@", error);
}

//Use DB
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];
Brams
  • 574
  • 4
  • 9
  • Added your code: NSFilePath=/Users/artjomsfomenko/Library/Application Support/iPhone Simulator/7.0/Applications/A6250653-8F87-49CD-97D8-48C200DA6A9B/Pasakas.app/stories_db.sqlite, NSDestinationFilePath=/Users/artjomsfomenko/Library/Application Support/iPhone Simulator/7.0/Applications/A6250653-8F87-49CD-97D8-48C200DA6A9B/Documents/stories_db.sqlite, NSUnderlyingError=0x8a81590 "The operation couldn’t be completed. File exists"} – Cheese Oct 23 '13 at 09:18
  • Can you check the database file into your document folder? Maybe it is an old version of it where the table 'favorites' doesn't exist. Try to reinstall the app to clean your document folder. – Brams Oct 23 '13 at 09:26
  • Interesting thing... i have just deleted DB from project, cleaned my emulator, and it still opens the DB... How can that be? – Cheese Oct 23 '13 at 09:39
  • Which path are you using? Actually, the document folder is not cleaned until you delete your app so maybe you are opening the database from this folder. – Brams Oct 23 '13 at 09:58
0

Found a solution. Moved my database file on top of the project... O.o and it worked...

Cheese
  • 3,865
  • 5
  • 29
  • 58