Skip to content

Adapt to db changes #422

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Adapt to db changes #422

wants to merge 4 commits into from

Conversation

rustamwin
Copy link
Member

Q A
Is bugfix? ✔️/❌
New feature? ✔️/❌
Breaks BC? ✔️/❌
Fixed issues yiisoft/db#94

Copy link

codecov bot commented Aug 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.69%. Comparing base (320fe4e) to head (facd1e1).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #422   +/-   ##
=========================================
  Coverage     98.69%   98.69%           
- Complexity      253      254    +1     
=========================================
  Files            24       24           
  Lines           764      766    +2     
=========================================
+ Hits            754      756    +2     
  Misses           10       10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Tigrov Tigrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL does not support FROM clause in UPDATE query. It should generate UPDATE table1, table2, ... query instead

Comment on lines +128 to +460
'val' => 1.2,
'val1' => 2,
'val_0' => 'Banana',
'val2' => 'Cherry',
],
],
'Expressions with the different params' => [
'{{product}}',
['name' => new Expression('LOWER(:val)', ['val' => 'Apple'])],
'[[name]] != :name',
null,
['name' => new Expression('UPPER(:val1)', ['val1' => 'Banana'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(:val) WHERE [[name]] != UPPER(:val1)
SQL
),
[
'val' => 'Apple',
'val1' => 'Banana',
],
],
'Expressions with nested Expressions' => [
'{{table}}',
[
'name' => new Expression(
':val || :val_0',
[
'val' => new Expression('LOWER(:val || :val_0)', ['val' => 'A', 'val_0' => 'B']),
'val_0' => new Param('C', DataType::STRING),
],
),
],
'[[name]] != :val || :val_0',
null,
[
'val_0' => new Param('F', DataType::STRING),
'val' => new Expression('UPPER(:val || :val_0)', ['val' => 'D', 'val_0' => 'E']),
],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=LOWER(:val_2 || :val_0_1) || :val_0_0 WHERE [[name]] != UPPER(:val_1 || :val_0_2) || :val_0
SQL
),
[
'val_2' => 'A',
'val_0_1' => 'B',
'val_0_0' => new Param('C', DataType::STRING),
'val_1' => 'D',
'val_0_2' => 'E',
'val_0' => new Param('F', DataType::STRING),
],
],
'Expressions with indexed params' => [
'{{product}}',
['name' => new Expression('LOWER(?)', ['Apple'])],
'[[name]] != ?',
null,
['Banana'],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(?) WHERE [[name]] != ?
SQL
),
// Wrong order of params
['Banana', 'Apple'],
],
'Expressions with a string value containing a placeholder name' => [
'{{product}}',
['price' => 10],
':val',
null,
[':val' => new Expression("label=':val' AND name=:val", [':val' => 'Apple'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=:qp1 WHERE label=':val' AND name=:val_0
SQL
),
[
':qp1' => 10,
':val_0' => 'Apple',
],
],
'Expressions without placeholders in SQL statement' => [
'{{product}}',
['price' => 10],
':val',
null,
[':val' => new Expression("label=':val'", [':val' => 'Apple'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=:qp1 WHERE label=':val'
SQL
),
[
':qp1' => 10,
':val_0' => 'Apple',
],
],
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return [
[
'{{table}}',
['name' => '{{test}}'],
[],
null,
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{test}}',
],
],
[
'{{table}}',
['name' => '{{test}}'],
['id' => 1],
null,
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0 WHERE [[id]] = 1
SQL
),
[
':qp0' => '{{test}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}.{{name}}'],
[],
'tmp',
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{tmp}}.{{name}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}.{{name}}'],
[],
['tmp'],
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{tmp}}.{{name}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}.{{name}}'],
['id' => 1],
'tmp',
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0 WHERE [[id]] = 1
SQL
),
[
':qp0' => '{{tmp}}.{{name}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}.{{name}}'],
[],
new Expression('SELECT [[name]] FROM [[tmp]] WHERE [[id]] = 1'),
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{tmp}}.{{name}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}.{{name}}'],
[],
[self::getDb()->select('name')->from('tmp')->where(['id' => 1])],
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{tmp}}.{{name}}',
],
],
[
'{{table}}',
['name' => '{{tmp}}'],
[],
['tmp' => self::getDb()->select('name')->from('tmp')->where(['id' => 1])],
[],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp0
SQL
),
[
':qp0' => '{{tmp}}',
],
],
[
'{{table}}',
['{{table}}.name' => '{{test}}'],
['id' => 1],
null,
['id' => 'boolean'],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=:qp1 WHERE [[id]] = 1
SQL
),
[
'id' => 'boolean',
':qp1' => '{{test}}',
],
],
[
'customer',
['status' => 1, 'updated_at' => new Expression('now()')],
['id' => 100],
null,
[],
self::replaceQuotes(
<<<SQL
UPDATE [[customer]] SET [[status]]=:qp0, [[updated_at]]=now() WHERE [[id]] = 100
SQL
),
[':qp0' => 1],
],
'Expressions without params' => [
'{{product}}',
['name' => new Expression('UPPER([[name]])')],
'[[name]] = :name',
null,
['name' => new Expression('LOWER([[name]])')],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=UPPER([[name]]) WHERE [[name]] = LOWER([[name]])
SQL
),
[],
],
'Expression with params and without params' => [
'{{product}}',
['price' => new Expression('[[price]] + :val', [':val' => 1])],
'[[start_at]] < :date',
null,
['date' => new Expression('NOW()')],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=[[price]] + :val WHERE [[start_at]] < NOW()
SQL
),
[':val' => 1],
],
'Expression without params and with params' => [
'{{product}}',
['name' => new Expression('UPPER([[name]])')],
'[[name]] = :name',
null,
['name' => new Expression('LOWER(:val)', [':val' => 'Apple'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=UPPER([[name]]) WHERE [[name]] = LOWER(:val)
SQL
),
[':val' => 'Apple'],
],
'Expressions with the same params' => [
'{{product}}',
['name' => new Expression('LOWER(:val)', ['val' => 'Apple'])],
'[[name]] != :name',
null,
['name' => new Expression('UPPER(:val)', ['val' => 'Banana'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(:val) WHERE [[name]] != UPPER(:val_0)
SQL
),
[
'val' => 'Apple',
'val_0' => 'Banana',
],
],
'Expressions with the same params starting with and without colon' => [
'{{product}}',
['name' => new Expression('LOWER(:val)', [':val' => 'Apple'])],
'[[name]] != :name',
null,
['name' => new Expression('UPPER(:val)', ['val' => 'Banana'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(:val) WHERE [[name]] != UPPER(:val_0)
SQL
),
[
':val' => 'Apple',
'val_0' => 'Banana',
],
],
'Expressions with the same and different params' => [
'{{product}}',
['price' => new Expression('[[price]] * :val + :val1', ['val' => 1.2, 'val1' => 2])],
'[[name]] IN :values',
null,
['values' => new Expression('(:val, :val2)', ['val' => 'Banana', 'val2' => 'Cherry'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=[[price]] * :val + :val1 WHERE [[name]] IN (:val_0, :val2)
SQL
),
[
'val' => 1.2,
'val1' => 2,
'val_0' => 'Banana',
'val2' => 'Cherry',
],
],
'Expressions with the different params' => [
'{{product}}',
['name' => new Expression('LOWER(:val)', ['val' => 'Apple'])],
'[[name]] != :name',
null,
['name' => new Expression('UPPER(:val1)', ['val1' => 'Banana'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(:val) WHERE [[name]] != UPPER(:val1)
SQL
),
[
'val' => 'Apple',
'val1' => 'Banana',
],
],
'Expressions with nested Expressions' => [
'{{table}}',
[
'name' => new Expression(
':val || :val_0',
[
'val' => new Expression('LOWER(:val || :val_0)', ['val' => 'A', 'val_0' => 'B']),
'val_0' => new Param('C', DataType::STRING),
],
),
],
'[[name]] != :val || :val_0',
null,
[
'val_0' => new Param('F', DataType::STRING),
'val' => new Expression('UPPER(:val || :val_0)', ['val' => 'D', 'val_0' => 'E']),
],
self::replaceQuotes(
<<<SQL
UPDATE [[table]] SET [[name]]=LOWER(:val_2 || :val_0_1) || :val_0_0 WHERE [[name]] != UPPER(:val_1 || :val_0_2) || :val_0
SQL
),
[
'val_2' => 'A',
'val_0_1' => 'B',
'val_0_0' => new Param('C', DataType::STRING),
'val_1' => 'D',
'val_0_2' => 'E',
'val_0' => new Param('F', DataType::STRING),
],
],
'Expressions with indexed params' => [
'{{product}}',
['name' => new Expression('LOWER(?)', ['Apple'])],
'[[name]] != ?',
null,
['Banana'],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[name]]=LOWER(?) WHERE [[name]] != ?
SQL
),
// Wrong order of params
['Banana', 'Apple'],
],
'Expressions with a string value containing a placeholder name' => [
'{{product}}',
['price' => 10],
':val',
null,
[':val' => new Expression("label=':val' AND name=:val", [':val' => 'Apple'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=:qp1 WHERE label=':val' AND name=:val_0
SQL
),
[
':qp1' => 10,
':val_0' => 'Apple',
],
],
'Expressions without placeholders in SQL statement' => [
'{{product}}',
['price' => 10],
':val',
null,
[':val' => new Expression("label=':val'", [':val' => 'Apple'])],
self::replaceQuotes(
<<<SQL
UPDATE [[product]] SET [[price]]=:qp1 WHERE label=':val'
SQL
),
[
':qp1' => 10,
':val_0' => 'Apple',
],
],
];
$data = parent::update();
// Change $data values...
return $data;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants