Skip to content

Commit fe19820

Browse files
committed
Fix issue 13
1 parent d6ed1c7 commit fe19820

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/io/elastic/jdbc/QueryColumnNamesProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public JsonObject getMetaModel(JsonObject configuration) {
4444
public JsonObject getColumns(JsonObject configuration) {
4545
JsonObjectBuilder properties = Json.createObjectBuilder();
4646
String sqlQuery = configuration.getString("sqlQuery");
47+
Pattern patternPoint = Pattern.compile("\\B@\\S+");
48+
Matcher matcherPoint = patternPoint.matcher(sqlQuery);
49+
if (matcherPoint.find()) {
50+
do {
51+
if (matcherPoint.group().contains(".")){
52+
throw new RuntimeException(
53+
"The variable name of the prepared statement '"
54+
+ matcherPoint.group()
55+
+ "' should not contain '.' symbol");
56+
}
57+
} while (matcherPoint.find());
58+
}
4759
Pattern pattern = Pattern.compile(Utils.VARS_REGEXP);
4860
Matcher matcher = pattern.matcher(sqlQuery);
4961
Boolean isEmpty = true;

src/test/groovy/io/elastic/jdbc/QueryColumnNamesProviderSpec.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import javax.json.Json
66
import javax.json.JsonObject
77
import javax.json.JsonObjectBuilder
88

9-
@Ignore
109
class QueryColumnNamesProviderSpec extends Specification {
1110

1211
JsonObjectBuilder configuration = Json.createObjectBuilder()
1312
String sqlQuery
13+
String wrongSqlQuery
1414

1515
def setup() {
1616
sqlQuery = "SELECT * FROM films WHERE watched = @watched:boolean AND created = @created:date"
17+
wrongSqlQuery = "SELECT * FROM films WHERE watched = @watched.name:boolean"
1718
}
1819

1920
def "get metadata model, given json object"() {
@@ -25,4 +26,14 @@ class QueryColumnNamesProviderSpec extends Specification {
2526
expect:
2627
meta.toString() == "{\"out\":{\"type\":\"object\",\"properties\":{\"watched\":{\"title\":\"watched\",\"type\":\"boolean\"},\"created\":{\"title\":\"created\",\"type\":\"date\"}}},\"in\":{\"type\":\"object\",\"properties\":{\"watched\":{\"title\":\"watched\",\"type\":\"boolean\"},\"created\":{\"title\":\"created\",\"type\":\"date\"}}}}"
2728
}
29+
30+
def "get metadata model, wrong sqlQuery"() {
31+
configuration.add("sqlQuery", wrongSqlQuery)
32+
given :
33+
QueryColumnNamesProvider provider = new QueryColumnNamesProvider()
34+
when:
35+
provider.getMetaModel(configuration.build())
36+
then:
37+
thrown RuntimeException
38+
}
2839
}

0 commit comments

Comments
 (0)