Character escaping in where clause

eincandea
Member | 1
+
0
-

Hello,

i' trying to use the new jsonb operator of Postgresl

one of them is “?” like in

<?php
delete from users where myfield::jsonb ? 'akey'
?>

i'm trying to use the where() method but of course, it auto escape the ? character and wait for a parameters.

I tried

<?php
->where('myfield::jsonb ? 'akey'))
?>

or tried to fool it with

<?php
->where('myfield::jsonb ?', "? 'akey'))
?>

or

<?php
->where('myfield::jsonb ?',  $con::literal("? 'akey'"))
?>

but it always throw me some errors like “There are more placeholders than passed parameters.” Argument count does not match placeholder count.", etc

the problem is obviously the ? characters which is used by nett database processing AND postgres json !

Is there an easy way to add a where clause with preprocessing disabled?

Thank you for any help

Last edited by eincandea (2019-09-30 22:08)

Jan Tvrdík
Nette guru | 2595
+
0
-

Such query in AFAIK impossible with PDO in PHP < 7.4. See https://wiki.php.net/…placeholders for details.