[Bug 14704] New: members/statistics.pl crashes because the SQL 'return'-keyword might be reserved at 'return FROM ('
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 Bug ID: 14704 Summary: members/statistics.pl crashes because the SQL 'return'-keyword might be reserved at 'return FROM (' Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Patrons Assignee: koha-bugs@lists.koha-community.org Reporter: olli-antti.kivilahti@jns.fi QA Contact: testopia@bugs.koha-community.org CC: gmcharlt@gmail.com, kyle.m.hall@gmail.com At Ubuntu 14.04 using MariaDB, the following SQL doesn't work: SELECT COUNT(*) as count_precedent_state,issues,onloan,return FROM ( SELECT it.* FROM issues i, items it WHERE i.borrowernumber = 1234 AND i.itemnumber = it.itemnumber AND DATE(i.issuedate) < CAST(now() AS date) UNION SELECT it.* FROM old_issues oi, items it WHERE oi.borrowernumber = 1234 AND oi.itemnumber = it.itemnumber AND DATE(oi.issuedate) < CAST(now() AS date) AND DATE(oi.returndate) = CAST(now() AS date) ) tmp GROUP BY issues,onloan,return; We get "Syntax error near 'return FROM ('" This patch changes the SQL to prefix the selected columns with a table name prefix, so we get: SELECT COUNT(*) as count_precedent_state,tmp.issues,tmp.onloan,tmp.return FROM ( SELECT it.* FROM issues i, items it WHERE i.borrowernumber = 1234 AND i.itemnumber = it.itemnumber AND DATE(i.issuedate) < CAST(now() AS date) UNION SELECT it.* FROM old_issues oi, items it WHERE oi.borrowernumber = 1234 AND oi.itemnumber = it.itemnumber AND DATE(oi.issuedate) < CAST(now() AS date) AND DATE(oi.returndate) = CAST(now() AS date) ) tmp GROUP BY tmp.issues,tmp.onloan,tmp.return; Which is more formal and less implicit. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 --- Comment #1 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- Created attachment 41775 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=41775&action=edit Bug 14704 - members/statistics.pl crashes because the SQL 'return'-keyword might be reserved at 'return FROM (' -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@bugs.koha-c | |ommunity.org --- Comment #2 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- I got the following if I execute directly the second query in my MariaDB CLI: ERROR 1054 (42S22): Unknown column 'tmp.return' in 'field list' -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 --- Comment #3 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- (In reply to Jonathan Druart from comment #2)
I got the following if I execute directly the second query in my MariaDB CLI:
ERROR 1054 (42S22): Unknown column 'tmp.return' in 'field list'
That is because my hastily created example SQL was missing explicit definition for issues.return and old_issues.return. This wasn't the case in the code (hopefully). Try this: SELECT COUNT(*) as count_precedent_state,tmp.issues,tmp.onloan,tmp.return FROM ( SELECT it.*, i.return FROM issues i, items it WHERE i.borrowernumber = 1234 AND i.itemnumber = it.itemnumber AND DATE(i.issuedate) < CAST(now() AS date) UNION SELECT it.*, oi.return FROM old_issues oi, items it WHERE oi.borrowernumber = 1234 AND oi.itemnumber = it.itemnumber AND DATE(oi.issuedate) < CAST(now() AS date) AND DATE(oi.returndate) = CAST(now() AS date) ) tmp GROUP BY tmp.issues,tmp.onloan,tmp.return; -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |In Discussion --- Comment #4 from Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> --- The dynamically created SQL here is problematic and needs to be overhauled on a more broader level. Since the columns desired can be gained from a syspref, the SQL needs to take that into account as well. This is an optimal scenario to leverage DBIx and its more configurable search building. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|unspecified |master -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14704 Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |http://bugs.koha-community. | |org/bugzilla3/show_bug.cgi? | |id=14719 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org