function testSelectLimit() { $this->dbo->execute('DELETE FROM q_posts'); $idList = $this->_insertIntoPosts(10); $sql = "SELECT post_id FROM q_posts ORDER BY post_id ASC"; $length = 10; $offset = 0; $rowset = $this->dbo->selectLimit($sql, $length, $offset)->fetchAll(); $msg = "\$rowset = \$this->dbo->select_limit('{$sql}', {$length}, {$offset});"; $this->assertEquals($length, count($rowset), $msg); for ($i = $offset; $i < $offset + $length; $i++) { $msg = "\$length = {$length}, \$offset = {$offset}"; $this->assertEquals($idList[$i], $rowset[$i - $offset]['post_id'], $msg); } $length = 3; $offset = 5; $rowset = $this->dbo->selectLimit($sql, $length, $offset)->fetchAll(); $msg = "\$rowset = \$this->dbo->select_limit('{$sql}', {$length}, {$offset});"; $this->assertEquals($length, count($rowset), $msg); for ($i = $offset; $i < $offset + $length; $i++) { $msg = "\$length = {$length}, \$offset = {$offset}"; $this->assertEquals($idList[$i], $rowset[$i - $offset]['post_id'], $msg); } }
/** * 执行查询,返回结果句柄 * * @return QDB_Result_Abstract */ function getQueryHandle() { // 构造查询 SQL,并取得查询中用到的关联 $sql = $this->__toString(); $offset = $this->_parts[self::LIMIT_OFFSET]; $count = $this->_parts[self::LIMIT_COUNT]; if (is_null($offset) && is_null($count)) { return $this->_conn->execute($sql); } else { return $this->_conn->selectLimit($sql, $offset, $count); } }