Skip to content

Commit 0fcfb67

Browse files
Resolved conflicts
2 parents f70e1d5 + b169bb7 commit 0fcfb67

5 files changed

Lines changed: 43 additions & 11 deletions

File tree

UPGRADING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ From version 2.0.0, the namespace of the `Splitter` and `Tokenizer` has changed
1212
<?php
1313

1414
-use Kodus\SQLSplit\Splitter;
15-
+use Kodus\SQLSPlit\Splitter;
15+
+use Kodus\SQLSplit\Splitter;
1616
-use Kodus\SQLSplit\Tokenizer;
17-
+use Kodus\SQLSPlit\Tokenizer;
17+
+use Kodus\SQLSplit\Tokenizer;
1818
```
1919

2020
_The namespace Kodus/SQL collided with a namespace of another (private) kodus repository. The namespace `Kodus\SQL` is

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"name": "Rasmus Schultz",
99
"email": "rasmus@mindplay.dk"
1010
},
11-
{
11+
{
1212
"name": "Thomas Nordahl Pedersen",
1313
"email": "thno@jfmedier.dk"
14-
}
14+
}
1515
],
1616
"require": {
1717
"php": ">=8.0"

src/Tokenizer.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,24 @@ protected function statements(): array
4646
{
4747
$statements = [];
4848

49-
$result = $this->statement();
50-
while ($result) {
51-
$statements[] = $result;
49+
do {
5250
$result = $this->statement();
53-
}
51+
if ($result !== null && count($result) > 0) {
52+
$statements[] = $result;
53+
}
54+
} while ($result !== null);
55+
5456

5557
return $statements;
5658
}
5759

5860
/**
61+
* Returns an array containing the tokens in the next statement of the input.
62+
*
63+
* Returns empty array on empty statements (i.e. repeated delimiters, like: ;;;).
64+
*
65+
* Returns null if End-Of-File reached.
66+
*
5967
* @return string[]|null
6068
*/
6169
protected function statement(): ?array
@@ -67,8 +75,13 @@ protected function statement(): ?array
6775
}
6876

6977
$tokens = [];
78+
7079
$token = $this->token();
7180
while ($token !== "") {
81+
/**
82+
* DEV NOTE: This checks for DELIMITER statement, that changes delimiter from ; to something else.
83+
* If detected, it will extract the new DELIMITER and reassign $this->delimiter_pattern.
84+
*/
7285
if (is_string($token) && preg_match('/^delimiter$/i', $token) === 1) {
7386
// Omit DELIMITER command - it isn't part of SQL statement syntax
7487

tests/unit/SplitterCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace unit;
44

55
use Codeception\Example;
6-
use Kodus\SQL\Splitter;
6+
use Kodus\SQLSplit\Splitter;
77
use UnitTester;
88

99
class SplitterCest

tests/unit/TokenizerCest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace unit;
44

55
use Codeception\Example;
6-
use Codeception\PHPUnit\TestCase;
7-
use Kodus\SQL\Tokenizer;
6+
use Kodus\SQLSplit\Tokenizer;
87
use UnitTester;
98

109
class TokenizerCest
@@ -138,6 +137,26 @@ protected function useCases(): array
138137
["/* three\nfour */", "\n", "SELECT", " ", "2"],
139138
],
140139
],
140+
[
141+
self::MESSAGE => "Empty statement - in between",
142+
self::INPUT => "SELECT 1;; SELECT 2",
143+
self::EXPECTED => [["SELECT", " ", "1"], ["SELECT", " ", "2"]],
144+
],
145+
[
146+
self::MESSAGE => "Empty statements - first",
147+
self::INPUT => ";;SELECT 1; SELECT 2;",
148+
self::EXPECTED => [["SELECT", " ", "1"], ["SELECT", " ", "2"]],
149+
],
150+
[
151+
self::MESSAGE => "Empty statements - last",
152+
self::INPUT => "SELECT 1; SELECT 2;;;",
153+
self::EXPECTED => [["SELECT", " ", "1"], ["SELECT", " ", "2"]],
154+
],
155+
[
156+
self::MESSAGE => "Empty statements - all over",
157+
self::INPUT => ";;;;SELECT 1;;;; SELECT 2;;;",
158+
self::EXPECTED => [["SELECT", " ", "1"], ["SELECT", " ", "2"]],
159+
],
141160
];
142161
}
143162
}

0 commit comments

Comments
 (0)