Re: [sqlite] Odd error on "BEGIN IMMEDIATE"

2007-08-18 Thread Scott Derrick

OK, I understand.  Must have miss read teh docs..

thanks,

Scott

Trevor Talbot wrote:

On 8/17/07, Scott Derrick <[EMAIL PROTECTED]> wrote:

  

exec a "BEGIN IMMEDIATE", with a sleep loop if I can't acquire the
reserved lock.

Then prepare,  step, finalize, exit the function

When I come back into the function and exec a "BEGIN IMMEDIATE" I get an
error

"Cannot start a transaction within a transaction".

Whats wrong?  Doesn't sqlite3_finalize(stmt),  release the locks,
deletes the prepared statement and causes the database to be updated?



It deletes the prepared statement.  The statement's action would have
been performed by a previous sqlite3_step().  Locks and database
updates are another matter, because...

  

Why does the engine think I'm still in a transaction?



...you started a transaction with BEGIN.  Unless the statement you
stepped is a COMMIT, your transaction isn't done yet :)

Exec a COMMIT at the end of the loop.

Incidentally, you can keep the prepared statement around if it's
appropriate.  You can open the database, prepare the statement, and
only step() and reset() within the loop.  This way you don't have to
keep preparing it over and over again.  You must finalize() it before
closing the database, though.

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




  


--

-
   The most effectual engines for [pacifying a nation] are the public papers... 
[A despotic] government always [keeps] a kind of standing army of newswriters 
who, without any regard to truth or to what should be like truth, [invent] and 
put into the papers whatever might serve the ministers.

   Thomas Jefferson to G. K. van Hogendorp
   Oct. 13, 1785. (*) ME 5:181, Papers 8:632 



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



Re: [sqlite] Odd error on "BEGIN IMMEDIATE"

2007-08-17 Thread Trevor Talbot
On 8/17/07, Scott Derrick <[EMAIL PROTECTED]> wrote:

> exec a "BEGIN IMMEDIATE", with a sleep loop if I can't acquire the
> reserved lock.
>
> Then prepare,  step, finalize, exit the function
>
> When I come back into the function and exec a "BEGIN IMMEDIATE" I get an
> error
>
> "Cannot start a transaction within a transaction".
>
> Whats wrong?  Doesn't sqlite3_finalize(stmt),  release the locks,
> deletes the prepared statement and causes the database to be updated?

It deletes the prepared statement.  The statement's action would have
been performed by a previous sqlite3_step().  Locks and database
updates are another matter, because...

> Why does the engine think I'm still in a transaction?

...you started a transaction with BEGIN.  Unless the statement you
stepped is a COMMIT, your transaction isn't done yet :)

Exec a COMMIT at the end of the loop.

Incidentally, you can keep the prepared statement around if it's
appropriate.  You can open the database, prepare the statement, and
only step() and reset() within the loop.  This way you don't have to
keep preparing it over and over again.  You must finalize() it before
closing the database, though.

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



Re: [sqlite] Odd error on "BEGIN IMMEDIATE"

2007-08-17 Thread Nuno Lucas
On 8/18/07, Scott Derrick <[EMAIL PROTECTED]> wrote:
> I have a process that repeatedly, once a second,  inserts data into the
> database.
>
> I open the database, on the class instantiation.
>
> once a second I call a function that;
>
> exec a "BEGIN IMMEDIATE", with a sleep loop if I can't acquire the
> reserved lock.
>
> Then prepare,  step, finalize, exit the function
>
> When I come back into the function and exec a "BEGIN IMMEDIATE" I get an
> error
>
> "Cannot start a transaction within a transaction".
>
> Whats wrong?  Doesn't sqlite3_finalize(stmt),  release the locks,
> deletes the prepared statement and causes the database to be updated?

No, your assumptions are wrong, that's not it's job.
If it did then you couldn't have more than a single statement inside a
transaction, don't you think?

> Why does the engine think I'm still in a transaction?

You didn't end the transaction with either "COMMIT"/"END" or "ROLLBACK".

Regards,
~Nuno Lucas

> thanks,
>
> Scott

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



[sqlite] Odd error on "BEGIN IMMEDIATE"

2007-08-17 Thread Scott Derrick
I have a process that repeatedly, once a second,  inserts data into the 
database.


I open the database, on the class instantiation.

once a second I call a function that;

exec a "BEGIN IMMEDIATE", with a sleep loop if I can't acquire the 
reserved lock.


Then prepare,  step, finalize, exit the function

When I come back into the function and exec a "BEGIN IMMEDIATE" I get an 
error


"Cannot start a transaction within a transaction". 

Whats wrong?  Doesn't sqlite3_finalize(stmt),  release the locks, 
deletes the prepared statement and causes the database to be updated?  
Why does the engine think I'm still in a transaction?


thanks,

Scott

--

-
   The only security of all is in a free press. The force of public opinion 
cannot be resisted when permitted freely to be expressed. The agitation it 
produces must be submitted to. It is necessary, to keep the waters pure.

   Thomas Jefferson to Lafayette, 1823. ME 15:491 



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