Skip to content

Commit

Permalink
BL-164 #resolve
Browse files Browse the repository at this point in the history
BL Compat module should coerce null values to empty string
  • Loading branch information
lmajano committed Jul 9, 2024
1 parent 03f94e9 commit 637fefb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/main/bx/ModuleConfig.bx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
// Choose your engine: adobe or lucee
engine = "lucee",
isLucee = false,
isAdobe = false
isAdobe = false,
// This simulates the query to empty value that Adobe/Lucee do when NOT in full null support
// We default it to true to simulate Adobe/Lucee behavior
queryNullToEmpty = true
};

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/bx/interceptors/AdobeServerScope.bx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import java:ortus.boxlang.runtime.scopes.Key;
*/
class{

/**
* Injections by BoxLang
*/

property name;
property properties;
property log;
property interceptorService;
property boxRuntime;
property moduleRecord;

function configure(){
// Nothing to do here
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/bx/interceptors/LuceeServerScope.bx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import java:ortus.boxlang.runtime.scopes.Key;
*/
class{

/**
* Injections by BoxLang
*/

property name;
property properties;
property log;
property interceptorService;
property boxRuntime;
property moduleRecord;

function configure(){
// Nothing to do here
}
Expand Down
41 changes: 28 additions & 13 deletions src/main/bx/interceptors/QueryCompat.bx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ import java:ortus.boxlang.runtime.jdbc.QueryOptions;
*/
class{

/**
* Injections by BoxLang
*/

property name;
property properties;
property log;
property interceptorService;
property boxRuntime;
property moduleRecord;

function configure(){
// Nothing to do here
}
Expand Down Expand Up @@ -70,13 +81,13 @@ class{

/**
* add cache attribute aliases:
*
*
* - `cacheId` -> `cacheKey`
* - `cacheRegion` -> `cacheProvider`
* - `cachedWithin` -> `cacheTimeout` OR `cachedWithin="request"` should also be implemented
* - `cachedAfter` -> custom datetime check, followed by `cache=true, cacheTimeout=0`
*/

if( structOptions.keyExists( "cacheId" ) && !structOptions.keyExists( "cacheKey" ) ){
modifiedOptions.cacheKey = structOptions.cacheId;
}
Expand Down Expand Up @@ -108,12 +119,12 @@ class{

/**
* Modify the query results before they are returned to the calling code.
*
*
* This is where we handle CFML compatibility features at the data level, such as:
*
*
* - converting null values to empty strings [BL-164](https://ortussolutions.atlassian.net/browse/BL-164)
* - converting time values to the time specified in the `timezone` query option [BL-116](https://ortussolutions.atlassian.net/browse/BL-116)
*
*
* Incoming data:
* - sql : The original, unmodified SQL string,
* - bindings : Parameter binding values,
Expand All @@ -124,14 +135,18 @@ class{
* - executedQuery : The BoxLang ExecutedQuery instance - https://s3.amazonaws.com/apidocs.ortussolutions.com/boxlang/1.0.0/ortus/boxlang/runtime/jdbc/ExecutedQuery.html
*/
function postQueryExecute( struct data ){
data.data.map( ( row ) -> {
row.each( ( key, value, row ) -> {
// CFML Compatibility: Convert null values to empty strings
if( isNull( row[ key ] ) ){
row[ key ] = "";
}

// Only active if the setting: queryNullToEmpty is true
if( properties.containsKey( "queryNullToEmpty" ) && properties.queryNullToEmpty ){
data.data.map( ( row ) -> {
row.each( ( key, value, row ) -> {
// CFML Compatibility: Convert null values to empty strings
if( isNull( row[ key ] ) ){
row[ key ] = "";
}
} );
return row;
} );
return row;
});
}
}
}

0 comments on commit 637fefb

Please sign in to comment.