Passed
Branch develop (d6f62e)
by Tito
06:29
created
extensions/libraries/redcore/html/rdropdown.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@
 block discarded – undo
110 110
 	{
111 111
 		$dropDownList = static::$dropDownList;
112 112
 		$dropDownList .= '</ul></div>';
113
-		static::$dropDownList	= null;
113
+		static::$dropDownList = null;
114 114
 		static::$loaded['JHtmlDropdown::start'] = false;
115 115
 
116 116
 		return $dropDownList;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -133,8 +133,7 @@  discard block
 block discarded – undo
133 133
 		{
134 134
 			$option = JFactory::getApplication()->input->getCmd('option');
135 135
 			$link = 'index.php?option=' . $option;
136
-		}
137
-		else
136
+		} else
138 137
 		{
139 138
 			$link = $customLink;
140 139
 		}
@@ -323,8 +322,7 @@  discard block
 block discarded – undo
323 322
 		if ($ajaxLoad)
324 323
 		{
325 324
 			$href = ' href = "javascript:void(0)" onclick="loadAjax(\'' . $link . '\', \'' . $jsCallBackFunc . '\')"';
326
-		}
327
-		else
325
+		} else
328 326
 		{
329 327
 			$href = ' href = "' . $link . '" ';
330 328
 		}
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/driver.php 1 patch
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@  discard block
 block discarded – undo
79 79
 							JError::setErrorHandling(E_ERROR, 'die');
80 80
 
81 81
 							return JError::raiseError(500, JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver']));
82
-						}
83
-						else
82
+						} else
84 83
 						{
85 84
 							throw new JDatabaseException(JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver']));
86 85
 						}
@@ -101,8 +100,7 @@  discard block
 block discarded – undo
101 100
 						JError::setErrorHandling(E_ERROR, 'die');
102 101
 
103 102
 						return JError::raiseError(500, JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver']));
104
-					}
105
-					else
103
+					} else
106 104
 					{
107 105
 						throw new JDatabaseException(JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver']));
108 106
 					}
@@ -112,8 +110,7 @@  discard block
 block discarded – undo
112 110
 				try
113 111
 				{
114 112
 					$instance = $class::getInstance($options);
115
-				}
116
-				catch (JDatabaseException $e)
113
+				} catch (JDatabaseException $e)
117 114
 				{
118 115
 
119 116
 					// Legacy error handling switch based on the JError::$legacy switch.
@@ -127,8 +124,7 @@  discard block
 block discarded – undo
127 124
 						JError::setErrorHandling(E_ERROR, 'ignore');
128 125
 
129 126
 						return JError::raiseError(500, JText::sprintf('JLIB_DATABASE_ERROR_CONNECT_DATABASE', $e->getMessage()));
130
-					}
131
-					else
127
+					} else
132 128
 					{
133 129
 						throw new JDatabaseException(JText::sprintf('JLIB_DATABASE_ERROR_CONNECT_DATABASE', $e->getMessage()));
134 130
 					}
@@ -153,8 +149,7 @@  discard block
 block discarded – undo
153 149
 			self::$instances = null;
154 150
 		}
155 151
 	}
156
-}
157
-else
152
+} else
158 153
 {
159 154
 	/**
160 155
 	 * Database Driver Class extends Joomla Platform Database Driver Class
@@ -218,8 +213,7 @@  discard block
 block discarded – undo
218 213
 					);
219 214
 
220 215
 					$options['driver'] = 'mysqli';
221
-				}
222
-				else
216
+				} else
223 217
 				{
224 218
 					JLog::add(
225 219
 						'The PHP `ext/mysql` extension is removed in PHP 7, cannot use the `mysql` driver.  Trying `pdomysql` instead.',
@@ -263,8 +257,7 @@  discard block
 block discarded – undo
263 257
 				try
264 258
 				{
265 259
 					$instance = new $class($options);
266
-				}
267
-				catch (RuntimeException $e)
260
+				} catch (RuntimeException $e)
268 261
 				{
269 262
 					throw new RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage()));
270 263
 				}
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/lexersplitter.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -41,21 +41,21 @@
 block discarded – undo
41 41
 
42 42
 class RDatabaseSqlparserLexersplitter {
43 43
 
44
-    private static $splitters = array("\r\n", "!=", ">=", "<=", "<>", ":=", "\\", "&&", ">", "<", "|", "=", "^", "(",
45
-                                      ")", "\t", "\n", "'", "\"", "`", ",", "@", " ", "+", "-", "*", "/", ";");
46
-    private $tokenSize;
47
-    private $hashSet;
44
+	private static $splitters = array("\r\n", "!=", ">=", "<=", "<>", ":=", "\\", "&&", ">", "<", "|", "=", "^", "(",
45
+									  ")", "\t", "\n", "'", "\"", "`", ",", "@", " ", "+", "-", "*", "/", ";");
46
+	private $tokenSize;
47
+	private $hashSet;
48 48
 
49
-    public function __construct() {
50
-        $this->tokenSize = strlen(self::$splitters[0]); # should be the largest one
51
-        $this->hashSet = array_flip(self::$splitters);
52
-    }
49
+	public function __construct() {
50
+		$this->tokenSize = strlen(self::$splitters[0]); # should be the largest one
51
+		$this->hashSet = array_flip(self::$splitters);
52
+	}
53 53
 
54
-    public function getMaxLengthOfSplitter() {
55
-        return $this->tokenSize;
56
-    }
54
+	public function getMaxLengthOfSplitter() {
55
+		return $this->tokenSize;
56
+	}
57 57
 
58
-    public function isSplitter($token) {
59
-        return isset($this->hashSet[$token]);
60
-    }
58
+	public function isSplitter($token) {
59
+		return isset($this->hashSet[$token]);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqlparserutils.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -141,18 +141,18 @@
 block discarded – undo
141 141
 		'UTC_TIME', 'UTC_TIMESTAMP', 'UUID', 'VAR_POP', 'VAR_SAMP', 'VARIANCE',
142 142
 		'VERSION', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR', 'YEARWEEK');
143 143
 
144
-    /**
145
-     * Ends the given string $haystack with the string $needle?
146
-     * @param string $haystack
147
-     * @param string $needle
148
-     */
149
-    protected function endsWith($haystack, $needle) {
150
-        $length = strlen($needle);
151
-        if ($length == 0) {
152
-            return true;
153
-        }
144
+	/**
145
+	 * Ends the given string $haystack with the string $needle?
146
+	 * @param string $haystack
147
+	 * @param string $needle
148
+	 */
149
+	protected function endsWith($haystack, $needle) {
150
+		$length = strlen($needle);
151
+		if ($length == 0) {
152
+			return true;
153
+		}
154 154
 
155
-        $start = $length * -1;
156
-        return (substr($haystack, $start) === $needle);
157
-    }
155
+		$start = $length * -1;
156
+		return (substr($haystack, $start) === $needle);
157
+	}
158 158
 }
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/positioncalculator.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -49,164 +49,164 @@
 block discarded – undo
49 49
  */
