Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Closes #1180. Return types for DB columns that are primitives will co…

…me back as null rather than 0/false if the columns are null
  • Loading branch information...
commit d0baf2e1f0d6963ffa4b6f36c081e2badfe698e9 1 parent dff0b6a
@dpp dpp authored
Showing with 14 additions and 6 deletions.
  1. +14 −6 persistence/db/src/main/scala/net/liftweb/db/DB.scala
View
20 persistence/db/src/main/scala/net/liftweb/db/DB.scala
@@ -396,9 +396,9 @@ trait DB extends Loggable {
case x => x.toString
}
- case BIGINT | INTEGER | /* DECIMAL | NUMERIC | */ SMALLINT | TINYINT => rs.getLong(pos).toString
+ case BIGINT | INTEGER | /* DECIMAL | NUMERIC | */ SMALLINT | TINYINT => checkNull(rs, pos, rs.getLong(pos).toString)
- case BIT | BOOLEAN => rs.getBoolean(pos).toString
+ case BIT | BOOLEAN => checkNull(rs, pos, rs.getBoolean(pos).toString)
case VARCHAR | CHAR | CLOB | LONGVARCHAR => rs.getString(pos)
@@ -407,10 +407,18 @@ trait DB extends Loggable {
case x => x.toString
}
- case DOUBLE | FLOAT | REAL => rs.getDouble(pos).toString
+ case DOUBLE | FLOAT | REAL => checkNull(rs, pos, rs.getDouble(pos).toString)
}
}
+ /*
+ If the column is null, return null rather than the boxed primitive
+ */
+ def checkNull[T](rs: ResultSet, pos: Int, res: => T): T = {
+ if (null eq rs.getObject(pos)) null.asInstanceOf[T]
+ else res
+ }
+
private def asAny(pos: Int, rs: ResultSet, md: ResultSetMetaData): Any = {
import java.sql.Types._
md.getColumnType(pos) match {
@@ -418,15 +426,15 @@ trait DB extends Loggable {
case DECIMAL | NUMERIC => rs.getBigDecimal(pos)
- case BIGINT | INTEGER | /* DECIMAL | NUMERIC | */ SMALLINT | TINYINT => rs.getLong(pos)
+ case BIGINT | INTEGER | /* DECIMAL | NUMERIC | */ SMALLINT | TINYINT => checkNull(rs, pos, rs.getLong(pos))
- case BIT | BOOLEAN => rs.getBoolean(pos)
+ case BIT | BOOLEAN => checkNull(rs, pos, rs.getBoolean(pos))
case VARCHAR | CHAR | CLOB | LONGVARCHAR => rs.getString(pos)
case DATE | TIME | TIMESTAMP => rs.getTimestamp(pos)
- case DOUBLE | FLOAT | REAL => rs.getDouble(pos)
+ case DOUBLE | FLOAT | REAL => checkNull(rs, pos, rs.getDouble(pos))
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.