0

我在我的项目中使用 FMDB,我在终端中构建了第一个 sqlite3 数据库,并将其加载到我的项目中。后来我对该数据库进行了一些更改,因此我将其从项目中删除(移动到垃圾箱),然后再次“添加文件”。但是运行结果似乎还是和以前的数据库一致,或者有时只是没有查询结果。我还尝试删除数据库并运行项目,它仍在运行且没有错误...此外,我导入了另一个名称的较新数据库,它也无法工作。那么我需要做些什么来完全删除objective-c中的数据库并重新加载一个吗?谢谢!

我的代码如下所示:

- (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];

}

4

2 回答 2

0

如果您在模拟器上进行测试,则数据库路径为

~/Library/Application Support/iPhone Simulator/<SIMULATOR-VERSION>/Applications/<APP-NAME>/Documents/finalCarpool.db

您可以从那里删除它。否则,您可以从模拟器中删除应用程序(与从 iPhone 中删除的方式相同)。

于 2013-04-10T21:56:54.967 回答
0

转到 Ios Simulator> ResetContent 和设置

于 2013-08-26T12:47:37.633 回答