Quering with a variable in sqlite, Data binding

In my app I use the scene transitions. I get one value from scene1 and pass it to scene2 using

local routeId = storyboard.state.routeId

This works fine. Next I’d like to get all the data from a table, using routeId. For this I have:

for row in db:nrows("SELECT \* FROM route WHERE route\_id = routeId") do ...

This doesn’t work. I have been looking at parameterized queris, binding values, SQL injection, etc. But since I’m a begginer this is all pretty advanced stuff for me. Any ideas?

 

Btw, if I put it like this, it works just fine

for row in db:nrows("SELECT \* FROM route WHERE route\_id = 1") do

In your first snippet, try this instead:

[lua]

for row in db:nrows("SELECT * FROM route WHERE route_id = " … routeId) do

[/lua]

This builds the SQL query string by concatenating the value of your routeId variable into the the query in the appropriate spot.

  • Andrew

Great, its working… Thanks a lot. :slight_smile:

In your first snippet, try this instead:

[lua]

for row in db:nrows("SELECT * FROM route WHERE route_id = " … routeId) do

[/lua]

This builds the SQL query string by concatenating the value of your routeId variable into the the query in the appropriate spot.

  • Andrew

Great, its working… Thanks a lot. :slight_smile: