iphone中的登录页面问题

iphone中的登录页面问题,iphone,objective-c,sqlite,Iphone,Objective C,Sqlite,我也遇到了同样的问题,其中一个是stackoverflow: if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { //const char *sql ="select Username@'%@',Password@'%@' from userinformation"; NSString *sql = [[NSString alloc] initWithFormat:@"select * from

我也遇到了同样的问题,其中一个是stackoverflow:

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
    //const char *sql ="select Username@'%@',Password@'%@' from userinformation";
    NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where UserName='%@' and Password='%@' ",Username.text,Password.text];
    sqlite3_stmt *selectSatement;

    // Here i am getting the problem.Im not sure why sqlite3_prepare_v2 ins't meeting SQLITE_OK 
    if( sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectSatement, NULL) == SQLITE_OK)
    {
        //-------------------------------------
        //Loop all the 
        NSString *user1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectSatement, 0)];
        NSLog(@"%@",user1);
    }
}

非常感谢您提供的任何帮助。

检查查询本身,在日志中打印查询,并通过从日志中复制查询并直接在数据库中执行来检查查询

首先:如果打开数据库,还应该使用sqlite3\u close(数据库)关闭它

我在下面的代码中写了一个断言语句,它将告诉您,如果您的查询中出现了错误。进一步说,如果出于某种原因,您的密码或用户名为“nil”,则可能会出现错误,这就是为什么我调整了您设置用户名和密码的方式。如果该值不存在,则其“0”

您还应该记住的是,数据库应该存在于预期的路径上,例如通过调用以下方法

-(void) checkAndCreateDatabase
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if([fileManager fileExistsAtPath:dbPath]) return;
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
    [fileManager release];
}

它给了我正确的结果。对于在日志中打印,我使用NSString*sql=[[NSString alloc]initWithFormat:@“从UserInformation中选择*,其中UserName='%@'和Password='%@',UserName.text,Password.text];NSLog(@“%@”,sql);当我在代码上使用断点时。当出现if(sqlite3\u prepare\u v2(数据库,[sql UTF8String],-1,&selectsaement,NULL)==SQLITE\u OK)时,BP会直接从作用域中出来删除where子句并重试..让我知道。。。NSString*sql=[[NSString alloc]initWithFormat:@“从用户信息中选择*”;它给出错误2011-04-06 15:37:24.232 logintes1[18130:207]***在-[logintes1ViewController check]、/Users/HarishYadav/Desktop/logintes1/Classes/logintes1ViewController.m:72 2011-04-06 15:37:24.243 logintes1[18130:207]***由于未捕获的异常“nsinternalinconsistenceexception”终止应用程序,原因:“选择数据时出错:库例程调用顺序不正确”***第一次抛出时调用堆栈:您应该确保tableName和属性写入正确,如果有一个小错误(例如大写字母,因为查询区分大小写),则无法按预期执行查询。
-(void) checkAndCreateDatabase
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if([fileManager fileExistsAtPath:dbPath]) return;
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
    [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
    [fileManager release];
}