Dennis Volodomanov
<dennis.volodomanov-UC7k0eIJC1pWk0Htik3J/[EMAIL PROTECTED]> wrote:
I'm converting sqlite3_mprintf() into sqlite3_prepare_v2() and the SQL
for that was like this:

"SELECT *, Table1.ID AS _ID FROM Table1 LEFT JOIN Table2 ON
Table2.ID=Table1.ID %s"

and I was putting a "WHERE _ID=1", for example, in the %s

Now, I'm trying to do the same:

"SELECT *, Table1.ID AS _ID FROM Table1 LEFT JOIN Table2 ON
Table2.ID=Table1.ID ?1"

and then sqlite3_bind_text

No, you can't do that. You can only use a parameter in place of, say, an integer constant or a string literal. You can't replace whole SQL fragments.

My question is, can I do it like this or do I have to something like:

"SELECT *, Table1.ID AS _ID FROM Table1 LEFT JOIN Table2 ON
Table2.ID=Table1.ID WHERE _ID=?1" and bind only the _ID parameter in
this case?

This would work.

The issue is that I don't know beforehand what can be in
that
WHERE statement and how many parameters it might have - it's formed
elsewhere.

Parameters cannot change a structure of the query. If you need to do this, then you have to build the query in a string, with sprintf or similar, then prepare. Of course you can still use parameters in place of any literals you may need in the query.

Igor Tandetnik

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to