Skip to content

Commit 4d0138d

Browse files
committed
Merge with xerial/master
2 parents 7a725e8 + 6e4c691 commit 4d0138d

24 files changed

+368
-71
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
# strategy:
8484
# matrix:
8585
# os: [ ubuntu-latest, windows-latest, macos-latest ]
86-
# java: [ '17', '21' ]
86+
# java: [ '17', '21', '22' ]
8787
# profiles: ['native', 'native,native-exported']
8888
# runs-on: ${{ matrix.os }}
8989
# steps:

README.adoc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
= SQLite JDBC Driver
2-
:project-version: 3.46.0.1
2+
:project-version: 3.47.0.0
33

44
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]
55
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/]
@@ -29,19 +29,18 @@ SQLite JDBC is a library for accessing SQLite databases through the JDBC API. Fo
2929

3030
. <<Download,Download>> `sqlite-jdbc-{project-version}.jar`
3131
then append this jar file into your classpath.
32-
. https://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar[Download] `slf4j-api-1.7.36.jar` then append this jar file into your classpath.
3332
. Open a SQLite database connection from your code. (see the example below)
3433

3534
=== Example usage
3635

37-
Assuming `sqlite-jdbc-{project-version}.jar` and `slf4j-api-1.7.36.jar` are placed in the current directory.
36+
Assuming `sqlite-jdbc-{project-version}.jar` is placed in the current directory.
3837

3938
[source,shell,subs="attributes+"]
4039
----
4140
> javac Sample.java
42-
> java -classpath ".;sqlite-jdbc-{project-version}.jar;slf4j-api-1.7.36.jar" Sample # in Windows
41+
> java -classpath ".;sqlite-jdbc-{project-version}.jar" Sample # in Windows
4342
or
44-
> java -classpath ".:sqlite-jdbc-{project-version}.jar:slf4j-api-1.7.36.jar" Sample # in macOS or Linux
43+
> java -classpath ".:sqlite-jdbc-{project-version}.jar" Sample # in macOS or Linux
4544
name = leo
4645
id = 1
4746
name = yui
@@ -116,7 +115,7 @@ the following operating systems:
116115
|macOS | |✔ | | | |✔ | |
117116
|Linux (libc) |✔ |✔ |✔ |✔ |✔ |✔ |✔ |✔
118117
|Linux (musl) |✔ |✔ | | | |✔ | |
119-
|Android |✔ |✔ |✔ | | |✔ | |
118+
|Android (API Level 24+) |✔ |✔ |✔ | | |✔ | |
120119
|FreeBSD |✔ |✔ | | | |✔ | |
121120
|===
122121

USAGE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,22 @@ Here is what you need to know.
233233
4. Change the key to `null` using`PRAGMA rekey=''`
234234
5. Use normally
235235

