Plugin Directory

Changeset 429284


Ignore:
Timestamp:
08/27/2011 12:35:29 AM (15 years ago)
Author:
hawk__
Message:

Added "ADD COLUMN" support to the "ALTER TABLE" handling code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postgresql-for-wordpress/trunk/pg4wp/driver_pgsql_install.php

    r429283 r429284  
    8181                $sql = $newq;
    8282            }
     83            $pattern = '/ALTER TABLE\s+(\w+)\s+ADD COLUMN\s+([^\s]+)\s+([^ ]+)( unsigned|)\s+(NOT NULL|)\s*(default (.+)|)/';
     84            if( 1 === preg_match( $pattern, $sql, $matches))
     85            {
     86                $table = $matches[1];
     87                $col = $matches[2];
     88                $type = $matches[3];
     89                if( isset($GLOBALS['pg4wp_ttr'][$type]))
     90                    $type = $GLOBALS['pg4wp_ttr'][$type];
     91                $unsigned = $matches[4];
     92                $notnull = $matches[5];
     93                $default = $matches[6];
     94                $defval = $matches[7];
     95                if( isset($GLOBALS['pg4wp_ttr'][$defval]))
     96                    $defval = $GLOBALS['pg4wp_ttr'][$defval];
     97                $newq = "ALTER TABLE $table ADD COLUMN $col $type";
     98                if( !empty($default))
     99                    $newq .= " DEFAULT $defval";
     100                if( !empty($notnull))
     101                    $newq .= " NOT NULL";
     102                $sql = $newq;
     103            }
    83104            $pattern = '/ALTER TABLE\s+(\w+)\s+ADD (UNIQUE |)KEY\s+([^\s]+)\s+\(([^\)]+)\)/';
    84105            if( 1 === preg_match( $pattern, $sql, $matches))
Note: See TracChangeset for help on using the changeset viewer.