Skip to content

Commit

Permalink
Fix casting integer to string in AbstractCommand::getRawSql() (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Dec 4, 2023
1 parent 261a9c1 commit 199070f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Enh #786: Refactor `AbstractSchema::getDataType()` (@Tigrov)
- Enh #784: Specify result type of `ConstraintSchemaInterface::getTableIndexes()` method to `IndexConstraint[]` (@vjik)
- Enh #784: Remove unused code in `AbstractSchema::getTableIndexes()` (@vjik)
- Bug #788: Fix casting integer to string in `AbstractCommand::getRawSql()` (@Tigrov)

## 1.2.0 November 12, 2023

Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public function getRawSql(): string
$value = $param->getValue();

$params[$name] = match ($param->getType()) {
DataType::INTEGER => (string)$value,
DataType::INTEGER => (string)(int)$value,
DataType::STRING, DataType::LOB => match (true) {
$value instanceof Expression => (string)$value,
is_resource($value) => $name,
Expand Down
14 changes: 14 additions & 0 deletions tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Db\Tests\Provider;

use Yiisoft\Db\Command\DataType;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\SchemaInterface;
Expand Down Expand Up @@ -553,6 +555,18 @@ public static function rawSql(): array
static::$driverName,
),
],
[
<<<SQL
SELECT * FROM [[customer]] WHERE [[id]] = :id
SQL,
['id' => new Param('1 OR 1=1', DataType::INTEGER)],
DbHelper::replaceQuotes(
<<<SQL
SELECT * FROM [[customer]] WHERE [[id]] = 1
SQL,
static::$driverName,
),
],
[
<<<SQL
SELECT * FROM [[customer]] WHERE [[id]] = :id
Expand Down

0 comments on commit 199070f

Please sign in to comment.