From 98bd4f5ab009fafbf99e3601f7eca536035fa636 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 26 Sep 2024 08:46:02 +0700 Subject: [PATCH] Fix bind param size --- src/Command.php | 2 +- tests/CommandTest.php | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Command.php b/src/Command.php index 3042409..820d197 100644 --- a/src/Command.php +++ b/src/Command.php @@ -54,7 +54,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra $returnParams[$phName]['dataType'] = PDO::PARAM_INT; } - $returnParams[$phName]['size'] = $columnSchemas[$name]?->getSize() ?? 4000; + $returnParams[$phName]['size'] = ($columnSchemas[$name]?->getSize() ?? 3998) + 2; $returning[] = $this->db->getQuoter()->quoteColumnName($name); } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 8bdc7b1..7062677 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -359,22 +359,45 @@ public function testInsertWithReturningPksWithPrimaryKeyString(): void $command = $db->createCommand(); $schema = $db->getSchema(); - if ($schema->getTableSchema('{{test_insert_ex_string}}') !== null) { - $command->dropTable('{{test_insert_ex_string}}')->execute(); + if ($schema->getTableSchema('{{test_insert_pk}}') !== null) { + $command->dropTable('{{test_insert_pk}}')->execute(); } $command->createTable( - '{{test_insert_ex_string}}', + '{{test_insert_pk}}', ['id' => 'varchar(10) primary key', 'name' => 'varchar(10)'], )->execute(); - $result = $command->insertWithReturningPks('{{test_insert_ex_string}}', ['id' => '1', 'name' => 'test']); + $result = $command->insertWithReturningPks('{{test_insert_pk}}', ['id' => '1', 'name' => 'test']); $this->assertSame(['id' => '1'], $result); $db->close(); } + public function testInsertWithReturningPksWithPrimaryKeySignedDecimal(): void + { + $db = $this->getConnection(); + + $command = $db->createCommand(); + $schema = $db->getSchema(); + + if ($schema->getTableSchema('{{test_insert_pk}}') !== null) { + $command->dropTable('{{test_insert_pk}}')->execute(); + } + + $command->createTable( + '{{test_insert_pk}}', + ['id' => 'number(5,2) primary key', 'name' => 'varchar(10)'], + )->execute(); + + $result = $command->insertWithReturningPks('{{test_insert_pk}}', ['id' => '-123.45', 'name' => 'test']); + + $this->assertSame(['id' => '-123.45'], $result); + + $db->close(); + } + /** * @throws Exception * @throws InvalidConfigException