i want to log the sql passed to cfquery in every c...
# cfml-beginners
g
i want to log the sql passed to cfquery in every cfquery we are using storedproc how can i log my queries to know what parameters passed
v
You can use
cfsavecontent
but you will need to wrap the content of cfquery individually in all cfquery occurence
g
isn't there any better way like underlying java method ?
m
if you are running lucee 5.3.x+ you might be able to leverage queryListeners, i haven't had need to try them yet, https://docs.lucee.org/guides/cookbooks/query_listeners.html
r
The SQL, and SQL parameters, are contained in the result of a cfquery or queryExecute(), if specified.
<cfquery result="queryResults">
SELECT *
FROM Employees
WHERE status = 'Active'
</cfquery>
<cfdump var="#queryResults#">
Merge the SQL and params with something like below:
sql = queryResults.sqlParameters.reduce( ( previous, element ) => {
return previous.replace( "?", element );
}, queryResults.sql );
b
@gsr If you just want it for debugging, use the built in CF debugging templates which displays the query executed on the bottom of each page.
Also, tools like FusionReactor will show you the queries executed on a given page