r67651 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67650‎ | r67651 | r67652 >
Date:18:14, 8 June 2010
Author:freakolowsky
Status:ok
Tags:
Comment:
* Fixed parserTests compatibility for Oracle
* Fixed DBPrefix not being set in the old installer
Modified paths:
  • /trunk/phase3/config/Installer.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/maintenance/ora/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/ora/tables.sql
@@ -581,7 +581,8 @@
582582 );
583583 CREATE INDEX &mw_prefix.l10n_cache_u01 ON &mw_prefix.l10n_cache (lc_lang, lc_key);
584584
585 -CREATE TABLE &mw_prefix.wiki_field_info_full (
 585+-- do not prefix this table as it breaks parserTests
 586+CREATE TABLE wiki_field_info_full (
586587 table_name VARCHAR2(35) NOT NULL,
587588 column_name VARCHAR2(35) NOT NULL,
588589 data_default VARCHAR2(4000),
@@ -592,14 +593,14 @@
593594 uniq NUMBER(1),
594595 nonuniq NUMBER(1)
595596 );
596 -ALTER TABLE &mw_prefix.wiki_field_info_full ADD CONSTRAINT &mw_prefix.wiki_field_info_full_pk PRIMARY KEY (table_name, column_name);
 597+ALTER TABLE wiki_field_info_full ADD CONSTRAINT wiki_field_info_full_pk PRIMARY KEY (table_name, column_name);
597598
598599 /*$mw$*/
599 -CREATE PROCEDURE &mw_prefix.fill_wiki_info IS
 600+CREATE PROCEDURE fill_wiki_info IS
600601 BEGIN
601 - DELETE &mw_prefix.wiki_field_info_full;
 602+ DELETE wiki_field_info_full;
602603
603 - FOR x_rec IN (SELECT '&mw_prefix.' || t.table_name table_name, t.column_name,
 604+ FOR x_rec IN (SELECT t.table_name table_name, t.column_name,
604605 t.data_default, t.data_length, t.data_type,
605606 DECODE (t.nullable, 'Y', '1', 'N', '0') not_null,
606607 (SELECT 1
@@ -629,7 +630,7 @@
630631 FROM user_tab_columns t, user_tables ut
631632 WHERE ut.table_name = t.table_name)
632633 LOOP
633 - INSERT INTO &mw_prefix.wiki_field_info_full
 634+ INSERT INTO wiki_field_info_full
634635 (table_name, column_name,
635636 data_default, data_length,
636637 data_type, not_null, prim,
@@ -646,79 +647,104 @@
647648 /*$mw$*/
648649
649650 /*$mw$*/
650 -CREATE OR REPLACE PROCEDURE duplicate_table(p_oldname IN VARCHAR2, p_newname IN VARCHAR2, p_temporary IN BOOLEAN)
651 -IS
652 - v_oldname VARCHAR2(32) := RTRIM(LTRIM(p_oldname, '"'), '"');
653 - v_newname VARCHAR2(32) := RTRIM(LTRIM(p_newname, '"'), '"');
654 - v_prefix VARCHAR2(32) := SUBSTR(v_newname, 1, INSTR(v_newname, v_oldname, -1)-1);
655 - e_table_not_exist EXCEPTION;
656 - PRAGMA EXCEPTION_INIT(e_table_not_exist, -00942);
 651+CREATE OR REPLACE PROCEDURE duplicate_table(p_tabname IN VARCHAR2,
 652+ p_oldprefix IN VARCHAR2,
 653+ p_newprefix IN VARCHAR2,
 654+ p_temporary IN BOOLEAN) IS
 655+ e_table_not_exist EXCEPTION;
 656+ PRAGMA EXCEPTION_INIT(e_table_not_exist, -00942);
657657 BEGIN
658 - BEGIN
659 - EXECUTE IMMEDIATE 'DROP TABLE '||v_newname||' CASCADE CONSTRAINTS';
660 - EXCEPTION WHEN e_table_not_exist THEN NULL; END;
661 -
662 - IF (p_temporary) THEN
663 - EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE '||v_newname||
664 - ' AS SELECT * FROM '||v_oldname||' WHERE ROWNUM = 0';
665 - ELSE
666 - EXECUTE IMMEDIATE 'CREATE TABLE '||v_newname||
667 - ' AS SELECT * FROM '||v_oldname||' WHERE ROWNUM = 0';
668 - END IF;
669 -
670 - FOR rc IN (SELECT column_name, data_default
671 - FROM user_tab_columns
672 - WHERE table_name = v_oldname
673 - AND data_default IS NOT NULL) LOOP
674 - EXECUTE IMMEDIATE 'ALTER TABLE '||v_newname||' MODIFY '||rc.column_name||' DEFAULT '||substr(rc.data_default, 1, 2000);
675 - END LOOP;
676 -
677 - FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl ('CONSTRAINT', constraint_name), 32767, 1),
678 - USER||'"."', USER||'"."'||v_prefix),
679 - '"'||constraint_name||'"', '"'||v_prefix||constraint_name||'"') DDLVC2
680 - , constraint_name
681 - FROM user_constraints uc
682 - WHERE table_name = v_oldname
683 - AND constraint_type = 'P') LOOP
684 - EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE')-1);
685 - END LOOP;
686 -
687 - FOR rc IN (SELECT REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl ('REF_CONSTRAINT', constraint_name), 32767, 1),
688 - USER||'"."', USER||'"."'||v_prefix) DDLVC2
689 - , constraint_name
690 - FROM user_constraints uc
691 - WHERE table_name = v_oldname
692 - AND constraint_type = 'R') LOOP
693 - EXECUTE IMMEDIATE rc.ddlvc2;
694 - END LOOP;
695 -
696 - FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl ('INDEX', index_name), 32767, 1),
697 - USER||'"."', USER||'"."'||v_prefix),
698 - '"'||index_name||'"', '"'||v_prefix||index_name||'"') DDLVC2
699 - , index_name
700 - FROM user_indexes ui
701 - WHERE table_name = v_oldname
702 - AND index_type != 'LOB'
703 - AND NOT EXISTS (SELECT NULL FROM user_constraints
704 - WHERE table_name = ui.table_name
705 - AND constraint_name = ui.index_name)) LOOP
706 - EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE')-1);
707 - END LOOP;
708 -
709 - FOR rc IN (SELECT REPLACE(REPLACE(UPPER(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl ('TRIGGER', trigger_name), 32767, 1)),
710 - USER||'"."', USER||'"."'||v_prefix),
711 - ' ON '||v_oldname, ' ON '||v_newname) DDLVC2
712 - , trigger_name
713 - FROM user_triggers
714 - WHERE table_name = v_oldname) LOOP
715 - EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ')-1);
716 - END LOOP;
 658+ BEGIN
 659+ EXECUTE IMMEDIATE 'DROP TABLE ' || p_newprefix || p_tabname ||
 660+ ' CASCADE CONSTRAINTS';
 661+ EXCEPTION
 662+ WHEN e_table_not_exist THEN
 663+ NULL;
 664+ END;
 665+ IF (p_temporary) THEN
 666+ EXECUTE IMMEDIATE 'CREATE GLOBAL TEMPORARY TABLE ' || p_newprefix ||
 667+ p_tabname || ' AS SELECT * FROM ' || p_oldprefix ||
 668+ p_tabname || ' WHERE ROWNUM = 0';
 669+ ELSE
 670+ EXECUTE IMMEDIATE 'CREATE TABLE ' || p_newprefix || p_tabname ||
 671+ ' AS SELECT * FROM ' || p_oldprefix || p_tabname ||
 672+ ' WHERE ROWNUM = 0';
 673+ END IF;
 674+ FOR rc IN (SELECT column_name, data_default
 675+ FROM user_tab_columns
 676+ WHERE table_name = p_oldprefix || p_tabname
 677+ AND data_default IS NOT NULL) LOOP
 678+ EXECUTE IMMEDIATE 'ALTER TABLE ' || p_newprefix || p_tabname ||
 679+ ' MODIFY ' || rc.column_name || ' DEFAULT ' ||
 680+ substr(rc.data_default, 1, 2000);
 681+ END LOOP;
 682+ FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('CONSTRAINT',
 683+ constraint_name),
 684+ 32767,
 685+ 1),
 686+ USER || '"."' || p_oldprefix,
 687+ USER || '"."' || p_newprefix),
 688+ '"' || constraint_name || '"',
 689+ '"' || p_newprefix || constraint_name || '"') DDLVC2,
 690+ constraint_name
 691+ FROM user_constraints uc
 692+ WHERE table_name = p_oldprefix || p_tabname
 693+ AND constraint_type = 'P') LOOP
 694+ dbms_output.put_line(SUBSTR(rc.ddlvc2,
 695+ 1,
 696+ INSTR(rc.ddlvc2, 'PCTFREE') - 1));
 697+ EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
 698+ END LOOP;
 699+ FOR rc IN (SELECT REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('REF_CONSTRAINT',
 700+ constraint_name),
 701+ 32767,
 702+ 1),
 703+ USER || '"."' || p_oldprefix,
 704+ USER || '"."' || p_newprefix) DDLVC2,
 705+ constraint_name
 706+ FROM user_constraints uc
 707+ WHERE table_name = p_oldprefix || p_tabname
 708+ AND constraint_type = 'R') LOOP
 709+ EXECUTE IMMEDIATE rc.ddlvc2;
 710+ END LOOP;
 711+ FOR rc IN (SELECT REPLACE(REPLACE(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('INDEX',
 712+ index_name),
 713+ 32767,
 714+ 1),
 715+ USER || '"."' || p_oldprefix,
 716+ USER || '"."' || p_newprefix),
 717+ '"' || index_name || '"',
 718+ '"' || p_newprefix || index_name || '"') DDLVC2,
 719+ index_name
 720+ FROM user_indexes ui
 721+ WHERE table_name = p_oldprefix || p_tabname
 722+ AND index_type != 'LOB'
 723+ AND NOT EXISTS
 724+ (SELECT NULL
 725+ FROM user_constraints
 726+ WHERE table_name = ui.table_name
 727+ AND constraint_name = ui.index_name)) LOOP
 728+ EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'PCTFREE') - 1);
 729+ END LOOP;
 730+ FOR rc IN (SELECT REPLACE(REPLACE(UPPER(DBMS_LOB.SUBSTR(DBMS_METADATA.get_ddl('TRIGGER',
 731+ trigger_name),
 732+ 32767,
 733+ 1)),
 734+ USER || '"."' || p_oldprefix,
 735+ USER || '"."' || p_newprefix),
 736+ ' ON ' || p_oldprefix || p_tabname,
 737+ ' ON ' || p_newprefix || p_tabname) DDLVC2,
 738+ trigger_name
 739+ FROM user_triggers
 740+ WHERE table_name = p_oldprefix || p_tabname) LOOP
 741+ EXECUTE IMMEDIATE SUBSTR(rc.ddlvc2, 1, INSTR(rc.ddlvc2, 'ALTER ') - 1);
 742+ END LOOP;
