-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
RawSql not working in UpdateBatch #6554
Comments
Your Steps to Reproduce does not use It seems v4.2.6 does not support
That's all. |
Sorry about that. I edited the issue to include it. |
I have tested this in 4.3 without issue: public function testUpdateBatchRawSql()
{
$sql = $this->db->table('table')->testMode()->updateBatch([
'id' => 1,
'int_column' => new RawSql('(CASE WHEN int_column > 1 THEN int_column - 1 ELSE 0 END)'),
], 'id');
$expectedSql = <<<'SQL'
UPDATE `db_table`
SET
`int_column` = _u.`int_column`
FROM (
SELECT 1 `id`, (CASE WHEN int_column > 1 THEN int_column - 1 ELSE 0 END) `int_column`
) _u
WHERE `db_table`.`id` = _u.`id`
SQL;
$this->assertStringContainsString($expectedSql, $sql[0]);
} |
PHP Version
8.0
CodeIgniter4 Version
4.2.6
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MySQL 5.6
What happened?
I'm trying to implement a decrement with UpdateBatch, and previously used the escape, but was recommended to use the RawSql class instead. However, when I checked the query, it seems to be escaped, and when I digged deeper, I didn't see RawSql being implemented in the UpdateBatch method.
Steps to Reproduce
Expected Output
Anything else?
One way to solve this, is to update this line (in Database/BaseBuilder.php)
$clean[$this->db->protectIdentifiers($k2, false)] = $escape ? $this->db->escape($v2) : $v2;
to
$clean[$this->db->protectIdentifiers($k2, false)] = $escape && !($v2 instanceof RawSql) ? $this->db->escape($v2) : (string) $v2;
The text was updated successfully, but these errors were encountered: