From 678094a47df1ed6d19e47ad32992bb1d26eb5247 Mon Sep 17 00:00:00 2001 From: Steven Murray <steven.murray@cern.ch> Date: Thu, 1 Dec 2016 17:14:55 +0100 Subject: [PATCH] Replaced PL/SQL with straight SQL --- catalogue/drop_oracle_catalogue_schema.sql | 124 +++------------------ 1 file changed, 14 insertions(+), 110 deletions(-) diff --git a/catalogue/drop_oracle_catalogue_schema.sql b/catalogue/drop_oracle_catalogue_schema.sql index 7d25ddb70b..811a21dca6 100644 --- a/catalogue/drop_oracle_catalogue_schema.sql +++ b/catalogue/drop_oracle_catalogue_schema.sql @@ -1,110 +1,14 @@ -WHENEVER SQLERROR EXIT 1 -SET SERVEROUTPUT ON -SET FEEDBACK OFF - -VARIABLE plSqlReturnValue NUMBER - -DECLARE - SchemaIsLockedException EXCEPTION; - TYPE NameList IS TABLE OF VARCHAR2(30); - - tables NameList := NameList( - 'CTA_CATALOGUE', - 'ARCHIVE_ROUTE', - 'TAPE_FILE', - 'ARCHIVE_FILE', - 'TAPE', - 'REQUESTER_MOUNT_RULE', - 'REQUESTER_GROUP_MOUNT_RULE', - 'ADMIN_USER', - 'ADMIN_HOST', - 'STORAGE_CLASS', - 'TAPE_POOL', - 'LOGICAL_LIBRARY', - 'MOUNT_POLICY'); - - sequences NameList := NameList( - 'ARCHIVE_FILE_ID_SEQ'); - - PROCEDURE dropTableIfExists(tableName IN VARCHAR2) IS - BEGIN - EXECUTE IMMEDIATE 'DROP TABLE ' || tableNAme; - DBMS_OUTPUT.PUT_LINE('Table ' || tableName || ' dropped'); - EXCEPTION - WHEN OTHERS THEN - -- ORA-00942: table or view does not exist - IF SQLCODE = -942 THEN - DBMS_OUTPUT.PUT_LINE('Table ' || tableName || ' not dropped because it does not exist'); - ELSE - RAISE; - END IF; - END; - - PROCEDURE dropSequenceIfExists(sequenceName IN VARCHAR2) IS - BEGIN - EXECUTE IMMEDIATE 'DROP SEQUENCE ' || sequenceName; - DBMS_OUTPUT.PUT_LINE('Sequence ' || sequenceName || ' dropped'); - EXCEPTION - WHEN OTHERS THEN - -- ORA-02289: sequence does not exist - IF SQLCODE = -2289 THEN - DBMS_OUTPUT.PUT_LINE('Sequence ' || sequenceName || ' not dropped because it does not exist'); - ELSE - RAISE; - END IF; - END; - - FUNCTION catalogueSchemaIsLocked RETURN BOOLEAN IS - TYPE StatusList IS TABLE OF VARCHAR2(100); - schemaLocked INTEGER; - schemaStatus VARCHAR2(100); - BEGIN - EXECUTE IMMEDIATE 'SELECT SCHEMA_STATUS FROM CTA_CATALOGUE' INTO schemaStatus; - RETURN 'LOCKED' = schemaStatus; - EXCEPTION - WHEN NO_DATA_FOUND THEN - DBMS_OUTPUT.PUT_LINE('Catalogue schema considered LOCKED because CTA_CATALOGUE table is corrupted'); - DBMS_OUTPUT.PUT_LINE('CTA_CATALOGUE table is empty when it should contain one row'); - RETURN TRUE; - WHEN OTHERS THEN - DBMS_OUTPUT.PUT_LINE('SQLCODE=' || SQLCODE); - -- ORA-00942: table or view does not exis - IF SQLCODE = -942 THEN - DBMS_OUTPUT.PUT_LINE('Catalogue schema considered UNLOCKED because the CTA_CATALOGUE table does not exist'); - RETURN FALSE; - -- ORA-01422: exact fetch returns more than requested number of rows - ELSIF SQLCODE = -1422 THEN - DBMS_OUTPUT.PUT_LINE('Catalogue schema considered LOCKED because CTA_CATALOGUE table is corrupted'); - DBMS_OUTPUT.PUT_LINE('CTA_CATALOGUE table contains more than one row when it should contain one'); - RETURN TRUE; - ELSE - RAISE; - END IF; - END; - -BEGIN - -- Non-zero means failure - :plSqlReturnValue := 1; - - IF catalogueSchemaIsLocked() THEN - DBMS_OUTPUT.PUT_LINE('Aborting drop of catalogue schema objects: Schema is LOCKED'); - DBMS_OUTPUT.PUT_LINE('See the following command-line tools for more details:'); - DBMS_OUTPUT.PUT_LINE('cta-catalogue-schema-lock'); - DBMS_OUTPUT.PUT_LINE('cta-catalogue-schema-status'); - DBMS_OUTPUT.PUT_LINE('cta-catalogue-schema-unlock'); - ELSE - FOR i IN 1 .. tables.COUNT LOOP - dropTableIfExists(tables(i)); - END LOOP; - - FOR i IN 1 .. sequences.COUNT LOOP - dropSequenceIfExists(sequences(i)); - END LOOP; - - -- Zero means success - :plSqlReturnValue := 0; - END IF; -END; -/ - -EXIT :plSqlReturnValue +DROP TABLE CTA_CATALOGUE; +DROP TABLE ARCHIVE_ROUTE; +DROP TABLE TAPE_FILE; +DROP TABLE ARCHIVE_FILE; +DROP TABLE TAPE; +DROP TABLE REQUESTER_MOUNT_RULE; +DROP TABLE REQUESTER_GROUP_MOUNT_RULE; +DROP TABLE ADMIN_USER; +DROP TABLE ADMIN_HOST; +DROP TABLE STORAGE_CLASS; +DROP TABLE TAPE_POOL; +DROP TABLE LOGICAL_LIBRARY; +DROP TABLE MOUNT_POLICY; +DROP SEQUENCE ARCHIVE_FILE_ID_SEQ; -- GitLab