private function getActionSql($action, $tab, $sql)
    {
        $result = 'ALTER TABLE `' . $tab . '` ';
        $action = strtolower($action);
        $keyField = '`?\w`?(?:\(\d+\))?';//matches `name`(10)
        $keyFieldList = '(?:' . $keyField . '(?:,\s?)?)+';//matches `name`(10),`desc`(255)

        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\(' . $keyFieldList . '\))/i', $sql, $m)) {   //key and index operations
            $type = strtolower(trim($m[1]));
            $name = trim($m[2]);
            $fields = trim($m[3]);

            switch ($action) {
                case 'drop':
                    if ($type == 'primary') {
                        $result .= 'DROP PRIMARY KEY';
                    } else {
                        $result .= 'DROP INDEX `' . $name . '`';
                    }
                    break;
                case 'add':
                    if ($type == 'primary') {
                        $result .= 'ADD PRIMARY KEY ' . $fields;
                    } elseif ($type == '') {
                        $result .= 'ADD INDEX `' . $name . '` ' . $fields;
                    } else {
                        $result .= 'ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields;//fulltext or unique
                    }
                    break;
                case 'modify':
                    if ($type == 'primary') {
                        $result .= 'DROP PRIMARY KEY, ADD PRIMARY KEY ' . $fields;
                    } elseif ($type == '') {
                        $result .= 'DROP INDEX `' . $name . '`, ADD INDEX `' . $name . '` ' . $fields;
                    } else {
                        $result .= 'DROP INDEX `' . $name . '`, ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields;//fulltext or unique
                    }
                    break;

            }
        } else // fields operations
        {
            $sql = rtrim(trim($sql), ',');
            $result .= strtoupper($action);
            if ($action == 'drop') {
                $spacePos = strpos($sql, ' ');
                $result .= ' ' . substr($sql, 0, $spacePos);
            } else {
                $result .= ' ' . $sql;
            }
        }

        return $result;
    }
private function getActionSql($action, $tab, $sql)
    {
        $result = 'ALTER TABLE `' . $tab . '` ';
        $action = strtolower($action);
        $keyField = '`?\w`?(?:\(\d+\))?';//matches `name`(10)
        $keyFieldList = '(?:' . $keyField . '(?:,\s?)?)+';//matches `name`(10),`desc`(255)

        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\(' . $keyFieldList . '\))/i', $sql, $m)) {   //key and index operations
            $type = strtolower(trim($m[1]));
            $name = trim($m[2]);
            $fields = trim($m[3]);

            switch ($action) {
                case 'drop':
                    if ($type == 'primary') {
                        $result .= 'DROP PRIMARY KEY';
                    } else {
                        $result .= 'DROP INDEX `' . $name . '`';
                    }
                    break;
                case 'add':
                    if ($type == 'primary') {
                        $result .= 'ADD PRIMARY KEY ' . $fields;
                    } elseif ($type == '') {
                        $result .= 'ADD INDEX `' . $name . '` ' . $fields;
                    } else {
                        $result .= 'ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields;//fulltext or unique
                    }
                    break;
                case 'modify':
                    if ($type == 'primary') {
                        $result .= 'DROP PRIMARY KEY, ADD PRIMARY KEY ' . $fields;
                    } elseif ($type == '') {
                        $result .= 'DROP INDEX `' . $name . '`, ADD INDEX `' . $name . '` ' . $fields;
                    } else {
                        $result .= 'DROP INDEX `' . $name . '`, ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields;//fulltext or unique
                    }
                    break;

            }
        } else // fields operations
        {
            $sql = rtrim(trim($sql), ',');
            $result .= strtoupper($action);
            if ($action == 'drop') {
                $spacePos = strpos($sql, ' ');
                $result .= ' ' . substr($sql, 0, $spacePos);
            } else {
                $result .= ' ' . $sql;
            }
        }

        return $result;
    }
private function getActionSql ( $ action , $ tab , $ sql ) { $ result = 'ALTER TABLE `' . $ tab . '` ' ; $ action = strtolower ( $ action ) ; $ keyField = '`?\w`?(?:\(\d+\))?' ; //matches `name`(10) $ keyFieldList = '(?:' . $ keyField . '(?:,\s?)?)+' ; //matches `name`(10),`desc`(255) if ( preg_match ( '/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\(' . $ keyFieldList . '\))/i' , $ sql , $ m ) ) { //key and index operations $ type = strtolower ( trim ( $ m [ 1 ] ) ) ; $ name = trim ( $ m [ 2 ] ) ; $ fields = trim ( $ m [ 3 ] ) ; switch ( $ action ) { case 'drop' : if ( $ type == 'primary' ) { $ result .= 'DROP PRIMARY KEY' ; } else { $ result .= 'DROP INDEX `' . $ name . '`' ; } break ; case 'add' : if ( $ type == 'primary' ) { $ result .= 'ADD PRIMARY KEY ' . $ fields ; } elseif ( $ type == '' ) { $ result .= 'ADD INDEX `' . $ name . '` ' . $ fields ; } else { $ result .= 'ADD ' . strtoupper ( $ type ) . ' `' . $ name . '` ' . $ fields ; //fulltext or unique } break ; case 'modify' : if ( $ type == 'primary' ) { $ result .= 'DROP PRIMARY KEY, ADD PRIMARY KEY ' . $ fields ; } elseif ( $ type == '' ) { $ result .= 'DROP INDEX `' . $ name . '`, ADD INDEX `' . $ name . '` ' . $ fields ; } else { $ result .= 'DROP INDEX `' . $ name . '`, ADD ' . strtoupper ( $ type ) . ' `' . $ name . '` ' . $ fields ; //fulltext or unique } break ; } } else // fields operations { $ sql = rtrim ( trim ( $ sql ) , ',' ) ; $ result .= strtoupper ( $ action ) ; if ( $ action == 'drop' ) { $ spacePos = strpos ( $ sql , ' ' ) ; $ result .= ' ' . substr ( $ sql , 0 , $ spacePos ) ; } else { $ result .= ' ' . $ sql ; } } return $ result ; }
Compiles update sql
@access private
@param string $action - 'drop', 'add' or 'modify'
@param string $tab table name
@param string $sql definition of the element to change
@return string update sql
Compiles update sql