示例#1
0
文件: DB2.php 项目: opis/database
 /**
  * Returns the SQL for a select statement
  * 
  * @param   SQLStatement  $select
  * 
  * @return  string
  */
 public function select(SQLStatement $select)
 {
     $limit = $select->getLimit();
     if ($limit <= 0) {
         return parent::select($select);
     }
     $order = trim($this->handleOrderings($select->getOrder()));
     if (empty($order)) {
         $order = 'ORDER BY (SELECT 0)';
     }
     $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
     $sql .= $this->handleColumns($select->getColumns());
     $sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
     $sql .= ' FROM ';
     $sql .= $this->handleTables($select->getTables());
     $sql .= $this->handleJoins($select->getJoins());
     $sql .= $this->handleWheres($select->getWheres());
     $sql .= $this->handleGroupings($select->getGroupBy());
     $sql .= $this->handleHavings($select->getHaving());
     $offset = $select->getOffset();
     if ($offset < 0) {
         $offset = 0;
     }
     $limit += $offset;
     $offset++;
     return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
 }
示例#2
0
 /**
  * @param   string|Closure  $column
  * @param   Closure   $value
  * @param   string  $separator
  * 
  * @return  $this
  */
 protected function addCondition($column, Closure $value = null, $separator) : self
 {
     if ($column instanceof Closure) {
         $this->sql->addHavingGroupCondition($column, $separator);
     } else {
         $value($this->expression->init($column, $separator));
     }
     return $this;
 }
示例#3
0
 /**
  * Add a column
  * 
  * @param   string|Closure  $name   Column's name
  * @param   string          $alias  (optional) Alias
  * 
  * @return  $this
  */
 public function column($name, string $alias = null) : self
 {
     if ($name instanceof Closure) {
         $expression = $this->expression();
         $name($expression);
         $name = $expression;
     }
     $this->sql->addColumn($name, $alias);
     return $this;
 }
示例#4
0
 /**
  * @param   SQLStatement $update
  * 
  * @return  string
  */
 public function update(SQLStatement $update) : string
 {
     $joins = $this->handleJoins($update->getJoins());
     $tables = $update->getTables();
     if ($joins !== '') {
         $joins = ' FROM ' . $this->handleTables($tables) . ' ' . $joins;
         $tables = array_values($tables);
     }
     $sql = 'UPDATE ';
     $sql .= $this->handleTables($tables);
     $sql .= $this->handleSetColumns($update->getColumns());
     $sql .= $joins;
     $sql .= $this->handleWheres($update->getWheres());
     return $sql;
 }
示例#5
0
文件: Oracle.php 项目: opis/database
 /**
  * Compiles a SELECT query.
  *
  * @param   SQLStatement $select
  * 
  * @return  string
  */
 public function select(SQLStatement $select) : string
 {
     $limit = $select->getLimit();
     if ($limit <= 0) {
         return parent::select($select);
     }
     $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
     $sql .= $this->handleColumns($select->getColumns());
     $sql .= ' FROM ';
     $sql .= $this->handleTables($select->getTables());
     $sql .= $this->handleJoins($select->getJoins());
     $sql .= $this->handleWheres($select->getWheres());
     $sql .= $this->handleGroupings($select->getGroupBy());
     $sql .= $this->handleOrderings($select->getOrder());
     $sql .= $this->handleHavings($select->getHaving());
     $offset = $select->getOffset();
     if ($offset < 0) {
         return 'SELECT * FROM (' . $sql . ') M1 WHERE ROWNUM <= ' . $limit;
     }
     $limit += $offset;
     $offset++;
     return 'SELECT * FROM (SELECT M1.*, ROWNUM AS OPIS_ROWNUM FROM (' . $sql . ') M1 WHERE ROWNUM <= ' . $limit . ') WHERE OPIS_ROWNUM >= ' . $offset;
 }
示例#6
0
 /**
  * Returns the SQL for a delete statement
  *
  * @param SQLStatement $delete
  * @return string
  */
 public function delete(SQLStatement $delete) : string
 {
     $sql = 'DELETE ' . $this->handleTables($delete->getTables());
     $sql .= $sql === 'DELETE ' ? 'FROM ' : ' FROM ';
     $sql .= $this->handleTables($delete->getFrom());
     $sql .= $this->handleJoins($delete->getJoins());
     $sql .= $this->handleWheres($delete->getWheres());
     return $sql;
 }
示例#7
0
文件: Where.php 项目: opis/database
 /**
  * @param   bool    $not
  *
  * @return  WhereStatement
  */
 protected function addNullCondition(bool $not) : WhereStatement
 {
     $this->sql->addWhereNullCondition($this->column, $this->separator, $not);
     return $this->statement;
 }
示例#8
0
文件: Having.php 项目: opis/database
 /**
  * @param   string|float|int $value1
  * @param   string|float|int $value2
  */
 public function notBetween($value1, $value2)
 {
     $this->sql->addHavingBetweenCondition($this->aggregate, $value1, $value2, $this->separator, true);
 }
示例#9
0
 /**
  * Compiles a SELECT query.
  *
  * @access  public
  * @param   SQLStatement    $select
  * @return  array
  */
 public function select(SQLStatement $select)
 {
     $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
     $sql .= $this->handleColumns($select->getColumns());
     $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
     $sql .= ' FROM ';
     $sql .= $this->handleTables($select->getTables());
     $sql .= $this->handleJoins($select->getJoins());
     $sql .= $this->handleWheres($select->getWheres());
     $sql .= $this->handleGroupings($select->getGroupBy());
     $sql .= $this->handleOrderings($select->getOrder());
     $sql .= $this->handleHavings($select->getHaving());
     $sql .= $this->handleOffset($select->getOffset(), $select->getLimit());
     $sql .= $this->handleLimit($select->getLimit(), $select->getOffset());
     return $sql;
 }
示例#10
0
 /**
  * @param   string  $table
  */
 public function into(string $table)
 {
     $this->sql->addTables([$table]);
 }
示例#11
0
 /**
  * @param Closure $select
  * @param string $separator
  * @param bool $not
  * @return WhereStatement
  */
 protected function addWhereExistCondition(Closure $select, string $separator = 'AND', bool $not = false) : self
 {
     $this->sql->addWhereExistsCondition($select, $separator, $not);
     return $this;
 }