Skip to content

Commit

Permalink
fix(QueryUtils): Fix serializing simple value bindings to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed May 28, 2024
1 parent 4021601 commit 2ac6b0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
17 changes: 4 additions & 13 deletions models/Grammars/BaseGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ component displayname="Grammar" accessors="true" singleton {
tryPreInterceptor( data );
structAppend( data.options, { result: "local.result" }, true );
if ( variables.log.canDebug() ) {
variables.log.debug( "Executing sql: #data.sql#", "With bindings: #serializeBindings( data.bindings )#" );
variables.log.debug(
"Executing sql: #data.sql#",
"With bindings: #variables.utils.serializeBindings( data.bindings )#"
);
}
var startTick = getTickCount();
data.result = {};
Expand Down Expand Up @@ -1813,16 +1816,4 @@ component displayname="Grammar" accessors="true" singleton {
return "";
}

private string function serializeBindings( required array bindings ) {
return serializeJSON(
arguments.bindings.map( function( binding ) {
var newBinding = duplicate( binding );
if ( isBinary( newBinding.value ) ) {
newBinding.value = toBase64( newBinding.value );
}
return newBinding;
} )
);
}

}
16 changes: 2 additions & 14 deletions models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ component displayname="QueryBuilder" accessors="true" {
*/
public boolean function existsOrFail( struct options = {}, any errorMessage ) {
if ( !this.exists( arguments.options ) ) {
param arguments.errorMessage = "No rows found with constraints [#serializeBindings( this.getBindings() )#]";
param arguments.errorMessage = "No rows found with constraints [#variables.utils.serializeBindings( this.getBindings() )#]";
throw( type = "RecordNotFound", message = arguments.errorMessage );
}
return true;
Expand Down Expand Up @@ -3699,7 +3699,7 @@ component displayname="QueryBuilder" accessors="true" {
public any function firstOrFail( any errorMessage, struct options = {} ) {
var result = first( arguments.options );
if ( structIsEmpty( result ) ) {
param arguments.errorMessage = "No rows found with constraints [#serializeBindings( this.getBindings() )#]";
param arguments.errorMessage = "No rows found with constraints [#variables.utils.serializeBindings( this.getBindings() )#]";
if ( isClosure( arguments.errorMessage ) || isCustomFunction( arguments.errorMessage ) ) {
arguments.errorMessage = arguments.errorMessage( this );
}
Expand Down Expand Up @@ -4416,16 +4416,4 @@ component displayname="QueryBuilder" accessors="true" {
return isSimpleValue( column ) ? variables.columnFormatter( column ) : column;
}

private string function serializeBindings( required array bindings ) {
return serializeJSON(
arguments.bindings.map( function( binding ) {
var newBinding = duplicate( binding );
if ( isBinary( newBinding.value ) ) {
newBinding.value = toBase64( newBinding.value );
}
return newBinding;
} )
);
}

}
12 changes: 12 additions & 0 deletions models/Query/QueryUtils.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,18 @@ component singleton displayname="QueryUtils" accessors="true" {
return true;
}

public string function serializeBindings( required array bindings ) {
return serializeJSON(
arguments.bindings.map( function( binding ) {
var newBinding = extractBinding( duplicate( binding ) );
if ( isBinary( newBinding.value ) ) {
newBinding.value = toBase64( newBinding.value );
}
return newBinding;
} )
);
}

private boolean function isFloatingPoint( required struct binding ) {
if ( isNull( arguments.binding.value ) || arguments.binding.null ) {
return false;
Expand Down

0 comments on commit 2ac6b0b

Please sign in to comment.