Skip to content

Commit

Permalink
Merge remote-tracking branch 'xerial/master' into sync-3.45.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Willena committed Jan 21, 2024
2 parents a66e510 + c024a88 commit fdeeacb
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 20
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
# with:
# fetch-depth: 0
# - name: Set up Apache Maven Central
# uses: actions/setup-java@v3
# uses: actions/setup-java@v4
# with: # running setup-java again overwrites the settings.xml
# distribution: 'temurin'
# java-version: '11'
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ $(SQLITE_OUT)/sqlite3.o: $(SQLITE_UNPACKED) $(SQLITE_SOURCE)/sqlite3.c $(SQLITE_
-DSQLITE_ENABLE_CARRAY=1 \
-DSQLITE_ENABLE_SERIES=1 \
-DSQLITE_ENABLE_UUID=1 \
-DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS \
-DSQLITE_TEMP_STORE=2 \
-DSQLITE_USE_URI=1 \
-DSQLITE_USER_AUTHENTICATION=1 \
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= SQLite JDBC Driver
:project-version: 3.44.2.0
:project-version: 3.45.0.0

image:https://img.shields.io/github/actions/workflow/status/willena/sqlite-jdbc-crypt/ci.yml?branch=master[GitHub Workflow Status (branch),link=https://github.com/willena/sqlite-jdbc/actions/workflows/ci.yml?query=branch%3Amaster]
image:https://maven-badges.herokuapp.com/maven-central/io.github.willena/sqlite-jdbc/badge.svg[Maven Central,link=https://maven-badges.herokuapp.com/maven-central/io.github.willena/sqlite-jdbc/]
Expand Down
6 changes: 3 additions & 3 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=3.44.2
artifactVersion=3.44.2.0
sqliteMCVersion=1.8.1
version=3.45.0
artifactVersion=3.45.0.0-SNAPSHOT
sqliteMCVersion=1.8.2
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.willena</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.44.2.0</version>
<version>3.45.0.0-SNAPSHOT</version>
<name>SQLite JDBC</name>
<description>SQLite JDBC library with encryption and authentication support</description>
<url>https://github.com/Willena/sqlite-jdbc-crypt</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.1</junit.version>
<surefire.version>3.2.2</surefire.version>
<surefire.version>3.2.5</surefire.version>
<graalvm.version>23.1.1</graalvm.version>
<java9.sourceDirectory>${project.basedir}/src/main/java9</java9.sourceDirectory>
</properties>
Expand Down Expand Up @@ -98,7 +98,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<release>8</release>
</configuration>
Expand Down Expand Up @@ -196,7 +196,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.16.1</version>
<version>2.16.2</version>
</plugin>

<plugin>
Expand Down Expand Up @@ -300,7 +300,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<configuration>
<sourcepath>src/main/java</sourcepath>
<additionalOptions>-Xdoclint:none</additionalOptions>
Expand Down Expand Up @@ -425,7 +425,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<version>3.25.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -441,26 +441,26 @@
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.7.0</version>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
<!-- Required by archunit -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.12</version>
<version>1.2.13</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/sqlite/core/CoreStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.sqlite.SQLiteConnection;
import org.sqlite.SQLiteConnectionConfig;
import org.sqlite.jdbc3.JDBC3Connection;
Expand All @@ -33,6 +34,9 @@ public abstract class CoreStatement implements Codes {
protected Object[] batch = null;
protected boolean resultsWaiting = false;

private Statement generatedKeysStat = null;
private ResultSet generatedKeysRs = null;

protected CoreStatement(SQLiteConnection c) {
conn = c;
rs = new JDBC4ResultSet(this);
Expand Down Expand Up @@ -149,4 +153,48 @@ protected void checkIndex(int index) throws SQLException {
throw new SQLException("Parameter index is invalid");
}
}

protected void clearGeneratedKeys() throws SQLException {
if (generatedKeysRs != null && !generatedKeysRs.isClosed()) {
generatedKeysRs.close();
}
generatedKeysRs = null;
if (generatedKeysStat != null && !generatedKeysStat.isClosed()) {
generatedKeysStat.close();
}
generatedKeysStat = null;
}

/**
* SQLite's last_insert_rowid() function is DB-specific. However, in this implementation we
* ensure the Generated Key result set is statement-specific by executing the query immediately
* after an insert operation is performed. The caller is simply responsible for calling
* updateGeneratedKeys on the statement object right after execute in a synchronized(connection)
* block.
*/
public void updateGeneratedKeys() throws SQLException {
clearGeneratedKeys();
if (sql != null && sql.toLowerCase().startsWith("insert")) {
generatedKeysStat = conn.createStatement();
generatedKeysRs = generatedKeysStat.executeQuery("SELECT last_insert_rowid();");
}
}

/**
* This implementation uses SQLite's last_insert_rowid function to obtain the row ID. It cannot
* provide multiple values when inserting multiple rows. Suggestion is to use a <a
* href=https://www.sqlite.org/lang_returning.html>RETURNING</a> clause instead.
*
* @see java.sql.Statement#getGeneratedKeys()
*/
public ResultSet getGeneratedKeys() throws SQLException {
// getGeneratedKeys is required to return an EmptyResult set if the statement
// did not generate any keys. Thus, if the generateKeysResultSet is NULL, spin
// up a new result set without any contents by issuing a query with a false where condition
if (generatedKeysRs == null) {
generatedKeysStat = conn.createStatement();
generatedKeysRs = generatedKeysStat.executeQuery("SELECT 1 WHERE 1 = 2;");
}
return generatedKeysRs;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public boolean supportsFullOuterJoins() throws SQLException {

/** @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys() */
public boolean supportsGetGeneratedKeys() {
return false;
return true;
}

/** @see java.sql.DatabaseMetaData#supportsGroupBy() */
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/org/sqlite/jdbc3/JDBC3PreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ public boolean execute() throws SQLException {
() -> {
boolean success = false;
try {
resultsWaiting =
conn.getDatabase().execute(JDBC3PreparedStatement.this, batch);
success = true;
updateCount = getDatabase().changes();
synchronized (conn) {
resultsWaiting =
conn.getDatabase().execute(JDBC3PreparedStatement.this, batch);
updateGeneratedKeys();
success = true;
updateCount = getDatabase().changes();
}
return 0 != columnCount;
} finally {
if (!success && !pointer.isClosed()) pointer.safeRunConsume(DB::reset);
Expand Down Expand Up @@ -119,7 +122,15 @@ public long executeLargeUpdate() throws SQLException {
}

return this.withConnectionTimeout(
() -> conn.getDatabase().executeUpdate(JDBC3PreparedStatement.this, batch));
() -> {
synchronized (conn) {
long rc =
conn.getDatabase()
.executeUpdate(JDBC3PreparedStatement.this, batch);
updateGeneratedKeys();
return rc;
}
});
}

/** @see java.sql.PreparedStatement#addBatch() */
Expand Down
41 changes: 18 additions & 23 deletions src/main/java/org/sqlite/jdbc3/JDBC3Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected JDBC3Statement(SQLiteConnection conn) {

/** @see java.sql.Statement#close() */
public void close() throws SQLException {
clearGeneratedKeys();
internalClose();
}

Expand All @@ -49,12 +50,14 @@ public boolean execute(final String sql) throws SQLException {
}

JDBC3Statement.this.sql = sql;

conn.getDatabase().prepare(JDBC3Statement.this);
boolean result = exec();
updateCount = getDatabase().changes();
exhaustedResults = false;
return result;
synchronized (conn) {
conn.getDatabase().prepare(JDBC3Statement.this);
boolean result = exec();
updateGeneratedKeys();
updateCount = getDatabase().changes();
exhaustedResults = false;
return result;
}
});
}

Expand Down Expand Up @@ -126,13 +129,16 @@ public long executeLargeUpdate(String sql) throws SQLException {
ext.execute(db);
} else {
try {
changes = db.total_changes();

// directly invokes the exec API to support multiple SQL statements
int statusCode = db._exec(sql);
if (statusCode != SQLITE_OK) throw DB.newSQLException(statusCode, "");
synchronized (db) {
changes = db.total_changes();
// directly invokes the exec API to support multiple SQL statements
int statusCode = db._exec(sql);
if (statusCode != SQLITE_OK)
throw DB.newSQLException(statusCode, "");
updateGeneratedKeys();
changes = db.total_changes() - changes;
}

changes = db.total_changes() - changes;
} finally {
internalClose();
}
Expand Down Expand Up @@ -350,17 +356,6 @@ public void setFetchDirection(int direction) throws SQLException {
}
}

/**
* SQLite's last_insert_rowid() function is DB-specific, not statement specific, and cannot
* provide multiple values when inserting multiple rows. Suggestion is to use a <a
* href=https://www.sqlite.org/lang_returning.html>RETURNING</a> clause instead.
*
* @see java.sql.Statement#getGeneratedKeys()
*/
public ResultSet getGeneratedKeys() throws SQLException {
throw unsupported();
}

/**
* SQLite does not support multiple results from execute().
*
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/sqlite/DBMetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void close() throws SQLException {
public void getTables() throws SQLException {
ResultSet rs = meta.getTables(null, null, null, null);
assertThat(rs).isNotNull();

stat.close();

assertThat(rs.next()).isTrue();
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/org/sqlite/PrepStmtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ public void update() throws SQLException {
assertThat(prep.executeUpdate()).isEqualTo(1);
prep.setInt(1, 7);
assertThat(prep.executeUpdate()).isEqualTo(1);
prep.close();

ResultSet rsgk = prep.getGeneratedKeys();
assertThat(rsgk.next()).isTrue();
assertThat(rsgk.getInt(1)).isEqualTo(3);
rsgk.close();

prep.close();
// check results with normal statement
ResultSet rs = stat.executeQuery("select sum(c1) from s1;");
assertThat(rs.next()).isTrue();
Expand Down
Loading

0 comments on commit fdeeacb

Please sign in to comment.