Ejemplo n.º 1
0
 /**
  * Returns the beginning of any SQL statement, depending on $this->queryType.
  *
  * @return string
  */
 protected function getTypeSQL()
 {
     $sql = '';
     $quotedTableName = $this->orm->quoteIdentifier($this->tableName);
     switch ($this->queryType) {
         case self::QUERY_TYPE_SELECT:
             $top = '';
             if ($this->limit !== null && $this->detectLimitStyle() === self::LIMIT_STYLE_TOP) {
                 $top = ' TOP ' . $this->limit;
             }
             $sql = sprintf('SELECT %s * FROM %s', $top, $quotedTableName);
             break;
         case self::QUERY_TYPE_DELETE:
             $sql = sprintf('DELETE FROM %s', $quotedTableName);
             break;
         case self::QUERY_TYPE_UPDATE:
             $sets = array();
             foreach ($this->modelData as $columnName => $columnValue) {
                 $sets[] = sprintf('%s = ?', $this->orm->quoteIdentifier($columnName));
                 $this->parameters[] = $columnValue;
             }
             $sql = sprintf('UPDATE %s SET %s', $quotedTableName, implode(',', $sets));
             break;
         case self::QUERY_TYPE_INSERT:
             $quotedColumnNames = $this->orm->quoteIdentifier(array_keys($this->modelData));
             $placeholders = implode(',', array_fill(0, count($this->modelData), '?'));
             $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $quotedTableName, $quotedColumnNames, $placeholders);
             $this->parameters = array_merge($this->parameters, array_values($this->modelData));
             break;
     }
     return $sql;
 }