/** * * @throws PDOException */ public function _query() { if ($this->_rowset === false) { if (self::$_stmt) { while (self::$_stmt->nextRowset()) { //如果已经在结果缓存中,则搜寻结果集 $query = array_shift(self::$_fetchingQueue); $query->_rowset = $query->_fetchAll(); if ($query === $this) { return; } } self::$_stmt = null; } //将当前的语句插到第一个,然后把所有语句一口气打包发送给mysql $keys = array_keys(self::$_waitingQueue, $this); if (count($keys)) { unset(self::$_waitingQueue[$keys[0]]); } $sql = $this->_select->assemble(); if (count(self::$_waitingQueue)) { $sql .= ";\n" . implode(";\n", self::$_waitingQueue); } implode(";\n", self::$_waitingQueue); self::$_stmt = $this->_select->getAdapter()->query($sql); $this->_rowset = $this->_fetchAll(); self::$_fetchingQueue = self::$_waitingQueue; self::$_waitingQueue = array(); } }
/** * Performs a validation on the select query before passing back to the parent class. * Ensures that only columns from the primary DataObject are returned in the result. * * @return string|null This object as a SELECT string (or null if a string cannot be produced) */ public function assemble() { if (count($this->_parts[self::UNION]) == 0) { $fields = $this->getPart(Select::COLUMNS); $primary = $this->_info[DataObject::NAME]; $schema = $this->_info[DataObject::SCHEMA]; // If no fields are specified we assume all fields from primary table if (!count($fields)) { $this->from($primary, self::SQL_WILDCARD, $schema); } } return parent::assemble(); }