r89370 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89369‎ | r89370 | r89371 >
Date:22:23, 2 June 2011
Author:freakolowsky
Status:ok
Tags:
Comment:
* fixed table duplication for phpunit testing
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/installer/OracleUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/oracle/archives/patch_rebuild_dupfunc.sql (added) (history)
  • /trunk/phase3/maintenance/oracle/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/oracle/archives/patch_rebuild_dupfunc.sql
@@ -0,0 +1,119 @@
 2+/*$mw$*/
 3+CREATE OR REPLACE PROCEDURE duplicate_table(p_tabname IN VARCHAR2,
 4+ p_oldprefix IN VARCHAR2,
 5+ p_newprefix IN VARCHAR2,
 6+ p_temporary IN BOOLEAN) IS
 7+ e_table_not_exist EXCEPTION;
 8+ PRAGMA EXCEPTION_INIT(e_table_not_exist, -00942);
 9+ l_temp_ei_sql VARCHAR2(2000);
 10+BEGIN
 11+ BEGIN
 12+ EXECUTE IMMEDIATE 'DROP TABLE ' || p_newprefix || p_tabname ||
 13+ ' CASCADE CONSTRAINTS';
 14+ EXCEPTION
 15+ WHEN e_table_not_exist THEN
 16+ NULL;
 17+ END;
 18+ IF (p_temporary) THEN
 19+ EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE ' || p_newprefix ||
 20+ p_tabname || ' AS SELECT * FROM ' || p_oldprefix ||
 21+ p_tabname || ' WHERE ROWNUM = 0';
 22+ ELSE
 23+ EXECUTE IMMEDIATE 'CREATE TABLE ' || p_newprefix || p_tabname ||
 24+ ' AS SELECT * FROM ' || p_oldprefix || p_tabname ||
 25+ ' WHERE ROWNUM = 0';
 26+ END IF;
 27+ FOR rc IN (SELECT column_name, data_default
 28+ FROM user_tab_columns
 29+ WHERE table_name = p_oldprefix || p_tabname
 30+ AND data_default IS NOT NULL) LOOP
 31+ EXECUTE IMMEDIATE 'ALTER TABLE ' || p_newprefix || p_tabname ||
 32+ ' MODIFY ' || rc.column_name || ' DEFAULT ' ||
 33+ SUBSTR(rc.data_default, 1, 2000);
 34+ END LOOP;
 35+ FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('CONSTRAINT',
 36+ constraint_name),
 37+ 32767,
 38+ 1),
 39+ USER || '"."' || p_oldprefix,
 40+ USER || '"."' || p_newprefix),
 41+ '"' || constraint_name || '"',
 42+ '"' || p_newprefix || constraint_name || '"') DDLVC2,
 43+ constraint_name
 44+ FROM user_constraints uc
 45+ WHERE table_name = p_oldprefix || p_tabname
 46+ AND constraint_type = 'P') LOOP
 47+ l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
 48+ l_temp_ei_sql := SUBSTR(l_temp_ei_sql,
 49+ 1,
 50+ INSTR(l_temp_ei_sql,
 51+ ')',
 52+ INSTR(l_temp_ei_sql, 'PRIMARY KEY') + 1) + 1);
 53+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 54+ EXECUTE IMMEDIATE l_temp_ei_sql;
 55+ END IF;
 56+ END LOOP;
 57+ IF (NOT p_temporary) THEN
 58+ FOR rc IN (SELECT REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('REF_CONSTRAINT',
 59+ constraint_name),
 60+ 32767,
 61+ 1),
 62+ USER || '"."' || p_oldprefix,
 63+ USER || '"."' || p_newprefix) DDLVC2,
 64+ constraint_name
 65+ FROM user_constraints uc
 66+ WHERE table_name = p_oldprefix || p_tabname
 67+ AND constraint_type = 'R') LOOP
 68+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 69+ EXECUTE IMMEDIATE l_temp_ei_sql;
 70+ END IF;
 71+ END LOOP;
 72+ END IF;
 73+ FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('INDEX',
 74+ index_name),
 75+ 32767,
 76+ 1),
 77+ USER || '"."' || p_oldprefix,
 78+ USER || '"."' || p_newprefix),
 79+ '"' || index_name || '"',
 80+ '"' || p_newprefix || index_name || '"') DDLVC2,
 81+ index_name,
 82+ index_type
 83+ FROM user_indexes ui
 84+ WHERE table_name = p_oldprefix || p_tabname
 85+ AND index_type NOT IN ('LOB', 'DOMAIN')
 86+ AND NOT EXISTS
 87+ (SELECT NULL
 88+ FROM user_constraints
 89+ WHERE table_name = ui.table_name
 90+ AND constraint_name = ui.index_name)) LOOP
 91+ l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
 92+ l_temp_ei_sql := SUBSTR(l_temp_ei_sql,
 93+ 1,
 94+ INSTR(l_temp_ei_sql,
 95+ ')',
 96+ INSTR(l_temp_ei_sql,
 97+ '"' || USER || '"."' || p_newprefix || '"') + 1) + 1);
 98+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 99+ EXECUTE IMMEDIATE l_temp_ei_sql;
 100+ END IF;
 101+ END LOOP;
 102+ FOR rc IN (SELECT REPLACE(REPLACE(UPPER(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('TRIGGER',
 103+ trigger_name),
 104+ 32767,
 105+ 1)),
 106+ USER || '"."' || p_oldprefix,
 107+ USER || '"."' || p_newprefix),
 108+ ' ON ' || p_oldprefix || p_tabname,
 109+ ' ON ' || p_newprefix || p_tabname) DDLVC2,
 110+ trigger_name
 111+ FROM user_triggers
 112+ WHERE table_name = p_oldprefix || p_tabname) LOOP
 113+ l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1);
 114+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 115+ EXECUTE IMMEDIATE l_temp_ei_sql;
 116+ END IF;
 117+ END LOOP;
 118+END;
 119+/*$mw$*/
 120+
