@@ -1416,8 +1416,8 @@ public static function provideCases(): iterable
14161416 yield 'COALESCE(t.col_bool, t.col_bool) ' => [
14171417 'data ' => self ::dataDefault (),
14181418 'select ' => 'SELECT COALESCE(t.col_bool, t.col_bool) FROM %s t ' ,
1419- 'mysql ' => self ::boolAsInt (),
1420- 'sqlite ' => self ::boolAsInt (),
1419+ 'mysql ' => self ::int (),
1420+ 'sqlite ' => self ::int (),
14211421 'pdo_pgsql ' => self ::bool (),
14221422 'pgsql ' => self ::bool (),
14231423 'mssql ' => self ::mixed (),
@@ -2232,10 +2232,10 @@ public static function provideCases(): iterable
22322232 yield "MAX('foobar') " => [
22332233 'data ' => self ::dataDefault (),
22342234 'select ' => "SELECT MAX('foobar') FROM %s t " ,
2235- 'mysql ' => TypeCombinator::addNull (new ConstantStringType ( ' foobar ' )),
2236- 'sqlite ' => TypeCombinator::addNull (new ConstantStringType ( ' foobar ' )),
2237- 'pdo_pgsql ' => TypeCombinator::addNull (new ConstantStringType ( ' foobar ' )),
2238- 'pgsql ' => TypeCombinator::addNull (new ConstantStringType ( ' foobar ' )),
2235+ 'mysql ' => TypeCombinator::addNull (self :: string ( )),
2236+ 'sqlite ' => TypeCombinator::addNull (self :: string ( )),
2237+ 'pdo_pgsql ' => TypeCombinator::addNull (self :: string ( )),
2238+ 'pgsql ' => TypeCombinator::addNull (self :: string ( )),
22392239 'mssql ' => self ::mixed (),
22402240 'mysqlResult ' => 'foobar ' ,
22412241 'sqliteResult ' => 'foobar ' ,
@@ -3348,6 +3348,168 @@ public static function provideCases(): iterable
33483348 'mssqlResult ' => '2024年01月31日 12:59:59.000000 ' , // doctrine/dbal changes default ReturnDatesAsStrings to true
33493349 'stringify ' => self ::STRINGIFY_NONE ,
33503350 ];
3351+ 3352+ yield 'COALESCE(SUM(t.col_int_nullable), 0) ' => [
3353+ 'data ' => self ::dataDefault (),
3354+ 'select ' => 'SELECT COALESCE(SUM(t.col_int_nullable), 0) FROM %s t ' ,
3355+ 'mysql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3356+ 'sqlite ' => self ::int (),
3357+ 'pdo_pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3358+ 'pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3359+ 'mssql ' => self ::mixed (),
3360+ 'mysqlResult ' => '0 ' ,
3361+ 'sqliteResult ' => 0 ,
3362+ 'pdoPgsqlResult ' => 0 ,
3363+ 'pgsqlResult ' => 0 ,
3364+ 'mssqlResult ' => 0 ,
3365+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3366+ ];
3367+ 3368+ yield "COALESCE(t.col_int_nullable, 'foo') " => [
3369+ 'data ' => self ::dataDefault (),
3370+ 'select ' => "SELECT COALESCE(t.col_int_nullable, 'foo') FROM %s t " ,
3371+ 'mysql ' => TypeCombinator::union (self ::int (), self ::string ()),
3372+ 'sqlite ' => TypeCombinator::union (self ::int (), self ::string ()),
3373+ 'pdo_pgsql ' => null , // COALESCE types cannot be matched
3374+ 'pgsql ' => null , // COALESCE types cannot be matched
3375+ 'mssql ' => null , // Conversion failed
3376+ 'mysqlResult ' => 'foo ' ,
3377+ 'sqliteResult ' => 'foo ' ,
3378+ 'pdoPgsqlResult ' => null ,
3379+ 'pgsqlResult ' => null ,
3380+ 'mssqlResult ' => null ,
3381+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3382+ ];
3383+ 3384+ yield "COALESCE(t.col_int, 'foo') " => [
3385+ 'data ' => self ::dataDefault (),
3386+ 'select ' => "SELECT COALESCE(t.col_int, 'foo') FROM %s t " ,
3387+ 'mysql ' => TypeCombinator::union (self ::int (), self ::string ()),
3388+ 'sqlite ' => TypeCombinator::union (self ::int (), self ::string ()),
3389+ 'pdo_pgsql ' => null , // COALESCE types cannot be matched
3390+ 'pgsql ' => null , // COALESCE types cannot be matched
3391+ 'mssql ' => self ::mixed (),
3392+ 'mysqlResult ' => '9 ' ,
3393+ 'sqliteResult ' => 9 ,
3394+ 'pdoPgsqlResult ' => null ,
3395+ 'pgsqlResult ' => null ,
3396+ 'mssqlResult ' => 9 ,
3397+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3398+ ];
3399+ 3400+ yield "COALESCE(t.col_bool, 'foo') " => [
3401+ 'data ' => self ::dataDefault (),
3402+ 'select ' => "SELECT COALESCE(t.col_bool, 'foo') FROM %s t " ,
3403+ 'mysql ' => TypeCombinator::union (self ::int (), self ::string ()),
3404+ 'sqlite ' => TypeCombinator::union (self ::int (), self ::string ()),
3405+ 'pdo_pgsql ' => null , // COALESCE types cannot be matched
3406+ 'pgsql ' => null , // COALESCE types cannot be matched
3407+ 'mssql ' => self ::mixed (),
3408+ 'mysqlResult ' => '1 ' ,
3409+ 'sqliteResult ' => 1 ,
3410+ 'pdoPgsqlResult ' => null ,
3411+ 'pgsqlResult ' => null ,
3412+ 'mssqlResult ' => 1 ,
3413+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3414+ ];
3415+ 3416+ yield "COALESCE(1, 'foo') " => [
3417+ 'data ' => self ::dataDefault (),
3418+ 'select ' => "SELECT COALESCE(1, 'foo') FROM %s t " ,
3419+ 'mysql ' => TypeCombinator::union (self ::int (), self ::string ()),
3420+ 'sqlite ' => TypeCombinator::union (self ::int (), self ::string ()),
3421+ 'pdo_pgsql ' => null , // COALESCE types cannot be matched
3422+ 'pgsql ' => null , // COALESCE types cannot be matched
3423+ 'mssql ' => self ::mixed (),
3424+ 'mysqlResult ' => '1 ' ,
3425+ 'sqliteResult ' => 1 ,
3426+ 'pdoPgsqlResult ' => null ,
3427+ 'pgsqlResult ' => null ,
3428+ 'mssqlResult ' => 1 ,
3429+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3430+ ];
3431+ 3432+ yield 'COALESCE(t.col_int_nullable, 0) ' => [
3433+ 'data ' => self ::dataDefault (),
3434+ 'select ' => 'SELECT COALESCE(t.col_int_nullable, 0) FROM %s t ' ,
3435+ 'mysql ' => self ::int (),
3436+ 'sqlite ' => self ::int (),
3437+ 'pdo_pgsql ' => self ::int (),
3438+ 'pgsql ' => self ::int (),
3439+ 'mssql ' => self ::mixed (),
3440+ 'mysqlResult ' => 0 ,
3441+ 'sqliteResult ' => 0 ,
3442+ 'pdoPgsqlResult ' => 0 ,
3443+ 'pgsqlResult ' => 0 ,
3444+ 'mssqlResult ' => 0 ,
3445+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3446+ ];
3447+ 3448+ yield 'COALESCE(t.col_float_nullable, 0) ' => [
3449+ 'data ' => self ::dataDefault (),
3450+ 'select ' => 'SELECT COALESCE(t.col_float_nullable, 0) FROM %s t ' ,
3451+ 'mysql ' => TypeCombinator::union (self ::float (), self ::int ()),
3452+ 'sqlite ' => TypeCombinator::union (self ::float (), self ::int ()),
3453+ 'pdo_pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3454+ 'pgsql ' => TypeCombinator::union (self ::float (), self ::int ()),
3455+ 'mssql ' => self ::mixed (),
3456+ 'mysqlResult ' => 0.0 ,
3457+ 'sqliteResult ' => 0 ,
3458+ 'pdoPgsqlResult ' => '0 ' ,
3459+ 'pgsqlResult ' => 0.0 ,
3460+ 'mssqlResult ' => 0.0 ,
3461+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3462+ ];
3463+ 3464+ yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, 0) ' => [
3465+ 'data ' => self ::dataDefault (),
3466+ 'select ' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, 0) FROM %s t ' ,
3467+ 'mysql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3468+ 'sqlite ' => TypeCombinator::union (self ::float (), self ::int ()),
3469+ 'pdo_pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3470+ 'pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3471+ 'mssql ' => self ::mixed (),
3472+ 'mysqlResult ' => '0.0 ' ,
3473+ 'sqliteResult ' => 0 ,
3474+ 'pdoPgsqlResult ' => '0 ' ,
3475+ 'pgsqlResult ' => '0 ' ,
3476+ 'mssqlResult ' => '.0 ' ,
3477+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3478+ ];
3479+ 3480+ yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0) ' => [
3481+ 'data ' => self ::dataDefault (),
3482+ 'select ' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, 0) FROM %s t ' ,
3483+ 'mysql ' => TypeCombinator::union (self ::numericString (), self ::int (), self ::float ()),
3484+ 'sqlite ' => TypeCombinator::union (self ::float (), self ::int ()),
3485+ 'pdo_pgsql ' => TypeCombinator::union (self ::numericString (), self ::int ()),
3486+ 'pgsql ' => TypeCombinator::union (self ::numericString (), self ::int (), self ::float ()),
3487+ 'mssql ' => self ::mixed (),
3488+ 'mysqlResult ' => 0.0 ,
3489+ 'sqliteResult ' => 0 ,
3490+ 'pdoPgsqlResult ' => '0 ' ,
3491+ 'pgsqlResult ' => 0.0 ,
3492+ 'mssqlResult ' => 0.0 ,
3493+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3494+ ];
3495+ 3496+ yield 'COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, t.col_string) ' => [
3497+ 'data ' => self ::dataDefault (),
3498+ 'select ' => 'SELECT COALESCE(t.col_int_nullable, t.col_decimal_nullable, t.col_float_nullable, t.col_string) FROM %s t ' ,
3499+ 'mysql ' => TypeCombinator::union (self ::string (), self ::int (), self ::float ()),
3500+ 'sqlite ' => TypeCombinator::union (self ::float (), self ::int (), self ::string ()),
3501+ 'pdo_pgsql ' => null , // COALESCE types cannot be matched
3502+ 'pgsql ' => null , // COALESCE types cannot be matched
3503+ 'mssql ' => null , // Error converting data
3504+ 'mysqlResult ' => 'foobar ' ,
3505+ 'sqliteResult ' => 'foobar ' ,
3506+ 'pdoPgsqlResult ' => null ,
3507+ 'pgsqlResult ' => null ,
3508+ 'mssqlResult ' => null ,
3509+ 'stringify ' => self ::STRINGIFY_DEFAULT ,
3510+ ];
3511+ 3512+ // TODO test IDENTITY
33513513 }
33523514
33533515 /**
@@ -3700,14 +3862,6 @@ private static function boolOrNull(): Type
37003862 return TypeCombinator::addNull (new BooleanType ());
37013863 }
37023864
3703- private static function boolAsInt (): Type
3704- {
3705- return TypeCombinator::union (
3706- new ConstantIntegerType (0 ),
3707- new ConstantIntegerType (1 )
3708- );
3709- }
3710- 37113865 private static function numericString (): Type
37123866 {
37133867 return new IntersectionType ([
0 commit comments