Validate SQL and display the output

2,410 pts.
Tags:
SQL Query
SQL scripts
SQLRPGLE
I have a screen where the user can enter an SQL script, I need to validate whether the SQL query is a valid one, if so then display the output on to the screen. I am planning to execute a SQL prepare statement out of the script entered and then use SQLCOD to determine whether it is valid or not. But how to display the out put of the query?Any suggestions?
ASKED: January 29, 2013  8:14 AM
UPDATED: January 29, 2013  12:43 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • RamvishakRamesh
    Meantime, I have used FETCH NEXT FROM CURSOR INTO:Data Now the 'Data' field has the result of the query, but as we cannot say how lengthy the result can be, I have declared it as 9999A and thinking about moving it onto a display file screen field. Any better suggestions? Instead of embedded SQL I thought about RUNSQLSTM, but it requires additional source file for the SQL statements and it gives a chance for someone to change the SQL inside the source file. So I am not going for that. Please give your suggestions  
    2,410 pointsBadges:
    report
  • TomLiotta
    To check the SQL statement, pass it to the Syntax Check SQL Statement (QSQCHKS) API. To display the output, there are three general ways.First, you can analyze the statement to determine the tables and libraries. Then determine the column list and retrieve the attributes of all columns that will be displayed. Define a SQL descriptor area (SQLDA) to hold column values according to their data types. You'll need to work out out ways to dynamically display values on a screen without declaring the fields in a display file. There are various MI APIs that would be helpful. Most likely, this will take a couple months to get working.Second, you could pass the SQL into a REXX function or the Qshell db2 utility, and let them do most of the work. The db2 utility would probably be easiest. Almost as easy and probably a little cleaner would be passing the statement into a generic QM query, and running STRQMQRY to list the output. It should only take a day or so to get a generic QM query working. Numerous examples can be downloaded.But third and probably best might be just to let the system do it all for you. Why create something that you already have on the system? Just let the users type the SQL into QM query and run it. All that needs to be done is to create QM profiles for the users who need it. Authorize the users only to SELECT statements and you're essentially done. There isn't even any need for syntax checking ahead of time.Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following