Skip to content

Commit

Permalink
Fixed substring function to be 0-based
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Sep 18, 2024
1 parent f798b7d commit d83530b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FROST-Server version 2.5 and higher requires Java 21. This is because some libra
* Set limit to 1 for entity-by-primary-key requests.
* Improved OpenAPI generator, better property types.
* Fixed substring not working on PostgreSQL due to failing cast.
* Fixed substring function to be 0-based. substring(name,1) should return name after
the first character, but it returned name including the first character.


## Release version 2.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,9 @@ public FieldWrapper visit(Substring node) {
Expression p3 = node.getParameters().get(2);
FieldWrapper e3 = p3.accept(this);
Field<Integer> n3 = e3.getFieldAsType(Integer.class, true);
return new SimpleFieldWrapper(DSL.substring(s1, n2, n3));
return new SimpleFieldWrapper(DSL.substring(s1, n2.add(1), n3));
}
return new SimpleFieldWrapper(DSL.substring(s1, n2));
return new SimpleFieldWrapper(DSL.substring(s1, n2.add(1)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ void testSubString() throws ServiceFailureException {
LOGGER.info(" testSubString");
Dao doa = sSrvc.dao(sMdl.etThing);

testFilterResults(doa, "substring(properties/string, 1) eq 'wo'", getFromList(THINGS, 2));
testFilterResults(doa, "substring(properties/string, 1, 1) eq 'w'", getFromList(THINGS, 2));
testFilterResults(doa, "substring(name, 4) eq 'g 4'", getFromList(THINGS, 3));
testFilterResults(doa, "substring(name, 4, 3) eq 'g 4'", getFromList(THINGS, 3));
}

Expand Down

0 comments on commit d83530b

Please sign in to comment.