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;");
}