Property changes on: trunk/phase3/maintenance/oracle/archives/patch_rebuild_dupfunc.sql
___________________________________________________________________
Added: svn:eol-style
1121 + native
Index: trunk/phase3/maintenance/oracle/tables.sql
@@ -756,22 +756,30 @@
757757 WHERE table_name = p_oldprefix || p_tabname
758758 AND constraint_type = 'P') LOOP
759759 l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
760 - l_temp_ei_sql := SUBSTR(l_temp_ei_sql, 1, INSTR(l_temp_ei_sql, ')', INSTR(l_temp_ei_sql, 'PRIMARY KEY')+1)+1);
761 - EXECUTE IMMEDIATE l_temp_ei_sql;
 760+ l_temp_ei_sql := SUBSTR(l_temp_ei_sql,
 761+ 1,
 762+ INSTR(l_temp_ei_sql,
 763+ ')',
 764+ INSTR(l_temp_ei_sql, 'PRIMARY KEY') + 1) + 1);
 765+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 766+ EXECUTE IMMEDIATE l_temp_ei_sql;
 767+ END IF;
762768 END LOOP;
763769 IF (NOT p_temporary) THEN
764 - FOR rc IN (SELECT REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('REF_CONSTRAINT',
765 - constraint_name),
766 - 32767,
767 - 1),
768 - USER || '"."' || p_oldprefix,
769 - USER || '"."' || p_newprefix) DDLVC2,
770 - constraint_name
771 - FROM user_constraints uc
772 - WHERE table_name = p_oldprefix || p_tabname
773 - AND constraint_type = 'R') LOOP
774 - EXECUTE IMMEDIATE rc.ddlvc2;
775 - END LOOP;
 770+ FOR rc IN (SELECT REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('REF_CONSTRAINT',
 771+ constraint_name),
 772+ 32767,
 773+ 1),
 774+ USER || '"."' || p_oldprefix,
 775+ USER || '"."' || p_newprefix) DDLVC2,
 776+ constraint_name
 777+ FROM user_constraints uc
 778+ WHERE table_name = p_oldprefix || p_tabname
 779+ AND constraint_type = 'R') LOOP
 780+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 781+ EXECUTE IMMEDIATE l_temp_ei_sql;
 782+ END IF;
 783+ END LOOP;
