/** * 编译sql语句 * * @return array */ protected function compile() { $fields = $this->fields; $updateFields = array(); $updateValues = array(); foreach ($this->expressionFields as $field => $data) { !empty($data['arguments']) and $updateValues += $data['arguments']; if ($data['expression'] instanceof Select) { $updateValues += $data['expression']->getArguments($this->queryIdentifier); $data['expression'] = ' (' . $data['expression']->getString($this->queryIdentifier) . ')'; } $updateFields[] = $field . '=' . $data['expression']; unset($fields[$field]); } $maxPlaceholder = $placeholder = 0; foreach ($fields as $field => $value) { $placeholder = ':mkUpdatePlaceholder' . $maxPlaceholder++; $updateFields[] = $field . '=' . $placeholder; $updateValues[$placeholder] = $value; } $query = 'UPDATE {:' . $this->table . ':} SET ' . implode(', ', $updateFields); if (count($this->condition)) { $query .= "\nWHERE " . $this->condition->getString($this->queryIdentifier); $updateValues = array_merge($updateValues, $this->condition->getArguments($this->queryIdentifier)); } return array('sql' => $query, 'arguments' => $updateValues); }
/** * 编译查询条件 * * @return array */ protected function compile() { $query = array(); $query['sql'] = 'DELETE FROM {:' . $this->table . ':} '; $query['arguments'] = array(); if (count($this->condition)) { $query['sql'] .= "\nWHERE " . $this->condition->getString($this->queryIdentifier); $query['arguments'] = $this->condition->getArguments($this->queryIdentifier); } return $query; }
/** * 获取查询参数值 * * @param string $queryIdentifier * * @return array|null */ public function getArguments($queryIdentifier = NULL) { $queryIdentifier and $this->queryIdentifier = $queryIdentifier; $qi = $this->queryIdentifier; $args = $this->where->getArguments($qi) + $this->having->getArguments($qi); foreach ($this->tables as $table) { $table['arguments'] and $args += $table['arguments']; $table['table'] instanceof Select and $args += $table['table']->getArguments($qi); } foreach ($this->expressions as $expression) { $expression['arguments'] and $args += $expression['arguments']; } return $args; }