>From: Igor Tandetnik <[EMAIL PROTECTED]>
>Subject: Re: Where to look in the code for this ?
>Newsgroups: gmane.comp.db.sqlite.general
>Date: 2006-10-02 21:53:13 GMT (1 hour and 1 minute ago)

>Martin Alfredsson <[EMAIL PROTECTED]> wrote:
>>> Surely you mean "until the process completes its write operation".
>>
>> I wish, but no, the database is locked until the process that writes
>> is terminated.

>I find it hard to believe. Concurrent reads and writes work in my
>experience. I'd look for problems in that other process: perhaps it
>starts a transaction and forgets to end it, or something like that.
>
>Igor Tandetnik

I understand, I to did not understand what happened.
But the code below shows my point (sorry for the horrible indentation).

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.

I do hope this is an error in my setup but I doubt it.

/Martin


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

#include <windows.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;
        char                    szFile[256];


        sprintf(szFile, "boka.dat");

        if (argc != 2)
           {
           printf("Must have parameter");
           return (1);
           }

        if (strcmp(argv[1], "1") == 0)
           {
           if (sqlite3_open(szFile, &db) == SQLITE_OK)
                  {
if (sqlite3_prepare(db, "SELECT * FROM tbookings", -1, &rs, &psz) == SQLITE_OK)
                         {
                         rc = SQLITE_ROW;
                         while (rc == SQLITE_ROW)
                                   {
                                   rc = sqlite3_step(rs);
                                   printf("id = %d, ", sqlite3_column_int(rs, 
0));
                                   }
                         }
printf("About to finalize, do UPDATE now, then press Esc, rc = %d\n", rc);

                  while (getch() != 27)
                                ;

                  sqlite3_finalize(rs);

                  sqlite3_close(db);
                  }
           }

        if (strcmp(argv[1], "2") == 0)
           {
           if (sqlite3_open(szFile, &db) == SQLITE_OK)
                  {
                  printf("Press ENTER to UPDATE the table !\n");
                  while (getch() != 13)
                                ;
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 (getch() != 13)
                                ;
                  }
           }
        }


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

Reply via email to