0

I am reading the sqlite but unable to get data instead it showing nil values. please refer the given code....

-(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];
 }

please point out where I am going wrong or why I am not able to get data from sqlite. thanks

Lion
  • 872
  • 1
  • 17
  • 43

1 Answers1

0

I was doing wrong in sqlite3_stmt *statement; and sqlite3_stmt * compiledStatement; that I mixed the both sqlite3_stmt

Lion
  • 872
  • 1
  • 17
  • 43