From 48ce4adf0b425acbfe7a57f2d82005101ee453cb Mon Sep 17 00:00:00 2001 From: Sven Hettwer Date: Wed, 30 Oct 2019 09:27:08 +0100 Subject: [PATCH] (#29)changed first regex group to be non-catching --- .../citrus/db/driver/statement/StatementComposer.java | 10 ++++------ .../db/driver/statement/StatementComposerTest.java | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/driver/src/main/java/com/consol/citrus/db/driver/statement/StatementComposer.java b/driver/src/main/java/com/consol/citrus/db/driver/statement/StatementComposer.java index c9650f0..9225c4c 100644 --- a/driver/src/main/java/com/consol/citrus/db/driver/statement/StatementComposer.java +++ b/driver/src/main/java/com/consol/citrus/db/driver/statement/StatementComposer.java @@ -39,18 +39,16 @@ private Collection determineParameterOrder(final String statement, The intended group to catch is the group of variables in the sql statement. In case of a callable statement, it is possible that the statement starts with a '? = ' indicating a out parameter of the statement. This parameter should be ignored concerning variable - replacement. That is why the first group catches the '? = ' (if existing) and the second group catches + replacement. That is why the first non-catching group handles the '? = ' (if existing) and the second group catches named and unnamed variable references within the rest of the sql statement. - This is why the first group should be ignored due variable substitution while the second group contains all - variables to replace */ - final Pattern parameterPattern = Pattern.compile("^(\\? ?=)+|(:[a-zA-Z]+|\\?)"); + final Pattern parameterPattern = Pattern.compile("(?:\\? ?=)|(:[a-zA-Z]+|\\?)"); final Matcher parameterMatcher = parameterPattern.matcher(statement); final LinkedList orderedParameterList = new LinkedList<>(); for(int matchIndex = 1; parameterMatcher.find(); matchIndex++){ - final String parameterPlaceholder = parameterMatcher.group(2); + final String parameterPlaceholder = parameterMatcher.group(1); if(parameterPlaceholder != null) { orderedParameterList.add( getParameterValue(parameters, parameterPlaceholder, matchIndex)); @@ -76,4 +74,4 @@ private Object getParameterValue(final StatementParameters parameters, return parameterPlaceholder; } } -} +} \ No newline at end of file diff --git a/driver/src/test/java/com/consol/citrus/db/driver/statement/StatementComposerTest.java b/driver/src/test/java/com/consol/citrus/db/driver/statement/StatementComposerTest.java index 9b2bb5c..10d90e9 100644 --- a/driver/src/test/java/com/consol/citrus/db/driver/statement/StatementComposerTest.java +++ b/driver/src/test/java/com/consol/citrus/db/driver/statement/StatementComposerTest.java @@ -113,11 +113,13 @@ public void testCallableStatementParameterAreReplacedCorrectly(){ public void testReturnValuesOfCallableStatementsAreParsedCorrectly(){ //GIVEN - final String statement = "? = CALL someFunction(?)"; - final String expectedComposedStatement = statement + " - (?)"; + final String statement = "{? = CALL someFunction(?)}"; + final StatementParameters statementParameters = new StatementParameters(); + statementParameters.setParameter(2, "foobar"); + final String expectedComposedStatement = statement + " - (foobar)"; //WHEN - final String composedStatement = statementComposer.composeStatement(statement, new StatementParameters()); + final String composedStatement = statementComposer.composeStatement(statement, statementParameters); //THEN assertEquals(composedStatement, expectedComposedStatement);