Skip to content

Commit c27b571

Browse files
committed
Add tests for UNION and UNION ALL
1 parent 8b27c85 commit c27b571

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

tests/WP_SQLite_Driver_Tests.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,4 +3683,59 @@ public function testSelectNonExistentColumn(): void {
36833683
'no such column: non_existent_column'
36843684
);
36853685
}
3686+
3687+
public function testUnion(): void {
3688+
$this->assertQuery( 'CREATE TABLE t (id INT, name VARCHAR(20))' );
3689+
$this->assertQuery( "INSERT INTO t (id, name) VALUES (1, 'a')" );
3690+
$this->assertQuery( "INSERT INTO t (id, name) VALUES (2, 'b')" );
3691+
3692+
$this->assertQuery(
3693+
'SELECT name FROM t WHERE id = 1 UNION SELECT name FROM t WHERE id = 2'
3694+
);
3695+
$this->assertEquals(
3696+
array(
3697+
(object) array( 'name' => 'a' ),
3698+
(object) array( 'name' => 'b' ),
3699+
),
3700+
$this->engine->get_query_results()
3701+
);
3702+
3703+
$this->assertQuery(
3704+
'SELECT name FROM t WHERE id = 1 UNION SELECT name FROM t WHERE id = 1'
3705+
);
3706+
$this->assertEquals(
3707+
array(
3708+
(object) array( 'name' => 'a' ),
3709+
),
3710+
$this->engine->get_query_results()
3711+
);
3712+
}
3713+
3714+
public function testUnionAll(): void {
3715+
$this->assertQuery( 'CREATE TABLE t (id INT, name VARCHAR(20))' );
3716+
$this->assertQuery( "INSERT INTO t (id, name) VALUES (1, 'a')" );
3717+
$this->assertQuery( "INSERT INTO t (id, name) VALUES (2, 'b')" );
3718+
3719+
$this->assertQuery(
3720+
'SELECT name FROM t WHERE id = 1 UNION SELECT name FROM t WHERE id = 2'
3721+
);
3722+
$this->assertEquals(
3723+
array(
3724+
(object) array( 'name' => 'a' ),
3725+
(object) array( 'name' => 'b' ),
3726+
),
3727+
$this->engine->get_query_results()
3728+
);
3729+
3730+
$this->assertQuery(
3731+
'SELECT name FROM t WHERE id = 1 UNION ALL SELECT name FROM t WHERE id = 1'
3732+
);
3733+
$this->assertEquals(
3734+
array(
3735+
(object) array( 'name' => 'a' ),
3736+
(object) array( 'name' => 'a' ),
3737+
),
3738+
$this->engine->get_query_results()
3739+
);
3740+
}
36863741
}

0 commit comments

Comments
 (0)