Changeset 4990
- Timestamp:
- 09/26/08 18:31:22 (9 months ago)
- Location:
- branches/1.0
- Files:
-
- 3 modified
-
lib/Doctrine/Export.php (modified) (4 diffs)
-
lib/Doctrine/Export/Oracle.php (modified) (2 diffs)
-
tests/Export/OracleTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/lib/Doctrine/Export.php
r4804 r4990 1107 1107 'create_sequences' => array(), 1108 1108 'create_indexes' => array(), 1109 'alters' => array() 1109 'alters' => array(), 1110 'create_triggers' => array(), 1110 1111 ); 1111 1112 } … … 1140 1141 } 1141 1142 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') { 1144 1146 $connections[$connectionName]['alters'][] = $query; 1145 1147 … … 1147 1149 continue; 1148 1150 } 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 } 1149 1159 } 1150 1160 } … … 1153 1163 $build = array(); 1154 1164 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'])); 1156 1166 } 1157 1167 -
branches/1.0/lib/Doctrine/Export/Oracle.php
r4252 r4990 103 103 'fields' => array($name => true), 104 104 ); 105 106 $sql[] = $this->createConstraintSql($table, $indexName, $definition); 107 105 106 $sql[] = 'DECLARE 107 constraints_Count NUMBER; 108 BEGIN 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; 113 END;'; 114 108 115 if (is_null($start)) { 109 116 $query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true); … … 139 146 END LOOP; 140 147 END IF; 141 END; 142 '; 148 END;'; 143 149 return $sql; 144 150 } -
branches/1.0/tests/Export/OracleTestCase.php
r3884 r4990 106 106 107 107 $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'); 109 109 $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"); 111 111 $this->assertEqual($this->adapter->pop(), 'CREATE TABLE mytable (id INT)'); 112 112 $this->assertEqual($this->adapter->pop(), 'BEGIN TRANSACTION');