Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 调用sql语句时出错_Ios_Sqlite - Fatal编程技术网

Ios 调用sql语句时出错

Ios 调用sql语句时出错,ios,sqlite,Ios,Sqlite,我得到一个奇怪的错误,我有我的代码从本地数据库获取数据 我的问题如下 SELECT * FROM Survey_Details Where feedBack_status="YES" 当我触发上面的查询时,函数会给出正确的输出。但是当我传递NO时,它会给我一个错误 以下是我的功能 -(NSMutableArray*)selectFromDBAndAddtoArrayForFeedbackStatus:(NSString *)feedBackStatus { NSMuta

我得到一个奇怪的错误,我有我的代码从本地数据库获取数据

我的问题如下

SELECT * FROM Survey_Details Where feedBack_status="YES"
当我触发上面的查询时,函数会给出正确的输出。但是当我传递NO时,它会给我一个错误

以下是我的功能

 -(NSMutableArray*)selectFromDBAndAddtoArrayForFeedbackStatus:(NSString *)feedBackStatus
    {
       NSMutableArray *TableArray = [[NSMutableArray alloc]init];
       sqlite3_stmt    *statement;


    const char *dbpath = [databasePath UTF8String];
    if (sqlite3_open(dbpath, &passionDB) == SQLITE_OK)
    {

        NSString *insertSQL = [NSString stringWithFormat: @"SELECT * FROM Survey_Details Where feedBack_status != \"%@\"",feedBackStatus];
        NSLog(@"insert stmnt %@", insertSQL);
        const char *insert_stmt = [insertSQL UTF8String];


    if(sqlite3_prepare_v2(passionDB, insert_stmt, -1, &statement, nil)== SQLITE_OK)
        {
            NSLog(@"SQLITE_OK");
            if (SQLITE_ROW != sqlite3_step(passionDB))
            {

            }
            else{

            }
            while(sqlite3_step(statement) == SQLITE_ROW)
            {
                NSMutableArray *editTableArray = [[NSMutableArray alloc]init];

                NSString *title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];

                NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];

                NSString *surname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];

                NSString *time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 14)];

                // NSString *user_ID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];

                NSNumber *user_ID = [NSNumber numberWithInt:(int)sqlite3_column_int(statement, 1)];


                [editTableArray addObject:title];
                [editTableArray addObject:name];
                [editTableArray addObject:surname];
                [editTableArray addObject:time];
                [editTableArray addObject:user_ID];

                NSString *imagePath;

                if ([feedBackStatus isEqualToString:@"YES"])
                {

                    if(sqlite3_column_text(statement, 13) != nil)
                    {
                        imagePath = [NSString stringWithUTF8String:(char    *)sqlite3_column_text(statement, 13)];
                    }
                    else
                    {
                        imagePath = @"none";
                    }
                    [editTableArray addObject:imagePath];
                }


                [TableArray addObject:editTableArray];
                editTableArray=nil;

            }

            NSLog(@"TableArray1 is %@",TableArray);
        }

        if (sqlite3_step(statement) == SQLITE_DONE)

        {
            NSLog(@"sqlite is done");
            NSLog(@"Error %s while sqlite3_step ", sqlite3_errmsg(passionDB));
        } else {
            NSLog(@"sqlite is not  done");
            NSLog(@"Error %s while sqlite3_step ", sqlite3_errmsg(passionDB));
        }
        sqlite3_finalize(statement);
        sqlite3_close(passionDB);
    }
    NSLog(@"TableArray2 is %@",TableArray);
    return TableArray;
    }
尝试使用以下查询:

  NSString *status= @"NO";

NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM Survey_Details WHERE feedBack_status ='%@'",status];

查看此查询是否适用。

您是否能够使用sqlite broweser查看数据库中的数据?只是为了确保您的数据库不包含任何值提供有关错误的详细信息。如果对sqlite3_prepare_v2的调用失败,您应该记录错误。如果SQLITE_ROW!=sqlite3_数据库?1不能将数据库指针传递给sqlite3\u步骤。2该行应该用于什么?不要使用stringWithFormat生成查询。使用适当的sqlite3\u bind\u xxx函数将值正确绑定到查询中。