1

Actually I am not sure there is a problem but, I have some data and I want to insert it to database.

Code seems to works well, every statement works, there are no errors shown but I cant see the data in database. It doesn't insert the data to database but in code it is shown as data is inserted.

Is there a setting related with database? I am using Sqlite Firefox Add-on. When selecting records there are no problems. I checked the .sqlite file's permissions but it is setted to read & write.

Sorry, I forgot to add code snippet;

   NSString *stmt=[NSString stringWithFormat:@"INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(%d, %d, %d, %d, %d, %d, %d)", 0,exam_id,0,0,0,0,0];
        [stmt UTF8String];
        const char *sql=(const char *) [stmt UTF8String];
        //const char *sql= "INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(?,?,?,?,?,?,?)";

    sqlite3_stmt *statement;

    sqlite3_prepare_v2(database, sql, -1, &statement, NULL);

    if (sqlite3_step(statement) == SQLITE_DONE)
        NSLog(@"SQLITE statement executed");
    else 
        NSLog(@"ERROR!!");

    sqlite3_finalize(statement);
1
  • Have you got uncommitted transactions? Commented Apr 6, 2011 at 14:11

2 Answers 2

1

Given that this is tagged for iPhone dev I would recommend using an objective c wrapper for sqlite like FMDB. FMDB is very lightweight and widely used (check it out on github: https://github.com/ccgus/fmdb/) and will simplify this whole process for you.

Here is an example of a simple insert with FMDB:

self.db = [FMDatabase databaseWithPath:fullPath];

 if (![db open]) {
     NSLog(@"DB Open Failed");
     return NO;
 }

[db executeUpdate:@"INSERT INTO TestTable (id, value) VALUES (?,?)", [NSNumber numberWithInt:1], @"SomeString"];

[db close];
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you are messaging nil when adding the data (assuming you use Obj-C)? That's not an error, but it also doesn't do anything. More info or code snippet needed for more specific answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.