Passed
Branch develop (d6f62e)
by Tito
06:29
created
libraries/redcore/layouts/webservice/documentationoperation/example.php 1 patch
Switch Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -31,39 +31,39 @@
 block discarded – undo
31 31
 
32 32
 switch ($operationName)
33 33
 {
34
-	case 'create' :
35
-		$method = 'POST';
36
-		$errorList = array(201, 400, 404, 405, 406, 500);
37
-		break;
38
-	case 'read list' :
39
-		$method = 'GET';
40
-		$noteName = '_LIST';
41
-		$errorList = array(200, 405, 500);
42
-		break;
43
-	case 'read item' :
44
-		$fields = RApiHalHelper::getFieldsArray($operationXml, true, true);
45
-		$method = 'GET';
46
-		$noteName = '_ITEM';
47
-		$errorList = array(200, 404, 405, 500);
48
-
49
-		foreach ($fields as $primaryKey => $primaryKeyField)
50
-		{
51
-			$defaultValue = !empty($primaryKeyField['defaultValue']) ? $primaryKeyField['defaultValue'] : 1;
52
-			$basicUrl .= '&' . $primaryKey . '=' . $defaultValue;
53
-		}
54
-		break;
55
-	case 'update' :
56
-		$method = 'PUT';
57
-		$errorList = array(200, 400, 405, 406, 500);
58
-		break;
59
-	case 'delete' :
60
-		$method = 'DELETE';
61
-		$errorList = array(200, 400, 405, 406, 500);
62
-		break;
63
-	case 'task' :
64
-		$method = 'GET / POST';
65
-		$errorList = array(200, 400, 405, 406, 500);
66
-		break;
34
+		case 'create' :
35
+			$method = 'POST';
36
+			$errorList = array(201, 400, 404, 405, 406, 500);
37
+			break;
38
+		case 'read list' :
39
+			$method = 'GET';
40
+			$noteName = '_LIST';
41
+			$errorList = array(200, 405, 500);
42
+			break;
43
+		case 'read item' :
44
+			$fields = RApiHalHelper::getFieldsArray($operationXml, true, true);
45
+			$method = 'GET';
46
+			$noteName = '_ITEM';
47
+			$errorList = array(200, 404, 405, 500);
48
+
49
+			foreach ($fields as $primaryKey => $primaryKeyField)
50
+			{
51
+				$defaultValue = !empty($primaryKeyField['defaultValue']) ? $primaryKeyField['defaultValue'] : 1;
52
+				$basicUrl .= '&' . $primaryKey . '=' . $defaultValue;
53
+			}
54
+			break;
55
+		case 'update' :
56
+			$method = 'PUT';
57
+			$errorList = array(200, 400, 405, 406, 500);
58
+			break;
59
+		case 'delete' :
60
+			$method = 'DELETE';
61
+			$errorList = array(200, 400, 405, 406, 500);
62
+			break;
63
+		case 'task' :
64
+			$method = 'GET / POST';
65
+			$errorList = array(200, 400, 405, 406, 500);
66
+			break;
67 67
 }
68 68
 
69 69
 if (!$authorizationNotNeeded):
Please login to merge, or discard this patch.
extensions/libraries/redcore/database/sqlparser/sqlcreator.php 1 patch
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.
extensions/libraries/redcore/database/sqlparser/sqlparser.php 1 patch
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.