developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #1232: oci.patch

File oci.patch, 3.6 KB (added by laurentj, 10 years ago)
  • lib/jelix/plugins/db/oci/oci.dbtools.php

    # HG changeset patch
    # Parent 03507821307e1fa9421b6f9cc011163bd6d1b5bc
    # User Laurent Jouanneau <laurent@xulfr.org>
    
    diff --git a/lib/jelix/plugins/db/oci/oci.dbtools.php b/lib/jelix/plugins/db/oci/oci.dbtools.php
    a b class ociDbTools extends jDbTools { 
    131131
    132132        $query = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH, NULLABLE, DATA_DEFAULT, 
    133133                        (SELECT CONSTRAINT_TYPE
    134134                         FROM USER_CONSTRAINTS UC, USER_CONS_COLUMNS UCC
    135135                         WHERE UCC.TABLE_NAME = UTC.TABLE_NAME
    136136                            AND UC.TABLE_NAME = UTC.TABLE_NAME
    137137                            AND UCC.COLUMN_NAME = UTC.COLUMN_NAME
    138138                            AND UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
    139                             AND UC.CONSTRAINT_TYPE = \'P\') AS CONSTRAINT_TYPE,
    140                          (SELECT \'Y\' FROM USER_SEQUENCES US
    141                          WHERE US.SEQUENCE_NAME = concat(\''.$this->_getAISequenceName($tableName,'\', UTC.COLUMN_NAME').')) AS IS_AUTOINCREMENT   
     139                            AND UC.CONSTRAINT_TYPE = \'P\') AS CONSTRAINT_TYPE
    142140                    FROM USER_TAB_COLUMNS UTC
    143141                    WHERE UTC.TABLE_NAME = \''.strtoupper($tableName).'\'';
    144142
    145143        $rs = $this->_conn->query ($query);
    146144
    147145        while ($line = $rs->fetch ()){
    148146
    149147            $field = new jDbFieldProperties();
    class ociDbTools extends jDbTools { 
    161159            if ($field->type == 'varchar2' || $field->type == 'varchar' ){
    162160                $field->length = intval($line->data_length);
    163161                $field->maxLength = $field->length;
    164162            }
    165163
    166164            $field->notNull = ($line->nullable == 'N');
    167165            $field->primary = ($line->constraint_type == 'P');
    168166
    169             /**
    170              * A chaque champ auto increment correspond une sequence
    171              */
    172             if ($line->is_autoincrement == 'Y'){
    173                 $field->autoIncrement  = true;
    174                 $field->sequence = $this->_getAISequenceName($tableName, $field->name);
     167            // FIXME, retrieve autoincrement property for other field than primary key
     168            if ($field->primary) {
     169                $sequenceName = $this->_getAISequenceName($tableName, $field->name);
     170                $sqlai = "SELECT 'Y' FROM USER_SEQUENCES US
     171                            WHERE US.SEQUENCE_NAME = '".$sequenceName."'";
     172                $rsai = $this->_conn->query ($sqlai);
     173                if ($this->_conn->query($sqlai)->fetch()){
     174                    $field->autoIncrement  = true;
     175                    $field->sequence = $sequenceName;
     176                }
    175177            }
    176178
    177179            if ($line->data_default !== null || !($line->data_default === null && $field->notNull)){
    178180                $field->hasDefault = true;
    179181                $field->default =  $line->data_default;   
    180182            }
    181183
    182184            $results[$field->name] = $field;
    class ociDbTools extends jDbTools { 
    184186        return $results;
    185187    }
    186188
    187189    /**
    188190    * récupère le nom de séquence correspondant à un champ auto_increment
    189191    * @return   string
    190192    */
    191193    function _getAISequenceName($tbName, $clName){
    192         return preg_replace(array('/\*tbName\*/', '/\*clName\*/'), array(strtoupper($tbName), strtoupper($clName)), $this->_conn->profile['sequence_AI_pattern']);
     194        return preg_replace(array('/\*tbName\*/', '/\*clName\*/'),
     195                            array(strtoupper($tbName), strtoupper($clName)),
     196                            $this->_conn->profile['sequence_AI_pattern']);
    193197    }
    194198}