50 50
 class RDatabaseSqlparserPositioncalculator extends RDatabaseSqlparserSqlparserutils {
51 51
 
52
-    private static $allowedOnOperator = array("\t", "\n", "\r", " ", ",", "(", ")", "_", "'", "\"");
53
-    private static $allowedOnOther = array("\t", "\n", "\r", " ", ",", "(", ")", "<", ">", "*", "+", "-", "/", "|",
54
-                                           "&", "=", "!", ";");
55
-
56
-    private function printPos($text, $sql, $charPos, $key, $parsed, $backtracking) {
57
-        if (!isset($_ENV['DEBUG'])) {
58
-            return;
59
-        }
60
-
61
-        $spaces = "";
62
-        $caller = debug_backtrace();
63
-        $i = 1;
64
-        while ($caller[$i]['function'] === 'lookForBaseExpression') {
65
-            $spaces .= "   ";
66
-            $i++;
67
-        }
68
-        $holdem = substr($sql, 0, $charPos) . "^" . substr($sql, $charPos);
69
-        echo $spaces . $text . " key:" . $key . "  parsed:" . $parsed . " back:" . serialize($backtracking) . " "
70
-                . $holdem . "\n";
71
-    }
72
-
73
-    public function setPositionsWithinSQL($sql, $parsed) {
74
-        $charPos = 0;
75
-        $backtracking = array();
76
-        $this->lookForBaseExpression($sql, $charPos, $parsed, 0, $backtracking);
77
-        return $parsed;
78
-    }
79
-
80
-    private function findPositionWithinString($sql, $value, $expr_type) {
81
-
82
-        $offset = 0;
83
-        while (true) {
84
-
85
-            $pos = strpos($sql, $value, $offset);
86
-            if ($pos === false) {
87
-                break;
88
-            }
89
-
90
-            $before = "";
91
-            if ($pos > 0) {
92
-                $before = $sql[$pos - 1];
93
-            }
94
-
95
-            $after = "";
96
-            if (isset($sql[$pos + strlen($value)])) {
97
-                $after = $sql[$pos + strlen($value)];
98
-            }
99
-
100
-	        // if we have an operator, it should be surrounded by
101
-	        // whitespace, comma, parenthesis, digit or letter, end_of_string
102
-	        // an operator should not be surrounded by another operator
103
-
104
-            if ($expr_type === 'operator') {
105
-
106
-                $ok = ($before === "" || in_array($before, self::$allowedOnOperator, true))
107
-                        || (strtolower($before) >= 'a' && strtolower($before) <= 'z')
108
-                        || ($before >= '0' && $before <= '9');
109
-                $ok = $ok
110
-                        && ($after === "" || in_array($after, self::$allowedOnOperator, true)
111
-                                || (strtolower($after) >= 'a' && strtolower($after) <= 'z')
112
-                                || ($after >= '0' && $after <= '9') || ($after === '?') || ($after === '@'));
113
-
114
-                if (!$ok) {
115
-                    $offset = $pos + 1;
116
-                    continue;
117
-                }
118
-
119
-                break;
120
-            }
121
-
122
-	        // in all other cases we accept
123
-	        // whitespace, comma, operators, parenthesis and end_of_string
124
-
125
-            $ok = ($before === "" || in_array($before, self::$allowedOnOther, true));
126
-            $ok = $ok && ($after === "" || in_array($after, self::$allowedOnOther, true));
127
-
128
-            if ($ok) {
129
-                break;
130
-            }
131
-
132
-            $offset = $pos + 1;
133
-        }
134
-
135
-        return $pos;
136
-    }
137
-
138
-    private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking) {
139
-        if (!is_numeric($key)) {
140
-            if (($key === 'UNION' || $key === 'UNION ALL') || ($key === 'expr_type' && $parsed === 'expression')
141
-                    || ($key === 'expr_type' && $parsed === 'subquery')
142
-                    || ($key === 'expr_type' && $parsed === 'bracket_expression')
143
-                    || ($key === 'expr_type' && $parsed === 'table_expression')
144
-                    || ($key === 'expr_type' && $parsed === 'record')
145
-                    || ($key === 'expr_type' && $parsed === 'in-list') || ($key === 'alias' && $parsed !== false)) {
146
-	            // we hold the current position and come back after the next base_expr
147
-	            // we do this, because the next base_expr contains the complete expression/subquery/record
148
-	            // and we have to look into it too
149
-                $backtracking[] = $charPos;
150
-
151
-            } elseif (($key === 'ref_clause' || $key === 'columns') && $parsed !== false) {
152
-              // we hold the current position and come back after n base_expr(s)
153
-              // there is an array of sub-elements before (!) the base_expr clause of the current element
154
-              // so we go through the sub-elements and must come at the end
155
-                $backtracking[] = $charPos;
156
-                $parsedCount = count($parsed);
157
-                for ($i = 1; $i < $parsedCount; $i++) {
158
-                    $backtracking[] = false; // backtracking only after n base_expr!
159
-                }
160
-            } elseif ($key === 'sub_tree' && $parsed !== false) {
161
-              // we prevent wrong backtracking on subtrees (too much array_pop())
162
-              // there is an array of sub-elements after(!) the base_expr clause of the current element
163
-              // so we go through the sub-elements and must not come back at the end
164
-                $parsedCount = count($parsed);
165
-                for ($i = 1; $i < $parsedCount; $i++) {
166
-                    $backtracking[] = false;
167
-                }
168
-            } else {
169
-	            // move the current pos after the keyword
170
-	            // SELECT, WHERE, INSERT etc.
171
-                if (in_array($key, parent::$reserved)) {
172
-                    $charPos = stripos($sql, $key, $charPos);
173
-                    $charPos += strlen($key);
174
-                }
175
-            }
176
-        }
177
-
178
-        if (!is_array($parsed)) {
179
-            return;
180
-        }
181
-
182
-        foreach ($parsed as $key => $value) {
183
-            if ($key === 'base_expr') {
184
-
185
-	            // $this->printPos("0", $sql, $charPos, $key, $value, $backtracking);
186
-
187
-                $subject = substr($sql, $charPos);
188
-                $pos = $this->findPositionWithinString($subject, $value,
189
-                        isset($parsed['expr_type']) ? $parsed['expr_type'] : 'alias');
190
-                if ($pos === false) {
191
-                    throw new Exception("cannot calculate position of " . $value . " within " . $subject, 5);
192
-
193
-                }
194
-
195
-                $parsed['position'] = $charPos + $pos;
196
-                $charPos += $pos + strlen($value);
197
-
198
-	            // $this->printPos("1", $sql, $charPos, $key, $value, $backtracking);
199
-
200
-                $oldPos = array_pop($backtracking);
201
-                if (isset($oldPos) && $oldPos !== false) {
202
-                    $charPos = $oldPos;
203
-                }
204
-
205
-	            // $this->printPos("2", $sql, $charPos, $key, $value, $backtracking);
206
-
207
-            } else {
208
-                $this->lookForBaseExpression($sql, $charPos, $parsed[$key], $key, $backtracking);
209
-            }
210
-        }
211
-    }
52
+	private static $allowedOnOperator = array("\t", "\n", "\r", " ", ",", "(", ")", "_", "'", "\"");
53
+	private static $allowedOnOther = array("\t", "\n", "\r", " ", ",", "(", ")", "<", ">", "*", "+", "-", "/", "|",
54
+										   "&", "=", "!", ";");
55
+
56
+	private function printPos($text, $sql, $charPos, $key, $parsed, $backtracking) {
57
+		if (!isset($_ENV['DEBUG'])) {
58
+			return;
59
+		}
60
+
61
+		$spaces = "";
62
+		$caller = debug_backtrace();
63
+		$i = 1;
64
+		while ($caller[$i]['function'] === 'lookForBaseExpression') {
65
+			$spaces .= "   ";
66
+			$i++;
67
+		}
68
+		$holdem = substr($sql, 0, $charPos) . "^" . substr($sql, $charPos);
69
+		echo $spaces . $text . " key:" . $key . "  parsed:" . $parsed . " back:" . serialize($backtracking) . " "
70
+				. $holdem . "\n";
71
+	}
72
+
73
+	public function setPositionsWithinSQL($sql, $parsed) {
74
+		$charPos = 0;
75
+		$backtracking = array();
76
+		$this->lookForBaseExpression($sql, $charPos, $parsed, 0, $backtracking);
77
+		return $parsed;
78
+	}
79
+
80
+	private function findPositionWithinString($sql, $value, $expr_type) {
81
+
82
+		$offset = 0;
83
+		while (true) {
84
+
85
+			$pos = strpos($sql, $value, $offset);
86
+			if ($pos === false) {
87
+				break;
88
+			}
89
+
90
+			$before = "";
91
+			if ($pos > 0) {
92
+				$before = $sql[$pos - 1];
93
+			}
94
+
95
+			$after = "";
96
+			if (isset($sql[$pos + strlen($value)])) {
97
+				$after = $sql[$pos + strlen($value)];
98
+			}
99
+
100
+			// if we have an operator, it should be surrounded by
101
+			// whitespace, comma, parenthesis, digit or letter, end_of_string
102
+			// an operator should not be surrounded by another operator
103
+
104
+			if ($expr_type === 'operator') {
105
+
106
+				$ok = ($before === "" || in_array($before, self::$allowedOnOperator, true))
107
+						|| (strtolower($before) >= 'a' && strtolower($before) <= 'z')
108
+						|| ($before >= '0' && $before <= '9');
109
+				$ok = $ok
110
+						&& ($after === "" || in_array($after, self::$allowedOnOperator, true)
111
+								|| (strtolower($after) >= 'a' && strtolower($after) <= 'z')
112
+								|| ($after >= '0' && $after <= '9') || ($after === '?') || ($after === '@'));
113
+
114
+				if (!$ok) {
115
+					$offset = $pos + 1;
116
+					continue;
117
+				}
118
+
119
+				break;
120
+			}
121
+
122
+			// in all other cases we accept
123
+			// whitespace, comma, operators, parenthesis and end_of_string
124
+
125
+			$ok = ($before === "" || in_array($before, self::$allowedOnOther, true));
126
+			$ok = $ok && ($after === "" || in_array($after, self::$allowedOnOther, true));
127
+
128
+			if ($ok) {
129
+				break;
130
+			}
131
+
132
+			$offset = $pos + 1;
133
+		}
134
+
135
+		return $pos;
136
+	}
137
+
138
+	private function lookForBaseExpression($sql, &$charPos, &$parsed, $key, &$backtracking) {
139
+		if (!is_numeric($key)) {
140
+			if (($key === 'UNION' || $key === 'UNION ALL') || ($key === 'expr_type' && $parsed === 'expression')
141
+					|| ($key === 'expr_type' && $parsed === 'subquery')
142
+					|| ($key === 'expr_type' && $parsed === 'bracket_expression')
143
+					|| ($key === 'expr_type' && $parsed === 'table_expression')
144
+					|| ($key === 'expr_type' && $parsed === 'record')
145
+					|| ($key === 'expr_type' && $parsed === 'in-list') || ($key === 'alias' && $parsed !== false)) {
146
+				// we hold the current position and come back after the next base_expr
147
+				// we do this, because the next base_expr contains the complete expression/subquery/record
148
+				// and we have to look into it too
149
+				$backtracking[] = $charPos;
150
+
151
+			} elseif (($key === 'ref_clause' || $key === 'columns') && $parsed !== false) {
152
+			  // we hold the current position and come back after n base_expr(s)
153
+			  // there is an array of sub-elements before (!) the base_expr clause of the current element
154
+			  // so we go through the sub-elements and must come at the end
155
+				$backtracking[] = $charPos;
156
+				$parsedCount = count($parsed);
157
+				for ($i = 1; $i < $parsedCount; $i++) {
158
+					$backtracking[] = false; // backtracking only after n base_expr!
159
+				}
160
+			} elseif ($key === 'sub_tree' && $parsed !== false) {
161
+			  // we prevent wrong backtracking on subtrees (too much array_pop())
162
+			  // there is an array of sub-elements after(!) the base_expr clause of the current element
163
+			  // so we go through the sub-elements and must not come back at the end
164
+				$parsedCount = count($parsed);
165
+				for ($i = 1; $i < $parsedCount; $i++) {
166
+					$backtracking[] = false;
167
+				}
168
+			} else {
169
+				// move the current pos after the keyword
170
+				// SELECT, WHERE, INSERT etc.
171
+				if (in_array($key, parent::$reserved)) {
172
+					$charPos = stripos($sql, $key, $charPos);
173
+					$charPos += strlen($key);
174
+				}
175
+			}
176
+		}
177
+
178
+		if (!is_array($parsed)) {
179
+			return;
180
+		}
181
+
182
+		foreach ($parsed as $key => $value) {
183
+			if ($key === 'base_expr') {
184
+
185
+				// $this->printPos("0", $sql, $charPos, $key, $value, $backtracking);
186
+
187
+				$subject = substr($sql, $charPos);
188
+				$pos = $this->findPositionWithinString($subject, $value,
189
+						isset($parsed['expr_type']) ? $parsed['expr_type'] : 'alias');
190
+				if ($pos === false) {
191
+					throw new Exception("cannot calculate position of " . $value . " within " . $subject, 5);
192
+
193
+				}
194
+
195
+				$parsed['position'] = $charPos + $pos;
196
+				$charPos += $pos + strlen($value);
197
+
198
+				// $this->printPos("1", $sql, $charPos, $key, $value, $backtracking);
199
+
200
+				$oldPos = array_pop($backtracking);
201
+				if (isset($oldPos) && $oldPos !== false) {
202
+					$charPos = $oldPos;
203
+				}
204
+
205
+				// $this->printPos("2", $sql, $charPos, $key, $value, $backtracking);
206
+
207
+			} else {
208
+				$this->lookForBaseExpression($sql, $charPos, $parsed[$key], $key, $backtracking);
209
+			}
210
+		}
211
+	}
212 212
 }
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqltranslation.php 1 patch
Braces   +21 added lines, -42 removed lines patch added patch discarded remove patch
@@ -119,8 +119,7 @@  discard block
 block discarded – undo
119 119
 							if (in_array($tableColumn, $translationTables[$foundTable['originalTableName']]->primaryKeys))
120 120
 							{
121 121
 								$column['base_expr'] = $foundTable['alias']['originalName'] . '.' . $tableColumn;
122
-							}
123
-							else
122
+							} else
124 123
 							{
125 124
 								$column['base_expr'] = ''
126 125
 										. 'COALESCE('
@@ -161,8 +160,7 @@  discard block
 block discarded – undo
161 160
 					return self::$parsedQueries[$hashedQueryKey];
162 161
 				}
163 162
 			}
164
-		}
165
-		catch (Exception $e)
163
+		} catch (Exception $e)
166 164
 		{
167 165
 			return null;
168 166
 		}
@@ -203,8 +201,7 @@  discard block
 block discarded – undo
203 201
 
204 202
 					$numbers[$index][$key] = $value;
205 203
 					unset($queryArray[$key]);
206
-				}
207
-				else
204
+				} else
208 205
 				{
209 206
 					if (!empty($numbers[$index]))
210 207
 					{
@@ -221,8 +218,7 @@  discard block
 block discarded – undo
221 218
 					{
222 219
 						$queryArray[$key] = $value;
223 220
 					}
224
-				}
225
-				else
221
+				} else
226 222
 				{
227 223
 					$firstKey               = key($values);
228 224
 					$hashValue              = $db->q(md5(json_encode($values)));
@@ -356,19 +352,16 @@  discard block
 block discarded – undo
356 352
 									if (empty($primaryKey) && $groupColumnsKey != 'FROM')
357 353
 									{
358 354
 										$tagColumnsValue['base_expr'] = self::breakColumnAndReplace($tagColumnsValue['base_expr'], $column['table']['alias']['name']);
359
-									}
360
-									else
355
+									} else
361 356
 									{
362 357
 										$tagColumnsValue['base_expr'] = self::breakColumnAndReplace($tagColumnsValue['base_expr'], $column['table']['alias']['originalName']);
363 358
 									}
