core icon indicating copy to clipboard operation
core copied to clipboard

Bug in Query builder Join

Open qhung opened this issue 7 years ago • 4 comments

Hello,

Currently, I am tired with JOIN and DB :: expr() Is the code below a bug? if ($this->_table instanceof \Database_Query_Builder_Select) { // Compile the subquery and add it $sql .= ' ('.$this->_table->compile().')'; } elseif ($this->_table instanceof \Database_Expression) { // Compile the expression and add its value $sql .= ' ('.trim($this->_table->value(), ' ()').')'; <== bug } Why trim() with ' ()' is used?

Example, i am using in my code: $qr->join(DB::expr(" table FORCE INDEX(PRIMARY) "), 'INNER'); Its make after of ')' is lost.

table FORCE INDEX ( PRIMARY

Thanks!

qhung avatar Jul 09 '18 09:07 qhung

Not really a bug, the first parameter of join() is the name of the table to join, not some arbitrary piece of SQL.

And the functionality was probably not included because its syntax is DB specific, so you can't make a generic compiler. The posibility to have per-driver compilers was only introduced recently.

WanWizard avatar Jul 16 '18 11:07 WanWizard

Dear WanWizard, Thanks for your answer!

But, i can use it in fuel 1.7. How can I write it in 1.8 version?

qhung avatar Jul 17 '18 05:07 qhung

I can't recall anything significant changed between 1.7 and 1.8, that needs to be checked.

WanWizard avatar Jul 22 '18 10:07 WanWizard

Please tell me when you understand. Thank you!

qhung avatar Jul 25 '18 13:07 qhung