Sidebar

Can I include some sort of debug info in an SQL query?

0 votes
202 views
asked Apr 27, 2021 by rich-c-2789 (16,180 points)
Occasionally I will get a query from our DBA that was captured in a profile session.  Often these are sent to the whole team to be researched.  Is there a way to include some info in the query that will help me identify it as one that originated from an interface I have responsibly over?  I would also like to include some debug info during testing.  Is this possible?

1 Answer

0 votes

Yes.  Have you tried using SQL comments in your queries? 

With SQL comments you can include comments that are not executed on the database server or alter the way your queries execute.  Your DBA should see the query with comments.  Then the next time he sends you a query you can identify if it is something you need to look into.  That is if the DBA doesn't copy the query without the comments. ;-)  If you communicate and test it with your DBA, I am sure he will recognize the value in receiving a faster response.

Here is a couple examples in a QIE mapping function:

Single Line Comment Example:

var pQuery = qie.getParameterizedQuery("-- Set last name with reverse phone number lookup in Test Sql Comments channel, \n" +
   "SELECT Last FROM PatientProfile WHERE Phone1 = '5036462755' -- Comment at the end of a line");
var queryResult = pQuery.doQuery(
   "MyDatabaseConnection",
   false,
   false
);
message.setNode("PID-5.1", queryResult.getNode("Last"));

 

Multi Line Comment Example:

var pQuery = qie.getParameterizedQuery("/* \n" +
   "  Set last name with reverse phone number lookup\n" +
   "  Test Sql Comments channel, \n" +
   "  Test Multi Line Comment function\n" +
   "*/\n" +
   "SELECT Last /* comment inline */ FROM PatientProfile WHERE Phone1 = '5036497551' /* comment at the end of a line*/");
var queryResult = pQuery.doQuery(
   "MyDatabaseConnection",
   false,
   false
);
message.setNode("PID-5.1", queryResult.getNode("Last"));

 

See also:

What is the most common SQL comment syntax?

answered Apr 27, 2021 by rich-c-2789 (16,180 points)
...