364
-								}
365
-								else
359
+								} else
366 360
 								{
367 361
 									if (in_array($groupColumnsKey, array('ORDER', 'WHERE', 'GROUP')) && !empty($primaryKey))
368 362
 									{
369 363
 										$tagColumnsValue['base_expr'] = self::breakColumnAndReplace($tagColumnsValue['base_expr'], $column['table']['alias']['originalName']);
370
-									}
371
-									else
364
+									} else
372 365
 									{
373 366
 										$tagColumnsValue['base_expr'] = $column['base_expr'];
374 367
 
@@ -393,14 +386,12 @@  discard block
 block discarded – undo
393 386
 									}
394 387
 								}
395 388
 							}
396
-						}
397
-						elseif (!empty($tagColumnsValue['sub_tree']))
389
+						} elseif (!empty($tagColumnsValue['sub_tree']))
398 390
 						{
399 391
 							if (!empty($tagColumnsValue['expr_type']) && $tagColumnsValue['expr_type'] == 'subquery')
400 392
 							{
401 393
 								// SubQuery is already parsed so we do not need to parse columns again
402
-							}
403
-							elseif (!empty($tagColumnsValue['expr_type']) && in_array($tagColumnsValue['expr_type'], array('expression')))
394
+							} elseif (!empty($tagColumnsValue['expr_type']) && in_array($tagColumnsValue['expr_type'], array('expression')))
404 395
 							{
405 396
 								foreach ($tagColumnsValue['sub_tree'] as $subKey => $subTree)
406 397
 								{
@@ -416,8 +407,7 @@  discard block
 block discarded – undo
416 407
 										$tagColumnsValue['sub_tree'][$subKey]['sub_tree'] = $tagColumnsValue['sub_tree'][$subKey]['sub_tree'][$groupColumnsKey];
417 408
 									}
418 409
 								}
419
-							}
420
-							elseif (is_array($tagColumnsValue['sub_tree']))
410
+							} elseif (is_array($tagColumnsValue['sub_tree']))
421 411
 							{
422 412
 								// We will not replace some aggregate functions columns
423 413
 								if (!(in_array($tagColumnsValue['expr_type'], array('aggregate_function')) && strtolower($tagColumnsValue['base_expr']) == 'count'))
@@ -433,8 +423,7 @@  discard block
 block discarded – undo
433 423
 											$columnFound,
434 424
 											false
435 425
 										);
436
-									}
437
-									else
426
+									} else
438 427
 									{
439 428
 										$tagColumnsValue['sub_tree'] = self::parseColumnReplacements(
440 429
 											array($groupColumnsKey => $tagColumnsValue['sub_tree']),
@@ -447,8 +436,7 @@  discard block
 block discarded – undo
447 436
 									}
448 437
 								}
449 438
 							}
450
-						}
451
-						elseif (!empty($tagColumnsValue['ref_clause']))
439
+						} elseif (!empty($tagColumnsValue['ref_clause']))
452 440
 						{
453 441
 							if (is_array($tagColumnsValue['ref_clause']))
454 442
 							{
@@ -463,8 +451,7 @@  discard block
 block discarded – undo
463 451
 										$columnFound,
464 452
 										false
465 453
 									);
466
-								}
467
-								else
454
+								} else
468 455
 								{
469 456
 									$tagColumnsValue['ref_clause'] = self::parseColumnReplacements(
470 457
 										array($groupColumnsKey => $tagColumnsValue['ref_clause']),
@@ -481,8 +468,7 @@  discard block
 block discarded – undo
481 468
 						if (!is_numeric($tagKey))
482 469
 						{
483 470
 							$filteredGroup[$tagKey] = $tagColumnsValue;
484
-						}
485
-						else
471
+						} else
486 472
 						{
487 473
 							$filteredGroup[] = $tagColumnsValue;
488 474
 						}
@@ -620,8 +606,7 @@  discard block
 block discarded – undo
620 606
 									$tagValue['base_expr'] = $parsedSubQuery;
621 607
 									$subQueryFound = true;
622 608
 								}
623
-							}
624
-							elseif (!empty($tagValue['expr_type']) && in_array($tagValue['expr_type'], array('expression')))
609
+							} elseif (!empty($tagValue['expr_type']) && in_array($tagValue['expr_type'], array('expression')))
625 610
 							{
626 611
 								foreach ($tagValue['sub_tree'] as $subKey => $subTree)
627 612
 								{
@@ -639,8 +624,7 @@  discard block
 block discarded – undo
639 624
 											$tagValue['sub_tree'][$subKey]['base_expr'] = '(' . $parsedSubQuery . ')';
640 625
 											$subQueryFound = true;
641 626
 										}
642
-									}
643
-									elseif (!empty($tagValue['sub_tree'][$subKey]['sub_tree']))
627
+									} elseif (!empty($tagValue['sub_tree'][$subKey]['sub_tree']))
644 628
 									{
645 629
 										$tagValue['sub_tree'][$subKey]['sub_tree'] = self::parseTableReplacements(
646 630
 											$tagValue['sub_tree'][$subKey]['sub_tree'],
@@ -652,8 +636,7 @@  discard block
 block discarded – undo
652 636
 										);
653 637
 									}
654 638
 								}
655
-							}
656
-							else
639
+							} else
657 640
 							{
658 641
 								$tagValue['sub_tree'] = self::parseTableReplacements(
659 642
 									$tagValue['sub_tree'],
@@ -669,8 +652,7 @@  discard block
 block discarded – undo
669 652
 						if (!is_numeric($tagKey))
670 653
 						{
671 654
 							$filteredGroup[$tagKey] = $tagValue;
672
-						}
673
-						else
655
+						} else
674 656
 						{
675 657
 							$filteredGroup[] = $tagValue;
676 658
 						}
@@ -680,8 +662,7 @@  discard block
 block discarded – undo
680 662
 							if (!empty($translationTables[$tableName]->tableJoinEndPosition))
681 663
 							{
682 664
 								$filteredGroupEndPosition[] = $newTagValue;
683
-							}
684
-							else
665
+							} else
685 666
 							{
686 667
 								$filteredGroup[] = $newTagValue;
687 668
 							}
@@ -939,8 +920,7 @@  discard block
 block discarded – undo
939 920
 
940 921
 						return $fieldFromListQuotes;
941 922
 				}
942
-			}
943
-			elseif ($tableAlias == '')
923
+			} elseif ($tableAlias == '')
944 924
 			{
945 925
 				switch (self::cleanEscaping($fieldFromList['columnName']))
946 926
 				{
@@ -954,8 +934,7 @@  discard block
 block discarded – undo
954 934
 
955 935
 						return $fieldFromList;
956 936
 				}
957
-			}
958
-			else
937
+			} else
959 938
 			{
960 939
 				switch (self::cleanEscaping($fieldFromList))
961 940
 				{
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqlcreator.php 2 patches
Switch Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -51,25 +51,25 @@
 block discarded – undo
51 51
 		$k = key($parsed);
52 52
 		switch ($k) {
53 53
 
54
-		case "UNION":
55
-		case "UNION ALL":
56
-			throw new Exception($k . " not implemented.", 20);
57
-			break;
58
-		case "SELECT":
59
-			$this->created = $this->processSelectStatement($parsed);
60
-			break;
61
-		case "INSERT":
62
-			$this->created = $this->processInsertStatement($parsed);
63
-			break;
64
-		case "DELETE":
65
-			$this->created = $this->processDeleteStatement($parsed);
66
-			break;
67
-		case "UPDATE":
68
-			$this->created = $this->processUpdateStatement($parsed);
69
-			break;
70
-		default:
71
-			throw new Exception($k . " not implemented.", 20);
72
-			break;
54
+			case "UNION":
55
+			case "UNION ALL":
56
+				throw new Exception($k . " not implemented.", 20);
57
+				break;
58
+			case "SELECT":
59
+				$this->created = $this->processSelectStatement($parsed);
60
+				break;
61
+			case "INSERT":
62
+				$this->created = $this->processInsertStatement($parsed);
63
+				break;
64
+			case "DELETE":
65
+				$this->created = $this->processDeleteStatement($parsed);
66
+				break;
67
+			case "UPDATE":
68
+				$this->created = $this->processUpdateStatement($parsed);
69
+				break;
70
+			default:
71
+				throw new Exception($k . " not implemented.", 20);
72
+				break;
73 73
 		}
74 74
 		return $this->created;
75 75
 	}
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -421,8 +421,7 @@  discard block
 block discarded – undo
421 421
 	protected function processWhereBracketExpression($parsed) {
422 422
 		if (empty($parsed['expr_type']) || $parsed['expr_type'] !== 'bracket_expression') {
423 423
 			return "";
424
-		}
425
-		elseif (empty($parsed['sub_tree']))
424
+		} elseif (empty($parsed['sub_tree']))
426 425
 		{
427 426
 			return "()";
428 427
 		}
@@ -549,8 +548,7 @@  discard block
 block discarded – undo
549 548
 		if (empty($parsed['expr_type']) || $parsed['expr_type'] !== 'bracket_expression')
550 549
 		{
551 550
 			return "";
552
-		}
553
-		elseif (empty($parsed['sub_tree']))
551
+		} elseif (empty($parsed['sub_tree']))
554 552
 		{
555 553
 			return "";
556 554
 		}
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqllexer.php 2 patches
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -47,322 +47,322 @@
 block discarded – undo
47 47
  */
