Changeset 4990

Show
Ignore:
Timestamp:
09/26/08 18:31:22 (9 months ago)
Author:
jwage
Message:

[1.0] fixes #1337 Fixes issue with oracle export driver

Location:
branches/1.0
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Export.php

    r4804 r4990  
    11071107                     'create_sequences' => array(), 
    11081108                     'create_indexes'   => array(), 
    1109                      'alters'           => array() 
     1109                     'alters'           => array(), 
     1110                     'create_triggers'  => array(), 
    11101111                 ); 
    11111112             } 
     
    11401141                 } 
    11411142 
    1142                  // If alter table statement 
    1143                  if (substr($query, 0, strlen('ALTER TABLE')) == 'ALTER TABLE') { 
     1143                 // If alter table statement or oracle anonymous block enclosing alter 
     1144                 if (substr($query, 0, strlen('ALTER TABLE')) == 'ALTER TABLE' 
     1145                       || substr($query, 0, strlen('DECLARE')) == 'DECLARE') { 
    11441146                     $connections[$connectionName]['alters'][] = $query; 
    11451147 
     
    11471149                     continue; 
    11481150                 } 
     1151                  
     1152                 // If create trgger statement 
     1153                 if (substr($query, 0, strlen('CREATE TRIGGER')) == 'CREATE TRIGGER') { 
     1154                        $connections[$connectionName]['create_triggers'][] = $query; 
     1155                         
     1156                        unset($sql[$key]); 
     1157                        continue; 
     1158                 } 
    11491159             } 
    11501160         } 
     
    11531163         $build = array(); 
    11541164         foreach ($connections as $connectionName => $sql) { 
    1155              $build[$connectionName] = array_unique(array_merge($sql['create_tables'], $sql['create_sequences'], $sql['create_indexes'], $sql['alters'])); 
     1165             $build[$connectionName] = array_unique(array_merge($sql['create_tables'], $sql['create_sequences'], $sql['create_indexes'], $sql['alters'], $sql['create_triggers'])); 
    11561166         } 
    11571167 
  • branches/1.0/lib/Doctrine/Export/Oracle.php

    r4252 r4990  
    103103            'fields' => array($name => true), 
    104104        ); 
    105  
    106         $sql[] = $this->createConstraintSql($table, $indexName, $definition); 
    107  
     105                 
     106        $sql[] = 'DECLARE 
     107  constraints_Count NUMBER; 
     108BEGIN 
     109  SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \''.$table.'\' AND CONSTRAINT_TYPE = \'P\'; 
     110  IF constraints_Count = 0 THEN 
     111    EXECUTE IMMEDIATE \''.$this->createConstraintSql($table, $indexName, $definition).'\'; 
     112  END IF; 
     113END;';    
     114                 
    108115        if (is_null($start)) { 
    109116            $query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true); 
     
    139146      END LOOP; 
    140147   END IF; 
    141 END; 
    142 '; 
     148END;'; 
    143149        return $sql; 
    144150    } 
  • branches/1.0/tests/Export/OracleTestCase.php

    r3884 r4990  
    106106 
    107107        $this->assertEqual($this->adapter->pop(), 'COMMIT'); 
    108         $this->assertEqual(substr($this->adapter->pop(),0, 14), 'CREATE TRIGGER'); 
     108        $this->assertEqual(substr($this->adapter->pop(), 0, 14), 'CREATE TRIGGER'); 
    109109        $this->assertEqual($this->adapter->pop(), 'CREATE SEQUENCE MYTABLE_seq START WITH 1 INCREMENT BY 1 NOCACHE');   
    110         $this->assertEqual($this->adapter->pop(), 'ALTER TABLE MYTABLE ADD CONSTRAINT MYTABLE_AI_PK_idx PRIMARY KEY (id)'); 
     110        $this->assertEqual(substr($this->adapter->pop(), 0, 7), "DECLARE"); 
    111111        $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT)'); 
    112112        $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');