Unverified Commit 749984b9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3152390 by munish.kumar, Deepak Goyal, daffie: Bracket-encapsulated...

Issue #3152390 by munish.kumar, Deepak Goyal, daffie: Bracket-encapsulated field names for static queries in core/tests/Drupal/KernelTests/Core/Database

(cherry picked from commit dbd93506)
parent 25e59e2f
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ public function testConcatLiterals() {
   */
  public function testConcatFields() {
    $result = $this->connection->query(
      'SELECT CONCAT(:a1, CONCAT(job, CONCAT(:a2, CONCAT(age, :a3)))) FROM {test} WHERE age = :age', [
      'SELECT CONCAT(:a1, CONCAT([job], CONCAT(:a2, CONCAT([age], :a3)))) FROM {test} WHERE [age] = :age', [
        ':a1' => 'The age of ',
        ':a2' => ' is ',
        ':a3' => '.',
@@ -64,7 +64,7 @@ public function testConcatWsLiterals() {
   * Tests string concatenation with separator, with field values.
   */
  public function testConcatWsFields() {
    $result = $this->connection->query("SELECT CONCAT_WS('-', :a1, name, :a2, age) FROM {test} WHERE age = :age", [
    $result = $this->connection->query("SELECT CONCAT_WS('-', :a1, [name], :a2, [age]) FROM {test} WHERE [age] = :age", [
      ':a1' => 'name',
      ':a2' => 'age',
      ':age' => 25,
@@ -160,7 +160,7 @@ public function testAllowSquareBrackets() {
    $this->assertIdentical('[square]', $result->fetchField());

    // Test that allow_square_brackets has no effect on arguments.
    $result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]']);
    $result = $this->connection->query("select [name] from {test} where [name] = :value", [':value' => '[square]']);
    $this->assertIdentical('[square]', $result->fetchField());
    $result = $this->connection->query("select name from {test} where name = :value", [':value' => '[square]'], ['allow_square_brackets' => TRUE]);
    $this->assertIdentical('[square]', $result->fetchField());
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ public function testCaseSensitiveInsert() {

    $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
    $this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
    $saved_age = $this->connection->query('SELECT age FROM {test} WHERE name = :name', [':name' => 'john'])->fetchField();
    $saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'john'])->fetchField();
    $this->assertIdentical($saved_age, '2', 'Can retrieve after inserting.');
  }

+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ class DeleteTruncateTest extends DatabaseTestBase {
   */
  public function testSubselectDelete() {
    $num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test_task}')->fetchField();
    $pid_to_delete = $this->connection->query("SELECT * FROM {test_task} WHERE task = 'sleep' ORDER BY tid")->fetchField();
    $pid_to_delete = $this->connection->query("SELECT * FROM {test_task} WHERE [task] = 'sleep' ORDER BY [tid]")->fetchField();

    $subquery = $this->connection->select('test', 't')
      ->fields('t', ['id'])
+11 −11
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ class FetchTest extends DatabaseTestBase {
   */
  public function testQueryFetchDefault() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]);
    $this->assertInstanceOf(StatementInterface::class, $result);
    foreach ($result as $record) {
      $records[] = $record;
@@ -36,7 +36,7 @@ public function testQueryFetchDefault() {
   */
  public function testQueryFetchObject() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_OBJ]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_OBJ]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsObject($record);
@@ -51,7 +51,7 @@ public function testQueryFetchObject() {
   */
  public function testQueryFetchArray() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_ASSOC]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_ASSOC]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsArray($record);
@@ -69,7 +69,7 @@ public function testQueryFetchArray() {
   */
  public function testQueryFetchClass() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => FakeRecord::class]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => FakeRecord::class]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertInstanceOf(FakeRecord::class, $record);
@@ -87,7 +87,7 @@ public function testQueryFetchClass() {
   */
  public function testQueryFetchObjectClass() {
    $records = 0;
    $query = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25]);
    $query = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]);
    while ($result = $query->fetchObject(FakeRecord::class)) {
      $records += 1;
      $this->assertInstanceOf(FakeRecord::class, $result);
@@ -104,7 +104,7 @@ public function testQueryFetchObjectClass() {
   */
  public function testQueryFetchClasstype() {
    $records = [];
    $result = $this->connection->query('SELECT classname, name, job FROM {test_classtype} WHERE age = :age', [':age' => 26], ['fetch' => \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE]);
    $result = $this->connection->query('SELECT [classname], [name], [job] FROM {test_classtype} WHERE [age] = :age', [':age' => 26], ['fetch' => \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertInstanceOf(FakeRecord::class, $record);
@@ -121,7 +121,7 @@ public function testQueryFetchClasstype() {
   */
  public function testQueryFetchNum() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_NUM]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_NUM]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsArray($record);
@@ -137,7 +137,7 @@ public function testQueryFetchNum() {
   */
  public function testQueryFetchBoth() {
    $records = [];
    $result = $this->connection->query('SELECT name FROM {test} WHERE age = :age', [':age' => 25], ['fetch' => \PDO::FETCH_BOTH]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25], ['fetch' => \PDO::FETCH_BOTH]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsArray($record);
@@ -167,11 +167,11 @@ public function testQueryFetchAllColumn() {
   * Confirms that we can fetch an entire column of a result set at once.
   */
  public function testQueryFetchCol() {
    $result = $this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25]);
    $column = $result->fetchCol();
    $this->assertCount(3, $column, 'fetchCol() returns the right number of records.');

    $result = $this->connection->query('SELECT name FROM {test} WHERE age > :age', [':age' => 25]);
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25]);
    $i = 0;
    foreach ($result as $record) {
      $this->assertIdentical($record->name, $column[$i++], 'Column matches direct access.');
@@ -182,7 +182,7 @@ public function testQueryFetchCol() {
   * Tests that rowCount() throws exception on SELECT query.
   */
  public function testRowCount() {
    $result = $this->connection->query('SELECT name FROM {test}');
    $result = $this->connection->query('SELECT [name] FROM {test}');
    try {
      $result->rowCount();
      $exception = FALSE;
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ public function testDefaultInsert() {

    $schema = drupal_get_module_schema('database_test', 'test');

    $job = $this->connection->query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField();
    $job = $this->connection->query('SELECT [job] FROM {test} WHERE [id] = :id', [':id' => $id])->fetchField();
    $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
  }

@@ -54,7 +54,7 @@ public function testDefaultInsertWithFields() {

    $schema = drupal_get_module_schema('database_test', 'test');

    $job = $this->connection->query('SELECT job FROM {test} WHERE id = :id', [':id' => $id])->fetchField();
    $job = $this->connection->query('SELECT [job] FROM {test} WHERE [id] = :id', [':id' => $id])->fetchField();
    $this->assertEqual($job, $schema['fields']['job']['default'], 'Default field value is set.');
  }

Loading