Skip to content

Commit b6dcb57

Browse files
committed
Fixed prepared statements validations
1 parent 1141ff0 commit b6dcb57

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

jdbc/src/main/java/tech/ydb/jdbc/query/params/BatchedQuery.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,9 @@ public void clearBatch() {
9595

9696
protected StructValue getCurrentValues() throws SQLException {
9797
for (ParamDescription prm: params) {
98-
if (currentValues.containsKey(prm.name())) {
99-
continue;
98+
if (!currentValues.containsKey(prm.name())) {
99+
throw new SQLDataException(YdbConst.MISSING_VALUE_FOR_PARAMETER + prm.displayName());
100100
}
101-
102-
if (prm.type().isOptional()) {
103-
currentValues.put(prm.name(), prm.type().nullValue());
104-
continue;
105-
}
106-
107-
throw new SQLDataException(YdbConst.MISSING_VALUE_FOR_PARAMETER + prm.displayName());
108101
}
109102
return StructValue.of(currentValues);
110103
}

jdbc/src/main/java/tech/ydb/jdbc/query/params/BulkUpsertQuery.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public static BulkUpsertQuery build(String tablePath, List<String> columns, Tabl
5757

5858
Map<String, Type> structTypes = new HashMap<>();
5959
for (String column: columns) {
60+
if (!columnTypes.containsKey(column)) {
61+
throw new SQLException("Cannot parse BULK upsert: column " + column + " not found");
62+
}
6063
structTypes.put(column, columnTypes.get(column));
6164
}
6265

jdbc/src/main/java/tech/ydb/jdbc/query/params/InMemoryQuery.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44

5+
import java.sql.SQLDataException;
56
import java.sql.SQLException;
67
import java.util.ArrayList;
78
import java.util.HashMap;
@@ -109,15 +110,15 @@ public Params getCurrentParams() throws SQLException {
109110
@Override
110111
public String getNameByIndex(int index) throws SQLException {
111112
if (index <= 0 || index > parameters.size()) {
112-
throw new SQLException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
113+
throw new SQLDataException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
113114
}
114115
return parameters.get(index - 1).getName();
115116
}
116117

117118
@Override
118119
public TypeDescription getDescription(int index) throws SQLException {
119120
if (index <= 0 || index > parameters.size()) {
120-
throw new SQLException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
121+
throw new SQLDataException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
121122
}
122123

123124
JdbcPrm p = parameters.get(index - 1);
@@ -127,7 +128,7 @@ public TypeDescription getDescription(int index) throws SQLException {
127128
@Override
128129
public void setParam(int index, Object obj, int sqlType) throws SQLException {
129130
if (index <= 0 || index > parameters.size()) {
130-
throw new SQLException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
131+
throw new SQLDataException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + index);
131132
}
132133

133134
parameters.get(index - 1).setValue(obj, sqlType);
@@ -137,7 +138,7 @@ public void setParam(int index, Object obj, int sqlType) throws SQLException {
137138
public void setParam(String name, Object obj, int sqlType) throws SQLException {
138139
JdbcPrm param = parametersByName.get(name);
139140
if (param == null) {
140-
throw new SQLException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + name);
141+
throw new SQLDataException(YdbConst.PARAMETER_NUMBER_NOT_FOUND + name);
141142
}
142143
param.setValue(obj, sqlType);
143144
}

jdbc/src/main/java/tech/ydb/jdbc/query/params/SimpleJdbcPrm.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.jdbc.query.params;
22

3+
import java.sql.SQLDataException;
34
import java.sql.SQLException;
45

56
import tech.ydb.jdbc.YdbConst;
@@ -34,7 +35,7 @@ public void reset() {
3435
@Override
3536
public void copyToParams(Params params) throws SQLException {
3637
if (value == null) {
37-
throw new SQLException(YdbConst.MISSING_VALUE_FOR_PARAMETER + name);
38+
throw new SQLDataException(YdbConst.MISSING_VALUE_FOR_PARAMETER + name);
3839
}
3940
params.put(name, value);
4041
}
@@ -56,7 +57,7 @@ public void setValue(Object obj, int sqlType) throws SQLException {
5657

5758
Type type = YdbTypes.findType(obj, sqlType);
5859
if (type == null) {
59-
throw new SQLException(String.format(YdbConst.PARAMETER_TYPE_UNKNOWN, sqlType, obj));
60+
throw new SQLDataException(String.format(YdbConst.PARAMETER_TYPE_UNKNOWN, sqlType, obj));
6061
}
6162

6263
if (obj == null) {

0 commit comments

Comments
 (0)