diff --git a/core/OSQL/Joiner.class.php b/core/OSQL/Joiner.class.php index 121a89fec5..2df9c56a21 100644 --- a/core/OSQL/Joiner.class.php +++ b/core/OSQL/Joiner.class.php @@ -70,6 +70,18 @@ public function rightJoin(SQLRightJoin $join) return $this; } + + /** + * @param SQLFullOuterJoin $join + * @return Joiner + */ + public function fullOuterJoin(SQLFullOuterJoin $join) + { + $this->from[] = $join; + $this->tables[$join->getTable()] = true; + + return $this; + } public function getFirstTable() { diff --git a/core/OSQL/SQLFullOuterJoin.class.php b/core/OSQL/SQLFullOuterJoin.class.php new file mode 100644 index 0000000000..5854fe15ff --- /dev/null +++ b/core/OSQL/SQLFullOuterJoin.class.php @@ -0,0 +1,26 @@ +joiner->fullOuterJoin( + new SQLFullOuterJoin($table, $logic, $alias) + ); + + $this->aliases[$alias] = true; + + return $this; + } /** * @return SelectQuery diff --git a/doc/ChangeLog b/doc/ChangeLog index adb105ead5..c991ecbb11 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,7 +1,15 @@ 2012-04-22 Georgiy T. Kutsurua - + * core/OSQL/DBColumn.class.php: Fix DBColumn +2012-04-20 Timofey A. Anisimov + + * test/main/OsqlSelectTest.class.php, + core/SQLFullOuterJoin.class.php, + core/Joiner.class.php + core/SelectQuery.class.php: + Full outer join capability in select query + 2012-04-12 Evgeny V. Kokovikhin * test/main/Utils/PinbaTest.class.php, main/Monitoring/PinbaClient.class.php: diff --git a/test/main/OsqlSelectTest.class.php b/test/main/OsqlSelectTest.class.php index f3267fc67f..b69e1a1090 100644 --- a/test/main/OsqlSelectTest.class.php +++ b/test/main/OsqlSelectTest.class.php @@ -53,5 +53,73 @@ public function testSelectSubqueryGet() .'FROM "test_table"' ); } + + public function testSelectJoin() + { + $dialect = PostgresDialect::me(); + + $joinTypeList = array( + 'JOIN ' => 'join', + 'LEFT JOIN ' => 'leftJoin', + 'RIGHT JOIN ' => 'rightJoin', + 'FULL OUTER JOIN ' => 'fullOuterJoin' + ); + + $joinExpression = + Expression::eq( + DBField::create('joinField', 'table1'), + DBField::create('joinField', 'table2') + ); + + $baseRawQuery = + 'SELECT ' + .'"table1"."field1", ' + .'"table2"."field2" ' + .'FROM "table1" '; + + + foreach ($joinTypeList as $sqlJoin => $method) { + $query = + $this->getBaseJoinSelect()->{$method}('table2', $joinExpression); + + $rawQuery = + $baseRawQuery + .$sqlJoin + .'"table2" ON ("table1"."joinField" = "table2"."joinField")'; + + $this->assertEquals( + $rawQuery, + $query->toDialectString($dialect) + ); + + $query = + $this->getBaseJoinSelect()->{$method}( + 'table2', + $joinExpression, + 'table2' + ); + + $rawQuery = + $baseRawQuery + .$sqlJoin + .'"table2" AS "table2" ' + .'ON ("table1"."joinField" = "table2"."joinField")'; + + $this->assertEquals( + $rawQuery, + $query->toDialectString($dialect) + ); + } + } + + private function getBaseJoinSelect() + { + return + OSQL::select()-> + from('table1')-> + get(DBField::create('field1', 'table1'))-> + get(DBField::create('field2', 'table2')); + } + } ?> \ No newline at end of file