[DC-918] Causing ORA-01791 when try to sort on relation field and use limit in query to Oracle DB Created: 06/Nov/10  Updated: 06/Nov/10

Status: Open
Project: Doctrine 1
Component/s: Query
Affects Version/s: 1.2.3
Fix Version/s: None

Type: Bug Priority: Blocker
Reporter: Dmitriy Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 2
Labels: None
Environment:

Windows 2003 Server, Oracle 10g, Symfony 1.4.8



 Description   

Schema in yml format
in Symfony it looks more simple, but i'm going to show relation in detail

PrType:
  columns:   
    name:                   { type: string(255), notnull: true }                          

PrTypeTranslation:
  columns:   
    id:                     { type: integer, notnull: true }
    name:                   { type: string(255), notnull: true }
    lang:                   { type: string(255), notnull: true }
  relations:
    PrType:                 { onDelete: CASCADE, local: id_id, foreign: id, foreignAlias: Translation }

When i try to execute this code:

   $q = Doctrine_Query::create()
            ->from('PrType tp')
            ->leftJoin('tp.Translation t WITH t.lang = ?', 'ru')
            ->orderBy('t.name')
            ->limit(10);

doctrine executes next statement:

SELECT "p"."id", "p2"."name" AS "p2__name", "p2"."lang" AS "p2__lang"
FROM "pr_type" "p"
LEFT JOIN "pr_type_translation" "p2" ON "p"."id" = "p2"."id" AND ("p2"."lang" = :oci_b_var_1)
WHERE "p"."id" IN (
              SELECT a."id" FROM ( 
                          SELECT DISTINCT "p3"."id"
                          FROM "pr_type" "p3"
                          INNER JOIN "pr_type_translation" "p4" ON "p3"."id" = "p4"."id" AND ("p4"."lang" = 'ru') 
                          ORDER BY "p4"."name" ) a 
                          WHERE ROWNUM <= 10) 
ORDER BY "p2"."name"

This sql code produces next error

ORA-01791: not a SELECTed expression

Error occures, because (from ORACODE)

There is an incorrect ORDER BY item. The query is a SELECT DISTINCT query with an ORDER BY clause. In this context, all ORDER BY items must be constants, SELECT list expressions, or expressions whose operands are constants or SELECT list expressions



 Comments   
Comment by Dmitriy [ 06/Nov/10 ]

Some very similar issue were reported and resolved here http://trac.doctrine-project.org/ticket/1038.

Comment by Dmitriy [ 06/Nov/10 ]

Reason of issue was founded. It appears because i'm using oci8 driver, and this drivername not be listed in if statement on line 1401 in Doctrine/Query.php:

LINE 1401: if ($driverName == 'pgsql' || $driverName == 'oracle' || $driverName == 'oci' || $driverName == 'mssql' || $driverName == 'odbc') {

I changed to:

LINE 1401: if ($driverName == 'pgsql' || $driverName == 'oracle' || $driverName == 'oci' || $driverName == 'oci8' || $driverName == 'mssql' || $driverName == 'odbc') {

Sorry, but i don't know how to create patch diff file.

Generated at Sat Oct 25 21:19:32 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.