Example #1
0
 /**
  * @group count
  * @covers Query::getQuery
  */
 function testGetQueryCountAggregateFunctionsWithoutGroup()
 {
     $q = new Query('test_table');
     $q->addColumn('count(0)');
     $q->addColumn('sum(2)');
     $q->setAction(Query::ACTION_COUNT);
     $count_q = $q->getQuery()->__toString();
     // if there is an aggregate function and no group by, the
     $q->setAction(Query::ACTION_SELECT);
     $select_q = $q->getQuery()->__toString();
     $this->assertEquals("SELECT count(0)\nFROM ({$select_q}) a", $count_q);
     $q = new Query('test_table');
     $q->addColumn('count(0)');
     $q->addColumn('sum(2)');
     $q->addColumn('not_allowed_in_sql_server');
     $q->setAction(Query::ACTION_COUNT);
     $count_q = $q->getQuery()->__toString();
     // if there is an aggregate function and no group by, the
     $q->setAction(Query::ACTION_SELECT);
     $select_q = $q->getQuery()->__toString();
     $this->assertNotEquals("SELECT count(0)\nFROM ({$select_q}) a", $count_q);
 }
Example #2
0
<?php

// create a new Query object
$q = new Query('table');
// add a calculated column
$q->addColumn('count(0)');
// retrieve the count of all records from `table`
$q->doSelect();