From 3541c7963664f11835be8ae31be0b9ece1a80195 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 24 Aug 2025 16:50:52 +0300 Subject: [PATCH] Adapt tests to yiisoft/db#1044 --- tests/Provider/QueryBuilderProvider.php | 61 ++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 58366b128..422e3c293 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -137,14 +137,12 @@ public static function insertReturningPks(): array ], [], << 'test@example.com', - ':qp1' => 'silverfire', - ':qp2' => 'Kyiv {{city}}, Ukraine', - ':qp3' => false, - ':qp4' => null, + ':qp0' => new Param('test@example.com', DataType::STRING), + ':qp1' => new Param('silverfire', DataType::STRING), + ':qp2' => new Param('Kyiv {{city}}, Ukraine', DataType::STRING), ], ], 'params-and-expressions' => [ @@ -152,9 +150,9 @@ public static function insertReturningPks(): array ['{{%type}}.[[related_id]]' => null, '[[time]]' => new Expression('now()')], [], << null], + [], ], 'carry passed params' => [ 'customer', @@ -168,15 +166,13 @@ public static function insertReturningPks(): array ], [':phBar' => 'bar'], << 'bar', - ':qp1' => 'test@example.com', - ':qp2' => 'sergeymakinen', - ':qp3' => '{{city}}', - ':qp4' => false, - ':qp5' => null, + ':qp1' => new Param('test@example.com', DataType::STRING), + ':qp2' => new Param('sergeymakinen', DataType::STRING), + ':qp3' => new Param('{{city}}', DataType::STRING), ':phFoo' => 'foo', ], ], @@ -212,9 +208,9 @@ public static function insertReturningPks(): array ['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 1.0], [], << 1, ':qp1' => 1, ':qp2' => 1, ':qp3' => 1.0,], + [], ], ]; } @@ -224,23 +220,23 @@ public static function upsert(): array $concreteData = [ 'regular values' => [ 3 => 'INSERT INTO "T_upsert" ("email", "address", "status", "profile_id") ' . - 'VALUES (:qp0, :qp1, :qp2, :qp3) ON CONFLICT ("email") ' . + 'VALUES (:qp0, :qp1, 1, NULL) ON CONFLICT ("email") ' . 'DO UPDATE SET "address"=EXCLUDED."address", "status"=EXCLUDED."status", "profile_id"=EXCLUDED."profile_id"', ], 'regular values with unique at not the first position' => [ 3 => 'INSERT INTO "T_upsert" ("address", "email", "status", "profile_id") ' . - 'VALUES (:qp0, :qp1, :qp2, :qp3) ON CONFLICT ("email") ' . + 'VALUES (:qp0, :qp1, 1, NULL) ON CONFLICT ("email") ' . 'DO UPDATE SET "address"=EXCLUDED."address", "status"=EXCLUDED."status", "profile_id"=EXCLUDED."profile_id"', ], 'regular values with update part' => [ 2 => ['address' => 'foo {{city}}', 'status' => 2, 'orders' => new Expression('"T_upsert"."orders" + 1')], 3 => 'INSERT INTO "T_upsert" ("email", "address", "status", "profile_id") ' . - 'VALUES (:qp0, :qp1, :qp2, :qp3) ON CONFLICT ("email") ' . - 'DO UPDATE SET "address"=:qp4, "status"=2, "orders"="T_upsert"."orders" + 1', + 'VALUES (:qp0, :qp1, 1, NULL) ON CONFLICT ("email") ' . + 'DO UPDATE SET "address"=:qp2, "status"=2, "orders"="T_upsert"."orders" + 1', ], 'regular values without update part' => [ 3 => 'INSERT INTO "T_upsert" ("email", "address", "status", "profile_id") ' . - 'VALUES (:qp0, :qp1, :qp2, :qp3) ON CONFLICT DO NOTHING', + 'VALUES (:qp0, :qp1, 1, NULL) ON CONFLICT DO NOTHING', ], 'query' => [ 3 => 'INSERT INTO "T_upsert" ("email", "status") SELECT "email", 2 AS "status" FROM "customer" ' . @@ -293,7 +289,7 @@ public static function upsert(): array 3 => 'INSERT INTO "T_upsert" ("email", [[ts]]) SELECT :phEmail AS "email", extract(epoch from now()) * 1000 AS [[ts]] ON CONFLICT DO NOTHING', ], 'no columns to update' => [ - 3 => 'INSERT INTO "T_upsert_1" ("a") VALUES (:qp0) ON CONFLICT DO NOTHING', + 3 => 'INSERT INTO "T_upsert_1" ("a") VALUES (1) ON CONFLICT DO NOTHING', ], 'no columns to update with unique' => [ 3 => 'INSERT INTO "T_upsert" ("email") VALUES (:qp0) ON CONFLICT DO NOTHING', @@ -313,8 +309,8 @@ public static function upsert(): array 'animal_view', ['id' => 3, 'type' => 'yiiunit\data\ar\Mouse'], true, - 'INSERT INTO "animal_view" ("id", "type") VALUES (:qp0, :qp1) ON CONFLICT ("id") DO UPDATE SET "type"=EXCLUDED."type"', - [':qp0' => 3, ':qp1' => 'yiiunit\data\ar\Mouse'], + 'INSERT INTO "animal_view" ("id", "type") VALUES (3, :qp0) ON CONFLICT ("id") DO UPDATE SET "type"=EXCLUDED."type"', + [':qp0' => new Param('yiiunit\data\ar\Mouse', DataType::STRING)], ]; return $upsert; @@ -342,7 +338,7 @@ public static function upsertReturning(): array } $upsert['no columns to update'][3] = ['a']; - $upsert['no columns to update'][4] = 'INSERT INTO "T_upsert_1" ("a") VALUES (:qp0) ON CONFLICT ("a")' + $upsert['no columns to update'][4] = 'INSERT INTO "T_upsert_1" ("a") VALUES (1) ON CONFLICT ("a")' . ' DO UPDATE SET "a" = "T_upsert_1"."a" RETURNING "a"'; return [ @@ -352,28 +348,31 @@ public static function upsertReturning(): array ['id_1' => 1, 'id_2' => 2.5, 'type' => 'Test'], true, ['id_1', 'id_2'], - 'INSERT INTO "notauto_pk" ("id_1", "id_2", "type") VALUES (:qp0, :qp1, :qp2)' + 'INSERT INTO "notauto_pk" ("id_1", "id_2", "type") VALUES (1, 2.5, :qp0)' . ' ON CONFLICT ("id_1", "id_2") DO UPDATE SET "type"=EXCLUDED."type" RETURNING "id_1", "id_2"', - [':qp0' => 1, ':qp1' => 2.5, ':qp2' => 'Test'], + [':qp0' => new Param('Test', DataType::STRING)], ], 'no return columns' => [ 'type', ['int_col' => 3, 'char_col' => 'a', 'float_col' => 1.2, 'bool_col' => true], true, [], - 'INSERT INTO "type" ("int_col", "char_col", "float_col", "bool_col") VALUES (:qp0, :qp1, :qp2, :qp3)', - [':qp0' => 3, ':qp1' => 'a', ':qp2' => 1.2, ':qp3' => true], + 'INSERT INTO "type" ("int_col", "char_col", "float_col", "bool_col") VALUES (3, :qp0, 1.2, TRUE)', + [':qp0' => new Param('a', DataType::STRING)], ], 'return all columns' => [ 'T_upsert', ['email' => 'test@example.com', 'address' => 'test address', 'status' => 1, 'profile_id' => 1], true, null, - 'INSERT INTO "T_upsert" ("email", "address", "status", "profile_id") VALUES (:qp0, :qp1, :qp2, :qp3)' + 'INSERT INTO "T_upsert" ("email", "address", "status", "profile_id") VALUES (:qp0, :qp1, 1, 1)' . ' ON CONFLICT ("email") DO UPDATE SET' . ' "address"=EXCLUDED."address", "status"=EXCLUDED."status", "profile_id"=EXCLUDED."profile_id"' . ' RETURNING "id", "ts", "email", "recovery_email", "address", "status", "orders", "profile_id"', - [':qp0' => 'test@example.com', ':qp1' => 'test address', ':qp2' => 1, ':qp3' => 1], + [ + ':qp0' => new Param('test@example.com', DataType::STRING), + ':qp1' => new Param('test address', DataType::STRING), + ], ], ]; }