summaryrefslogtreecommitdiffstats
path: root/src/Fragments/KeyFragment.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-03 21:18:10 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-04 23:41:52 +0300
commitb3eff80030f9bd6d90e65360eb89e18a1be298b2 (patch)
treedb420fef27f24856f4cfaeee008104fdfcb77942 /src/Fragments/KeyFragment.php
parent4dabcc2ae266c022e44294bfbe3344b05e66e266 (diff)
downloadsql-parser-b3eff80030f9bd6d90e65360eb89e18a1be298b2.zip
sql-parser-b3eff80030f9bd6d90e65360eb89e18a1be298b2.tar.gz
sql-parser-b3eff80030f9bd6d90e65360eb89e18a1be298b2.tar.bz2
The context depends on the SQL mode.
Implemented a few more builders. Improved some fragments and statement types. Fixed the noAlias option in FieldFragment. Reordered CREATE statements's options. Updated contexts definitions. Fixed typos. Improved tests.
Diffstat (limited to 'src/Fragments/KeyFragment.php')
-rw-r--r--src/Fragments/KeyFragment.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Fragments/KeyFragment.php b/src/Fragments/KeyFragment.php
index d84c9f6..1964cd2 100644
--- a/src/Fragments/KeyFragment.php
+++ b/src/Fragments/KeyFragment.php
@@ -67,6 +67,16 @@ class KeyFragment extends Fragment
*/
public $options;
+
+ public function __construct($name = null, array $columns = array(),
+ $type = null, $options = null
+ ) {
+ $this->name = $name;
+ $this->columns = $columns;
+ $this->type = $type;
+ $this->options = $options;
+ }
+
/**
* @param Parser $parser The parser that serves as context.
* @param TokensList $list The list of tokens that are being parsed.
@@ -131,6 +141,21 @@ class KeyFragment extends Fragment
--$list->idx;
return $ret;
+ }
+ /**
+ * @param KeyFragment $fragment The fragment to be built.
+ *
+ * @return string
+ */
+ public static function build($fragment)
+ {
+ $ret = $fragment->type . ' ';
+ if (!empty($fragment->name)) {
+ $ret .= Context::escape($fragment->name) . ' ';
+ }
+ $ret .= '(' . implode(', ', Context::escape($fragment->columns)) . ')';
+ $ret .= OptionsFragment::build($fragment->options);
+ return trim($ret);
}
}