我在我的应用程序中使用 sqlite 数据库。在我的 sqlite 中存在 10 条记录。我想从这个数据库中读取 4 个数据,并且我想获取这些数据,直到最后一个数据中的 BroID 为 NULL(BroID 是列数据之一)这是我的代码,但我不知道如何在我的代码中使用循环,直到 BroID 成为无效的。
-(NSMutableArray *)readInformationFromDatabase
{
array = [[NSMutableArray alloc] init];
// Setup the database object
sqlite3 *database;
// Open the database from the users filessytem
if(sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK)
{
// I want to use loop for certain work!!! (this work is get name from data base until BroID to be NULL )
NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"Select * from table1"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement_userInfo UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
// Init the Data Dictionary
NSMutableDictionary *_dataDictionary=[[NSMutableDictionary alloc] init];
NSString *_userName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_userName] forKey:@"Name"];
[array addObject:_dataDictionary];
}
}
else
{
NSLog(@"No Data Found");
}
请告诉我完成此代码的想法。