Bug 340056 - Queries having the same field name in 2 tables not handled
Summary: Queries having the same field name in 2 tables not handled
Status: CLOSED FIXED
Alias: None
Product: KEXI
Classification: Applications
Component: Queries (show other bugs)
Version: 2.8.6
Platform: Mint (Ubuntu based) Linux
: NOR normal
Target Milestone: 2.9.11
Assignee: Jarosław Staniek
URL:
Keywords:
: 330512 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-10-17 14:50 UTC by robert leleu
Modified: 2016-03-03 22:49 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 2.9.11
Sentry Crash Report:


Attachments
query liensidentite (24.20 KB, image/png)
2014-10-22 13:39 UTC, robert leleu
Details
query is available (661.79 KB, image/jpeg)
2014-10-22 13:44 UTC, robert leleu
Details
SQL is incorrect (32.79 KB, image/png)
2014-10-22 13:52 UTC, robert leleu
Details
links disappeared (23.58 KB, image/png)
2014-10-22 13:55 UTC, robert leleu
Details
the query is no longer available (747.50 KB, image/jpeg)
2014-10-22 13:58 UTC, robert leleu
Details
Simple test database, for the record (12.00 KB, application/x-kexiproject-sqlite2)
2016-01-22 00:54 UTC, Jarosław Staniek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description robert leleu 2014-10-17 14:50:23 UTC
New query doesn't show up in the internal source for report, even after having restarted kexi

Reproducible: Always

Steps to Reproduce:
1.create a query, save it, close it
2.create a new report
3

Actual Results:  
.the new query is not in the combo of internal sources

Expected Results:  
.the new query is in the combo of internal sources

I had similar problem about one year ago with modified queries. It seems fixed.

Unfortunately I am not at the last rev of Kexi. I did not succeed to install Neon-project, nor to compile from source. I hope I have more time in the future to try again
Comment 1 robert leleu 2014-10-17 15:08:08 UTC
Happens if the query includes a field having the same name in 2 tables (the field used to have a relation) although the field name is correctly prefixed in the SQL view.
This field can be used to build the query, but cannot be displayed.
Comment 2 Jarosław Staniek 2014-10-17 23:01:29 UTC
Thanks Robert. As always, perfect details!
Comment 3 Jarosław Staniek 2014-10-17 23:03:08 UTC
I've set the component to Queries as this is the place where the issue is manifested.
Comment 4 Wojciech Kosowicz 2014-10-21 21:32:01 UTC
Robert, Staniek could anyone provide me example of such behaviour? :) By description I'm not sure if I understand it right and if I would be able to reproduce it correctly? :)
Comment 5 Wojciech Kosowicz 2014-10-21 21:38:23 UTC
i tried reproduce it on latest master and everything worked. Please provide me more information or sample file to reproduce it
Comment 6 robert leleu 2014-10-22 13:39:06 UTC
Created attachment 89254 [details]
query liensidentite
Comment 7 robert leleu 2014-10-22 13:44:18 UTC
Created attachment 89255 [details]
query is available
Comment 8 Jarosław Staniek 2014-10-22 13:47:46 UTC
Thanks @Robert!
Comment 9 robert leleu 2014-10-22 13:52:57 UTC
Created attachment 89258 [details]
SQL is incorrect
Comment 10 robert leleu 2014-10-22 13:55:49 UTC
Created attachment 89259 [details]
links disappeared
Comment 11 robert leleu 2014-10-22 13:58:33 UTC
Created attachment 89260 [details]
the query is no longer available
Comment 12 robert leleu 2014-10-22 14:32:30 UTC
see the query liensidentite, attached

this query is available (attachment) as internal source in reports

I modify the query (through the gui) to display field liens.licleunik.
The resulting SQL is incorrect (the field is not .prefixed, see attachment) 

and the links disappeared (see attachment)

and the query is no longer available (attachment) for reports

Suppressing the display of the incriminated field, and re-creating the links, the query is again available for reports


