Ejemplo n.º 1
0
 private function endRightFoot(Prototype $aPrototype, $sRightColumn = null)
 {
     $sTableName = $aPrototype->tableName();
     if (!$sRightColumn) {
         $sRightColumn = self::rightColumn($aPrototype);
     }
     $aRecords = DB::singleton()->query("select {$sRightColumn} as rgt from {$sTableName} order by {$sRightColumn} desc limit 1 ;");
     if (!$aRecords->rowCount()) {
         return 0;
     }
     $arrRow = $aRecords->fetch();
     return (int) $arrRow['rgt'];
 }
Ejemplo n.º 2
0
 /**
  * @return org\jecat\framework\db\sql\Select
  */
 public static function buildSelect(Prototype $aPrototype, array &$arrSelectState = null)
 {
     $arrSelectState['statement'] = new Select($aPrototype->tableName(), $aPrototype->sqlTableAlias(), $aPrototype->sqlForceIndex());
     if (!isset($arrSelectState['multitermAssocs'])) {
         $arrSelectState['multitermAssocs'] = array();
     }
     $arrTokenTree =& $arrSelectState['statement']->rawSql();
     $arrTokenTree['omited_first_table'] = $aPrototype->sqlTableAlias();
     $arrTokenTree['omited_first_table_len'] = strlen($arrTokenTree['omited_first_table']);
     // where
     if ($arrRawWhere = $aPrototype->criteria()->rawClause(SQL::CLAUSE_WHERE)) {
         $arrSelectState['statement']->setRawClause(SQL::CLAUSE_WHERE, $arrRawWhere);
     }
     // group by
     if ($arrRawGroup = $aPrototype->criteria()->rawClause(SQL::CLAUSE_GROUP)) {
         $arrSelectState['statement']->setRawClause(SQL::CLAUSE_GROUP, $arrRawGroup);
     }
     // order by
     if ($arrRawOrder = $aPrototype->criteria()->rawClause(SQL::CLAUSE_ORDER)) {
         $arrSelectState['statement']->setRawClause(SQL::CLAUSE_ORDER, $arrRawOrder);
     }
     // 递归连接所有关联原型的 table
     self::joinTables($arrSelectState, $aPrototype);
     return $arrSelectState['statement'];
 }