Skip to content

Commit 4e6038e

Browse files
committed
BLMODULES-29 - ensure correct casting for boolean strings in HQL
1 parent 476e952 commit 4e6038e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/main/java/ortus/boxlang/modules/orm/HQLQuery.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private List<QueryParameter> buildParameterList( Array positionalParameters, ISt
122122
}
123123

124124
boolean isPositional = positionalParameters != null;
125-
String HQL = this.hql;
125+
String HQL = sanitizeHQL( this.hql );
126126
// This is the HQL string with the named parameters replaced with positional placeholders
127127
StringBuilder newHQL = new StringBuilder();
128128
// This is the name of the current named parameter being processed
@@ -349,4 +349,17 @@ public Object execute() {
349349
}
350350

351351
}
352+
353+
/**
354+
* Sanitize the HQL string to ensure that common strings are cast correctly
355+
*
356+
* @param hql
357+
*
358+
* @return
359+
*/
360+
private String sanitizeHQL( String hql ) {
361+
return hql.replaceAll( "= true", "= cast( true as boolean )" )
362+
.replaceAll( "= false", "= cast( true as boolean )" );
363+
364+
}
352365
}

src/test/java/ortus/boxlang/modules/orm/bifs/ORMExecuteQueryTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ public void testHQLCollection() {
153153
@Test
154154
public void testHQLAdvancedMap() {
155155
// @formatter:off
156-
// TODO: We need to add support for a raw `WHERE isPublished = true` which currently throws a strict type error
157156
instance.executeSource( """
158157
results = ormExecuteQuery( "
159158
SELECT new map(
@@ -162,10 +161,10 @@ SELECT new map(
162161
MONTH( MAX( publishedDate ) ) as month
163162
)
164163
FROM cbEntry
165-
WHERE isPublished = :isPublished
164+
WHERE isPublished = true
166165
AND passwordProtection = ''
167166
AND publishedDate <= :now",
168-
{ isPublished: true, now : now() }
167+
{ now : now() }
169168
);
170169
result = results.map( ( entity ) => getMetadata( entity ).name );
171170

0 commit comments

Comments
 (0)