diff options
author | Michal Čihař <michal@cihar.com> | 2017-02-07 12:08:13 +0100 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2017-02-07 12:08:13 +0100 |
commit | 72f95283f576cc397e26759a95d61712bb6c6159 (patch) | |
tree | bffa73b7316e1a21d540d4f74d301b09c060f98c /src | |
parent | 8f2e0bb9be24504e5241862ab10ee92a9d8db797 (diff) | |
download | sql-parser-72f95283f576cc397e26759a95d61712bb6c6159.zip sql-parser-72f95283f576cc397e26759a95d61712bb6c6159.tar.gz sql-parser-72f95283f576cc397e26759a95d61712bb6c6159.tar.bz2 |
Split select flags calculation to separate method
It's the most complex case right now, so let's separate it.
Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Utils/Query.php | 138 |
1 files changed, 76 insertions, 62 deletions
diff --git a/src/Utils/Query.php b/src/Utils/Query.php index e0ca0cb..6e64021 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -206,6 +206,81 @@ class Query ); /** + * Gets an array with flags select statement has. + * + * @param Statement|null $statement the statement to be processed + * @param array $flagsi flags set so far + * + * @return array + */ + private static function _getFlagsSelect($statement, $flags) + { + $flags['querytype'] = 'SELECT'; + $flags['is_select'] = true; + + if (!empty($statement->from)) { + $flags['select_from'] = true; + } + + if ($statement->options->has('DISTINCT')) { + $flags['distinct'] = true; + } + + if ((!empty($statement->group)) || (!empty($statement->having))) { + $flags['is_group'] = true; + } + + if ((!empty($statement->into)) + && ($statement->into->type === 'OUTFILE') + ) { + $flags['is_export'] = true; + } + + $expressions = $statement->expr; + if (!empty($statement->join)) { + foreach ($statement->join as $join) { + $expressions[] = $join->expr; + } + } + + foreach ($expressions as $expr) { + if (!empty($expr->function)) { + if ($expr->function === 'COUNT') { + $flags['is_count'] = true; + } elseif (in_array($expr->function, static::$FUNCTIONS)) { + $flags['is_func'] = true; + } + } + if (!empty($expr->subquery)) { + $flags['is_subquery'] = true; + } + } + + if ((!empty($statement->procedure)) + && ($statement->procedure->name === 'ANALYSE') + ) { + $flags['is_analyse'] = true; + } + + if (!empty($statement->group)) { + $flags['group'] = true; + } + + if (!empty($statement->having)) { + $flags['having'] = true; + } + + if (!empty($statement->union)) { + $flags['union'] = true; + } + + if (!empty($statement->join)) { + $flags['join'] = true; + } + return $flags; + } + + /** * Gets an array with flags this statement has. * * @param Statement|null $statement the statement to be processed @@ -270,68 +345,7 @@ class Query $flags['is_replace'] = true; $flags['is_insert'] = true; } elseif ($statement instanceof SelectStatement) { - $flags['querytype'] = 'SELECT'; - $flags['is_select'] = true; - - if (!empty($statement->from)) { - $flags['select_from'] = true; - } - - if ($statement->options->has('DISTINCT')) { - $flags['distinct'] = true; - } - - if ((!empty($statement->group)) || (!empty($statement->having))) { - $flags['is_group'] = true; - } - - if ((!empty($statement->into)) - && ($statement->into->type === 'OUTFILE') - ) { - $flags['is_export'] = true; - } - - $expressions = $statement->expr; - if (!empty($statement->join)) { - foreach ($statement->join as $join) { - $expressions[] = $join->expr; - } - } - - foreach ($expressions as $expr) { - if (!empty($expr->function)) { - if ($expr->function === 'COUNT') { - $flags['is_count'] = true; - } elseif (in_array($expr->function, static::$FUNCTIONS)) { - $flags['is_func'] = true; - } - } - if (!empty($expr->subquery)) { - $flags['is_subquery'] = true; - } - } - - if ((!empty($statement->procedure)) - && ($statement->procedure->name === 'ANALYSE') - ) { - $flags['is_analyse'] = true; - } - - if (!empty($statement->group)) { - $flags['group'] = true; - } - - if (!empty($statement->having)) { - $flags['having'] = true; - } - - if (!empty($statement->union)) { - $flags['union'] = true; - } - - if (!empty($statement->join)) { - $flags['join'] = true; - } + $flags = self::_getFlagsSelect($statement, $flags); } elseif ($statement instanceof ShowStatement) { $flags['querytype'] = 'SHOW'; $flags['is_show'] = true; |