Ticket #5568 (closed defect: fixed)

Opened 4 years ago

Last modified 2 weeks ago

[Patch] SQL query failures with MySQL

Reported by: scouret@alten.fr Assigned to: rjollos
Priority: normal Component: TracTicketStatsPlugin
Severity: blocker Keywords: mysql
Cc: Trac Release: 0.11

Description (Last modified by rjollos)

Hello,

I ran into SQL requests issues while running TracTicketStatsPlugin with a mysql backend :

  1. (1054, "Unknown column 'created' in 'where clause'") This is due to Mysql poor Alias handling, i propose to use the column name (t.time) instead of alias name(created) as shown in following patch :
ticketstats.py 
@@ -88,13 +88,13 @@
-               cursor.execute("SELECT t.type AS type, owner, status, time AS created FROM ticket t, enum p WHERE p.name = t.priority AND p.type = 'priority' AND created <= %s" % to_timestamp(at_date))
+               cursor.execute("SELECT t.type AS type, owner, status, time AS created FROM ticket t, enum p WHERE p.name = t.priority AND p.type = 'priority' AND t.time <= %s" % to_timestamp(at_date))
  1. The next issue is related with the use of 'enum p' . Here comes the proposed patch :
ticketstats.py 
@@ -61,7 +61,7 @@
-               cursor.execute("SELECT t.id, tc.field, tc.time, tc.oldvalue, tc.newvalue, t.priority FROM ticket_change tc, enum p INNER JOIN ticket t ON t.id = tc.ticket AND tc.time > %s AND tc.time <= %s WHERE p.name = t.priority AND p.type = 'priority' ORDER BY tc.time" % (to_timestamp(from_date), to_timestamp(at_date)))
+               cursor.execute("SELECT t.id, tc.field, tc.time, tc.oldvalue, tc.newvalue, t.priority FROM enum p, ticket_change tc INNER JOIN ticket t ON t.id = tc.ticket AND tc.time > %s AND tc.time <= %s WHERE p.name = t.priority AND p.type = 'priority' ORDER BY tc.time" % (to_timestamp(from_date), to_timestamp(at_date)))

Hope this helps. Thanks for all your good job with this plugin

Attachments

mysql.patch (2.3 kB) - added by bart on 10/07/09 15:14:11.
patch for the MySQL issues

Change History

(follow-up: ↓ 2 ) 08/13/09 20:14:29 changed by anonymous

omg, thanks for the fix was driving me crazy... could it be that enum is some reserved word?

(in reply to: ↑ 1 ) 10/07/09 15:13:24 changed by anonymous

Replying to anonymous:

omg, thanks for the fix was driving me crazy... could it be that enum is some reserved word?

No.

First issue is that the column aliases are not allowed in WHERE clause.
http://dev.mysql.com/doc/refman/5.1/en/problems-with-alias.html

Second is that the JOIN has the higher precedence, so the table being joined must be next to JOIN clause (i.e. must go after tables not participating in JOIN).
http://dev.mysql.com/doc/refman/5.1/en/join.html

BTW. I was about to submit same patches.

10/07/09 15:14:11 changed by bart

  • attachment mysql.patch added.

patch for the MySQL issues

08/23/10 02:58:56 changed by rjollos

  • summary changed from Mysql requests issues with TracTicketStatsPlugin to [Patch] SQL query failures with MySQL.

11/20/10 09:49:20 changed by rjollos

  • owner changed from echo0101 to rjollos.

Reassigning ticket to new maintainer.

12/10/10 11:30:37 changed by sterun

After applying the patch it works fine as long as Milestone = 'All Milestones'. If I choose a specific milestone I get a similar error though:

2010-12-09 16:10:54,163 Trac[main] ERROR: column "<milestone_name>" does not exist

12/10/10 12:04:29 changed by sterun

Please ignore the previous comment. I installed the patch incorrectly.

12/11/10 03:18:38 changed by rjollos

Thanks for letting me know that the patch works with MySQL. I'll test it with SQLite and apply if it doesn't break anything.

12/11/10 22:51:50 changed by rjollos

  • status changed from new to assigned.
  • description changed.

12/11/10 23:17:42 changed by rjollos

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [9660]) Fixed SQL queries that were incompatible with MySQL. Fixes #5568.

12/11/10 23:39:04 changed by rjollos

(In [9661]) Merged [9660] from trunk to branches/0.11 and branches/0.12. Refs #5568.

05/13/13 05:25:53 changed by rjollos

(In [13104]) Refs #8600, #5568, #3594: Removed the 0.11 and 0.12 branches. The trunk will be kept compatible with 0.11 and higher for now.


Add/Change #5568 ([Patch] SQL query failures with MySQL)




Change Properties
Action