예제 #1
0
 protected function executeQuery()
 {
     if ($this->result) {
         return;
     }
     if ($this->page_size) {
         if ($this->db->supportsSqlCalcFoundRows() && is_null($this->custom_count)) {
             $this->setSqlCalcFoundRows();
         }
         $limit = $this->pageSize();
         $offset = max($this->currentPage() - 1, 0) * $this->pageSize();
         $this->setLimit($limit);
         $this->setOffset($offset);
     }
     $result = $this->db->query($this);
     $result->setFetchMode(PDO::FETCH_BOTH);
     if (method_exists($this->gateway, 'load')) {
         $this->result = new pdoext_Resultset($result, $this->gateway);
     } else {
         $this->result = $result;
     }
     if ($this->page_size && is_null($this->custom_count)) {
         if ($this->db->supportsSqlCalcFoundRows()) {
             // MySql specific
             $result = $this->db->query("SELECT FOUND_ROWS()");
             $row = $result->fetch();
             $this->total_count = $row[0];
         } else {
             // fall back on select count(*)
             $this->setLimit(null);
             $this->setOffset(null);
             $q = new pdoext_Query($this);
             $q->addColumn(pdoext_literal('count(*)'), 'total_count');
             $result = $this->db->query($q);
             $row = $result->fetch();
             $this->total_count = $row[0];
             $this->setLimit($limit);
             $this->setOffset($offset);
         }
     }
 }
예제 #2
0
 function test_select_complex_query()
 {
     $db = $this->getConnection();
     $q = new pdoext_Query('people');
     $q->addColumn("first_name");
     $q->setLimit(10);
     $q->setOffset(10);
     $j = $q->addJoin('accounts', 'LEFT JOIN');
     $sub = $j->addCriterion(new pdoext_query_Criteria("OR"));
     $sub->addConstraint('people.account_id', 'accounts.account_id');
     $sub->addCriterion('people.account_id', 28, '>');
     $q->addCriterion('first_name', "John");
     $this->assertSqlEqual($q->toSql($db), "\nselect `first_name`\nfrom `people`\nleft join `accounts`\non `people`.`account_id` = `accounts`.`account_id` or `people`.`account_id` > '28'\nwhere `first_name` = 'John'\nlimit 10\noffset 10\n");
 }