Skip to content

Commit c68e2c8

Browse files
authored
Fix float type in AbstractCommand::getRawSql() (#828)
1 parent e28a16c commit c68e2c8

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Enh #806: Non-unique placeholder names inside `Expression::$params` will be replaced with unique names (@Tigrov)
99
- Enh #806: Build `Expression` instances inside `Expression::$params` when build a query using `QueryBuilder` (@Tigrov)
1010
- Enh #766: Allow `ColumnInterface` as column type. (@Tigrov)
11+
- Bug #828: Fix `float` type when use `AbstractCommand::getRawSql()` method (@Tigrov)
1112

1213
## 1.3.0 March 21, 2024
1314

src/Command/AbstractCommand.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
use Yiisoft\Db\Query\QueryInterface;
1313
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
1414
use Yiisoft\Db\Schema\Builder\ColumnInterface;
15+
use Yiisoft\Db\Schema\SchemaInterface;
1516

1617
use function explode;
1718
use function get_resource_type;
19+
use function gettype;
1820
use function is_array;
1921
use function is_int;
2022
use function is_resource;
@@ -351,11 +353,13 @@ public function getRawSql(): string
351353
$value = $param->getValue();
352354

353355
$params[$name] = match ($param->getType()) {
354-
DataType::INTEGER => (string)(int)$value,
355-
DataType::STRING, DataType::LOB => match (true) {
356-
$value instanceof Expression => (string)$value,
357-
is_resource($value) => $name,
358-
default => $quoter->quoteValue((string)$value),
356+
DataType::INTEGER => (string) (int) $value,
357+
DataType::STRING, DataType::LOB => match (gettype($value)) {
358+
SchemaInterface::PHP_TYPE_RESOURCE => $name,
359+
SchemaInterface::PHP_TYPE_DOUBLE => (string) $value,
360+
default => $value instanceof Expression
361+
? (string) $value
362+
: $quoter->quoteValue((string) $value),
359363
},
360364
DataType::BOOLEAN => $value ? 'TRUE' : 'FALSE',
361365
DataType::NULL => 'NULL',

tests/Provider/CommandProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,18 @@ public static function rawSql(): array
741741
static::$driverName,
742742
),
743743
],
744+
[
745+
<<<SQL
746+
SELECT * FROM [[product]] WHERE [[price]] = :price
747+
SQL,
748+
['price' => 123.45],
749+
DbHelper::replaceQuotes(
750+
<<<SQL
751+
SELECT * FROM [[product]] WHERE [[price]] = 123.45
752+
SQL,
753+
static::$driverName,
754+
),
755+
],
744756
];
745757
}
746758

0 commit comments

Comments
 (0)