Skip to content

Commit

Permalink
Update to Drupal 7.77. For more information, see https://www.drupal.o…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantheon Automation committed Dec 3, 2020
1 parent f3065a9 commit fde9d42
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Drupal 7.77, 2020-12-03
-----------------------
- Hotfix for schema.prefixed tables

Drupal 7.76, 2020-12-02
-----------------------
- Support for MySQL 8
Expand Down
2 changes: 1 addition & 1 deletion includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* The current system version.
*/
define('VERSION', '7.76');
define('VERSION', '7.77');

/**
* Core API compatibility.
Expand Down
7 changes: 5 additions & 2 deletions includes/database/mysql/database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,11 @@ class DatabaseConnection_mysql extends DatabaseConnection {
if (substr($prefixSearch, 0, 1) === '{') {
// If the prefix already contains one or more quotes remove them.
// This can happen when - for example - DrupalUnitTestCase sets up a
// "temporary prefixed database".
$this->prefixReplace[$i] = $quote_char . str_replace($quote_char, '', $this->prefixReplace[$i]);
// "temporary prefixed database". Also if there's a dot in the prefix,
// wrap it in quotes to cater for schema names in prefixes.
$search = array($quote_char, '.');
$replace = array('', $quote_char . '.' . $quote_char);
$this->prefixReplace[$i] = $quote_char . str_replace($search, $replace, $this->prefixReplace[$i]);
}
if (substr($prefixSearch, -1) === '}') {
$this->prefixReplace[$i] .= $quote_char;
Expand Down
51 changes: 48 additions & 3 deletions modules/simpletest/tests/database_test.test
Original file line number Diff line number Diff line change
Expand Up @@ -4247,9 +4247,9 @@ class ConnectionUnitTest extends DrupalUnitTestCase {
}
}

/**
* Test reserved keyword handling (introduced for MySQL 8+)
*/
/**
* Test reserved keyword handling (introduced for MySQL 8+)
*/
class DatabaseReservedKeywordTestCase extends DatabaseTestCase {
public static function getInfo() {
return array(
Expand Down Expand Up @@ -4373,5 +4373,50 @@ class DatabaseReservedKeywordTestCase extends DatabaseTestCase {
$num_records_after = db_query('SELECT COUNT(*) FROM {virtual}')->fetchField();
$this->assertIdentical($num_records_before, $num_records_after, 'Successful merge query on a table with a name and column which are reserved words.');
}
}

/**
* Test table prefix handling.
*/
class DatabaseTablePrefixTestCase extends DatabaseTestCase {
public static function getInfo() {
return array(
'name' => 'Table prefixes',
'description' => 'Test handling of table prefixes.',
'group' => 'Database',
);
}

public function testSchemaDotTablePrefixes() {
// Get a copy of the default connection options.
$db = Database::getConnection('default', 'default');
$connection_options = $db->getConnectionOptions();

if ($connection_options['driver'] === 'sqlite') {
// In SQLite simpletest's prefixed db tables exist in their own schema
// (e.g. simpletest124904.system), so we cannot test the schema.table
// prefix syntax here.
$this->assert(TRUE, 'Skipping schema.table prefixed tables test for SQLite.');
return;
}

$db_name = $connection_options['database'];
// This prefix is usually something like simpletest12345
$test_prefix = $connection_options['prefix']['default'];

// Set up a new connection with table prefixes in the form "schema.table"
$prefixed = $connection_options;
$prefixed['prefix'] = array(
'default' => $test_prefix,
'users' => $db_name . '.' . $test_prefix,
'role' => $db_name . '.' . $test_prefix,
);
Database::addConnectionInfo('default', 'prefixed', $prefixed);

// Test that the prefixed database connection can query the prefixed tables.
$num_users_prefixed = Database::getConnection('prefixed', 'default')->query('SELECT COUNT(1) FROM {users}')->fetchField();
$this->assertTrue((int) $num_users_prefixed > 0, 'Successfully queried the users table using a schema.table prefix');
$num_users_default = Database::getConnection('default', 'default')->query('SELECT COUNT(1) FROM {users}')->fetchField();
$this->assertEqual($num_users_default, $num_users_prefixed, 'Verified results of query using a connection with schema.table prefixed tables');
}
}

0 comments on commit fde9d42

Please sign in to comment.