Hi, Joel:
You could use the CL CALL command to implement a very simple syntax for
"embedded SQL" in CL programs, like this:
CALL SQL ( SELECT DISTINCT * FROM 'QGPL/QAUOOPT' )
:Leverage what the CALL command provides by writing a little "SQL"
program that concatenates all of its arguments, (e.g. using *BCAT), to
form the SQL query string to pass to your RUNSQL command (or the one now
provided by IBM.)
To ease the use of single-quotes, use a "special value" of *QUOTE, that
tells the SQL program to "en-quote" the next argument ... so in this case:
CALL PGM(SQL) PARM( SELECT * FROM 'QGPL/QAUOOPT' +
WHERE OPTION = *QUOTE &OPT )
the value of &OPT will have single-quotes around it in the query
string.
This SQL program is trivial to write in C, and also fairly easy to do in
ILE RPG IV, and is even possible in ILE CL (CLLE), although slightly
more work.
Let me know if you want to see a working example of this technique, and
I can post examples at code.midrange.com ...
Also, it is easy to create a iuser-defined "SQL" command, so the syntax
would now look like this in your CL programs that use SQL:
SQL (SELECT DISTINCT * FROM 'QGPL/QAUOOPT')
or
SQL (SELECT * FROM 'QGPL/QAUOOPT' +
WHERE OPTION = *QUOTE &OPT)
I can post the command definition source, along with working examples of
the CPP (command processing program) for the proposed SQL command, at
code.midrange.com, if anyone is interested. :-)
All the best,
Mark S. Waterbury
> On 5/11/2012 3:01 PM, Stone, Joel wrote:
There MUST be a better method of coding SQL in a CL source member.
...(snip)...
Thanks!
As an Amazon Associate we earn from qualifying purchases.