Getting placeholder variables to work in revDataFromQuery

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Locked
Quentin Brown
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Apr 17, 2013 11:15 pm

Getting placeholder variables to work in revDataFromQuery

Post by Quentin Brown » Tue Sep 03, 2013 11:11 pm

I am trying to get a list of columns in a SQLite table - chosen by the user from a list of Tables in the database.

The following works fine:

Code: Select all

function ListTableColumns pTable
   local tColumnList, tSelectedTable
   put pTable into tSelectedTable
   databaseConnect
   put revDataFromQuery(comma, return, GetDatabaseID(), "pragma table_info(Projects);") into tColumnList 
   return tColumnList
end ListTableColumns
Above I manually and explicitly entered the Table name into the SQL Query

But adding a placeholder Variable within the SQL Query as follows results in a revdberr,Database Error: near ":1": syntax error message.

Code: Select all

function ListTableColumns pTable
   local tColumnList, tSelectedTable
   put pTable into tSelectedTable
   databaseConnect
   put revDataFromQuery(comma, return, GetDatabaseID(), "pragma table_info(:1);", tSelectedTable) into tColumnList 
   return tColumnList
end ListTableColumns
Where am I going wrong?

Any help would be very much appreciated...

Quentin.

elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Getting placeholder variables to work in revDataFromQuer

Post by elanorb » Wed Sep 04, 2013 10:01 am

Hi Quentin

I think it might just be that you need quotation marks around your variable name e.g.

put revDataFromQuery(comma, return, GetDatabaseID(), "pragma table_info(:1);", "tSelectedTable") into tColumnList

I haven't set up a test so this may not work but syntax wise as least that's how it should be.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

Quentin Brown
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Apr 17, 2013 11:15 pm

Re: Getting placeholder variables to work in revDataFromQuer

Post by Quentin Brown » Wed Sep 04, 2013 10:49 pm

Brilliant. That did the trick, thanks.
I was wondering if there was some kind of syntax I was getting wrong. I guess I am too used to developing in Filemaker where only explicit values require quotes and variables don't use them or they are parsed as if explicit rather than being replaced with the contents of the variable! Good to know it doesn't work like that in Livecode.

Kind Regards,

Quentin.

Locked

Return to “Summer School 2013”