mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-08-02 19:14:27 +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;";
|
$newq .= ";ALTER TABLE $table RENAME COLUMN $col TO $newcol;";
|
||||||
$sql = $newq;
|
$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+\(([^\)]+)\)/';
|
$pattern = '/ALTER TABLE\s+(\w+)\s+ADD (UNIQUE |)KEY\s+([^\s]+)\s+\(([^\)]+)\)/';
|
||||||
if( 1 === preg_match( $pattern, $sql, $matches))
|
if( 1 === preg_match( $pattern, $sql, $matches))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user