Suggestions needed with SQLite

thomaswguy

New member
Jul 15, 2009
3
0
0
Visit site
Hi there, i am new to the forum and would like to ask for help with a problem i am having.

I have a Sqlite database consisting of one table.

The table has 4 columns. I would like to extract from the table details from two columns dependent on another column.

To make that clearer i need to store the details of column 2 + column 3, if column 4 is equal to *variable 1.

I am looking to store this information into two seperate strings so the results from each column can be displayed on two seperate labels.

- I have created the .sql file and loaded it into Xcode
- i have connected to the database

- i now need to get the required details from the database (as explained above)

What i have worked out so far is this:
//connect to the database and open it.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:mad:"Database.sql"];


//this is where i am attempting to get the required details and it all goes a bit wrong :)

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *name = variable1; //set name to my variable
NSString *sqlStr = [NSString stringWithFormat:mad:"select column2, column3 from table where column4 = '%@'", name];

const char *sql = [sqlStr UTF8String]; //convert our objective c string into C ???

sqlite3_stmt *selectStatement; // ???


and thats as far as i get...i have been trauling the web for something similar to give me a clearer picture but was hoping someone here might be able to help :)

From where i left off i am basically trying to get the values of column 2 + 3 stored in two seperate strings .

Any help would be appreciated.

And if any of this does not make sense....let me know :)
 

netsyd

Member
Mar 6, 2009
8
0
0
Visit site
Might I suggest that instead of struggling with SQLite (since you are trying to learn it) - instead try using/learning CoreData. Its a much higher level interaction with the database and you don't have to deal with converting OBJ-C to C and back.

There's some good tutorials around to get you started (keep in mind ones that use Cocoa Bindings do not apply to the iPhone). The Books sample code on the developer site even has a lot of re-useable code you can try, and there's a good amount of documentation in the developer portal as well.
 

thomaswguy

New member
Jul 15, 2009
3
0
0
Visit site
Thanks

Thanks for the info.... sorry for the super late reply but i did not realise anyone had responded.... i was waiting for an E-mail :)
 

Trending Posts

Members online

Forum statistics

Threads
259,860
Messages
1,764,763
Members
441,208
Latest member
janikhan1234