/**
  * Confirms that temporary tables work and are limited to one request.
  */
 function testTemporaryQuery()
 {
     $this->drupalGet('database_test/db_query_temporary');
     $data = json_decode($this->drupalGetContent());
     if ($data) {
         $this->assertEqual($this->countTableRows('test'), $data->row_count, 'The temporary table contains the correct amount of rows.');
         $this->assertFalse(db_table_exists($data->table_name), 'The temporary table is, indeed, temporary.');
     } else {
         $this->fail('The creation of the temporary table failed.');
     }
     // Now try to run two db_query_temporary() in the same request.
     $table_name_test = db_query_temporary('SELECT name FROM {test}', array());
     $table_name_task = db_query_temporary('SELECT pid FROM {test_task}', array());
     $this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'A temporary table was created successfully in this request.');
     $this->assertEqual($this->countTableRows($table_name_task), $this->countTableRows('test_task'), 'A second temporary table was created successfully in this request.');
     // Check that leading whitespace and comments do not cause problems
     // in the modified query.
     $sql = "\n      -- Let's select some rows into a temporary table\n      SELECT name FROM {test}\n    ";
     $table_name_test = db_query_temporary($sql, array());
     $this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'Leading white space and comments do not interfere with temporary table creation.');
 }
 /**
  * Runs db_query_temporary() and outputs the table name and its number of rows.
  *
  * We need to test that the table created is temporary, so we run it here, in a
  * separate menu callback request; After this request is done, the temporary
  * table should automatically dropped.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function dbQueryTemporary()
 {
     $table_name = db_query_temporary('SELECT age FROM {test}', array());
     return new JsonResponse(array('table_name' => $table_name, 'row_count' => db_select($table_name)->countQuery()->execute()->fetchField()));
 }