Esempio n. 1
0
 function test_join()
 {
     $query = new SQL_Query();
     $join = new SQL_Query_Join();
     $join->addJoin(array('t' => 'table', 'table1'), new SQL_Condition('table.x', '=', 'table1.x'));
     $query->setFrom($join);
     $ren = new $this->_renderer($query);
     $this->assertStringEquals('table t INNER JOIN table1 ON table.x = table1.x', $ren->renderFrom());
 }
Esempio n. 2
0
 function test_nestedJoinsAndAliases()
 {
     $join1 = new SQL_Query_Join();
     $join1->addJoin(array('1t' => '1table', '1t2' => '1table2'), null);
     $join2 = new SQL_Query_Join();
     $join2->addJoin(array('2t' => '2table', '2t2' => $join1), null);
     $join = new SQL_Query_Join();
     // the alias 't2' is not important here and getTables() doesnt return it either
     $join->addJoin(array('t' => 'table1', 't2' => $join2), null);
     $expected = array(array('table1', 't'), array('2table', '2t'), array('1table', '1t'), array('1table2', '1t2'));
     $this->assertEquals($expected, $join->getTables());
 }
Esempio n. 3
0
*/
ini_set('error_reporting', E_ALL);
ini_set('include_path', realpath(dirname(__FILE__) . '/../../..'));
#define('DB_DSN',  'mysql://root@localhost/test');
$tableStructures = array();
require_once 'SQL/Query.php';
require_once 'SQL/Query/Join.php';
require_once 'SQL/Query/Condition.php';
/*$aliases = array(
				TABLE_CONTACT     =>  'contact'
				,TABLE_CONTACT2TREE  =>  'contact2tree'
				,TABLE_CONTACTTREE   =>  'contactTree'
				);
*/
#DB_QueryTool::addAliases($aliases);
$query = new SQL_Query_Join('contact');
$query->autoJoin('contact2tree', 'contactTree');
$query->addLeftJoin('email', new SQL_Query_Condition('email.contact_id', '=', 'id', 'AND', 'email.primaryMail', '=', 1));
$query->addWhere('contactTree.user_id', '=', 7);
$query->addOrder('surname,name');
// this is just to demonstrate nested where clauses, the query doesnt really make sense, at least not to me :-)
// SELECT * FROM user WHERE (name LIKE 'n%' AND name LIKE 'a%') OR name LIKE 's%'
$query = new SQL_Query('user');
$c1 = $query->condition('name', 'LIKE', '"n%"');
$c1->add('name', 'LIKE', '"a%"', 'AND');
$query->addWhere($c1, 'OR', $query->condition('name', 'LIKE', '"%s"'));
require_once 'SQL/Query/Renderer.php';
$render = SQL_Query_Renderer::factory($query, $tableStructures);
print $render->toString();
print "<pre>";
print_r($query);