Skip to content

Commit 966e411

Browse files
committed
Remove exception for returing of column names
1 parent 8f8ab4c commit 966e411

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

jdbc/src/main/java/tech/ydb/jdbc/impl/YdbConnectionImpl.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,32 +216,47 @@ public YdbStatement createStatement(int resultSetType, int resultSetConcurrency,
216216
public YdbPreparedStatement prepareStatement(String origSql, int resultSetType, int resultSetConcurrency,
217217
int resultSetHoldability) throws SQLException {
218218
checkStatementParams(resultSetType, resultSetConcurrency, resultSetHoldability);
219-
return prepareStatement(origSql, resultSetType, YdbPrepareMode.AUTO);
219+
return prepareStatement(origSql, resultSetType, null, YdbPrepareMode.AUTO);
220220
}
221221

222222
@Override
223223
public YdbPreparedStatement prepareStatement(String sql, YdbPrepareMode mode) throws SQLException {
224-
return prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, mode);
224+
return prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, null, mode);
225225
}
226226

227227
@Override
228228
public YdbPreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
229-
if (autoGeneratedKeys != Statement.NO_GENERATED_KEYS) {
230-
throw new SQLFeatureNotSupportedException(YdbConst.AUTO_GENERATED_KEYS_UNSUPPORTED);
229+
if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS) {
230+
return prepareStatement(sql);
231231
}
232-
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
233-
ResultSet.HOLD_CURSORS_OVER_COMMIT);
232+
return prepareStatement(sql, new String[]{"*"});
233+
}
234+
235+
@Override
236+
public YdbPreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
237+
if (columnIndexes != null && columnIndexes.length == 0) {
238+
return prepareStatement(sql);
239+
}
240+
throw new SQLFeatureNotSupportedException(YdbConst.AUTO_GENERATED_KEYS_UNSUPPORTED);
241+
}
242+
243+
@Override
244+
public YdbPreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
245+
if (columnNames == null || columnNames.length == 0) {
246+
return prepareStatement(sql);
247+
}
248+
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, columnNames, YdbPrepareMode.AUTO);
234249
}
235250

236-
private YdbPreparedStatement prepareStatement(String sql, int resultSetType, YdbPrepareMode mode)
251+
private YdbPreparedStatement prepareStatement(String sql, int type, String[] columnNames, YdbPrepareMode mode)
237252
throws SQLException {
238253

239254
validator.clearWarnings();
240255
ctx.getTracer().trace("prepare statement");
241256
YdbQuery query = ctx.findOrParseYdbQuery(sql);
242257
YdbPreparedQuery params = ctx.findOrPrepareParams(query, mode);
243258
ctx.getTracer().trace("create prepared statement");
244-
return new YdbPreparedStatementImpl(this, query, params, resultSetType);
259+
return new YdbPreparedStatementImpl(this, query, params, type);
245260
}
246261

247262
@Override
@@ -329,16 +344,6 @@ public CallableStatement prepareCall(String sql, int resultSetType, int resultSe
329344
throw new SQLFeatureNotSupportedException(YdbConst.PREPARED_CALLS_UNSUPPORTED);
330345
}
331346

332-
@Override
333-
public YdbPreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
334-
throw new SQLFeatureNotSupportedException(YdbConst.AUTO_GENERATED_KEYS_UNSUPPORTED);
335-
}
336-
337-
@Override
338-
public YdbPreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
339-
throw new SQLFeatureNotSupportedException(YdbConst.AUTO_GENERATED_KEYS_UNSUPPORTED);
340-
}
341-
342347
@Override
343348
public Clob createClob() throws SQLException {
344349
throw new SQLFeatureNotSupportedException(YdbConst.CLOB_UNSUPPORTED);

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbConnectionImplTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,22 @@ public void prepareStatement() throws SQLException {
165165
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT)) {
166166
TableAssert.assertSelectInt(2, statement.executeQuery());
167167
}
168+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1", new int[0])) {
169+
TableAssert.assertSelectInt(2, statement.executeQuery());
170+
}
171+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1", new String[0])) {
172+
TableAssert.assertSelectInt(2, statement.executeQuery());
173+
}
174+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1",
175+
Statement.RETURN_GENERATED_KEYS)) {
176+
TableAssert.assertSelectInt(2, statement.executeQuery());
177+
}
168178
}
169179

170180
@Test
171181
public void prepareStatementInvalid() throws SQLException {
172182
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
173-
() -> jdbc.connection().prepareStatement(SELECT_2_2, new int[] {})
174-
);
175-
176-
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
177-
() -> jdbc.connection().prepareStatement(SELECT_2_2, new String[] {})
178-
);
179-
180-
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
181-
() -> jdbc.connection().prepareStatement(SELECT_2_2, Statement.RETURN_GENERATED_KEYS)
183+
() -> jdbc.connection().prepareStatement(SELECT_2_2, new int[] {1, 2})
182184
);
183185

184186
ExceptionAssert.sqlFeatureNotSupported(

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbTableConnectionImplTest.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,22 @@ public void prepareStatement() throws SQLException {
166166
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT)) {
167167
TableAssert.assertSelectInt(2, statement.executeQuery());
168168
}
169+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1", new int[0])) {
170+
TableAssert.assertSelectInt(2, statement.executeQuery());
171+
}
172+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1", new String[0])) {
173+
TableAssert.assertSelectInt(2, statement.executeQuery());
174+
}
175+
try (PreparedStatement statement = jdbc.connection().prepareStatement("select 1 + 1",
176+
Statement.RETURN_GENERATED_KEYS)) {
177+
TableAssert.assertSelectInt(2, statement.executeQuery());
178+
}
169179
}
170180

171181
@Test
172182
public void prepareStatementInvalid() throws SQLException {
173183
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
174-
() -> jdbc.connection().prepareStatement(SELECT_2_2, new int[] {})
175-
);
176-
177-
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
178-
() -> jdbc.connection().prepareStatement(SELECT_2_2, new String[] {})
179-
);
180-
181-
ExceptionAssert.sqlFeatureNotSupported("Auto-generated keys are not supported",
182-
() -> jdbc.connection().prepareStatement(SELECT_2_2, Statement.RETURN_GENERATED_KEYS)
184+
() -> jdbc.connection().prepareStatement(SELECT_2_2, new int[] {1, 2})
183185
);
184186

185187
ExceptionAssert.sqlFeatureNotSupported(

0 commit comments

Comments
 (0)