Hi:
I am wanting to use the filter() method of
Query to match on the value of a column of type bytea in PosgreSQL. I get a
SlickException message telling me that
Array[Byte] does not have a literal representation
I see in driver/PostgresDriver.scala line 103 that ByteArrayTypeMapperDelegate is defined, extending a superclass' member class of the same name, and overriding value member sqlTypeName but not overriding the valueToSQLLiteral() method, which is what I think would be necessary for matching on a bytea-type column without getting the mentioned error.
So I made a first attempt to write such a method. Here is the diff of PostgresDriver.scala with the change:
a103 2
override def valueToSQLLiteral(value: Array[Byte]) =
"E'\\\\x" + value.map( b => (new scala.runtime.StringFormat(b)).formatted("%02X")).mkString + "'"
I put this modified PostgresDriver.scala file into my sbt project along with the rest of my sources, changed the package name to my project, and changed the
import scala.slick.driver.PostgresDriver.simple._
line to refer to my project package instead of scala.slick.driver.
Now I get this error here:
[error] /usr/home/mackler/myproject/src/main/scala/PostgresDriver.scala:107: type mismatch;
[error] found : String
[error] required: Nothing
[error] "E'\\\\x" + value.map( b => (new scala.runtime.StringFormat(b)).formatted("%02X")).mkString + "'"
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 6 s, completed Jan 11, 2013 5:54:19 AM
This is a little beyond me, but I get the impression that this definition of valueToSQLLiteral() from line 77 of driver/BasicTypeMapperDelegatesComponent.scala
override def valueToSQLLiteral(value: Array[Byte]) =
throw new SlickException("Array[Byte] does not have a literal representation")
is a problem because it throws an exception but doesn't return a String, even though it's overriding the definition on line 164 of lifted/TypeMapper.scala that has type String, and somehow it's changing the type of that method from String to Nothing.
So I've tried a few things, but none worked and it was getting messy. I tried copying the BasicTypeMapperDelegatesComponent.scala file into my project and changing the definition of valueToSQLLiteral() so it returns a String. I tried changing the definition of valueToSQLLiteral() in PostgresDriver.scala so it extends DriverTypeMapperDelegate[Array[Byte]].
My gut tells me there must be a simpler way to get this to work. Obviously the best thing would be if the distributed version of PostgresDriver.scala were changed to produce byte array literals. But unless and until that happens, can anyone give me a suggestion about how I can get the Query.filter() method to work with bytea-type columns in a PostgreSQL database?
Thanks very much,
--
Adam Mackler