Skip to content

Commit e14fcd0

Browse files
committed
fix(jdbc): throw SQLFeatureNotSupportedException instead of SQLException for unsupported features
1 parent 1cab301 commit e14fcd0

File tree

4 files changed

+148
-100
lines changed

4 files changed

+148
-100
lines changed

src/main/java/org/sqlite/jdbc3/JDBC3Connection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.PreparedStatement;
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
7+
import java.sql.SQLFeatureNotSupportedException;
78
import java.sql.SQLWarning;
89
import java.sql.Savepoint;
910
import java.sql.Statement;
@@ -211,9 +212,7 @@ public void rollback(Savepoint savepoint) throws SQLException {
211212
getAutoCommit());
212213
}
213214

214-
// UNUSED FUNCTIONS /////////////////////////////////////////////
215-
216215
public Struct createStruct(String t, Object[] attr) throws SQLException {
217-
throw new SQLException("unsupported by SQLite");
216+
throw new SQLFeatureNotSupportedException("not implemented by SQLite JDBC driver");
218217
}
219218
}

src/main/java/org/sqlite/jdbc3/JDBC3PreparedStatement.java

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.sql.ResultSet;
1616
import java.sql.ResultSetMetaData;
1717
import java.sql.SQLException;
18+
import java.sql.SQLFeatureNotSupportedException;
1819
import java.sql.Statement;
1920
import java.sql.Time;
2021
import java.sql.Timestamp;
@@ -185,10 +186,7 @@ public void setBigDecimal(int pos, BigDecimal value) throws SQLException {
185186
*/
186187
private byte[] readBytes(InputStream istream, int length) throws SQLException {
187188
if (length < 0) {
188-
SQLException exception =
189-
new SQLException("Error reading stream. Length should be non-negative");
190-
191-
throw exception;
189+
throw new SQLException("Error reading stream. Length should be non-negative");
192190
}
193191

194192
byte[] bytes = new byte[length];
@@ -404,55 +402,97 @@ public ResultSetMetaData getMetaData() throws SQLException {
404402
return (ResultSetMetaData) rs;
405403
}
406404

407-
// UNUSED ///////////////////////////////////////////////////////
408-
protected SQLException unused() {
409-
return new SQLException("not implemented by SQLite JDBC driver");
405+
protected SQLException unsupported() {
406+
return new SQLFeatureNotSupportedException("not implemented by SQLite JDBC driver");
407+
}
408+
409+
protected SQLException invalid() {
410+
return new SQLException("method cannot be called on a PreparedStatement");
410411
}
411412

412413
// PreparedStatement ////////////////////////////////////////////
413414

414415
public void setArray(int i, Array x) throws SQLException {
415-
throw unused();
416+
throw unsupported();
416417
}
417-
// public void setBigDecimal(int parameterIndex, BigDecimal x)
418-
// throws SQLException { throw unused(); }
418+
419419
public void setBlob(int i, Blob x) throws SQLException {
420-
throw unused();
420+
throw unsupported();
421421
}
422422

423423
public void setClob(int i, Clob x) throws SQLException {
424-
throw unused();
424+
throw unsupported();
425425
}
426426

427427
public void setRef(int i, Ref x) throws SQLException {
428-
throw unused();
428+
throw unsupported();
429429
}
430430

431431
public void setURL(int pos, URL x) throws SQLException {
432-
throw unused();
432+
throw unsupported();
433433
}
434434

435435
/** @see org.sqlite.core.CoreStatement#exec(java.lang.String) */
436436
@Override
437437
public boolean execute(String sql) throws SQLException {
438-
throw unused();
438+
throw invalid();
439+
}
440+
441+
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
442+
throw invalid();
443+
}
444+
445+
public boolean execute(String sql, int[] colinds) throws SQLException {
446+
throw invalid();
447+
}
448+
449+
public boolean execute(String sql, String[] colnames) throws SQLException {
450+
throw invalid();
439451
}
440452

441453
/** @see org.sqlite.core.CoreStatement#exec(java.lang.String) */
442454
@Override
443455
public int executeUpdate(String sql) throws SQLException {
444-
throw unused();
456+
throw invalid();
457+
}
458+
459+
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
460+
throw invalid();
461+
}
462+
463+
public int executeUpdate(String sql, int[] colinds) throws SQLException {
464+
throw invalid();
465+
}
466+
467+
public int executeUpdate(String sql, String[] cols) throws SQLException {
468+
throw invalid();
469+
}
470+
471+
public long executeLargeUpdate(String sql) throws SQLException {
472+
throw invalid();
473+
}
474+
475+
public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
476+
throw invalid();
477+
}
478+
479+
public long executeLargeUpdate(String sql, int[] colinds) throws SQLException {
480+
throw invalid();
481+
}
482+
483+
public long executeLargeUpdate(String sql, String[] cols) throws SQLException {
484+
throw invalid();
445485
}
446486

447487
/** @see org.sqlite.core.CoreStatement#exec(String) */
448488
@Override
449489
public ResultSet executeQuery(String sql) throws SQLException {
450-
throw unused();
490+
throw invalid();
451491
}
452492

453493
/** */
454494
@Override
455495
public void addBatch(String sql) throws SQLException {
456-
throw unused();
496+
throw invalid();
457497
}
458498
}

src/main/java/org/sqlite/jdbc3/JDBC3Statement.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.sql.Connection;
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
7+
import java.sql.SQLFeatureNotSupportedException;
78
import java.sql.SQLWarning;
89
import java.util.Arrays;
910
import org.sqlite.ExtendedCommand;
@@ -74,7 +75,7 @@ public ResultSet executeQuery(String sql) throws SQLException {
7475

7576
static class BackupObserver implements ProgressObserver {
7677
public void progress(int remaining, int pageCount) {
77-
System.out.println(String.format("remaining:%d, page count:%d", remaining, pageCount));
78+
System.out.printf("remaining:%d, page count:%d%n", remaining, pageCount);
7879
}
7980
}
8081

@@ -364,29 +365,37 @@ public int getResultSetType() throws SQLException {
364365
/** @see java.sql.Statement#setEscapeProcessing(boolean) */
365366
public void setEscapeProcessing(boolean enable) throws SQLException {
366367
if (enable) {
367-
throw unused();
368+
throw unsupported();
368369
}
369370
}
370371

371-
protected SQLException unused() {
372-
return new SQLException("not implemented by SQLite JDBC driver");
372+
protected SQLException unsupported() {
373+
return new SQLFeatureNotSupportedException("not implemented by SQLite JDBC driver");
373374
}
374375

375376
// Statement ////////////////////////////////////////////////////
376377

377378
public boolean execute(String sql, int[] colinds) throws SQLException {
378-
throw unused();
379+
throw unsupported();
379380
}
380381

381382
public boolean execute(String sql, String[] colnames) throws SQLException {
382-
throw unused();
383+
throw unsupported();
383384
}
384385

385386
public int executeUpdate(String sql, int[] colinds) throws SQLException {
386-
throw unused();
387+
throw unsupported();
387388
}
388389

389390
public int executeUpdate(String sql, String[] cols) throws SQLException {
390-
throw unused();
391+
throw unsupported();
392+
}
393+
394+
public long executeLargeUpdate(String sql, int[] colinds) throws SQLException {
395+
throw unsupported();
396+
}
397+
398+
public long executeLargeUpdate(String sql, String[] cols) throws SQLException {
399+
throw unsupported();
391400
}
392401
}

0 commit comments

Comments
 (0)