/** * Conduct object query with EZOQL (see more in {@link epQuery}) * @param string $oql * @param mixed ... parameters to replace ? in the query string * @return false|integer|float|array * @throws epExceptionQuery, epExceptionManagerBase */ public function &query($oql) { if (!$oql) { return self::$false; } // get arguments $args = func_get_args(); // remove the first argument (the query string) array_shift($args); // get the new query object if (!$this->q) { include_once EP_SRC_RUNTIME . '/epQuery.php'; $this->q = new epQuery(); } // make sure manager is initialized $this->initialize(); // translate the oql stmts into a sql stmt if (!($sql_stmts = $this->q->parse($oql, $args))) { return self::$false; } // the class maps involved in the query if (!($cms = $this->q->getClassMaps())) { return self::$false; } // use the first class map $db =& $this->_getDb($cms[0]); // before query, commit objects of the involved classes if // option 'flush_before_find' is set. (see explanation in // class epQuery) if ($this->getConfigOption('flush_before_find')) { foreach ($cms as $cm) { $class = $cm->getName(); $this->flush($class, true); // true: flush all } } // get the root class $class = $cms[0]->getName(); // event: onPreLoad $this->_dispatchEvent(array('onPreLoad'), $class, array('operation' => 'query', 'params' => $oql)); // get query parts for later uses $limit = $this->q->getLimit(); $orderby = $this->q->getOrderBy(); // aggregation function in query? if ($aggr_func = $this->q->getAggregateFunction()) { // delegate aggreation function query to database layer return $db->query($cms, $sql_stmts, $orderby, $limit, $aggr_func); } // delegate query to database layer (epDbObject) if ($os = $db->query($cms, $sql_stmts, $orderby, $limit)) { // cache them all foreach ($os as &$o) { $this->cache($o); // event: onLoad and onPostLoad $this->_dispatchEvent(array('onLoad', 'onPostLoad'), $o); } } return $os; }
/** * Conduct object query with EZOQL (see more in {@link epQuery}) * @param string $oql * @param mixed ... parameters to replace ? in the query string * @return false|integer|float|array * @throws epExceptionQuery, epExceptionManagerBase */ public function &query($oql) { if (!$oql) { return self::$false; } // get arguments $args = func_get_args(); // remove the first argument (the query string) array_shift($args); // process query delegated from find() if (is_array($args) && isset($args[0]) && is_array($args[0]) && isset($args[0][0])) { $args = $args[0]; } // get the new query object if (!$this->q) { include_once EP_SRC_RUNTIME . '/epQuery.php'; $this->q = new epQuery(); } // translate the oql stmts into a sql stmt if (!($sql_stmts = $this->q->parse($oql, $args))) { return self::$false; } // the class maps involved in the query if (!($cms = $this->q->getClassMaps())) { return self::$false; } // use the first class map $db =& $this->_getDb($cms[0]->getName(), $cms[0]); // before query, commit and then evict all objects of the class // (see explanation in class epQuery) foreach ($cms as $cm) { $class = $cm->getName(); $this->flush($class, true); // true: flush all $this->_evictAll($class, false); // false: all classes, false: no event dispatching } // event: onPreLoad $this->_dispatchEvent(array('onPreLoad'), $class, array('operation' => 'query', 'params' => $oql)); // get query parts for later uses $limit = $this->q->getLimit(); $orderby = $this->q->getOrderBy(); // aggregation function in query? if ($aggr_func = $this->q->getAggregateFunction()) { // delegate aggreation function query to database layer return $db->query($cms, $sql_stmts, $orderby, $limit, $aggr_func); } // delegate query to database layer (epDbObject) if ($os = $db->query($cms, $sql_stmts, $orderby, $limit)) { // cache them all foreach ($os as &$o) { $this->cache($o); // event: onLoad and onPostLoad $this->_dispatchEvent(array('onLoad', 'onPostLoad'), $o); } } return $os; }