-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EXPOSED-220 Support multiple statements returning a result in e…
…xec() Fix KDocs Add test that confirms multiple statement exec works with parameterization args.
- Loading branch information
Showing
5 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 70 additions & 7 deletions
77
...sed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ParameterizationTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,86 @@ | ||
package org.jetbrains.exposed.sql.tests.shared | ||
|
||
import org.jetbrains.exposed.sql.* | ||
import org.jetbrains.exposed.sql.statements.StatementType | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import org.jetbrains.exposed.sql.tests.TestDB | ||
import org.jetbrains.exposed.sql.tests.inProperCase | ||
import org.jetbrains.exposed.sql.transactions.TransactionManager | ||
import org.jetbrains.exposed.sql.transactions.transaction | ||
import org.junit.Assume | ||
import org.junit.Test | ||
import kotlin.test.assertNotNull | ||
|
||
class ParameterizationTests : DatabaseTestsBase() { | ||
object TempTable : Table("tmp") { | ||
val name = varchar("foo", 50) | ||
} | ||
|
||
@Test | ||
fun testInsertWithQuotesAndGetItBack() { | ||
val table = object : Table("tmp") { | ||
val name = varchar("foo", 50) | ||
} | ||
|
||
withTables(table) { | ||
withTables(TempTable) { | ||
exec( | ||
"INSERT INTO ${table.tableName} (foo) VALUES (?)", | ||
"INSERT INTO ${TempTable.tableName} (foo) VALUES (?)", | ||
listOf(VarCharColumnType() to "John \"Johny\" Johnson") | ||
) | ||
|
||
assertEquals("John \"Johny\" Johnson", table.selectAll().single()[table.name]) | ||
assertEquals("John \"Johny\" Johnson", TempTable.selectAll().single()[TempTable.name]) | ||
} | ||
} | ||
|
||
@Test | ||
fun testParametersWithMultipleStatements() { | ||
val supported = setOf(TestDB.MYSQL, TestDB.MARIADB, TestDB.POSTGRESQL, TestDB.SQLSERVER) | ||
Assume.assumeTrue(supported.containsAll(TestDB.enabledDialects())) | ||
|
||
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(TempTable) | ||
|
||
val table = TempTable.tableName.inProperCase() | ||
val column = TempTable.name.name.inProperCase() | ||
|
||
val result = exec( | ||
""" | ||
INSERT INTO $table ($column) VALUES (?); | ||
INSERT INTO $table ($column) VALUES (?); | ||
INSERT INTO $table ($column) VALUES (?); | ||
DELETE FROM $table WHERE $table.$column LIKE ?; | ||
SELECT COUNT(*) FROM $table; | ||
""".trimIndent(), | ||
args = listOf( | ||
VarCharColumnType() to "Anne", | ||
VarCharColumnType() to "Anya", | ||
VarCharColumnType() to "Anna", | ||
VarCharColumnType() to "Ann%", | ||
), | ||
explicitStatementType = StatementType.MULTI | ||
) { resultSet -> | ||
resultSet.next() | ||
resultSet.getInt(1) | ||
} | ||
assertNotNull(result) | ||
assertEquals(1, result) | ||
|
||
assertEquals("Anya", TempTable.selectAll().single()[TempTable.name]) | ||
} finally { | ||
SchemaUtils.drop(TempTable) | ||
} | ||
} | ||
|
||
TransactionManager.closeAndUnregister(db) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters