How to update a string property of an sqlite database item

Posted by Thomas Joos on Stack Overflow See other posts from Stack Overflow or by Thomas Joos
Published on 2010-03-29T10:31:07Z Indexed on 2010/03/29 10:33 UTC
Read the original article Hit count: 165

Filed under:
|
|
|

hi all,

I'm trying to write an application that checks if there is an active internet connection. If so it reads an xml and checks every 'lastupdated' item ( php generated string ). It compares it to the database items and if there is a new value, this particular item needs to be updated.

My code seems to work ( compiles, no error messages, no failures, .. ) but I notice that the particular property does not change, it becomese (null). When I output the binded string value it returns the correct string value I want to update into the db..

Any idea what I'm doing wrong?

    const char *sql = "update myTable Set last_updated=? Where node_id =?";
    sqlite3_stmt *statement;

    // Preparing a statement compiles the SQL query into a byte-code program in the SQLite library.
    // The third parameter is either the length of the SQL string or -1 to read up to the first null terminator.        
    if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK){
        NSLog(@"last updated item: %@", [d lastupdated]);
        sqlite3_bind_text(statement, 1, [d lastupdated],-1,SQLITE_TRANSIENT);  
        sqlite3_bind_int  (statement, 2, [d node_id]);

    }else {
        NSLog(@"SQLite statement error!");
    }

    if(SQLITE_DONE != sqlite3_step(statement)){
        NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
    }else {
        NSLog(@"SQLite Update done!");
    }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about sqlite