View Issue Details

IDProjectCategoryView StatusLast Update
0006394mantisbtsqlpublic2006-09-12 00:54
Reporternaib Assigned Tothraxisp  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
PlatformSunOSSolarisOS Version8
Product Version0.19.3 
Fixed in Version1.0.0a1 
Summary0006394: Unknown column p.field_id when closing bug when using MySQL >= 5.0.12
Description

Things were working fine with MySQL Max 4.1.14 and Mantis 0.19.2, but since upgrading MySQL to Max 5.0.15, an application error is produced whenever I close a bug (it may also require using an empty note).

APPLICATION ERROR 0000401

Database query failed. Error received from database was #1054: Unknown column 'p.field_id' in 'on clause' for the query: SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value
FROM mantis_custom_field_project_table AS p, mantis_custom_field_table AS f
LEFT JOIN mantis_custom_field_string_table AS s
ON p.field_id=s.field_id AND s.bug_id='980'
WHERE p.project_id = '20' AND p.field_id = f.id
ORDER BY p.sequence ASC, f.name ASC

Upgrading to 0.19.3 and making sure the admin upgrades were all done did not fix the issue. I note that all 24 tables exist and the two tables mentioned above are empty (as expected) because I have not (knowingly) defined any custom fields. Bug ID 980 is the correct bug_id for the issue I'm attempting to close.

What exactly is the problem?

TagsNo tags attached.

Relationships

duplicate of 0005380 closedthraxisp Invalid LEFT JOIN syntax for Oracle 
has duplicate 0006428 closedryandesign MySQL 5: Unknown column 'p.field_id' in 'on clause' 
has duplicate 0006937 closedryandesign MySQL Compability v.4 and v.5 
child of 0005460 closedvboctor Critical Issues to Fix for Mantis 1.0.0 Release 

Activities

naib

naib

2005-11-07 03:19

reporter   ~0011597

Incidentally, I get a similar error when attempting to change the priority of another issue from urgent to high:

APPLICATION ERROR 0000401

Database query failed. Error received from database was #1054: Unknown column 'p.field_id' in 'on clause' for the query: SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value
FROM mantis_custom_field_project_table AS p, mantis_custom_field_table AS f
LEFT JOIN mantis_custom_field_string_table AS s
ON p.field_id=s.field_id AND s.bug_id='769'
WHERE p.project_id = '6' AND p.field_id = f.id
ORDER BY p.sequence ASC, f.name ASC

naib

naib

2005-11-07 20:50

reporter   ~0011601

OK, I've found the problem.

The issue comes from a recent change in MySQL 5, and I quote from the MySQL Reference Manual (http://dev.mysql.com/doc/refman/5.0/en/join.html):

"Before MySQL 5.0.12, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was intrepreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.

"Example:

"CREATE TABLE t1 (i1 INT, j1 INT);
CREATE TABLE t2 (i2 INT, j2 INT);
CREATE TABLE t3 (i3 INT, j3 INT);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t2 VALUES(1,1);
INSERT INTO t3 VALUES(1,1);
SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);

"Prior to 5.0.12, the SELECT is legal due to the implicit grouping of t1,t2 as (t1,t2). From 5.0.12 on, the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:

"SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);

"This change also applies to INNER JOIN, CROSS JOIN, LEFT JOIN, and RIGHT JOIN."

As a result, the first query I noted above can be corrected in code for all versions of MySQL as follows:

"SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value
FROM (mantis_custom_field_project_table AS p, mantis_custom_field_table AS f)
LEFT JOIN mantis_custom_field_string_table AS s
ON p.field_id=s.field_id AND s.bug_id='980'
WHERE p.project_id = '20' AND p.field_id = f.id
ORDER BY p.sequence ASC, f.name ASC"

Note addition of brackets around the tables in the FROM clause.

naib

naib

2005-11-07 22:39

reporter   ~0011602

Modified lines as follows to get things working:

"core/custom_field_api.php" line 754

No other query I could find required the change.

ryandesign

ryandesign

2005-11-22 08:42

reporter   ~0011646

See another possible solution in 0006428.

grangeway

grangeway

2005-12-23 05:31

reporter   ~0011839

Is this still an issue in 1.0.0rc4?

naib

naib

2006-02-03 20:34

reporter   ~0012078

Yes, this is now working for me in 1.0.0r5.

thraxisp

thraxisp

2006-04-17 21:50

reporter   ~0012564

This was actually fixed in 1.0.0a1 as part of other fixes. This query is changed in 1.0.1.