From 7add598ee2105dbe022cf859f851ada4790d1c4e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 8 Mar 2006 15:13:20 +0000 Subject: - Patch #51850 by chx, webchick et al: fixed various problems with db_rewrite_sql, made db_rewrite_sql slightly more robust. --- modules/forum.module | 2 +- modules/forum/forum.module | 2 +- modules/taxonomy.module | 12 ++++++------ modules/taxonomy/taxonomy.module | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'modules') diff --git a/modules/forum.module b/modules/forum.module index 9168f0819..4ccfa53f7 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -686,7 +686,7 @@ function forum_get_forums($tid = 0) { // This query does not use full ANSI syntax since MySQL 3.x does not support // table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria // used to join node_comment_statistics to users. - $sql = "SELECT n.nid, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) as last_comment_name, l.last_comment_uid FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r WHERE n.nid = r.nid AND r.tid = %d AND n.status = 1 AND n.type = 'forum' AND l.last_comment_uid = cu.uid AND n.nid = l.nid ORDER BY l.last_comment_timestamp DESC"; + $sql = "SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} cu ON l.last_comment_uid = cu.uid WHERE n.status = 1 AND r.tid = %d"; $sql = db_rewrite_sql($sql); $topic = db_fetch_object(db_query_range($sql, $forum->tid, 0, 1)); diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 9168f0819..4ccfa53f7 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -686,7 +686,7 @@ function forum_get_forums($tid = 0) { // This query does not use full ANSI syntax since MySQL 3.x does not support // table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria // used to join node_comment_statistics to users. - $sql = "SELECT n.nid, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) as last_comment_name, l.last_comment_uid FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r WHERE n.nid = r.nid AND r.tid = %d AND n.status = 1 AND n.type = 'forum' AND l.last_comment_uid = cu.uid AND n.nid = l.nid ORDER BY l.last_comment_timestamp DESC"; + $sql = "SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} cu ON l.last_comment_uid = cu.uid WHERE n.status = 1 AND r.tid = %d"; $sql = db_rewrite_sql($sql); $topic = db_fetch_object(db_query_range($sql, $forum->tid, 0, 1)); diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 45f128130..297a5b5ca 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -655,7 +655,7 @@ function taxonomy_form_alter($form_id, &$form) { * Find all terms associated to the given node, within one vocabulary. */ function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid') { - $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t, {term_node} r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); $terms = array(); while ($term = db_fetch_object($result)) { $terms[$term->$key] = $term; @@ -789,7 +789,7 @@ function taxonomy_get_related($tid, $key = 'tid') { */ function taxonomy_get_parents($tid, $key = 'tid') { if ($tid) { - $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); $parents = array(); while ($parent = db_fetch_object($result)) { $parents[$parent->$key] = $parent; @@ -822,10 +822,10 @@ function taxonomy_get_parents_all($tid) { */ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') { if ($vid) { - $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid); + $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid); } else { - $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight, name', 't', 'tid'), $tid); + $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid); } $children = array(); while ($term = db_fetch_object($result)) { @@ -864,7 +864,7 @@ function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) { if (!isset($children[$vid])) { $children[$vid] = array(); - $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t, {term_hierarchy} h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); while ($term = db_fetch_object($result)) { $children[$vid][$term->parent][] = $term->tid; $parents[$vid][$term->tid][] = $term->parent; @@ -927,7 +927,7 @@ function taxonomy_term_count_nodes($tid, $type = 0) { $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid')); } else { - $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type); + $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type); } while ($term = db_fetch_object($result)) { $count[$type][$term->tid] = $term->c; diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 45f128130..297a5b5ca 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -655,7 +655,7 @@ function taxonomy_form_alter($form_id, &$form) { * Find all terms associated to the given node, within one vocabulary. */ function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid') { - $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t, {term_node} r WHERE t.tid = r.tid AND t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); $terms = array(); while ($term = db_fetch_object($result)) { $terms[$term->$key] = $term; @@ -789,7 +789,7 @@ function taxonomy_get_related($tid, $key = 'tid') { */ function taxonomy_get_parents($tid, $key = 'tid') { if ($tid) { - $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); $parents = array(); while ($parent = db_fetch_object($result)) { $parents[$parent->$key] = $parent; @@ -822,10 +822,10 @@ function taxonomy_get_parents_all($tid) { */ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') { if ($vid) { - $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE t.vid = %d AND h.tid = t.tid AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid); + $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid); } else { - $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.tid = t.tid AND parent = %d ORDER BY weight, name', 't', 'tid'), $tid); + $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid); } $children = array(); while ($term = db_fetch_object($result)) { @@ -864,7 +864,7 @@ function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) { if (!isset($children[$vid])) { $children[$vid] = array(); - $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t, {term_hierarchy} h WHERE t.tid = h.tid AND t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); + $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); while ($term = db_fetch_object($result)) { $children[$vid][$term->parent][] = $term->tid; $parents[$vid][$term->tid][] = $term->parent; @@ -927,7 +927,7 @@ function taxonomy_term_count_nodes($tid, $type = 0) { $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid')); } else { - $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type); + $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND n.type = '%s' GROUP BY t.tid"), $type); } while ($term = db_fetch_object($result)) { $count[$type][$term->tid] = $term->c; -- cgit v1.2.3