Skip to content

Commit 3986ef2

Browse files
committed
Version 0.6.3
1 parent f693fd5 commit 3986ef2

File tree

10 files changed

+95
-14
lines changed

10 files changed

+95
-14
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ backend.native/tests/teamcity-test.property
5454
# Sample output
5555
samples/**/*.kt.bc-build
5656
samples/androidNativeActivity/Polyhedron
57+
58+
.vscode

SQLager/build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ buildscript {
33
jcenter()
44
google()
55
gradlePluginPortal()
6+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
67
}
78

89
dependencies {
@@ -14,6 +15,8 @@ apply plugin: 'org.jetbrains.kotlin.multiplatform'
1415

1516
repositories {
1617
mavenCentral()
18+
mavenLocal()
19+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
1720
maven {
1821
url 'https://oss.sonatype.org/content/repositories/snapshots/'
1922
}
@@ -64,7 +67,7 @@ kotlin {
6467
dependencies {
6568
implementation 'org.jetbrains.kotlin:kotlin-test-common'
6669
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
67-
implementation "co.touchlab:testhelp"
70+
implementation "co.touchlab:testhelp:$TESTHELP_VERSION"
6871
}
6972
}
7073
/*jvmMain {

SQLager/gradle.properties

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
kotlin.code.style=official
1818

1919
GROUP=co.touchlab
20-
VERSION_NAME=0.1.2-SNAPSHOT
20+
VERSION_NAME=0.2.0-eap-32
2121

22-
STATELY_VERSION=0.5.1
23-
TESTHELP_VERSION=0.1.0
24-
SQLITER_VERSION=0.5.9
25-
KOTLIN_VERSION=1.3.10
22+
STATELY_VERSION=0.7.3-eap-32
23+
TESTHELP_VERSION=0.2.3-eap-32
24+
SQLITER_VERSION=0.6.3-eap-32
25+
KOTLIN_VERSION=1.3.40-eap-32
2626

2727
POM_URL=https://github.com/touchlab/SQLiter
2828
POM_DESCRIPTION=Simple User-friendly Library
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

SQLiter/build.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ task mergeCppAll(dependsOn:build) {
160160
}
161161
}
162162

163-
164-
165163
apply from: "$rootDir/gradle/gradle-mvn-mpp-push.gradle"
166164

167165
tasks.findByName("publish").dependsOn("mergeCppAll")

SQLiter/gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
kotlin.code.style=official
1818

1919
GROUP=co.touchlab
20-
VERSION_NAME=0.6.2
20+
VERSION_NAME=0.6.3
2121

22-
STATELY_VERSION=0.7.2
23-
KOTLIN_VERSION=1.3.31
22+
STATELY_VERSION=0.7.3
23+
KOTLIN_VERSION=1.3.40
2424

2525
POM_URL=https://github.com/touchlab/SQLiter
2626
POM_DESCRIPTION=Simple SQLite Driver

SQLiter/src/commonMain/kotlin/co/touchlab/sqliter/DatabaseConfiguration.kt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ data class DatabaseConfiguration(
2323
val create: (DatabaseConnection) -> Unit,
2424
val upgrade: (DatabaseConnection, Int, Int) -> Unit = { _, _, _ -> },
2525
val journalMode: JournalMode = JournalMode.WAL,
26+
val foreignKeyConstraints: Boolean = false,
2627
val busyTimeout: Int = 2500,
2728
val pageSize: Int? = null,
2829
val inMemory: Boolean = false,

SQLiter/src/commonMain/kotlin/co/touchlab/sqliter/DatabaseConnection.kt

+5
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ fun DatabaseConnection.updateJournalMode(value: JournalMode):JournalMode{
7979
}else{
8080
value
8181
}
82+
}
83+
84+
fun DatabaseConnection.updateForeignKeyConstraints(enabled: Boolean){
85+
val newValue = if(enabled){1}else{0}
86+
withStatement("PRAGMA foreign_keys=$newValue") { execute() }
8287
}

SQLiter/src/nativeCommonMain/kotlin/co/touchlab/sqliter/NativeDatabaseManager.kt

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class NativeDatabaseManager(private val path:String,
5656
configuration.busyTimeout
5757
))
5858

59+
if(configuration.foreignKeyConstraints){
60+
conn.updateForeignKeyConstraints(true)
61+
}
62+
5963
if(connectionCount.value == 0){
6064
conn.updateJournalMode(configuration.journalMode)
6165

SQLiter/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConfigurationTest.kt

+70-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
8181
}))
8282

8383
val conn = manager.surpriseMeConnection()
84-
println("tr 0")
84+
8585
assertEquals(conn.journalMode, JournalMode.WAL)
86-
println("tr 1")
86+
8787
println("Update journal to DELETE result ${conn.updateJournalMode(JournalMode.DELETE)}")
8888
assertEquals(conn.journalMode, JournalMode.DELETE)
8989
println("Update journal to WAL result ${conn.updateJournalMode(JournalMode.WAL)}")
@@ -109,5 +109,73 @@ class DatabaseConfigurationTest : BaseDatabaseTest(){
109109
conn2.close()
110110
}
111111

112+
@Test
113+
fun foreignKeyConstraintsSetting(){
114+
runFkTest("fkoff", false)
115+
runFkTest("fkon", true)
116+
}
117+
118+
private fun runFkTest(dbname: String, enableFK: Boolean){
119+
var bookId = 1
120+
fun makeBookWithoutTransaction(conn: DatabaseConnection) =
121+
conn.withStatement("insert into book(id, name, author_id)values(${bookId++}, 'Hello Book', 5)") { executeInsert() }
122+
123+
fun makeBook(conn: DatabaseConnection) {
124+
conn.withTransaction { conn ->
125+
makeBookWithoutTransaction(conn)
126+
}
127+
}
128+
fun checkAB(conn:DatabaseConnection, expectBooks: Int, expectAuthors: Int){
129+
val books = conn.longForQuery("select count(*) from book").toInt()
130+
val authors = conn.longForQuery("select count(*) from author").toInt()
131+
132+
assertEquals(expectBooks, books)
133+
assertEquals(expectAuthors, authors)
134+
}
135+
136+
val manager = createDatabaseManager(DatabaseConfiguration(
137+
name = dbname,
138+
version = 1,
139+
journalMode = JournalMode.WAL,
140+
foreignKeyConstraints = enableFK,
141+
create = { db ->
142+
db.withStatement(AUTHOR) {
143+
execute()
144+
}
145+
db.withStatement(BOOK) {
146+
execute()
147+
}
148+
}))
149+
150+
val conn = manager.createMultiThreadedConnection()
151+
152+
try {
153+
checkAB(conn, 0, 0)
154+
155+
if(enableFK){
156+
assertFails { makeBook(conn) }
157+
assertFails { makeBookWithoutTransaction(conn) }
158+
checkAB(conn, 0, 0)
159+
}else{
160+
makeBook(conn)
161+
makeBookWithoutTransaction(conn)
162+
checkAB(conn, 2, 0)
163+
}
164+
} finally {
165+
conn.close()
166+
DatabaseFileContext.deleteDatabase(dbname)
167+
}
168+
}
112169

170+
private val AUTHOR = """CREATE TABLE author (
171+
id INTEGER NOT NULL PRIMARY KEY,
172+
name TEXT NOT NULL
173+
);"""
174+
175+
private val BOOK = """CREATE TABLE book (
176+
id INTEGER NOT NULL PRIMARY KEY,
177+
name TEXT NOT NULL,
178+
author_id INTEGER NOT NULL,
179+
FOREIGN KEY (author_id) REFERENCES author(id) ON DELETE CASCADE
180+
);"""
113181
}

0 commit comments

Comments
 (0)