1.20.x database_test.test public DatabaseReservedKeywordTestCase::testTableNameQuoting()

File

modules/simpletest/tests/database_test.test, line 4131
Database tests.

Class

DatabaseReservedKeywordTestCase
Test reserved keyword handling (introduced for MySQL 8+)

Code

public function testTableNameQuoting() {
  // Test db_query with {table} pattern.
  $record = db_query('SELECT * FROM {system} LIMIT 1')->fetchObject();
  $this->assertTrue(isset($record->filename), 'Successfully queried the {system} table.');

  $connection = Database::getConnection()->getConnectionOptions();
  if ($connection['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}
    // syntax here as the table name will have the schema name prepended to it
    // when prefixes are processed.
    $this->assert(TRUE, 'Skipping schema.{system} test for SQLite.');
  }
  else {
    $database = $connection['database'];
    // Test db_query with schema.{table} pattern
    db_query('SELECT * FROM ' . $database . '.{system} LIMIT 1')->fetchObject();
    $this->assertTrue(isset($record->filename), 'Successfully queried the schema.{system} table.');
  }
}