protected function add_column($table, $column, $data_type, $options = array())
 {
     $cmd = new SDBCommand('ALTER TABLE @table ADD @column ');
     $cmd->set('table', $table, SDB::TableName);
     $cmd->set('column', $column, SDB::FieldName);
     if (array_key_exists(strtolower($data_type), $this->_type_mappings)) {
         $data_type = $this->_type_mappings[strtolower($data_type)];
         if (is_array($data_type)) {
             $options = $options + $data_type[1];
             $data_type = $data_type[0];
         }
     }
     if (array_key_exists(strtolower($data_type), $this->_type_defaults)) {
         $options = $options + $this->_type_defaults[strtolower($data_type)];
     }
     $cmd->command .= strtoupper($data_type);
     if (strtolower($data_type) == 'enum') {
         $values = array();
         if (array_key_exists('values', $options)) {
             $values = $options['values'];
         } elseif (array_key_exists('options', $options)) {
             $values = $options['options'];
         }
         if (!is_array($values) || !count($values)) {
             throw new Exception('Invalid enum values');
         }
         foreach ($values as &$val) {
             $val = SDB::quote($val);
         }
         $cmd->command .= '(' . join(',', $values) . ')';
     } elseif (array_key_exists('size', $options) && $options['size'] > 0) {
         $cmd->command .= '(' . $options['size'] . ')';
     }
     if (array_key_exists('unsigned', $options) && $options['unsigned']) {
         $cmd->command .= ' UNSIGNED';
     }
     $cmd->command .= array_key_exists('null', $options) && $options['null'] ? ' NULL' : ' NOT NULL';
     $cmd->execute();
 }
Example #2
0
 protected function update_positions($position = 0)
 {
     $parent_childs = $this->parent_node == null ? self::get_root_nodes() : $this->parent_node->childs;
     $replace_data = array();
     $pos = 1;
     foreach ($parent_childs as $nd) {
         if ($nd->id != $this->id) {
             if ($pos == $position) {
                 $pos++;
             }
             if ($nd->position != $pos) {
                 $replace_data[] = sprintf("(%s,%s,%s,%s,%s,%s,%s)", SDB::quote($nd->id), SDB::quote($nd->path), SDB::quote($nd->name), SDB::quote($nd->title), SDB::quote($nd->type), SDB::quote($nd->flags), SDB::quote($pos));
             }
             $pos++;
         }
     }
     if (count($replace_data)) {
         $cmd = new SDBCommand("REPLACE INTO `nodes` (`id`,`path`,`name`,`title`,`type`,`flags`,`position`) VALUES " . join(',', $replace_data));
         $cmd->execute();
     }
     return $pos;
 }