Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix casting integer to string in AbstractCommand::getRawSql() #788

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading