我在我的項目中使用FMDB,我在終端中構建了第一個sqlite3數據庫,並將其加載到我的項目中。後來我對該數據庫進行了一些更改,因此我將其從項目中刪除(移至垃圾箱),然後再次「添加文件」。但運行結果似乎仍然符合以前的數據庫或有時只是沒有查詢結果。我也嘗試刪除數據庫和運行項目,它仍然運行沒有錯誤...此外,我導入了一個更新的數據庫與另一個名稱,它也無法工作。那麼,我還需要做些什麼來完全刪除objective-c中的數據庫並重新加載一個數據庫?謝謝!如何全面刷新object-c項目中的sqlite數據庫?
我的代碼顯示如下:
- (IBAction)submitButton:(id)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"finalCarpool.db"];
FMDatabase* db = [FMDatabase databaseWithPath:writableDBPath];
NSLog(@"Is SQLite compiled with it's thread safe options turned on? %@!", [FMDatabase isSQLiteThreadSafe] ? @"Yes" : @"No");
if (![db open]) {
NSLog(@"Could not open db.");
}
FMResultSet *rs = [db executeQuery:@"select * from userinfo"];
int count=0;
while ([rs next]) {
count++;
NSLog(@"%i",count);
}
FMResultSet *rs2 = [db executeQuery:@"select id from userinfo where username = ? AND password= ?", usernameTextField.text,passwordTextField.text];
if ([rs2 next]) {
NSString *welcomeMessage=[[NSString alloc]initWithFormat:@"Welcome, %@",usernameTextField.text];
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:@"Successfully Login!"
message:welcomeMessage
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[myAlert show];
[self.loginDelegate backToLaunch];
}
else {
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle:@"Something is wrong..."
message:@"Your username and/or password doesn't match!Please try again!"
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[myAlert show];
usernameTextField.text=Nil;
passwordTextField.text=Nil;
}
[usernameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
}
是的,我找到它並從模擬器和目錄路徑中刪除了應用程序。但項目仍然沒有結果(不輸出結果集),而我確信數據庫中有數據。我有兩個問題:1)重新加載數據庫,我是否應該只需要刪除模擬器中的前一個應用程序,還可以通過項目導航器刪除並添加新的數據庫? 2)我正在使用[FMDB](https://github.com/ccgus/fmdb),我可以刪除fmdb.m並使用上面顯示的類資源嗎?或者我需要做一些修改來查詢和更新? – omic 2013-04-11 03:35:22