我有一个包含数据的表。
id type
1 max
1 sam
1 rom
2 jak我想检索id=1;所在位置的所有type
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *aRecord = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSLog (@"%@",aRecord);
}这条语句只检索最后一条记录。我怎样才能得到所有的记录?
how to catch these records in the variable. I am using aRecord but it store only last record. So this is the main concern发布于 2010-08-30 23:03:54
sql ro执行此操作很简单:
select * from <table_name> where id = 1 这样做:
NSMutableString *myRecords = [NSMutableString initWithString:@""];
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *aRecord = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
myRecords = [myRecords stringByAppendingString:[NSString stringWithFormat:@"%@ ",arecord]];
NSLog (@"%@",aRecord);
} 正如Peter Hosey在评论中指出的那样,这将为您提供一个字符串,其中所有三条记录都由空格分隔。您可能希望用这些记录填充数组。
https://stackoverflow.com/questions/3601554
复制相似问题