• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code to unpack query array to tab-delimited data?
#2
Hi sltfn,

Here is one way to format the results of a batchQuery into a line delimited list of tab delimited records. I tried to make it as generic as possible so other users can use it if they'd like.


Code:
function flattenArray pBatchQueryA, pKeys, pDelimiter, pIncludeRecordID
    local tResults, tRecord
   
    repeat for each key xTableID in pBatchQueryA
         repeat for each key xIndex in pBatchQueryA[xTableID]
              repeat for each key xRecordID in pBatchQueryA[xTableID][xIndex]
                   repeat for each item xKey in pKeys
                        put pBatchQueryA[xTableID][xIndex][xRecordID][xKey] & pDelimiter after tRecord
                   end repeat
                   
                   if pIncludeRecordID then put xRecordID & pDelimiter after tRecord
                   
                   delete char -1 of tRecord --remove trailing delimiter
                   put tRecord & lf after tResults
                   put empty into tRecord
              end repeat
         end repeat
    end repeat
    delete char -1 of tResults --remove trailing lf
   
    return tResults
end flattenArray

A couple things to note:

- put flattenArray(tOutputA) into flattened will have to be changed to put flattenArray(tOutputA, "attributes,last_name,status,rank,city,year,name,date", "tab", true) into flattened.

- the code assumes that the batchQuery was only performed on one table. If this is not the case, you can pass another parameter after pBatchQueryA (pTableID) that will specify the table you are interested in. The outer repeat that uses xTableID will need to be removed and all references of xTableID will need to be changed to pTableID.

Hope this helps! Let me know if you have any questions.
  Reply


Messages In This Thread
RE: code to unpack query array to tab-delimited data? - by efrain.c - 08-21-2019, 09:53 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)