Skip to content

Commit

Permalink
Support simulation of date/dateime placeholders (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Staab <[email protected]>
  • Loading branch information
staabm and clxmstaab authored Feb 4, 2022
1 parent 3ae14e9 commit 9c50b0f
Show file tree
Hide file tree
Showing 8 changed files with 1,004 additions and 154 deletions.
23 changes: 16 additions & 7 deletions .phpstan-dba.cache

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/QueryReflection/MysqliQueryReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
5 changes: 4 additions & 1 deletion src/QueryReflection/QuerySimulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9c50b0f

Please sign in to comment.