From 41039cd4879e48503cee2f58fab1309ea09039a3 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 3 Dec 2025 14:36:58 +0300 Subject: [PATCH 1/2] Use `StringColumn` for decimal type by default --- tests/ActiveQueryFindTest.php | 9 ++++----- tests/ActiveRecordTest.php | 2 +- tests/Driver/Oracle/ActiveRecordTest.php | 2 +- tests/Driver/Oracle/MagicActiveRecordTest.php | 2 +- tests/Driver/Pgsql/ActiveRecordTest.php | 2 +- tests/MagicActiveRecordTest.php | 2 +- tests/Stubs/ActiveRecord/Type.php | 2 +- tests/data/mssql.sql | 12 ++++++------ tests/data/mysql.sql | 10 +++++----- tests/data/oci.sql | 10 +++++----- tests/data/pgsql.sql | 10 +++++----- tests/data/sqlite.sql | 10 +++++----- 12 files changed, 36 insertions(+), 37 deletions(-) diff --git a/tests/ActiveQueryFindTest.php b/tests/ActiveQueryFindTest.php index 52d47fc8a..95e64c97a 100644 --- a/tests/ActiveQueryFindTest.php +++ b/tests/ActiveQueryFindTest.php @@ -652,31 +652,30 @@ public function testFindCompositeRelationAsArray(): void ->asArray() ->all(); - $isOracle = self::db()->getDriverName() === 'oci'; $this->assertSame( [ [ 'order_id' => 1, 'item_id' => 1, 'quantity' => 1, - 'subtotal' => $isOracle ? 30 : 30.0, + 'subtotal' => 30.0, 'orderItemCompositeNoJoin' => [ 'order_id' => 1, 'item_id' => 1, 'quantity' => 1, - 'subtotal' => $isOracle ? 30 : 30.0, + 'subtotal' => 30.0, ], ], [ 'order_id' => 1, 'item_id' => 2, 'quantity' => 2, - 'subtotal' => $isOracle ? 40 : 40.0, + 'subtotal' => 40.0, 'orderItemCompositeNoJoin' => [ 'order_id' => 1, 'item_id' => 2, 'quantity' => 2, - 'subtotal' => $isOracle ? 40 : 40.0, + 'subtotal' => 40.0, ], ], ], diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 49cfc3449..75e0a6b91 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -174,7 +174,7 @@ public function testDefaultValues(): void $this->assertSame(1, $arClass->int_col2); $this->assertSame('something', $arClass->char_col2); $this->assertSame(1.23, $arClass->float_col2); - $this->assertSame(33.22, $arClass->numeric_col); + $this->assertSame('33.22', $arClass->numeric_col); $this->assertTrue($arClass->bool_col2); $this->assertSame('2002-01-01 00:00:00', $arClass->time); diff --git a/tests/Driver/Oracle/ActiveRecordTest.php b/tests/Driver/Oracle/ActiveRecordTest.php index 0cabe52fd..71034c368 100644 --- a/tests/Driver/Oracle/ActiveRecordTest.php +++ b/tests/Driver/Oracle/ActiveRecordTest.php @@ -21,7 +21,7 @@ public function testDefaultValues(): void $this->assertSame(1, $arClass->int_col2); $this->assertSame('something', $arClass->char_col2); $this->assertSame(1.23, $arClass->float_col2); - $this->assertSame(33.22, $arClass->numeric_col); + $this->assertSame('33.22', $arClass->numeric_col); $this->assertTrue($arClass->bool_col2); // not testing $arClass->time, because oci\Schema can't read default value diff --git a/tests/Driver/Oracle/MagicActiveRecordTest.php b/tests/Driver/Oracle/MagicActiveRecordTest.php index 6944411e7..3a2258f69 100644 --- a/tests/Driver/Oracle/MagicActiveRecordTest.php +++ b/tests/Driver/Oracle/MagicActiveRecordTest.php @@ -18,7 +18,7 @@ public function testDefaultValues(): void $this->assertSame(1, $arClass->int_col2); $this->assertSame('something', $arClass->char_col2); $this->assertSame(1.23, $arClass->float_col2); - $this->assertSame(33.22, $arClass->numeric_col); + $this->assertSame('33.22', $arClass->numeric_col); $this->assertSame(true, $arClass->bool_col2); // not testing $arClass->time, because oci\Schema can't read default value diff --git a/tests/Driver/Pgsql/ActiveRecordTest.php b/tests/Driver/Pgsql/ActiveRecordTest.php index e4c73fb2d..af9915a70 100644 --- a/tests/Driver/Pgsql/ActiveRecordTest.php +++ b/tests/Driver/Pgsql/ActiveRecordTest.php @@ -35,7 +35,7 @@ public function testDefaultValues(): void $this->assertSame(1, $arClass->int_col2); $this->assertSame('something', $arClass->char_col2); $this->assertSame(1.23, $arClass->float_col2); - $this->assertSame(33.22, $arClass->numeric_col); + $this->assertSame('33.22', $arClass->numeric_col); $this->assertTrue($arClass->bool_col2); $this->assertSame('2002-01-01 00:00:00', $arClass->time); $this->assertSame(['a' => 1], $arClass->json_col); diff --git a/tests/MagicActiveRecordTest.php b/tests/MagicActiveRecordTest.php index c06407e53..ee48cc7bf 100644 --- a/tests/MagicActiveRecordTest.php +++ b/tests/MagicActiveRecordTest.php @@ -152,7 +152,7 @@ public function testDefaultValues(): void $this->assertEquals(1, $arClass->int_col2); $this->assertEquals('something', $arClass->char_col2); $this->assertEquals(1.23, $arClass->float_col2); - $this->assertEquals(33.22, $arClass->numeric_col); + $this->assertEquals('33.22', $arClass->numeric_col); $this->assertTrue($arClass->bool_col2); if ($this->db()->getDriverName() === 'mysql') { diff --git a/tests/Stubs/ActiveRecord/Type.php b/tests/Stubs/ActiveRecord/Type.php index d8653f0b4..3ae9c9c0b 100644 --- a/tests/Stubs/ActiveRecord/Type.php +++ b/tests/Stubs/ActiveRecord/Type.php @@ -23,7 +23,7 @@ class Type extends ActiveRecord public float $float_col; public ?float $float_col2 = 1.23; public mixed $blob_col; - public ?float $numeric_col = 33.22; + public ?string $numeric_col = '33.22'; public string|DateTimeInterface|Expression $time = '2002-01-01 00:00:00'; public bool|int|string $bool_col; public bool|int|string|null $bool_col2 = true; diff --git a/tests/data/mssql.sql b/tests/data/mssql.sql index 22bd3c07b..707c04e25 100644 --- a/tests/data/mssql.sql +++ b/tests/data/mssql.sql @@ -90,7 +90,7 @@ CREATE TABLE [dbo].[order] ( [created_at] [int] NOT NULL, [updated_at] [int] NOT NULL, [deleted_at] [int], - [total] [decimal](10,0) NOT NULL, + [total] [float] NOT NULL, CONSTRAINT [PK_order] PRIMARY KEY CLUSTERED ( [id] ASC ) ON [PRIMARY] @@ -100,7 +100,7 @@ CREATE TABLE [dbo].[order_with_null_fk] ( [id] [int] IDENTITY NOT NULL, [customer_id] [int] , [created_at] [int] NOT NULL, - [total] [decimal](10,0) NOT NULL, + [total] [float] NOT NULL, CONSTRAINT [PK_order_with_null_fk] PRIMARY KEY CLUSTERED ( [id] ASC ) ON [PRIMARY] @@ -110,7 +110,7 @@ CREATE TABLE [dbo].[order_item] ( [order_id] [int] NOT NULL, [item_id] [int] NOT NULL, [quantity] [int] NOT NULL, - [subtotal] [decimal](10,0) NOT NULL, + [subtotal] [float] NOT NULL, CONSTRAINT [PK_order_item] PRIMARY KEY CLUSTERED ( [order_id] ASC, [item_id] ASC @@ -121,7 +121,7 @@ CREATE TABLE "order_item_name" ( [order_id] [int] NOT NULL, [item_name] [varchar](128) NOT NULL, [quantity] [int] NOT NULL, - [subtotal] [decimal](10,0) NOT NULL, + [subtotal] [float] NOT NULL, PRIMARY KEY ([order_id], [item_name]) ); @@ -141,7 +141,7 @@ CREATE TABLE [dbo].[order_item_with_null_fk] ( [order_id] [int], [item_id] [int], [quantity] [int] NOT NULL, - [subtotal] [decimal](10,0) NOT NULL + [subtotal] [float] NOT NULL ); CREATE TABLE [dbo].[null_values] ( @@ -170,7 +170,7 @@ CREATE TABLE [dbo].[type] ( [char_col] [char](100) NOT NULL, [char_col2] [varchar](100) DEFAULT 'something', [char_col3] [text], - [float_col] [decimal](4,3) NOT NULL, + [float_col] [float] NOT NULL, [float_col2] [float] DEFAULT '1.23', [blob_col] [varbinary](MAX), [numeric_col] [decimal](5,2) DEFAULT '33.22', diff --git a/tests/data/mysql.sql b/tests/data/mysql.sql index 130d1ffa2..e1ece6abf 100644 --- a/tests/data/mysql.sql +++ b/tests/data/mysql.sql @@ -107,7 +107,7 @@ CREATE TABLE `order` ( `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL, `deleted_at` int(11), - `total` decimal(10,0) NOT NULL, + `total` float NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `FK_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -116,7 +116,7 @@ CREATE TABLE `order_with_null_fk` ( `id` int(11) NOT NULL AUTO_INCREMENT, `customer_id` int(11), `created_at` int(11) NOT NULL, - `total` decimal(10,0) NOT NULL, + `total` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -124,7 +124,7 @@ CREATE TABLE `order_item` ( `order_id` int(11) NOT NULL, `item_id` int(11) NOT NULL, `quantity` int(11) NOT NULL, - `subtotal` decimal(10,0) NOT NULL, + `subtotal` float NOT NULL, PRIMARY KEY (`order_id`,`item_id`), KEY `FK_order_item_item_id` (`item_id`), CONSTRAINT `FK_order_item_order_id` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE, @@ -135,7 +135,7 @@ CREATE TABLE `order_item_name` ( `order_id` int(11) NOT NULL, `item_name` varchar(128) NOT NULL, `quantity` int(11) NOT NULL, - `subtotal` decimal(10,0) NOT NULL, + `subtotal` float NOT NULL, PRIMARY KEY (`order_id`, `item_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -143,7 +143,7 @@ CREATE TABLE `order_item_with_null_fk` ( `order_id` int(11), `item_id` int(11), `quantity` int(11) NOT NULL, - `subtotal` decimal(10,0) NOT NULL + `subtotal` float NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `composite_fk` ( diff --git a/tests/data/oci.sql b/tests/data/oci.sql index f99ce79d6..cafb9fdc2 100644 --- a/tests/data/oci.sql +++ b/tests/data/oci.sql @@ -120,7 +120,7 @@ CREATE TABLE "order" ( "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "deleted_at" integer, - "total" decimal(10,0) NOT NULL, + "total" float NOT NULL, CONSTRAINT "order_PK" PRIMARY KEY ("id") ENABLE ); CREATE SEQUENCE "order_SEQ"; @@ -129,7 +129,7 @@ CREATE TABLE "order_with_null_fk" ( "id" integer not null, "customer_id" integer, "created_at" integer NOT NULL, - "total" decimal(10,0) NOT NULL, + "total" float NOT NULL, CONSTRAINT "order_with_null_fk_PK" PRIMARY KEY ("id") ENABLE ); CREATE SEQUENCE "order_with_null_fk_SEQ"; @@ -138,7 +138,7 @@ CREATE TABLE "order_item" ( "order_id" integer NOT NULL references "order"("id") on DELETE CASCADE, "item_id" integer NOT NULL references "item"("id") on DELETE CASCADE, "quantity" integer NOT NULL, - "subtotal" decimal(10,0) NOT NULL, + "subtotal" float NOT NULL, CONSTRAINT "order_item_PK" PRIMARY KEY ("order_id", "item_id") ENABLE ); @@ -146,7 +146,7 @@ CREATE TABLE "order_item_name" ( "order_id" integer NOT NULL, "item_name" varchar2(128) NOT NULL, "quantity" integer NOT NULL, - "subtotal" decimal(10,0) NOT NULL, + "subtotal" float NOT NULL, CONSTRAINT "order_item_name_PK" PRIMARY KEY ("order_id", "item_name") ENABLE ); @@ -154,7 +154,7 @@ CREATE TABLE "order_item_with_null_fk" ( "order_id" integer, "item_id" integer, "quantity" integer NOT NULL, - "subtotal" decimal(10,0) NOT NULL + "subtotal" float NOT NULL ); CREATE TABLE "composite_fk" ( diff --git a/tests/data/pgsql.sql b/tests/data/pgsql.sql index 35fb3d6ce..bbb18fcc0 100644 --- a/tests/data/pgsql.sql +++ b/tests/data/pgsql.sql @@ -123,21 +123,21 @@ CREATE TABLE "order" ( created_at integer NOT NULL, updated_at integer NOT NULL, deleted_at integer, - total decimal(10,0) NOT NULL + total float NOT NULL ); CREATE TABLE "order_with_null_fk" ( id serial not null primary key, customer_id integer, created_at integer NOT NULL, - total decimal(10,0) NOT NULL + total float NOT NULL ); CREATE TABLE "order_item" ( order_id integer NOT NULL references "order"(id) on UPDATE CASCADE on DELETE CASCADE, item_id integer NOT NULL references "item"(id) on UPDATE CASCADE on DELETE CASCADE, quantity integer NOT NULL, - subtotal decimal(10,0) NOT NULL, + subtotal float NOT NULL, PRIMARY KEY (order_id, item_id) ); @@ -145,7 +145,7 @@ CREATE TABLE "order_item_name" ( order_id integer NOT NULL, item_name varchar(128) NOT NULL, quantity integer NOT NULL, - subtotal decimal(10,0) NOT NULL, + subtotal float NOT NULL, PRIMARY KEY (order_id, item_name) ); @@ -153,7 +153,7 @@ CREATE TABLE "order_item_with_null_fk" ( order_id integer, item_id integer, quantity integer NOT NULL, - subtotal decimal(10,0) NOT NULL + subtotal float NOT NULL ); CREATE TABLE "composite_fk" ( diff --git a/tests/data/sqlite.sql b/tests/data/sqlite.sql index 631ebfdd9..a6f822ae7 100644 --- a/tests/data/sqlite.sql +++ b/tests/data/sqlite.sql @@ -80,7 +80,7 @@ CREATE TABLE "order" ( created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL, deleted_at INTEGER, - total decimal(10,0) NOT NULL, + total float NOT NULL, PRIMARY KEY (id) ); @@ -88,7 +88,7 @@ CREATE TABLE "order_with_null_fk" ( id INTEGER NOT NULL, customer_id INTEGER, created_at INTEGER NOT NULL, - total decimal(10,0) NOT NULL, + total float NOT NULL, PRIMARY KEY (id) ); @@ -96,7 +96,7 @@ CREATE TABLE "order_item" ( order_id INTEGER NOT NULL, item_id INTEGER NOT NULL, quantity INTEGER NOT NULL, - subtotal decimal(10,0) NOT NULL, + subtotal float NOT NULL, PRIMARY KEY (order_id, item_id) ); @@ -104,7 +104,7 @@ CREATE TABLE "order_item_name" ( order_id INTEGER NOT NULL, item_name VARCHAR(128) NOT NULL, quantity INTEGER NOT NULL, - subtotal decimal(10,0) NOT NULL, + subtotal float NOT NULL, PRIMARY KEY (order_id, item_name) ); @@ -112,7 +112,7 @@ CREATE TABLE "order_item_with_null_fk" ( order_id INTEGER, item_id INTEGER, quantity INTEGER NOT NULL, - subtotal decimal(10,0) NOT NULL + subtotal float NOT NULL ); CREATE TABLE "composite_fk" ( From f941ce010c9cb1484a770855fcaf480793c1d905 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 3 Dec 2025 14:54:50 +0300 Subject: [PATCH 2/2] fix --- tests/Stubs/ActiveRecord/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Stubs/ActiveRecord/Customer.php b/tests/Stubs/ActiveRecord/Customer.php index a89785553..8a12a078a 100644 --- a/tests/Stubs/ActiveRecord/Customer.php +++ b/tests/Stubs/ActiveRecord/Customer.php @@ -21,7 +21,7 @@ class Customer extends ArrayableActiveRecord public const STATUS_INACTIVE = 2; public int|string $status2; - public int|string|null $sumTotal; + public float|string|null $sumTotal; protected int $id; protected string $email;