views:

252

answers:

1

Hi all

I have an sqlite database I am writing and reading from. Most of the time I am writing, but occasionally I read something.

The routine for writing (skeletonized, error checking removed etc..) goes something like this: st1 and st2 are already prepared along with the initialization of the database.

-(BOOL) saveHvalue:(int) fid time:(int) t value:(double) v type:(int) ftype
{

    {
     sqlite3_bind_int(st1, 1, fid);
     sqlite3_bind_int(st1, 2, t);
     sqlite3_bind_int(st1, 3, ftype);
     sqlite3_bind_double(st1, 4, v);


     sqlite3_step(st1);
     sqlite3_reset(st1);
     sqlite3_clear_bindings(st1);
    }

    return YES;
}

The routine for reading is:

-(double) getHvalue:(int) fid time:(int) t type:(int) ftype
{
    double v=0;

    {
     sqlite3_bind_int(st2, 1, fid);
     sqlite3_bind_int(st2, 2, t);
     sqlite3_bind_int(st2, 3, ftype);
     sqlite3_step(st2);
     v = sqlite3_column_double(st2, 0);

        sqlite3_reset(st2);
        sqlite3_clear_bindings(st2);
        return v;
}

Most of the time I am using saveHvalue, but occasionally I read back something. The instant I try this the journal file created fails to go away and it seems the writing is killed immediately.

Do I need to do something to transition between writing and reading?

+1  A: 

Have you tried executing a COMMIT (e.g. with sqlite3_exec) after each write completes?

Alex Martelli