Query executes OK and returns the relevant records.
However retrieving the criterias is an issue: I’m expecting this:
`
[“brand=Volvo”]
`
but getCriterias() always returns an empty array.
`
[]
`
Coldbox documentation is no help on this. What I’m doing wrong?
Alternatively is there a way to retrieve the full underlying SQL string with parameters?
Purpose is to JSONify the structure to have it returned in a browser so logging in the console in not an option here.
Thanks for any help!
-Kermit
`
var oEntityService = entityNew(“Car”);
var oCriteria = oEntityService.newCriteria();
var oEntity = oEntityService.new();
var oRestrictions = oEntity.getRestrictions();
Conceivably, you could get the SQL string (from the previous code snippet), find all instances of the replacement parameter (?), and then replace it with the correct positional value. You could also use the correct positional type to properly place the parameter value (e.g., quotes for strings, 1/0 for boolean, etc). This would be necessary, of course, because all that you get back from getPositionalParameterValues() is the raw, un-SQL-ed value:
Something like this would work:
`
var types = translator.getQueryParameters().getPositionalParameterTypes();
var values = translator.getQueryParameters().getPositionalParameterValues();
var dialect = factory.getDialect();
var sqlValues = [];
for( var i=1; i<arrayLen( types ); i++ ) {
var type = types[ i ];
var value = values[ i ];
arrayAppend( sqlValues, type.objectToSQLString( value, dialect ) );
}
`
And will produce an array like this:
It would be nice, I think, to add this functionality to CB’s CriteriaBuilder. I know that I’ve wanted to be able to retrieve the SQL as well apart from just logging it.