48 48
 class RDatabaseSqlparserSqllexer extends RDatabaseSqlparserSqlparserutils {
49 49
 
50
-    private $splitters;
50
+	private $splitters;
51 51
 
52
-    public function __construct() {
53
-        $this->splitters = new RDatabaseSqlparserLexersplitter();
54
-    }
52
+	public function __construct() {
53
+		$this->splitters = new RDatabaseSqlparserLexersplitter();
54
+	}
55 55
 
56
-    public function split($sql) {
57
-        if (!is_string($sql))
58
-            throw new InvalidArgumentException("no SQL string to parse: \n" . $sql, 10);
56
+	public function split($sql) {
57
+		if (!is_string($sql))
58
+			throw new InvalidArgumentException("no SQL string to parse: \n" . $sql, 10);
59 59
 
60
-        $tokens = array();
61
-        $token = '';
62
-
63
-        $splitLen = $this->splitters->getMaxLengthOfSplitter();
64
-        $len = strlen($sql);
65
-        $pos = 0;
66
-
67
-        while ($pos < $len) {
68
-
69
-            for ($i = $splitLen; $i > 0; $i--) {
70
-                $substr = substr($sql, $pos, $i);
71
-                if ($this->splitters->isSplitter($substr)) {
72
-
73
-                    if ($token !== "") {
74
-                        $tokens[] = $token;
75
-                    }
60
+		$tokens = array();
61
+		$token = '';
62
+
63
+		$splitLen = $this->splitters->getMaxLengthOfSplitter();
64
+		$len = strlen($sql);
65
+		$pos = 0;
66
+
67
+		while ($pos < $len) {
68
+
69
+			for ($i = $splitLen; $i > 0; $i--) {
70
+				$substr = substr($sql, $pos, $i);
71
+				if ($this->splitters->isSplitter($substr)) {
72
+
73
+					if ($token !== "") {
74
+						$tokens[] = $token;
75
+					}
76 76
 
77
-                    $tokens[] = $substr;
78
-                    $pos += $i;
79
-                    $token = '';
77
+					$tokens[] = $substr;
78
+					$pos += $i;
79
+					$token = '';
80 80
 
81
-                    continue 2;
82
-                }
83
-            }
81
+					continue 2;
82
+				}
83
+			}
84 84
 
85
-            $token .= $sql[$pos];
86
-            $pos++;
87
-        }
85
+			$token .= $sql[$pos];
86
+			$pos++;
87
+		}
88 88
 
89
-        if ($token !== "") {
90
-            $tokens[] = $token;
91
-        }
89
+		if ($token !== "") {
90
+			$tokens[] = $token;
91
+		}
92 92
 
93
-        $tokens = $this->concatEscapeSequences($tokens);
94
-        $tokens = $this->balanceBackticks($tokens);
95
-        $tokens = $this->concatColReferences($tokens);
96
-        $tokens = $this->balanceParenthesis($tokens);
97
-        $tokens = $this->balanceMultilineComments($tokens);
98
-        $tokens = $this->concatInlineComments($tokens);
99
-        $tokens = $this->concatUserDefinedVariables($tokens);
100
-        return $tokens;
101
-    }
102
-
103
-    private function concatUserDefinedVariables($tokens) {
104
-        $i = 0;
105
-        $cnt = count($tokens);
106
-        $userdef = false;
107
-
108
-        while ($i < $cnt) {
109
-
110
-            if (!isset($tokens[$i])) {
111
-                $i++;
112
-                continue;
113
-            }
114
-
115
-            $token = $tokens[$i];
116
-
117
-            if ($userdef !== false) {
118
-                $tokens[$userdef] .= $token;
119
-                unset($tokens[$i]);
120
-                if ($token !== "@") {
121
-                    $userdef = false;
122
-                }
123
-            }
124
-
125
-            if ($userdef === false && $token === "@") {
126
-                $userdef = $i;
127
-            }
128
-
129
-            $i++;
130
-        }
131
-
132
-        return array_values($tokens);
133
-    }
134
-
135
-    private function concatInlineComments($tokens) {
136
-
137
-        $i = 0;
138
-        $cnt = count($tokens);
139
-        $comment = false;
140
-
141
-        while ($i < $cnt) {
142
-
143
-            if (!isset($tokens[$i])) {
144
-                $i++;
145
-                continue;
146
-            }
147
-
148
-            $token = $tokens[$i];
149
-
150
-            if ($comment !== false) {
151
-                if ($token === "\n" || $token === "\r\n") {
152
-                    $comment = false;
153
-                } else {
154
-                    unset($tokens[$i]);
155
-                    $tokens[$comment] .= $token;
156
-                }
157
-            }
158
-
159
-            if (($comment === false) && ($token === "-")) {
160
-                if (isset($tokens[$i + 1]) && $tokens[$i + 1] === "-") {
161
-                    $comment = $i;
162
-                    $tokens[$i] = "--";
163
-                    $i++;
164
-                    unset($tokens[$i]);
165
-                    continue;
166
-                }
167
-            }
168
-
169
-            $i++;
170
-        }
171
-
172
-        return array_values($tokens);
173
-    }
174
-
175
-    private function balanceMultilineComments($tokens) {
176
-
177
-        $i = 0;
178
-        $cnt = count($tokens);
179
-        $comment = false;
180
-
181
-        while ($i < $cnt) {
182
-
183
-            if (!isset($tokens[$i])) {
184
-                $i++;
185
-                continue;
186
-            }
187
-
188
-            $token = $tokens[$i];
189
-
190
-            if ($comment !== false) {
191
-                unset($tokens[$i]);
192
-                $tokens[$comment] .= $token;
193
-                if ($token === "*" && isset($tokens[$i + 1]) && $tokens[$i + 1] === "/") {
194
-                    unset($tokens[$i + 1]);
195
-                    $tokens[$comment] .= "/";
196
-                    $comment = false;
197
-                }
198
-            }
199
-
200
-            if (($comment === false) && ($token === "/")) {
201
-                if (isset($tokens[$i + 1]) && $tokens[$i + 1] === "*") {
202
-                    $comment = $i;
203
-                    $tokens[$i] = "/*";
204
-                    $i++;
205
-                    unset($tokens[$i]);
206
-                    continue;
207
-                }
208
-            }
209
-
210
-            $i++;
211
-        }
212
-        return array_values($tokens);
213
-    }
214
-
215
-    private function isBacktick($token) {
216
-        return ($token === "'" || $token === "\"" || $token === "`");
217
-    }
218
-
219
-    private function balanceBackticks($tokens) {
220
-        $i = 0;
221
-        $cnt = count($tokens);
222
-        while ($i < $cnt) {
223
-
224
-            if (!isset($tokens[$i])) {
225
-                $i++;
226
-                continue;
227
-            }
228
-
229
-            $token = $tokens[$i];
230
-
231
-            if ($this->isBacktick($token)) {
232
-                $tokens = $this->balanceCharacter($tokens, $i, $token);
233
-            }
234
-
235
-            $i++;
236
-        }
237
-
238
-        return $tokens;
239
-    }
93
+		$tokens = $this->concatEscapeSequences($tokens);
94
+		$tokens = $this->balanceBackticks($tokens);
95
+		$tokens = $this->concatColReferences($tokens);
96
+		$tokens = $this->balanceParenthesis($tokens);
97
+		$tokens = $this->balanceMultilineComments($tokens);
98
+		$tokens = $this->concatInlineComments($tokens);
99
+		$tokens = $this->concatUserDefinedVariables($tokens);
100
+		return $tokens;
101
+	}
102
+
103
+	private function concatUserDefinedVariables($tokens) {
104
+		$i = 0;
105
+		$cnt = count($tokens);
106
+		$userdef = false;
107
+
108
+		while ($i < $cnt) {
109
+
110
+			if (!isset($tokens[$i])) {
111
+				$i++;
112
+				continue;
113
+			}
114
+
115
+			$token = $tokens[$i];
116
+
117
+			if ($userdef !== false) {
118
+				$tokens[$userdef] .= $token;
119
+				unset($tokens[$i]);
120
+				if ($token !== "@") {
121
+					$userdef = false;
122
+				}
123
+			}
124
+
125
+			if ($userdef === false && $token === "@") {
126
+				$userdef = $i;
127
+			}
128
+
129
+			$i++;
130
+		}
131
+
132
+		return array_values($tokens);
133
+	}
134
+
135
+	private function concatInlineComments($tokens) {
136
+
137
+		$i = 0;
138
+		$cnt = count($tokens);
139
+		$comment = false;
140
+
141
+		while ($i < $cnt) {
142
+
143
+			if (!isset($tokens[$i])) {
144
+				$i++;
145
+				continue;
146
+			}
147
+
148
+			$token = $tokens[$i];
149
+
150
+			if ($comment !== false) {
151
+				if ($token === "\n" || $token === "\r\n") {
152
+					$comment = false;
153
+				} else {
154
+					unset($tokens[$i]);
155
+					$tokens[$comment] .= $token;
156
+				}
157
+			}
158
+
159
+			if (($comment === false) && ($token === "-")) {
160
+				if (isset($tokens[$i + 1]) && $tokens[$i + 1] === "-") {
161
+					$comment = $i;
162
+					$tokens[$i] = "--";
163
+					$i++;
164
+					unset($tokens[$i]);
165
+					continue;
166
+				}
167
+			}
168
+
169
+			$i++;
170
+		}
171
+
172
+		return array_values($tokens);
173
+	}
174
+
175
+	private function balanceMultilineComments($tokens) {
176
+
177
+		$i = 0;
178
+		$cnt = count($tokens);
179
+		$comment = false;
180
+
181
+		while ($i < $cnt) {
182
+
183
+			if (!isset($tokens[$i])) {
184
+				$i++;
185
+				continue;
186
+			}
187
+
188
+			$token = $tokens[$i];
189
+
190
+			if ($comment !== false) {
191
+				unset($tokens[$i]);
192
+				$tokens[$comment] .= $token;
193
+				if ($token === "*" && isset($tokens[$i + 1]) && $tokens[$i + 1] === "/") {
194
+					unset($tokens[$i + 1]);
195
+					$tokens[$comment] .= "/";
196
+					$comment = false;
197
+				}
198
+			}
199
+
200
+			if (($comment === false) && ($token === "/")) {
201
+				if (isset($tokens[$i + 1]) && $tokens[$i + 1] === "*") {
202
+					$comment = $i;
203
+					$tokens[$i] = "/*";
204
+					$i++;
205
+					unset($tokens[$i]);
206
+					continue;
207
+				}
208
+			}
209
+
210
+			$i++;
211
+		}
212
+		return array_values($tokens);
213
+	}
214
+
215
+	private function isBacktick($token) {
216
+		return ($token === "'" || $token === "\"" || $token === "`");
217
+	}
218
+
219
+	private function balanceBackticks($tokens) {
220
+		$i = 0;
221
+		$cnt = count($tokens);
222
+		while ($i < $cnt) {
223
+
224
+			if (!isset($tokens[$i])) {
225
+				$i++;
226
+				continue;
227
+			}
228
+
229
+			$token = $tokens[$i];
230
+
231
+			if ($this->isBacktick($token)) {
232
+				$tokens = $this->balanceCharacter($tokens, $i, $token);
233
+			}
234
+
235
+			$i++;
236
+		}
237
+
238
+		return $tokens;
239
+	}
240 240
 
241 241
 	// backticks are not balanced within one token, so we have
242 242
 	// to re-combine some tokens
243
-    private function balanceCharacter($tokens, $idx, $char) {
243
+	private function balanceCharacter($tokens, $idx, $char) {
244 244
 
245
-        $token_count = count($tokens);
246
-        $i = $idx + 1;
247
-        while ($i < $token_count) {
245
+		$token_count = count($tokens);
246
+		$i = $idx + 1;
247
+		while ($i < $token_count) {
248 248
 
249
-            if (!isset($tokens[$i])) {
250
-                $i++;
251
-                continue;
252
-            }
249
+			if (!isset($tokens[$i])) {
250
+				$i++;
251
+				continue;
252
+			}
253 253
 
254
-            $token = $tokens[$i];
255
-            $tokens[$idx] .= $token;
256
-            unset($tokens[$i]);
254
+			$token = $tokens[$i];
255
+			$tokens[$idx] .= $token;
256
+			unset($tokens[$i]);
257 257
 
258
-            if ($token === $char) {
259
-                break;
260
-            }
258
+			if ($token === $char) {
259
+				break;
260
+			}
261 261
 
262
-            $i++;
263
-        }
264
-        return array_values($tokens);
265
-    }
262
+			$i++;
263
+		}
264
+		return array_values($tokens);
265
+	}
266 266
 
267
-    /*
267
+	/*
268 268
      * does the token ends with dot?
269 269
      * concat it with the next token
270 270
      * 
271 271
      * does the token starts with a dot?
272 272
      * concat it with the previous token
273 273
      */
274
-    private function concatColReferences($tokens) {
275
-
276
-        $cnt = count($tokens);
277
-        $i = 0;
278
-        while ($i < $cnt) {
279
-
280
-            if (!isset($tokens[$i])) {
281
-                $i++;
282
-                continue;
283
-            }
284
-
285
-            if ($tokens[$i][0] === ".") {
286
-
287
-                // concat the previous tokens, till the token has been changed
288
-                $k = $i - 1;
289
-                $len = strlen($tokens[$i]);
290
-                while (($k >= 0) && ($len == strlen($tokens[$i]))) {
291
-                    if (!isset($tokens[$k])) { // FIXME: this can be wrong if we have schema . table . column
292
-                        $k--;
293
-                        continue;
294
-                    }
295
-                    $tokens[$i] = $tokens[$k] . $tokens[$i];
296
-                    unset($tokens[$k]);
297
-                    $k--;
298
-                }
299
-            }
300
-
301
-            if ($this->endsWith($tokens[$i], '.')) {
302
-
303
-                // concat the next tokens, till the token has been changed
304
-                $k = $i + 1;
305
-                $len = strlen($tokens[$i]);
306
-                while (($k < $cnt) && ($len == strlen($tokens[$i]))) {
307
-                    if (!isset($tokens[$k])) {
308
-                        $k++;
309
-                        continue;
310
-                    }
311
-                    $tokens[$i] .= $tokens[$k];
312
-                    unset($tokens[$k]);
313
-                    $k++;
314
-                }
315
-            }
316
-
317
-            $i++;
318
-        }
319
-
320
-        return array_values($tokens);
321
-    }
322
-
323
-    private function concatEscapeSequences($tokens) {
324
-        $tokenCount = count($tokens);
325
-        $i = 0;
326
-        while ($i < $tokenCount) {
327
-
328
-            if ($this->endsWith($tokens[$i], "\\")) {
329
-                $i++;
330
-                if (isset($tokens[$i])) {
331
-                    $tokens[$i - 1] .= $tokens[$i];
332
-                    unset($tokens[$i]);
333
-                }
334
-            }
335
-            $i++;
336
-        }
337
-        return array_values($tokens);
338
-    }
339
-
340
-    private function balanceParenthesis($tokens) {
341
-        $token_count = count($tokens);
342
-        $i = 0;
343
-        while ($i < $token_count) {
344
-            if ($tokens[$i] !== '(') {
345
-                $i++;
346
-                continue;
347
-            }
348
-            $count = 1;
349
-            for ($n = $i + 1; $n < $token_count; $n++) {
350
-                $token = $tokens[$n];
351
-                if ($token === '(') {
352
-                    $count++;
353
-                }
354
-                if ($token === ')') {
355
-                    $count--;
356
-                }
357
-                $tokens[$i] .= $token;
358
-                unset($tokens[$n]);
359
-                if ($count === 0) {
360
-                    $n++;
361
-                    break;
362
-                }
363
-            }
364
-            $i = $n;
365
-        }
366
-        return array_values($tokens);
367
-    }
274
+	private function concatColReferences($tokens) {
275
+
276
+		$cnt = count($tokens);
277
+		$i = 0;
278
+		while ($i < $cnt) {
279
+
280
+			if (!isset($tokens[$i])) {
281
+				$i++;
282
+				continue;
283
+			}
284
+
285
+			if ($tokens[$i][0] === ".") {
286
+
287
+				// concat the previous tokens, till the token has been changed
288
+				$k = $i - 1;
289
+				$len = strlen($tokens[$i]);
290
+				while (($k >= 0) && ($len == strlen($tokens[$i]))) {
291
+					if (!isset($tokens[$k])) { // FIXME: this can be wrong if we have schema . table . column
292
+						$k--;
293
+						continue;
294
+					}
295
+					$tokens[$i] = $tokens[$k] . $tokens[$i];
296
+					unset($tokens[$k]);
297
+					$k--;
298
+				}
299
+			}
300
+
301
+			if ($this->endsWith($tokens[$i], '.')) {
302
+
303
+				// concat the next tokens, till the token has been changed
304
+				$k = $i + 1;
305
+				$len = strlen($tokens[$i]);
306
+				while (($k < $cnt) && ($len == strlen($tokens[$i]))) {
307
+					if (!isset($tokens[$k])) {
308
+						$k++;
309
+						continue;
310
+					}
311
+					$tokens[$i] .= $tokens[$k];
312
+					unset($tokens[$k]);
313
+					$k++;
314
+				}
315
+			}
316
+
317
+			$i++;
318
+		}
319
+
320
+		return array_values($tokens);
321
+	}
322
+
323
+	private function concatEscapeSequences($tokens) {
324
+		$tokenCount = count($tokens);
325
+		$i = 0;
326
+		while ($i < $tokenCount) {
327
+
328
+			if ($this->endsWith($tokens[$i], "\\")) {
329
+				$i++;
330
+				if (isset($tokens[$i])) {
331
+					$tokens[$i - 1] .= $tokens[$i];
332
+					unset($tokens[$i]);
333
+				}
334
+			}
335
+			$i++;
336
+		}
337
+		return array_values($tokens);
338
+	}
339
+
340
+	private function balanceParenthesis($tokens) {
341
+		$token_count = count($tokens);
342
+		$i = 0;
343
+		while ($i < $token_count) {
344
+			if ($tokens[$i] !== '(') {
345
+				$i++;
346
+				continue;
347
+			}
348
+			$count = 1;
349
+			for ($n = $i + 1; $n < $token_count; $n++) {
350
+				$token = $tokens[$n];
351
+				if ($token === '(') {
352
+					$count++;
353
+				}
354
+				if ($token === ')') {
355
+					$count--;
356
+				}
357
+				$tokens[$i] .= $token;
358
+				unset($tokens[$n]);
359
+				if ($count === 0) {
360
+					$n++;
361
+					break;
362
+				}
363
+			}
364
+			$i = $n;
365
+		}
366
+		return array_values($tokens);
367
+	}
368 368
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,8 +54,9 @@
 block discarded – undo
54 54
     }
