Hello everyone,
I'm writing a little server-side function that searches a table for a given value in a given field, and returns a different given field in the same record. For instance, you could tell it to return the name of a customer with ID=5. I've gotten it working (muliple ways, actually) on a desktop app but can't seem to do it on a web/mobile app. The original basic logic was building a string out of my different variables and then run Lianja.execute on that string. Lianja.execute doesn't work on web/mobile clients so I needed another way.
I found the PREPARE/EXECUTE commands in the documentation and tried them. I couldn't work out how it handled different types of parameters but found a way to get it to work on desktop. What I thought should work was:
Code:
local mystring = "select ? from ? where ? = ?"
local selectfield = "total"
local tablename = "expenseclaim"
local searchfield = "claimid"
local searchvalue = 5
prepare stmt from :mystring
execute stmt using :selectfield, :tablename, :searchfield, :searchvalue
This seemed to behave oddly with respect to data types. For example, it accepted expenseclaim as the name of a table, but literally output the string "total" instead of the value in the field named total.
What I got to work on a desktop app was building "mystring" by placing the variables in it directly, then calling PREPARE/EXECUTE on it. Since EXECUTE needs at least one parameter and the table name seemed to behave properly, I left that in the string as a parameter:
Code:
local selectfield = "total"
local tablename = "expenseclaim"
local searchfield = "claimid"
local searchvalue = 5
local mystring = "select " + selectfield
mystring += " from ?"
mystring += " where " + searchfield + " = " + searchvalue
PREPARE stmt from :mystring
EXECUTE stmt USING :tablename
This works perfectly fine on desktop, but on web/mobile clients it breaks on the EXECUTE line.
That might be a bug , it might not be implemented on web/mobile or I might even be making some silly mistake, but even then it feels like a rather convoluted way of going about things. Is there a way to just execute a string within a Lianja/VFP script on a server? Or to just place variables into a Lianja/VFP command?
Thanks for the help,
Ryan
Bookmarks