Very long strings and how to code them for pjs.query()


#1

Hi all!! An amazing thing happened! I figured out what I was doing wrong and now I can populate my grids. I have some very long query statements to execute and I am not sure what the best way to build the strings are. I found this. https://davidwalsh.name/multiline-javascript-strings discussion about using \ vs concatenation.

Let me show you two examples of queries I have to execute. ( I don’t have a choice about how the data is being stored.)

This one will return the data to load the grid.
//eventsGrid
select a.e_transactionopen, a.e_name, b.e_transactionsupport, b.e_name, c.e_transactionclose, c.e_name, d.f_featurekey
from eventtransaction a
join eventtransaction b on a.e_transactionopen = b.e_transactionopen and (b.e_transactionsupport > ’ ’ OR b.e_transactionopen > ‘9999999999’)
join eventtransaction c on a.e_transactionopen = c.e_transactionopen and c.e_transactionclose > ’ ’
join transactionfeatures d on a.e_transactionopen = d.f_transactionopen
group by a.e_transactionopen, b.e_transactionsupport, c.e_transactionclose
order by a.e_transactionopen

This one will pull the selected detail record.
//eventDetail
select a.e_transactionopen, a.e_name, b.e_transactionsupport, b.e_name, c.e_transactionclose, c.e_name, d.f_featurekey
from eventtransaction a
join eventtransaction b on a.e_transactionopen = b.e_transactionopen and (b.e_transactionsupport > ’ ’ OR b.e_transactionopen > ‘9999999999’)
join eventtransaction c on a.e_transactionopen = c.e_transactionopen and c.e_transactionclose > ’ ’
join transactionfeatures d on a.e_transactionopen = d.f_transactionopen
group by a.e_transactionopen, b.e_transactionsupport, c.e_transactionclose
having a.e_transactionopen = ‘HOST1-76’ (The literal will be a replacement ?)

Using the \ seems to be the unloved way in the IDE. Concatenation style “xxxxx” + “yyyyy” might be better. Since I am retrieving data maybe the thing to do is put some stored procedures together and use them. What does everyone think?


#2

The easiest way to do multi-line strings in JavaScript is to use the backtick character (`) as a delimiter instead of single or double quotes.

Here is an example:
https://noderun.com/ide/alex/multi-line-strings/


#3

Alex, thank you. Very helpful. Not only did I try it out, I then googled and found the background info on it.