Skip to content

Commit 2f03f73

Browse files
authored
Merge branch 'main' into psh/address-warnings
2 parents eaa6192 + 4af76e2 commit 2f03f73

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
kotlin.code.style=official
22

33
GROUP=co.touchlab
4+
45
VERSION_NAME=1.2.0
56
KOTLIN_VERSION=1.7.20-Beta
67

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/ActualSqliteStatement.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ internal class ActualSqliteStatement(private val db: SqliteDatabase, private val
129129
private inline fun opResult(db: SqliteDatabase, block: () -> Int) {
130130
val err = block()
131131
if (err != SQLITE_OK) {
132-
throw sqlException(db.logger, db.config, "Sqlite operation failure", err)
132+
val error = sqlite3_errmsg(db.dbPointer)?.toKString()
133+
throw sqlException(db.logger, db.config, "Sqlite operation failure ${error?:""}", err)
133134
}
134135
}
135136

sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/interop/SqliteDatabase.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ internal class SqliteDatabase(path: String, label: String, val logger: Logger, p
4040
fun rawExecSql(sqlString: String){
4141
val err = sqlite3_exec(dbPointer, sqlString, null, null, null)
4242
if (err != SQLITE_OK) {
43-
throw sqlException(logger, config, "error rawExecSql: $sqlString", err)
43+
val error = sqlite3_errmsg(dbPointer)?.toKString()
44+
throw sqlException(logger, config, "error rawExecSql: $sqlString, ${error?:""}", err)
4445
}
4546
}
4647

@@ -97,8 +98,9 @@ internal fun dbOpen(
9798
if (lookasideSlotSize >= 0 && lookasideSlotCount >= 0) {
9899
val err = sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE, null, lookasideSlotSize, lookasideSlotCount);
99100
if (err != SQLITE_OK) {
101+
val error = sqlite3_errmsg(db)?.toKString()
100102
sqlite3_close(db)
101-
throw sqlException(logging, SqliteDatabaseConfig(path, label), "Cannot set lookaside : sqlite3_db_config(..., ${lookasideSlotSize}, %${lookasideSlotCount}) failed", err)
103+
throw sqlException(logging, SqliteDatabaseConfig(path, label), "Cannot set lookaside : sqlite3_db_config(..., ${lookasideSlotSize}, %${lookasideSlotCount}) failed, ${error?:""}", err)
102104
}
103105
}
104106

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,20 @@ class DatabaseConnectionTest {
361361
}
362362
}
363363

364+
@Test
365+
fun rawSqlFails() {
366+
basicTestDb(TWO_COL) { databaseManager ->
367+
databaseManager.withConnection {
368+
try {
369+
it.rawExecSql("INSERT INTO notthere(num, str)values(3,'abc')")
370+
fail("Should have thrown")
371+
} catch (e: Exception) {
372+
assertTrue(e.message?.contains("no such table: notthere") ?: false)
373+
}
374+
}
375+
}
376+
}
377+
364378
private fun checkDbIsFile(memoryName: String?, mem:Boolean): Boolean {
365379
var dbFileExists = false
366380
val checkName = memoryName ?: ":memory:"

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeDatabaseConnectionTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import kotlin.test.*
2424

2525
class NativeDatabaseConnectionTest : BaseDatabaseTest(){
2626

27-
@Test
27+
// @Test
2828
fun multithreadedActivityWAL() {
2929
multithreadedActivity(JournalMode.WAL)
3030
}

sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeStatementTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,25 @@ class NativeStatementTest : BaseDatabaseTest(){
262262
}
263263
}
264264
}
265+
266+
@Test
267+
fun failBindExtendedMessage() {
268+
basicTestDb(TWO_COL) {
269+
val errorMessage = try {
270+
it.withConnection {
271+
it.withStatement("insert into test(num, str)values(?,?)") {
272+
bindLong(1, 21)
273+
bindString(3, "asdf")
274+
executeInsert()
275+
}
276+
}
277+
""
278+
} catch (e: Exception) {
279+
e.message ?: ""
280+
}
281+
282+
assertTrue(errorMessage.contains("column index out of range"))
283+
}
284+
}
265285
}
266286

0 commit comments

Comments
 (0)