Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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
Iphone sqlite3\u prepare\u v2语句不是SQLITE\u OK,我不知道为什么_Iphone_Objective C_If Statement_Sqlite - Fatal编程技术网

Iphone sqlite3\u prepare\u v2语句不是SQLITE\u OK,我不知道为什么

Iphone sqlite3\u prepare\u v2语句不是SQLITE\u OK,我不知道为什么,iphone,objective-c,if-statement,sqlite,Iphone,Objective C,If Statement,Sqlite,我的viewWillExample方法中有以下代码: sqlite3 *database; if (sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) { sqlite3_close(database); NSAssert(0, @"Failed to open database"); } sqlite3_stmt *statement; //why is this

我的viewWillExample方法中有以下代码:

 sqlite3 *database;
if (sqlite3_open([[self dataFilePath] UTF8String], &database)
    != SQLITE_OK) { 

    sqlite3_close(database);
    NSAssert(0, @"Failed to open database");
}
sqlite3_stmt *statement;

//why is this if statement failing?
if (sqlite3_prepare_v2(database, [sqlStatement UTF8String],
                       -1, &statement, nil) == SQLITE_OK) {
它传递第一个if语句,但不输入哪个是好的。第二个if语句就是问题所在

sqlStatement的格式为SELECT*FROM food,其中foodType='FROURT'
我不明白为什么它没有进入if语句。任何帮助都将不胜感激

并根据您的要求进行更改

-(void) readDataFromDatabase
{
    chapterAry = [[NSMutableArray alloc] init];

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

    NSString *documentsDir = [documentPaths objectAtIndex:0];

    databasePath = [documentsDir stringByAppendingPathComponent:@"QuotesApp.sqlite"];

    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
    {
        const char *sqlStatement ="select * from MsExcelTutorial";

        sqlite3_stmt *compiledStatement;

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            while(sqlite3_step(compiledStatement)==SQLITE_ROW)
            {
                NSNumber *chapterId = [NSNumber numberWithInt:(int)sqlite3_column_int(compiledStatement, 0)];

                NSString *chapter = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

                NSString *link = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];

                NSString *bookmark = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

                NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:chapterId,@"chapterId",chapter,@"chapter",link,@"link",bookmark,@"bookmark", nil];

                [chapterAry addObject:dic];
            }
        }
        sqlite3_finalize(compiledStatement);
    }
    sqlite3_close(database);
}

仔细检查它会起作用的

问题不在代码中,而在我导出sqlite文件的方式中。这是一个关于INSERT语句的系列,而不是一个实际的表。

在我们提供帮助之前,您需要做更多的调查。sqlite3\u prepare\u v2实际返回的是什么,而不仅仅是SQLITE\u OK?sqlite3_errmsg说什么?我可以问其他问题你的模式是什么?SQL是否包含尾随分号?您使用的是什么线程模型?但这些都是暗中操作,没有更多信息。当您进行调查时,很可能会发现这一点。sqlite\u prepare\u v2返回1,sqlite3\u errmsg只是说没有这样的表:水果。然而,我知道桌子在那里。这个问题一直困扰着我,您是否使用sqlite3命令行工具验证了表格?您给出的SELECT示例从食物中读取数据,您说您在表格水果方面有错误。确保你对食物和水果没有问题:-你为什么要手写SQLite?浪费时间。使用核心数据,或者至少使用类似FMDB的数据。
NSString *DBPath = [ClsCommonFunctions GetDatabasePath];
if ([self OpenDBWithPath:DBPath])//Method to open database connection
{
//filesDB is database object 
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = "select fileID,filePath from tblFiles where  isUploadPending =1";
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(filesDB, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

        while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
        {
            // u Need to get data from database...                


        }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);
    sqlite3_close(filesDB);
}