Skip to content

Commit 199070f

Browse files
authored
Fix casting integer to string in AbstractCommand::getRawSql() (#788)
1 parent 261a9c1 commit 199070f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)
1515
- Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik)
1616
- Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik)
17+
- Bug #788: Fix casting integer to string in `AbstractCommand::getRawSql()` (@Tigrov)
1718

1819
## 1.2.0 November 12, 2023
1920

src/Command/AbstractCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function getRawSql(): string
351351
$value = $param->getValue();
352352

353353
$params[$name] = match ($param->getType()) {
354-
DataType::INTEGER => (string)$value,
354+
DataType::INTEGER => (string)(int)$value,
355355
DataType::STRING, DataType::LOB => match (true) {
356356
$value instanceof Expression => (string)$value,
357357
is_resource($value) => $name,

tests/Provider/CommandProvider.php

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Yiisoft\Db\Tests\Provider;
66

7+
use Yiisoft\Db\Command\DataType;
8+
use Yiisoft\Db\Command\Param;
79
use Yiisoft\Db\Expression\Expression;
810
use Yiisoft\Db\Query\Query;
911
use Yiisoft\Db\Schema\SchemaInterface;
@@ -553,6 +555,18 @@ public static function rawSql(): array
553555
static::$driverName,
554556
),
555557
],
558+
[
559+
<<<SQL
560+
SELECT * FROM [[customer]] WHERE [[id]] = :id
561+
SQL,
562+
['id' => new Param('1 OR 1=1', DataType::INTEGER)],
563+
DbHelper::replaceQuotes(
564+
<<<SQL
565+
SELECT * FROM [[customer]] WHERE [[id]] = 1
566+
SQL,
567+
static::$driverName,
568+
),
569+
],
556570
[
557571
<<<SQL
558572
SELECT * FROM [[customer]] WHERE [[id]] = :id

0 commit comments

Comments
 (0)