- Patch #491556 by Berdir: completed converting core to DBTNG. Oh my. Kudos to Berdir for this humongous effort.

merge-requests/26/head
Dries Buytaert 2009-07-28 19:18:08 +00:00
parent ff8b0618f5
commit a938e18a1b
17 changed files with 64 additions and 35 deletions

View File

@ -677,7 +677,6 @@ function drupal_uninstall_modules($module_list = array()) {
}
$paths[$index] = implode('/', $parts);
}
$placeholders = implode(', ', array_fill(0, count($paths), "'%s'"));
$result = db_select('menu_links')
->fields('menu_links')

View File

@ -217,7 +217,7 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
$pager_page_array = explode(',', $page);
// We calculate the total of pages as ceil(items / limit).
$pager_total_items[$element] = db_result(db_query($count_query, $args));
$pager_total_items[$element] = db_query($count_query, $args)->fetchField();
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
$pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
return db_query_range($query, $args, $pager_page_array[$element] * $limit, $limit);

View File

@ -174,7 +174,7 @@ function comment_multiple_delete_confirm(&$form_state) {
foreach (array_filter($edit['comments']) as $cid => $value) {
$comment = comment_load($cid);
if (is_object($comment) && is_numeric($comment->cid)) {
$subject = db_result(db_query('SELECT subject FROM {comment} WHERE cid = %d', $cid));
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
$form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '<li>', '#suffix' => check_plain($subject) . '</li>');
$comment_counter++;
}

View File

@ -42,7 +42,18 @@ function comment_uninstall() {
*/
function comment_enable() {
// Insert records into the node_comment_statistics for nodes that are missing.
db_query("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, n.uid, 0 FROM {node} n LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid WHERE c.comment_count IS NULL");
$query = db_select('node', 'n');
$query->leftJoin('node_comment_statistics', 'ncs', 'ncs.nid = n.nid');
$query->addField('n', 'changed', 'last_comment_timestamp');
$query->addField('n', 'uid', 'last_comment_uid');
$query->addField('n', 'nid');
$query->addExpression('0', 'comment_count');
$query->addExpression('NULL', 'last_comment_name');
$query->isNull('ncs.comment_count');
db_insert('node_comment_statistics')
->from($query)
->execute();
}
/**

View File

@ -210,7 +210,7 @@ class DBLogTestCase extends DrupalWebTestCase {
$this->drupalPost('user/' . $user->uid . '/cancel', array('user_cancel_method' => 'user_cancel_reassign'), t('Cancel account'));
// Count rows that have uids for the user.
$count = db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = %d', $user->uid)->fetchField();
$count = db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid))->fetchField();
$this->assertTrue($count == 0, t('DBLog contains @count records for @name', array('@count' => $count, '@name' => $user->name)));
// Count rows in watchdog that previously related to the deleted user.

View File

@ -43,8 +43,8 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$this->assertEqual($t1+1, $t2, 'Entity type ids are sequential');
$this->assertIdentical(variable_get('field_sql_storage_t1_etid', NULL), $t1, 'First entity type variable is correct');
$this->assertIdentical(variable_get('field_sql_storage_t2_etid', NULL), $t2, 'Second entity type variable is correct');
$this->assertEqual(db_result(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")), $t1, 'First entity type in database is correct');
$this->assertEqual(db_result(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")), $t2, 'Second entity type in database is correct');
$this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")->fetchField(), $t1, 'First entity type in database is correct');
$this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")->fetchField(), $t2, 'Second entity type in database is correct');
$this->assertEqual($t1, _field_sql_storage_etid('t1'), '_field_sql_storage_etid returns the same value for the first entity type');
$this->assertEqual($t2, _field_sql_storage_etid('t2'), '_field_sql_storage_etid returns the same value for the second entity type');
}
@ -197,31 +197,46 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
// Insert: Field is missing
field_attach_insert($entity_type, $entity);
$count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
$count = db_select($this->table)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 0, 'Missing field results in no inserts');
// Insert: Field is NULL
$entity->{$this->field_name} = NULL;
field_attach_insert($entity_type, $entity);
$count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
$count = db_select($this->table)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 0, 'NULL field results in no inserts');
// Add some real data
$entity->{$this->field_name} = array(0 => array('value' => 1));
field_attach_insert($entity_type, $entity);
$count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
$count = db_select($this->table)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 1, 'Field data saved');
// Update: Field is missing. Data should survive.
unset($entity->{$this->field_name});
field_attach_update($entity_type, $entity);
$count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
$count = db_select($this->table)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 1, 'Missing field leaves data in table');
// Update: Field is NULL. Data should be wiped.
$entity->{$this->field_name} = NULL;
field_attach_update($entity_type, $entity);
$count = db_result(db_query("SELECT COUNT(*) FROM {{$this->table}}"));
$count = db_select($this->table)
->countQuery()
->execute()
->fetchField();
$this->assertEqual($count, 0, 'NULL field leaves no data in table');
}
}

View File

@ -762,8 +762,12 @@ function hook_form($node, $form_state) {
* For a detailed usage example, see node_example.module.
*/
function hook_insert($node) {
db_query("INSERT INTO {mytable} (nid, extra)
VALUES (%d, '%s')", $node->nid, $node->extra);
db_insert('mytable')
->fields(array(
'nid' => $node->nid,
'extra' => $node->extra,
))
->execute();
}
/**
@ -804,8 +808,10 @@ function hook_load($nodes) {
* For a detailed usage example, see node_example.module.
*/
function hook_update($node) {
db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d",
$node->extra, $node->nid);
db_update('mytable')
->fields(array('extra' => $node->extra))
->condition('nid', $node->nid)
->execute();
}
/**

View File

@ -2699,7 +2699,7 @@ function _node_access_rebuild_batch_operation(&$context) {
// Process the next 20 nodes.
$limit = 20;
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit)->fetchCol();
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", array(':nid' => $context['sandbox']['current_node']), 0, $limit)->fetchCol();
$nodes = node_load_multiple($nids, array(), TRUE);
foreach ($nodes as $node) {
// To preserve database integrity, only acquire grants if the node
@ -3148,7 +3148,7 @@ function node_requirements($phase) {
// Only show rebuild button if there are either 0, or 2 or more, rows
// in the {node_access} table, or if there are modules that
// implement hook_node_grants().
$grant_count = db_result(db_query('SELECT COUNT(*) FROM {node_access}'));
$grant_count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchField();
if ($grant_count != 1 || count(module_implements('node_grants')) > 0) {
$value = format_plural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
} else {

View File

@ -681,7 +681,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
$this->assertTrue(node_load($node1->nid), t('Article node created.'));
// Check to see if grants added by node_test_node_access_records made it in.
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node1->nid)->fetchAll();
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll();
$this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
$this->assertEqual($records[0]->realm, 'test_article_realm', t('Grant with article_realm acquired for node without alteration.'));
$this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@ -691,7 +691,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
$this->assertTrue(node_load($node1->nid), t('Unpromoted page node created.'));
// Check to see if grants added by node_test_node_access_records made it in.
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node2->nid)->fetchAll();
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll();
$this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
$this->assertEqual($records[0]->realm, 'test_page_realm', t('Grant with page_realm acquired for node without alteration.'));
$this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@ -712,7 +712,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
// Check to see if grant added by node_test_node_access_records was altered
// by node_test_node_access_records_alter.
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = %d', $node4->nid)->fetchAll();
$records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node4->nid))->fetchAll();
$this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
$this->assertEqual($records[0]->realm, 'test_alter_realm', t('Altered grant with alter_realm acquired for node.'));
$this->assertEqual($records[0]->gid, 2, t('Altered grant with gid = 2 acquired for node.'));
@ -759,7 +759,7 @@ class NodeSaveTestCase extends DrupalWebTestCase {
*/
function testImport() {
// Node ID must be a number that is not in the database.
$max_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
$max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
$test_nid = $max_nid + mt_rand(1000, 1000000);
$title = $this->randomName(8);
$node = array(

View File

@ -341,7 +341,7 @@ function profile_view_profile(&$user) {
// Show private fields to administrators and people viewing their own account.
if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> %d ORDER BY category, weight', PROFILE_HIDDEN);
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN));
}
else {
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :private AND visibility <> :hidden ORDER BY category, weight', array(':private' => PROFILE_PRIVATE, ':hidden' => PROFILE_HIDDEN));

View File

@ -37,7 +37,7 @@ class ProfileTestCase extends DrupalWebTestCase {
$edit['explanation'] = $this->randomName(50);
$this->drupalPost('admin/user/profile/add/' . $type, $edit, t('Save field'));
$fid = db_result(db_query("SELECT fid FROM {profile_field} WHERE title = '%s'", $title));
$fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
$this->assertTrue($fid, t('New Profile field has been entered in the database'));
// Check that the new field is appearing on the user edit form.

View File

@ -221,10 +221,10 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
* The test ID to read log file for.
*/
function simpletest_log_read($test_id) {
$last_prefix = db_result(db_query('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id)));
$last_prefix = db_query('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id))->fetchField();
$last_prefix = substr($last_prefix, 10);
$test_class = db_result(db_query('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id', array(':test_id' => $test_id)));
$test_class = db_query('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id', array(':test_id' => $test_id))->fetchField();
$log = file_directory_path() . "/simpletest/$last_prefix/error.log";
if (file_exists($log)) {
foreach (file($log) as $line) {

View File

@ -394,5 +394,5 @@ function statistics_ranking() {
* Implement hook_update_index().
*/
function statistics_update_index() {
variable_set('node_cron_views_scale', 1.0 / max(1, db_result(db_query('SELECT MAX(totalcount) FROM {node_counter}'))));
variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
}

View File

@ -384,13 +384,11 @@ function system_install() {
// Built-in roles.
$rid_anonymous = db_insert('role')
->fields(array('name'))
->values(array('name' => 'anonymous user'))
->fields(array('name' => 'anonymous user'))
->execute();
$rid_authenticated = db_insert('role')
->fields(array('name'))
->values(array('name' => 'authenticated user'))
->fields(array('name' => 'authenticated user'))
->execute();
// Sanity check to ensure the anonymous and authenticated role IDs are the
@ -1555,7 +1553,7 @@ function system_update_7003() {
':status' => 0,
':type' => $type,
));
while ($blocked = db_fetch_object($result)) {
foreach ($result as $blocked) {
if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
$ret[] = update_sql("INSERT INTO {blocked_ips} (ip) VALUES ('$blocked->mask')");
}

View File

@ -60,7 +60,7 @@ class TriggerContentTestCase extends DrupalWebTestCase {
// Test 3: The action should be able to be unassigned from a trigger.
$this->drupalPost('admin/structure/trigger/unassign/node/presave/' . $hash, array(), t('Unassign'));
$this->assertRaw(t('Action %action has been unassigned.', array('%action' => ucfirst($info['name']))), t('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name'])));
$assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('" . implode("','", $content_actions) . "')"));
$assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField();
$this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
}
}

View File

@ -68,7 +68,7 @@ class UploadTestCase extends DrupalWebTestCase {
$this->assertTrue(strpos($teaser, format_plural(2, '1 attachment', '@count attachments')), 'Attachments link found on node teaser.');
// Fetch db record and use fid to rename and delete file.
$upload = db_fetch_object(db_query('SELECT fid, description FROM {upload} WHERE nid = %d', array($node->nid)));
$upload = db_query('SELECT fid, description FROM {upload} WHERE nid = :nid', array(':nid' => $node->nid))->fetchObject();
if ($upload) {
// Rename file.
$edit = array();

View File

@ -1044,7 +1044,7 @@ class UserSaveTestCase extends DrupalWebTestCase {
*/
function testUserImport() {
// User ID must be a number that is not in the database.
$max_uid = db_result(db_query('SELECT MAX(uid) FROM {users}'));
$max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
$test_uid = $max_uid + mt_rand(1000, 1000000);
$test_name = $this->randomName();