Skip to content

Commit 314efcb

Browse files
committed
Added some error message tests
1 parent 0f409b3 commit 314efcb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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/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)