I think that the chief bug is that the SQL doesn't capture the whole prefixed name when requested. Or perhaps shouldn't I use identical names in different tables ? (this is an heritage of the first BDD software I used (Windev).  In such a case there should be some message to inform the user ?
Comment 13 Jarosław Staniek 2014-10-23 09:58:15 UTC
@Robert in such cases please paste the original SQL statement as text here so we can test it.
Comment 14 robert leleu 2014-11-01 15:53:56 UTC
when the query «liensidentite» is built through the gui the SQL is as follows

<code>SELECT civilite, nom, prenom, courriel, tel, telmobil, adresse1, adresse2, codepays, code, commune, trilien, licleunik, idcleunik FROM lieide, identite, liens, localis, codecomm, pays WHERE (identite.idcleunik = lieide.idcleunik AND pays.pacleunik = codecomm.pacleunik AND codecomm.cocleunik = localis.cocleunik AND liens.licleunik = lieide.licleunik AND localis.locleunik = identite.locleunik) AND (identite.idcleunik = 3141 AND liens.licleunik = 1079) ORDER BY identite.nom
The query is incorrect
Both table "lieide" and "liens" have defined "licleunik" field. Use ".licleunik" notation to specify table name.</code>
and the query is not available for reports

the corrected query is SQL made as follows
<code>SELECT civilite, nom, prenom, courriel, tel, telmobil, adresse1, adresse2, codepays, code, commune, trilien, lieide.licleunik, lieide.idcleunik FROM lieide, identite, liens, localis, codecomm, pays WHERE (identite.idcleunik = lieide.idcleunik AND pays.pacleunik = codecomm.pacleunik AND codecomm.cocleunik = localis.cocleunik AND liens.licleunik = lieide.licleunik AND localis.locleunik = identite.locleunik) AND (identite.idcleunik = 3141 AND liens.licleunik = 1079) ORDER BY identite.nom
The query is correct</code>

but the links are no longer present in the gui.
to have an operational query available for reports one shall close kexi, reopen, fix the query, fix the report.
This seems to occur only if one (at less) «field to be prefixed» is prsent in the SELECT statement
Comment 15 Jarosław Staniek 2014-11-03 08:14:36 UTC
Issue until 2.8.6
Comment 16 Jarosław Staniek 2016-01-22 00:51:16 UTC
Git commit c346e86c6765a542057ae3ee19e1622e98685eb1 by Jaroslaw Staniek.
Committed on 22/01/2016 at 00:43.
Pushed by staniek into branch 'calligra/2.9'.

Kexi Query Designer: support queries having the same field name used in multiple tables
FIXED-IN:2.9.11

M  +2    -1    kexi/plugins/queries/kexiquerydesignerguieditor.cpp

http://commits.kde.org/calligra/c346e86c6765a542057ae3ee19e1622e98685eb1
Comment 17 Jarosław Staniek 2016-01-22 00:54:28 UTC
Created attachment 96777 [details]
Simple test database, for the record

See the query1: after the fix its SQL is "SELECT t1.b FROM t1, t2 WHERE t2.id = t1.a".
Before the fix it is "SELECT b FROM t1, t2 WHERE t2.id = t1.a" what caused error because "b" isn't unique name.
Comment 18 Jarosław Staniek 2016-01-22 00:54:56 UTC
Done, finally!
Please test.
Comment 19 Jarosław Staniek 2016-01-22 20:48:16 UTC
*** Bug 330512 has been marked as a duplicate of this bug. ***
Comment 20 Jarosław Staniek 2016-02-29 23:36:01 UTC
Git commit 1bb1df8f9bc51fed8cd77d304623ae133bbfda8c by Jaroslaw Staniek.
Committed on 29/02/2016 at 23:07.
Pushed by staniek into branch 'master'.

Query Designer: support queries having the same field name used in multiple tables
FIXED-IN:2.9.11

(from calligra.git)

M  +2    -1    src/plugins/queries/kexiquerydesignerguieditor.cpp

http://commits.kde.org/kexi/1bb1df8f9bc51fed8cd77d304623ae133bbfda8c