55 55
 
56 56
     public function split($sql) {
57
-        if (!is_string($sql))
58
-            throw new InvalidArgumentException("no SQL string to parse: \n" . $sql, 10);
57
+        if (!is_string($sql)) {
58
+                    throw new InvalidArgumentException("no SQL string to parse: \n" . $sql, 10);
59
+        }
59 60
 
60 61
         $tokens = array();
61 62
         $token = '';
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqlparser.php 2 patches
Switch Indentation   +473 added lines, -473 removed lines patch added patch discarded remove patch
@@ -243,244 +243,244 @@  discard block
 block discarded – undo
243 243
 			switch ($upper) {
244 244
 
245 245
 			/* Tokens that get their own sections. These keywords have subclauses. */
246
-			case 'SELECT':
247
-			case 'ORDER':
248
-			case 'LIMIT':
249
-			case 'SET':
250
-			case 'DUPLICATE':
251
-			case 'VALUES':
252
-			case 'GROUP':
253
-			case 'HAVING':
254
-			case 'WHERE':
255
-			case 'RENAME':
256
-			case 'CALL':
257
-			case 'PROCEDURE':
258
-			case 'FUNCTION':
259
-			case 'DATABASE':
260
-			case 'SERVER':
261
-			case 'LOGFILE':
262
-			case 'DEFINER':
263
-			case 'RETURNS':
264
-			case 'TABLESPACE':
265
-			case 'TRIGGER':
266
-			case 'DO':
267
-			case 'PLUGIN':
268
-			case 'FROM':
269
-			case 'FLUSH':
270
-			case 'KILL':
271
-			case 'RESET':
272
-			case 'START':
273
-			case 'STOP':
274
-			case 'PURGE':
275
-			case 'EXECUTE':
276
-			case 'PREPARE':
277
-			case 'DEALLOCATE':
278
-				if ($trim === 'DEALLOCATE') {
279
-					$skip_next = true;
280
-				}
281
-				/* this FROM is different from FROM in other DML (not join related) */
282
-				if ($token_category === 'PREPARE' && $upper === 'FROM') {
283
-					continue 2;
284
-				}
285
-
286
-				$token_category = $upper;
287
-				break;
246
+				case 'SELECT':
247
+				case 'ORDER':
248
+				case 'LIMIT':
249
+				case 'SET':
250
+				case 'DUPLICATE':
251
+				case 'VALUES':
252
+				case 'GROUP':
253
+				case 'HAVING':
254
+				case 'WHERE':
255
+				case 'RENAME':
256
+				case 'CALL':
257
+				case 'PROCEDURE':
258
+				case 'FUNCTION':
259
+				case 'DATABASE':
260
+				case 'SERVER':
261
+				case 'LOGFILE':
262
+				case 'DEFINER':
263
+				case 'RETURNS':
264
+				case 'TABLESPACE':
265
+				case 'TRIGGER':
266
+				case 'DO':
267
+				case 'PLUGIN':
268
+				case 'FROM':
269
+				case 'FLUSH':
270
+				case 'KILL':
271
+				case 'RESET':
272
+				case 'START':
273
+				case 'STOP':
274
+				case 'PURGE':
275
+				case 'EXECUTE':
276
+				case 'PREPARE':
277
+				case 'DEALLOCATE':
278
+					if ($trim === 'DEALLOCATE') {
279
+						$skip_next = true;
280
+					}
281
+					/* this FROM is different from FROM in other DML (not join related) */
282
+					if ($token_category === 'PREPARE' && $upper === 'FROM') {
283
+						continue 2;
284
+					}
288 285
 
289
-			case 'EVENT':
290
-				// issue 71
291
-				if ($prev_category === 'DROP' || $prev_category === 'ALTER' || $prev_category === 'CREATE') {
292 286
 					$token_category = $upper;
293
-				}
294
-				break;
287
+					break;
295 288
 
296
-			case 'DATA':
297
-				// prevent wrong handling of DATA as keyword
298
-				if ($prev_category === 'LOAD') {
299
-					$token_category = $upper;
300
-				}
301
-				break;
289
+				case 'EVENT':
290
+					// issue 71
291
+					if ($prev_category === 'DROP' || $prev_category === 'ALTER' || $prev_category === 'CREATE') {
292
+						$token_category = $upper;
293
+					}
294
+					break;
302 295
 
303
-			case 'PASSWORD':
304
-				// prevent wrong handling of PASSWORD as keyword
305
-				if ($prev_category === 'SET') {
306
-					$token_category = $upper;
307
-				}
308
-				break;
296
+				case 'DATA':
297
+					// prevent wrong handling of DATA as keyword
298
+					if ($prev_category === 'LOAD') {
299
+						$token_category = $upper;
300
+					}
301
+					break;
309 302
 
310
-			case 'INTO':
311
-				// prevent wrong handling of CACHE within LOAD INDEX INTO CACHE...
312
-				if ($prev_category === 'LOAD') {
313
-					$out[$prev_category][] = $upper;
314
-					continue 2;
315
-				}
316
-				$token_category = $upper;
317
-				break;
303
+				case 'PASSWORD':
304
+					// prevent wrong handling of PASSWORD as keyword
305
+					if ($prev_category === 'SET') {
306
+						$token_category = $upper;
307
+					}
308
+					break;
318 309
 
319
-			case 'USER':
320
-				// prevent wrong processing as keyword
321
-				if ($prev_category === 'CREATE' || $prev_category === 'RENAME' || $prev_category === 'DROP') {
310
+				case 'INTO':
311
+					// prevent wrong handling of CACHE within LOAD INDEX INTO CACHE...
312
+					if ($prev_category === 'LOAD') {
313
+						$out[$prev_category][] = $upper;
314
+						continue 2;
315
+					}
322 316
 					$token_category = $upper;
323
-				}
324
-				break;
317
+					break;
325 318
 
326
-			case 'VIEW':
327
-				// prevent wrong processing as keyword
328
-				if ($prev_category === 'CREATE' || $prev_category === 'ALTER' || $prev_category === 'DROP') {
329
-					$token_category = $upper;
330
-				}
331
-				break;
319
+				case 'USER':
320
+					// prevent wrong processing as keyword
321
+					if ($prev_category === 'CREATE' || $prev_category === 'RENAME' || $prev_category === 'DROP') {
322
+						$token_category = $upper;
323
+					}
324
+					break;
325
+
326
+				case 'VIEW':
327
+					// prevent wrong processing as keyword
328
+					if ($prev_category === 'CREATE' || $prev_category === 'ALTER' || $prev_category === 'DROP') {
329
+						$token_category = $upper;
330
+					}
331
+					break;
332 332
 
333
-			/* These tokens get their own section, but have no subclauses.
333
+				/* These tokens get their own section, but have no subclauses.
334 334
 			 These tokens identify the statement but have no specific subclauses of their own. */
335
-			case 'DELETE':
336
-			case 'ALTER':
337
-			case 'INSERT':
338
-			case 'REPLACE':
339
-			case 'TRUNCATE':
340
-			case 'CREATE':
341
-			case 'OPTIMIZE':
342
-			case 'GRANT':
343
-			case 'REVOKE':
344
-			case 'SHOW':
345
-			case 'HANDLER':
346
-			case 'LOAD':
347
-			case 'ROLLBACK':
348
-			case 'SAVEPOINT':
349
-			case 'UNLOCK':
350
-			case 'INSTALL':
351
-			case 'UNINSTALL':
352
-			case 'ANALZYE':
353
-			case 'BACKUP':
354
-			case 'CHECK':
355
-			case 'CHECKSUM':
356
-			case 'REPAIR':
357
-			case 'RESTORE':
358
-			case 'DESCRIBE':
359
-			case 'EXPLAIN':
360
-			case 'USE':
361
-			case 'HELP':
362
-				// We are using USE from FROM statement, not separate token category
363
-				if ($prev_category == 'FROM')
364
-				{
365
-					continue;
366
-				}
367
-				$token_category = $upper; /* set the category in case these get subclauses
335
+				case 'DELETE':
336
+				case 'ALTER':
337
+				case 'INSERT':
338
+				case 'REPLACE':
339
+				case 'TRUNCATE':
340
+				case 'CREATE':
341
+				case 'OPTIMIZE':
342
+				case 'GRANT':
343
+				case 'REVOKE':
344
+				case 'SHOW':
345
+				case 'HANDLER':
346
+				case 'LOAD':
347
+				case 'ROLLBACK':
348
+				case 'SAVEPOINT':
349
+				case 'UNLOCK':
350
+				case 'INSTALL':
351
+				case 'UNINSTALL':
352
+				case 'ANALZYE':
353
+				case 'BACKUP':
354
+				case 'CHECK':
355
+				case 'CHECKSUM':
356
+				case 'REPAIR':
357
+				case 'RESTORE':
358
+				case 'DESCRIBE':
359
+				case 'EXPLAIN':
360
+				case 'USE':
361
+				case 'HELP':
362
+					// We are using USE from FROM statement, not separate token category
363
+					if ($prev_category == 'FROM')
364
+					{
365
+						continue;
366
+					}
367
+					$token_category = $upper; /* set the category in case these get subclauses
368 368
 										  in a future version of MySQL */
369
-				$out[$upper][0] = $upper;
370
-				continue 2;
371
-
372
-			case 'CACHE':
373
-				if ($prev_category === "" || $prev_category === 'RESET' || $prev_category === 'FLUSH'
374
-						|| $prev_category === 'LOAD') {
375
-					$token_category = $upper;
369
+					$out[$upper][0] = $upper;
376 370
 					continue 2;
377
-				}
378
-				break;
379 371
 
380
-			/* This is either LOCK TABLES or SELECT ... LOCK IN SHARE MODE*/
381
-			case 'LOCK':
382
-				if ($token_category === "") {
383
-					$token_category = $upper;
384
-					$out[$upper][0] = $upper;
385
-				} else {
386
-					$trim = 'LOCK IN SHARE MODE';
387
-					$skip_next = true;
388
-					$out['OPTIONS'][] = $trim;
389
-				}
390
-				continue 2;
372
+				case 'CACHE':
373
+					if ($prev_category === "" || $prev_category === 'RESET' || $prev_category === 'FLUSH'
374
+							|| $prev_category === 'LOAD') {
375
+						$token_category = $upper;
376
+						continue 2;
377
+					}
378
+					break;
391 379
 
392
-			case 'USING': /* USING in FROM clause is different from USING w/ prepared statement*/
393
-				if ($token_category === 'EXECUTE') {
394
-					$token_category = $upper;
395
-					continue 2;
396
-				}
397
-				if ($token_category === 'FROM' && !empty($out['DELETE'])) {
398
-					$token_category = $upper;
380
+				/* This is either LOCK TABLES or SELECT ... LOCK IN SHARE MODE*/
381
+				case 'LOCK':
382
+					if ($token_category === "") {
383
+						$token_category = $upper;
384
+						$out[$upper][0] = $upper;
385
+					} else {
386
+						$trim = 'LOCK IN SHARE MODE';
387
+						$skip_next = true;
388
+						$out['OPTIONS'][] = $trim;
389
+					}
399 390
 					continue 2;
400
-				}
401
-				break;
402 391
 
403
-			/* DROP TABLE is different from ALTER TABLE DROP ... */
404
-			case 'DROP':
405
-				if ($token_category !== 'ALTER') {
406
-					$token_category = $upper;
407
-					$out[$upper][0] = $upper;
408
-					continue 2;
409
-				}
410
-				break;
392
+				case 'USING': /* USING in FROM clause is different from USING w/ prepared statement*/
393
+					if ($token_category === 'EXECUTE') {
394
+						$token_category = $upper;
395
+						continue 2;
396
+					}
397
+					if ($token_category === 'FROM' && !empty($out['DELETE'])) {
398
+						$token_category = $upper;
399
+						continue 2;
400
+					}
401
+					break;
411 402
 
412
-			case 'FOR':
413
-				$skip_next = true;
414
-				$out['OPTIONS'][] = 'FOR UPDATE';
415
-				continue 2;
403
+				/* DROP TABLE is different from ALTER TABLE DROP ... */
404
+				case 'DROP':
405
+					if ($token_category !== 'ALTER') {
406
+						$token_category = $upper;
407
+						$out[$upper][0] = $upper;
408
+						continue 2;
409
+					}
410
+					break;
416 411
 
417
-			case 'UPDATE':
418
-				if ($token_category === "") {
419
-					$token_category = $upper;
412
+				case 'FOR':
413
+					$skip_next = true;
414
+					$out['OPTIONS'][] = 'FOR UPDATE';
420 415
 					continue 2;
421 416
 
422
-				}
423
-				if ($token_category === 'DUPLICATE') {
424
-					continue 2;
425
-				}
426
-				break;
417
+				case 'UPDATE':
418
+					if ($token_category === "") {
419
+						$token_category = $upper;
420
+						continue 2;
427 421
 
428
-			/*case 'START':
422
+					}
423
+					if ($token_category === 'DUPLICATE') {
424
+						continue 2;
425
+					}
426
+					break;
427
+
428
+				/*case 'START':
429 429
 				$trim = "BEGIN";
430 430
 				$out[$upper][0] = $upper;
431 431
 				$skip_next = true;
432 432
 				break;*/
433 433
 
434
-			/* These tokens are ignored. */
435
-			case 'BY':
436
-			case 'ALL':
437
-			case 'SHARE':
438
-			case 'MODE':
439
-			case 'TO':
440
-			case ';':
441
-				continue 2;
442
-
443
-			case 'KEY':
444
-				if ($token_category === 'DUPLICATE') {
434
+				/* These tokens are ignored. */
435
+				case 'BY':
436
+				case 'ALL':
437
+				case 'SHARE':
438
+				case 'MODE':
439
+				case 'TO':
440
+				case ';':
445 441
 					continue 2;
446
-				}
447
-				break;
448 442
 
449
-			/* These tokens set particular options for the statement.  They never stand alone.*/
450
-			case 'HIGH_PRIORITY':
451
-			case 'LOW_PRIORITY':
452
-			case 'DELAYED':
453
-			case 'IGNORE':
454
-			case 'FORCE':
455
-			case 'STRAIGHT_JOIN':
456
-			case 'SQL_SMALL_RESULT':
457
-			case 'SQL_BIG_RESULT':
458
-			case 'QUICK':
459
-			case 'SQL_BUFFER_RESULT':
460
-			case 'SQL_CACHE':
461
-			case 'SQL_NO_CACHE':
462
-			case 'SQL_CALC_FOUND_ROWS':
463
-				$out['OPTIONS'][] = $upper;
464
-				continue 2;
465
-
466
-			case 'WITH':
467
-				if ($token_category === 'GROUP') {
468
-					$skip_next = true;
469
-					$out['OPTIONS'][] = 'WITH ROLLUP';
443
+				case 'KEY':
444
+					if ($token_category === 'DUPLICATE') {
445
+						continue 2;
446
+					}
447
+					break;
448
+
449
+				/* These tokens set particular options for the statement.  They never stand alone.*/
450
+				case 'HIGH_PRIORITY':
451
+				case 'LOW_PRIORITY':
452
+				case 'DELAYED':
453
+				case 'IGNORE':
454
+				case 'FORCE':
455
+				case 'STRAIGHT_JOIN':
456
+				case 'SQL_SMALL_RESULT':
457
+				case 'SQL_BIG_RESULT':
458
+				case 'QUICK':
459
+				case 'SQL_BUFFER_RESULT':
460
+				case 'SQL_CACHE':
461
+				case 'SQL_NO_CACHE':
462
+				case 'SQL_CALC_FOUND_ROWS':
463
+					$out['OPTIONS'][] = $upper;
470 464
 					continue 2;
471
-				}
472
-				break;
473 465
 
474
-			case 'AS':
475
-				break;
466
+				case 'WITH':
467
+					if ($token_category === 'GROUP') {
468
+						$skip_next = true;
469
+						$out['OPTIONS'][] = 'WITH ROLLUP';
470
+						continue 2;
471
+					}
472
+					break;
476 473
 
477
-			case '':
478
-			case ',':
479
-			//case ';':
480
-				break;
474
+				case 'AS':
475
+					break;
481 476
 
482
-			default:
483
-				break;
477
+				case '':
478
+				case ',':
479
+				//case ';':
480
+					break;
481
+
482
+				default:
483
+					break;
484 484
 			}
485 485
 
486 486
 			// remove obsolete category after union (empty category because of
@@ -570,14 +570,14 @@  discard block
 block discarded – undo
570 570
 		$type = substr($expression, 2, strpos($expression, ".", 2));
571 571
 
572 572
 		switch ($type) {
573
-		case 'GLOBAL':
574
-		case 'LOCAL':
575
-		case 'SESSION':
576
-			$type = strtolower($type) . '_variable';
577
-			break;
578
-		default:
579
-			$type = 'session_variable';
580
-			break;
573
+			case 'GLOBAL':
574
+			case 'LOCAL':
575
+			case 'SESSION':
576
+				$type = strtolower($type) . '_variable';
577
+				break;
578
+			default:
579
+				$type = 'session_variable';
580
+				break;
581 581
 		}
582 582
 		return $type;
583 583
 	}
@@ -591,29 +591,29 @@  discard block
 block discarded – undo
591 591
 			$upper = strtoupper(trim($token));
592 592
 
593 593
 			switch ($upper) {
594
-			case 'LOCAL':
595
-			case 'SESSION':
596
-			case 'GLOBAL':
597
-				if (!$isUpdate) {
598
-					$varType = strtolower($upper) . '_variable';
599
-					$baseExpr = "";
600
-					continue 2;
601
-				}
602
-				break;
594
+				case 'LOCAL':
595
+				case 'SESSION':
596
+				case 'GLOBAL':
597
+					if (!$isUpdate) {
598
+						$varType = strtolower($upper) . '_variable';
599
+						$baseExpr = "";
600
+						continue 2;
601
+					}
602
+					break;
603 603
 
604
-			case ',':
605
-				$assignment = $this->getAssignment($baseExpr);
606
-				if (!$isUpdate) {
607
-					if ($varType !== false) {
608
-						$assignment['sub_tree'][0]['expr_type'] = $varType;
604
+				case ',':
605
+					$assignment = $this->getAssignment($baseExpr);
606
+					if (!$isUpdate) {
607
+						if ($varType !== false) {
608
+							$assignment['sub_tree'][0]['expr_type'] = $varType;
609
+						}
609 610
 					}
610
-				}
611
-				$result[] = $assignment;
612
-				$baseExpr = "";
613
-				$varType = false;
614
-				continue 2;
611
+					$result[] = $assignment;
612
+					$baseExpr = "";
613
+					$varType = false;
614
+					continue 2;
615 615
 
616
-			default:
616
+				default:
617 617
 			}
618 618
 			$baseExpr .= $token;
619 619
 		}
@@ -867,122 +867,122 @@  discard block
 block discarded – undo
867 867
 			}
