コード例 #1
0
ファイル: delete.php プロジェクト: ascseb/database
 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(Database $db)
 {
     // Start a deletion query
     $query = 'DELETE FROM ' . $db->quote_table($this->_table);
     if (!empty($this->_where)) {
         // Add deletion conditions
         $query .= ' WHERE ' . Database_Query_Builder::compile_conditions($db, $this->_where);
     }
     return $query;
 }
コード例 #2
0
ファイル: select.php プロジェクト: jimktrains/rccms
 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(Database $db)
 {
     // Callback to quote identifiers
     $quote_ident = array($db, 'quote_identifier');
     // Start a selection query
     $query = 'SELECT ';
     if ($this->_distinct === TRUE) {
         // Select only unique results
         $query .= 'DISTINCT ';
     }
     if (empty($this->_select)) {
         // Select all columns
         $query .= '*';
     } else {
         // Select all columns
         $query .= implode(', ', array_map($quote_ident, $this->_select));
     }
     if (!empty($this->_from)) {
         // Set tables to select from
         $query .= ' FROM ' . implode(', ', array_map(array($db, 'quote_table'), $this->_from));
     }
     if (!empty($this->_join)) {
         // Add tables to join
         $query .= ' ' . Database_Query_Builder::compile_join($db, $this->_join);
     }
     if (!empty($this->_where)) {
         // Add selection conditions
         $query .= ' WHERE ' . Database_Query_Builder::compile_conditions($db, $this->_where);
     }
     if (!empty($this->_group_by)) {
         // Add sorting
         $query .= ' GROUP BY ' . implode(', ', array_map($quote_ident, $this->_group_by));
     }
     if (!empty($this->_having)) {
         // Add filtering conditions
         $query .= ' HAVING ' . Database_Query_Builder::compile_conditions($db, $this->_having);
     }
     if (!empty($this->_order_by)) {
         // Add sorting
         $query .= ' ' . Database_Query_Builder::compile_order_by($db, $this->_order_by);
     }
     if ($this->_limit !== NULL) {
         // Add limiting
         $query .= ' LIMIT ' . $this->_limit;
     }
     if ($this->_offset !== NULL) {
         // Add offsets
         $query .= ' OFFSET ' . $this->_offset;
     }
     return $query;
 }
コード例 #3
0
ファイル: update.php プロジェクト: ascseb/database
 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(Database $db)
 {
     // Start an update query
     $query = 'UPDATE ' . $db->quote_table($this->_table);
     $update = array();
     foreach ($this->_set as $set) {
         // Split the set
         list($column, $value) = $set;
         // Quote the column name
         $column = $db->quote_identifier($column);
         $update[$column] = $column . ' = ' . $db->quote($value);
     }
     // Add the columns to update
     $query .= ' SET ' . implode(', ', $update);
     if (!empty($this->_where)) {
         // Add selection conditions
         $query .= ' WHERE ' . Database_Query_Builder::compile_conditions($db, $this->_where);
     }
     return $query;
 }