Skip to content

Commit 29dee57

Browse files
committed
Fix tri-combination in + and /
1 parent b3ae6a6 commit 29dee57

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

src/Type/Doctrine/Query/QueryResultTypeWalker.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,11 +1707,11 @@ private function inferPlusMinusTimesType(array $termTypes): Type
17071707
if ($this->containsOnlyTypes($unionWithoutNull, [new FloatType(), new StringType()])) {
17081708
return $this->createFloat($nullable);
17091709
}
1710-
}
17111710

1712-
// TODO all 3?
1713-
// TODO string
1714-
// TODO string with number in it?
1711+
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType(), $this->createNumericString(false)])) {
1712+
return $this->createFloat($nullable);
1713+
}
1714+
}
17151715

17161716
// postgre fails and other drivers are unknown
17171717
return new MixedType();
@@ -1795,6 +1795,10 @@ private function inferDivisionType(array $termTypes): Type
17951795
return $this->createFloat($nullable);
17961796
}
17971797

1798+
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new FloatType(), $this->createNumericString(false)])) {
1799+
return $this->createFloat($nullable);
1800+
}
1801+
17981802
if ($this->containsOnlyTypes($unionWithoutNull, [new IntegerType(), new StringType()])) {
17991803
return $this->createFloat(true);
18001804
}

tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,24 @@ public static function provideCases(): iterable
594594
},
595595
];
596596

597+
yield 't.col_int + t.col_float + t.col_decimal' => [
598+
'data' => self::dataDefault(),
599+
'select' => 'SELECT t.col_int + t.col_float + t.col_decimal FROM %s t',
600+
'mysql' => self::float(),
601+
'sqlite' => self::float(),
602+
'pdo_pgsql' => self::numericString(),
603+
'pgsql' => self::float(),
604+
'mssql' => new MixedType(),
605+
'mysqlResult' => 9.225,
606+
'sqliteResult' => 9.225,
607+
'pdoPgsqlResult' => '9.225',
608+
'pgsqlResult' => 9.225,
609+
'mssqlResult' => 9.225,
610+
'shouldStringify' => static function (string $driver, int $php, string $configName): bool {
611+
return self::defaultStringification($driver, $php, $configName);
612+
},
613+
];
614+
597615
yield 't.col_decimal + t.col_decimal' => [
598616
'data' => self::dataDefault(),
599617
'select' => 'SELECT t.col_decimal + t.col_decimal FROM %s t',
@@ -630,6 +648,24 @@ public static function provideCases(): iterable
630648
},
631649
];
632650

651+
yield 't.col_int + t.col_string (int data)' => [
652+
'data' => self::dataAllIntLike(),
653+
'select' => 'SELECT t.col_int + t.col_string FROM %s t',
654+
'mysql' => self::float(),
655+
'sqlite' => self::int(),
656+
'pdo_pgsql' => null, // Undefined function
657+
'pgsql' => null, // Undefined function
658+
'mssql' => self::mixed(),
659+
'mysqlResult' => 2.0,
660+
'sqliteResult' => 2,
661+
'pdoPgsqlResult' => null,
662+
'pgsqlResult' => null,
663+
'mssqlResult' => 2,
664+
'shouldStringify' => static function (string $driver, int $php, string $configName): bool {
665+
return self::defaultStringification($driver, $php, $configName);
666+
},
667+
];
668+
633669
yield 't.col_int + t.col_bool' => [
634670
'data' => self::dataDefault(),
635671
'select' => 'SELECT t.col_int + t.col_bool FROM %s t',
@@ -774,6 +810,24 @@ public static function provideCases(): iterable
774810
},
775811
];
776812

813+
yield 't.col_int / t.col_float / t.col_decimal' => [
814+
'data' => self::dataDefault(),
815+
'select' => 'SELECT t.col_int / t.col_float / t.col_decimal FROM %s t',
816+
'mysql' => self::float(),
817+
'sqlite' => self::float(),
818+
'pdo_pgsql' => self::numericString(),
819+
'pgsql' => self::float(),
820+
'mssql' => new MixedType(),
821+
'mysqlResult' => 720.0,
822+
'sqliteResult' => 720.0,
823+
'pdoPgsqlResult' => '720',
824+
'pgsqlResult' => 720.0,
825+
'mssqlResult' => 720.0,
826+
'shouldStringify' => static function (string $driver, int $php, string $configName): bool {
827+
return self::defaultStringification($driver, $php, $configName);
828+
},
829+
];
830+
777831
yield 't.col_bigint / t.col_float' => [
778832
'data' => self::dataDefault(),
779833
'select' => 'SELECT t.col_bigint / t.col_float FROM %s t',
@@ -900,6 +954,24 @@ public static function provideCases(): iterable
900954
},
901955
];
902956

957+
yield 't.col_int / t.col_string (int data)' => [
958+
'data' => self::dataAllIntLike(),
959+
'select' => 'SELECT t.col_int / t.col_string FROM %s t',
960+
'mysql' => self::floatOrNull(),
961+
'sqlite' => self::intOrNull(),
962+
'pdo_pgsql' => null, // Undefined function
963+
'pgsql' => null, // Undefined function
964+
'mssql' => self::mixed(),
965+
'mysqlResult' => 1.0,
966+
'sqliteResult' => 1,
967+
'pdoPgsqlResult' => null,
968+
'pgsqlResult' => null,
969+
'mssqlResult' => 1,
970+
'shouldStringify' => static function (string $driver, int $php, string $configName): bool {
971+
return self::defaultStringification($driver, $php, $configName);
972+
},
973+
];
974+
903975
yield 't.col_string / t.col_int' => [
904976
'data' => self::dataDefault(),
905977
'select' => 'SELECT t.col_string / t.col_int FROM %s t',
@@ -3491,10 +3563,6 @@ public static function provideCases(): iterable
34913563
return false;
34923564
},
34933565
];
3494-
3495-
// TODO would col_numeric_string differ from col_string results ?
3496-
// TODO dbal/orm versions
3497-
// TODO run sqlsrv with custom setup (numeric, leading zero, native datetimes), check if implementable with current API
34983566
}
34993567

35003568
/**

0 commit comments

Comments
 (0)