On Wed, Jul 22, 2009 at 6:07 AM, Jeppe Nejsum Madsen <[email protected]>wrote:

>
> Hi,
>
> I'm using adhoc queries and I'm running into a problem where the results
> of aggregate functions get mapped to integers:
>
> I have this
>
>  val (_,result) = DB.runQuery("SELECT AVG(vt.fuel_efficiency),
> vt.fuel_type, vt.category FROM "+
>                    "vehicles v JOIN vehicle_types vt ON v.vehicle_type_id=
> vt.id "+
>                    "WHERE v.account_id=? "+
>                    "GROUP BY vt.fuel_type, vt.category "+
>                    "ORDER BY vt.fuel_type, vt.category",
>                    List(User.currentUser.open_!.account.is))
>
> in Postgres, the first column is returned as NUMERIC, ie with decimals, but
> in
>
> private def asString(pos: Int, rs: ResultSet, md: ResultSetMetaData)
>
> we have this:
>
> case BIGINT | INTEGER | DECIMAL | NUMERIC | SMALLINT | TINYINT =>
> rs.getLong(pos).toString
>
> which seems wrong.


So... numeric should be rs.getDouble(pos).toString ?

The rs.getString(pos) does not work correctly for all types in all JDBC
drivers.


>
>
> In fact, I think the entire function asString can be writting more
> correctly as:
>
>  private def asString(pos: Int, rs: ResultSet, md: ResultSetMetaData) =
> rs.getString(pos)
>
> i _think_ getString does "the right thing" in all cases, at least for
> Postgres :-)
>
> An even better approach would be to return a (list of) list of objects
> from resultSetTo, ie.  strings, Int, Double, BigDecimal etc, but I guess
> this would break existing code.
>
> /Jeppe
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to