function DatabaseReservedKeywordTestCase::testTableNameQuoting

File

modules/simpletest/tests/database_test.test, line 4513

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'];
        if ($connection['driver'] === 'pgsql') {
            // database.scheme.table for PostgreSQL
            // @see https://www.postgresql.org/docs/14/ddl-schemas.html
            $database .= '.public';
        }
        // 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.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.