• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

groovy sql confusion

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Curious as to whether anyone has seen this issue before or can at least tell me why its happening.

I have a sql query being executed in a groovy Service class which returns 3 columns. When I execute the identical query within mysql I get the results I expect, however in my app, the 3rd column somehow is being returned as an array and not a float/double.

I am always expecting only one row, so the code in my app is :

def sql = new Sql(dataSource)
def row = sql.firstRow(query)

where query is :

String query =
"SELECT "+
" MAX(cl.good) - MIN(cl.good) as 'good'," +
" MAX(cl.bad) - MIN(cl.bad) as 'poor', " +
"(MAX(cl.bad) - MIN(cl.bad)) / (MAX(cl.good) - MIN(cl.good)) * 100 as ratio "+
"FROM logs cl "+
"WHERE cl.id = " + id + " AND cl.date_created > (NOW() - INTERVAL 1 hour)"

an example of the results in the app (from a println) is
row = [good:59768255, poor:4113235, ratio:[54, 46, 56, 56, 50, 48]]

whereas the same in mysql is

good poor ratio
59768255 4113235 6.8820

it looks like ratio is coming back as a char array and not just the value

Has anyone else seen this before ?

Thanks

Dave
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Further to the behaviour above, it can easily be replicated with a an ever so simple query such as :



which will output ["floatValue":[51, 46, 50, 51, 50, 51]]

So I still don't understand why it returns a byte array rather than a float or a double but the way around I've used is just to create a new String() based on the column, as ultimately I needed a string anyway, e.g.

new String(row.floatValue)

Rgds,
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic