在我的iOS应用程序中,我能够创建一个包含两个表的数据库,并将数据插入到各自的行/列中。我在此while(sqlite3_step(statement) == SQLITE_OK)
循环中获取数据时遇到问题。
获取数据的实例方法如下:
-(NSArray)findData:(NSString*) rowID
{
int rowNumber = 0;
const char *dbpath = [databasePath UTF8String];
if(sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:"@SELECT T1.ID, T1.X, T1.Y, T2.ID, T2.A, T2.B FROM T1 JOIN T2 ON T1.ID = T2.ID WHERE T1.ID = \"%@\"",rowID];
const char* query_stmt = [querySQL UTF8String];
NSMutableArray *returnArray = [[NSMutableArray alloc]init];
if(sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL)==SQLITE_OK)
{
int columnCount = sqlite3_column_count(statement)
NSLog (@"Total number of columns:%d", comumnCount);
while(sqlite3_step(statement) == SQLITE_ROW)
{
rowNumber++;
NSlog(@"Rownumber is: %d", rowNumber);
for(int a=1; a<columnCount; a++)
{
NSString *field = [[NSString alloc] initWithUTF8String:(cont char*) sqlite3_column_text(statement,a)];
[returnArray addObject:field];
}
}
sqlite3_finalize(statement);
sqlite3_close(database);
return returnArray;
}
}
return nil;
}
这里,if
条件sqlite3_prepare_v2是好的。它工作正常,并打印columnCount
。但是,while
循环不起作用。它只从一个表中获取数据时工作正常。是否有任何要添加到多个表的条件?