236+
## Generated keys
237+
238+
SQLite has limited support to retrieve generated keys, using [last_insert_rowid](https://www.sqlite.org/c3ref/last_insert_rowid.html), with the following limitations:
239+
- a single ID can be retrieved, even if multiple rows were added or updated
240+
- it needs to be called right after the statement
241+
242+
By default the driver will eagerly retrieve the generated keys after each statement, which may impact performances.
243+
244+
You can disable the retrieval of generated keys in 3 ways:
245+
- via `SQLiteDataSource#setGetGeneratedKeys(false)`
246+
- via `SQLiteConnectionConfig#setGetGeneratedKeys(false)`:
247+
- using the pragma `jdbc.get_generated_keys`:
248+
```java
249+
try (Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:?jdbc.get_generated_keys=false")) { /*...*/ }
250+
```
251+
236252
## Explicit read only transactions (use with Hibernate)
237253

238254
In order for the driver to be compliant with Hibernate, it needs to allow setting the read only flag after a connection has been created.

VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=3.46.1
2-
artifactVersion=3.46.1.1-SNAPSHOT
3-
sqliteMCVersion=1.8.7
1+
version=3.47.0
2+
artifactVersion=3.47.0.0-SNAPSHOT
3+
sqliteMCVersion=1.9.0

pom.xml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.willena</groupId>
66
<artifactId>sqlite-jdbc</artifactId>
7-
<version>3.46.1.1-SNAPSHOT</version>
7+
<version>3.47.0.0-SNAPSHOT</version>
88
<name>SQLite JDBC</name>
99
<description>SQLite JDBC library with encryption and authentication support</description>
1010
<url>https://github.com/Willena/sqlite-jdbc-crypt</url>
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<junit.version>5.10.3</junit.version>
15-
<surefire.version>3.3.1</surefire.version>
14+
<junit.version>5.11.3</junit.version>
15+
<surefire.version>3.5.2</surefire.version>
1616
<archunit.version>1.3.0</archunit.version>
17-
<graalvm.version>24.0.2</graalvm.version>
17+
<graalvm.version>24.1.1</graalvm.version>
1818
<java9.sourceDirectory>${project.basedir}/src/main/java9</java9.sourceDirectory>
1919
</properties>
2020

@@ -93,7 +93,7 @@
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>
9595
<artifactId>maven-help-plugin</artifactId>
96-
<version>3.4.1</version>
96+
<version>3.5.1</version>
9797
</plugin>
9898

9999
<plugin>
@@ -280,7 +280,7 @@
280280
<plugin>
281281
<groupId>org.apache.maven.plugins</groupId>
282282
<artifactId>maven-gpg-plugin</artifactId>
283-
<version>3.2.5</version>
283+
<version>3.2.7</version>
284284
<configuration>
285285
<!-- Prevent gpg from using pinentry programs -->
286286
<gpgArguments>
@@ -301,7 +301,7 @@
301301
<plugin>
302302
<groupId>org.apache.maven.plugins</groupId>
303303
<artifactId>maven-javadoc-plugin</artifactId>
304-
<version>3.8.0</version>
304+
<version>3.11.1</version>
305305
<configuration>
306306
<sourcepath>src/main/java</sourcepath>
307307
<additionalOptions>-Xdoclint:none</additionalOptions>
@@ -340,7 +340,7 @@
340340
<plugin>
341341
<groupId>org.graalvm.buildtools</groupId>
342342
<artifactId>native-maven-plugin</artifactId>
343-
<version>0.10.2</version>
343+
<version>0.10.3</version>
344344
<extensions>true</extensions>
345345
<executions>
346346
<execution>
@@ -354,6 +354,10 @@
354354
<configuration>
355355
<fallback>false</fallback>
356356
<verbose>true</verbose>
357+
<buildArgs>
358+
<!-- required to allow junit-pioneer to compile with strict image heap enabled -->
359+
<arg>--initialize-at-build-time=org.junitpioneer.jupiter.issue.IssueExtensionExecutionListener</arg>
360+
</buildArgs>
357361
</configuration>
358362
</plugin>
359363

@@ -413,6 +417,7 @@
413417
<groupId>org.slf4j</groupId>
414418
<artifactId>slf4j-api</artifactId>
415419
<version>1.7.36</version>
420+
<optional>true</optional>
416421
</dependency>
417422
<!--
418423
This dependency makes compilation on non-GraalVM versions possible.
@@ -450,13 +455,13 @@
450455
<dependency>
451456
<groupId>org.junit-pioneer</groupId>
452457
<artifactId>junit-pioneer</artifactId>
453-
<version>2.2.0</version>
458+
<version>2.3.0</version>
454459
<scope>test</scope>
455460
</dependency>
456461
<dependency>
457462
<groupId>org.mockito</groupId>
458463
<artifactId>mockito-core</artifactId>
459-
<version>5.12.0</version>
464+
<version>5.14.2</version>
460465
<scope>test</scope>
461466
</dependency>
462467
<dependency>

src/main/java/org/sqlite/JDBC.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
import java.sql.*;
2020
import java.util.Properties;
21-
import java.util.logging.Logger;
22-
import org.slf4j.LoggerFactory;
2321
import org.sqlite.jdbc4.JDBC4Connection;
22+
import org.sqlite.util.Logger;
23+
import org.sqlite.util.LoggerFactory;
2424

2525
public class JDBC implements Driver {
26-
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JDBC.class);
26+
private static final Logger logger = LoggerFactory.getLogger(JDBC.class);
2727
public static final String PREFIX = "jdbc:sqlite:";
2828

2929
static {
3030
try {
3131
DriverManager.registerDriver(new JDBC());
3232
} catch (SQLException e) {
33-
logger.error("Could not register driver", e);
33+
logger.error(() -> "Could not register driver", e);
3434
}
3535
}
3636

@@ -49,7 +49,7 @@ public boolean jdbcCompliant() {
4949
return false;
5050
}
5151

52-
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
52+
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
5353
// TODO
5454
return null;
5555
}

