FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

Problems with WhereClause #53

Closed srgzah closed 5 years ago

srgzah commented 8 years ago

I need where clause like this $statement->where('DATE(myDate)', '>=', 'DATE(NOW())');

But if we look at what happened with $statement->__toString() we will see TE(myDate) >= ?

The problem in this expression: return ' WHERE '.ltrim(implode('', $args), ' AND'); ltrim removes all letters listed in $character_mask.

string ltrim ( string $str [, string $character_mask ] ) http://php.net/manual/en//function.ltrim.php

ha17 commented 8 years ago

Another problem is that >= ? part -- like it is looking for a variable to replace in there, instead of a comparison.

In the "value" part of the where() method, can we check to see if it is not a variable and if not, just use as, is? You can't do this, either:

->where('columnA', '<>', 'columnB')

It treats columnB like a value, eg:

SELECT * FROM table WHERE columnA <> ? 

instead of

SELECT * FROM table WHERE columnA <> columnB

If not in a ->where(), maybe a new method ->whereCompareCol() or something?

If Maintainer @FaaPz doesn't see any caveats, I'll do it and a PR.

kwhat commented 5 years ago

I believe this was fixed a while ago in a different bug report. Is this still using the latest 2.x branch? There is now a RAW clause for doing things that shouldn't be escaped.