在iPhone中通过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_ROW)
{
}
Sqlite3_finalize(statement);
}
我的疑问是,在 while 循环内我们可以通过表的索引获取列的值,如下代码所示。
NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
address.text = addressField;
对于一列,我们可以这样检索。就我而言,我不知道要检索的列数。在这种情况下,如何迭代列。请帮帮我。 谢谢。
I am developing an iphone application using sqlite. In that, I have a method to retrieve the values from the table which is shown partially.
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);
}
What my doubt is , inside the while loop we can get the values of the column through the index of the table like the following code.
NSString *addressField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
address.text = addressField;
For one column we can retrieve like this. In my case, I don’t know the number of columns to be retrieved. In this case, how to iterate over the columns. Please help me out.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的事情取决于你想做什么......
Something like this it depend what do you want to do ...