Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version to 1.2.1 #52

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

- Date format: YYYY-MM-dd

## v1.2.1 / 2023-10-18

### All

* Update `Kotlin`'s version to `1.9.10`

### sqllin-driver

* Fix the problem: [Native driver does not respect isReadOnly](https://github.com/ctripcorp/SQLlin/issues/50). ***On native platforms***.
Now, if a user set `isReadOnly = true` in `DatabaseConfigurtaion`, the database file must exist. And, if opening in read-write mode
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
a runtime exception. Thanks for [@nbransby](https://github.com/nbransby)

### sqllin-processor

* Update `KSP`'s version to `1.9.10-1.0.13`
* Now, if your data class with `@DBRow` can't be solved or imported successfully(Using `KSNode#validate` to judge), the
`ClauseProcessor` would try to resolve it in second round

## v1.2.0 / 2023-09-19

### sqllin-dsl
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION=1.2.0
VERSION=1.2.1
GROUP=com.ctrip.kotlin

kotlinVersion=1.9.0
kspVersion=1.9.0-1.0.13
kotlinVersion=1.9.10
kspVersion=1.9.10-1.0.13

#Maven Publish Information
githubURL=https://github.com/ctripcorp/SQLlin
Expand Down
Binary file modified sqllin-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions sqllin-driver/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Windows(mingwX86, mingwX64)。

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

从 `1.2.0` 开始, SQLlin 开始支持 JVM 目标平台,基于 [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc)。

## 基本用法

我不建议您在应用程序工程中直接使用 _sqllin-driver_ ,但是如果你想开发自己的 SQLite 高阶 API 库,你可以使用它。
Expand Down
2 changes: 1 addition & 1 deletion sqllin-driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
implementation("androidx.annotation:annotation:1.6.0")
implementation("androidx.annotation:annotation:1.7.0")
}
}
val androidInstrumentedTest by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,7 @@ import cnames.structs.sqlite3
import cnames.structs.sqlite3_stmt
import com.ctrip.sqllin.driver.DatabaseConfiguration
import com.ctrip.sqllin.driver.sqliteException
import com.ctrip.sqllin.sqlite3.SQLITE_DBCONFIG_LOOKASIDE
import com.ctrip.sqllin.sqlite3.SQLITE_OK
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_CREATE
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_READWRITE
import com.ctrip.sqllin.sqlite3.SQLITE_OPEN_URI
import com.ctrip.sqllin.sqlite3.sqlite3_busy_timeout
import com.ctrip.sqllin.sqlite3.sqlite3_close_v2
import com.ctrip.sqllin.sqlite3.sqlite3_db_config
import com.ctrip.sqllin.sqlite3.sqlite3_db_readonly
import com.ctrip.sqllin.sqlite3.sqlite3_errmsg
import com.ctrip.sqllin.sqlite3.sqlite3_exec
import com.ctrip.sqllin.sqlite3.sqlite3_open_v2
import com.ctrip.sqllin.sqlite3.sqlite3_prepare16_v2
import com.ctrip.sqllin.sqlite3.*
import kotlinx.cinterop.*

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

val db = memScoped {
val dbPtr = alloc<CPointerVar<sqlite3>>()
if(configuration.isReadOnly) {
//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
if (configuration.isReadOnly) {
// 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."
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, SQLITE_OPEN_READWRITE or SQLITE_OPEN_URI, null)
if (openResult == SQLITE_OK) return@memScoped dbPtr.value!!
if (openResult == SQLITE_OK)
return@memScoped dbPtr.value!!
}
val openResult = sqlite3_open_v2(realPath, dbPtr.ptr, sqliteFlags, null)
if (openResult != SQLITE_OK) {
if (openResult != SQLITE_OK)
throw sqliteException(sqlite3_errmsg(dbPtr.value)?.toKString() ?: "", openResult)
}
dbPtr.value!!
}

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

// Check that the database is really read/write when that is what we asked for.
if ((sqliteFlags and SQLITE_OPEN_READWRITE > 0) && sqlite3_db_readonly(db, null) != 0) {
if (!configuration.isReadOnly && sqlite3_db_readonly(db, null) != 0) {
sqlite3_close_v2(db)
throw sqliteException("Could not open the database in read/write mode")
}
Expand Down
2 changes: 1 addition & 1 deletion sqllin-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ kotlin {
}
val androidMain by getting {
dependencies {
implementation("androidx.annotation:annotation:1.6.0")
implementation("androidx.annotation:annotation:1.7.0")
}
}
val androidInstrumentedTest by getting {
Expand Down
2 changes: 1 addition & 1 deletion sqllin-dsl/doc/getting-start-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
id("com.google.devtools.ksp")
}

val sqllinVersion = "1.2.0"
val sqllinVersion = "1.2.1"

kotlin {
// ......
Expand Down
2 changes: 1 addition & 1 deletion sqllin-dsl/doc/getting-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
id("com.google.devtools.ksp")
}

val sqllinVersion = "1.2.0"
val sqllinVersion = "1.2.1"

kotlin {
// ......
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.symbol.*
import com.google.devtools.ksp.validate
import java.io.OutputStreamWriter

/**
Expand All @@ -37,17 +38,15 @@ class ClauseProcessor(
const val ANNOTATION_SERIALIZABLE = "kotlinx.serialization.Serializable"
}

private var invoked = false

@Suppress("UNCHECKED_CAST")
override fun process(resolver: Resolver): List<KSAnnotated> {
if (invoked) return emptyList()
invoked = true
val allDBRowClasses = resolver.getSymbolsWithAnnotation(ANNOTATION_DATABASE_ROW_NAME)
val invalidateDBRowClasses = allDBRowClasses.filter { !it.validate() }.toList()

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

for (classDeclaration in allClassAnnotatedWhereProperties) {
for (classDeclaration in validateDBRowClasses) {

if (classDeclaration.annotations.all { !it.annotationType.resolve().isAssignableFrom(serializableType) })
continue // Don't handle the class that don't annotated 'Serializable'
Expand Down Expand Up @@ -101,7 +100,7 @@ class ClauseProcessor(
writer.write("}")
}
}
return emptyList()
return invalidateDBRowClasses
}

private fun getClauseElementTypeStr(property: KSPropertyDeclaration): String? = when (
Expand Down
Loading