static function check_init() { if (!count(SDB::get_tables_list())) { $sql = file_get_contents(BASE . 'conf/simple.' . conf('db.type') . '.sql'); if (conf('db.type') == 'mysql') { $spl = explode(';', $sql); foreach ($spl as $part) { $cmd = new SDBCommand($part); $cmd->execute(); } } else { $cmd = new SDBCommand($sql); $cmd->execute(); } SDB::reset_cached_data(); $fl = new FileItem(); $fl->parent_id = 0; $fl->name = 's'; $fl->type = FileItem::Folder; $fl->save(); Initiator::fill_db(S_BASE, $fl->id); } }
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(); }
function set_utf8_connection($db) { $cmd = new SDBCommand('SET NAMES utf8', $db); $cmd->execute(); }
protected function apply_migration($id, $class_name, $method, $skip = false) { if ($skip) { $this->message("Skip {$method}: {$class_name}"); } else { $this->message("Migrate {$method}: {$class_name}"); require $this->get_migrations_dir() . "{$class_name}.php"; $migration = new $class_name($this); $cmd = new SDBCommand("BEGIN"); $cmd->execute(); try { call_user_func(array($migration, $method)); } catch (Exception $e) { if ($e->getPrevious()) { $e = $e->getPrevious(); } if ($e instanceof PDOException) { $this->message($e->getMessage()); } else { $this->message('Exception "' . get_class($e) . '" in ' . $e->getFile() . ':' . $e->getLine()); $this->message($e->getMessage()); $this->message($e->getTraceAsString()); } return false; } $cmd = new SDBCommand("COMMIT"); $cmd->execute(); } if ($method == 'down') { $cmd = new SDBCommand("DELETE FROM @schema_name WHERE `id`=@id"); } else { $cmd = new SDBCommand("INSERT INTO @schema_name (`id`) VALUES(@id)"); } $cmd->set('schema_name', self::SCHEMA_NAME, SDB::TableName); $cmd->set('id', $id, SDB::String); $cmd->execute(); return true; }
public static function remove_by_id($classname, $id) { $tmp = new $classname(); $tmp->_init(); $cmd = new SDBCommand("DELETE FROM @_db_table WHERE @_f_id=@id"); $cmd->set('_db_table', $tmp->_db_table, SDB::TableName); $cmd->set('_f_id', $tmp->_db_key, SDB::FieldName); $cmd->set('id', $id, SDB::Int); $cmd->execute(); }
<?php if (!count(SDB::get_tables_list())) { $sql = file_get_contents(BASE . '../common/examples.' . conf('db.type') . '.sql'); if (conf('db.type') == 'mysql') { $spl = explode(';', $sql); foreach ($spl as $part) { $cmd = new SDBCommand($part); $cmd->execute(); } } else { $cmd = new SDBCommand($sql); $cmd->execute(); } SDB::reset_cached_data(); }
public static function unlock() { $cmd = new SDBCommand("COMMIT"); $cmd->execute(); }