776784 END IF;
777785 FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('INDEX',
778786 index_name),
@@ -792,8 +800,15 @@
793801 WHERE table_name = ui.table_name
794802 AND constraint_name = ui.index_name)) LOOP
795803 l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
796 - l_temp_ei_sql := SUBSTR(l_temp_ei_sql, 1, INSTR(l_temp_ei_sql, ')', INSTR(l_temp_ei_sql, '"' || USER || '"."' || p_newprefix || '"')+1)+1);
797 - EXECUTE IMMEDIATE l_temp_ei_sql;
 804+ l_temp_ei_sql := SUBSTR(l_temp_ei_sql,
 805+ 1,
 806+ INSTR(l_temp_ei_sql,
 807+ ')',
 808+ INSTR(l_temp_ei_sql,
 809+ '"' || USER || '"."' || p_newprefix || '"') + 1) + 1);
 810+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 811+ EXECUTE IMMEDIATE l_temp_ei_sql;
 812+ END IF;
798813 END LOOP;
799814 FOR rc IN (SELECT REPLACE(REPLACE(UPPER(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('TRIGGER',
800815 trigger_name),
@@ -807,7 +822,9 @@
808823 FROM user_triggers
809824 WHERE table_name = p_oldprefix || p_tabname) LOOP
810825 l_temp_ei_sql := SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1);
811 - EXECUTE IMMEDIATE l_temp_ei_sql;
 826+ IF nvl(length(l_temp_ei_sql), 0) > 0 THEN
 827+ EXECUTE IMMEDIATE l_temp_ei_sql;
 828+ END IF;
812829 END LOOP;
813830 END;
814831 /*$mw$*/
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -818,12 +818,12 @@
819819 $newName = strtoupper( $newName );
820820 $oldName = strtoupper( $oldName );
821821
822 - $tabName = $this->addIdentifierQuotes( substr( $newName, strlen( $wgDBprefix ) ) );
823 - $oldPrefix = $this->addIdentifierQuotes( substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) ) );
824 - $newPrefix = $this->addIdentifierQuotes( $wgDBprefix );
 822+ $tabName = substr( $newName, strlen( $wgDBprefix ) );
 823+ $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) );
 824+ $newPrefix = strtoupper( $wgDBprefix );
825825
826826 $this->clearFlag( DBO_DDLMODE );
827 - return $this->doQuery( "BEGIN DUPLICATE_TABLE( $tabName, $oldPrefix, $newPrefix, $temporary ); END;" );
 827+ return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', '$oldPrefix', '$newPrefix', $temporary ); END;" );
828828 }
829829
830830 function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) {
@@ -833,7 +833,7 @@
834834 }
835835
836836 $owner = strtoupper( $this->mDBname );
837 - $result = $this->doQuery( "SELECT table_name FROM all_tables WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX$_' ESCAPE '!' $listWhere" );
 837+ $result = $this->doQuery( "SELECT table_name FROM all_tables WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" );
838838
839839 // dirty code ... i know
840840 $endArray = array();
Index: trunk/phase3/includes/installer/OracleUpdater.php
@@ -36,6 +36,10 @@
3737
3838 // 1.19
3939 array( 'addTable', 'config', 'patch-config.sql' ),
 40+
 41+
 42+ // till 2.0 i guess
 43+ array( 'doRebuildDuplicateFunction' ),
4044
4145 );
4246 }
@@ -118,7 +122,17 @@
119123 $this->output( "ok\n" );
120124 }
121125
 126+
122127 /**
 128+ * rebuilding of the function that duplicates tables for tests
 129+ */
 130+ protected function doRebuildDuplicateFunction() {
 131+ $this->output( "Rebuilding duplicate function ... " );
 132+ $this->applyPatch( 'patch_rebuild_dupfunc.sql', false );
 133+ $this->output( "ok\n" );
 134+ }
 135+
 136+ /**
123137 * Overload: after this action field info table has to be rebuilt
124138 *
125139 * @param $what array

Status & tagging log