Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在iphone sqlite选择查询中没有这样的表时出错?_Ios_Iphone_Sqlite - Fatal编程技术网

Ios 在iphone sqlite选择查询中没有这样的表时出错?

Ios 在iphone sqlite选择查询中没有这样的表时出错?,ios,iphone,sqlite,Ios,Iphone,Sqlite,我有一个选项卡式iPhone应用程序。在第一个选项卡中,我创建了sqlite表,并向表中插入了值,这些操作都成功完成。在第二个选项卡中,我可以从表中获取值,但在第三个类中,当我执行select查询时,我会得到“无此类表”异常。 甚至我从模拟器中删除了应用程序并清理了项目,但我也遇到了同样的问题。 请给我解答 创建和插入的编码: -(void)InsertLoginDetails:(NSString *)user fun:(NSString *)pwd{ sqlite3_stmt *sta

我有一个选项卡式iPhone应用程序。在第一个选项卡中,我创建了sqlite表,并向表中插入了值,这些操作都成功完成。在第二个选项卡中,我可以从表中获取值,但在第三个类中,当我执行select查询时,我会得到“无此类表”异常。 甚至我从模拟器中删除了应用程序并清理了项目,但我也遇到了同样的问题。 请给我解答

创建和插入的编码:

-(void)InsertLoginDetails:(NSString *)user fun:(NSString *)pwd{

sqlite3_stmt    *statement;
const char *dbpath = [_databasePath UTF8String];

if (sqlite3_open(dbpath, &_contactDB) == SQLITE_OK)
{

    NSString *insertSQL = [NSString stringWithFormat:
                           @"INSERT INTO Login ( USERNAME, PASSWORD) VALUES (\"%@\", \"%@\")",
                           user, pwd];

    const char *insert_stmt = [insertSQL UTF8String];
    sqlite3_prepare_v2(_contactDB, insert_stmt,
                       -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        NSLog(@"Inserted");

    } else {
        NSLog(@"Failed to insert");
    }
    sqlite3_finalize(statement);
    sqlite3_close(_contactDB);
}
-(void)checkLoginSession{
///////////////GET DB DATAS///////////////////////

const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt    *statement;

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


    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(_contactDB,
                           query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            strDBUsername = [[NSString alloc]
                             initWithUTF8String:
                             (const char *) sqlite3_column_text(
                                                                statement, 0)];
            strDBPwd = [[NSString alloc]
                        initWithUTF8String:(const char *)
                        sqlite3_column_text(statement, 1)];
            NSLog(@"Settings page Login Details %@ %@", strDBUsername , strDBPwd );
            //                _address.text = addressField;
            //
            //                _phone.text = phoneField;
            //                _status.text = @"Match found";
        } else {
            //                _status.text = @"Match not found";
            //                _address.text = @"";
            //                _phone.text = @"";
        }
        sqlite3_finalize(statement);
    }
    else{
        NSLog(@"SQLITE NOT OK");
        NSLog(@"Error %s ", sqlite3_errmsg(_contactDB));
    }
    sqlite3_close(_contactDB);
}
}

}

获取值的代码:

-(void)InsertLoginDetails:(NSString *)user fun:(NSString *)pwd{

sqlite3_stmt    *statement;
const char *dbpath = [_databasePath UTF8String];

if (sqlite3_open(dbpath, &_contactDB) == SQLITE_OK)
{

    NSString *insertSQL = [NSString stringWithFormat:
                           @"INSERT INTO Login ( USERNAME, PASSWORD) VALUES (\"%@\", \"%@\")",
                           user, pwd];

    const char *insert_stmt = [insertSQL UTF8String];
    sqlite3_prepare_v2(_contactDB, insert_stmt,
                       -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        NSLog(@"Inserted");

    } else {
        NSLog(@"Failed to insert");
    }
    sqlite3_finalize(statement);
    sqlite3_close(_contactDB);
}
-(void)checkLoginSession{
///////////////GET DB DATAS///////////////////////

const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt    *statement;

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


    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(_contactDB,
                           query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            strDBUsername = [[NSString alloc]
                             initWithUTF8String:
                             (const char *) sqlite3_column_text(
                                                                statement, 0)];
            strDBPwd = [[NSString alloc]
                        initWithUTF8String:(const char *)
                        sqlite3_column_text(statement, 1)];
            NSLog(@"Settings page Login Details %@ %@", strDBUsername , strDBPwd );
            //                _address.text = addressField;
            //
            //                _phone.text = phoneField;
            //                _status.text = @"Match found";
        } else {
            //                _status.text = @"Match not found";
            //                _address.text = @"";
            //                _phone.text = @"";
        }
        sqlite3_finalize(statement);
    }
    else{
        NSLog(@"SQLITE NOT OK");
        NSLog(@"Error %s ", sqlite3_errmsg(_contactDB));
    }
    sqlite3_close(_contactDB);
}

请输入相关代码,否则我们如何识别问题?请删除应用程序并重新安装。请在所有三种情况下记录数据库路径(使用
NSLog()
),并确保它们都匹配。另外,请忘记
fileExistsAtPath
检查;如果数据库不存在,sqlite将创建数据库,并且您的代码基本上假设数据库的存在与表的存在相同。这是不正确的。您应该初始化一次
\u databasePath
,并且可能在早期的应用程序委托方法中进行初始化。