src/main/java/org/sqlite/SQLiteConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public void apply(Connection conn) throws SQLException {
189189

190190
// exclude this "fake" pragma from execution
191191
pragmaParams.remove(Pragma.JDBC_EXPLICIT_READONLY.pragmaName);
192+
pragmaParams.remove(Pragma.JDBC_GET_GENERATED_KEYS.pragmaName);
192193

193194
setupConnection(conn, pragmaParams, pragmaTable);
194195
try (Statement stat = conn.createStatement()) {
@@ -369,6 +370,9 @@ public Properties toProperties() {
369370
defaultConnectionConfig.getDateStringFormat());
370371
pragmaTable.setProperty(
371372
Pragma.JDBC_EXPLICIT_READONLY.pragmaName, this.explicitReadOnly ? "true" : "false");
373+
pragmaTable.setProperty(
374+
Pragma.JDBC_GET_GENERATED_KEYS.pragmaName,
375+
defaultConnectionConfig.isGetGeneratedKeys() ? "true" : "false");
372376
return pragmaTable;
373377
}
374378

@@ -581,6 +585,8 @@ public enum Pragma {
581585
// extensions: "fake" pragmas to allow conformance with JDBC
582586
JDBC_EXPLICIT_READONLY(
583587
"jdbc.explicit_readonly", "Set explicit read only transactions", null),
588+
JDBC_GET_GENERATED_KEYS(
589+
"jdbc.get_generated_keys", "Enable retrieval of generated keys", OnOff.Values),
584590

585591
// New pragmas for SQLiteMC improved support
586592
KEY("key", "Specify at least the encryption key", null),
@@ -1317,4 +1323,12 @@ public void setBusyTimeout(int milliseconds) {
13171323
public int getBusyTimeout() {
13181324
return parseLimitPragma(Pragma.BUSY_TIMEOUT, 3000);
13191325
}
1326+
1327+
public boolean isGetGeneratedKeys() {
1328+
return this.defaultConnectionConfig.isGetGeneratedKeys();
1329+
}
1330+
1331+
public void setGetGeneratedKeys(boolean generatedKeys) {
1332+
this.defaultConnectionConfig.setGetGeneratedKeys(generatedKeys);
1333+
}
13201334
}

src/main/java/org/sqlite/SQLiteConnectionConfig.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class SQLiteConnectionConfig implements Cloneable {
1919
private int transactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
2020
private SQLiteConfig.TransactionMode transactionMode = SQLiteConfig.TransactionMode.DEFERRED;
2121
private boolean autoCommit = true;
22+
private boolean getGeneratedKeys = true;
2223

2324
public static SQLiteConnectionConfig fromPragmaTable(Properties pragmaTable) {
2425
return new SQLiteConnectionConfig(
@@ -38,7 +39,10 @@ public static SQLiteConnectionConfig fromPragmaTable(Properties pragmaTable) {
3839
pragmaTable.getProperty(
3940
SQLiteConfig.Pragma.TRANSACTION_MODE.pragmaName,
4041
SQLiteConfig.TransactionMode.DEFERRED.name())),
41-
true);
42+
true,
43+
Boolean.parseBoolean(
44+
pragmaTable.getProperty(
45+
SQLiteConfig.Pragma.JDBC_GET_GENERATED_KEYS.pragmaName, "true")));
4246
}
4347

4448
public SQLiteConnectionConfig(
@@ -47,13 +51,15 @@ public SQLiteConnectionConfig(
4751
String dateStringFormat,
4852
int transactionIsolation,
4953
SQLiteConfig.TransactionMode transactionMode,
50-
boolean autoCommit) {
54+
boolean autoCommit,
55+
boolean getGeneratedKeys) {
5156
setDateClass(dateClass);
5257
setDatePrecision(datePrecision);
5358
setDateStringFormat(dateStringFormat);
5459
setTransactionIsolation(transactionIsolation);
5560
setTransactionMode(transactionMode);
5661
setAutoCommit(autoCommit);
62+
setGetGeneratedKeys(getGeneratedKeys);
5763
}
5864

5965
public SQLiteConnectionConfig copyConfig() {
@@ -63,7 +69,8 @@ public SQLiteConnectionConfig copyConfig() {
6369
dateStringFormat,
6470
transactionIsolation,
6571
transactionMode,
66-
autoCommit);
72+
autoCommit,
73+
getGeneratedKeys);
6774
}
6875

6976
public long getDateMultiplier() {
@@ -124,8 +131,16 @@ public void setTransactionMode(SQLiteConfig.TransactionMode transactionMode) {
124131
this.transactionMode = transactionMode;
125132
}
126133

134+
public boolean isGetGeneratedKeys() {
135+
return getGeneratedKeys;
136+
}
137+
138+
public void setGetGeneratedKeys(boolean getGeneratedKeys) {
139+
this.getGeneratedKeys = getGeneratedKeys;
140+
}
141+
127142
private static final Map<SQLiteConfig.TransactionMode, String> beginCommandMap =
128-
new EnumMap<SQLiteConfig.TransactionMode, String>(SQLiteConfig.TransactionMode.class);
143+
new EnumMap<>(SQLiteConfig.TransactionMode.class);
129144

130145
static {
131146
beginCommandMap.put(SQLiteConfig.TransactionMode.DEFERRED, "begin;");

src/main/java/org/sqlite/SQLiteDataSource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,15 @@ public void setTransactionMode(String transactionMode) {
449449
config.setTransactionMode(transactionMode);
450450
}
451451

452+
/**
453+
* Configure where generated keys will be retrieved for this database.
454+
*
455+
* @param generatedKeys true to retrieve generated keys
456+
*/
457+
public void setGetGeneratedKeys(boolean generatedKeys) {
458+
config.setGetGeneratedKeys(generatedKeys);
459+
}
460+
452461
/**
453462
* Sets the value of the user-version. It is a big-endian 32-bit signed integer stored in the
454463
* database header at offset 60.

0 commit comments

Comments
 (0)