Commit 4a1d887a authored by catch's avatar catch
Browse files

Issue #3362726 by alexpott, oily, jrb, neclimdul: READ COMMITTED requirement...

Issue #3362726 by alexpott, oily, jrb, neclimdul: READ COMMITTED requirement check doesn't account for database views

(cherry picked from commit d5002caa)
parent 0fff4d79
Loading
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -25394,12 +25394,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/mysql/src/Driver/Database/mysql/Schema.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql\\\\Schema\\:\\:getComment\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/mysql/src/Driver/Database/mysql/Schema.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\mysql\\\\Driver\\\\Database\\\\mysql\\\\Schema\\:\\:processField\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -27236,12 +27230,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/pgsql/src/Driver/Database/pgsql/Schema.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\pgsql\\\\Driver\\\\Database\\\\pgsql\\\\Schema\\:\\:getComment\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/pgsql/src/Driver/Database/pgsql/Schema.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\pgsql\\\\Driver\\\\Database\\\\pgsql\\\\Schema\\:\\:processField\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+2 −0
Original line number Diff line number Diff line
@@ -194,6 +194,7 @@ protected function buildTableNameCondition($table_name, $operator = '=', $add_pr
   */
  public function tableExists($table, bool $add_prefix = TRUE) {
    $condition = $this->buildTableNameCondition($table, '=', $add_prefix);
    $condition->condition('table_type', 'BASE TABLE');
    $condition->compile($this->connection, $this);
    // Normally, we would heartily discourage the use of string
    // concatenation for conditionals like this however, we
@@ -221,6 +222,7 @@ public function findTables($table_expression) {
    // Load all the tables up front in order to take into account per-table
    // prefixes. The actual matching is done at the bottom of the method.
    $condition = $this->buildTableNameCondition('%', 'LIKE');
    $condition->condition('table_type', 'BASE TABLE');
    $condition->compile($this->connection, $this);

    $prefix = $this->connection->getPrefix();
+16 −4
Original line number Diff line number Diff line
@@ -671,21 +671,33 @@ public function prepareComment($comment, $length = NULL) {
  }

  /**
   * Retrieve a table or column comment.
   * Retrieves a table or column comment.
   *
   * @param string $table
   *   The table name.
   * @param string|null $column
   *   (optional) The column name.
   *
   * @return string|false
   *   The table or column comment. FALSE if the table or column does not exist.
   */
  public function getComment($table, $column = NULL) {
    $condition = $this->buildTableNameCondition($table);
    if (isset($column)) {
      if (!$this->tableExists($table)) {
        // If the table is a view it will be present in
        // information_schema.columns so we need to check if the table exists.
        return FALSE;
      }
      $condition->condition('column_name', $column);
      $condition->compile($this->connection, $this);
      // Don't use {} around information_schema.columns table.
      return $this->connection->query("SELECT column_comment AS column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField();
    }
    $condition->condition('table_type', 'BASE TABLE');
    $condition->compile($this->connection, $this);
    // Don't use {} around information_schema.tables table.
    $comment = $this->connection->query("SELECT table_comment AS table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
    // Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379
    return preg_replace('/; InnoDB free:.*$/', '', $comment);
    return $this->connection->query("SELECT table_comment AS table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class SchemaTest extends DriverSpecificSchemaTestBase {
  /**
   * {@inheritdoc}
   */
  public function checkSchemaComment(string $description, string $table, ?string $column = NULL): void {
  public function checkSchemaComment(string|false $description, string $table, ?string $column = NULL): void {
    $comment = $this->schema->getComment($table, $column);
    $max_length = $column ? 255 : 60;
    $description = Unicode::truncate($description, $max_length, TRUE, TRUE);
+11 −3
Original line number Diff line number Diff line
@@ -1056,16 +1056,24 @@ protected function _createKeys($table, $new_keys) {
  }

  /**
   * Retrieve a table or column comment.
   * Retrieves a table or column comment.
   *
   * @param string $table
   *   The table name.
   * @param string|null $column
   *   (optional) The column name.
   *
   * @return string|false
   *   The table or column comment. FALSE if the table or column does not exist.
   */
  public function getComment($table, $column = NULL) {
    $info = $this->getPrefixInfo($table);
    // Don't use {} around pg_class, pg_attribute tables.
    if (isset($column)) {
      return $this->connection->query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', [$info['table'], $column])->fetchField();
      return $this->connection->query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', [$info['table'], $column])->fetchField() ?? FALSE;
    }
    else {
      return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', ['pg_class', $info['table']])->fetchField();
      return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', ['pg_class', $info['table']])->fetchField() ?? FALSE;
    }
  }

Loading