PHP-SQL-Parser icon indicating copy to clipboard operation
PHP-SQL-Parser copied to clipboard

UNION with function causes array index error.

Open EatonEmmerich opened this issue 7 years ago • 6 comments

query is:

SELECT table1.field1, CONCAT(table1.field1, table1.field2) as newfield
FROM table1
UNION ALL
SELECT table2.field3, CONCAT(table2.field3, table2.field2) as newfield
FROM table2

error output:

PHP Notice: Undefined offset: 0 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 1 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 2 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 3 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 4 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 5 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67 PHP Notice: Undefined offset: 6 in /mnt/c/Users/eemet/Subversion/Charity/PHP-SQL-Parser/src/PHPSQLParser/processors/SQLProcessor.php on line 67

Using head on master.

EatonEmmerich avatar Feb 26 '18 16:02 EatonEmmerich

Hi, we're facing the same problem. Possible solution: Add the following code in line 81 of BracketProcessor.php

if (!is_array($subtree)) { return array(); }

krappi01 avatar Apr 26 '18 17:04 krappi01

Yes, facing the same problem.

Another solution not so good is use @new to stop all notices.

sinri avatar May 22 '18 15:05 sinri

@sinri The resulting object also has the incorrect data, so just suppressing the error output doesn't help with the problem. The resulting SQL query created is not valid SQL syntax. I have not given the solution for @krappi01 a try, at the moment I mitigated the problem by not using function in my union query.

EatonEmmerich avatar May 22 '18 22:05 EatonEmmerich

@EatonEmmerich Yes, that is a bad situation, hope this would be fixed soon. Suppressing works for me because I just use parser to determine the type of SQL and filter modification out, so it actually could not be called as a solution :-(


By my further test, union would act correctly only for

(
SELECT table1.field1, CONCAT(table1.field1, table1.field2) as newfield
FROM table1
) UNION ALL (
SELECT table2.field3, CONCAT(table2.field3, table2.field2) as newfield
FROM table2
)

sinri avatar May 23 '18 03:05 sinri

Made a fork to try to fix this...

https://github.com/sinri/PHP-SQL-Parser/tree/sinri

sinri avatar May 28 '18 09:05 sinri

Also having the same issue here.

amadoalmex avatar Jun 02 '18 14:06 amadoalmex