/** * @return Select */ public static function make($sSql, $factors = null) { $factors = func_get_args(); $sSql = array_shift($factors); if (!($arrRawSqls = self::parseSql($sSql)) or empty($arrRawSqls[0])) { return; } if (isset($arrRawSqls[0]['command'])) { switch ($arrRawSqls[0]['command']) { case 'SELECT': $aSql = new Select(); case 'INSERT': $aSql = new Insert(); case 'UPDATE': $aSql = new Update(); case 'DELETE': $aSql = new Delete(); break; default: $aSql = new SQL(); break; } } else { $aSql = new SQL(); } $aSql->setRawSql($arrRawSqls[0]); if ($factors) { $aSql->addFactors($factors); } return $aSql; }
/** * @wiki /MVC模式/数据库模型/数据表关联 * ==Bean配置数组== * type string 指定关系类型 * fromkeys array 起始表列名 * tokeys array 目标表列名 * frombridgekeys array 起始桥接表列名 * tobridgekeys array 起始桥接表列名 * bridge string 桥接表名 * fromPrototype string 指定起源原型配置 * on string */ public function buildBean(array &$arrConfig, $sNamespace = '*', \org\jecat\framework\bean\BeanFactory $aBeanFactory = null) { if (!$this->aDB) { $this->aDB = DB::singleton(); } $arrConfigForToPrototype = $arrConfig; $arrConfigForToPrototype['class'] = 'prototype'; $this->aToPrototype = BeanFactory::singleton()->createBean($arrConfigForToPrototype, $sNamespace); $this->aToPrototype->setassociatedBy($this); if (!empty($arrConfig['type'])) { $this->nType = $arrConfig['type']; } if (!empty($arrConfig['fromkeys'])) { $this->setFromKeys($arrConfig['fromkeys']); } if (!empty($arrConfig['tokeys'])) { $this->setToKeys($arrConfig['tokeys']); } if (!empty($arrConfig['tobridgekeys'])) { $this->setToBridgeKeys($arrConfig['tobridgekeys']); } if (!empty($arrConfig['frombridgekeys'])) { $this->setFromBridgeKeys($arrConfig['frombridgekeys']); } if (!empty($arrConfig['bridge'])) { $this->sBridgeTable = $arrConfig['bridge']; } if (!empty($arrConfig['fromPrototype'])) { $this->aFromPrototype = $arrConfig['fromPrototype']; } if (!empty($arrConfig['on'])) { if (is_array($arrConfig['on'])) { $arrOnFactors = $arrConfig['on']; $this->arrOnRawSql['expr_type'] = 'clause_on'; $this->arrOnRawSql['subtree'] =& SQL::parseSql(array_shift($arrOnFactors), 'on', true); $aOnClause = new SQL($this->arrOnRawSql); $aOnClause->addFactors($arrOnFactors); } else { $this->arrOnRawSql['expr_type'] = 'clause_on'; $this->arrOnRawSql['subtree'] =& SQL::parseSql($arrConfig['on'], 'on', true); } } if (!empty($arrConfig['join'])) { $this->sJoinType = strtoupper($arrConfig['join']); } $this->done(); $this->arrBeanConfig = $arrConfig; }