Gé
Thanks for the advise, I will alter my program.
Do you know which compilers do need this treatment? (I am using GCC 3.3.3).
Regards,
Ben
Gé Weijers wrote:
On an almost pedantic note:
declare the variable as:
static volatile sig_atomic_t bKilled = 0;
"volatile" keeps the compiler from caching the value in a register, and
not noticing its change,
and "sig_atomic_t" is an integer type guaranteed to be written in one
instruction.
Some processors can only write certain integer sizes atomically, chars
may need read and write cycles and are not atomic.
alternatively you can mask the signal before you read 'bKilled'.
Gé
On Jul 8, 2005, at 7:50 AM, Ben Clewett wrote:
Derrell,
Thanks for the idea and the excellent coding example.
This works perfectly, thank!
Regards,
Ben.
[EMAIL PROTECTED] wrote:
Ben Clewett <[EMAIL PROTECTED]> writes:
Dear SQLite,
I am running a sequence of inserts:
BEGIN
INSERT INTO table ...
INSERT INTO table ...
INSERT INTO table ...
INSERT INTO table ...
INSERT INTO table ...
I am catching the 'kill -1' signal (aka CTRL-C) and executing a
final query:
COMMIT
When I execute the 'COMMIT' I get:
"library routine called out of sequence"
Every other query command after this returns the same.
My guess is the interrupt is kicking in during SQLite completion of
the previous query. Therefore SQLite is half way through something
when this occurs.
Can any person suggest a possible solution as I am out of options.
For instance, some command to tidy up SQLite so that the next
statement does not fail. Otherwise I loose all my inserted data :)
Instead of issuing the COMMIT from the signal handler, set a global
flag in
the signal handler which you check in your main code. If the flag
has been
set, then COMMIT and exit.
You can do something akin to this (untested code):
---------------------------------------------------------------------
---------
static int bKilled = 0;
static void
sigHandler(int signum)
{
if (signum == SIGTERM)
{
bKilled = 1;
}
}
static void
doInserts()
{
char ** ppQueries;
char * queries[] =
{
"INSERT INTO table ...",
"INSERT INTO table ...",
"INSERT INTO table ...",
NULL
};
/* Start a transaction */
issueQuery("BEGIN;");
/* For each query... */
for (ppQueries = queries; ppQueries != NULL; ppQueries++)
{
/* Issue the query */
issueQuery(*ppQueries);
/* If we've been signaled, exit loop */
if (bKilled)
{
break;
}
}
/*
* Commit the transaction.
*
* Note that signal could have occurred *before* the BEGIN.
You'll need
* to handle that case as well (or ignore the error from COMMIT)
*/
issueQuery("COMMIT;");
}
--
Gé Weijers
e-mail: [EMAIL PROTECTED]