-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.databend.jdbc; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.commons.lang3.tuple.ImmutablePair; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static com.databend.jdbc.StatementUtil.replaceParameterMarksWithValues; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
public class StatementUtilTest { | ||
@Test | ||
void shouldGetAllQueryParamsFromIn() { | ||
String sql = "SElECT * FROM EMPLOYEES WHERE id IN (?,?)"; | ||
assertEquals(ImmutableMap.of(1, 37, 2, 39), StatementUtil.getParamMarketsPositions(sql)); | ||
assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); | ||
} | ||
@Test | ||
void shouldGetAllQueryParams() { | ||
String sql = "SElECT * FROM EMPLOYEES WHERE id = ?"; | ||
assertEquals(ImmutableMap.of(1, 35), StatementUtil.getParamMarketsPositions(sql)); | ||
assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); | ||
} | ||
|
||
@Test | ||
void shouldReplaceAQueryParam() { | ||
String sql = "SElECT * FROM EMPLOYEES WHERE id is ?"; | ||
String expectedSql = "SElECT * FROM EMPLOYEES WHERE id is 5"; | ||
Map<Integer, String> params = ImmutableMap.of(1, "5"); | ||
System.out.println(replaceParameterMarksWithValues(params, sql)); | ||
assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); | ||
} | ||
|
||
@Test | ||
void shouldReplaceMultipleQueryParams() { | ||
String sql = "SElECT * FROM EMPLOYEES WHERE id = ? AND name LIKE ? AND dob = ? "; | ||
String expectedSql = "SElECT * FROM EMPLOYEES WHERE id = 5 AND name LIKE 'George' AND dob = '1980-05-22' "; | ||
Map<Integer, String> params = ImmutableMap.of(1, "5", 2, "'George'", 3, "'1980-05-22'"); | ||
assertEquals(expectedSql, replaceParameterMarksWithValues(params, sql).get(0).getSql()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters