public function testMergeWhere()
 {
     $this->queryBuilder->where('id', 5, DeleteQueryBuilder::LESS_THAN);
     $qb = new SelectQueryBuilder();
     $qb->_open(SelectQueryBuilder::LOGICAL_OR)->where('title', 'Dune', SelectQueryBuilder::NOT_EQUALS, null)->_close();
     $this->queryBuilder->mergeWhere($qb);
     $expected = array(array('column' => 'id', 'value' => 5, 'operator' => '<', 'connector' => 'AND'), array('bracket' => '(', 'connector' => 'OR'), array('column' => 'title', 'value' => 'Dune', 'operator' => '!=', 'connector' => 'AND'), array('bracket' => ')', 'connector' => NULL));
     $this->assertEquals($expected, $this->queryBuilder->getWhereParts());
 }
 /**
  *
  * @dataProvider mergeProvider
  */
 public function testMerge($overwriteLimit, $mergeOrderBy, $expectedQuery, $expectedBoundParameters)
 {
     $this->queryBuilder->from('book', 'b')->select('id')->select('count(*)', 'nb')->join('author', 'a', 'a.id = b.author_id', SelectQueryBuilder::INNER_JOIN)->where('id', 5, SelectQueryBuilder::LESS_THAN)->groupBy('id')->having('score', 5, SelectQueryBuilder::LESS_THAN)->orderBy('price', SelectQueryBuilder::DESC)->limit(20)->offset(10);
     $qb = new SelectQueryBuilder();
     $qb->from('book')->select('title')->addOption('DISTINCT')->join('editor', 'e', 'e.id = b.editor_id', SelectQueryBuilder::LEFT_JOIN)->_open(SelectQueryBuilder::LOGICAL_OR)->where('title', 'Dune', SelectQueryBuilder::NOT_EQUALS, null)->_close()->groupBy('score', SelectQueryBuilder::ASC)->openHaving(SelectQueryBuilder::LOGICAL_OR)->having('price', 9, SelectQueryBuilder::NOT_EQUALS, null)->closeHaving()->orderBy('score', SelectQueryBuilder::ASC)->limit(50)->offset(0);
     $this->queryBuilder->merge($qb, $overwriteLimit, $mergeOrderBy);
     $this->assertEquals($expectedQuery, $this->queryBuilder->getQueryString());
     $this->assertEquals($expectedBoundParameters, $this->queryBuilder->getBoundParameters());
 }
 public function getQueryStringProvider()
 {
     $select1 = new SelectQueryBuilder();
     $select1->select('AVG(price)');
     $select1->from('OldBook', 'o');
     return array(array('', array(), array(), array(), '', ''), array('book', array(array('score', null, 5), array('price', null, 8)), array(array('title', 'Dune', UpdateQueryBuilder::EQUALS, null)), array(5, 8, 'Dune'), 'UPDATE book SET score = ?, price = ? WHERE title = ? ', 'UPDATE book ' . "\n" . 'SET ' . "\n" . 'score = ?, ' . "\n" . 'price = ? ' . "\n" . 'WHERE title = ? ' . "\n"));
 }
 public function getQueryStringProvider()
 {
     $select1 = new SelectQueryBuilder();
     $select1->select('id');
     $select1->select('title');
     $select1->from('OldBook', 'o');
     $select1->where('price', 8, SelectQueryBuilder::GREATER_THAN_OR_EQUAL);
     return array(array('', array(), array(), null, array(), '', ''), array('book', array('id', 'title'), array(array(1, 'Dune')), null, array(1, 'Dune'), 'INSERT INTO book (id, title) VALUES (?, ?) ', 'INSERT INTO book (id, title) ' . "\n" . 'VALUES ' . "\n" . '(?, ?) ' . "\n"), array('book', array('id', 'title'), array(array(1, 'Dune'), array(2, 'The Man in the High Castles')), null, array(1, 'Dune', 2, 'The Man in the High Castles'), 'INSERT INTO book (id, title) VALUES (?, ?), (?, ?) ', 'INSERT INTO book (id, title) ' . "\n" . 'VALUES ' . "\n" . '(?, ?), ' . "\n" . '(?, ?) ' . "\n"), array('book', array('id', 'title'), array(), $select1, array(1, 'Dune', 2, 'The Man in the High Castles'), 'INSERT INTO book (id, title) SELECT id, title FROM OldBook AS o WHERE price >= ? ', 'INSERT INTO book (id, title) ' . "\n" . 'SELECT id, title ' . "\n" . 'FROM OldBook AS o ' . "\n" . 'WHERE price >= ? ' . "\n"), array('book', array('id', 'title'), array(array(3, 'Do Androids Dream of Electric Sheep?')), $select1, array(1, 'Dune', 2, 'The Man in the High Castles'), 'INSERT INTO book (id, title) SELECT id, title FROM OldBook AS o WHERE price >= ? ', 'INSERT INTO book (id, title) ' . "\n" . 'SELECT id, title ' . "\n" . 'FROM OldBook AS o ' . "\n" . 'WHERE price >= ? ' . "\n"));
 }
Пример #5
0
 /**
  * Merges the given QueryBuilder's LIMITs into this QueryBuilder.
  *
  * @param \SQL\SelectQueryBuilder $QueryBuilder to merge
  *
  * @return \SQL\SelectQueryBuilder the current QueryBuilder
  */
 public function mergeLimit(SelectQueryBuilder $QueryBuilder)
 {
     $this->limit($QueryBuilder->getLimit());
     $this->offset($QueryBuilder->getOffset());
     return $this;
 }