summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeven Bansod <devenbansod.bits@gmail.com>2016-09-10 17:28:24 +0530
committerDeven Bansod <devenbansod.bits@gmail.com>2016-09-10 19:20:27 +0530
commit044fe5b24e8d87134353f196b1458c5ae9e887b4 (patch)
tree6ec21d45e5d0b8096b30835dd9723fd61a8397a6
parentbd8936d2d6d1b932211a29cea313749be13bac83 (diff)
downloadsql-parser-044fe5b24e8d87134353f196b1458c5ae9e887b4.zip
sql-parser-044fe5b24e8d87134353f196b1458c5ae9e887b4.tar.gz
sql-parser-044fe5b24e8d87134353f196b1458c5ae9e887b4.tar.bz2
Add special cases for SET CHARACTER SET, CHARSET, NAMES
Fix #51 Fix #74 Signed-off-by: Deven Bansod <devenbansod.bits@gmail.com>
-rw-r--r--src/Components/OptionsArray.php19
-rw-r--r--src/Statements/SetStatement.php29
2 files changed, 48 insertions, 0 deletions
diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php
index 3d2fded..c048e19 100644
--- a/src/Components/OptionsArray.php
+++ b/src/Components/OptionsArray.php
@@ -242,6 +242,25 @@ class OptionsArray extends Component
}
}
+ /*
+ * We reached the end of statement without getting a value
+ * for an option for which a value was required
+ */
+ if ($state === 1
+ && $lastOption
+ && ($lastOption[1] == 'expr'
+ || $lastOption[1] == 'var'
+ || $lastOption[1] == 'var=')
+ ) {
+ $parser->error(
+ sprintf(
+ __('Value/Expression for the option %1$s was expected'),
+ $ret->options[$lastOptionId]['name']
+ ),
+ $list->tokens[$list->idx - 1]
+ );
+ }
+
if (empty($options['_UNSORTED'])) {
ksort($ret->options);
}
diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php
index d412853..a5cffa2 100644
--- a/src/Statements/SetStatement.php
+++ b/src/Statements/SetStatement.php
@@ -10,6 +10,7 @@ namespace SqlParser\Statements;
use SqlParser\Statement;
use SqlParser\Components\SetOperation;
+use SqlParser\Components\OptionsArray;
/**
* `SET` statement.
@@ -35,9 +36,37 @@ class SetStatement extends Statement
);
/**
+ * Possible exceptions in SET statment
+ *
+ * @var array
+ */
+ public static $OPTIONS = array(
+ 'CHARSET' => array(3, 'var'),
+ 'CHARACTER SET' => array(3, 'var'),
+ 'NAMES' => array(3, 'var'),
+ 'PASSWORD' => array(3, 'expr'),
+ );
+
+ /**
+ * Options used in current statement
+ *
+ * @var OptionsArray[]
+ */
+ public $options;
+
+ /**
* The updated values.
*
* @var SetOperation[]
*/
public $set;
+
+ /**
+ * @return string
+ */
+ public function build()
+ {
+ return 'SET ' . OptionsArray::build($this->options)
+ . ' ' . SetOperation::build($this->set);
+ }
}