Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1.4
-
Fix Version/s: 1.2.0-RC1
-
Component/s: Connection
-
Labels:None
-
Environment:Oracle database 10 or higher
Description
If I create a limited query with Oracle sometimes it generates an invalid query, giving ORA-00904 errror.
A simple DQL query like this:
$q = Doctrine_Query::create()
->select("$i.nome, $s.denominazione")
->from("Istituto $i")
->leftJoin("$i.Sedi $s");
creates this intermediate sql:
SELECT
"i"."id" AS "i__id",
"i"."nome" AS "i__nome",
"s"."id" AS "s__id",
"s"."denominazione" AS "s__denominazione"
FROM "istituto" "i"
LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto"
that passed to Doctrine_Pager generates this query:
SELECT "i"."id" AS "i__id",
"i"."nome" AS "i__nome",
"s"."id" AS "s__id",
"s"."denominazione" AS "s__denominazione"
FROM "istituto" "i"
LEFT JOIN "sede"
"s" ON "i"."id" = "s"."id_istituto"
WHERE "i"."id" IN (SELECT a."id" FROM (SELECT DISTINCT "i2"."id" FROM "istituto" "i") a WHERE ROWNUM <= 10)
The problem is in "i2" referenced in the inner SELECT statement. This inner query hasn't been correctly parsed, while the column has been aliased, the table name has an incorrect alias.
The problem is that the injected sql code necessary to pagination has some space missing inside the parenthesis, thus the tokenizer misses to alias the table name.
Here it follows a simple patch:
--- Oracle.php 2009-10-26 17:04:17.000000000 +0100
+++ Oracle-orig.php 2009-09-25 19:12:10.000000000 +0200
@@ -103,13 +103,13 @@
$column = $column === null ? '*' : $this->quoteIdentifier($column);
if ($offset > 0) {
$min = $offset + 1;
+ $query = 'SELECT b.'.$column.' FROM ( '.
+ 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ( '
+ . $query . ' ) a '.
+ ' ) b '.
- $query = 'SELECT b.'.$column.' FROM ('.
- 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ('
- . $query . ') a '.
- ') b '.
'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max;
} else {
+ $query = 'SELECT a.'.$column.' FROM ( ' . $query .' ) a WHERE ROWNUM <= ' . $max;
- $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max;
}
}
}
Activity
| Field | Original Value | New Value |
|---|---|---|
| Description |
If I create a limited query with Oracle sometimes it generates an invalid query, giving ORA-00904 errror. A simple DQL query like this: $q = Doctrine_Query::create() ->select("$i.nome, $s.denominazione") ->from("Istituto $i") ->leftJoin("$i.Sedi $s"); creates this intermediate sql: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" that passed to Doctrine_Pager generates this query: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" WHERE "i"."id" IN (SELECT a."id" FROM (SELECT DISTINCT "i2"."id" FROM "istituto" "i") a WHERE ROWNUM <= 10) The problem is in "i2" referenced in the inner SELECT statement. This inner query hasn't been correctly parsed, while the column has been aliased, the table name has an incorrect alias. The problem is that the injected sql code necessary to pagination has some space missing inside the parenthesis, thus the tokenizer misses to alias the table name. Here it follows a simple patch: --- Oracle.php 2009-10-26 17:04:17.000000000 +0100 +++ Oracle-orig.php 2009-09-25 19:12:10.000000000 +0200 @@ -103,13 +103,13 @@ $column = $column === null ? '*' : $this->quoteIdentifier($column); if ($offset > 0) { $min = $offset + 1; - $query = 'SELECT b.'.$column.' FROM ( '. - 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ( ' - . $query . ' ) a '. - ' ) b '. + $query = 'SELECT b.'.$column.' FROM ('. + 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (' + . $query . ') a '. + ') b '. 'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max; } else { - $query = 'SELECT a.'.$column.' FROM ( ' . $query .' ) a WHERE ROWNUM <= ' . $max; + $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max; } } } |
If I create a limited query with Oracle sometimes it generates an invalid query, giving ORA-00904 errror. A simple DQL query like this: $q = Doctrine_Query::create() ->select("$i.nome, $s.denominazione") ->from("Istituto $i") ->leftJoin("$i.Sedi $s"); creates this intermediate sql: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" that passed to Doctrine_Pager generates this query: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" WHERE "i"."id" IN (SELECT a."id" FROM (SELECT DISTINCT "i2"."id" FROM "istituto" "i") a WHERE ROWNUM <= 10) The problem is in "i2" referenced in the inner SELECT statement. This inner query hasn't been correctly parsed, while the column has been aliased, the table name has an incorrect alias. The problem is that the injected sql code necessary to pagination has some space missing inside the parenthesis, thus the tokenizer misses to alias the table name. Here it follows a simple patch: {code} --- Oracle.php 2009-10-26 17:04:17.000000000 +0100 +++ Oracle-orig.php 2009-09-25 19:12:10.000000000 +0200 @@ -103,13 +103,13 @@ $column = $column === null ? '*' : $this->quoteIdentifier($column); if ($offset > 0) { $min = $offset + 1; - $query = 'SELECT b.'.$column.' FROM ( '. - 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ( ' - . $query . ' ) a '. - ' ) b '. + $query = 'SELECT b.'.$column.' FROM ('. + 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (' + . $query . ') a '. + ') b '. 'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max; } else { - $query = 'SELECT a.'.$column.' FROM ( ' . $query .' ) a WHERE ROWNUM <= ' . $max; + $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max; } } } {code} |
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
| Resolution | Fixed [ 1 ] | |
| Status | Resolved [ 5 ] | Reopened [ 4 ] |
| Description |
If I create a limited query with Oracle sometimes it generates an invalid query, giving ORA-00904 errror. A simple DQL query like this: $q = Doctrine_Query::create() ->select("$i.nome, $s.denominazione") ->from("Istituto $i") ->leftJoin("$i.Sedi $s"); creates this intermediate sql: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" that passed to Doctrine_Pager generates this query: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" WHERE "i"."id" IN (SELECT a."id" FROM (SELECT DISTINCT "i2"."id" FROM "istituto" "i") a WHERE ROWNUM <= 10) The problem is in "i2" referenced in the inner SELECT statement. This inner query hasn't been correctly parsed, while the column has been aliased, the table name has an incorrect alias. The problem is that the injected sql code necessary to pagination has some space missing inside the parenthesis, thus the tokenizer misses to alias the table name. Here it follows a simple patch: {code} --- Oracle.php 2009-10-26 17:04:17.000000000 +0100 +++ Oracle-orig.php 2009-09-25 19:12:10.000000000 +0200 @@ -103,13 +103,13 @@ $column = $column === null ? '*' : $this->quoteIdentifier($column); if ($offset > 0) { $min = $offset + 1; - $query = 'SELECT b.'.$column.' FROM ( '. - 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ( ' - . $query . ' ) a '. - ' ) b '. + $query = 'SELECT b.'.$column.' FROM ('. + 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (' + . $query . ') a '. + ') b '. 'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max; } else { - $query = 'SELECT a.'.$column.' FROM ( ' . $query .' ) a WHERE ROWNUM <= ' . $max; + $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max; } } } {code} |
If I create a limited query with Oracle sometimes it generates an invalid query, giving ORA-00904 errror. A simple DQL query like this: $q = Doctrine_Query::create() ->select("$i.nome, $s.denominazione") ->from("Istituto $i") ->leftJoin("$i.Sedi $s"); creates this intermediate sql: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" that passed to Doctrine_Pager generates this query: SELECT "i"."id" AS "i__id", "i"."nome" AS "i__nome", "s"."id" AS "s__id", "s"."denominazione" AS "s__denominazione" FROM "istituto" "i" LEFT JOIN "sede" "s" ON "i"."id" = "s"."id_istituto" WHERE "i"."id" IN (SELECT a."id" FROM (SELECT DISTINCT "i2"."id" FROM "istituto" "i") a WHERE ROWNUM <= 10) The problem is in "i2" referenced in the inner SELECT statement. This inner query hasn't been correctly parsed, while the column has been aliased, the table name has an incorrect alias. The problem is that the injected sql code necessary to pagination has some space missing inside the parenthesis, thus the tokenizer misses to alias the table name. Here it follows a simple patch: {code} --- Oracle.php 2009-10-26 17:04:17.000000000 +0100 +++ Oracle-orig.php 2009-09-25 19:12:10.000000000 +0200 @@ -103,13 +103,13 @@ $column = $column === null ? '*' : $this->quoteIdentifier($column); if ($offset > 0) { $min = $offset + 1; + $query = 'SELECT b.'.$column.' FROM ( '. + 'SELECT a.*, ROWNUM AS doctrine_rownum FROM ( ' + . $query . ' ) a '. + ' ) b '. - $query = 'SELECT b.'.$column.' FROM ('. - 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (' - . $query . ') a '. - ') b '. 'WHERE doctrine_rownum BETWEEN ' . $min . ' AND ' . $max; } else { + $query = 'SELECT a.'.$column.' FROM ( ' . $query .' ) a WHERE ROWNUM <= ' . $max; - $query = 'SELECT a.'.$column.' FROM (' . $query .') a WHERE ROWNUM <= ' . $max; } } } {code} |
| Status | Reopened [ 4 ] | Closed [ 6 ] |
| Fix Version/s | 1.2.0-RC1 [ 10041 ] | |
| Resolution | Fixed [ 1 ] |
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-140, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
This is already fixed in all versions. 1.0, 1.1 and 1.2