Skip to content
Snippets Groups Projects
Commit 8a128c64 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #851748 by Stevel: weird logic in SelectQuery::addField().

parent b8a7b8a8
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -1125,14 +1125,14 @@ public function addField($table_alias, $field, $alias = NULL) {
}
// If that's already in use, try the table name and field name.
if (!empty($this->tables[$alias])) {
if (!empty($this->fields[$alias])) {
$alias = $table_alias . '_' . $field;
}
// If that is already used, just add a counter until we find an unused alias.
$alias_candidate = $alias;
$count = 2;
while (!empty($this->tables[$alias_candidate])) {
while (!empty($this->fields[$alias_candidate])) {
$alias_candidate = $alias . '_' . $count++;
}
$alias = $alias_candidate;
......
......@@ -1543,6 +1543,16 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
sort($sorted_ids_second_set);
$this->assertEqual($sorted_ids_second_set, $sorted_ids, t('After sorting the second random list, the result matches the sorted version of the first random list.'));
}
/**
* Test that aliases are renamed when duplicates.
*/
function testSelectDuplicateAlias() {
$query = db_select('test', 't');
$alias1 = $query->addField('t', 'name', 'the_alias');
$alias2 = $query->addField('t', 'age', 'the_alias');
$this->assertNotIdentical($alias1, $alias2, 'Duplicate aliases are renamed.');
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment