Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error on SQL with DELIMITER statements #8

Open
ktarasov opened this issue Nov 3, 2023 · 0 comments
Open

Fatal error on SQL with DELIMITER statements #8

ktarasov opened this issue Nov 3, 2023 · 0 comments

Comments

@ktarasov
Copy link

ktarasov commented Nov 3, 2023

Hi.

The parser throw fatal error on SQL with DELIMITER statements.
Test code:

<?php

use Kodus\SQLSplit\Splitter;

require 'vendor/autoload.php';

$sql = <<<SQL
	DELIMITER $$

	CREATE OR REPLACE FUNCTION `someFunc`(`percent` INT UNSIGNED) RETURNS double(15,2)
		NO SQL
	BEGIN
		IF percent = 100 THEN
			RETURN 0.00;
		END IF;

		RETURN 100;
	END
	$$

	DELIMITER ;
SQL;

$statements = Splitter::split($sql);
var_dump($statements);

Output:

PHP Fatal error:  Uncaught RuntimeException: unexpected input: expected delimiter character(s), at: 201, got: ";" in /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Tokenizer.php:320
Stack trace:
#0 /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Tokenizer.php(93): Kodus\SQLSplit\Tokenizer->fail()
#1 /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Tokenizer.php(50): Kodus\SQLSplit\Tokenizer->statement()
#2 /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Tokenizer.php(34): Kodus\SQLSplit\Tokenizer->statements()
#3 /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Splitter.php(18): Kodus\SQLSplit\Tokenizer::tokenize()
#4 /home/kvt/Dev/tmp/tst/testSQL/test.php(24): Kodus\SQLSplit\Splitter::split()
#5 {main}
  thrown in /home/kvt/Dev/tmp/tst/testSQL/vendor/kodus/sql-split/src/Tokenizer.php on line 320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant