/** * 生成查询条件 * * @return string */ protected function renderWhere() { if ($this->where === NULL) { return ''; } return 'where ' . $this->where->toString(); }
/** * 生成文字表达的SQL语句 * * orObject、andObject有可能共存,or优先,最好不要共存 */ public function toString() { //获取自身对象代表的语句 $method = 'render' . ucfirst($this->type); $whereString = '(' . $this->{$method}() . ')'; if ($this->andObject) { if ($this->andHand == self::HAND_RIGHT) { $whereString = '(' . $whereString . ' ' . self::WHERE_AND . ' ' . $this->andObject->toString() . ')'; } else { $whereString = '(' . $this->andObject->toString() . ' ' . self::WHERE_AND . ' ' . $whereString . ')'; } } if ($this->orObject) { if ($this->orHand == self::HAND_RIGHT) { $whereString = '(' . $whereString . ' ' . self::WHERE_OR . ' ' . $this->orObject->toString() . ')'; } else { $whereString = '(' . $this->orObject->toString() . ' ' . self::WHERE_OR . ' ' . $whereString . ')'; } } return $whereString; }