868 868
 
869 869
 			switch ($upper) {
870
-			case 'OUTER':
871
-			case 'LEFT':
872
-			case 'RIGHT':
873
-			case 'NATURAL':
874
-			case 'CROSS':
875
-			case ',':
876
-			case 'JOIN':
877
-			case 'INNER':
878
-				break;
870
+				case 'OUTER':
871
+				case 'LEFT':
872
+				case 'RIGHT':
873
+				case 'NATURAL':
874
+				case 'CROSS':
875
+				case ',':
876
+				case 'JOIN':
877
+				case 'INNER':
878
+					break;
879 879
 
880
-			default:
881
-				$parseInfo['expression'] .= $token;
882
-				if ($parseInfo['ref_type'] !== false) { // all after ON / USING
883
-					$parseInfo['ref_expr'] .= $token;
884
-				}
885
-				break;
880
+				default:
881
+					$parseInfo['expression'] .= $token;
882
+					if ($parseInfo['ref_type'] !== false) { // all after ON / USING
883
+						$parseInfo['ref_expr'] .= $token;
884
+					}
885
+					break;
886 886
 			}
887 887
 
888 888
 			switch ($upper) {
889
-			case 'AS':
890
-				$parseInfo['alias'] = array('as' => true, 'name' => "", 'base_expr' => $token);
891
-				$parseInfo['token_count']++;
892
-				$n = 1;
893
-				$str = "";
894
-				while ($str == "") {
895
-					$parseInfo['alias']['base_expr'] .= ($tokens[$i + $n] === "" ? " " : $tokens[$i + $n]);
896
-					$str = trim($tokens[$i + $n]);
897
-					++$n;
898
-				}
899
-				$parseInfo['alias']['name'] = $str;
900
-				$parseInfo['alias']['base_expr'] = trim($parseInfo['alias']['base_expr']);
901
-				continue;
902
-
903
-			case 'INDEX':
904
-				if (!empty($token_category) && $token_category == 'CREATE') {
905
-					$token_category = $upper;
906
-					continue 2;
907
-				}
889
+				case 'AS':
890
+					$parseInfo['alias'] = array('as' => true, 'name' => "", 'base_expr' => $token);
891
+					$parseInfo['token_count']++;
892
+					$n = 1;
893
+					$str = "";
894
+					while ($str == "") {
895
+						$parseInfo['alias']['base_expr'] .= ($tokens[$i + $n] === "" ? " " : $tokens[$i + $n]);
896
+						$str = trim($tokens[$i + $n]);
897
+						++$n;
898
+					}
899
+					$parseInfo['alias']['name'] = $str;
900
+					$parseInfo['alias']['base_expr'] = trim($parseInfo['alias']['base_expr']);
901
+					continue;
908 902
 
909
-				break;
903
+				case 'INDEX':
904
+					if (!empty($token_category) && $token_category == 'CREATE') {
905
+						$token_category = $upper;
906
+						continue 2;
907
+					}
910 908
 
911
-			case 'USING':
912
-			case 'ON':
913
-				$parseInfo['ref_type'] = $upper;
914
-				$parseInfo['ref_expr'] = "";
915
-				$parseInfo['token_count']++;
916
-				continue;
909
+					break;
917 910
 
918
-			case 'USE':
919
-			case 'FORCE':
920
-			case 'IGNORE':
921
-				$tableOptions = array('option' => $upper, 'name' => $upper, 'expr_type' => 'index_hints', 'base_expr' => $token);
922
-				$parseInfo['token_count']++;
923
-				$n = 1;
924
-				$tokenCount = count($token);
911
+				case 'USING':
912
+				case 'ON':
913
+					$parseInfo['ref_type'] = $upper;
914
+					$parseInfo['ref_expr'] = "";
915
+					$parseInfo['token_count']++;
916
+					continue;
925 917
 
926
-				while ($tokenCount < ($i + $n))
927
-				{
928
-					$tableOptions['base_expr'] .= ($tokens[$i + $n] === "" ? " " : $tokens[$i + $n]);
918
+				case 'USE':
919
+				case 'FORCE':
920
+				case 'IGNORE':
921
+					$tableOptions = array('option' => $upper, 'name' => $upper, 'expr_type' => 'index_hints', 'base_expr' => $token);
922
+					$parseInfo['token_count']++;
923
+					$n = 1;
924
+					$tokenCount = count($token);
929 925
 
930
-					if (strpos($tokens[$i + $n], ')') !== false)
926
+					while ($tokenCount < ($i + $n))
931 927
 					{
932
-						break;
933
-					}
928
+						$tableOptions['base_expr'] .= ($tokens[$i + $n] === "" ? " " : $tokens[$i + $n]);
934 929
 
935
-					++$n;
936
-				}
930
+						if (strpos($tokens[$i + $n], ')') !== false)
931
+						{
932
+							break;
933
+						}
937 934
 
938
-				$parseInfo['index_hints'] = $tableOptions;
939
-				continue;
940
-				break;
935
+						++$n;
936
+					}
941 937
 
