Hello,

do you know how can I check which PHP function executes some specific query?

I need it because, I have a little problem after upgrading from 4.7 to 5.1. I receive a warning about ambiguous query after posting new content or editing an existing content:

user warning: Column 'tid' in field list is ambiguous query: SELECT tid FROM term_data LEFT JOIN term_data catd ON term_data.tid = catd.tid WHERE (term_data.tid IN (2, 0) OR catd.vid NOT IN (2)) ORDER BY tid LIMIT 305, 1 in C:\xampp\htdocs\drupal-5.1\includes\database.mysql.inc on line 172.

Obviously in this case, I don't need left join and I would like to change this, but I don't find the place where I should make the change. I've searched in the whole 5.1 directory for "SELECT tid" or "LEFT JOIN", but can't find which function is called. I think that it has to do with the taxonomy module, but I can't find there such kind of query.

Have somebody experienced something like that?

Comments

nancydru’s picture

What were you doing when this happened? Based on the format of the query, I'm guessing there is a local module (as opposed to core or contrib) doing this, probably also using db_rewrite_sql. Another guess is that this has to do with the Category module.

BTW, I've not had much luck with Windows search finding anything in Drupal modules.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

erdtek’s picture

I copied all the files of the site into the 5.1 and then removed the old modules and put the 5.1 modules. And after a enabling the modules and running update.php I got to this situation. I found out that it has something to do with the tac_lite ("Taxonomy Access Control Lite") module, because when I disable it, I don't get the message. But still the question is interesting, whether I can follow the methods which are executed, to find who invokes a particular query. I think that in order to do this one needs PHP debugger, or maybe Drupal can log this somewhere...

P.S. about the searching, I use the search function in Eclipse.

NEW: I fix it after some experiments :)
The problem was that in the module two tables are joined, but it is not checked that these two tables may be the same, so I had to add this check manually ($primary_table == 'term_data'):

// hack BEGIN
//$join = "LEFT JOIN {term_data} catd ON $primary_table.tid = catd.tid"; // commented out
if($primary_table == 'term_data')
$join = "";
else $join = "LEFT JOIN {term_data} catd ON $primary_table.tid = catd.tid";
// hack END

// hack BEGIN
//$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR catd.vid NOT IN (". implode(',', $vids) .")"; // commented out
if($primary_table == 'term_data')
$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR $primary_table.vid NOT IN (". implode(',', $vids) .")";
else
$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR catd.vid NOT IN (". implode(',', $vids) .")";
// hack END

erdtek’s picture