Naveed Rafi
Naveed Rafi

Reputation: 2633

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?

Upvotes: 4

Views: 5172

Answers (1)

falconcreek
falconcreek

Reputation: 4170

Check out 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.

One of the problems of using sqlite directly instead of CoreData which will handle this for you.

Upvotes: 3

Related Questions