You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To do that, I would expect something like this to work:
val columns: Seq[SQLSyntax] = Seq("a", "b").map(SQLSyntax.createUnsafely(_, Nil))
val values: Seq[SQLSyntax] = Seq(Seq(1, 2), Seq(3, 4), Seq(5, 6)).map { xs => sqls"($xs)" }
sqls"$columns IN ($values)"
However, the implementation in SQLInterpolationString treats all Traversables the same, without looking at whether the arguments are SQLSyntax, so that will actually render to the following SQL:
(?, ?) IN (?, ?, ?)
I believe this can be fixed like this:
private def addPlaceholders(sb: StringBuilder, param: Any): StringBuilder = param match {
case _: String => sb += '?'
case t: Traversable[_] => t.map(addPlaceholders(new StringBuilder, _)).addString(sb, ", ")
case LastParameter => sb
case SQLSyntax(s, _) => sb ++= s
case _ => sb += '?'
}
private def buildParams(params: Traversable[Any]): Seq[Any] = params.foldLeft(Seq.newBuilder[Any]) {
case (b, s: String) => b += s
case (b, t: Traversable[_]) => b ++= buildParams(t)
case (b, SQLSyntax(_, params)) => b ++= params
case (b, n) => b += n
}.result()
I tested these definitions and it worked for the few examples I tried.
The text was updated successfully, but these errors were encountered:
Sometimes I want to render SQL like this:
To do that, I would expect something like this to work:
However, the implementation in SQLInterpolationString treats all Traversables the same, without looking at whether the arguments are SQLSyntax, so that will actually render to the following SQL:
I believe this can be fixed like this:
I tested these definitions and it worked for the few examples I tried.
The text was updated successfully, but these errors were encountered: