staabm / phpstan-dba

PHPStan based SQL static analysis and type inference for the database access layer
https://staabm.github.io/archive.html#phpstan-dba
MIT License
249 stars 17 forks source link

Issue with update to 0.2.80: Query expects 0 placeholder, but 1 value is given #657

Closed mitelg closed 1 month ago

mitelg commented 1 month ago

Hey there,

With the newest version, the check for placeholder does not work on certain queries in our project: https://github.com/shopware5/shopware/pull/2697

one example query looks like this:

$sql = <<<'EOD'
UPDATE `s_cms_support` SET `email_template` = "{sShopname} Anfrage-Formular

Anrede: {sVars.anrede}
Vorname: {sVars.vorname}
Nachname: {sVars.nachname}
eMail: {sVars.email}
Telefon: {sVars.telefon}
Artikel: {sVars.sordernumber}

Frage:
{sVars.inquiry}", `email_subject`="{sShopname} Anfrage-Formular" WHERE `id`= ? AND md5(`email_template`) = "02c8993563bf42f52a95504e6e8549f5";
EOD;

$statement = $conn->prepare($sql);
$statement->execute([$id]);

From this file: https://github.com/shopware5/shopware/blob/5.7/_sql/migrations/962-add-ordernumber-form-field.php#L73-L88

Maybe you can find the issue. If you need more information, just let me know :+1: Thank you very much, also for your amazing work on PHPStan core :muscle:

Best regards from the Münsterland

staabm commented 1 month ago

Thank you very much, also for your amazing work on PHPStan core 💪

thanks for the kind words - sponsoring would be welcome :-).

Maybe you can find the issue. If you need more information, just let me know

sounds like this regressed with https://github.com/staabm/phpstan-dba/pull/651

//cc @b-viguier could you have a look?

b-viguier commented 1 month ago

Hi 👋 🙂 You're right, this is because of #651 The issue seems to come from strings containing new lines \n, regex seems to be reset for each new line, not sure why 😕 @mitelg I will try to find a fix, but in the meantime here is a workaround: instead of writing this

... `email_template` = "...
...
...", `email_subject`="..." WHERE ...

try this

... `email_template` = "...
...
...",
`email_subject`="..." WHERE ...

at least to confirm that I'm chasing the same bug that you spotted.

mitelg commented 1 month ago

hey @b-viguier

thanks for looking into this :+1:

I can confirm, that reformating the code to your suggestion is indeed fixing the issue :grin: :+1: