From c4e6265d1d601c1b04faa08d9463c2963e52b94e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 4 Feb 2022 15:29:41 +0100 Subject: [PATCH] doctrine dbal: fix error detection in queries without args (#246) Co-authored-by: Markus Staab --- .phpstan-dba.cache | 169 +++++++++++++++++- ...ntaxErrorInPreparedStatementMethodRule.php | 38 ++-- ...ErrorInPreparedStatementMethodRuleTest.php | 4 + tests/default/config/.phpstan-dba.cache | 153 +++++++++++++++- .../default/config/.phpunit-phpstan-dba.cache | 132 +------------- .../syntax-error-in-prepared-statement.php | 6 + tests/stringify/config/.phpstan-dba.cache | 1 - .../config/.phpunit-phpstan-dba.cache | 1 - 8 files changed, 358 insertions(+), 146 deletions(-) diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index b24f62554..d386135cb 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -180,9 +180,28 @@ )), ), ), + 'SELECT email adaid WHERE gesperrt freigabe1u1 FROM ada' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'freigabe1u1 FROM ada LIMIT 0\' at line 1', + 'code' => 1064, + )), + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email adaid gesperrt freigabe1u1 FROM ada' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'gesperrt freigabe1u1 FROM ada LIMIT 0\' at line 1', + 'code' => 1064, + )), + ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -787,6 +806,154 @@ )), ), ), + 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada; ' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 4 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + 5 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 6 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + 7 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + 2 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 3 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 4 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 5 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 6 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + 7 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 127, + )), + ), + 'nextAutoIndex' => 4, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 2 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 3, + )), + 4 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 5 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + 6 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'freigabe1u1', + 'isClassString' => false, + )), + 7 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'gesperrt', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -128, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), + ), + ), ), 'runtimeConfig' => array ( diff --git a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php index cbcdaf0d1..59229d7e2 100644 --- a/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php +++ b/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php @@ -91,7 +91,7 @@ private function checkErrors(CallLike $callLike, Scope $scope): array { $args = $callLike->getArgs(); - if (\count($args) < 2) { + if (\count($args) < 1) { return []; } @@ -102,19 +102,28 @@ private function checkErrors(CallLike $callLike, Scope $scope): array } $queryReflection = new QueryReflection(); - $parameterTypes = $scope->getType($args[1]->value); - try { - $parameters = $queryReflection->resolveParameters($parameterTypes) ?? []; - } catch (UnresolvableQueryException $exception) { - return [ - RuleErrorBuilder::message($exception->asRuleMessage())->tip(UnresolvableQueryException::RULE_TIP)->line($callLike->getLine())->build(), - ]; + + $parameters = null; + if (\count($args) > 1) { + $parameterTypes = $scope->getType($args[1]->value); + try { + $parameters = $queryReflection->resolveParameters($parameterTypes) ?? []; + } catch (UnresolvableQueryException $exception) { + return [ + RuleErrorBuilder::message($exception->asRuleMessage())->tip(UnresolvableQueryException::RULE_TIP)->line($callLike->getLine())->build(), + ]; + } + } + + if (null === $parameters) { + $queryStrings = $queryReflection->resolveQueryStrings($queryExpr, $scope); + } else { + $queryStrings = $queryReflection->resolvePreparedQueryStrings($queryExpr, $parameterTypes, $scope); } $errors = []; - $placeholderValidation = new PlaceholderValidation(); try { - foreach ($queryReflection->resolvePreparedQueryStrings($queryExpr, $parameterTypes, $scope) as $queryString) { + foreach ($queryStrings as $queryString) { $queryError = $queryReflection->validateQueryString($queryString); if (null !== $queryError) { $error = $queryError->asRuleMessage(); @@ -122,9 +131,12 @@ private function checkErrors(CallLike $callLike, Scope $scope): array } } - foreach ($placeholderValidation->checkQuery($queryExpr, $scope, $parameters) as $error) { - // make error messages unique - $errors[$error] = $error; + if (null !== $parameters) { + $placeholderValidation = new PlaceholderValidation(); + foreach ($placeholderValidation->checkQuery($queryExpr, $scope, $parameters) as $error) { + // make error messages unique + $errors[$error] = $error; + } } $ruleErrors = []; diff --git a/tests/default/SyntaxErrorInPreparedStatementMethodRuleTest.php b/tests/default/SyntaxErrorInPreparedStatementMethodRuleTest.php index 4d077403f..49c81dfaa 100644 --- a/tests/default/SyntaxErrorInPreparedStatementMethodRuleTest.php +++ b/tests/default/SyntaxErrorInPreparedStatementMethodRuleTest.php @@ -61,6 +61,10 @@ public function testSyntaxErrorInQueryRule(): void 'Query expects placeholder :name, but it is missing from values given.', 307, ], + [ + "Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'gesperrt freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).", + 319, + ], ]); } } diff --git a/tests/default/config/.phpstan-dba.cache b/tests/default/config/.phpstan-dba.cache index b142ac377..0589f0da3 100644 --- a/tests/default/config/.phpstan-dba.cache +++ b/tests/default/config/.phpstan-dba.cache @@ -9,6 +9,10 @@ 'message' => 'Unknown column \'doesNotExist\' in \'group statement\'', 'code' => 1054, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT * FROM ada ORDER BY doesNotExist' => array ( @@ -17,6 +21,10 @@ 'message' => 'Unknown column \'doesNotExist\' in \'order clause\'', 'code' => 1054, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT * FROM ada WHERE doesNotExist=1' => array ( @@ -25,9 +33,14 @@ 'message' => 'Unknown column \'doesNotExist\' in \'where clause\'', 'code' => 1054, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT * FROM typemix' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -661,9 +674,14 @@ 'message' => 'Table \'phpstan_dba.unknownTable\' doesn\'t exist', 'code' => 1146, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT MAX(adaid), MIN(adaid), COUNT(adaid), AVG(adaid) FROM ada WHERE adaid = 1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -788,6 +806,7 @@ ), 'SELECT a.email, b.adaid, b.gesperrt FROM ada a LEFT JOIN ada b ON a.adaid=b.adaid' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -892,6 +911,7 @@ ), 'SELECT adaid FROM ada LIMIT 1 FOR SHARE' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -932,6 +952,7 @@ ), 'SELECT adaid FROM ada LIMIT 1 OFFSET 1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -972,6 +993,7 @@ ), 'SELECT adaid FROM ada LIMIT 1 OFFSET 1 FOR UPDATE' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -1012,6 +1034,7 @@ ), 'SELECT adaid FROM ada WHERE adaid IN (\'1\')' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1131,7 +1154,6 @@ ), 'SELECT adaid FROM ada WHERE adaid IN (\'1\') AND email LIKE \'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1191,6 +1213,7 @@ ), 'SELECT adaid FROM ada WHERE adaid IN (\'1.0\')' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1255,6 +1278,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':adaids) LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT adaid FROM ada WHERE adaid IN (:ids)' => array ( @@ -1263,6 +1290,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':ids) LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT adaid FROM ada WHERE adaid IN (:ids) AND email LIKE :time' => array ( @@ -1271,6 +1302,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':ids) AND email LIKE :time LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'1\'' => array ( @@ -1334,7 +1369,6 @@ ), 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1394,6 +1428,7 @@ ), 'SELECT adaid FROM ada WHERE email LIKE ":gesperrt%"' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1487,6 +1522,7 @@ ), 'SELECT adaid FROM ada WHERE email LIKE "hello?%"' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1580,6 +1616,7 @@ ), 'SELECT adaid FROM ada WHERE email LIKE \'%questions ?%\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1673,6 +1710,7 @@ ), 'SELECT adaid FROM ada WHERE email LIKE \':gesperrt%\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -1826,7 +1864,6 @@ ), 'SELECT adaid FROM ada WHERE email=\'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1891,9 +1928,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':email LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT akid FROM ak WHERE eadavk>1.0' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -1934,6 +1976,7 @@ ), 'SELECT akid FROM ak WHERE eadavk>1.1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -1974,7 +2017,6 @@ ), 'SELECT count(*) FROM typemix WHERE c_date = \'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2028,7 +2070,6 @@ ), 'SELECT count(*) FROM typemix WHERE c_datetime = \'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2087,9 +2128,14 @@ 'message' => 'Unknown column \'doesNotExist\' in \'field list\'', 'code' => 1054, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT eladaid FROM ak' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -2153,9 +2199,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':gesperrt LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email FROM ada WHERE gesperrt=NULL' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -2214,9 +2265,28 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'freigabe1u1 FROM ada LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 3 => NULL, + 5 => NULL, + 4 => NULL, + ), + ), + 'SELECT email adaid gesperrt freigabe1u1 FROM ada' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'gesperrt freigabe1u1 FROM ada LIMIT 0\' at line 1', + 'code' => 1064, + )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -2434,9 +2504,14 @@ 'message' => 'Unknown column \'xy\' in \'group statement\'', 'code' => 1054, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = \'1\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -2529,6 +2604,7 @@ ), 'SELECT email, adaid FROM ada WHERE adaid = \'1\' and email = \'email@example.org\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -2626,6 +2702,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':email LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = \'1\' and email = ?' => array ( @@ -2634,6 +2714,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = :adaid' => array ( @@ -2642,6 +2726,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':adaid LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = :adaid and email = \'email@example.org\'' => array ( @@ -2650,6 +2738,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':adaid and email = \'email@example.org\' LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = :adaid and email = :email' => array ( @@ -2658,6 +2750,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':adaid and email = :email LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = ?' => array ( @@ -2666,6 +2762,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid = ? and email = ?' => array ( @@ -2674,9 +2774,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? and email = ? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE adaid=1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -2831,6 +2936,7 @@ ), 'SELECT email, adaid FROM ada WHERE email <=> \'\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -2928,9 +3034,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':email LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE email = \'email@example.org\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -3023,6 +3134,7 @@ ), 'SELECT email, adaid FROM ada WHERE email = \'test@example.org\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -3120,6 +3232,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \':email LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid FROM ada WHERE email = ?' => array ( @@ -3128,6 +3244,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid GROUP BY xy FROM ada LIMIT 1' => array ( @@ -3136,9 +3256,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'FROM ada LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 3 => NULL, + ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -3463,6 +3588,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -3561,6 +3687,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -3659,6 +3786,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1, 10' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -3757,6 +3885,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = \'1\'' => array ( + 'error' => NULL, 'result' => array ( 5 => @@ -3905,6 +4034,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = 1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -4008,9 +4138,14 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid=1' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -4114,6 +4249,10 @@ 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'? LIMIT 0\' at line 1', 'code' => 1064, )), + 'result' => + array ( + 5 => NULL, + ), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'1\'' => array ( @@ -4266,7 +4405,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'2022-02-04\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -4415,6 +4553,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'test@example.org\'' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -4513,6 +4652,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email=\'foo\'' => array ( + 'error' => NULL, 'result' => array ( 3 => @@ -4611,6 +4751,7 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE gesperrt = \'1\'' => array ( + 'error' => NULL, 'result' => array ( 3 => diff --git a/tests/default/config/.phpunit-phpstan-dba.cache b/tests/default/config/.phpunit-phpstan-dba.cache index 0c75fa584..f52262f82 100644 --- a/tests/default/config/.phpunit-phpstan-dba.cache +++ b/tests/default/config/.phpunit-phpstan-dba.cache @@ -121,125 +121,6 @@ array ( 'error' => NULL, ), - ' - SELECT email adaid - WHERE gesperrt = \'1\' AND email LIKE \'%@example.com\' - FROM ada - LIMIT 1 - ' => - array ( - 'error' => - staabm\PHPStanDba\Error::__set_state(array( - 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'FROM ada LIMIT 0\' at line 3', - 'code' => 1064, - )), - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - FOR UPDATE - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - FOR UPDATE - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - OFFSET \'1\' - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - OFFSET \'1\' - FOR SHARE - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - OFFSET \'1\' - FOR UPDATE - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\' - OFFSET 1 - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\', \'1\' - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' - LIMIT \'1\', \'1\' - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' AND email LIKE \'%@example%\' - LIMIT 1 - ' => - array ( - 'error' => NULL, - ), - ' - SELECT email, adaid - FROM ada - WHERE gesperrt = \'1\' AND email LIKE NULL - LIMIT 1 - ' => - array ( - 'error' => NULL, - ), 'SELECT * FROM ada GROUP BY doesNotExist' => array ( 'error' => @@ -2333,6 +2214,14 @@ 3 => NULL, ), ), + 'SELECT email adaid gesperrt freigabe1u1 FROM ada' => + array ( + 'error' => + staabm\PHPStanDba\Error::__set_state(array( + 'message' => 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near \'gesperrt freigabe1u1 FROM ada LIMIT 0\' at line 1', + 'code' => 1064, + )), + ), 'SELECT email, adaid FROM ada' => array ( 'error' => NULL, @@ -3504,11 +3393,6 @@ array ( 'error' => NULL, ), - 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada - WHERE (gesperrt=\'1\' AND freigabe1u1=1) OR (gesperrt=\'1\' AND freigabe1u1=0)' => - array ( - 'error' => NULL, - ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' => array ( 'error' => NULL, diff --git a/tests/default/data/syntax-error-in-prepared-statement.php b/tests/default/data/syntax-error-in-prepared-statement.php index 3c5bef686..99e837226 100644 --- a/tests/default/data/syntax-error-in-prepared-statement.php +++ b/tests/default/data/syntax-error-in-prepared-statement.php @@ -312,4 +312,10 @@ public function noErrorOnTraillingSemicolonAndWhitespace(Connection $connection) $query = 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada; '; $connection->preparedQuery($query, []); } + + public function errorOnQueryWithoutArgs(\Doctrine\DBAL\Connection $connection) + { + $query = 'SELECT email adaid gesperrt freigabe1u1 FROM ada'; + $connection->executeQuery($query); + } } diff --git a/tests/stringify/config/.phpstan-dba.cache b/tests/stringify/config/.phpstan-dba.cache index 4c39b5c8b..2c3c111b7 100644 --- a/tests/stringify/config/.phpstan-dba.cache +++ b/tests/stringify/config/.phpstan-dba.cache @@ -4,7 +4,6 @@ array ( 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( - 'error' => NULL, 'result' => array ( 3 => diff --git a/tests/stringify/config/.phpunit-phpstan-dba.cache b/tests/stringify/config/.phpunit-phpstan-dba.cache index 4c39b5c8b..2c3c111b7 100644 --- a/tests/stringify/config/.phpunit-phpstan-dba.cache +++ b/tests/stringify/config/.phpunit-phpstan-dba.cache @@ -4,7 +4,6 @@ array ( 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( - 'error' => NULL, 'result' => array ( 3 =>