database icon indicating copy to clipboard operation
database copied to clipboard

Unable to use lowercase SQL params

Open aiphee opened this issue 8 years ago • 2 comments

NTDB is escaping lowercase, so i am unable to use expressions like this: $selection->where(["DATE_FORMAT(eventStart,'%Y-%m-%d'" => '2017-01-26'])

It always escaped (even when i use SQLLiteral), and resulting SQL looks like this: (DATE_FORMAT(`eventStart`,'%Y-%`m`-%`d`' = '2017-01-26)

Notice that Y is not escaped, while the other two letters are.

Of what i found, escaping happens here: https://github.com/nette/database/blob/master/src/Database/Table/SqlBuilder.php#L759

aiphee avatar Jan 23 '17 13:01 aiphee

For this moment you can write like:

dump($selection->where('DATE_FORMAT(registration_date, ?) = ?', '%Y-%m-%d', '2017-01-26')->fetch());
// or if you need this format YYYY-MM-DD
dump($selection->where('DATE(registration_date)', '2017-01-26')->fetch());

h4kuna avatar Jan 25 '17 08:01 h4kuna

Oh, thank you, it works. I guess it is solved then?

It would just be nice if documentation had this info.

aiphee avatar Jan 25 '17 08:01 aiphee