diff --git a/.phpstan-dba.cache b/.phpstan-dba.cache index 1e16de072..de2767c82 100644 --- a/.phpstan-dba.cache +++ b/.phpstan-dba.cache @@ -2,9 +2,24 @@ 'schemaVersion' => 'v5-runtime-config-bugfix', 'records' => array ( - 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => + 'SELECT count(*) FROM typemix WHERE c_date = \'1\'' => array ( 'error' => NULL, + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT count(*) FROM typemix WHERE c_datetime = \'1\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada' => + array ( 'result' => array ( 5 => @@ -153,7 +168,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = \'1\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -307,14 +321,9 @@ '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 ( - 'error' => NULL, 'result' => array ( 5 => diff --git a/src/QueryReflection/MysqliQueryReflector.php b/src/QueryReflection/MysqliQueryReflector.php index 2f13a807c..cdd7a8f82 100644 --- a/src/QueryReflection/MysqliQueryReflector.php +++ b/src/QueryReflection/MysqliQueryReflector.php @@ -31,6 +31,8 @@ final class MysqliQueryReflector implements QueryReflector public const MYSQL_HOST_NOT_FOUND = 2002; + public const DATE_FORMAT = 'Y-m-d'; + private const MAX_CACHE_SIZE = 50; /** diff --git a/src/QueryReflection/QuerySimulation.php b/src/QueryReflection/QuerySimulation.php index de58437a3..72f0fc314 100644 --- a/src/QueryReflection/QuerySimulation.php +++ b/src/QueryReflection/QuerySimulation.php @@ -75,7 +75,10 @@ public static function simulateParamValueType(Type $paramType, bool $preparedPar if ($stringType->isSuperTypeOf($paramType)->yes() || $paramType instanceof ObjectType && $paramType->isInstanceOf(Stringable::class)->yes()) { // in a prepared context, regular strings are fine if (true === $preparedParam) { - return '1'; + // returns a string in date-format, so in case the simulated value is used against a date/datetime column + // we won't run into a sql error. + // XX in case we would have a proper sql parser, we could feed schema-type-dependent default values in case of strings. + return date(MysqliQueryReflector::DATE_FORMAT); } // plain string types can contain anything.. we cannot reason about it diff --git a/tests/default/config/.phpstan-dba.cache b/tests/default/config/.phpstan-dba.cache index c74ac4a90..b142ac377 100644 --- a/tests/default/config/.phpstan-dba.cache +++ b/tests/default/config/.phpstan-dba.cache @@ -9,10 +9,6 @@ 'message' => 'Unknown column \'doesNotExist\' in \'group statement\'', 'code' => 1054, )), - 'result' => - array ( - 3 => NULL, - ), ), 'SELECT * FROM ada ORDER BY doesNotExist' => array ( @@ -21,10 +17,6 @@ 'message' => 'Unknown column \'doesNotExist\' in \'order clause\'', 'code' => 1054, )), - 'result' => - array ( - 3 => NULL, - ), ), 'SELECT * FROM ada WHERE doesNotExist=1' => array ( @@ -33,14 +25,9 @@ 'message' => 'Unknown column \'doesNotExist\' in \'where clause\'', 'code' => 1054, )), - 'result' => - array ( - 3 => NULL, - ), ), 'SELECT * FROM typemix' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -674,14 +661,9 @@ '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 => @@ -806,7 +788,6 @@ ), '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 => @@ -911,7 +892,6 @@ ), 'SELECT adaid FROM ada LIMIT 1 FOR SHARE' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -952,7 +932,6 @@ ), 'SELECT adaid FROM ada LIMIT 1 OFFSET 1' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -993,7 +972,6 @@ ), 'SELECT adaid FROM ada LIMIT 1 OFFSET 1 FOR UPDATE' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -1034,7 +1012,6 @@ ), 'SELECT adaid FROM ada WHERE adaid IN (\'1\')' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1152,7 +1129,7 @@ )), ), ), - 'SELECT adaid FROM ada WHERE adaid IN (\'1.0\')' => + 'SELECT adaid FROM ada WHERE adaid IN (\'1\') AND email LIKE \'2022-02-04\'' => array ( 'error' => NULL, 'result' => @@ -1212,6 +1189,65 @@ )), ), ), + 'SELECT adaid FROM ada WHERE adaid IN (\'1.0\')' => + array ( + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + )), + ), + ), 'SELECT adaid FROM ada WHERE adaid IN (:adaids)' => array ( 'error' => @@ -1219,10 +1255,6 @@ '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 ( @@ -1231,10 +1263,6 @@ '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 ( @@ -1243,12 +1271,68 @@ '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, )), + ), + 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'1\'' => + array ( + 'error' => NULL, 'result' => array ( - 5 => NULL, + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + )), ), ), - 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'1\'' => + 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'2022-02-04\'' => array ( 'error' => NULL, 'result' => @@ -1310,7 +1394,6 @@ ), 'SELECT adaid FROM ada WHERE email LIKE ":gesperrt%"' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1404,7 +1487,6 @@ ), 'SELECT adaid FROM ada WHERE email LIKE "hello?%"' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1498,7 +1580,6 @@ ), 'SELECT adaid FROM ada WHERE email LIKE \'%questions ?%\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1592,7 +1673,6 @@ ), 'SELECT adaid FROM ada WHERE email LIKE \':gesperrt%\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -1744,6 +1824,66 @@ )), ), ), + 'SELECT adaid FROM ada WHERE email=\'2022-02-04\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + )), + ), + ), 'SELECT adaid FROM ada WHERE email=:email' => array ( 'error' => @@ -1751,14 +1891,49 @@ '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, )), + ), + 'SELECT akid FROM ak WHERE eadavk>1.0' => + array ( 'result' => array ( - 5 => NULL, + 3 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'akid', + 'isClassString' => false, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -2147483648, + 'max' => 2147483647, + )), + ), + 'nextAutoIndex' => 0, + 'optionalKeys' => + array ( + ), + 'keyType' => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'akid', + 'isClassString' => false, + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -2147483648, + 'max' => 2147483647, + )), + )), ), ), - 'SELECT akid FROM ak WHERE eadavk>1.0' => + 'SELECT akid FROM ak WHERE eadavk>1.1' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -1790,50 +1965,117 @@ 'isClassString' => false, )), 'itemType' => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -2147483648, - 'max' => 2147483647, + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => -2147483648, + 'max' => 2147483647, + )), + )), + ), + ), + 'SELECT count(*) FROM typemix WHERE c_date = \'2022-02-04\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + 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' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( )), )), ), ), - 'SELECT akid FROM ak WHERE eadavk>1.1' => + 'SELECT count(*) FROM typemix WHERE c_datetime = \'2022-02-04\'' => array ( 'error' => NULL, 'result' => array ( - 3 => + 5 => PHPStan\Type\Constant\ConstantArrayType::__set_state(array( 'allArrays' => NULL, 'keyTypes' => array ( 0 => PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'akid', + 'value' => 'count(*)', 'isClassString' => false, )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), ), 'valueTypes' => array ( 0 => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -2147483648, - 'max' => 2147483647, + PHPStan\Type\IntegerType::__set_state(array( + )), + 1 => + PHPStan\Type\IntegerType::__set_state(array( )), ), - 'nextAutoIndex' => 0, + 'nextAutoIndex' => 1, 'optionalKeys' => array ( ), 'keyType' => - PHPStan\Type\Constant\ConstantStringType::__set_state(array( - 'value' => 'akid', - 'isClassString' => false, + PHPStan\Type\UnionType::__set_state(array( + 'types' => + array ( + 0 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + 1 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + ), )), 'itemType' => - PHPStan\Type\IntegerRangeType::__set_state(array( - 'min' => -2147483648, - 'max' => 2147483647, + PHPStan\Type\IntegerType::__set_state(array( )), )), ), @@ -1845,14 +2087,9 @@ 'message' => 'Unknown column \'doesNotExist\' in \'field list\'', 'code' => 1054, )), - 'result' => - array ( - 3 => NULL, - ), ), 'SELECT eladaid FROM ak' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -1916,14 +2153,9 @@ '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 => @@ -1982,16 +2214,9 @@ '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 FROM ada' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2209,14 +2434,9 @@ '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 => @@ -2309,7 +2529,6 @@ ), 'SELECT email, adaid FROM ada WHERE adaid = \'1\' and email = \'email@example.org\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2407,10 +2626,6 @@ '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 ( @@ -2419,10 +2634,6 @@ '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 ( @@ -2431,10 +2642,6 @@ '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 ( @@ -2443,10 +2650,6 @@ '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 ( @@ -2455,10 +2658,6 @@ '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 ( @@ -2467,10 +2666,6 @@ '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 ( @@ -2479,14 +2674,9 @@ '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 => @@ -2641,7 +2831,6 @@ ), 'SELECT email, adaid FROM ada WHERE email <=> \'\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2739,14 +2928,9 @@ '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 => @@ -2839,7 +3023,6 @@ ), 'SELECT email, adaid FROM ada WHERE email = \'test@example.org\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -2937,10 +3120,6 @@ '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 ( @@ -2949,10 +3128,6 @@ '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 ( @@ -2961,14 +3136,9 @@ '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 => @@ -3293,7 +3463,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -3392,7 +3561,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -3491,7 +3659,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada LIMIT 1, 10' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -3590,7 +3757,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = \'1\'' => array ( - 'error' => NULL, 'result' => array ( 5 => @@ -3739,7 +3905,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = 1' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -3843,14 +4008,9 @@ '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 => @@ -3954,12 +4114,157 @@ '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, )), + ), + 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'1\'' => + array ( + 'error' => NULL, 'result' => array ( - 5 => NULL, + 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( + )), + ), + )), + )), ), ), - 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'1\'' => + 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'2022-02-04\'' => array ( 'error' => NULL, 'result' => @@ -4110,7 +4415,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'test@example.org\'' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -4209,7 +4513,6 @@ ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email=\'foo\'' => array ( - 'error' => NULL, 'result' => array ( 3 => @@ -4308,7 +4611,6 @@ ), '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 50c826ccb..0c75fa584 100644 --- a/tests/default/config/.phpunit-phpstan-dba.cache +++ b/tests/default/config/.phpunit-phpstan-dba.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' => @@ -1196,6 +1315,65 @@ ), ), 'SELECT adaid FROM ada WHERE adaid IN (\'1\') AND email LIKE \'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' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + )), + ), + ), + 'SELECT adaid FROM ada WHERE adaid IN (\'1\') AND email LIKE \'2022-02-04\'' => array ( 'error' => NULL, 'result' => @@ -1352,6 +1530,65 @@ ), ), 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'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' => 'adaid', + 'isClassString' => false, + )), + 1 => + PHPStan\Type\Constant\ConstantIntegerType::__set_state(array( + 'value' => 0, + )), + ), + 'valueTypes' => + array ( + 0 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + 1 => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + ), + 'nextAutoIndex' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'adaid', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerRangeType::__set_state(array( + 'min' => 0, + 'max' => 4294967295, + )), + )), + ), + ), + 'SELECT adaid FROM ada WHERE adaid IN (NULL) AND email LIKE \'2022-02-04\'' => array ( 'error' => NULL, 'result' => @@ -1419,6 +1656,14 @@ array ( 'error' => NULL, ), + 'SELECT adaid FROM ada WHERE email = \'2022-02-04\'' => + array ( + 'error' => NULL, + ), + 'SELECT adaid FROM ada WHERE email = \'2022-02-04\' AND gesperrt = \'1\'' => + array ( + 'error' => NULL, + ), 'SELECT adaid FROM ada WHERE email LIKE ":gesperrt%"' => array ( 'error' => NULL, @@ -1881,6 +2126,130 @@ )), ), ), + 'SELECT count(*) FROM typemix WHERE c_date = \'1\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT count(*) FROM typemix WHERE c_date = \'2022-02-04\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + 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' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), + 'SELECT count(*) FROM typemix WHERE c_datetime = \'1\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => NULL, + ), + ), + 'SELECT count(*) FROM typemix WHERE c_datetime = \'2022-02-04\'' => + array ( + 'error' => NULL, + 'result' => + array ( + 5 => + PHPStan\Type\Constant\ConstantArrayType::__set_state(array( + 'allArrays' => NULL, + 'keyTypes' => + array ( + 0 => + PHPStan\Type\Constant\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + 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' => 1, + '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\ConstantStringType::__set_state(array( + 'value' => 'count(*)', + 'isClassString' => false, + )), + ), + )), + 'itemType' => + PHPStan\Type\IntegerType::__set_state(array( + )), + )), + ), + ), 'SELECT doesNotExist, adaid, gesperrt, freigabe1u1 FROM ada' => array ( 'error' => @@ -3135,6 +3504,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, @@ -3713,6 +4087,154 @@ )), ), 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'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, + )), + 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( + )), + ), + )), + )), + ), + ), + 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE email = \'2022-02-04\'' => array ( 'error' => NULL, 'result' => diff --git a/tests/default/data/doctrine-dbal.php b/tests/default/data/doctrine-dbal.php index f9e1909a2..793be6a6d 100644 --- a/tests/default/data/doctrine-dbal.php +++ b/tests/default/data/doctrine-dbal.php @@ -157,4 +157,18 @@ public function fetchStringable(Connection $conn) $fetchResult = $conn->fetchAllKeyValue($query, [new StringableObject()]); assertType('array>', $fetchResult); } + + public function datetimeParameter(Connection $conn) + { + $query = 'SELECT count(*) FROM typemix WHERE c_datetime = ?'; + $fetchResult = $conn->fetchOne($query, [date('Y-m-d H:i:s', strtotime('-3hour'))]); + assertType('int|false', $fetchResult); + } + + public function dateParameter(Connection $conn) + { + $query = 'SELECT count(*) FROM typemix WHERE c_date = ?'; + $fetchResult = $conn->fetchOne($query, [date('Y-m-d', strtotime('-3hour'))]); + assertType('int|false', $fetchResult); + } } 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 =>