Ejemplo n.º 1
0
 /**
  * Setup method
  */
 public function setUp()
 {
     with($conn = \rdbms\DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
     Job::getPeer()->setConnection($conn);
     Person::getPeer()->setConnection($conn);
     $this->qa = new SelectQuery();
     $this->qa->setPeer(Job::getPeer());
     $this->qa->setCriteria((new Criteria(Job::column('job_id')->equal(5)))->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Job::column('job_id'))->add(Job::column('title'))));
     $this->qb = new SelectQuery();
     $this->qb->setPeer(Person::getPeer());
     $this->qb->setCriteria((new Criteria())->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Person::column('job_id'))->add(Person::column('name'))));
 }
 function mathArithFunctionTest()
 {
     $this->assertProjection('abs(-6)', 'abs(-6)', 'abs(-6)', 'php(\'abs\', -6)', create(new \rdbms\Criteria())->setProjection(SQLFunctions::abs(-6)));
     $this->assertProjection('ceil(5.1)', 'ceiling(5.1)', 'ceil(5.1)', 'php(\'ceil\', 5.1)', create(new \rdbms\Criteria())->setProjection(SQLFunctions::ceil(5.1)));
     $this->assertProjection('floor(5.7)', 'floor(5.7)', 'floor(5.7)', 'php(\'floor\', 5.7)', create(new \rdbms\Criteria())->setProjection(SQLFunctions::floor(5.7)));
     $this->assertProjection('exp(log(1))', 'exp(log(1))', 'exp(log(1))', 'php(\'exp\', php(\'log\', 1))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::exp(SQLFunctions::log(1))));
     $this->assertProjection('log10(power(10, 5))', 'log10(power(10, 5))', 'log10(power(10, 5))', 'php(\'log10\', php(\'pow\', 10, 5))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::log10(SQLFunctions::power(10, 5))));
     $this->assertProjection('power(10, log10(5))', 'power(10, log10(5))', 'power(10, log10(5))', 'php(\'pow\', 10, php(\'log10\', 5))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::power(10, SQLFunctions::log10(5))));
     $this->assertProjection('round(1.5, 0) as `roundtest1`, round(1.49, 0) as `roundtest2`, round(1.49, 1) as `roundtest3`', 'round(1.5, 0) as \'roundtest1\', round(1.49, 0) as \'roundtest2\', round(1.49, 1) as \'roundtest3\'', 'round(1.5, 0) as "roundtest1", round(1.49, 0) as "roundtest2", round(1.49, 1) as "roundtest3"', 'php(\'round\', 1.5, 0) as \'roundtest1\', php(\'round\', 1.49, 0) as \'roundtest2\', php(\'round\', 1.49, 1) as \'roundtest3\'', create(new \rdbms\Criteria())->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(SQLFunctions::round(1.5), 'roundtest1')->add(SQLFunctions::round(1.49), 'roundtest2')->add(SQLFunctions::round(1.49, 1), 'roundtest3')));
     $this->assertProjection('sign(-7) as `signTest1`, sign(0) as `signTest2`, sign(4) as `signTest3`', 'convert(int, sign(-7)) as \'signTest1\', convert(int, sign(0)) as \'signTest2\', convert(int, sign(4)) as \'signTest3\'', 'sign(-7) as "signTest1", sign(0) as "signTest2", sign(4) as "signTest3"', 'sign(-7) as \'signTest1\', sign(0) as \'signTest2\', sign(4) as \'signTest3\'', create(new \rdbms\Criteria())->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(SQLFunctions::sign(-7), 'signTest1')->add(SQLFunctions::sign(0), 'signTest2')->add(SQLFunctions::sign(4), 'signTest3')));
 }
 public function testJoinWithProjection()
 {
     $jp = new \rdbms\join\JoinProcessor(Job::getPeer());
     $jp->setFetchModes(array('PersonJob->Department' => 'join'));
     $jp->enterJoinContext();
     $this->assertEquals('select  PersonJob.job_id, PersonJob_Department.department_id from JOBS.job as start, JOBS.Person as PersonJob, JOBS.Department as PersonJob_Department where start.job_id *= PersonJob.job_id and PersonJob.department_id *= PersonJob_Department.department_id and  1 = 1', create(new Criteria())->setFetchmode(\rdbms\join\Fetchmode::join('PersonJob'))->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Job::column('PersonJob->job_id'))->add(Job::column('PersonJob->Department->department_id')))->getSelectQueryString($this->conn, $this->peer, $jp));
     $jp->leaveJoinContext();
 }
Ejemplo n.º 4
0
 /**
  * Set projection
  * param can also be a rdbms.Column, a property
  * If the first parameter is omitted or NULL given the projection will be cleared
  * projection is then assumed
  *
  * @param   rdbms.SQLRenderable projection optional
  * @param   string optional alias
  * @return  rdbms.Criteria this object
  */
 public function setProjection(SQLRenderable $projection = null, $alias = '')
 {
     $this->projection = is_null($projection) || $projection instanceof ProjectionList ? $projection : ($projection = Projections::projectionList()->add($projection, $alias));
     return $this;
 }
 function withProjectionTest()
 {
     $crit = new \rdbms\Criteria();
     $this->assertClass($crit->withProjection(Projections::property(Job::column('job_id'))), 'rdbms.Criteria');
     $this->assertFalse($crit->isProjection());
     $this->assertTrue($crit->withProjection(Projections::property(Job::column('job_id')))->isProjection());
 }
Ejemplo n.º 6
0
 function regressionIteratorDatasetType()
 {
     $conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1');
     $conn->setResultSet(new MockResultSet([['count' => 5]]));
     $crit = (new Criteria())->withProjection(Projections::count('*'));
     $this->peer->setConnection($conn);
     $this->assertInstanceOf(Record::class, $this->peer->iteratorFor($crit)->next());
 }