Skip to content

Commit 8945632

Browse files
committed
Not Like: Implementation
1 parent 44dfc18 commit 8945632

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/SQLParser/Node/NodeFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public static function mapArrayToNodeObjectList(array $items)
497497
array('<<', '>>'),
498498
array('&'),
499499
array('|'),
500-
array('=' /*(comparison)*/, '<=>', '>=', '>', '<=', '<', '<>', '!=', 'IS', 'LIKE', 'REGEXP', 'IN', 'IS NOT', 'NOT IN'),
500+
array('=' /*(comparison)*/, '<=>', '>=', '>', '<=', '<', '<>', '!=', 'IS', 'LIKE', 'REGEXP', 'IN', 'IS NOT', 'NOT IN', 'NOT LIKE'),
501501
array('AND_FROM_BETWEEN'),
502502
array('THEN'),
503503
array('WHEN'),
@@ -520,6 +520,7 @@ public static function mapArrayToNodeObjectList(array $items)
520520
'IS' => 'SQLParser\Node\Is',
521521
'IS NOT' => 'SQLParser\Node\IsNot',
522522
'LIKE' => 'SQLParser\Node\Like',
523+
'NOT LIKE' => 'SQLParser\Node\NotLike',
523524
'REGEXP' => 'SQLParser\Node\Regexp',
524525
'IN' => 'SQLParser\Node\In',
525526
'NOT IN' => 'SQLParser\Node\NotIn',
@@ -578,6 +579,12 @@ public static function simplify($nodes)
578579
$notIn->setValue('NOT IN');
579580
$newNodes[] = $notIn;
580581
++$i;
582+
} elseif ($node instanceof Operator && isset($nodes[$i + 1]) && $nodes[$i + 1] instanceof Operator
583+
&& strtoupper($node->getValue()) == 'NOT' && strtoupper($nodes[$i + 1]->getValue()) == 'LIKE') {
584+
$notLike = new Operator();
585+
$notLike->setValue('NOT LIKE');
586+
$newNodes[] = $notLike;
587+
++$i;
581588
} else {
582589
$newNodes[] = $node;
583590
}

src/SQLParser/Node/NotLike.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace SQLParser\Node;
4+
5+
/**
6+
* This class represents an NOT LIKE operation in an SQL expression.
7+
*
8+
* @author David Négrier <[email protected]>
9+
*/
10+
class NotLike extends AbstractTwoOperandsOperator
11+
{
12+
/**
13+
* Returns the symbol for this operator.
14+
*
15+
* @return string
16+
*/
17+
protected function getOperatorSymbol()
18+
{
19+
return 'NOT LIKE';
20+
}
21+
}

0 commit comments

Comments
 (0)