开发者

Assertion failure in sqlite3 using XCode, binding problem?

    -(void)updatepw{

databaseName=@"bestfb.sqlite";

NSArray *documnetPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documnetDir =[documnetPath objectAtIndex:0];
databasePath=[documnetDir stringByAppendingPathComponent:databaseName];

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

NSString *update = [[NSString alloc] initWithFormat:@"update staff set pword = %@ where staffID=1;", todb];


sqlite3_stmt *selectstmt;

    const char *sql= (char *) update;
    NSLog(@"new sql :%@", sql);

    NSLog(@"values: %@", newpw.text);



    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) ==SQLITE_OK){
        NSLog(@"prepare failed");
        NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
    }

    else {

        sqlite3_bind_text(selectstmt, 1, [todb UTF8String], -1, SQLITE_TRANSIENT);
        NSLog(@"binding done");

    }

    int success1 = sqlite3_step(selectstmt);        
    if (success1 != SQLITE_DONE) {
        NSAssert1(0, @"Error: failed to save priority with message '%s'.", sqlite3_errmsg(data开发者_JAVA技巧base));
    }
    sqlite3_finalize(selectstmt);

}   
sqlite3_close(database);

    }

Hi all, I've been working on solving the error for hours. I could not get the database to update, it would just crash whenever I tries to update.

Anyone who can help is the most welcome!

Please be gentle, as I am only a newbie to XCode.


I think you have missed the single quotes in the below sentence before and after %@

replace with this.

NSString *update = [[NSString alloc] initWithFormat:@"update staff set pword = '%@' where staffID=1;", todb];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