From 314efcba0528222956974bc065a191524a6b1efd Mon Sep 17 00:00:00 2001 From: Kevin Galligan Date: Mon, 29 Aug 2022 19:45:58 -0400 Subject: [PATCH] Added some error message tests --- .../sqliter/DatabaseConnectionTest.kt | 14 +++++++++++++ .../touchlab/sqliter/NativeStatementTest.kt | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt b/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt index 952f18f2..c25580d4 100644 --- a/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt +++ b/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/DatabaseConnectionTest.kt @@ -361,6 +361,20 @@ class DatabaseConnectionTest { } } + @Test + fun rawSqlFails() { + basicTestDb(TWO_COL) { databaseManager -> + databaseManager.withConnection { + try { + it.rawExecSql("INSERT INTO notthere(num, str)values(3,'abc')") + fail("Should have thrown") + } catch (e: Exception) { + assertTrue(e.message?.contains("no such table: notthere") ?: false) + } + } + } + } + private fun checkDbIsFile(memoryName: String?, mem:Boolean): Boolean { var dbFileExists = false val checkName = memoryName ?: ":memory:" diff --git a/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeStatementTest.kt b/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeStatementTest.kt index 776a2172..011f4a30 100644 --- a/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeStatementTest.kt +++ b/sqliter-driver/src/nativeCommonTest/kotlin/co/touchlab/sqliter/NativeStatementTest.kt @@ -262,5 +262,25 @@ class NativeStatementTest : BaseDatabaseTest(){ } } } + + @Test + fun failBindExtendedMessage() { + basicTestDb(TWO_COL) { + val errorMessage = try { + it.withConnection { + it.withStatement("insert into test(num, str)values(?,?)") { + bindLong(1, 21) + bindString(3, "asdf") + executeInsert() + } + } + "" + } catch (e: Exception) { + e.message ?: "" + } + + assertTrue(errorMessage.contains("column index out of range")) + } + } }