queryTemporary example


class TemporaryQueryTest extends TemporaryQueryTestBase {

  /** * Confirms that temporary tables work. */
  public function testTemporaryQuery() {
    parent::testTemporaryQuery();

    $connection = $this->getConnection();

    $table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);

    // Assert that the table is indeed a temporary one.     $temporary_table_info = $connection->query("SELECT * FROM pg_class WHERE relname LIKE '%$table_name_test%'")->fetch();
    $this->assertEquals("t", $temporary_table_info->relpersistence);

    // Assert that both have the same field names.     $normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();
    $temp_table_name = $connection->queryTemporary('SELECT * FROM {test}');
    $temp_table_fields = $connection->query("SELECT * FROM {" . $temp_table_name . "}")->fetch();

    $normal_table_fields = array_keys(get_object_vars($normal_table_fields));
    

class TemporaryQueryTest extends TemporaryQueryTestBase {

  /** * Confirms that temporary tables work. */
  public function testTemporaryQuery() {
    parent::testTemporaryQuery();

    $connection = $this->getConnection();

    $table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);

    // Assert that the table is indeed a temporary one.     $this->stringContains("temp.", $table_name_test);

    // Assert that both have the same field names.     $normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();
    $temp_table_name = $connection->queryTemporary('SELECT * FROM {test}');
    $temp_table_fields = $connection->query("SELECT * FROM $temp_table_name")->fetch();

    $normal_table_fields = array_keys(get_object_vars($normal_table_fields));
    $temp_table_fields = array_keys(get_object_vars($temp_table_fields));

    
public function countTableRows($table_name) {
    return Database::getConnection()->select($table_name)->countQuery()->execute()->fetchField();
  }

  /** * Confirms that temporary tables work. */
  public function testTemporaryQuery() {
    $connection = $this->getConnection();

    // Now try to run two temporary queries in the same request.     $table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);
    $table_name_task = $connection->queryTemporary('SELECT [pid] FROM {test_task}', []);

    $this->assertEquals($this->countTableRows('test')$this->countTableRows($table_name_test), 'A temporary table was created successfully in this request.');
    $this->assertEquals($this->countTableRows('test_task')$this->countTableRows($table_name_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 = " -- Let's select some rows into a temporary table SELECT [name] FROM {test} ";
    

class TemporaryQueryTest extends TemporaryQueryTestBase {

  /** * Confirms that temporary tables work. */
  public function testTemporaryQuery() {
    parent::testTemporaryQuery();

    $connection = $this->getConnection();

    $table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);

    // Assert that the table is indeed a temporary one.     $temporary_table_info = $connection->query("SHOW CREATE TABLE {" . $table_name_test . "}")->fetchAssoc();
    $this->stringContains($temporary_table_info["Create Table"], "CREATE TEMPORARY TABLE");

    // Assert that both have the same field names.     $normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();
    $temp_table_name = $connection->queryTemporary('SELECT * FROM {test}');
    $temp_table_fields = $connection->query("SELECT * FROM {" . $temp_table_name . "}")->fetch();

    $normal_table_fields = array_keys(get_object_vars($normal_table_fields));
    
Home | Imprint | This part of the site doesn't use cookies.