Page 1 of 1

Variables in Sqlite Query

Posted: Wed Dec 28, 2011 1:03 pm
by Jason1234
Hi... I hope I have this wrong as my hole application is defunct if I cannot get this to work...

I am using an Sqlite database and all is good with the tables and query working well, when not using variables.
Having got it to work my application will now query the database from variables created from combo box or text entry.

It appears that variables cannot be used in the query statement for Sqlite database.

Basic code for clarity....
put revQueryDatabase(conID, "SELECT * FROM ttable") into tresult
ttable is a variable table name selected from a combo box.

I will need to add the WHERE bit above to include other variables in the same query to narrow the returned result...

Can variables be used in the query construct? In fact I would think most applications would need to change the query based on user input? The query must alter depending on user selection before the query is run.

Please can someone help me.... how do I use the variable ttable in the query statement?

Thanks for any help

Re: Variables in Sqlite Query

Posted: Wed Dec 28, 2011 1:23 pm
by Klaus
Hi Jason,

you need to create the correct string(s) for the SQL command(s) like this:
...
put ("SELECT * FROM" && ttable) into tSQL1
## parens not really necessary, just for clarification!

## Now just pass the correct string to the function:
put revQueryDatabase(conID, tSQL1) into tresult
...

Best

Klaus

Re: Variables in Sqlite Query

Posted: Wed Dec 28, 2011 8:10 pm
by Jason1234
Klaus

Thank you, just what I needed... works perfect.

Regards

Jason