Argument must be single variable or literal

Post Reply
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Argument must be single variable or literal

Post by barry.marcus »

Why doesn't this work:

<$tabName="PATN_TEST">
<$Query="SELECT DISTINCT PATN_ISD FROM $tabName WHERE PATN_ISD > '20051231' ORDER BY PATN_ISD">

I get the error message "Argument must be single variable or literal"

Thanks.
User avatar
jason112
Site Admin
Posts: 347
Joined: Tue Oct 26, 2004 5:35 pm

Argument must be single variable or literal

Post by jason112 »

you need to double escape dollar signs to get them in string constants.

<$Query="SELECT DISTINCT PATN_ISD FROM $$tabName WHERE PATN_ISD > '20051231' ORDER BY PATN_ISD">

This will put "FROM $tabName WHERE" in Query, which <SQL> will correctly parameterize.
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Argument must be single variable or literal

Post by barry.marcus »

But that makes the query "SELECT DISTINCT PATN_ISD FROM $tabName WHERE PATN_ISD > '20051231' ORDER BY PATN_ISD" when it is sent to texis. I want it to be:

SELECT DISTINCT PATN_ISD FROM PATN_TEST WHERE PATN_ISD > '20051231' ORDER BY PATN_ISD
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

Argument must be single variable or literal

Post by barry.marcus »

Sorry. I see what you mean. Thanks, I think that worked.
User avatar
jason112
Site Admin
Posts: 347
Joined: Tue Oct 26, 2004 5:35 pm

Argument must be single variable or literal

Post by jason112 »

Yeah I didn't notice $tabName is the name of the table (you'd think the variable name would've tipped me off X-| )

For that strfmt will insert the actual value:

<strfmt "SELECT DISTINCT PATN_ISD FROM %s WHERE PATN_ISD > '20051231' ORDER BY PATN_ISD" $tabName><$Query=$ret>
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Argument must be single variable or literal

Post by mark »

SQL INJECTION WARNING!

Make sure "tabName" is not coming from the user via form input or similar. If it is they can change it to something that will change the meaning of your SQL. If it's based on user input (even if it's "hidden" on the form) it should be sanitized before use in SQL.
Post Reply