我创建了一个类方法,但它不显示数据。
当我这样做时,它在控制台中显示空值:
NSLog(@"full and array data :- %@",[array ObjectAtIndex:0]);
“字典”(它是 NSMutableDictionary 的对象)显示数据,但是当我使用以下方法将此对象添加到“数组”(它是 NSMutableArray 的对象)中时:
[array addObject:dict];
在此行之后,当我打印NSLog(@"array data :- %@",[array objectAtIndex:0] );
数组的值(使用)时,它显示了“空”值。
+(NSMutableArray *)showAllDetail:(NSString *)query{
sqlite3 *stmnt;
NSMutableArray *array;
NSString *databasepath=[database getDatabasePath];
if (sqlite3_open([databasepath UTF8String], &stmnt)) {
NSLog(@"database not open......");
}
else{
const char *queryStmt=[query UTF8String];
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(stmnt, queryStmt, -1, &stmt, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt)==SQLITE_ROW) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
const char *text;
text=(char *)sqlite3_column_text(stmt,1);
//NSLog(@"text :- %s",text);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"id"];
//NSLog(@"dictionary with id : - %@",dictionary);
}
text=(char *)sqlite3_column_text(stmt,2);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"name"];
// NSLog(@"dictionary with name : - %@",dictionary);
}
text=(char *)sqlite3_column_text(stmt,3);
if (text!=NULL) {
[dictionary setObject:[NSString stringWithUTF8String:text] forKey:@"dob"];
// NSLog(@"dictionary with dob: - %@",dictionary);
}
NSLog(@"in the dic :- %s",text);
NSLog(@"dictionary data :- %@",dictionary);
//------------------------------------------------
//---------this show the result data dictionary --
//------------------------------------------------
[array addObject:dict];
NSLog(@"array data :- %@",[array objectAtIndex:0] );
//------------------------------------------------------------
//---------this show the result :- "full and array data :- null"
//---------------------------------------------------------------
dict=nil;
}
}
sqlite3_finalize(stmt);
if ([array count]>0) {
return array ;
}
else
return nil;
}
return nil;
}
我的输出是: -
2013-10-29 17:30:32.644 myCRUD[1231:a0b] dictionary data :- {
id = 1;
name = naresh;
dob = "10/10/1990";
}
2013-10-29 17:30:32.645 myCRUD[1231:a0b] array data :- (null)