Welcome to the iMore Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 3 of 3
  1. Thread AuthorThread Author   #1  
    thomaswguy's Avatar
    iPhone Nanite

    3 Posts

    Default Suggestions needed with SQLite

    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(NSDocumentDire ctory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"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:@"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
  2. #2  
    netsyd's Avatar
    iPhone Nanite

    8 Posts
    Global Posts
    12 Global Posts


    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.
  3. Thread AuthorThread Author   #3  
    thomaswguy's Avatar
    iPhone Nanite

    3 Posts

    Default 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

Posting Permissions