Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHQL generating broken query for Oracle PDO if aliasing tables (extra AS in query) #11799

Closed
Skydev0h opened this issue May 17, 2016 · 0 comments
Milestone

Comments

@Skydev0h
Copy link
Contributor

Using PHQL to make a query with joins generates broken PDO query.
For example, next code:

$res = $this->modelsManager->executeQuery('select p.payOrderPosId, o.payDate, a.lastName ' . 
    'from HL\\PayOrderPos p join HL\\PayOrder o on p.payOrderId = o.payOrderId ' .
            'join HL\\Anketa a on a.anketaId = o.anketaId limit 50');

Generates the following query:

SELECT * FROM (SELECT Z1.*, ROWNUM PHALCON_RN FROM 
(SELECT p.PAY_ORDER_POS_ID AS payOrderPosId,
o.PAY_DATE AS payDate, a.LAST_NAME AS lastName FROM PAY_ORDER_POS AS p  
INNER JOIN PAY_ORDER AS o ON p.PAY_ORDER_ID = o.PAY_ORDER_ID 
INNER JOIN ANKETA AS a ON a.ANKETA_ID = o.ANKETA_ID) 
Z1 WHERE ROWNUM <= 50)
SELECT * FROM (SELECT Z1.*, ROWNUM PHALCON_RN FROM (SELECT p.PAY_ORDER_POS_ID AS payOrderPosId, o.PAY_DATE AS payDate, a.LAST_NAME AS lastName FROM PAY_ORDER_POS AS p  INNER JOIN PAY_ORDER AS o ON p.PAY_ORDER_ID = o.PAY_ORDER_ID INNER JOIN ANKETA AS a ON a.ANKETA_ID = o.ANKETA_ID) Z1 WHERE ROWNUM <= 50)

which results in error:
SQLSTATE[HY000]: General error: 907 OCIStmtExecute: ORA-00907: missing right parenthesis (/root/build/php-5.6.17/ext/pdo_oci/oci_statement.c:148)

Trying to query without limit gives another error:

$res = $this->modelsManager->executeQuery('select p.payOrderPosId, o.payDate, a.lastName ' . 
    'from HL\\PayOrderPos p join HL\\PayOrder o on p.payOrderId = o.payOrderId ' .
    'join HL\\Anketa a on a.anketaId = o.anketaId');
SELECT p.PAY_ORDER_POS_ID AS payOrderPosId, o.PAY_DATE AS payDate, a.LAST_NAME AS lastName 
FROM PAY_ORDER_POS AS p  
INNER JOIN PAY_ORDER AS o ON p.PAY_ORDER_ID = o.PAY_ORDER_ID 
INNER JOIN ANKETA AS a ON a.ANKETA_ID = o.ANKETA_ID
SELECT p.PAY_ORDER_POS_ID AS payOrderPosId, o.PAY_DATE AS payDate, a.LAST_NAME AS lastName FROM PAY_ORDER_POS AS p  INNER JOIN PAY_ORDER AS o ON p.PAY_ORDER_ID = o.PAY_ORDER_ID INNER JOIN ANKETA AS a ON a.ANKETA_ID = o.ANKETA_ID

SQLSTATE[HY000]: General error: 933 OCIStmtExecute: ORA-00933: SQL command not properly ended (/root/build/php-5.6.17/ext/pdo_oci/oci_statement.c:148)

Checking this with SQLDeveloper i figured that AS in the table naming should be omitted for Oracle. Therefore correct query is following:

SELECT p.PAY_ORDER_POS_ID AS payOrderPosId, o.PAY_DATE AS payDate, a.LAST_NAME AS lastName 
FROM PAY_ORDER_POS p  
INNER JOIN PAY_ORDER o ON p.PAY_ORDER_ID = o.PAY_ORDER_ID 
INNER JOIN ANKETA a ON a.ANKETA_ID = o.ANKETA_ID

A little more investigation is that the first error about "right paranthesis" is as well caused by extra "AS"es in the query.

Phalcon version: 2.1.0 RC 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants