Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/OSQL/Joiner.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
26 changes: 26 additions & 0 deletions core/OSQL/SQLFullOuterJoin.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/***************************************************************************
* Copyright (C) 2012 by Timofey A. Anisimov *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/

/**
* @ingroup OSQL
**/
final class SQLFullOuterJoin extends SQLBaseJoin
{
/**
* @param Dialect $dialect
* @return string
*/
public function toDialectString(Dialect $dialect)
{
return parent::baseToString($dialect, 'FULL OUTER ');
}

}
17 changes: 17 additions & 0 deletions core/OSQL/SelectQuery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ public function rightJoin($table, LogicalObject $logic, $alias = null)

return $this;
}

/**
* @param $table
* @param LogicalObject $logic
* @param null $alias
* @return SelectQuery
*/
public function fullOuterJoin($table, LogicalObject $logic, $alias = null)
{
$this->joiner->fullOuterJoin(
new SQLFullOuterJoin($table, $logic, $alias)
);

$this->aliases[$alias] = true;

return $this;
}

/**
* @return SelectQuery
Expand Down
10 changes: 9 additions & 1 deletion doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
68 changes: 68 additions & 0 deletions test/main/OsqlSelectTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}
?>