Maybe I'm really slow today, but I don't understand one important issue :-)

That issue is, if I query a row before I want to change it, and I get some
values, and reading from a database is allowed by all, even if the database
is locked for writing, then how will I know that the database was changed?

So, in terms of code (to make things simpler):

Below is what I currently have (for example) - this is done after one entry
in a form view changes, so that I update the database in real time:

---
sqlite *db;
char *zErrMsg = 0;
int rc;
db = sqlite_open(current_file, 0, &zErrMsg);
if( db==0 ){
 strErr.Format("SQL Open Error: %s",zErrMsg);
 return;
}
rc=sqlite_exec_printf(db,"update data set chip_id='%q' where
id='%d'",0,0,&zErrMsg,str,curRowID);
if( rc!=SQLITE_OK){
 strErr.Format("SQL Exec Error: %s",zErrMsg);
 return;
}
sqlite_close(db);
sqlite_freemem(zErrMsg);
---

I guess before that sqlite_exec_printf(db,"update...") I have to add
something like:

---
const char** Values;
const char** ColumnNames;
sqlite_vm * Vm;
char *stmt;
const char *s;
int cnt;
stmt="select * from data where ROWID=my_rowid_number_here";
s=stmt;
rc=sqlite_compile(db,stmt,&s,&Vm,&zErrMsg);
if(rc!=SQLITE_OK)
{
  strErr.Format("SQL Compile Error: %s",zErrMsg);
  ASSERT(FALSE);
}
while(sqlite_step(Vm,&cnt,&Values,&ColumnNames)!=SQLITE_DONE)
{
  for(int i=0;i<cnt;i++)
  {
    switch(i)
    {
      case 0: // let's say we have a timestamp here
      // I'll store the timestamp in some local variable
      break;
    }
  }
 }
}
sqlite_finalize(Vm,&zErrMsg);
sqlite_freemem(zErrMsg);
---

... and then I'll check if the database is locked by trying to write to
another column in that row and check for SQLITE_BUSY return value:

---
rc=SQLITE_BUSY;
count=10; // just to make sure we don't wait forever
do
{
 rc=sqlite_exec_printf(db,"update data set special_column='1' where
id='%d'",0,0,&zErrMsg,curRowID);
 sleep(500);
 count++;
} while(rc!=SQLITE_OK || count!=10);
if(count==10)
{
  // we waited without result, abort
}
// continue and give this user access to the database
---

I'm sorry for such a long and confusing post, but I always understand things
better with code :-) Now, am I right in what I have above, or are there
flaws in this approach?

Thank you for your time and patience!

   Dennis

----- Original Message ----- 
From: "Greg Obleshchuk" <[EMAIL PROTECTED]>
To: "'Dennis Volodomanov'" <[EMAIL PROTECTED]>
Sent: Wednesday, October 29, 2003 6:24 PM
Subject: RE: [sqlite] Checking the busy state


Hi Dennis,
You should get and save the original values when you first query the record.
(strictly speaking this is conflict stuff not locking)
I.e.
Get record & Save copy

You haven't said what you are programming in languages like VB and .net have
tag properties to control and you can use them
So you could do

Name.Text = sqldataforcol1
Name.tag = sqldataforcol1

Then these two could be compared

Yes you could just have a column and just set the value.  You could use a
trigger on the table (for update and insert) if there was a datetime
function but just checking there isn't (maybe someone could write one that
returned yyyymmddhhmmsshhh )
But if you manually set it yourself it would work.


Kind regards
Greg O


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to