简体   繁体   English

在SQLite中按列名获取?

[英]Get by column names in SQLite?

Currently I am getting the values from statement like this: 目前我从这样的语句中获取值:

[[NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,0)] retain];

I want to get the values by entering the column name like this: 我想通过输入列名来获取值,如下所示:

[[NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement,@"FirstColumn")] retain];

Is there any way to do this? 有没有办法做到这一点?

Check out http://sqlite.org/c3ref/column_name.html . 查看http://sqlite.org/c3ref/column_name.html You will have to iterate over the column indices returned by the query to add the column names to an array or dictionary that you can reference later to lookup the column index given a name to provide to the column_text function which only accepts the column index as an integer parameter. 您将不得不迭代查询返回的列索引,以将列名称添加到稍后可以引用的数组或字典中,以查找给定名称的列索引,以提供给column_text函数,该函数仅接受列索引作为整数参数。

One of the problems of using sqlite directly instead of CoreData which will handle this for you. 直接使用sqlite而不是CoreData的问题之一,它将为您处理此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM