Opened 16 years ago
Closed 11 years ago
#3359 closed defect (fixed)
Tickets tags don't work when using MySQL 4.x
Reported by: | nigelsim | Owned by: | Steffen Hoffmann |
---|---|---|---|
Priority: | normal | Component: | TagsPlugin |
Severity: | normal | Keywords: | MySQL SQL syntax compatibility |
Cc: | Ryan J Ollos, Michael Renzmann | Trac Release: | 0.10 |
Description
If you try to enable the tickets tags module, while using MySQL 4.x you get the following error:
ProgrammingError: (1064, "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 'fields FROM ticket WHERE status != 'closed') s WHERE fields != '' ORDER BY id' at line 1") File "/opt/trac-0.11/src/tractags/tags/0.6/tractags/ticket.py", line 66, in get_tagged_resources
The issue is that this SQL stanza
SELECT id, %s, %s AS fields FROM ticket%s
fails, because MySQL seems to think fields is a keyword. On my site I renamed fields to fieldss. Another option is using backticks ` around the field name, but I'm not sure this is compatible with other databases.
Attachments (0)
Change History (9)
comment:1 Changed 15 years ago by
comment:3 Changed 13 years ago by
Cc: | Ryan J Ollos Michael Renzmann added; anonymous removed |
---|---|
Keywords: | MySQL SQL syntax compatibility added |
Owner: | changed from Alec Thomas to Steffen Hoffmann |
Would like to fix as many real bugs as possible for next stable release.
Anyone ready for testing a patch so that I don't need to do a MySQL setup here on my own?
comment:4 Changed 13 years ago by
While I'm investigating #4277 you could already check this patch (essentially the suggested field group alias rename plus some SQL statement re-formatting):
-
tagsplugin/trunk/tractags/ticket.py
diff --git a/tagsplugin/trunk/tractags/ticket.py b/tagsplugin/trunk/tractags/ticket.py
a b 52 52 ignore = '' 53 53 if self.ignore_closed_tickets: 54 54 ignore = " WHERE status != 'closed'" 55 sql = "SELECT * FROM (SELECT id, %s, %s AS fields FROM ticket%s) s" % ( 56 ','.join(self.fields), 57 '||'.join(["COALESCE(%s, '')" % f for f in self.fields]), 58 ignore) 55 sql = """SELECT * 56 FROM (SELECT id, %s, %s 57 AS std_fields 58 FROM ticket%s) s 59 """ % (','.join(self.fields), 60 '||'.join(["COALESCE(%s, '')" % f for f in self.fields]), 61 ignore) 59 62 constraints = [] 60 63 if tags: 61 64 constraints.append( 62 "(" + ' OR '.join([" fields LIKE %s" for t in tags]) + ")")65 "(" + ' OR '.join(["std_fields LIKE %s" for t in tags]) + ")") 63 66 args += ['%' + t + '%' for t in tags] 64 67 else: 65 constraints.append(" fields != ''")68 constraints.append("std_fields != ''") 66 69 67 70 if constraints: 68 71 sql += " WHERE " + " AND ".join(constraints)
comment:5 Changed 13 years ago by
I noticed, that just quoting strings falsely misinterpreted as keywords would solve the problem as well. Comments?
And that 'fields' isn't on the list of any relevant database system - strange.
comment:6 Changed 13 years ago by
(In [10774]) TagsPlugin: Use a different alias name for (standard ticket) fields, refs #3359.
Prevent misinterpretation as keyword, that has been reported for MySQL.
comment:7 Changed 12 years ago by
Would be nice to have a success report here, because I'm unable to test against MySQL yet.
comment:8 Changed 11 years ago by
Counting in myself here, but my deployment has been on MySQL 5, so still not a real reference.
Same problem here, I had to change the name into another one so there is no conflict with mysql.
This changed inside plugin sources...