summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Components/AlterOperation.php37
-rw-r--r--src/Statements/AlterStatement.php30
2 files changed, 50 insertions, 17 deletions
diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php
index d0b09f1..d4ce77a 100644
--- a/src/Components/AlterOperation.php
+++ b/src/Components/AlterOperation.php
@@ -26,19 +26,31 @@ class AlterOperation extends Component
{
/**
- * All alter operations.
- *
+ * All database options
+ *
* @var array
*/
- public static $OPTIONS = array(
+ public static $DB_OPTIONS = array(
+ 'CHARACTER SET' => array(1, 'var'),
+ 'CHARSET' => array(1, 'var'),
+ 'DEFAULT CHARACTER SET' => array(1, 'var'),
+ 'DEFAULT CHARSET' => array(1, 'var'),
+ 'UPGRADE' => array(1, 'var'),
+ 'COLLATE' => array(2, 'var'),
+ 'DEFAULT COLLATE' => array(2, 'var'),
+ );
- // table_options
+ /**
+ * All table options
+ *
+ * @var array
+ */
+ public static $TABLE_OPTIONS = array(
'ENGINE' => array(1, 'var='),
'AUTO_INCREMENT' => array(1, 'var='),
'AVG_ROW_LENGTH' => array(1, 'var'),
'MAX_ROWS' => array(1, 'var'),
'ROW_FORMAT' => array(1, 'var'),
-
'ADD' => 1,
'ALTER' => 1,
'ANALYZE' => 1,
@@ -60,6 +72,7 @@ class AlterOperation extends Component
'RENAME' => 1,
'REORGANIZE' => 1,
'REPAIR' => 1,
+ 'UPGRADE' => 1,
'COLUMN' => 2,
'CONSTRAINT' => 2,
@@ -75,11 +88,15 @@ class AlterOperation extends Component
'SPATIAL' => 2,
'TABLESPACE' => 2,
'INDEX' => 2,
+ );
- 'DEFAULT CHARACTER SET' => array(3, 'var'),
- 'DEFAULT CHARSET' => array(3, 'var'),
-
- 'COLLATE' => array(4, 'var'),
+ /**
+ * All view options
+ *
+ * @var array
+ */
+ public static $VIEW_OPTIONS = array(
+ 'AS' => 1,
);
/**
@@ -165,7 +182,7 @@ class AlterOperation extends Component
}
if ($state === 0) {
- $ret->options = OptionsArray::parse($parser, $list, static::$OPTIONS);
+ $ret->options = OptionsArray::parse($parser, $list, $options);
$state = 1;
} elseif ($state === 1) {
$ret->field = Expression::parse(
diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php
index c8786bd..4aea0d6 100644
--- a/src/Statements/AlterStatement.php
+++ b/src/Statements/AlterStatement.php
@@ -51,6 +51,15 @@ class AlterStatement extends Statement
'ONLINE' => 1,
'OFFLINE' => 1,
'IGNORE' => 2,
+
+ 'DATABASE' => 3,
+ 'EVENT' => 3,
+ 'FUNCTION' => 3,
+ 'PROCEDURE' => 3,
+ 'SERVER' => 3,
+ 'TABLE' => 3,
+ 'TABLESPACE' => 3,
+ 'VIEW' => 3,
);
/**
@@ -67,16 +76,14 @@ class AlterStatement extends Statement
$list,
static::$OPTIONS
);
-
- // Skipping `TABLE`.
- $list->getNextOfTypeAndValue(Token::TYPE_KEYWORD, 'TABLE');
+ ++$list->idx;
// Parsing affected table.
$this->table = Expression::parse(
$parser,
$list,
array(
- 'parseField' => 'column',
+ 'parseField' => 'table',
'breakOnAlias' => true,
)
);
@@ -114,7 +121,16 @@ class AlterStatement extends Statement
}
if ($state === 0) {
- $this->altered[] = AlterOperation::parse($parser, $list);
+ $options = array();
+ if ($this->options->has('DATABASE')) {
+ $options = AlterOperation::$DB_OPTIONS;
+ } elseif ($this->options->has('TABLE')) {
+ $options = AlterOperation::$TABLE_OPTIONS;
+ } elseif ($this->options->has('VIEW')) {
+ $options = AlterOperation::$VIEW_OPTIONS;
+ }
+
+ $this->altered[] = AlterOperation::parse($parser, $list, $options);
$state = 1;
} elseif ($state === 1) {
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) {
@@ -135,7 +151,7 @@ class AlterStatement extends Statement
}
return 'ALTER ' . OptionsArray::build($this->options)
- . ' TABLE ' . Expression::build($this->table)
- . ' ' . implode(', ', $tmp);
+ . ' ' . Expression::build($this->table)
+ . ' ' . implode(', ', $tmp);
}
}