arrays with merge

Lyn Teyla lyn.teyla at gmail.com
Fri Jun 5 03:17:14 EDT 2015


> Terence Heaford <t.heaford at icloud.com> wrote:
> 
> This line gives a syntax error, obviously because an array does not work in merge?
> 
> put merge("SELECT [[tColumns]] FROM '[[tTable]]' [[myArray["test"]]] [[tSortOrder]]") into tSQL
> 
> Is there a way around this or do I have to resort to using &?



Method 1: Turn it into a 2-liner:

--------
put myArray["test"] into tTest
put merge("SELECT [[tColumns]] FROM '[[tTable]]' [[tTest]] [[tSortOrder]]") into tSQL
--------



Method 2: Have the entire string to be merged already stored elsewhere:

--------
put merge(the uSQL of me) into tSQL
--------
or
--------
put merge(url "file:sql.txt") into tSQL
--------

where the custom property "uSQL" or the file "sql.txt" already contains the string:

SELECT [[tColumns]] FROM '[[tTable]]' [[myArray["test"]]] [[tSortOrder]]



Method 3: Use a function to represent an array:

--------
local myArray -- make sure this is outside both handlers

function myArray pString
   return myArrayTest[pString]
end myArray

on doStuff
   -- some stuff here
   put merge("SELECT [[tColumns]] FROM '[[tTable]]' [[myArray(test)]] [[tSortOrder]]") into tSQL
   -- more stuff here
end doStuff
--------

This last method works as long as the name of the key ("test" in your example) isn't a LiveCode reserved word.


Hope this helps! :)

Lyn







More information about the Use-livecode mailing list