如何在Sqlite3表中比较两行?

时间:2014-09-03 07:33:33

标签: login sqlite ios7.1

这里我试图比较组成表中的行值的细节。我的表内容[这里是我的表 ] [1] 还有我的代码

`-

     (IBAction)LogIn:(id)sender {

        sqlite3 *dbConnection;
        const char *dbpath = [[sharedobj getSandboxPath] UTF8String];
        sqlite3_stmt    *statement;


        if (sqlite3_open(dbpath, &dbConnection) == SQLITE_OK)
        {
            NSString *querySQL = @"SELECT USERNAME, PASSWORD FROM NEWVALUES";


            const char *query_stmt = [querySQL UTF8String];

            if (sqlite3_prepare_v2(dbConnection,
                                   query_stmt, -1, &statement, NULL) == SQLITE_OK)
            {
                if (sqlite3_step(statement) == SQLITE_ROW)
                {
                     NSString *emailId = [[NSString alloc]
                                initWithUTF8String:
                                (const char *) sqlite3_column_text(statement,0)];
                    NSString *password  = [[NSString alloc]
                                initWithUTF8String:(const char *)
                                sqlite3_column_text(statement, 1)];

                    if ([emailId isEqualToString:self.userNameField.text] || [password isEqualToString:self.passwordField.text]) {
                        NSLog(@"Login Credentials Correct");
                        CHECKViewController *checkobj=[self.storyboard instantiateViewControllerWithIdentifier:@"CHECK"];
                        [self.navigationController pushViewController:checkobj animated:YES];

                    }
                    else{

                           UIAlertView *alert = [[UIAlertView alloc]
                                              initWithTitle:@"Error"
                                              message:@"Login Credentials are Incorrect"
                                              delegate:nil
                                              cancelButtonTitle:nil
                                              otherButtonTitles:@"OK ", nil];
                        [alert show];
                    }
                    }
                    NSLog(@"Login Details %@ %@",self.userNameField.text ,self.passwordField.text );
                }
                sqlite3_finalize(statement);


            }
            else{
                NSLog(@"SQLITE NOT OK");
                NSLog(@"Error %s ", sqlite3_errmsg(dbConnection));
            }
            sqlite3_close(dbConnection);
       }

imgur.com/QW6KX.png

当输入第一行值时它工作但是当我输入第二行值时它没有比较。我在这里做错了什么? 请提出解决此问题的建议。 提前致谢。

0 个答案:

没有答案