Permalink
Browse files

Merge pull request #16 from lift/dpp_issue_1180

Dpp issue 1180
  • Loading branch information...
2 parents 6482572 + 9ff78d3 commit 2adfb8bea1fb210bbaf1906da2430676deb8d9ab @dpp dpp committed Feb 11, 2012
Showing with 14 additions and 6 deletions.
  1. +14 −6 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,26 +407,34 @@ 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 {
case ARRAY | BINARY | BLOB | DATALINK | DISTINCT | JAVA_OBJECT | LONGVARBINARY | NULL | OTHER | REF | STRUCT | VARBINARY => rs.getObject(pos)
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))
}
}

0 comments on commit 2adfb8b

Please sign in to comment.