Skip to content

Commit

Permalink
feat: EXPOSED-220 Support multiple statements returning a result in e…
Browse files Browse the repository at this point in the history
…xec()

Add test that uses multiple statements with multiple parameter args for
each statement.
  • Loading branch information
bog-walk committed Nov 24, 2023
1 parent 93549c0 commit 9ad6557
Showing 1 changed file with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class ParameterizationTests : DatabaseTestsBase() {
val name = varchar("foo", 50)
}

private val supportMultipleStatements by lazy {
setOf(TestDB.MYSQL, TestDB.MARIADB, TestDB.POSTGRESQL, TestDB.SQLSERVER)
}

@Test
fun testInsertWithQuotesAndGetItBack() {
withTables(TempTable) {
Expand All @@ -29,9 +33,8 @@ class ParameterizationTests : DatabaseTestsBase() {
}

@Test
fun testParametersWithMultipleStatements() {
val supported = setOf(TestDB.MYSQL, TestDB.MARIADB, TestDB.POSTGRESQL, TestDB.SQLSERVER)
Assume.assumeTrue(supported.containsAll(TestDB.enabledDialects()))
fun testSingleParametersWithMultipleStatements() {
Assume.assumeTrue(supportMultipleStatements.containsAll(TestDB.enabledDialects()))

val dialect = TestDB.enabledDialects().first()
val urlExtra = when (dialect) {
Expand Down Expand Up @@ -83,4 +86,64 @@ class ParameterizationTests : DatabaseTestsBase() {

TransactionManager.closeAndUnregister(db)
}

@Test
fun testMultipleParametersWithMultipleStatements() {
Assume.assumeTrue(supportMultipleStatements.containsAll(TestDB.enabledDialects()))

val tester = object : Table("tester") {
val name = varchar("foo", 50)
val age = integer("age")
val active = bool("active")
}

val dialect = TestDB.enabledDialects().first()
val urlExtra = when (dialect) {
TestDB.MYSQL -> "&allowMultiQueries=true"
TestDB.MARIADB -> "?&allowMultiQueries=true"
else -> ""
}
val db = Database.connect(
dialect.connection.invoke().plus(urlExtra),
dialect.driver,
dialect.user,
dialect.pass
)

transaction(db) {
try {
SchemaUtils.create(tester)

val table = tester.tableName.inProperCase()
val (name, age, active) = tester.columns.map { it.name.inProperCase() }

val result = exec(
"""
INSERT INTO $table ($active, $age, $name) VALUES (?, ?, ?);
INSERT INTO $table ($active, $age, $name) VALUES (?, ?, ?);
UPDATE $table SET $age=? WHERE ($table.$name LIKE ?) AND ($table.$active = ?);
SELECT COUNT(*) FROM $table WHERE ($table.$name LIKE ?) AND ($table.$age = ?);
""".trimIndent(),
args = listOf(
BooleanColumnType() to true, IntegerColumnType() to 1, VarCharColumnType() to "Anna",
BooleanColumnType() to false, IntegerColumnType() to 1, VarCharColumnType() to "Anya",
IntegerColumnType() to 2, VarCharColumnType() to "A%", BooleanColumnType() to true,
VarCharColumnType() to "A%", IntegerColumnType() to 2
),
explicitStatementType = StatementType.MULTI
) { resultSet ->
resultSet.next()
resultSet.getInt(1)
}
assertNotNull(result)
assertEquals(1, result)

assertEquals(2, tester.selectAll().count())
} finally {
SchemaUtils.drop(tester)
}
}

TransactionManager.closeAndUnregister(db)
}
}

0 comments on commit 9ad6557

Please sign in to comment.