/** * Create an index * * The presence of an existing index with the same name or column set is not checked. * * @param string $name Index name * @param mixed Column name or array of column names * @param bool $unique Create unique index, default: false */ public function createIndex($name, $columns, $unique = false) { if (!is_array($columns)) { $columns = array($columns); } foreach ($columns as &$column) { $column = $this->_database->prepareIdentifier($column); } $this->_database->exec(sprintf('CREATE %s INDEX %s ON %s (%s)', $unique ? 'UNIQUE' : '', $this->_database->prepareIdentifier($name), $this->_database->prepareIdentifier($this->_name), implode(', ', $columns))); // Reset index cache to force re-read by next getIndexes() invokation $this->_indexes = array(); }
/** * DBMS-specific implementation for setting a column's default value **/ protected function _setDefault() { if ($this->_default === null) { $this->_table->alter(sprintf('ALTER COLUMN %s DROP DEFAULT', $this->_database->prepareIdentifier($this->_name))); } else { $this->_table->alter(sprintf('ALTER COLUMN %s SET DEFAULT %s', $this->_database->prepareIdentifier($this->_name), $this->_database->prepareValue($this->_default, $this->_datatype))); } }