mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-29 17:27:13 +02:00
Added "ADD COLUMN" support to the "ALTER TABLE" handling code
git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@429284 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
@ -80,6 +80,27 @@ WHERE bc.oid = i.indrelid
|
||||
$newq .= ";ALTER TABLE $table RENAME COLUMN $col TO $newcol;";
|
||||
$sql = $newq;
|
||||
}
|
||||
$pattern = '/ALTER TABLE\s+(\w+)\s+ADD COLUMN\s+([^\s]+)\s+([^ ]+)( unsigned|)\s+(NOT NULL|)\s*(default (.+)|)/';
|
||||
if( 1 === preg_match( $pattern, $sql, $matches))
|
||||
{
|
||||
$table = $matches[1];
|
||||
$col = $matches[2];
|
||||
$type = $matches[3];
|
||||
if( isset($GLOBALS['pg4wp_ttr'][$type]))
|
||||
$type = $GLOBALS['pg4wp_ttr'][$type];
|
||||
$unsigned = $matches[4];
|
||||
$notnull = $matches[5];
|
||||
$default = $matches[6];
|
||||
$defval = $matches[7];
|
||||
if( isset($GLOBALS['pg4wp_ttr'][$defval]))
|
||||
$defval = $GLOBALS['pg4wp_ttr'][$defval];
|
||||
$newq = "ALTER TABLE $table ADD COLUMN $col $type";
|
||||
if( !empty($default))
|
||||
$newq .= " DEFAULT $defval";
|
||||
if( !empty($notnull))
|
||||
$newq .= " NOT NULL";
|
||||
$sql = $newq;
|
||||
}
|
||||
$pattern = '/ALTER TABLE\s+(\w+)\s+ADD (UNIQUE |)KEY\s+([^\s]+)\s+\(([^\)]+)\)/';
|
||||
if( 1 === preg_match( $pattern, $sql, $matches))
|
||||
{
|
||||
|
Reference in New Issue
Block a user