After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 495843 - GROUP BY different behaviour between GdaCommand and GdaQuery
GROUP BY different behaviour between GdaCommand and GdaQuery
Status: RESOLVED FIXED
Product: libgda
Classification: Other
Component: SQLite provider
3.1.x
Other Linux
: Normal normal
: ---
Assigned To: malerba
gnome-db Maintainers
Depends on:
Blocks:
 
 
Reported: 2007-11-11 12:03 UTC by Massimo Cora'
Modified: 2008-06-10 09:15 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Massimo Cora' 2007-11-11 12:03:23 UTC
Following test case proposed by Malerba in bug#488860 (thanks!) I converted all my GdaCommand queries into GdaQuery objects.
I notice a different behaviour in a query like this [provider SQLite]:

Parameters are hardcoded for now. The only sensible parameter here is 'namespace'

SELECT symbol.symbol_id, symbol.name FROM symbol JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id LEFT JOIN sym_access ON symbol.access_kind_id = sym_access.access_kind_id  WHERE symbol.scope_id <= 0 AND sym_kind.kind_name = 'namespace' GROUP BY symbol.name

With a GdaCommand I get the sql executed correctly, with grouped symbol.name entries.
On SQLite command line I get it executed correctly too, but with a GdaQuery I don't get the GROUP BY clause executed, e.g. I get all duplicates symbol.name(s).
Is it a limitation of GdaQuery or a bug?

thanks and regards,
Massimo
Comment 1 malerba 2007-12-03 09:32:21 UTC
This bug will be corrected once the new parser and statement infrastructure will be available.
Comment 2 Massimo Cora' 2008-01-13 17:22:10 UTC
Another note I discovered:

running this query without the GROUP BY statement doesn't output nothing.
SELECT symbol.symbol_id, symbol.name, symbol.file_position, symbol.is_file_scope, symbol.signature, sym_kind.kind_name  FROM symbol  JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id WHERE symbol.is_file_scope = 0 AND sym_kind.kind_name IN ('class') 


while this outputs correct results.
SELECT symbol.symbol_id, symbol.name, symbol.file_position, symbol.is_file_scope, symbol.signature, sym_kind.kind_name  FROM symbol  JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id WHERE symbol.is_file_scope = 0 AND sym_kind.kind_name IN ('class') GROUP BY symbol.name

I saw you added a new parsing mechanism on svn. Is it already usable or does it need improvements?

thanks and regards,
Massimo

Comment 3 malerba 2008-01-30 09:11:12 UTC
It should be useable and work correctly at least on the SQLite provider.
Comment 4 Murray Cumming 2008-03-01 18:14:15 UTC
malerba, What version (tarball?) should he try to confirm that this is fixed?
Comment 5 malerba 2008-03-06 07:59:27 UTC
The trunk version (after V4-branch merge) has this fixed.
Comment 6 Murray Cumming 2008-04-05 17:09:03 UTC
Massimmo, it would be great if you could confirm that this is now fixed.
Comment 7 Massimo Cora' 2008-04-08 18:50:05 UTC
With libgda v 4.x it's fixed, but probably there's a minor issue left.

Take for example this query:

SELECT symbol.symbol_id, symbol.name, symbol.file_position, symbol.is_file_scope ,
symbol.signature, sym_kind.kind_name FROM symbol 
      JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id 
      WHERE symbol.scope_id <= 0 AND symbol.is_file_scope

using gda_data_model_dump (data, stdout); I get something like:

symbol.symbol_id | symbol.name             | symbol.file_position | symbol.is_file_scope | symbol.signature | sym_kind.kind_name | sym_kind.access_name
----------+------------------+---------------+---------------+-----------+-----------+------------
      356 | Build            |            34 |             0 |           | namespace |            
      669 | Commander        |            34 |             0 |           | namespace | 

I was expecting to be able to retrieve the different fields' values with something like

gda_data_model_iter_get_value_for_field (priv->data_iter, "kind_name");

without specifing the exact "sym_kind.kind_name" field. I'm not using prepared statements for this query, just a simple  gda_connection_statement_execute_select (). As now I fixed that "bug" (?) with a query like


SELECT symbol.symbol_id AS symbol_id, symbol.name AS name, symbol.file_position AS file_position, symbol.is_file_scope AS is_file_scope,
symbol.signature AS signature, sym_kind.kind_name AS kind_name FROM symbol 
      JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id 
      WHERE symbol.scope_id <= 0 AND symbol.is_file_scope


but I don't think that's really correct nor that I need that aliasing. There are no conflicting fields names between different tables.


thanks and regards,
Massimo
Comment 8 Massimo Cora' 2008-04-19 14:35:01 UTC
I've just tried to make this query prepared

SELECT symbol.symbol_id, symbol.name, symbol.file_position,
symbol.is_file_scope ,
symbol.signature, sym_kind.kind_name FROM symbol 
      JOIN sym_kind ON symbol.kind_id = sym_kind.sym_kind_id 
      WHERE symbol.scope_id <= 0 AND symbol.is_file_scope

and I'm able to retrieve the fields just specifying the field as "kind_name".

Comment 9 malerba 2008-04-30 08:14:05 UTC
When executing a SELECT statement, the column names of the returned GdaDataModel are the ones returned by the DBMS's API. In any way I would recommend against using column names to find a column as nothing guarantees that column names will be unique; it's better to use column numbers (even though it has its drawbacks as well).

Of course it would still be possible to override the column names in a generic way but I can't think of a correct algorythm which would ensure unique column names and still use real column names when possible. Any idea?
Comment 10 Massimo Cora' 2008-05-04 10:52:00 UTC
Well, I thought it was libgda that had to take care of the naming of the columns.
Probably, but this is just an idea that may not work at all, the columns returned can be named as "tablename"_"columnname", with the "_" that concatenates the two strings and make unique the result.

Anyway I solved the problem specifying an alias for every column name, say 
"select field1 AS my_foo_field from ...".
With a prepared statement that works good without speed problems...

thanks and regards,
Massimo

ps: I think you can close this bug.

Comment 11 malerba 2008-06-10 09:15:49 UTC
Ok closing the bug. If you have a proposal for a better fields naming, then please fill another bug.
Thanks, Vivien