8000 fix binding for spi.Parameter · jasync-sql/jasync-sql@12f0fcf · GitHub
[go: up one dir, main page]

Skip to content

Commit 12f0fcf

Browse files
committed
fix binding for spi.Parameter
Also throw unsupported on named binding. See #331
1 parent d4c6506 commit 12f0fcf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

r2dbc-mysql/src/main/java/JasyncStatement.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.github.jasync.sql.db.exceptions.InsufficientParametersException
55
import com.github.jasync.sql.db.mysql.MySQLQueryResult
66
import com.github.jasync.sql.db.mysql.exceptions.MySQLException
77
import com.github.jasync.sql.db.mysql.exceptions.MysqlErrors
8+
import io.r2dbc.spi.Parameter
89
import io.r2dbc.spi.R2dbcBadGrammarException
910
import io.r2dbc.spi.R2dbcDataIntegrityViolationException
1011
import io.r2dbc.spi.R2dbcPermissionDeniedException
@@ -55,7 +56,7 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
5556
}
5657

5758
override fun bind(identifier: String, value: Any): Statement {
58-
return bind(identifier.toInt(), value)
59+
throw UnsupportedOperationException("named binding is not supported by jasync driver $identifier=$value")
5960
}
6061

6162
override fun bind(index: Int, value: Any): Statement {
@@ -87,13 +88,12 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
8788
val allParams = bindings.all().asSequence().mapIndexed { i, binding ->
8889
(0 until binding.size).map {
8990
if (it in binding) {
90-
binding[it]
91+
mapBindingValue(binding[it])
9192
} else {
9293
throw IllegalStateException("binding failed with bind index $i and param index $it for query '$sql'")
9394
}
9495
}
9596
}.toFlux()
96-
9797
allParams.concatMap { connection.sendPreparedStatement(sql, it, releasePreparedStatementAfterUse).toMono() }
9898
} else {
9999
connection.sendQuery(sql).toMono()
@@ -112,6 +112,13 @@ internal class JasyncStatement(private val clientSupplier: Supplier<JasyncConnec
112112
}
113113
}
114114

115+
private fun mapBindingValue(bindValue: Any?): Any? {
116+
return when (bindValue) {
117+
is Parameter -> bindValue.value
118+
else -> bindValue
119+
5317 }
120+
}
121+
115122
private fun mapException(throwable: Throwable) = when (throwable) {
116123
is ConnectionTimeoutedException -> R2dbcTimeoutException(throwable)
117124
is IllegalArgumentException -> throwable

0 commit comments

Comments
 (0)
0