[Git][java-team/xerial-sqlite-jdbc][master] 7 commits: Refreshing the list of files to exclude when repacking
Pierre Gruet (@pgt)
gitlab at salsa.debian.org
Wed Apr 10 21:46:01 BST 2024
Pierre Gruet pushed to branch master at Debian Java Maintainers / xerial-sqlite-jdbc
Commits:
94c71945 by Pierre Gruet at 2024-04-10T21:49:57+02:00
Refreshing the list of files to exclude when repacking
- - - - -
a3744462 by Pierre Gruet at 2024-04-10T21:50:07+02:00
New upstream version 3.45.2.0+dfsg
- - - - -
6c10c125 by Pierre Gruet at 2024-04-10T21:50:09+02:00
Update upstream source from tag 'upstream/3.45.2.0+dfsg'
Update to upstream version '3.45.2.0+dfsg'
with Debian dir 4f8479815b29375077193ec746c0c5b216044460
- - - - -
ac43e878 by Pierre Gruet at 2024-04-10T21:51:17+02:00
Refreshing patches
- - - - -
4539b917 by Pierre Gruet at 2024-04-10T21:51:56+02:00
Raising Standards version to 4.7.0 (no change)
- - - - -
0b70abbf by Pierre Gruet at 2024-04-10T21:52:39+02:00
Updating changelog
- - - - -
fbc337bf by Pierre Gruet at 2024-04-10T21:53:22+02:00
Upload to unstable
- - - - -
24 changed files:
- Makefile
- README.adoc
- USAGE.md
- VERSION
- debian/changelog
- debian/control
- debian/copyright
- debian/patches/allow_discrepancy_in_driver_version.patch
- debian/patches/build.patch
- debian/patches/cleaning.patch
- debian/patches/junit-jupiter-params_artifact.patch
- debian/patches/test.patch
- debian/patches/tests_without_archunit-junit5_and_some_assertions.patch
- demo/Sample.java
- pom.xml
- src/main/java/org/sqlite/core/CoreStatement.java
- src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
- src/main/java/org/sqlite/jdbc3/JDBC3PreparedStatement.java
- src/main/java/org/sqlite/jdbc3/JDBC3Statement.java
- − src/main/resources/org/sqlite/native/Mac/aarch64/libsqlitejdbc.dylib
- − src/main/resources/org/sqlite/native/Mac/x86_64/libsqlitejdbc.dylib
- src/test/java/org/sqlite/DBMetaDataTest.java
- src/test/java/org/sqlite/PrepStmtTest.java
- src/test/java/org/sqlite/StatementTest.java
Changes:
=====================================
Makefile
=====================================
@@ -31,6 +31,7 @@ CCFLAGS:= -I$(SQLITE_OUT) -I$(SQLITE_INCLUDE) $(CCFLAGS)
$(SQLITE_ARCHIVE):
@mkdir -p $(@D)
+ curl -L --max-redirs 0 -f -o$@ https://www.sqlite.org/2024/$(SQLITE_AMAL_PREFIX).zip || \
curl -L --max-redirs 0 -f -o$@ https://www.sqlite.org/2023/$(SQLITE_AMAL_PREFIX).zip || \
curl -L --max-redirs 0 -f -o$@ https://www.sqlite.org/2022/$(SQLITE_AMAL_PREFIX).zip || \
curl -L --max-redirs 0 -f -o$@ https://www.sqlite.org/2021/$(SQLITE_AMAL_PREFIX).zip || \
=====================================
README.adoc
=====================================
@@ -1,5 +1,5 @@
= SQLite JDBC Driver
-:project-version: 3.44.1.0
+:project-version: 3.45.2.0
image:https://img.shields.io/github/actions/workflow/status/xerial/sqlite-jdbc/ci.yml?branch=master[GitHub Workflow Status (branch),link=https://github.com/xerial/sqlite-jdbc/actions/workflows/ci.yml?query=branch%3Amaster]
image:https://badges.gitter.im/xerial/sqlite-jdbc.svg[Join the chat,link=https://gitter.im/xerial/sqlite-jdbc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge]
@@ -62,12 +62,15 @@ id = 2
{
public static void main(String[] args)
{
- Connection connection = null;
+ // NOTE: Connection and Statement are AutoClosable.
+ // Don't forget to close them both in order to avoid leaks.
try
- {
+ (
// create a database connection
- connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
+ Connection connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
Statement statement = connection.createStatement();
+ )
+ {
statement.setQueryTimeout(30); // set timeout to 30 sec.
statement.executeUpdate("drop table if exists person");
@@ -86,20 +89,7 @@ id = 2
{
// if the error message is "out of memory",
// it probably means no database file is found
- System.err.println(e.getMessage());
- }
- finally
- {
- try
- {
- if(connection != null)
- connection.close();
- }
- catch(SQLException e)
- {
- // connection close failed.
- System.err.println(e.getMessage());
- }
+ e.printStackTrace(System.err);
}
}
}
@@ -193,6 +183,33 @@ Download from https://search.maven.org/artifact/org.xerial/sqlite-jdbc[Maven Cen
Snapshots of the development version are available in https://oss.sonatype.org/content/repositories/snapshots/org/xerial/sqlite-jdbc/[Sonatype's snapshots repository].
+=== Validating downloads
+
+Maven Central resources are signed using https://gnupg.org/[GPG] and the signature files, ending in .asc, are available in the same location as the other downloads.
+
+The following key is currently used to sign releases:
+
+----
+
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Comment: C1CB A75E C9BD 0BAF 8061 9354 59E0 5CE6 1818 7ED4
+Comment: Taro L. Saito (For GitHub Actions) <leo at xerial.org>
+
+xjMEYuRVGhYJKwYBBAHaRw8BAQdA2Dp4m1Yhtb1g94pQzzL24FuP6b9KXF8lP9Dh
+hZnynhfNM1Rhcm8gTC4gU2FpdG8gKEZvciBHaXRIdWIgQWN0aW9ucykgPGxlb0B4
+ZXJpYWwub3JnPsKUBBMWCgA8FiEEwcunXsm9C6+AYZNUWeBc5hgYftQFAmLkVRoC
+GwMFCwkIBwIDIgIBBhUKCQgLAgQWAgMBAh4HAheAAAoJEFngXOYYGH7UfPwBAK7x
+TVRebZeWcAwmGaMUsbg7SgJou8xnkhByObPLUC/4AQDPsZeYmi4KXyXPzmqhCicd
+Y+ZSJWIDQqitK2ujPDFXA844BGLkVRoSCisGAQQBl1UBBQEBB0Atu9kejBi+6wfO
+T0a9z/LYEEdNXM/VX6xt1onKToPPdQMBCAfCeAQYFgoAIBYhBMHLp17JvQuvgGGT
+VFngXOYYGH7UBQJi5FUaAhsMAAoJEFngXOYYGH7UlMABAKyRCazhVyUFg5FOpAnm
+ckBY38CaMGPPLXVyY8Kr6dYFAP9wYLu7nsDZCOXkAgS+et4Pk1WZCggoYUkxsX1o
+0KZXBQ==
+=Wyas
+-----END PGP PUBLIC KEY BLOCK-----
+
+----
+
=== Project versioning explained
The project's version follows the version of the SQLite library that is bundled in the jar, with an extra digit to denote the project's increment.
@@ -229,4 +246,4 @@ We are always looking for:
- *Reviewers* for issues or PRs, you can check image:https://img.shields.io/github/labels/xerial/sqlite-jdbc/review%20wanted[GitHub labels,link=https://github.com/xerial/sqlite-jdbc/labels/review%20wanted]
- *Contributors* to submit PRs, you can check image:https://img.shields.io/github/labels/xerial/sqlite-jdbc/help%20wanted[GitHub labels,link=https://github.com/xerial/sqlite-jdbc/labels/help%20wanted] and image:https://img.shields.io/github/labels/xerial/sqlite-jdbc/good%20first%20issue[GitHub labels,link=https://github.com/xerial/sqlite-jdbc/labels/good%20first%20issue]
-Please read our link:./CONTRIBUTING.md[contribution] guide.
\ No newline at end of file
+Please read our link:./CONTRIBUTING.md[contribution] guide.
=====================================
USAGE.md
=====================================
@@ -3,48 +3,54 @@
Here is an example to establishing a connection to a database file `C:\work\mydatabase.db` (in Windows)
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite:C:/work/mydatabase.db");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite:C:/work/mydatabase.db")) { /*...*/ }
```
Opening a UNIX (Linux, maxOS, etc.) file `/home/leo/work/mydatabase.db`
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite:/home/leo/work/mydatabase.db");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite:/home/leo/work/mydatabase.db")) { /*...*/ }
```
## How to Use Memory Databases
SQLite supports on-memory database management, which does not create any database files. To use a memory database in your Java code, get the database connection as follows:
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:")) { /*...*/ }
```
And also, you can create memory database as follows:
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite:");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite:")) { /*...*/ }
```
## How to use Online Backup and Restore Feature
Take a backup of the whole database to `backup.db` file:
```java
-// Create a memory database
-Connection conn = DriverManager.getConnection("jdbc:sqlite:");
-Statement stmt = conn.createStatement();
-// Do some updates
-stmt.executeUpdate("create table sample(id, name)");
-stmt.executeUpdate("insert into sample values(1, \"leo\")");
-stmt.executeUpdate("insert into sample values(2, \"yui\")");
-// Dump the database contents to a file
-stmt.executeUpdate("backup to backup.db");
+try (
+ // Create a memory database
+ Connection conn = DriverManager.getConnection("jdbc:sqlite:");
+ Statement stmt = conn.createStatement();
+) {
+ // Do some updates
+ stmt.executeUpdate("create table sample(id, name)");
+ stmt.executeUpdate("insert into sample values(1, \"leo\")");
+ stmt.executeUpdate("insert into sample values(2, \"yui\")");
+ // Dump the database contents to a file
+ stmt.executeUpdate("backup to backup.db");
+}
```
Restore the database from a backup file:
```java
-// Create a memory database
-Connection conn = DriverManager.getConnection("jdbc:sqlite:");
-// Restore the database from a backup file
-Statement stat = conn.createStatement();
-stat.executeUpdate("restore from backup.db");
+try (
+ // Create a memory database
+ Connection conn = DriverManager.getConnection("jdbc:sqlite:");
+ // Restore the database from a backup file
+ Statement stat = conn.createStatement();
+) {
+ stat.executeUpdate("restore from backup.db");
+}
```
## Creating BLOB data
@@ -62,18 +68,18 @@ use `jdbc:sqlite::resource:` prefix.
For example, here is an example to access an SQLite DB file, `sample.db`
in a Java package `org.yourdomain`:
```java
-Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:org/yourdomain/sample.db");
+try (Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:org/yourdomain/sample.db")) { /*...*/ }
```
In addition, external DB resources can be used as follows:
```java
-Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc/src/test/java/org/sqlite/sample.db");
+try (Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc/src/test/java/org/sqlite/sample.db")) { /*...*/ }
```
To access db files inside some specific jar file (in local or remote),
use the [JAR URL](http://java.sun.com/j2se/1.5.0/docs/api/java/net/JarURLConnection.html):
```java
-Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:jar:http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc/src/test/resources/testdb.jar!/sample.db");
+try (Connection conn = DriverManager.getConnection("jdbc:sqlite::resource:jar:http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc/src/test/resources/testdb.jar!/sample.db")) { /*...*/ }
```
DB files will be extracted to a temporary folder specified in `System.getProperty("java.io.tmpdir")`.
@@ -102,7 +108,7 @@ SQLiteConfig config = new SQLiteConfig();
config.setSharedCache(true);
config.recursiveTriggers(true);
// ... other configuration can be set via SQLiteConfig object
-Connection conn = DriverManager.getConnection("jdbc:sqlite:sample.db", config.toProperties());
+try (Connection conn = DriverManager.getConnection("jdbc:sqlite:sample.db", config.toProperties())) { /*...*/ }
```
## How to Use Encrypted Databases
@@ -116,7 +122,7 @@ SQLite support encryption of the database via special drivers and a key. To use
Now the only need to specify the password is via:
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite:db.sqlite", "", "password");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite:db.sqlite", "", "password")) { /*...*/ }
```
### Binary Passphrase
@@ -130,7 +136,7 @@ The binary password is provided via `pragma key="x'AE...'"`
You set the mode at the connection string level:
```java
-Connection connection = DriverManager.getConnection("jdbc:sqlite:db.sqlite?hexkey_mode=sse", "", "AE...");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite:db.sqlite?hexkey_mode=sse", "", "AE...")) { /*...*/ }
```
## Explicit read only transactions (use with Hibernate)
@@ -160,7 +166,7 @@ config.setExplicitReadOnly(true);
```
- using the pragma `jdbc.explicit_readonly`:
```java
-DriverManager.getConnection("jdbc:sqlite::memory:?jdbc.explicit_readonly=true");
+try (Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:?jdbc.explicit_readonly=true")) { /*...*/ }
```
## How to use with Android
=====================================
VERSION
=====================================
@@ -1 +1 @@
-version=3.44.1
+version=3.45.2
=====================================
debian/changelog
=====================================
@@ -1,3 +1,12 @@
+xerial-sqlite-jdbc (3.45.2.0+dfsg-1) unstable; urgency=medium
+
+ * New upstream version 3.45.2.0+dfsg
+ * Refreshing patches
+ * Raising Standards version to 4.7.0 (no change)
+ * Refreshing the list of files to exclude when repacking
+
+ -- Pierre Gruet <pgt at debian.org> Wed, 10 Apr 2024 21:53:15 +0200
+
xerial-sqlite-jdbc (3.44.1.0+dfsg-1) unstable; urgency=medium
* New upstream version 3.44.1.0+dfsg
=====================================
debian/control
=====================================
@@ -16,7 +16,7 @@ Build-Depends: debhelper-compat (= 13),
libslf4j-java,
libsqlite3-dev,
maven-debian-helper
-Standards-Version: 4.6.2
+Standards-Version: 4.7.0
Vcs-Browser: https://salsa.debian.org/java-team/xerial-sqlite-jdbc
Vcs-Git: https://salsa.debian.org/java-team/xerial-sqlite-jdbc.git
Rules-Requires-Root: no
=====================================
debian/copyright
=====================================
@@ -1,12 +1,9 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: sqlite-jdbc
Source: https://github.com/xerial/sqlite-jdbc
-Files-Excluded: src/main/resources/org/sqlite/native/*/*/*.so
- src/main/resources/org/sqlite/native/*/*/*.jnilib
- src/main/resources/org/sqlite/native/Windows/*/*.dll
- **/*.jar
- archive/*.tgz
- archive/*.tar.gz
+Files-Excluded: src/main/resources/org
+ **/*.jar
+ archive
lib
.github
.gitignore
=====================================
debian/patches/allow_discrepancy_in_driver_version.patch
=====================================
@@ -7,7 +7,7 @@ Last-Update: 2022-01-07
--- a/src/test/java/org/sqlite/DBMetaDataTest.java
+++ b/src/test/java/org/sqlite/DBMetaDataTest.java
-@@ -1628,13 +1628,13 @@
+@@ -1627,13 +1627,13 @@
assertThat(majorVersion > 0).as("major version check").isTrue();
assertThat(meta.getDriverName()).as("driver name").isEqualTo("SQLite JDBC");
=====================================
debian/patches/build.patch
=====================================
@@ -9,7 +9,7 @@ Last-Update: 2022-08-15
--- a/Makefile
+++ b/Makefile
-@@ -53,9 +53,9 @@
+@@ -54,9 +54,9 @@
jni-header: $(TARGET)/common-lib/NativeDB.h
@@ -21,7 +21,7 @@ Last-Update: 2022-08-15
mv target/common-lib/org_sqlite_core_NativeDB.h target/common-lib/NativeDB.h
test:
-@@ -106,14 +106,18 @@
+@@ -107,14 +107,18 @@
$(SQLITE_SOURCE)/sqlite3.h: $(SQLITE_UNPACKED)
@@ -46,7 +46,7 @@ Last-Update: 2022-08-15
NATIVE_DIR=src/main/resources/org/sqlite/native/$(OS_NAME)/$(OS_ARCH)
NATIVE_TARGET_DIR:=$(TARGET)/classes/org/sqlite/native/$(OS_NAME)/$(OS_ARCH)
-@@ -125,10 +129,11 @@
+@@ -126,10 +130,11 @@
native: $(NATIVE_DLL)
$(NATIVE_DLL): $(SQLITE_OUT)/$(LIBNAME)
@@ -62,7 +62,7 @@ Last-Update: 2022-08-15
win32: $(SQLITE_UNPACKED) jni-header
./docker/dockcross-windows-x86 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86'
-@@ -212,9 +217,12 @@
+@@ -213,9 +218,12 @@
mac-arm64-signed: mac-arm64
$(CODESIGN) src/main/resources/org/sqlite/native/Mac/aarch64/libsqlitejdbc.dylib
=====================================
debian/patches/cleaning.patch
=====================================
@@ -5,7 +5,7 @@ Last-Update: 2022-01-07
--- a/Makefile
+++ b/Makefile
-@@ -61,7 +61,8 @@
+@@ -62,7 +62,8 @@
test:
mvn test
=====================================
debian/patches/junit-jupiter-params_artifact.patch
=====================================
@@ -6,7 +6,7 @@ Last-Update: 2023-02-04
--- a/pom.xml
+++ b/pom.xml
-@@ -434,6 +434,12 @@
+@@ -427,6 +427,12 @@
<scope>test</scope>
</dependency>
<dependency>
@@ -18,4 +18,4 @@ Last-Update: 2023-02-04
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.24.2</version>
+ <version>3.25.3</version>
=====================================
debian/patches/test.patch
=====================================
@@ -5,7 +5,7 @@ Last-Update: 2022-01-07
--- a/pom.xml
+++ b/pom.xml
-@@ -339,6 +339,9 @@
+@@ -332,6 +332,9 @@
<profile>
<id>native</id>
@@ -15,7 +15,7 @@ Last-Update: 2022-01-07
<build>
<plugins>
<plugin>
-@@ -375,6 +378,7 @@
+@@ -368,6 +371,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
=====================================
debian/patches/tests_without_archunit-junit5_and_some_assertions.patch
=====================================
@@ -27,7 +27,7 @@ Last-Update: 2022-11-16
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.data.Offset.offset;
-@@ -734,7 +734,7 @@
+@@ -739,7 +739,7 @@
assertThat(rs.isClosed()).isTrue();
assertThat(ps.isClosed()).isFalse();
@@ -99,7 +99,7 @@ Last-Update: 2022-11-16
import static org.assertj.core.data.Offset.offset;
import java.lang.reflect.Method;
-@@ -539,7 +539,7 @@
+@@ -618,7 +618,7 @@
rs.close();
}
@@ -108,7 +108,7 @@ Last-Update: 2022-11-16
public void setEscapeProcessingToFalse() {
assertThatNoException().isThrownBy(() -> stat.setEscapeProcessing(false));
}
-@@ -547,7 +547,7 @@
+@@ -626,7 +626,7 @@
@Test
public void setEscapeProcessingToTrue() {
assertThatNoException().isThrownBy(() -> stat.setEscapeProcessing(true));
=====================================
demo/Sample.java
=====================================
@@ -8,12 +8,15 @@
{
public static void main(String[] args)
{
- Connection connection = null;
+ // NOTE: Connection and Statement are AutoClosable.
+ // Don't forget to close them both in order to avoid leaks.
try
- {
+ (
// create a database connection
- connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
+ Connection connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
Statement statement = connection.createStatement();
+ )
+ {
statement.setQueryTimeout(30); // set timeout to 30 sec.
statement.executeUpdate("drop table if exists person");
@@ -32,20 +35,7 @@
{
// if the error message is "out of memory",
// it probably means no database file is found
- System.err.println(e.getMessage());
- }
- finally
- {
- try
- {
- if(connection != null)
- connection.close();
- }
- catch(SQLException e)
- {
- // connection close failed.
- System.err.println(e);
- }
+ e.printStackTrace(System.err);
}
}
}
=====================================
pom.xml
=====================================
@@ -4,16 +4,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
- <version>3.44.1.0</version>
+ <version>3.45.2.0</version>
<name>SQLite JDBC</name>
<description>SQLite JDBC library</description>
<url>https://github.com/xerial/sqlite-jdbc</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <junit.version>5.10.1</junit.version>
- <surefire.version>3.2.2</surefire.version>
- <graalvm.version>23.1.1</graalvm.version>
+ <junit.version>5.10.2</junit.version>
+ <surefire.version>3.2.5</surefire.version>
+ <graalvm.version>23.1.2</graalvm.version>
<java9.sourceDirectory>${project.basedir}/src/main/java9</java9.sourceDirectory>
</properties>
@@ -100,7 +100,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>
@@ -198,7 +198,7 @@
<plugin>
<groupId>org.jreleaser</groupId>
<artifactId>jreleaser-maven-plugin</artifactId>
- <version>1.9.0</version>
+ <version>1.11.0</version>
<configuration>
<configFile>jreleaser.yml</configFile>
</configuration>
@@ -284,14 +284,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
- <version>3.1.0</version>
- <configuration>
- <!-- Prevent gpg from using pinentry programs -->
- <gpgArguments>
- <arg>--pinentry-mode</arg>
- <arg>loopback</arg>
- </gpgArguments>
- </configuration>
+ <version>3.2.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
@@ -305,7 +298,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>
@@ -344,7 +337,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
- <version>0.9.28</version>
+ <version>0.10.1</version>
<extensions>true</extensions>
<executions>
<execution>
@@ -430,7 +423,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.24.2</version>
+ <version>3.25.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
@@ -452,20 +445,20 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>5.7.0</version>
+ <version>5.11.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>
=====================================
src/main/java/org/sqlite/core/CoreStatement.java
=====================================
@@ -17,6 +17,8 @@ package org.sqlite.core;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.regex.Pattern;
import org.sqlite.SQLiteConnection;
import org.sqlite.SQLiteConnectionConfig;
import org.sqlite.jdbc3.JDBC3Connection;
@@ -33,6 +35,16 @@ public abstract class CoreStatement implements Codes {
protected Object[] batch = null;
protected boolean resultsWaiting = false;
+ private Statement generatedKeysStat = null;
+ private ResultSet generatedKeysRs = null;
+
+ // pattern for matching insert statements of the general format starting with INSERT or REPLACE.
+ // CTEs used prior to the insert or replace keyword are also be permitted.
+ private static final Pattern INSERT_PATTERN =
+ Pattern.compile(
+ "^\\s*(?:with\\s+.+\\(.+?\\))*\\s*(?:insert|replace)\\s*",
+ Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+
protected CoreStatement(SQLiteConnection c) {
conn = c;
rs = new JDBC4ResultSet(this);
@@ -149,4 +161,48 @@ public abstract class CoreStatement implements Codes {
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 && INSERT_PATTERN.matcher(sql).find()) {
+ 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;
+ }
}
=====================================
src/main/java/org/sqlite/jdbc3/JDBC3DatabaseMetaData.java
=====================================
@@ -559,7 +559,7 @@ public abstract class JDBC3DatabaseMetaData extends CoreDatabaseMetaData {
/** @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys() */
public boolean supportsGetGeneratedKeys() {
- return false;
+ return true;
}
/** @see java.sql.DatabaseMetaData#supportsGroupBy() */
=====================================
src/main/java/org/sqlite/jdbc3/JDBC3PreparedStatement.java
=====================================
@@ -54,10 +54,13 @@ public abstract class JDBC3PreparedStatement extends CorePreparedStatement {
() -> {
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);
@@ -119,7 +122,15 @@ public abstract class JDBC3PreparedStatement extends CorePreparedStatement {
}
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() */
=====================================
src/main/java/org/sqlite/jdbc3/JDBC3Statement.java
=====================================
@@ -32,6 +32,7 @@ public abstract class JDBC3Statement extends CoreStatement {
/** @see java.sql.Statement#close() */
public void close() throws SQLException {
+ clearGeneratedKeys();
internalClose();
}
@@ -49,12 +50,14 @@ public abstract class JDBC3Statement extends CoreStatement {
}
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;
+ }
});
}
@@ -126,13 +129,16 @@ public abstract class JDBC3Statement extends CoreStatement {
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();
}
@@ -350,17 +356,6 @@ public abstract class JDBC3Statement extends CoreStatement {
}
}
- /**
- * 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().
*
=====================================
src/main/resources/org/sqlite/native/Mac/aarch64/libsqlitejdbc.dylib deleted
=====================================
Binary files a/src/main/resources/org/sqlite/native/Mac/aarch64/libsqlitejdbc.dylib and /dev/null differ
=====================================
src/main/resources/org/sqlite/native/Mac/x86_64/libsqlitejdbc.dylib deleted
=====================================
Binary files a/src/main/resources/org/sqlite/native/Mac/x86_64/libsqlitejdbc.dylib and /dev/null differ
=====================================
src/test/java/org/sqlite/DBMetaDataTest.java
=====================================
@@ -51,7 +51,6 @@ public class DBMetaDataTest {
public void getTables() throws SQLException {
ResultSet rs = meta.getTables(null, null, null, null);
assertThat(rs).isNotNull();
-
stat.close();
assertThat(rs.next()).isTrue();
=====================================
src/test/java/org/sqlite/PrepStmtTest.java
=====================================
@@ -67,8 +67,13 @@ public class PrepStmtTest {
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();
=====================================
src/test/java/org/sqlite/StatementTest.java
=====================================
@@ -305,10 +305,89 @@ public class StatementTest {
public void getGeneratedKeys() throws SQLException {
ResultSet rs;
stat.executeUpdate("create table t1 (c1 integer primary key, v);");
+
+ // test standard insert operation
stat.executeUpdate("insert into t1 (v) values ('red');");
+ rs = stat.getGeneratedKeys();
+ assertThat(rs.next()).isTrue();
+ assertThat(rs.getInt(1)).isEqualTo(1);
+ rs.close();
- assertThatExceptionOfType(SQLFeatureNotSupportedException.class)
- .isThrownBy(() -> stat.getGeneratedKeys());
+ stat.executeUpdate("insert into t1 (v) values ('blue');");
+ rs = stat.getGeneratedKeys();
+ assertThat(rs.next()).isTrue();
+ assertThat(rs.getInt(1)).isEqualTo(2);
+ rs.close();
+
+ // test INSERT ith special replace keyword. This will trigger a primary key conflict on the
+ // first
+ // inserted row ('red') and replace the record with a value of 'yellow' with the same
+ // primary
+ // key. The value returned from getGeneratedKeys should be primary key of the replaced
+ // record
+ stat.executeUpdate("replace into t1 (c1, v) values (1, 'yellow');");
+ rs = stat.getGeneratedKeys();
+ assertThat(rs.next()).isTrue();
+ assertThat(rs.getInt(1)).isEqualTo(1);
+ rs.close();
+
+ // test INSERT with common table expression
+ stat.executeUpdate(
+ " WITH colors as (select 'green' as color) \n"
+ + "INSERT into t1 (v) select color from colors;");
+ rs = stat.getGeneratedKeys();
+ assertThat(rs.next()).isTrue();
+ assertThat(rs.getInt(1)).isEqualTo(3);
+ rs.close();
+
+ stat.close();
+
+ // generated keys are now attached to the statement. calling getGeneratedKeys
+ // on a statement that has not generated any should return an empty result set
+ Statement stat2 = conn.createStatement();
+ stat.executeUpdate(
+ "with colors as (select 'insert' as color) update t1 set v = (select color from colors);");
+ rs = stat2.getGeneratedKeys();
+ assertThat(rs).isNotNull();
+ assertThat(rs.next()).isFalse();
+ stat2.close();
+ }
+
+ @Test
+ public void getGeneratedKeysIsStatementSpecific() throws SQLException {
+ /* this test ensures that the results of getGeneratedKeys are tied to
+ a specific statement. To verify this, we create two separate Statement
+ objects and then execute inserts on both. We then make getGeneratedKeys()
+ calls and verify that the two separate expected values are returned.
+
+ Note that the old implementation of getGeneratedKeys was called lazily, so
+ the result of both getGeneratedKeys calls would be the same value, the row ID
+ of the last insert on the connection. As a result it was unsafe to use
+ with multiple statements or in a multithreaded application.
+ */
+ stat.executeUpdate("create table t1 (c1 integer primary key, v);");
+
+ ResultSet rs1;
+ Statement stat1 = conn.createStatement();
+ ResultSet rs2;
+ Statement stat2 = conn.createStatement();
+
+ stat1.executeUpdate("insert into t1 (v) values ('red');");
+ stat2.executeUpdate("insert into t1 (v) values ('blue');");
+
+ rs2 = stat2.getGeneratedKeys();
+ rs1 = stat1.getGeneratedKeys();
+
+ assertThat(rs1.next()).isTrue();
+ assertThat(rs1.getInt(1)).isEqualTo(1);
+ rs1.close();
+
+ assertThat(rs2.next()).isTrue();
+ assertThat(rs2.getInt(1)).isEqualTo(2);
+ rs2.close();
+
+ stat1.close();
+ stat2.close();
}
@Test
View it on GitLab: https://salsa.debian.org/java-team/xerial-sqlite-jdbc/-/compare/29d5390b1a24088a1a6d3721f844def62f6abc13...fbc337bf10c32550a7b980b90809551f67eb13bf
--
View it on GitLab: https://salsa.debian.org/java-team/xerial-sqlite-jdbc/-/compare/29d5390b1a24088a1a6d3721f844def62f6abc13...fbc337bf10c32550a7b980b90809551f67eb13bf
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20240410/be6c925a/attachment.htm>
More information about the pkg-java-commits
mailing list