2013-10-23 159 views
0

你好我正在使用FMDB來使用SQLite數據庫。我有下一個代碼:iPhone上的SQLite數據庫

FMDatabase *db = [FMDatabase databaseWithPath:@"stories_db.sqlite"]; 
[db open]; 
FMResultSet *resultsFavorite = [db executeQuery:@"SELECT * from favorites"]; 

但是在[db open]上顯示錯誤;

2013年10月23日11:08:22.951 Pasakas [1013:A0B]錯誤開口!:14

enter image description here

也許我應該改變路徑?

回答

2

你必須給路徑數據庫的沒有名字的數據庫,

嘗試

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]; 
FMResultSet *resultsFavorite = [db executeQuery:@"SELECT * from favorites"]; 
+2

+1不過在此之前......你要複製你的本地數據庫文件,文檔目錄..很棒.. –

+0

2013-10-23 11:20:24.211 Pasakas [1093:a0b] DB Error:1「no such table:favorites」 2013-10-23 11:20:24.212 Pasakas [1093:a0b]數據庫查詢:從收藏夾SELECT * 2013-10-23 11:20:24.213 Pasakas [1093:a0b]數據庫路徑:/ Users/artjomsfomenko/Library/Application Support/iPho ne Simulator/7.0/Applications/645A59FD-1667-4A4B-8B24-EF87C2A3D271/Documents/stories_db.sqlite – Cheese

+0

CREATE TABLE「offline」(「_id」TEXT PRIMARY KEY NOT NULL UNIQUE,「story_name」TEXT NOT NULL,「video_path」TEXT ,「image_path」TEXT) – Cheese