717743 END;
718744 /*$mw$*/
719745
720746 /*$mw$*/
721747 BEGIN
722 - &mw_prefix.fill_wiki_info;
 748+ fill_wiki_info;
723749 END;
724750 /*$mw$*/
725751
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -767,7 +767,27 @@
768768
769769 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) {
770770 $temporary = $temporary ? 'TRUE' : 'FALSE';
771 - return $this->query( 'BEGIN DUPLICATE_TABLE(\'' . $oldName . '\', \'' . $newName . '\', ' . $temporary . '); END;', $fname );
 771+ $oldName = trim(strtoupper($oldName), '"');
 772+ $oldParts = explode('_', $oldName);
 773+
 774+ $newName = trim(strtoupper($newName), '"');
 775+ $newParts = explode('_', $newName);
 776+
 777+ $oldPrefix = '';
 778+ $newPrefix = '';
 779+ for ($i = count($oldParts)-1; $i >= 0; $i--) {
 780+ if ($oldParts[$i] != $newParts[$i]) {
 781+ $oldPrefix = implode('_', $oldParts).'_';
 782+ $newPrefix = implode('_', $newParts).'_';
 783+ break;
 784+ }
 785+ unset($oldParts[$i]);
 786+ unset($newParts[$i]);
 787+ }
 788+
 789+ $tabName = substr($oldName, strlen($oldPrefix));
 790+
 791+ return $this->query( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \''.$newPrefix.'\', ' . $temporary . '); END;', $fname );
772792 }
773793
774794 function timestamp( $ts = 0 ) {
@@ -855,7 +875,7 @@
856876 $tableWhere = '= \''.$table.'\'';
857877 }
858878
859 - $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM '.$this->tableName('wiki_field_info_full').' WHERE table_name '.$tableWhere.' and column_name = \''.$field.'\'' );
 879+ $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name '.$tableWhere.' and column_name = \''.$field.'\'' );
860880 if ( oci_execute( $fieldInfoStmt, OCI_DEFAULT ) === false ) {
861881 $e = oci_error( $fieldInfoStmt );
862882 $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ );
Index: trunk/phase3/config/Installer.php
@@ -1866,7 +1866,7 @@
18671867 } elseif( $conf->DBtype == 'oracle' ) {
18681868 $dbsettings =
18691869 "# Oracle specific settings
1870 -\$wgDBprefix = \"{$slconf['DBprefix']}\";";
 1870+\$wgDBprefix = \"{$slconf['DBprefix_ora']}\";";
18711871 } else {
18721872 // ummm... :D
18731873 $dbsettings = '';

Follow-up revisions

RevisionCommit summaryAuthorDate
r67654* Backport r67651.freakolowsky18:15, 8 June 2010

Status & tagging log