开发者

sqlite3 no insert is done after --> insert into --> SQLITE_DONE

I'm trying to insert some data in a table using sqlite3 on an iphone... All the error codes I get from the various steps indicate that the operation should have been successful, but in fact, the table remains empty...I think I'm missing something...

here the code:

sqlite3 *database = nil;
NSString *dbPath = [[[ NSBundle mainBundle ] resourcePath ] stringByAppendingPathComponent:@"placemarks.sql"];

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

sqlite3_stmt *insert_statement = nil;
//where int pk, varchar name,varchar description, blob picture
开发者_如何学Cstatic char *sql = "INSERT INTO placemarks (pk, name, description, picture) VALUES(99,'nnnooooo','dddooooo', '');";
    if (sqlite3_prepare_v2(database, sql, -1, &insert_statement, NULL) != SQLITE_OK) {
        NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
    }

int success = sqlite3_step(insert_statement);

int finalized = sqlite3_finalize(insert_statement);

NSLog(@"success: %i finalized: %i",success, finalized);

NSAssert1(101, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));


sqlit3_step returns 101, so SQLITE_DONE, which should be ok..

If I execute the sql statement in the command line it works properly...

anyone has an idea? could it be that there's a problem in writing the placemarks.sql because it's in the resources folder?

rgds

Fra


Found out what it was! as I thought...I cannot modify a *.sql that is in the resources folder, I have to first make a copy in the application's documents and use that copy!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