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 1 commit
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: 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 @@ -28,7 +28,6 @@ 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
Expand All @@ -49,15 +48,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,10 +70,10 @@ 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 ((sqliteFlags and SQLITE_OPEN_READWRITE > 0) && sqlite3_db_readonly(db, null) != 0) {
sqlite3_close_v2(db)
throw sqliteException("Could not open the database in read/write mode")
}
}*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you keep this in but change the if to if (!configuration.isReadOnly && sqlite3_db_readonly(db, null) != 0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also I dont think this is possible anyway because it would fail here


// Set the default busy handler to retry automatically before returning SQLITE_BUSY.
val err = sqlite3_busy_timeout(db, configuration.busyTimeout)
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
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