Example #1
0
 /**
  * Magic function to convert the query to a string.
  *
  * @return  string	The completed query.
  *
  * @since   2.0
  */
 public function __toString()
 {
     $query = '';
     switch ($this->type) {
         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;
         default:
             $query = parent::__toString();
             break;
     }
     return $query;
 }