dg / dibi

Dibi - smart database abstraction layer

Home Page:https://dibiphp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ARRAY[...] expression raises syntax error because of Translation

groupnet opened this issue · comments

Version: 4.1.3

Bug Description

An Uncaught Dibi\\DriverException: syntax error ... is raised, when selecting a simple ARRAY[...] in Postgresql.

The expression ARRAY[1,2] is translated to ARRAY "1,2" I guess by this regex:

. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s',

Steps To Reproduce

$database->query('SELECT ARRAY[1,2]');

Expected Behavior

No translation of ARRAY[...] expressions

Possible Solution

Couldn't solve it. Quick'n'dirty workaround is to remove the square bracket [ from line 89, to skip translation:

$toSkip = strcspn($arg, '`[\'":%?');

Try use %SQL modifier or $connection->literal('ARRAY[1,2]').

Works - thanks for the help!