Skip to content

Commit 98bd4f5

Browse files
committed
Fix bind param size
1 parent 7c2cd4f commit 98bd4f5

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/Command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
5454
$returnParams[$phName]['dataType'] = PDO::PARAM_INT;
5555
}
5656

57-
$returnParams[$phName]['size'] = $columnSchemas[$name]?->getSize() ?? 4000;
57+
$returnParams[$phName]['size'] = ($columnSchemas[$name]?->getSize() ?? 3998) + 2;
5858

5959
$returning[] = $this->db->getQuoter()->quoteColumnName($name);
6060
}

tests/CommandTest.php

+27-4
Original file line numberDiff line numberDiff line change
@@ -359,22 +359,45 @@ public function testInsertWithReturningPksWithPrimaryKeyString(): void
359359
$command = $db->createCommand();
360360
$schema = $db->getSchema();
361361

362-
if ($schema->getTableSchema('{{test_insert_ex_string}}') !== null) {
363-
$command->dropTable('{{test_insert_ex_string}}')->execute();
362+
if ($schema->getTableSchema('{{test_insert_pk}}') !== null) {
363+
$command->dropTable('{{test_insert_pk}}')->execute();
364364
}
365365

366366
$command->createTable(
367-
'{{test_insert_ex_string}}',
367+
'{{test_insert_pk}}',
368368
['id' => 'varchar(10) primary key', 'name' => 'varchar(10)'],
369369
)->execute();
370370

371-
$result = $command->insertWithReturningPks('{{test_insert_ex_string}}', ['id' => '1', 'name' => 'test']);
371+
$result = $command->insertWithReturningPks('{{test_insert_pk}}', ['id' => '1', 'name' => 'test']);
372372

373373
$this->assertSame(['id' => '1'], $result);
374374

375375
$db->close();
376376
}
377377

378+
public function testInsertWithReturningPksWithPrimaryKeySignedDecimal(): void
379+
{
380+
$db = $this->getConnection();
381+
382+
$command = $db->createCommand();
383+
$schema = $db->getSchema();
384+
385+
if ($schema->getTableSchema('{{test_insert_pk}}') !== null) {
386+
$command->dropTable('{{test_insert_pk}}')->execute();
387+
}
388+
389+
$command->createTable(
390+
'{{test_insert_pk}}',
391+
['id' => 'number(5,2) primary key', 'name' => 'varchar(10)'],
392+
)->execute();
393+
394+
$result = $command->insertWithReturningPks('{{test_insert_pk}}', ['id' => '-123.45', 'name' => 'test']);
395+
396+
$this->assertSame(['id' => '-123.45'], $result);
397+
398+
$db->close();
399+
}
400+
378401
/**
379402
* @throws Exception
380403
* @throws InvalidConfigException

0 commit comments

Comments
 (0)