catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

wrong where-statement output when comparing the value of columns #1014

Closed Fluit closed 3 years ago

Fluit commented 3 years ago

Information

Describe the Problem According to the documentation Columns Relationship I use ["fld1[=]fld2"] as a condition for comparing the values of the 2 columns. Instead of WHERE fld1 = fld2 i get WHERE fld1 = "fld1[=]fld2"

Detail Code $this->Db->select('tbl1', ["[><]tbl2" => ['id' => 'tbl1_id']], ['fld1', 'fld2', ....], ["fld1[=]fld2"]) results in sql-string SELECT * tbl1 INNER JOIN tbl2 ON tbl1.id = tbl2.tb1_id WHERE fld1 = "fld1[=]fld2" FYI: fld1 & fld2 are unique fieldnames in tbl2! Even changing the where-array in ['tbl2.fld1[=]tbl2.fld2"] makes no difference.

It looks like the second part of the condition is not quoted correctly.

Expected output is should be ... SELECT * tbl1 INNER JOIN tbl2 ON tbl1.id = tbl2.tb1_id WHERE tbl2.fld1 = tbl2.fld2"

Fluit commented 3 years ago

A workaround is using Medoo;;raw statement: ['fld1' => \Medoo\Medoo::raw('<tbl2.fld2>')]

catfan commented 3 years ago

That's a bug. Fixed it on 6f9a6c6.

Fluit commented 3 years ago

Tested and approved!

thanks.