0

我正在阅读 sqlite 但无法获取数据,而是显示 nil 值。请参考给定的代码....

-(void)getDatabasePath:(NSString *)dBPath sqlCatagoryId:(NSString *)catId {
     if(sqlite3_open([dBPath UTF8String], &_database) == SQLITE_OK) {
         NSLog(@"database path %@", dBPath);
 NSString *sqlStatement = [NSString stringWithFormat:@"SELECT * FROM SubCategories where CAT_ID = '%@'",catId];

NSString *aCategoryId, *aSubCategoryId, *aSubCategoryName, *aSubCategoryDescription;
 sqlite3_stmt *statement;
     if (sqlite3_prepare_v2(_database, [sqlStatement UTF8String], -1, &statement, nil) 
 == SQLITE_OK) {
         while (sqlite3_step(statement) == SQLITE_ROW) {

             char * str1 = (char *)sqlite3_column_text(compiledStatement, 1);
             if (str1) {
                 aCategoryId = [NSString stringWithUTF8String:str1];
             }
             else {
                 aCategoryId = @"";
             }
             char * str2 = (char *)sqlite3_column_text(compiledStatement, 2);
             if (str1) {
                 aSubCategoryId = [NSString stringWithUTF8String:str2];
             }
             else {
                 aSubCategoryId = @"";
             }
             char * str3 = (char *)sqlite3_column_text(compiledStatement, 3);
             if (str1) {
                 aSubCategoryName = [NSString stringWithUTF8String:str3];
             }
             else {
                 aSubCategoryName = @"";
             }
             char * str4 = (char *)sqlite3_column_text(compiledStatement, 4);
             if (str1) {
                 aSubCategoryDescription = [NSString stringWithUTF8String:str4];
             }
             else {
                 aSubCategoryDescription = @"";
             }

             NSData *aSubCategoryImage;
             NSUInteger blobLength = sqlite3_column_bytes(compiledStatement, 5);
             if(blobLength > 0){
                 aSubCategoryImage = [NSData dataWithBytes:sqlite3_column_blob(compiledStatement, 5) length:blobLength];
             }
             else {
                 aSubCategoryImage = nil;
             }

             SubCategoryModel *subCategoryModel = [[SubCategoryModel alloc] initWithCategoryId:aCategoryId subCategoryId:aSubCategoryId subCategoryName:aSubCategoryName subCategoryDescription:aSubCategoryDescription subCategoryImage:aSubCategoryImage];// database:database
             //Add the details object to the Array   
             [subCategorryArray addObject:subCategoryModel];
              [subCategoryModel release];
        }
 sqlite3_finalize(statement);
     }
    }
     [self.aTableView reloadData];
 }

请指出我哪里出错或为什么我无法从 sqlite 获取数据。谢谢

4

1 回答 1

0

我做错了sqlite3_stmt *statement;sqlite3_stmt * compiledStatement; 我把两者混在一起了sqlite3_stmt

于 2011-08-26T15:25:19.817 回答