Skip to content

Commit fde9d42

Browse files
author
Pantheon Automation
committed
Update to Drupal 7.77. For more information, see https://www.drupal.org/project/drupal/releases/7.77
1 parent f3065a9 commit fde9d42

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

CHANGELOG.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Drupal 7.77, 2020-12-03
2+
-----------------------
3+
- Hotfix for schema.prefixed tables
4+
15
Drupal 7.76, 2020-12-02
26
-----------------------
37
- Support for MySQL 8

includes/bootstrap.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* The current system version.
1010
*/
11-
define('VERSION', '7.76');
11+
define('VERSION', '7.77');
1212

1313
/**
1414
* Core API compatibility.

includes/database/mysql/database.inc

+5-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,11 @@ class DatabaseConnection_mysql extends DatabaseConnection {
392392
if (substr($prefixSearch, 0, 1) === '{') {
393393
// If the prefix already contains one or more quotes remove them.
394394
// This can happen when - for example - DrupalUnitTestCase sets up a
395-
// "temporary prefixed database".
396-
$this->prefixReplace[$i] = $quote_char . str_replace($quote_char, '', $this->prefixReplace[$i]);
395+
// "temporary prefixed database". Also if there's a dot in the prefix,
396+
// wrap it in quotes to cater for schema names in prefixes.
397+
$search = array($quote_char, '.');
398+
$replace = array('', $quote_char . '.' . $quote_char);
399+
$this->prefixReplace[$i] = $quote_char . str_replace($search, $replace, $this->prefixReplace[$i]);
397400
}
398401
if (substr($prefixSearch, -1) === '}') {
399402
$this->prefixReplace[$i] .= $quote_char;

modules/simpletest/tests/database_test.test

+48-3
Original file line numberDiff line numberDiff line change
@@ -4247,9 +4247,9 @@ class ConnectionUnitTest extends DrupalUnitTestCase {
42474247
}
42484248
}
42494249

4250-
/**
4251-
* Test reserved keyword handling (introduced for MySQL 8+)
4252-
*/
4250+
/**
4251+
* Test reserved keyword handling (introduced for MySQL 8+)
4252+
*/
42534253
class DatabaseReservedKeywordTestCase extends DatabaseTestCase {
42544254
public static function getInfo() {
42554255
return array(
@@ -4373,5 +4373,50 @@ class DatabaseReservedKeywordTestCase extends DatabaseTestCase {
43734373
$num_records_after = db_query('SELECT COUNT(*) FROM {virtual}')->fetchField();
43744374
$this->assertIdentical($num_records_before, $num_records_after, 'Successful merge query on a table with a name and column which are reserved words.');
43754375
}
4376+
}
4377+
4378+
/**
4379+
* Test table prefix handling.
4380+
*/
4381+
class DatabaseTablePrefixTestCase extends DatabaseTestCase {
4382+
public static function getInfo() {
4383+
return array(
4384+
'name' => 'Table prefixes',
4385+
'description' => 'Test handling of table prefixes.',
4386+
'group' => 'Database',
4387+
);
4388+
}
43764389

4390+
public function testSchemaDotTablePrefixes() {
4391+
// Get a copy of the default connection options.
4392+
$db = Database::getConnection('default', 'default');
4393+
$connection_options = $db->getConnectionOptions();
4394+
4395+
if ($connection_options['driver'] === 'sqlite') {
4396+
// In SQLite simpletest's prefixed db tables exist in their own schema
4397+
// (e.g. simpletest124904.system), so we cannot test the schema.table
4398+
// prefix syntax here.
4399+
$this->assert(TRUE, 'Skipping schema.table prefixed tables test for SQLite.');
4400+
return;
4401+
}
4402+
4403+
$db_name = $connection_options['database'];
4404+
// This prefix is usually something like simpletest12345
4405+
$test_prefix = $connection_options['prefix']['default'];
4406+
4407+
// Set up a new connection with table prefixes in the form "schema.table"
4408+
$prefixed = $connection_options;
4409+
$prefixed['prefix'] = array(
4410+
'default' => $test_prefix,
4411+
'users' => $db_name . '.' . $test_prefix,
4412+
'role' => $db_name . '.' . $test_prefix,
4413+
);
4414+
Database::addConnectionInfo('default', 'prefixed', $prefixed);
4415+
4416+
// Test that the prefixed database connection can query the prefixed tables.
4417+
$num_users_prefixed = Database::getConnection('prefixed', 'default')->query('SELECT COUNT(1) FROM {users}')->fetchField();
4418+
$this->assertTrue((int) $num_users_prefixed > 0, 'Successfully queried the users table using a schema.table prefix');
4419+
$num_users_default = Database::getConnection('default', 'default')->query('SELECT COUNT(1) FROM {users}')->fetchField();
4420+
$this->assertEqual($num_users_default, $num_users_prefixed, 'Verified results of query using a connection with schema.table prefixed tables');
4421+
}
43774422
}

0 commit comments

Comments
 (0)