/**
  * 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 '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;
 }
 /**
  * Clear data from the query or a specific clause of the query.
  *
  * @param   string  $clause  Optionally, the name of the clause to clear, or nothing to clear the whole query.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function clear($clause = null)
 {
     switch ($clause) {
         case 'limit':
             $this->limit = null;
             break;
         case 'offset':
             $this->offset = null;
             break;
         case 'forUpdate':
             $this->forUpdate = null;
             break;
         case 'forShare':
             $this->forShare = null;
             break;
         case 'noWait':
             $this->noWait = null;
             break;
         case 'returning':
             $this->returning = null;
             break;
         case 'select':
         case 'update':
         case 'delete':
         case 'insert':
         case 'from':
         case 'join':
         case 'set':
         case 'where':
         case 'group':
         case 'having':
         case 'order':
         case 'columns':
         case 'values':
             parent::clear($clause);
             break;
         default:
             $this->type = null;
             $this->limit = null;
             $this->offset = null;
             $this->forUpdate = null;
             $this->forShare = null;
             $this->noWait = null;
             $this->returning = null;
             parent::clear($clause);
             break;
     }
     return $this;
 }
 /**
  * Method to append the primary keys for this table to a query.
  *
  * @param   Query  $query  A query object to append.
  * @param   mixed  $pk     Optional primary key parameter.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function appendPrimaryKeys($query, $pk = null)
 {
     if (is_null($pk)) {
         foreach ($this->_tbl_keys as $k) {
             $query->where($this->_db->quoteName($k) . ' = ' . $this->_db->quote($this->{$k}));
         }
     } else {
         if (is_string($pk)) {
             $pk = array($this->_tbl_key => $pk);
         }
         $pk = (object) $pk;
         foreach ($this->_tbl_keys as $k) {
             $query->where($this->_db->quoteName($k) . ' = ' . $this->_db->quote($pk->{$k}));
         }
     }
 }