Skip to content

Commit

Permalink
Merge pull request apache#611 from Jugen/fix-clob-empty-string-compar…
Browse files Browse the repository at this point in the history
…ison

CAY-2850 Query using Clob comparison with empty String fails
  • Loading branch information
stariy95 authored Apr 23, 2024
2 parents e0a5d09 + 9143de9 commit 064dc2a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ CAY-2827 Saved data-source XML data doesn't correspond to the XSD schema
CAY-2838 Vertical Inheritance: Problem setting db attribute to null via flattened path
CAY-2840 Vertical Inheritance: Missing subclass attributes with joint prefetch
CAY-2841 Multi column ColumnSelect with SHARED_CACHE fails after 1st select
CAY-2844 Joint prefetch doesn't use ObjEntity qualifier
CAY-2844 Joint prefetch doesn't use ObjEntity qualifier
CAY-2850 Query using Clob comparison with empty String fails
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ protected int getColumnSize() {
}
if(sibling.getType() == NodeType.VALUE) {
if(((ValueNode)sibling).getValue() instanceof CharSequence) {
return ((CharSequence) ((ValueNode)sibling).getValue()).length();
int valLen = ((CharSequence) ((ValueNode)sibling).getValue()).length();
return Math.max(1, valLen);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DerbyValueNode(Object value, boolean isArray, DbAttribute attribute, bool

protected void appendStringValue(QuotingAppendable buffer, CharSequence value) {
if(getAttribute() == null || (getAttribute() != null && getAttribute().getType() == Types.CLOB)) {
buffer.append(" CAST(? AS VARCHAR(").append(value.length()).append("))");
buffer.append(" CAST(? AS VARCHAR(").append(Math.max(1,value.length())).append("))");
} else {
buffer.append(" ?");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void onValueNode(Node parent, ValueNode child, int index) {
protected void appendStringValue(QuotingAppendable buffer, CharSequence value) {
buffer.append("CAST(");
super.appendStringValue(buffer, value);
buffer.append(" AS VARCHAR(").append(value.length()).append("))");
buffer.append(" AS VARCHAR(").append(Math.max(1,value.length())).append("))");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ public void testSelectNotEqualsClob() throws Exception {
assertEquals(1, objects.size());
}
}

@Test
public void testSelectNotEqualsEmptyClob() throws Exception {
if (accessStackAdapter.supportsLobComparisons()) {
createClobDataSet();
List<?> objects = ObjectSelect.query(ClobTestEntity.class)
.where(ClobTestEntity.CLOB_COL.ne(""))
.select(context);
assertEquals(2, objects.size());
}
}
}

0 comments on commit 064dc2a

Please sign in to comment.