diff --git a/.phpstan-dba-mysqli.cache b/.phpstan-dba-mysqli.cache index a839a3719..629043392 100644 --- a/.phpstan-dba-mysqli.cache +++ b/.phpstan-dba-mysqli.cache @@ -120,6 +120,175 @@ 5 => NULL, ), ), + 'SELECT + coalesce(COLUMN_NAME, "") as COLUMN_NAME, + coalesce(EXTRA, "") as EXTRA, + COLUMN_TYPE + FROM information_schema.columns + WHERE table_name = \'1970-01-01\' AND table_schema = DATABASE()' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'COLUMN_NAME', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 2 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'EXTRA', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 4 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'COLUMN_TYPE', + 'isClassString' => false, + )), + 5 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 2, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\StringType::__set_state(array( + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + 2 => + PHPStan\Type\StringType::__set_state(array( + )), + 3 => + PHPStan\Type\StringType::__set_state(array( + )), + 4 => + PHPStan\Type\StringType::__set_state(array( + )), + 5 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + 'nextAutoIndex' => 3, + '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\ConstantStringType::__set_state(array( + 'value' => 'COLUMN_NAME', + 'isClassString' => false, + )), + 4 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'COLUMN_TYPE', + 'isClassString' => false, + )), + 5 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'EXTRA', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\StringType::__set_state(array( + )), + )), + ), + ), + 'SELECT + coalesce(COLUMN_NAME, "") as COLUMN_NAME, + coalesce(EXTRA, "") as EXTRA, + COLUMN_TYPE + FROM information_schema.columns + WHERE table_name = ? AND table_schema = DATABASE()' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT 1' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerType::__set_state(array( + )), + ), + 'nextAutoIndex' => 2, + '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, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), 'SELECT a.email, b.adaid, b.gesperrt FROM ada a LEFT JOIN ada b ON a.adaid=b.adaid' => array ( 'result' => @@ -371,6 +540,140 @@ )), ), ), + 'SELECT email, adaid FROM ada WHERE adaid = \'1\'' => + 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, + )), + ), + '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, + )), + ), + 'nextAutoIndex' => 2, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 3 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'email', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\StringType::__set_state(array( + )), + ), + )), + )), + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = \'1\' and email = :email' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = \'1\' and email = ?' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = :adaid' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = :adaid and email = \'email@example.org\'' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = :adaid and email = :email' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid FROM ada WHERE adaid = ? and email = ?' => + array ( + 'result' => + array ( + 5 => NULL, + ), + ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => array ( 'result' => diff --git a/tests/default/config/.phpstan-dba-mysqli.cache b/tests/default/config/.phpstan-dba-mysqli.cache index 667af47aa..2830e9e02 100644 --- a/tests/default/config/.phpstan-dba-mysqli.cache +++ b/tests/default/config/.phpstan-dba-mysqli.cache @@ -1150,6 +1150,57 @@ )), ), ), + 'SELECT 1' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerType::__set_state(array( + )), + ), + 'nextAutoIndex' => 2, + '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, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), 'SELECT MAX(adaid), MIN(adaid), COUNT(adaid), AVG(adaid) FROM ada WHERE adaid = 1' => array ( 'result' => diff --git a/tests/default/config/.phpunit-phpstan-dba-mysqli.cache b/tests/default/config/.phpunit-phpstan-dba-mysqli.cache index d42a4baa1..8e283087e 100644 --- a/tests/default/config/.phpunit-phpstan-dba-mysqli.cache +++ b/tests/default/config/.phpunit-phpstan-dba-mysqli.cache @@ -1150,6 +1150,57 @@ )), ), ), + 'SELECT 1' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerType::__set_state(array( + )), + ), + 'nextAutoIndex' => 2, + '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, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), 'SELECT MAX(adaid), MIN(adaid), COUNT(adaid), AVG(adaid) FROM ada WHERE adaid = 1' => array ( 'result' => diff --git a/tests/rules/config/.phpstan-dba-mysqli.cache b/tests/rules/config/.phpstan-dba-mysqli.cache index bb0c62388..f694d5d1e 100644 --- a/tests/rules/config/.phpstan-dba-mysqli.cache +++ b/tests/rules/config/.phpstan-dba-mysqli.cache @@ -30,6 +30,57 @@ 5 => NULL, ), ), + 'SELECT 1' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 1, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerType::__set_state(array( + )), + ), + 'nextAutoIndex' => 2, + '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, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), 'SELECT adaid FROM ada WHERE email=\'1970-01-01\'' => array ( 'result' => diff --git a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache index 9d1987005..94d1c8d5f 100644 --- a/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache +++ b/tests/rules/config/.phpunit-phpstan-dba-mysqli.cache @@ -121,6 +121,125 @@ 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' => @@ -238,6 +357,11 @@ 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/rules/data/bug276.php b/tests/rules/data/bug276.php new file mode 100644 index 000000000..972a02ea2 --- /dev/null +++ b/tests/rules/data/bug276.php @@ -0,0 +1,18 @@ +prepare($test); // reusing variable + $test->execute(); + } + } +} diff --git a/tests/rules/data/pdo-stmt-execute-error.php b/tests/rules/data/pdo-stmt-execute-error.php index c4fe548a7..2356d099b 100644 --- a/tests/rules/data/pdo-stmt-execute-error.php +++ b/tests/rules/data/pdo-stmt-execute-error.php @@ -72,4 +72,14 @@ public function errorsBind(PDO $pdo) $stmt->bindValue(':email', 'email@example.org'); $stmt->execute(); // wrong number of parameters } + + public function bug276(PDO $pdo) + { + $queries = ['SELECT 1', 'SELECT 1']; + + foreach ($queries as $test) { + $test = $pdo->prepare($test); // reusing variable + $test->execute(); + } + } }