You are here

public function SqlServerSelectTest::testTemporaryTables in Drupal driver for SQL Server and SQL Azure 7.2

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

Test the temporary table functionality.

File

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

Class

SqlServerSelectTest
@file Support tests for SQL Server.

Code

public function testTemporaryTables() {
  $query = db_select('test_task', 't');
  $query
    ->fields('t');
  $table = db_query_temporary((string) $query);

  // First assert that the table exists
  $this
    ->assertTRUE(db_table_exists($table), 'The temporary table exists.');
  $query2 = db_select($table, 't');
  $query2
    ->fields('t');

  // Now make sure that both tables are exactly the same.
  $data1 = $query
    ->execute()
    ->fetchAllAssoc('tid');
  $data2 = $query2
    ->execute()
    ->fetchAllAssoc('tid');

  // User ID's are negative, so this should return 0 matches.
  $this
    ->assertEqual(count($data1), count($data2), 'Temporary table has the same number of rows.');

  // $this->assertEqual(count($data1[0]), count($data2[0]), 'Temporary table has the same number of columns.');
  // Drop the table.
  db_drop_table($table);

  // The table should not exist now.
  $this
    ->assertFALSE(db_table_exists($table), 'The temporary table does not exists.');
}