Bug 6579

Summary: getalert SQL invalid for KOHA_USER
Product: Koha Reporter: Joe Atzberger <ohiocore>
Component: NoticesAssignee: Bugs List <koha-bugs>
Status: CLOSED INVALID QA Contact: Bugs List <koha-bugs>
Severity: normal    
Priority: P5 - low CC: jonathan.druart
Version: rel_3_0   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:

Description Joe Atzberger 2011-07-12 04:00:32 UTC
The code for getalert in C4::Letters fails to account for one important case.  While the POD says "all parameters NON mandatory", the result of NO arguments produces invalid SQL. 

The errors in the log look like:

[error] [client 71.64.0.171] [Mon Jul 11 19:54:12 2011] opac-user.pl: DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 at /usr/share/koha/lib/C4/Letters.pm line 197, <DATA> line 522., referer: https://my.koha.edu/cgi-bin/koha/opac-user.pl

[error] [client 71.64.0.171] [Mon Jul 11 19:54:12 2011] opac-user.pl: DBD::mysql::st fetchall_arrayref failed: fetch() without execute() at /usr/share/koha/lib/C4/Letters.pm line 198, <DATA> line 522., referer: https://my.koha.edu/cgi-bin/koha/opac-user.pl

If you look at the logic, you'll agree that "SELECT * FROM alert WHERE" is not a valid SQL query.

Code should assemble bind name/value pairs in a hash instead of appending to the query and pushing onto an array.  Then build the WHERE clause at the end only when hash is populated.
Comment 1 Joe Atzberger 2011-07-12 04:02:33 UTC
Alternatively, the standard hack of "SELECT ... WHERE 1 AND ..." could be used here.
Comment 2 Jonathan Druart 2015-03-27 09:57:13 UTC
You are not allowed to use Koha with the DB user.