forked from JetBrains/Exposed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] escape parameter placeholder '?' by double question mark '??' J…
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 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
50 changes: 50 additions & 0 deletions
50
exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/StatementTest.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jetbrains.exposed.sql.tests.shared | ||
|
||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
import org.jetbrains.exposed.sql.ComplexExpression | ||
import org.jetbrains.exposed.sql.Expression | ||
import org.jetbrains.exposed.sql.Op | ||
import org.jetbrains.exposed.sql.QueryBuilder | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import kotlin.test.Test | ||
|
||
class StatementTest : DatabaseTestsBase() { | ||
@Test | ||
fun `query with double question`() { | ||
val table = object : IntIdTable("test_mod_on_pk") { | ||
val otherColumn = short("other") | ||
} | ||
|
||
open class SubQueryComplex<T>( | ||
private val operator: String, | ||
private val expr: Expression<T>, | ||
private val expr2: Expression<T>, | ||
) : Op<Boolean>(), ComplexExpression { | ||
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder { | ||
+expr | ||
+" " | ||
+operator | ||
+" (" | ||
+expr2 | ||
+")" | ||
} | ||
} | ||
|
||
withTables(table) { | ||
val actual = table | ||
.select(table.otherColumn) | ||
.where { | ||
SubQueryComplex( | ||
"??", | ||
table.id, | ||
table.id | ||
) | ||
} | ||
.prepareSQL(this, false) | ||
assertEquals( | ||
"SELECT TEST_MOD_ON_PK.OTHER FROM TEST_MOD_ON_PK WHERE TEST_MOD_ON_PK.ID ?? (TEST_MOD_ON_PK.ID)".lowercase(), | ||
actual.lowercase() | ||
) | ||
} | ||
} | ||
} |