Bug 330910 - Queries with lookup field and table alias do not work
Summary: Queries with lookup field and table alias do not work
Status: CLOSED FIXED
Alias: None
Product: KEXI
Classification: Applications
Component: Queries (show other bugs)
Version: 2.8 beta2
Platform: Compiled Sources All
: NOR normal
Target Milestone: 2.8
Assignee: Jarosław Staniek
URL:
Keywords:
Depends on:
Blocks: 330410
  Show dependency treegraph
 
Reported: 2014-02-08 10:37 UTC by Jarosław Staniek
Modified: 2014-03-04 14:15 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 2.8.0


Attachments
Test case. Contains tables t1, t2, and query q. (12.00 KB, application/octet-stream)
2014-02-08 12:01 UTC, Jarosław Staniek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jarosław Staniek 2014-02-08 10:37:26 UTC
Queries with lookup field and table alias do not work. 

Consider database consisted of two tables:
t1 (id_t1)
t2 (id_t2, id_t1 [lookup-to] t1.id_t1)

Then create this query in SQL view: SELECT tb2.id_t1 AS a FROM t2 AS tb2

Kexi executes this physical query:

SELECT tb2.id_t1 AS a, __kexidb_t1_0.id_t1, t2.OID
FROM t2 AS tb2
LEFT OUTER JOIN t1 AS __kexidb_t1_0
                ON t2.id_t1=__kexidb_t1_0.id_t1 

Result: 
Message from server: "no such column: t2.OID"
Also "t2.id_t1" in the JOIN isn't correct.

Expected: 
The query should work, physical SQL should look like:

SELECT tb2.id_t1 AS a, __kexidb_t1_0.id_t1, t2b.OID
FROM t2 AS tb2
LEFT OUTER JOIN t1 AS __kexidb_t1_0
                ON t2b.id_t1=__kexidb_t1_0.id_t1 

Tested with SQLite but probably applies to any db engine.

+++ This bug is related to Bug #330410 +++
Comment 1 Jarosław Staniek 2014-02-08 12:01:10 UTC
Created attachment 85043 [details]
Test case. Contains tables t1, t2, and query q.
Comment 2 Jarosław Staniek 2014-02-20 10:26:54 UTC
Git commit 40364666a4f2253e190a0c143eb5ab2bb0f19d85 by Jaroslaw Staniek.
Committed on 08/02/2014 at 20:33.
Pushed by staniek into branch 'master'.

Make queries with lookup field and table alias work

M  +2    -2    libs/db/connection.cpp

http://commits.kde.org/calligra/40364666a4f2253e190a0c143eb5ab2bb0f19d85
Comment 3 Jarosław Staniek 2014-02-20 10:28:13 UTC
Git commit 439504a6502d0340a274bb23e0a6e5cfcc466af2 by Jaroslaw Staniek.
Committed on 08/02/2014 at 20:33.
Pushed by staniek into branch 'calligra/2.8'.

Make queries with lookup field and table alias work
REVIEW:115594

M  +2    -2    libs/db/connection.cpp

http://commits.kde.org/calligra/439504a6502d0340a274bb23e0a6e5cfcc466af2