The workaround would be to build the statement some other way (sqlite3_mprintf(), for example) for each individual ALTER TABLE command. At that point you may want to use sqlite3_exec() instead of sqlite3_prepare(), depending on how you'll be using the statement. You'll also have to be more careful about SQL injection, if the variable column name comes from any sort of user input.
- Pam On 5/23/06, Dennis Cote <[EMAIL PROTECTED]> wrote:
Kevin Piciulo wrote: > Can I add a column using a variable for the column name? Below is > the prepare statement, which is returning an error. > > sqlite3_prepare(m_dbDataBase, "ALTER TABLE users ADD COLUMN ? > varchar;", -1, &stmt, NULL); > > I'm pretty sure my syntax is correct which leads me to believe you > cannot do this. If that's the case is there some sort of work around? > Kevin, You are correct, this is illegal. You can only use a parameter where an "expression" is allowed in the SQL syntax. Parameters do not do string substitution in the SQL. You can check if your SQL still makes sense by substituting a simple sum expression for your parameter. In your case, the following does not make sense. ALTER TABLE users ADD COLUMN 5+2 varchar; HTH Dennis Cote