Skip to content

Commit

Permalink
Added some error message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan committed Aug 29, 2022
1 parent 0f409b3 commit 314efcb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}

0 comments on commit 314efcb

Please sign in to comment.