You are here

public function SqlsrvTest::testDuplicatePlaceholders in Drupal driver for SQL Server and SQL Azure 8.2

Same name and namespace in other branches
  1. 4.2.x tests/src/Kernel/SqlsrvTest.php \Drupal\Tests\sqlsrv\Kernel\SqlsrvTest::testDuplicatePlaceholders()
  2. 3.0.x tests/src/Kernel/SqlsrvTest.php \Drupal\Tests\sqlsrv\Kernel\SqlsrvTest::testDuplicatePlaceholders()
  3. 3.1.x tests/src/Kernel/SqlsrvTest.php \Drupal\Tests\sqlsrv\Kernel\SqlsrvTest::testDuplicatePlaceholders()
  4. 4.0.x tests/src/Kernel/SqlsrvTest.php \Drupal\Tests\sqlsrv\Kernel\SqlsrvTest::testDuplicatePlaceholders()
  5. 4.1.x tests/src/Kernel/SqlsrvTest.php \Drupal\Tests\sqlsrv\Kernel\SqlsrvTest::testDuplicatePlaceholders()

Test duplicate placeholders in queries.

Although per official documentation you cannot send duplicate placeholders in same query, this works in mySQL and is present in some queries, even in core, which have not gotten enough attention.

File

tests/src/Kernel/SqlsrvTest.php, line 49

Class

SqlsrvTest
Test behavior that is unique to the Sql Server Driver.

Namespace

Drupal\Tests\sqlsrv\Kernel

Code

public function testDuplicatePlaceholders() {
  $query = $this->connection
    ->select('test_task', 't');
  $query
    ->addExpression('COUNT(task)', 'num');
  $query
    ->where('t.task IN (:data0, :data0)', [
    ':data0' => 'sleep',
  ]);
  $result = NULL;

  // If > 2100 we can get SQL Exception! The driver must handle that.
  try {
    $result = $query
      ->execute()
      ->fetchField();
  } catch (\Exception $err) {
  }
  $this
    ->assertEqual($result, 2, 'Returned the correct number of total rows.');
}