Beispiel #1
0
 /**
  * Magic function to convert the query to a string.
  *
  * @return  string	The completed query.
  *
  * @since   11.1
  */
 public function __toString()
 {
     $query = '';
     switch ($this->type) {
         case 'select':
             $query .= (string) $this->select;
             $query .= (string) $this->from;
             if ($this->join) {
                 // Special case for joins
                 foreach ($this->join as $join) {
                     $query .= (string) $join;
                 }
             }
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             if ($this->group) {
                 $query .= (string) $this->group;
             }
             if ($this->order) {
                 $query .= (string) $this->order;
             }
             if ($this->having) {
                 $query .= (string) $this->having;
             }
             if ($this instanceof F0FDatabaseQueryLimitable && ($this->limit > 0 || $this->offset > 0)) {
                 $query = $this->processLimit($query, $this->limit, $this->offset);
             }
             break;
         case 'insert':
             $query .= (string) $this->insert;
             // Set method
             if ($this->set) {
                 $query .= (string) $this->set;
             } elseif ($this->values) {
                 if ($this->columns) {
                     $query .= (string) $this->columns;
                 }
                 $elements = $this->insert->getElements();
                 $tableName = array_shift($elements);
                 $query .= 'VALUES ';
                 $query .= (string) $this->values;
                 if ($this->autoIncrementField) {
                     $query = 'SET IDENTITY_INSERT ' . $tableName . ' ON;' . $query . 'SET IDENTITY_INSERT ' . $tableName . ' OFF;';
                 }
                 if ($this->where) {
                     $query .= (string) $this->where;
                 }
             }
             break;
         case 'delete':
             $query .= (string) $this->delete;
             $query .= (string) $this->from;
             if ($this->join) {
                 // Special case for joins
                 foreach ($this->join as $join) {
                     $query .= (string) $join;
                 }
             }
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             if ($this->order) {
                 $query .= (string) $this->order;
             }
             break;
         case 'update':
             $query .= (string) $this->update;
             if ($this->join) {
                 // Special case for joins
                 foreach ($this->join as $join) {
                     $query .= (string) $join;
                 }
             }
             $query .= (string) $this->set;
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             if ($this->order) {
                 $query .= (string) $this->order;
             }
             break;
         default:
             $query = parent::__toString();
             break;
     }
     return $query;
 }
 /**
  * Magic function to convert the query to a string, only for postgresql specific query
  *
  * @return  string	The completed query.
  *
  * @since   11.3
  */
 public function __toString()
 {
     $query = '';
     switch ($this->type) {
         case 'select':
             $query .= (string) $this->select;
             $query .= (string) $this->from;
             if ($this->join) {
                 // Special case for joins
                 foreach ($this->join as $join) {
                     $query .= (string) $join;
                 }
             }
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             if ($this->group) {
                 $query .= (string) $this->group;
             }
             if ($this->having) {
                 $query .= (string) $this->having;
             }
             if ($this->order) {
                 $query .= (string) $this->order;
             }
             if ($this->forUpdate) {
                 $query .= (string) $this->forUpdate;
             } else {
                 if ($this->forShare) {
                     $query .= (string) $this->forShare;
                 }
             }
             if ($this->noWait) {
                 $query .= (string) $this->noWait;
             }
             break;
         case 'update':
             $query .= (string) $this->update;
             $query .= (string) $this->set;
             if ($this->join) {
                 $onWord = ' ON ';
                 // Workaround for special case of JOIN with UPDATE
                 foreach ($this->join as $join) {
                     $joinElem = $join->getElements();
                     $joinArray = explode($onWord, $joinElem[0]);
                     $this->from($joinArray[0]);
                     $this->where($joinArray[1]);
                 }
                 $query .= (string) $this->from;
             }
             if ($this->where) {
                 $query .= (string) $this->where;
             }
             break;
         case 'insert':
             $query .= (string) $this->insert;
             if ($this->values) {
                 if ($this->columns) {
                     $query .= (string) $this->columns;
                 }
                 $elements = $this->values->getElements();
                 if (!$elements[0] instanceof $this) {
                     $query .= ' VALUES ';
                 }
                 $query .= (string) $this->values;
                 if ($this->returning) {
                     $query .= (string) $this->returning;
                 }
             }
             break;
         default:
             $query = parent::__toString();
             break;
     }
     if ($this instanceof F0FDatabaseQueryLimitable) {
         $query = $this->processLimit($query, $this->limit, $this->offset);
     }
     return $query;
 }