From 2b1131c4b85cbb4fdd6cc767932d752c210d3e0e Mon Sep 17 00:00:00 2001 From: Silvio Date: Fri, 11 Feb 2011 13:27:47 -0200 Subject: Using dynamic queries --- node_truncate.module | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/node_truncate.module b/node_truncate.module index a4f34fe..6ea0b85 100644 --- a/node_truncate.module +++ b/node_truncate.module @@ -95,13 +95,24 @@ function node_truncate_form_submit($form, &$form_state) { function node_truncate($type, &$context) { $where = 'WHERE type = :type'; if (empty($context['sandbox'])) { + $query = db_select('node', 'n'); + $query + ->condition('n.type', $type, '=') + ->addExpression('COUNT(DISTINCT(nid))'); + $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; - $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node} ' . $where, - array(':type' => $type))->fetchField(); + $context['sandbox']['max'] = $query->execute()->fetchField(); } - $limit = 5; - $result = db_query_range('SELECT node.nid FROM {node} ' . $where, 0, $limit, array(':type' => $type)); + + $limit = 5; + $query = db_select('node', 'n'); + $query + ->condition('n.type', $type, '=') + ->fields('n', array('nid')) + ->range(0, $limit); + $result = $query->execute(); + while ($row = $result->fetchAssoc()) { $node = node_delete($row['nid'], NULL, TRUE); $context['sandbox']['progress']++; -- cgit v1.2.3