diff --git a/src/PHPSQLParser/positions/PositionCalculator.php b/src/PHPSQLParser/positions/PositionCalculator.php index 53eb57f6..0808b96a 100644 --- a/src/PHPSQLParser/positions/PositionCalculator.php +++ b/src/PHPSQLParser/positions/PositionCalculator.php @@ -127,6 +127,9 @@ public function setPositionsWithinSQL($sql, $parsed) { } protected function findPositionWithinString($sql, $value, $expr_type) { + if ($value === '') { + return false; + } $offset = 0; $ok = false; diff --git a/tests/cases/parser/issue320Test.php b/tests/cases/parser/issue320Test.php new file mode 100644 index 00000000..1f3b274e --- /dev/null +++ b/tests/cases/parser/issue320Test.php @@ -0,0 +1,60 @@ + + * @copyright 2010-2014 Justin Swanhart and André Rothe + * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) + * @version SVN: $Id$ + */ +namespace PHPSQLParser\Test\Parser; +use PHPSQLParser\PHPSQLParser; +use PHPSQLParser\PHPSQLCreator; + +class issue320Test extends \PHPUnit_Framework_TestCase +{ + public function test_no_warning_is_issued_when_help_table_is_used() + { + $parser = new PHPSQLParser(); + $sql = 'SELECT * FROM help'; + + // there currently is an exception because `HELP` is a keyword + // but this query seems valid at least in mysql and mssql + // so ideally PHPSQLParser would be able to parse it + $this->setExpectedException( + '\PHPSQLParser\exceptions\UnableToCalculatePositionException' + ); + + $parser->parse($sql, true); + } +}