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

[BUG] Invalid Oracle Limiting #760

Closed
mingalevme opened this issue Jul 2, 2013 · 8 comments
Closed

[BUG] Invalid Oracle Limiting #760

mingalevme opened this issue Jul 2, 2013 · 8 comments
Labels
bug A bug report status: medium Medium

Comments

@mingalevme
Copy link

$p = Package::findFirst(3);

Exception: Column "DB_ROWNUM" doesn't make part of the column map

Generates the SQL:

SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( SELECT [COLUMS] FROM "RADIO"."RADIO_PACKAGE" WHERE "RADIO_PACKAGE"."RADIO_PACKAGE_ID" = 3 ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN 1 AND 1
SELECT COUNT(*) AS "numrows" FROM (SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( SELECT [COLUMNS] FROM "RADIO"."RADIO_PACKAGE" WHERE "RADIO_PACKAGE"."RADIO_PACKAGE_ID" = 3 ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN 1 AND 1)

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@phalcon
Copy link
Collaborator

phalcon commented Jul 3, 2013

@marciopaiva can you take a look?

@marciopaiva
Copy link
Contributor

checking...

@marciopaiva
Copy link
Contributor

@mingalevme I can´t simulate the error.
which version of Oracle you are using??

@mingalevme
Copy link
Author

@marciopaiva I think, the problem is in SQL-query and Column-mapping (Model::columnMap()). The SQL-query:

SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( SELECT [COLUMS] FROM "RADIO"."RADIO_PACKAGE" WHERE "RADIO_PACKAGE"."RADIO_PACKAGE_ID" = 3 ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN 1 AND 1

returns all table columns and column DB_ROWNUM, but model don't expect that column.
P.S. I use Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production.

@marciopaiva
Copy link
Contributor

@mingalevme plz, post u Model.

@mingalevme
Copy link
Author

<?php

namespace Radio\MVC;

abstract class Model extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->setSchema('RADIO');
    }
}
<?php

class Package extends \Radio\MVC\Model
{
    public function getSource()
    {
        return 'RADIO_PACKAGE';
    }

    public static function columnMap()
    {
        return [
            'RADIO_PACKAGE_ID' => 'id',
            'RADIO_PACKAGE_TITLE' => 'title',
            'RADIO_PACKAGE_BODY_ORIG' => 'body',
            'RADIO_PACKAGE_BODY_REWRITE' => 'body_rewrite',
            'RADIO_PACKAGE_ANNOUNCE' => 'lead',
            'RADIO_PACKAGE_STATUS_ID' => 'status_id',
            'RADIO_PACKAGE_FILENAME' => 'filename',
            'RADIO_PACKAGE_DATE_CREATED' => 'date_created',
            'RADIO_PACKAGE_DATE_MODIFIED' => 'date_modified',
            'RADIO_PACKAGE_AIR_START_DATE' => 'air_start_date',
            'RADIO_PACKAGE_AIR_STOP_DATE' => 'air_stop_date',
            'RADIO_PACKAGE_AIR_PERIOD' => 'air_period',
            'RADIO_PACKAGE_DISCLAIMER' => 'disclaimer',
            'RADIO_PACKAGE_COMMENT' => 'comment',
            'RADIO_HOTDOG_ID' => 'hotdog_id',
            'RADIO_USER' => 'user',
            'RADIO_PACKAGE_IS_ACTIVE' => 'is_active',
        ];
    }
}

@marciopaiva
Copy link
Contributor

@mingalevme put in u columnMap() map to "DB_ROWNUM"

<?php

class Package extends \Radio\MVC\Model
{
    public function getSource()
    {
        return 'RADIO_PACKAGE';
    }

    public static function columnMap()
    {
        return [
            'RADIO_PACKAGE_ID' => 'id',
            'RADIO_PACKAGE_TITLE' => 'title',
            'RADIO_PACKAGE_BODY_ORIG' => 'body',
            'RADIO_PACKAGE_BODY_REWRITE' => 'body_rewrite',
            'RADIO_PACKAGE_ANNOUNCE' => 'lead',
            'RADIO_PACKAGE_STATUS_ID' => 'status_id',
            'RADIO_PACKAGE_FILENAME' => 'filename',
            'RADIO_PACKAGE_DATE_CREATED' => 'date_created',
            'RADIO_PACKAGE_DATE_MODIFIED' => 'date_modified',
            'RADIO_PACKAGE_AIR_START_DATE' => 'air_start_date',
            'RADIO_PACKAGE_AIR_STOP_DATE' => 'air_stop_date',
            'RADIO_PACKAGE_AIR_PERIOD' => 'air_period',
            'RADIO_PACKAGE_DISCLAIMER' => 'disclaimer',
            'RADIO_PACKAGE_COMMENT' => 'comment',
            'RADIO_HOTDOG_ID' => 'hotdog_id',
            'RADIO_USER' => 'user',
            'RADIO_PACKAGE_IS_ACTIVE' => 'is_active',
            'DB_ROWNUM' => 'db_rownum',
        ];
    }
}

I will find a solution to this problem, stupid oracle :(

@andresgutierrez
Copy link
Contributor

This is fixed in the 2.0.x branch (Phalcon 2.0.4), you have to change a global ORM setting to allow unexpected columns:

\Phalcon\Mvc\Model::setup(['ignoreUnknownColumns' => true]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

4 participants