You are here

public function SqlServerSelectTest::testDuplicatePlaceholders in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 7.3 tests/sqlsrv.select.test \SqlServerSelectTest::testDuplicatePlaceholders()
  2. 7.2 tests/sqlsrv.select.test \SqlServerSelectTest::testDuplicatePlaceholders()

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, wich have not gotten enough attention.

File

tests/sqlsrv.select.test, line 86
Support tests for SQL Server.

Class

SqlServerSelectTest
@file Support tests for SQL Server.

Code

public function testDuplicatePlaceholders() {
  $query = db_select('test_task', 't');
  $query
    ->addExpression('COUNT(task)', 'num');
  $query
    ->where('t.task IN (:data0, :data0)', array(
    ':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.');
}