|
4 | 4 |
|
5 | 5 | use Doctrine\DBAL\Cache\QueryCacheProfile;
|
6 | 6 | use Doctrine\DBAL\Connection;
|
| 7 | +use Doctrine\DBAL\Types\Types; |
7 | 8 | use function PHPStan\Testing\assertType;
|
8 | 9 | use staabm\PHPStanDba\Tests\Fixture\StringableObject;
|
9 | 10 |
|
@@ -218,4 +219,49 @@ public function dateParameter(Connection $conn)
|
218 | 219 | $fetchResult = $conn->fetchOne($query, [date('Y-m-d', strtotime('-3hour'))]);
|
219 | 220 | assertType('int|false', $fetchResult);
|
220 | 221 | }
|
| 222 | + |
| 223 | + public function customTypeParameters(Connection $conn, int $adaid) |
| 224 | + { |
| 225 | + $stmt = $conn->prepare('SELECT count(*) AS c FROM typemix WHERE c_datetime=:last_dt'); |
| 226 | + $result = $stmt->execute(['dt' => new \DateTime()], ['dt' => Types::DATETIME_MUTABLE]); |
| 227 | + assertType('Doctrine\DBAL\Statement<array{c: int, 0: int}>', $result); |
| 228 | + |
| 229 | + $stmt = $conn->prepare('SELECT count(*) AS c FROM typemix WHERE c_datetime=:last_dt'); |
| 230 | + $result = $stmt->execute(['dt' => new \DateTime()], ['dt' => Types::DATETIME_IMMUTABLE]); |
| 231 | + // TODO should probably fail as DateTime is passed to a DATETIME_IMMUTABLE type |
| 232 | + assertType('Doctrine\DBAL\Statement<array{c: int, 0: int}>', $result); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * @param array<int> $ids |
| 237 | + * @param array<string> $vals |
| 238 | + */ |
| 239 | + public function boundArrays(Connection $conn, array $ids, array $vals) |
| 240 | + { |
| 241 | + $result = $conn->executeQuery( |
| 242 | + 'SELECT count(*) AS c FROM ada WHERE adaid IN (?)', |
| 243 | + [$ids], |
| 244 | + [\Doctrine\DBAL\Connection::PARAM_INT_ARRAY] |
| 245 | + ); |
| 246 | + assertType('Doctrine\DBAL\Statement<array{c: int, 0: int}>', $result); |
| 247 | + |
| 248 | + $result = $conn->executeQuery( |
| 249 | + 'SELECT count(*) AS c FROM ada WHERE email IN (?)', |
| 250 | + [$vals], |
| 251 | + [\Doctrine\DBAL\Connection::PARAM_STR_ARRAY] |
| 252 | + ); |
| 253 | + assertType('Doctrine\DBAL\Statement<array{c: int, 0: int}>', $result); |
| 254 | + |
| 255 | + $result = $conn->executeQuery( |
| 256 | + 'SELECT count(*) AS c FROM ada WHERE adaid IN (?)', |
| 257 | + [$vals], // TODO should error as $vals is not int array |
| 258 | + [\Doctrine\DBAL\Connection::PARAM_INT_ARRAY] |
| 259 | + ); |
| 260 | + |
| 261 | + $result = $conn->executeQuery( |
| 262 | + 'SELECT count(*) AS c FROM ada WHERE email IN (?)', |
| 263 | + [$ids], // TODO should error as $ids is not str array |
| 264 | + [\Doctrine\DBAL\Connection::PARAM_STR_ARRAY] |
| 265 | + ); |
| 266 | + } |
221 | 267 | }
|
0 commit comments