Variables in Sqlite Query

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Jason1234
Posts: 42
Joined: Sat Jun 18, 2011 9:20 am

Variables in Sqlite Query

Post by Jason1234 » Wed Dec 28, 2011 1:03 pm

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
Windows / MAC / IOS / Android - Deployment
Build 5.5.4 / & Community Version 6.1

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Variables in Sqlite Query

Post by Klaus » Wed Dec 28, 2011 1:23 pm

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

Jason1234
Posts: 42
Joined: Sat Jun 18, 2011 9:20 am

Re: Variables in Sqlite Query

Post by Jason1234 » Wed Dec 28, 2011 8:10 pm

Klaus

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

Regards

Jason
Windows / MAC / IOS / Android - Deployment
Build 5.5.4 / & Community Version 6.1

Post Reply