コード例 #1
0
ファイル: Insert.class.php プロジェクト: map-framework/map
 /**
  * @return Query
  */
 public function assemble()
 {
     $query = new Query();
     $sql = 'INSERT INTO ' . $query->ph(Query::TYPE_TABLE, $this->getTableName());
     $columnPart = '';
     $valuePart = '';
     foreach ($this->valueList as $columnName => $options) {
         if ($columnPart !== '' && $valuePart !== '') {
             $columnPart .= ', ';
             $valuePart .= ', ';
         }
         $columnPart .= $query->ph(Query::TYPE_COLUMN, $columnName);
         $valuePart .= $query->ph($options['type'], $options['value']);
     }
     $sql .= ' (' . $columnPart . ') VALUES (' . $valuePart . ')';
     return $query->setQuery($sql);
 }
コード例 #2
0
ファイル: Delete.class.php プロジェクト: map-framework/map
 /**
  * @return Query
  */
 public function assemble()
 {
     $query = new Query();
     $sql = 'DELETE FROM ' . $query->ph(Query::TYPE_TABLE, $this->getTableName());
     if (count($this->getConditionList())) {
         $sql .= ' WHERE';
         foreach ($this->getConditionList() as $nr => $condition) {
             if ($nr !== 0) {
                 $sql .= ' &&';
             }
             $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $condition['columnName']);
             $sql .= ' ' . $condition['operator'];
             $sql .= ' ' . $query->ph($condition['type'], $condition['value']);
         }
     }
     if ($this->getLimit() >= 1) {
         $sql .= ' LIMIT ' . $query->ph(Query::TYPE_INT, $this->getLimit());
     }
     return $query->setQuery($sql);
 }
コード例 #3
0
ファイル: Update.class.php プロジェクト: map-framework/map
 /**
  * @return Query
  */
 public function assemble()
 {
     $query = new Query();
     $sql = 'UPDATE ' . $query->ph(Query::TYPE_TABLE, $this->getTableName()) . ' SET';
     if (count($this->getAssignmentList()) === 0) {
         throw new RuntimeException('assignmentList is empty');
     }
     foreach ($this->getAssignmentList() as $columnName => $options) {
         if (isset($notFirst)) {
             $sql .= ',';
         }
         $notFirst = true;
         $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $columnName);
         $sql .= '=';
         $sql .= $query->ph($options['type'], $options['value']);
     }
     if (count($this->getConditionList())) {
         $sql .= ' WHERE';
         foreach ($this->getConditionList() as $nr => $condition) {
             if ($nr !== 0) {
                 $sql .= ' &&';
             }
             $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $condition['columnName']);
             $sql .= ' ' . $condition['operator'] . ' ';
             $sql .= $query->ph($condition['type'], $condition['value']);
         }
     }
     if ($this->getLimit() >= 1) {
         $sql .= ' LIMIT ' . $query->ph(Query::TYPE_INT, $this->getLimit());
     }
     return $query->setQuery($sql);
 }
コード例 #4
0
ファイル: Select.class.php プロジェクト: map-framework/map
 /**
  * @return Query
  */
 public function assemble()
 {
     $query = new Query();
     $sql = 'SELECT';
     if ($this->isDistinctEnabled()) {
         $sql .= ' DISTINCT';
     }
     if (count($this->getExpressionList())) {
         foreach ($this->getExpressionList() as $nr => $expression) {
             if ($nr !== 0) {
                 $sql .= ',';
             }
             $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $expression);
         }
     } else {
         $sql .= ' *';
     }
     $sql .= ' FROM ' . $query->ph(Query::TYPE_TABLE, $this->getTableName());
     if (count($this->getConditionList())) {
         $sql .= ' WHERE';
         foreach ($this->getConditionList() as $nr => $condition) {
             if ($nr !== 0) {
                 $sql .= ' &&';
             }
             $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $condition['columnName']);
             $sql .= ' ' . $condition['operator'];
             $sql .= ' ' . $query->ph($condition['type'], $condition['value']);
         }
     }
     if (count($this->getOrderByList())) {
         $sql .= ' ORDER BY';
         foreach ($this->getOrderByList() as $nr => $orderBy) {
             if ($nr !== 0) {
                 $sql .= ',';
             }
             $sql .= ' ' . $query->ph(Query::TYPE_COLUMN, $orderBy['columnName']);
             if ($orderBy['desc'] === true) {
                 $sql .= ' DESC';
             }
         }
     }
     if ($this->getLimit() >= 1) {
         $sql .= ' LIMIT ' . $query->ph(Query::TYPE_INT, $this->getLimit());
         if ($this->getOffset() >= 1) {
             $sql .= ' OFFSET ' . $query->ph(Query::TYPE_INT, $this->getOffset());
         }
     }
     return $query->setQuery($sql);
 }