942
-			case 'CROSS':
943
-			case 'INNER':
944
-			case 'OUTER':
945
-				$parseInfo['token_count']++;
946
-				continue;
938
+					$parseInfo['index_hints'] = $tableOptions;
939
+					continue;
940
+					break;
947 941
 
948
-			case 'FOR':
949
-				$parseInfo['token_count']++;
950
-				$skip_next = true;
951
-				continue;
942
+				case 'CROSS':
943
+				case 'INNER':
944
+				case 'OUTER':
945
+					$parseInfo['token_count']++;
946
+					continue;
952 947
 
953
-			case 'LEFT':
954
-			case 'RIGHT':
955
-			case 'STRAIGHT_JOIN':
956
-				$parseInfo['next_join_type'] = $upper;
957
-				break;
948
+				case 'FOR':
949
+					$parseInfo['token_count']++;
950
+					$skip_next = true;
951
+					continue;
958 952
 
959
-			case ',':
960
-				$parseInfo['next_join_type'] = 'CROSS';
953
+				case 'LEFT':
954
+				case 'RIGHT':
955
+				case 'STRAIGHT_JOIN':
956
+					$parseInfo['next_join_type'] = $upper;
957
+					break;
961 958
 
962
-			case 'JOIN':
963
-				if ($parseInfo['subquery']) {
964
-					$parseInfo['sub_tree'] = $this->parse($this->removeParenthesisFromStart($parseInfo['subquery']));
965
-					$parseInfo['expression'] = $parseInfo['subquery'];
966
-				}
959
+				case ',':
960
+					$parseInfo['next_join_type'] = 'CROSS';
967 961
 
968
-				$expr[] = $this->processFromExpression($parseInfo);
969
-				$parseInfo = $this->initParseInfoForFrom($parseInfo);
970
-				break;
962
+				case 'JOIN':
963
+					if ($parseInfo['subquery']) {
964
+						$parseInfo['sub_tree'] = $this->parse($this->removeParenthesisFromStart($parseInfo['subquery']));
965
+						$parseInfo['expression'] = $parseInfo['subquery'];
966
+					}
971 967
 
972
-			default:
973
-				if ($upper === "") {
974
-					continue; // ends the switch statement!
975
-				}
968
+					$expr[] = $this->processFromExpression($parseInfo);
969
+					$parseInfo = $this->initParseInfoForFrom($parseInfo);
970
+					break;
976 971
 
977
-				if ($parseInfo['token_count'] === 0) {
978
-					if ($parseInfo['table'] === "") {
979
-						$parseInfo['table'] = $token;
972
+				default:
973
+					if ($upper === "") {
974
+						continue; // ends the switch statement!
980 975
 					}
981
-				} else if ($parseInfo['token_count'] === 1) {
982
-					$parseInfo['alias'] = array('as' => false, 'name' => trim($token), 'base_expr' => trim($token));
983
-				}
984
-				$parseInfo['token_count']++;
985
-				break;
976
+
977
+					if ($parseInfo['token_count'] === 0) {
978
+						if ($parseInfo['table'] === "") {
979
+							$parseInfo['table'] = $token;
980
+						}
981
+					} else if ($parseInfo['token_count'] === 1) {
982
+						$parseInfo['alias'] = array('as' => false, 'name' => trim($token), 'base_expr' => trim($token));
983
+					}
984
+					$parseInfo['token_count']++;
985
+					break;
986 986
 			}
987 987
 			++$i;
988 988
 		}
@@ -1105,21 +1105,21 @@  discard block
 block discarded – undo
1105 1105
 		foreach ($tokens as $token) {
1106 1106
 			$upper = strtoupper(trim($token));
1107 1107
 			switch ($upper) {
1108
-			case ',':
1109
-				$out[] = $this->processOrderExpression($parseInfo, $select);
1110
-				$parseInfo = $this->initParseInfoForOrder();
1111
-				break;
1108
+				case ',':
1109
+					$out[] = $this->processOrderExpression($parseInfo, $select);
1110
+					$parseInfo = $this->initParseInfoForOrder();
1111
+					break;
1112 1112
 
1113
-			case 'DESC':
1114
-				$parseInfo['dir'] = "DESC";
1115
-				break;
1113
+				case 'DESC':
1114
+					$parseInfo['dir'] = "DESC";
1115
+					break;
1116 1116
 
1117
-			case 'ASC':
1118
-				$parseInfo['dir'] = "ASC";
1119
-				break;
1117
+				case 'ASC':
1118
+					$parseInfo['dir'] = "ASC";
1119
+					break;
1120 1120
 
1121
-			default:
1122
-				$parseInfo['expr'] .= $token;
1121
+				default:
1122
+					$parseInfo['expr'] .= $token;
1123 1123
 
1124 1124
 			}
1125 1125
 		}
@@ -1140,16 +1140,16 @@  discard block
 block discarded – undo
1140 1140
 		foreach ($tokens as $token) {
1141 1141
 			$trim = strtoupper(trim($token));
1142 1142
 			switch ($trim) {
1143
-			case ',':
1144
-				$parsed = $this->processOrderExpression($parseInfo, $select, true);
1145
-				unset($parsed['direction']);
1143
+				case ',':
1144
+					$parsed = $this->processOrderExpression($parseInfo, $select, true);
1145
+					unset($parsed['direction']);
1146 1146
 
1147
-				$out[] = $parsed;
1148
-				$parseInfo = $this->initParseInfoForOrder();
1149
-				break;
1150
-			default:
1151
-				$parseInfo['base_expr'] .= $token;
1152
-				$parseInfo['expr'] .= $token;
1147
+					$out[] = $parsed;
1148
+					$parseInfo = $this->initParseInfoForOrder();
1149
+					break;
1150
+				default:
1151
+					$parseInfo['base_expr'] .= $token;
1152
+					$parseInfo['expr'] .= $token;
1153 1153
 			}
1154 1154
 		}
1155 1155
 
@@ -1311,116 +1311,116 @@  discard block
 block discarded – undo
1311 1311
 				/* it is either an operator, a colref or a constant */
