From d83530b924a5e2628fe2524977b6c6d1d41d6134 Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Wed, 18 Sep 2024 09:40:35 +0200 Subject: [PATCH] Fixed substring function to be 0-based --- CHANGELOG.md | 2 ++ .../frostserver/persistence/pgjooq/PgExpressionHandler.java | 4 ++-- .../iosb/ilt/statests/c03filtering/FilterTests.java | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c0b5f23..3f64f911b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java index 38ce71dac..78fa80654 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java @@ -1252,9 +1252,9 @@ public FieldWrapper visit(Substring node) { Expression p3 = node.getParameters().get(2); FieldWrapper e3 = p3.accept(this); Field 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 diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java index 30422bc38..8bfdac77c 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java @@ -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)); }