Is it possible to recompile sql parameters using cfquery result?

When I run the following code:

<cfquery name="someQuery" result="queryResult" datasource="wetakepictures"> SELECT id FROM events WHERE category_id = <cfqueryparam value="1" cfsqltype="cf_sql_integer"> OR title like <cfqueryparam value="%test%" cfsqltype="cf_sql_varchar"> </cfquery> <cfoutput> #queryResult.sql# <br /> #ArrayToList(queryResult.sqlparameters)# </cfoutput> 

It outputs:

 SELECT id FROM events WHERE category_id = ? OR title like ? 1,%test% 

I need the actual line "SELECT id FROM events WHERE category_id = 1 OR type name"% test% "".

Is there a way to re-configure parameters in sql?

---- edit ----

The reason for this is to eliminate duplicate SQL when paging results. I would like to do something like this:

 <cftransaction> <cfquery name='getCount' result='queryResult'> SELECT count(*) ... conditions that are guarded by <cfif> ... </cfquery> <cfquery name='getLimitedRecords'> #replace(queryResult.sql, 'count(*)', 'id')# LIMIT ... based on pagination ... </cfquery> </cftransaction> 

Note. I looked through this question and decided to use two queries with MySQL.

+4
source share
1 answer

Two approaches, depending on what you are trying to do:

Ben Nadel: Combining ColdFusion SQL debugging and queries with Javascript - Useful if you only want to copy and paste

The best debugging template is useful if you want to redesign the code to restore your request in the code, as well as perform some logging, etc.

+1
source

Source: https://habr.com/ru/post/1308631/


All Articles