Kevin Piciulo <[EMAIL PROTECTED]> wrote:
> Hello,
>     I've been staring at this line for quite a while now, and can't 
> figure out what the problem is.  I know the database is created and 
> open.  The following returns SQLITE_ERROR. 
> 
> sqlite3_prepare(m_dbDataBase, "UPDATE Users SET ? = ? WHERE user_id == 
> ?;", -1, &stmt, NULL);
> 
>   My guess is that i can't use a variable to represent the column name.  
> Is this the case?  

Your guess is right.  You can only use a variable in places
where it is valid to put an expression.  You cannot say

    UPDATE users SET 5+x = 22.7/y ...

because the expression "5+x" is not valid in that context.
So that means you cannot put a variable there either.

The sqlite3_prepare() routine actually invokes a compiler
that translates your SQL statement into bytecode that will
implement the statement.  The "?" tokens get translated into
a load-immediate kind of instruction where the value to
be loaded is supplied by a subsequent sqlite3_bind_... call.
The value to be loaded defaults to NULL.

Changes to the column name on the left-hand side of the
assignment cause different code to be generated, and
sqlite3_bind_... calls do not have the ability to recompile
the bytecode to accomodate the change.
--
D. Richard Hipp   <[EMAIL PROTECTED]>

Reply via email to