How To: Display the Full Executed Query Text, Including Parameters

When trouble shooting a query in your report design, wouldn’t it be nice to be able to write the entire query out to your console…

OpenText  profile picture
OpenText

May 12, 20153 min read

When trouble shooting a query in your report design, wouldn’t it be nice to be able to write the entire query out to your console or to a text control within your design, including the parameters? Or, maybe you want to write out the full queries that your users are running to a log file for monitoring.

If you are not using data set parameters, this is easy (and also unnecessary since the entire query text is static and available in the data set editor). You could just write the following script in a dynamic text control in your report design (or write it out to a log file or the console if running eclipsec.exe):

dataSetQueryDefinition

If you are using data set parameters, things are a little different.

With a query like:

queryText

You would get exactly that as your output, even after the user has entered parameter values or you’ve passed values through the data set parameters in another manner. The parameter values would not automatically replace the ‘?’ in the queryText property.

To get the values that are passed to the query, we can access the input parameter values from the data set’s afterOpen script with:

getInputParams

We can also access the queryText property from the afterOpen script with:

thisQueryText

With a little script, we can take the queryText and replace the ‘?’ markers with the actual parameter values:

afterOpen

This script takes the query text, replaces the ‘?’ markers with ‘–‘ (this is done because the split does not work on the ‘?’), splits the query text where the parameter values need to be inserted, then loops through these query pieces combining them with the query values.

If you had more query after the last data set parameter, you would need to add the last piece of the query back, but for our example, this is not needed. This also does not handle the single quotes that would surround a string or a date. You’d have to handle that by checking the class of the value:

parameterClass

This will return “class java.lang.Integer”, “class java.lang.String”, etc. allowing you to handle the insertion of quotes.

Now, we have our query with parameter values stored in the “newqry” variable to display in the report output, write to a log file, etc. In this example, we write it out to a global variable and recall it from a text control in the report, as you can see here:

reportOutput

Thanks for reading.

Share this post

Share this post to x. Share to linkedin. Mail to
OpenText avatar image

OpenText

OpenText, The Information Company, enables organizations to gain insight through market-leading information management solutions, powered by OpenText Cloud Editions.

See all posts

More from the author

Can CIOs meet today’s challenges and plan for tomorrow?

Can CIOs meet today’s challenges and plan for tomorrow?

Read the new white paper

April 21, 2025

4 min read

From the Great North to global innovation: How OpenText powers the future of tech

From the Great North to global innovation: How OpenText powers the future of tech

The beginning of the year is the perfect time to reflect on one’s successful journey and set our sights on the future. At OpenText, our…

February 28, 2025

3 min read

Why SAST + SCA is the key to protecting your organization in 2025

Why SAST + SCA is the key to protecting your organization in 2025

Software supply chain risk continues to rise—just last year we witnessed a staggering 156% year-over-year increase in malicious software supply chain attacks.

January 17, 2025

4 min read

Stay in the loop!

Get our most popular content delivered monthly to your inbox.