prefixTables example

$this->connection->query("ALTER TABLE {" . $table . "} AUTO_INCREMENT = " . ($max + 1));
    }
  }

  /** * {@inheritdoc} */
  public function prepareComment($comment$length = NULL) {
    // Truncate comment to maximum comment length.     if (isset($length)) {
      // Add table prefix before truncating.       $comment = Unicode::truncate($this->connection->prefixTables($comment)$length, TRUE, TRUE);
    }
    // Remove semicolons to avoid triggering multi-statement check.     $comment = strtr($comment[';' => '.']);
    return $this->connection->quote($comment);
  }

  /** * Retrieve a table or column comment. */
  public function getComment($table$column = NULL) {
    $condition = $this->buildTableNameCondition($table);
    

  protected function getTableCollation(Connection $connection$table, &$definition) {
    // Remove identifier quotes from the table name. See     // \Drupal\mysql\Driver\Database\mysql\Connection::$identifierQuotes.     $table = trim($connection->prefixTables('{' . $table . '}'), '"');
    $query = $connection->query("SHOW TABLE STATUS WHERE NAME = :table_name", [':table_name' => $table]);
    $data = $query->fetchAssoc();

    // Map the collation to a character set. For example, 'utf8mb4_general_ci'     // (MySQL 5) or 'utf8mb4_0900_ai_ci' (MySQL 8) will be mapped to 'utf8mb4'.     [$charset] = explode('_', $data['Collation'], 2);

    // Set `mysql_character_set`. This will be ignored by other backends.     $definition['mysql_character_set'] = $charset;
  }

  

  }

  /** * Exercise the prefixTables() method. * * @dataProvider providerTestPrefixTables */
  public function testPrefixTables($expected$prefix_info$query, array $quote_identifier = ['"', '"']) {
    $mock_pdo = $this->createMock('Drupal\Tests\Core\Database\Stub\StubPDO');
    $connection = new StubConnection($mock_pdo['prefix' => $prefix_info]$quote_identifier);
    $this->assertEquals($expected$connection->prefixTables($query));
  }

  /** * Data provider for testGetDriverClass(). * * @return array * Array of arrays with the following elements: * - Expected namespaced class name. * - Namespace. * - Class name without namespace. */
  
->compile()
      ->addSort()
      ->finish();

    // Quote arguments so query is able to be run.     $quoted = [];
    foreach ($clone->sqlQuery->getArguments() as $key => $value) {
      $quoted[$key] = is_null($value) ? 'NULL' : $this->connection->quote($value);
    }

    // Replace table name brackets.     $sql = $clone->connection->prefixTables((string) $clone->sqlQuery);
    $sql = $clone->connection->quoteIdentifiers($sql);

    return strtr($sql$quoted);
  }

}

  protected static function isStatementRelatedToTable(string $statement, string $tableName): bool {
    $realTableIdentifier = Database::getConnection()->prefixTables('{' . $tableName . '}');
    $pattern = '/.*(INTO|FROM|UPDATE)( |\n)' . preg_quote($realTableIdentifier, '/') . '/';
    return preg_match($pattern$statement) === 1 ? TRUE : FALSE;
  }

}

  public function queryTableInformation($table) {
    // Generate a key to reference this table's information on.     $prefixed_table = $this->connection->getPrefix() . $table;
    $key = $this->connection->prefixTables('{' . $table . '}');

    // Take into account that temporary tables are stored in a different schema.     // \Drupal\Core\Database\Connection::generateTemporaryTableName() sets the     // 'db_temporary_' prefix to all temporary tables.     if (str_contains($table, 'db_temporary_')) {
      $key = $quoted_key = $this->getTempNamespaceName() . '.' . $prefixed_table;
    }
    else {
      $key = $this->defaultSchema . '.' . $prefixed_table;
      $quoted_key = '"' . $this->defaultSchema . '"."' . $prefixed_table . '"';
    }

    
    // positives unless delimiter is allowed.     $trim_chars = " \xA0\t\n\r\0\x0B";
    if (empty($options['allow_delimiter_in_query'])) {
      $trim_chars .= ';';
    }
    $query = rtrim($query$trim_chars);
    if (str_contains($query, ';') && empty($options['allow_delimiter_in_query'])) {
      throw new \InvalidArgumentException('; is not supported in SQL strings. Use only one statement at a time.');
    }

    // Resolve {tables} and [identifiers] to the platform specific syntax.     $query = $this->prefixTables($query);
    if (!($options['allow_square_brackets'] ?? FALSE)) {
      $query = $this->quoteIdentifiers($query);
    }

    return $query;
  }

  /** * Tells this connection object what its target value is. * * This is needed for logging and auditing. It's sloppy to do in the * constructor because the constructor for child classes has a different * signature. We therefore also ensure that this function is only ever * called once. * * @param string $target * (optional) The target this connection is for. */
$expected->addField("base_table", "revision_id", "revision_id");
    $expected->addField("base_table", "id", "id");
    $expected->join("entity_test_mulrev__$figures", "entity_test_mulrev__$figures", '[entity_test_mulrev__' . $figures . '].[entity_id] = [base_table].[id]');
    $expected->join("entity_test_mulrev__$figures", "entity_test_mulrev__{$figures}_2", '[entity_test_mulrev__' . $figures . '_2].[entity_id] = [base_table].[id]');
    $expected->addJoin("LEFT", "entity_test_mulrev__$figures", "entity_test_mulrev__{$figures}_3", '[entity_test_mulrev__' . $figures . '_3].[entity_id] = [base_table].[id]');
    $expected->condition("entity_test_mulrev__$figures.{$figures}_color", ["blue"], "IN");
    $expected->condition("entity_test_mulrev__{$figures}_2.{$figures}_color", ["red"], "IN");
    $expected->isNull("entity_test_mulrev__{$figures}_3.{$figures}_color");
    $expected->orderBy("base_table.id");

    // Apply table prefixes and quote identifiers for the expected SQL.     $expected_string = $connection->prefixTables((string) $expected);
    $expected_string = $connection->quoteIdentifiers($expected_string);
    // Resolve placeholders in the expected SQL to their values.     $quoted = [];
    foreach ($expected->getArguments() as $key => $value) {
      $quoted[$key] = $connection->quote($value);
    }
    $expected_string = strtr($expected_string$quoted);

    $this->assertSame($expected_string(string) $query);
  }

  
Home | Imprint | This part of the site doesn't use cookies.