コード例 #1
0
 /**
  * @return  string
  */
 public function __toString()
 {
     if ($this->sql === null) {
         $this->sql = $this->compiler->insert($this);
     }
     return $this->sql;
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: SQLServer.php プロジェクト: Textalk/opis-database
 /**
  * Compiles a SELECT query.
  *
  * @access  public
  * @param   \Opis\Database\SQL\SelectStatement    $select  Query object.
  * @return  array
  */
 public function select(SelectStatement $select)
 {
     $limit = $select->getLimit();
     $offset = $select->getOffset();
     if ($limit === null && $offset === null) {
         return parent::select($select);
     }
     if ($offset === null) {
         $sql = $select->isDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
         $sql .= 'TOP ' . $limit . ' ';
         $sql .= $this->handleColumns($select->getColumns());
         $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
         $sql .= ' FROM ';
         $sql .= $this->handleTables($select->getTables());
         $sql .= $this->handleJoins($select->getJoinClauses());
         $sql .= $this->handleWheres($select->getWhereConditions());
         $sql .= $this->handleGroupings($select->getGroupClauses());
         $sql .= $this->handleOrderings($select->getOrderClauses());
         $sql .= $this->handleHavings($select->getHavingConditions());
         return $sql;
     }
     $order = trim($this->handleOrderings($select->getOrderClauses()));
     if (empty($order)) {
         $order = 'ORDER BY (SELECT 0)';
     }
     $sql = $select->isDistinct() ? '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->getJoinClauses());
     $sql .= $this->handleWheres($select->getWhereConditions());
     $sql .= $this->handleGroupings($select->getGroupClauses());
     $sql .= $this->handleHavings($select->getHavingConditions());
     if ($offset === null) {
         $offset = 0;
     }
     $limit += $offset;
     $offset++;
     return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
 }
コード例 #4
0
ファイル: Oracle.php プロジェクト: Textalk/opis-database
 /**
  * Compiles a SELECT query.
  *
  * @access  public
  * @param   \Opis\Database\SQL\SelectStatament    $select  Query object.
  * @return  array
  */
 public function select(SelectStatement $select)
 {
     $limit = $select->getLimit();
     $offset = $select->getOffset();
     if ($limit === null && $offset === null) {
         return parent::select($select);
     }
     $sql = $select->isDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
     $sql .= $this->handleColumns($select->getColumns());
     $sql .= ' FROM ';
     $sql .= $this->handleTables($select->getTables());
     $sql .= $this->handleJoins($select->getJoinClauses());
     $sql .= $this->handleWheres($select->getWhereConditions());
     $sql .= $this->handleGroupings($select->getGroupClauses());
     $sql .= $this->handleOrderings($select->getOrderClauses());
     $sql .= $this->handleHavings($select->getHavingConditions());
     if ($offset === null) {
         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;
 }