1312 1312
 				switch ($parseInfo['upper']) {
1313 1313
 
1314
-				case '*':
1315
-					$parseInfo['processed'] = false; // no subtree
1316
-
1317
-					// last token is colref, const or expression
1318
-					// it is an operator, in all other cases it is an all-columns-alias
1319
-					// if the previous colref ends with a dot, the * is the all-columns-alias
1320
-					if (!is_array($parseInfo['expr'])) {
1321
-						$parseInfo['tokenType'] = "colref"; // single or first element of select -> *
1322
-						break;
1323
-					}
1324
-
1325
-					$last = array_pop($parseInfo['expr']);
1326
-					if ($last['expr_type'] !== 'colref' && $last['expr_type'] !== 'const'
1327
-							&& $last['expr_type'] !== 'expression') {
1328
-						$parseInfo['expr'][] = $last;
1329
-						$parseInfo['tokenType'] = "colref";
1330
-						break;
1331
-					}
1332
-
1333
-					if ($last['expr_type'] === 'colref' && substr($last['base_expr'], -1, 1) === ".") {
1334
-						$last['base_expr'] .= '*'; // tablealias dot *
1335
-						$parseInfo['expr'][] = $last;
1336
-						continue 2;
1337
-					}
1314
+					case '*':
1315
+						$parseInfo['processed'] = false; // no subtree
1338 1316
 
1339
-					$parseInfo['expr'][] = $last;
1340
-					$parseInfo['tokenType'] = "operator";
1341
-					break;
1317
+						// last token is colref, const or expression
1318
+						// it is an operator, in all other cases it is an all-columns-alias
1319
+						// if the previous colref ends with a dot, the * is the all-columns-alias
1320
+						if (!is_array($parseInfo['expr'])) {
1321
+							$parseInfo['tokenType'] = "colref"; // single or first element of select -> *
1322
+							break;
1323
+						}
1342 1324
 
1343
-				case 'AND':
1344
-				case '&&':
1345
-				case 'BETWEEN':
1346
-				case 'BINARY':
1347
-				case '&':
1348
-				case '~':
1349
-				case '|':
1350
-				case '^':
1351
-				case 'DIV':
1352
-				case '/':
1353
-				case '<=>':
1354
-				case '=':
1355
-				case '>=':
1356
-				case '>':
1357
-				case 'IS':
1358
-				case 'NOT':
1359
-				case '<<':
1360
-				case '<=':
1361
-				case '<':
1362
-				case 'LIKE':
1363
-				case '%':
1364
-				case '!=':
1365
-				case '<>':
1366
-				case 'REGEXP':
1367
-				case '!':
1368
-				case '||':
1369
-				case 'OR':
1370
-				case '>>':
1371
-				case 'RLIKE':
1372
-				case 'SOUNDS':
1373
-				case 'XOR':
1374
-				case 'IN':
1375
-					$parseInfo['processed'] = false;
1376
-					$parseInfo['tokenType'] = "operator";
1377
-					break;
1325
+						$last = array_pop($parseInfo['expr']);
1326
+						if ($last['expr_type'] !== 'colref' && $last['expr_type'] !== 'const'
1327
+								&& $last['expr_type'] !== 'expression') {
1328
+							$parseInfo['expr'][] = $last;
1329
+							$parseInfo['tokenType'] = "colref";
1330
+							break;
1331
+						}
1378 1332
 
1379
-				case 'NULL':
1380
-					$parseInfo['processed'] = false;
1381
-					$parseInfo['tokenType'] = 'const';
1382
-					break;
1333
+						if ($last['expr_type'] === 'colref' && substr($last['base_expr'], -1, 1) === ".") {
1334
+							$last['base_expr'] .= '*'; // tablealias dot *
1335
+							$parseInfo['expr'][] = $last;
1336
+							continue 2;
1337
+						}
1383 1338
 
1384
-				case '-':
1385
-				case '+':
1386
-				// differ between preceding sign and operator
1387
-					$parseInfo['processed'] = false;
1339
+						$parseInfo['expr'][] = $last;
1340
+						$parseInfo['tokenType'] = "operator";
1341
+						break;
1388 1342
 
1389
-					if ($parseInfo['prevTokenType'] === 'colref' || $parseInfo['prevTokenType'] === 'function'
1390
-							|| $parseInfo['prevTokenType'] === 'aggregate_function'
1391
-							|| $parseInfo['prevTokenType'] === 'const'
1392
-							|| $parseInfo['prevTokenType'] === 'subquery') {
1343
+					case 'AND':
1344
+					case '&&':
1345
+					case 'BETWEEN':
1346
+					case 'BINARY':
1347
+					case '&':
1348
+					case '~':
1349
+					case '|':
1350
+					case '^':
1351
+					case 'DIV':
1352
+					case '/':
1353
+					case '<=>':
1354
+					case '=':
1355
+					case '>=':
1356
+					case '>':
1357
+					case 'IS':
1358
+					case 'NOT':
1359
+					case '<<':
1360
+					case '<=':
1361
+					case '<':
1362
+					case 'LIKE':
1363
+					case '%':
1364
+					case '!=':
1365
+					case '<>':
1366
+					case 'REGEXP':
1367
+					case '!':
1368
+					case '||':
1369
+					case 'OR':
1370
+					case '>>':
1371
+					case 'RLIKE':
1372
+					case 'SOUNDS':
1373
+					case 'XOR':
1374
+					case 'IN':
1375
+						$parseInfo['processed'] = false;
1393 1376
 						$parseInfo['tokenType'] = "operator";
1394
-					} else {
1395
-						$parseInfo['tokenType'] = "sign";
1396
-					}
1397
-					break;
1377
+						break;
1398 1378
 
1399
-				default:
1400
-					switch ($parseInfo['token'][0]) {
1401
-					case "'":
1402
-					case '"':
1379
+					case 'NULL':
1380
+						$parseInfo['processed'] = false;
1403 1381
 						$parseInfo['tokenType'] = 'const';
1404 1382
 						break;
1405
-					case '`':
1406
-						$parseInfo['tokenType'] = 'colref';
1407
-						break;
1408 1383
 
1409
-					default:
1410
-						if (is_numeric($parseInfo['token'])) {
1411
-							$parseInfo['tokenType'] = 'const';
1412
-
1413
-							if ($parseInfo['prevTokenType'] === 'sign') {
1414
-								array_pop($parseInfo['expr']);
1415
-								$parseInfo['token'] = $parseInfo['prevToken'] . $parseInfo['token'];
1416
-							}
1384
+					case '-':
1385
+					case '+':
1386
+					// differ between preceding sign and operator
1387
+						$parseInfo['processed'] = false;
1417 1388
 
1389
+						if ($parseInfo['prevTokenType'] === 'colref' || $parseInfo['prevTokenType'] === 'function'
1390
+								|| $parseInfo['prevTokenType'] === 'aggregate_function'
1391
+								|| $parseInfo['prevTokenType'] === 'const'
1392
+								|| $parseInfo['prevTokenType'] === 'subquery') {
1393
+							$parseInfo['tokenType'] = "operator";
1418 1394
 						} else {
1419
-							$parseInfo['tokenType'] = 'colref';
1395
+							$parseInfo['tokenType'] = "sign";
1420 1396
 						}
1421 1397
 						break;
1422 1398
 
1423
-					}
1399
+					default:
1400
+						switch ($parseInfo['token'][0]) {
1401
+							case "'":
1402
+							case '"':
1403
+								$parseInfo['tokenType'] = 'const';
1404
+								break;
1405
+							case '`':
1406
+								$parseInfo['tokenType'] = 'colref';
1407
+								break;
1408
+
1409
+							default:
1410
+								if (is_numeric($parseInfo['token'])) {
1411
+									$parseInfo['tokenType'] = 'const';
1412
+
1413
+									if ($parseInfo['prevTokenType'] === 'sign') {
1414
+										array_pop($parseInfo['expr']);
1415
+										$parseInfo['token'] = $parseInfo['prevToken'] . $parseInfo['token'];
1416
+									}
1417
+
1418
+								} else {
1419
+									$parseInfo['tokenType'] = 'colref';
1420
+								}
1421
+								break;
1422
+
1423
+						}
1424 1424
 					$parseInfo['processed'] = false;
1425 1425
 				}
1426 1426
 			}
@@ -1431,36 +1431,36 @@  discard block
 block discarded – undo
1431 1431
 					&& in_array($parseInfo['upper'], parent::$reserved)) {
1432 1432
 
1433 1433
 				switch ($parseInfo['upper']) {
1434
-				case 'AVG':
1435
-				case 'SUM':
1436
-				case 'COUNT':
1437
-				case 'MIN':
1438
-				case 'MAX':
1439
-				case 'STDDEV':
1440
-				case 'STDDEV_SAMP':
1441
-				case 'STDDEV_POP':
1442
-				case 'VARIANCE':
1443
-				case 'VAR_SAMP':
1444
-				case 'VAR_POP':
1445
-				case 'GROUP_CONCAT':
1446
-				case 'BIT_AND':
1447
-				case 'BIT_OR':
1448
-				case 'BIT_XOR':
1449
-					$parseInfo['tokenType'] = 'aggregate_function';
1450
-					break;
1434
+					case 'AVG':
1435
+					case 'SUM':
1436
+					case 'COUNT':
1437
+					case 'MIN':
1438
+					case 'MAX':
1439
+					case 'STDDEV':
1440
+					case 'STDDEV_SAMP':
1441
+					case 'STDDEV_POP':
1442
+					case 'VARIANCE':
1443
+					case 'VAR_SAMP':
1444
+					case 'VAR_POP':
1445
+					case 'GROUP_CONCAT':
1446
+					case 'BIT_AND':
1447
+					case 'BIT_OR':
1448
+					case 'BIT_XOR':
1449
+						$parseInfo['tokenType'] = 'aggregate_function';
1450
+						break;
1451 1451
 
1452
-				case 'NULL':
1453
-				// it is a reserved word, but we would like to have set it as constant
1454
-					$parseInfo['tokenType'] = 'const';
1455
-					break;
1452
+					case 'NULL':
1453
+					// it is a reserved word, but we would like to have set it as constant
1454
+						$parseInfo['tokenType'] = 'const';
1455
+						break;
1456 1456
 
1457
-				default:
1458
-					if (in_array($parseInfo['upper'], parent::$functions)) {
1459
-						$parseInfo['tokenType'] = 'function';
1460
-					} else {
1461
-						$parseInfo['tokenType'] = 'reserved';
1462
-					}
1463
-					break;
1457
+					default:
1458
+						if (in_array($parseInfo['upper'], parent::$functions)) {
1459
+							$parseInfo['tokenType'] = 'function';
1460
+						} else {
1461
+							$parseInfo['tokenType'] = 'reserved';
1462
+						}
1463
+						break;
1464 1464
 				}
1465 1465
 			}
1466 1466
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1060,10 +1060,11 @@  discard block
 block discarded – undo
1060 1060
 			return false;
1061 1061
 		}
1062 1062
 
1063
-		if ($groupby)
1064
-			$parseInfo['expr'] = trim($parseInfo['expr']);
1065
-		else
1066
-			$parseInfo['expr'] = trim($this->revokeEscaping($parseInfo['expr']));
1063
+		if ($groupby) {
1064
+					$parseInfo['expr'] = trim($parseInfo['expr']);
1065
+		} else {
1066
+					$parseInfo['expr'] = trim($this->revokeEscaping($parseInfo['expr']));
1067
+		}
1067 1068
 
1068 1069
 		if (is_numeric($parseInfo['expr'])) {
1069 1070
 			$parseInfo['type'] = 'pos';
@@ -1510,8 +1511,9 @@  discard block
 block discarded – undo
1510 1511
 
1511 1512
 		$into = $tokens['INTO'];
1512 1513
 		foreach ($into as $token) {
1513
-			if (trim($token) === "")
1514
-				continue;
1514
+			if (trim($token) === "") {
1515
+							continue;
1516
+			}
1515 1517
 			if ($table === "") {
1516 1518
 				$table = $token;
1517 1519
 			} elseif (empty($cols)) {
Please login to merge, or discard this patch.