[英]Could not determine data type in SQL Like operator with params
I'm trying to write a "select" with a parameter inside "like" operator.我正在尝试在“like”运算符中编写一个带有参数的“select”。 This is my code:
这是我的代码:
val result = connection.queryWithParamsAwait(
"select * from users where username like '%?%'",
jsonArrayOf(query)
)
But I'm getting this error:但我收到此错误:
could not determine data type of parameter $1
无法确定参数 $1 的数据类型
I suspect it is caused by the quotes, so I have also tried this:我怀疑它是由引号引起的,所以我也试过这个:
val result = conn.queryWithParamsAwait(
"select * from users where username like ?",
jsonArrayOf("\'%$query%\'")
)
It doesn't crash but returns no results, and it should.它不会崩溃但不返回任何结果,它应该。
I'm using this client: https://github.com/vert-x3/vertx-mysql-postgresql-client我正在使用这个客户端: https : //github.com/vert-x3/vertx-mysql-postgresql-client
连接通配符和参数:
like '%' || ? || '%'
You might find that regular expressions are more convenient:您可能会发现正则表达式更方便:
where username ~ ?
A regular expression matches anywhere in the string, so you don't need wildcards for the beginning and end.正则表达式匹配字符串中的任何位置,因此开头和结尾不需要通配符。
This is fine if ?
如果
?
only consists of digits and letters -- that is, if it doesn't have special regular expression characters.仅由数字和字母组成——也就是说,如果它没有特殊的正则表达式字符。 However, it might be a feature that you have the power of regular expressions.
但是,您可能拥有正则表达式的强大功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.