szeiger/scala-query — Issue #29: getOr does not work within computed columns
Author: umm
Created: 2012-01-01 17:36:38+00:00
State: open

Using getOr in a computed column returns 0 for a NULL value; the supplied default value and of the rest of the computation are ignored.

Short example:

```scala
import org.scalaquery.ql.extended.HsqldbDriver.Implicit._
import org.scalaquery.ql.extended.{ExtendedTable => Table}
import org.scalaquery.session.Database.threadLocalSession
import org.scalaquery.session._
import org.scalaquery.ql._
import org.scalaquery.ql.TypeMapper._

object Sqtest extends App {

val Persons = new Table[(Int, String, Option[Int])]("PERSONS") {
def id = column[Int]("ID", O.PrimaryKey)
def name = column[String]("NAME", O.NotNull)
def year = column[Option[Int]]("YEAR")

def * = id ~ name ~ year
}

Database.forURL("jdbc:hsqldb:mem:testdb").withSession {
Persons.ddl.create
Persons.insertAll(
(0, "Alice", Some(2000)),
(1, "Bob", None))

val q = for {
p <- Persons
} yield p.* ~ p.year.getOr(2000) ~ (p.year.getOr(2000)-0)

println(q.selectStatement)
q.foreach(println)
}

}
```

This yields
SELECT "t1"."ID","t1"."NAME","t1"."YEAR","t1"."YEAR",("t1"."YEAR" - 0) FROM "PERSONS" "t1"
(0,Alice,Some(2000),2000,2000)
(1,Bob,None,2000,0)

The last line should be "(1,Bob,None,2000,2000)".

Version used: 0.9.5, scala 2.9.1