Commit c17499b6 authored by Dries's avatar Dries

- Patch #163191 by hswong3i: removed db_num_rows() for compatibility with...

- Patch #163191 by hswong3i: removed db_num_rows() for compatibility with Oracle and DB2.  Also a performance improvement. (Correct version this time.)
parent b134b023
......@@ -720,11 +720,13 @@ function menu_tree_page_data($menu_name = 'navigation') {
// their children to the list as well.
do {
$result = db_query("SELECT mlid FROM {menu_links} WHERE menu_name = '%s' AND expanded = 1 AND has_children = 1 AND plid IN (". $placeholders .') AND mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args));
$num_rows = FALSE;
while ($item = db_fetch_array($result)) {
$args[] = $item['mlid'];
$num_rows = TRUE;
}
$placeholders = implode(', ', array_fill(0, count($args), '%d'));
} while ($item);
} while ($num_rows);
}
array_unshift($args, $menu_name);
}
......
......@@ -964,10 +964,12 @@ function aggregator_parse_feed(&$data, $feed) {
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
$items = array();
$num_rows = FALSE;
while ($item = db_fetch_object($result)) {
$items[] = $item->iid;
$num_rows = TRUE;
}
if ($item) {
if ($num_rows) {
db_query('DELETE FROM {aggregator_category_item} WHERE iid IN ('. implode(', ', $items) .')');
db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age);
}
......
......@@ -1019,6 +1019,7 @@ function comment_render($node, $cid = 0) {
$divs = 0;
$last_depth = 0;
$num_rows = FALSE;
$comments = '';
drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
while ($comment = db_fetch_object($result)) {
......@@ -1053,9 +1054,11 @@ function comment_render($node, $cid = 0) {
else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
$comments .= theme('comment_thread_expanded', $comment, $node);
}
$num_rows = TRUE;
}
if ($comment && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
if ($num_rows && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
}
$output .= $comments;
......@@ -1065,7 +1068,7 @@ function comment_render($node, $cid = 0) {
}
$output .= theme('pager', NULL, $comments_per_page, 0);
if ($comment && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
if ($num_rows && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
$output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
}
}
......
......@@ -119,11 +119,13 @@ function node_cron() {
*/
function node_title_list($result, $title = NULL) {
$items = array();
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$items[] = l($node->title, 'node/'. $node->nid, !empty($node->comment_count) ? array('title' => format_plural($node->comment_count, '1 comment', '@count comments')) : array());
$num_rows = TRUE;
}
return $node ? theme('node_list', $items, $title) : FALSE;
return $num_rows ? theme('node_list', $items, $title) : FALSE;
}
/**
......@@ -2557,11 +2559,13 @@ function node_page_default() {
$result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));
$output = '';
$num_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows = TRUE;
}
if ($node) {
if ($num_rows) {
$feed_url = url('rss.xml', array('absolute' => TRUE));
drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') .' '. t('RSS'));
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
......
......@@ -1428,9 +1428,9 @@ function system_update_159() {
$ret = array();
$result = db_query_range("SELECT * FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20);
$result_rows = db_result(db_query_range("SELECT COUNT(*) FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20));
$num_rows = db_result(db_query_range("SELECT COUNT(*) FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20));
if ($result_rows) {
if ($num_rows) {
$vid = db_next_id('{node_revisions}_vid');
while ($node = db_fetch_object($result)) {
$revisions = unserialize($node->revisions);
......@@ -1520,7 +1520,7 @@ function system_update_159() {
}
}
if ($result_rows < 20) {
if ($num_rows < 20) {
$ret[] = update_sql('ALTER TABLE {old_revisions} DROP done');
}
else {
......@@ -2169,6 +2169,7 @@ function system_update_179() {
$limit = 20;
$args = array_merge(array($_SESSION['system_update_179_uid'], $_SESSION['system_update_179_fid'], $_SESSION['system_update_179_uid']), $_SESSION['system_update_179_fields']);
$result = db_query_range("SELECT fid, uid, value FROM {profile_values} WHERE ((uid = %d AND fid > %d) OR uid > %d) AND fid IN ". $_SESSION['system_update_179_field_string'] .' ORDER BY uid ASC, fid ASC', $args, 0, $limit);
$num_rows = 0;
while ($field = db_fetch_object($result)) {
$_SESSION['system_update_179_uid'] = $field->uid;
$_SESSION['system_update_179_fid'] = $field->fid;
......@@ -2176,11 +2177,11 @@ function system_update_179() {
if ($field->value !== FALSE) {
db_query("UPDATE {profile_values} SET value = '%s' WHERE uid = %d AND fid = %d", $field->value, $field->uid, $field->fid);
}
$num_rows++;
}
// Done?
if (!$field) {
if ($num_rows == 0) {
unset($_SESSION['system_update_179_uid']);
unset($_SESSION['system_update_179_fid']);
unset($_SESSION['system_update_179_max']);
......
......@@ -983,10 +983,12 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
*/
function taxonomy_render_nodes($result) {
$output = '';
$num_rows = 0;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$num_rows++;
}
if ($node) {
if ($num_rows > 0) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
......
......@@ -1096,10 +1096,12 @@ function user_current_to_arg($arg) {
function user_get_authmaps($authname = NULL) {
$result = db_query("SELECT authname, module FROM {authmap} WHERE authname = '%s'", $authname);
$authmaps = array();
$num_rows = 0;
while ($authmap = db_fetch_object($result)) {
$authmaps[$authmap->module] = $authmap->authname;
$num_rows++;
}
return count($authmaps) ? $authmaps : 0;
return $num_rows > 0 ? $authmaps : 0;
}
function user_set_authmaps($account, $authmaps) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment