Hi Gonzalo
For my
Quote:
I can process the named parameters myself, but not sure how I actually get a 'Query' object from that without going through createSQLQuery - but createSQLQuery seems to be the lowest level of call
what I could do is process the query that I get from the higher levels of my application and then call MySQl myself: i.e. get the query and the map of named parameters, run through the named parameters and substitute their values into the query string. At that point I would have a query string without any named parameters in it. I would then use that string to perform my query - except I'm not sure if there is any good way to execute the query besides using createSQLQuery and then calling 'list' - and since that string will still have the ':=' in it, I'll still have my original problem.
After a bit more investigation this morning, I think I could use session.connection() to get a raw JDBC connection object and go from there, but I've seen a few mentions (for example,
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2603) of that being deprecated in Hibernate 3.2 (I'm using 3.1.3 right now). Also in HHH-2603 is:
Quote:
...make sure that everyone becomes aware of the dangers of using .connection()...
but no explanation of what those dangers are (or even if that statement is factual) - so I've been hesitating to go in that direction.
What I am trying to do is calculate averages over sets of rows. So, if I have the table var_test:
CREATE TABLE `var_test` (
`num` int(10) default NULL
);
and it has 25 rows with 'num' set to 1..25, I want to do something like this to get the averages of sets of 5 items:
set @x = -1; select floor((@x := @x + 1) / 6), avg(num) from var_test group by 1;
and get:
+---------------------------+----------+
| floor((@x := @x + 1) / 6) | avg(num) |
+---------------------------+----------+
| 0 | 3.0000 |
| 1 | 8.0000 |
| 2 | 13.0000 |
| 3 | 18.0000 |
| 4 | 23.0000 |
+---------------------------+----------+
5 rows in set (0.00 sec)
My actual query is more complex than that, with a subquery and where and order clauses - so I cannot use a column containing sequential id numbers rather than my '@x' variable.
NOTE the ' / 6' - for some reason, MySql handles the equation differently if there is an aggregation function (max, min, count, avg, sum, ...) in the list of columns. That is
mysql> set @x = -1; select floor((@x := @x + 1) / 5), num from var_test group by 1;
produces 5 rows
+---------------------------+------+
| floor((@x := @x + 1) / 5) | num |
+---------------------------+------+
| 0 | 1 |
| 1 | 6 |
| 2 | 11 |
| 3 | 16 |
| 4 | 21 |
+---------------------------+------+
5 rows in set (0.00 sec)
while
set @x = -1; select floor((@x := @x + 1) / 5), min(num) from var_test group by 1;
produces 7 rows
+---------------------------+----------+
| floor((@x := @x + 1) / 5) | min(num) |
+---------------------------+----------+
| 0 | 1 |
| 1 | 5 |
| 2 | 9 |
| 3 | 13 |
| 4 | 17 |
| 5 | 21 |
| 6 | 25 |
+---------------------------+----------+
7 rows in set (0.00 sec)
But I think that is an issue for the MySQL forums...
Many thanks for your interest,
Doug.