RE: [sqlite] Binding a column name?

2005-07-09 Thread Brown, Dave
Actually I doubt it can - since without the column name it can't create the
prepared statement byte code, right?

-Dave 

-Original Message-
From: Brown, Dave [mailto:[EMAIL PROTECTED] 
Sent: Saturday, July 09, 2005 8:46 PM
To: sqlite-users@sqlite.org
Subject: [sqlite] Binding a column name?


Is it possible for a bind variable to be a column name? I'd like to make a
query which is:

select  from MyTable;

and I'd like the column_name to be a bind variable. This doesn't work using
the straight sqlite3_bind_text() call on the statement "select ? from
MyTable;", which treats the column name as text and not part of the compiled
statement.

-Dave



[sqlite] Binding a column name?

2005-07-09 Thread Brown, Dave

Is it possible for a bind variable to be a column name? I'd like to make a
query which is:

select  from MyTable;

and I'd like the column_name to be a bind variable. This doesn't work using
the straight sqlite3_bind_text() call on the statement "select ? from
MyTable;", which treats the column name as text and not part of the compiled
statement.

-Dave


Re: [sqlite] Error 21, "library routine called out of sequence"

2005-07-09 Thread Gé Weijers

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]




Re: [sqlite] how to force a database to be corrupted

2005-07-09 Thread Ulrik Petersen

Hi Olivier,

Olivier Singla wrote:


Hi,

I was wondering, is there is way to force a database to be corrupted ?
(obviously I need this for testing purposes). Basically I'd like to patch
the database so the next sql command will return SQLITE_CORRUPT.
 


You might want to look at:

http://www.sqlite.org/lockingv3.html

Scroll down to section 6.0 "How To Corrupt Your Database Files".

Ulrik Petersen

--
Ulrik Petersen
University of Aalborg, Denmark
http://ulrikp.org/