From 30145129795543ea3eec7c543a8e8788b0896700 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Tue, 19 Apr 2011 08:09:54 +0000 Subject: [PATCH] 2011-04-19 Juan Manuel Ramon * install.php: Now it's possible to drop oracle db before installation. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4247 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 4 +++ pandora_console/install.php | 62 ++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 0d8ba86db0..f3aef34f82 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,7 @@ +2011-04-19 Juan Manuel Ramon + + * install.php: Now it's possible to drop oracle db before installation. + 2011-04-18 Sergio Martin * include/graphs/functions_pchart.php diff --git a/pandora_console/install.php b/pandora_console/install.php index f3fe7b4f31..b235a4bf9a 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -36,7 +36,7 @@ options_text = new Array('An existing Database','A new Database'); options_values = new Array('db_exist','db_new'); function ChangeDBDrop(causer) { - if (causer.value == 'db_exist') { + if (causer.value != 'db_exist' && window.document.step2_form.engine.value != 'mysql') { window.document.step2_form.drop.checked=0; window.document.step2_form.drop.disabled=1; } @@ -316,6 +316,33 @@ function parse_oracle_dump($connection, $url, $debug = false) { } } +function oracle_drop_all_objects ($connection) { + + //Drop all objects of the current instalation + $stmt = oci_parse($connection, + "BEGIN " . + "FOR cur_rec IN (SELECT object_name, object_type " . + "FROM user_objects " . + "WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SNAPSHOT', 'MATERIALIZED VIEW')) LOOP " . + "BEGIN " . + "IF cur_rec.object_type = 'TABLE' THEN " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\" CASCADE CONSTRAINTS'; " . + "ELSE " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'; " . + "END IF; " . + "EXCEPTION " . + "WHEN OTHERS THEN " . + "DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'); " . + "END; " . + "END LOOP; " . + "END; "); + + $result = oci_execute($stmt); + oci_free_statement($stmt); + + return 0; +} + function random_name ($size){ $temp = ""; for ($a=0;$a< $size;$a++) @@ -669,7 +696,7 @@ function install_step4() { check_generic ( 1, "Connection with Database"); // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1 && $dbaction != 'db_exist') { + if ($dbdrop == 1) { mysql_query ("DROP DATABASE IF EXISTS $dbname"); } @@ -741,6 +768,11 @@ function install_step4() { else { check_generic(1, "Connection with Database"); + // Drop all objects if needed + if ($dbdrop == 1) { + oracle_drop_all_objects($connection); + } + $step1 = parse_oracle_dump($connection, "pandoradb.oracle.sql"); check_generic($step1, "Creating schema"); @@ -802,8 +834,8 @@ function install_step4() { else { check_generic(1, "Connection with Database"); - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1 && $dbaction != 'db_exist') { + // Drop database if needed + if ($dbdrop == 1 && $dbaction == 'db_exist') { $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); } @@ -1007,27 +1039,7 @@ function install_step4() { case 'pgsql': break; case 'oracle': - //Drop all objects of the current instalation - $stmt = oci_parse($connection, - "BEGIN " . - "FOR cur_rec IN (SELECT object_name, object_type " . - "FROM user_objects " . - "WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SNAPSHOT', 'MATERIALIZED VIEW')) LOOP " . - "BEGIN " . - "IF cur_rec.object_type = 'TABLE' THEN " . - "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\" CASCADE CONSTRAINTS'; " . - "ELSE " . - "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'; " . - "END IF; " . - "EXCEPTION " . - "WHEN OTHERS THEN " . - "DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'); " . - "END; " . - "END LOOP; " . - "END; "); - - $result = oci_execute($stmt); - oci_free_statement($stmt); + oracle_drop_all_objects($connection); break; } }