Exemple #1
0
 public function compile($db = NULL)
 {
     if (!is_object($db)) {
         // Get connected to the DB
         $db = Database::instance($db);
     }
     // Start the insert query
     $query = 'INSERT INTO ' . $db->quote_table($this->_table);
     // Add the column names
     $query .= ' (' . implode(', ', array_map(array($db, 'quote_column'), $this->_columns)) . ') ';
     if (is_array($this->_values)) {
         // Callback for quoting values
         $quote = array($db, 'quote');
         $groups = array();
         foreach ($this->_values as $group) {
             foreach ($group as $offset => $value) {
                 if ((is_string($value) and array_key_exists($value, $this->_parameters)) === FALSE) {
                     // Quote the value, it is not a parameter
                     $group[$offset] = $db->quote($value);
                 }
             }
             $groups[] = '(' . implode(', ', $group) . ')';
         }
         // Add the values
         $query .= 'VALUES ' . implode(', ', $groups);
     }
     $this->_sql = $query;
     return parent::compile($db);
 }
Exemple #2
0
 public function compile($db = NULL)
 {
     if (!is_object($db)) {
         // Get connected to the DB
         $db = Database::instance($db);
     }
     // Start the insert query
     $query = 'TRUNCATE TABLE ' . $db->quote_table($this->_table);
     $this->_sql = $query;
     return parent::compile($db);
 }