Skip to content

Commit 776e1f9

Browse files
authored
Merge pull request #52 from qiaoyuang/main
Update version to 1.2.1
2 parents 1d12b5c + 9ac2db2 commit 776e1f9

File tree

10 files changed

+41
-33
lines changed

10 files changed

+41
-33
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
- Date format: YYYY-MM-dd
44

5+
## v1.2.1 / 2023-10-18
6+
7+
### All
8+
9+
* Update `Kotlin`'s version to `1.9.10`
10+
11+
### sqllin-driver
12+
13+
* Fix the problem: [Native driver does not respect isReadOnly](https://github.com/ctripcorp/SQLlin/issues/50). ***On native platforms***.
14+
Now, if a user set `isReadOnly = true` in `DatabaseConfigurtaion`, the database file must exist. And, if opening in read-write mode
15+
fails due to OS-level permissions, the user will get a read-only database, and if the user try to modify the database, will receive
16+
a runtime exception. Thanks for [@nbransby](https://github.com/nbransby)
17+
18+
### sqllin-processor
19+
20+
* Update `KSP`'s version to `1.9.10-1.0.13`
21+
* Now, if your data class with `@DBRow` can't be solved or imported successfully(Using `KSNode#validate` to judge), the
22+
`ClauseProcessor` would try to resolve it in second round
23+
524
## v1.2.0 / 2023-09-19
625

726
### sqllin-dsl

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
VERSION=1.2.0
1+
VERSION=1.2.1
22
GROUP=com.ctrip.kotlin
33

4-
kotlinVersion=1.9.0
5-
kspVersion=1.9.0-1.0.13
4+
kotlinVersion=1.9.10
5+
kspVersion=1.9.10-1.0.13
66

77
#Maven Publish Information
88
githubURL=https://github.com/ctripcorp/SQLlin

sqllin-architecture.png

1.41 MB
Loading

sqllin-driver/README_CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Windows(mingwX86, mingwX64)。
2626

2727
无论如何,[SQLiter](https://github.com/touchlab/SQLiter) 仍然是一个非常棒的项目。我参考了许多它的设计与实现细节并将它们用在了 _sqllin-driver_*新 Native 驱动*中。
2828

29+
`1.2.0` 开始, SQLlin 开始支持 JVM 目标平台,基于 [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc)
30+
2931
## 基本用法
3032

3133
我不建议您在应用程序工程中直接使用 _sqllin-driver_ ,但是如果你想开发自己的 SQLite 高阶 API 库,你可以使用它。

sqllin-driver/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ kotlin {
6868
}
6969
val androidMain by getting {
7070
dependencies {
71-
implementation("androidx.annotation:annotation:1.6.0")
71+
implementation("androidx.annotation:annotation:1.7.0")
7272
}
7373
}
7474
val androidInstrumentedTest by getting {

sqllin-driver/src/nativeMain/kotlin/com/ctrip/sqllin/driver/cinterop/NativeDatabase.kt

+7-19
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,7 @@ import cnames.structs.sqlite3
2020
import cnames.structs.sqlite3_stmt
2121
import com.ctrip.sqllin.driver.DatabaseConfiguration
2222
import com.ctrip.sqllin.driver.sqliteException
23-
import com.ctrip.sqllin.sqlite3.SQLITE_DBCONFIG_LOOKASIDE
24-
import com.ctrip.sqllin.sqlite3.SQLITE_OK
25-
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_CREATE
26-
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_READWRITE
27-
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_URI
28-
import com.ctrip.sqllin.sqlite3.sqlite3_busy_timeout
29-
import com.ctrip.sqllin.sqlite3.sqlite3_close_v2
30-
import com.ctrip.sqllin.sqlite3.sqlite3_db_config
31-
import com.ctrip.sqllin.sqlite3.sqlite3_db_readonly
32-
import com.ctrip.sqllin.sqlite3.sqlite3_errmsg
33-
import com.ctrip.sqllin.sqlite3.sqlite3_exec
34-
import com.ctrip.sqllin.sqlite3.sqlite3_open_v2
35-
import com.ctrip.sqllin.sqlite3.sqlite3_prepare16_v2
23+
import com.ctrip.sqllin.sqlite3.*
3624
import kotlinx.cinterop.*
3725

3826
/**
@@ -49,15 +37,15 @@ internal class NativeDatabase private constructor(val dbPointer: CPointer<sqlite
4937

5038
val db = memScoped {
5139
val dbPtr = alloc<CPointerVar<sqlite3>>()
52-
if(configuration.isReadOnly) {
53-
//from sqlite3_open_v2 docs: if opening in read-write mode fails due to OS-level permissions, an attempt is made to open it in read-only mode
40+
if (configuration.isReadOnly) {
41+
// From sqlite3_open_v2 docs: "if opening in read-write mode fails due to OS-level permissions, an attempt is made to open it in read-only mode."
5442
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, SQLITE_OPEN_READWRITE or SQLITE_OPEN_URI, null)
55-
if (openResult == SQLITE_OK) return@memScoped dbPtr.value!!
43+
if (openResult == SQLITE_OK)
44+
return@memScoped dbPtr.value!!
5645
}
5746
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, sqliteFlags, null)
58-
if (openResult != SQLITE_OK) {
47+
if (openResult != SQLITE_OK)
5948
throw sqliteException(sqlite3_errmsg(dbPtr.value)?.toKString() ?: "", openResult)
60-
}
6149
dbPtr.value!!
6250
}
6351

@@ -71,7 +59,7 @@ internal class NativeDatabase private constructor(val dbPointer: CPointer<sqlite
7159
}
7260

7361
// Check that the database is really read/write when that is what we asked for.
74-
if ((sqliteFlags and SQLITE_OPEN_READWRITE > 0) && sqlite3_db_readonly(db, null) != 0) {
62+
if (!configuration.isReadOnly && sqlite3_db_readonly(db, null) != 0) {
7563
sqlite3_close_v2(db)
7664
throw sqliteException("Could not open the database in read/write mode")
7765
}

sqllin-dsl/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ kotlin {
7474
}
7575
val androidMain by getting {
7676
dependencies {
77-
implementation("androidx.annotation:annotation:1.6.0")
77+
implementation("androidx.annotation:annotation:1.7.0")
7878
}
7979
}
8080
val androidInstrumentedTest by getting {

sqllin-dsl/doc/getting-start-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414
id("com.google.devtools.ksp")
1515
}
1616

17-
val sqllinVersion = "1.2.0"
17+
val sqllinVersion = "1.2.1"
1818

1919
kotlin {
2020
// ......

sqllin-dsl/doc/getting-start.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
id("com.google.devtools.ksp")
1717
}
1818

19-
val sqllinVersion = "1.2.0"
19+
val sqllinVersion = "1.2.1"
2020

2121
kotlin {
2222
// ......

sqllin-processor/src/main/kotlin/com/ctrip/sqllin/processor/ClauseProcessor.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.google.devtools.ksp.processing.Resolver
2121
import com.google.devtools.ksp.processing.SymbolProcessor
2222
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
2323
import com.google.devtools.ksp.symbol.*
24+
import com.google.devtools.ksp.validate
2425
import java.io.OutputStreamWriter
2526

2627
/**
@@ -37,17 +38,15 @@ class ClauseProcessor(
3738
const val ANNOTATION_SERIALIZABLE = "kotlinx.serialization.Serializable"
3839
}
3940

40-
private var invoked = false
41-
4241
@Suppress("UNCHECKED_CAST")
4342
override fun process(resolver: Resolver): List<KSAnnotated> {
44-
if (invoked) return emptyList()
45-
invoked = true
43+
val allDBRowClasses = resolver.getSymbolsWithAnnotation(ANNOTATION_DATABASE_ROW_NAME)
44+
val invalidateDBRowClasses = allDBRowClasses.filter { !it.validate() }.toList()
4645

47-
val allClassAnnotatedWhereProperties = resolver.getSymbolsWithAnnotation(ANNOTATION_DATABASE_ROW_NAME) as Sequence<KSClassDeclaration>
46+
val validateDBRowClasses = allDBRowClasses.filter { it.validate() } as Sequence<KSClassDeclaration>
4847
val serializableType = resolver.getClassDeclarationByName(resolver.getKSNameFromString(ANNOTATION_SERIALIZABLE))!!.asStarProjectedType()
4948

50-
for (classDeclaration in allClassAnnotatedWhereProperties) {
49+
for (classDeclaration in validateDBRowClasses) {
5150

5251
if (classDeclaration.annotations.all { !it.annotationType.resolve().isAssignableFrom(serializableType) })
5352
continue // Don't handle the class that don't annotated 'Serializable'
@@ -101,7 +100,7 @@ class ClauseProcessor(
101100
writer.write("}")
102101
}
103102
}
104-
return emptyList()
103+
return invalidateDBRowClasses
105104
}
106105

107106
private fun getClauseElementTypeStr(property: KSPropertyDeclaration): String? = when (

0 commit comments

Comments
 (0)