Skip to content

Commit

Permalink
Fix bind param size
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Sep 26, 2024
1 parent 7c2cd4f commit 98bd4f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 27 additions & 4 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98bd4f5

Please sign in to comment.