我正在使用xcode 4.5和ios模拟器6.0,我想删除我正在使用的数据库,但我不知道如何。我想要完整地设置数据库。
我读到可以在Macintosh / Library / Application Support / iOS Simulator下删除该文件。但是这个文件夹在我的mac上不存在。
那么如何删除我的数据库?
- (void)createOrOpenDB {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [path objectAtIndex:0];
dbPathString = [docPath stringByAppendingPathComponent:@"WorkoutPlans.db"];
char *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:dbPathString]) {
const char *dbPath = [dbPathString UTF8String];
if (sqlite3_open(dbPath, &workoutPlansDB) == SQLITE_OK) {
const char *sql_cr_wp = "CREATE TABLE IF NOT EXISTS WORKOUTPLANS (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE , DESCRIPTION TEXT NOT NULL UNIQUE)";
const char *sql_cr_en = "CREATE TABLE TABLE IF NOT EXISTS ENTITY (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE , DESCRIPTION TEXT NOT NULL UNIQUE )";
const char *sql_cr_ex = "CREATE TABLE IF NOT EXISTS EXERCISE (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , NAME TEXT NOT NULL UNIQUE , DESCRIPTION TEXT NOT NULL UNIQUE , REPS TEXT NOT NULL , WEIGHT TEXT NOT NULL)";
const char *sql_cr_plen = "CREATE TABLE IF NOT EXISTS WPEN (PLANID, ENID, FOREIGN KEY(PLANID) REFERENCES WORKOUTPLANS(ID) ON DELETE CASCADE, FOREIGN KEY(ENID) REFERENCES ENTITY(ID) ON DELETE CASCADE)";
const char *sql_cr_enex = "CREATE TABLE IF NOT EXISTS ENEX (ENTITYID, EXERCISEID, FOREIGN KEY(ENTITYID) REFERENCES ENTITY(ID) ON DELETE CASCADE, FOREIGN KEY(EXERCISEID) REFERENCES EXERCISE(ID) ON DELETE CASCADE)";
sqlite3_exec(workoutPlansDB, sql_cr_wp, NULL, NULL, &error);
sqlite3_exec(workoutPlansDB, sql_cr_ex, NULL, NULL, &error);
sqlite3_exec(workoutPlansDB, sql_cr_en, NULL, NULL, &error);
sqlite3_exec(workoutPlansDB, sql_cr_plen, NULL, NULL, &error);
sqlite3_exec(workoutPlansDB, sql_cr_enex, NULL, NULL, &error);
sqlite3_close(workoutPlansDB);
}
}
}
答案 0 :(得分:0)
只需在applicationDidFinishLaunching
中调用删除方法即可。
if([fileManager fileExistsAtPath:dbPathString]) {
[fileManager removeItemAtPath:dbPathString error:&error];
}