0
我正在閱讀sqlite,但無法獲取數據,而是顯示nil值。請參考給定的代碼....sqlite iphone sdk的幫助?
-(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中獲取數據。感謝