Skip to content

Commit

Permalink
Add modifyColumn function
Browse files Browse the repository at this point in the history
Add function to Queries and DB classes to allow modification of column
types
  • Loading branch information
samerton committed Aug 18, 2016
1 parent 315c3d4 commit 902f355
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/classes/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ public function alterTable($name, $column, $attributes) {
return false;
}

public function modifyColumn($name, $column, $attributes) {
$name = $this->_prefix . $name;
$sql = "ALTER TABLE `{$name}` MODIFY {$column} {$attributes}";
if(!$this->createQuery($sql)->error()) {
return $this;
}
return false;
}

public function removeColumn($name, $column) {
$name = $this->_prefix . $name;
$sql = "ALTER TABLE `{$name}` DROP COLUMN {$column}";
Expand Down
6 changes: 6 additions & 0 deletions core/classes/Queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public function alterTable($table, $column, $attributes){
}
}

public function modifyColumn($table, $column, $attributes){
if(!$this->_db->modifyColumn($table, $column, $attributes)) {
throw new Exception('There was a problem modifying the column ' . htmlspecialchars($column));
}
}

public function removeColumn($table, $column){
if($this->_db->removeColumn($table, $column)){
throw new Exception('Unable to drop column.');
Expand Down

0 comments on commit 902f355

Please sign in to comment.