UNION with function causes array index error.
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.
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(); }
Yes, facing the same problem.
Another solution not so good is use @new to stop all notices.
@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 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
)
Made a fork to try to fix this...
https://github.com/sinri/PHP-SQL-Parser/tree/sinri
Also having the same issue here.