CakeDC / cakephp-oracle-driver

CakePHP 3 Driver for Oracle Database
Other
40 stars 24 forks source link

Columns used in index IDX_NAME in table TBL_NAME was not found #22

Closed enmacc closed 2 years ago

enmacc commented 7 years ago

Hi, i get this error with our application:

Columns used in index "idx_f_cognome" in table "anagrafica_0" must be added to the Table schema first. The column "sys_nc00020$" was not found

This happens because the index is not a table column but is a column expressions.

I don't know if this is a common things, but we have this kind of index in our databases. And this is blocking for ORM and cake model generation. We have a index with name idx_f_cognome that has a columns SYS_NC00020$ who is a column expressions SUBSTR("COGNOME",1,50).

So in the code .... /vendor/cakedc/cakephp-oracle-driver/src/Database/Schema/OracleSchema.php at line 535

if ($isIndex) { $table->addIndex($keyName, [ 'type' => $type, 'columns' => $columns,
]); this exception happens

Im not DBA and can't' modifiy the db structure, Also i cant make a view of this table, but i think it maybe be a good thing having a list of items, index, constraint etc to skip for the model generation, if it's possibile. Bye

enmacc commented 7 years ago

I do a little work around and this is the structure of your $tableIndex retrieved from our table [ 'name' => 'IDX_F_COGNOME', 'type' => 'FUNCTION-BASED NORMAL', 'is_unique' => '0', 'column_name' => 'SYS_NC00020$', 'column_pos' => '1', 'is_primary' => null ]

I brutally add this code for my purpouse

    if($tableIndex['type'] != 'NORMAL'){
        return;
    }

So, in my opinion , you can manage all kind of index... or skip the evalution of the type not NORMAL or FUNCTION-BASED maybe in the search phase you can get a type of index NORMAL .

At the end the cake orm make only a query, when you send this query to db it manage and run it, so the db engine use the index , for our porpouse we don't care that.. or not?

Thank'you, greetings, sorry for my poor english.

alphp commented 2 years ago

In src\Database\Schema\OracleSchema.php:488 insert this code:

        if (preg_match('~FUNCTION-BASED~i', ($tableIndex['type'] ?? ''))) {
            return;
        }