通过iPhone中的sqlite从数据库中选择值

通过iPhone中的sqlite从数据库中选择值,iphone,select,sqlite,Iphone,Select,Sqlite,我正在使用sqlite开发一个iphone应用程序。在这里,我有一个从部分显示的表中检索值的方法 NSString *sqlQuery = [NSString stringWithFormat: @”select * from %@”, tableName]; If(sqlite3_prepare_v2(db, [sqlQuery UTF8STRING] , -1, &statement, NULL)== SQLITE_OK) { While(sqlite3_step(statement

我正在使用sqlite开发一个iphone应用程序。在这里,我有一个从部分显示的表中检索值的方法

NSString *sqlQuery = [NSString stringWithFormat: @”select * from %@”, tableName];
If(sqlite3_prepare_v2(db, [sqlQuery UTF8STRING] , -1, &statement, NULL)== SQLITE_OK)
{
While(sqlite3_step(statement) == SQLITE_ROW)
{
}
Sqlite3_finalize(statement);
}
我怀疑的是,在while循环中,我们可以通过表的索引获得列的值,如下面的代码所示

NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
address.text = addressField;
对于一个列,我们可以这样检索。在我的例子中,我不知道要检索的列数。在这种情况下,如何在列上迭代。请帮帮我。 谢谢。

NSString*sqlQuery=[nsstringstringwithformat:@“select*from%@”,tableName];
If(sqlite3\u prepare\u v2(db,[sqlQuery UTF8STRING],-1,&语句,NULL)==SQLITE\u OK)
{
While(sqlite3\u步骤(语句)=SQLITE\u行)
{
int columnCount=YouKnowColumnCount;
NSMUTABLEARRY*array=[[NSMUTABLEARRY alloc]init];
对于(int i=0;i
NSString*sqlQuery=[nsstringstringwithformat:@“select*from%@”,tableName];
If(sqlite3\u prepare\u v2(db,[sqlQuery UTF8STRING],-1,&语句,NULL)==SQLITE\u OK)
{
While(sqlite3\u步骤(语句)=SQLITE\u行)
{
int columnCount=YouKnowColumnCount;
NSMUTABLEARRY*array=[[NSMUTABLEARRY alloc]init];

对于(int i=0;i认为您必须知道列的计数,或者在应用程序工作期间添加它们???您可以将列的计数存储在某个位置,然后编写i think while循环用于行数,而不是列数,我的朋友。@vito brothers:是的,它就像一个泛型类。@dks1725。是的,该循环仅用于行。但我们需要o知道要检索的列名。我想你必须知道列的计数,或者在应用程序工作期间添加它们???你可以将列的计数存储在某个地方,然后编写我认为while循环用于行数,而不是列数,我的朋友。@vito brothers:是的,它就像一个泛型类。@dks1725。是的,该循环用于行。但我们需要知道要检索的列名。
NSString *sqlQuery = [NSString stringWithFormat: @”select * from %@”, tableName];
If(sqlite3_prepare_v2(db, [sqlQuery UTF8STRING] , -1, &statement, NULL)== SQLITE_OK)
{
While(sqlite3_step(statement) == SQLITE_ROW)
{
int columnCount = YouKnowColumnCount;
NSMutableArray* array = [[NSMutableArray alloc]init];

for( int i=0; i<columnCount ; ++i) {
    [array addObject:[[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, i)]];
}
Sqlite3_finalize(statement);
}