@@ -44,28 +44,37 @@ public JsonObject getMetaModel(JsonObject configuration) {
44
44
public JsonObject getColumns (JsonObject configuration ) {
45
45
JsonObjectBuilder properties = Json .createObjectBuilder ();
46
46
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
- }
47
+ Pattern patternCheckCharacter = Pattern .compile ("\\ B@\\ S+" );
48
+ Matcher matcherCheckCharacter = patternCheckCharacter .matcher (sqlQuery );
59
49
Pattern pattern = Pattern .compile (Utils .VARS_REGEXP );
60
50
Matcher matcher = pattern .matcher (sqlQuery );
61
51
Boolean isEmpty = true ;
62
52
if (matcher .find ()) {
63
53
do {
54
+ matcherCheckCharacter .find ();
64
55
LOGGER .info ("Var = {}" , matcher .group ());
56
+ LOGGER .info ("Var matcherCheckCharacter = {}" , matcherCheckCharacter .group ());
57
+ if (!matcher .group ().equals (matcherCheckCharacter .group ())){
58
+ throw new RuntimeException (
59
+ "Prepared statement variables name '"
60
+ + matcherCheckCharacter .group ()
61
+ + "' contains a forbidden character. "
62
+ + "The name could contain: any word character, a digit and a character '_'" );
63
+ }
65
64
JsonObjectBuilder field = Json .createObjectBuilder ();
66
65
String result [] = matcher .group ().split (":" );
67
- String name = result [0 ].substring (1 );
68
- String type = result [1 ];
66
+ String name ;
67
+ String type ;
68
+ if (result .length > 0 && result .length < 3 ){
69
+ name = result [0 ].substring (1 );
70
+ if (result .length == 1 ){
71
+ type = "string" ;
72
+ } else {
73
+ type = result [1 ];
74
+ }
75
+ } else {
76
+ throw new RuntimeException ("Incorrect prepared statement" + matcher .group ());
77
+ }
69
78
field .add ("title" , name )
70
79
.add ("type" , type );
71
80
properties .add (name , field );
0 commit comments