Martin Alfredsson <[EMAIL PROTECTED]> wrote:
> 
> I understand, I to did not understand what happened.
> But the code below shows my point (sorry for the horrible indentation).

Rather than apologize, why not just fix it?  Is your time so
much more valuable than ours that you cannot be troubled with
such mundane work?

> 
> You need a database to run it and two tables in it, you start two 
> instances, one with parameter 1 (the SELECT) and one with 2 (the UPDATE).
> 
> When the first instance says "About to finalize..." press enter in to
> other instance. Now the database will be locked until you exut the
> second instance. If you add explicit transactions before/after
> sqlite3_prepare/sqlite3_finalize the problem will go away.
> 

Unable to reproduce.  I followed these instructions exactly
and everything works fine for me.  My code (with correct
indentation and a bug fix) follows:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlite3.h>


/*-----------------------------------------------------------------------------
//   main: Entrypoint into this program.
//---------------------------------------------------------------------------*/
int main(int argc, char **argv){
  sqlite3 *db;
  sqlite3_stmt *rs;
  const char *psz;
  int rc;
  static const char *zFile = "boka.dat";

  if (argc != 2){
    printf("Must have parameter");
    return (1);
  }
  if (strcmp(argv[1], "1") == 0){
    if (sqlite3_open(zFile, &db) == SQLITE_OK){
      rc = sqlite3_prepare(db, "SELECT * FROM tbookings", -1, &rs, &psz);
      if( rc==SQLITE_OK ){
        while( (rc=sqlite3_step(rs))==SQLITE_ROW ){
          printf("id = %d\n", sqlite3_column_int(rs, 0));
        }
      }
      printf("About to finalize, do UPDATE now, then press ENTER."
             " rc = %d\n", rc);
      while (getchar() != '\n'){}
      sqlite3_finalize(rs);
      sqlite3_close(db);
    }
  }

  if (strcmp(argv[1], "2") == 0){
    if (sqlite3_open(zFile, &db) == SQLITE_OK){
       printf("Press ENTER to UPDATE the table !\n");
       while (getchar() != '\n'){}
       rc = sqlite3_exec(db, "UPDATE tcompany SET company = 'UPDATE'", 
                              NULL, NULL, NULL);
       printf("sqlite3_exec = %d\n", rc);
       sqlite3_close(db);
       printf("Press ENTER to exit !\n");
       while (getchar() != '\n'){}
    }
  }
}

--
D. Richard Hipp   <[EMAIL PROTECTED]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to