Files
Database/_UP/prologue.inc
Jos Groot Lipman 1efbe7329b 2022 -> 2023
svn path=/Database/trunk/; revision=58134
2022-11-28 09:55:13 +00:00

154 lines
5.6 KiB
SQL
Raw Blame History

/* _up/prologue.inc
* Prologue of database schema update script for Facilitor, to be included in every schema update
*
* $Revision$
* $Id$
*/
#include "modules.h"
#include "comsql.h"
/* Check the current version number. If it is different from the expected version
* the user has the option to cancel the upgrace by pressing Ctrl-C.
* If you want to use this script in a non-interactive fashion, use e.g.
DEFINE ACCEPT_DB33=1
@@DB32TO33.SQL
in a script
* At the end the schema version and upgrade date are updated.
*/
SET HEADING OFF
SET TERMOUT ON
SET FEEDBACK OFF
SET ECHO OFF
SET VERIFY OFF
SET PAGESIZE 0
#define _MKVER(a) STRINGIZE(a)
column fcltlogfile new_value fcltlogfile NOPRINT;
select _MKVER(_VER) || '_' || UPPER(USER || '_' || sys_context('USERENV', 'SERVICE_NAME') || '_' || sys_context('USERENV', 'SERVER_HOST')) || '_' || to_char(sysdate,'YYYYMMDD_HH24MISS') || '.lst' as fcltlogfile from dual;
spool &fcltlogfile
column 1 new_value 1 noprint
select '' "1" from dual where rownum = 0;
define forceit = &1 "donot"
WHENEVER SQLERROR EXIT;
DECLARE
tekst VARCHAR2 (1000);
fac_schema fac_version.fac_version_schema%TYPE;
BEGIN
SELECT fac_version_schema
INTO fac_schema
FROM fac_version;
IF SUBSTR(fac_schema, 1, 2) <> SUBSTR(_MKVER(_VER), 3, 2) AND '&forceit' != 'FORCE' THEN
tekst := '==================================================================' || CHR(10)
|| 'This upgrade can only be applied to a DB'|| SUBSTR(_MKVER(_VER), 3, 2) || ' database' || CHR(10)
|| 'Current database is version DB'|| fac_schema || CHR(10)
|| 'Add parameter FORCE when calling this script to force the upgrade' || CHR(10)
|| 'This upgrade script is now cancelled!' || CHR(10)
|| '==================================================================' || CHR(10);
RAISE_APPLICATION_ERROR(-20000, 'OR'||'A-' || CHR(10) || tekst);
END IF;
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE <> -20000 THEN
RAISE_APPLICATION_ERROR(-20000, 'Could not find table FAC_VERSION. Not a Facilitor database?');
ELSE
RAISE;
END IF;
END;
/
DECLARE
tekst VARCHAR2 (1000);
BEGIN
CASE ASCII('<EFBFBD>')
WHEN 191 THEN tekst :='WE8ISO8859P1';
WHEN 128 THEN tekst :='WE8MSWIN1252'; -- De enige goede
ELSE tekst :='UNKNOWN ';
END CASE;
IF tekst <> 'WE8MSWIN1252' THEN
tekst := '=================================================================' || CHR(10)
|| 'Wrong clientside NLS_LANG ['|| TO_CHAR(ASCII('<EFBFBD>')) ||'] for this Facilitor upgrade.' || CHR(10)
|| 'WE8MSWIN1252 is required, we suspect '|| tekst || CHR(10)
|| 'Please enter before you start SQL*Plus:' || CHR(10)
|| ' on Windows:' || CHR(10)
|| ' SET NLS_LANG=.WE8MSWIN1252' || CHR(10)
|| ' on Unix:' || CHR(10)
|| ' export NLS_LANG=.WE8MSWIN1252' || CHR(10)
|| 'This upgrade script is now cancelled!' || CHR(10)
|| '=================================================================' || CHR(10);
RAISE_APPLICATION_ERROR(-20000, 'OR'||'A-' || CHR(10) || tekst);
END IF;
BEGIN
SELECT table_name
INTO tekst
FROM user_tables
WHERE table_name = 'FAC_VERSION';
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000, 'Could not find table FAC_VERSION. Not a Facilitor database?');
END;
END;
/
WHENEVER SQLERROR CONTINUE;
PROMPT [&fcltlogfile]
PROMPT
PROMPT ************************************************************************
PROMPT UPGRADE of Facilitor schema to version EVALCONCAT(DB, _DBV) $Revision$
PROMPT Copyright (c) 1996-2023 Aareon Nederland B.V. All rights reserved.
PROMPT
SELECT 'The current version of Facilitor@' || USER || ' is: ' || fac.getdbversion()
FROM DUAL;
PROMPT After the upgrade the schema version will be: EVALCONCAT(DB, _DBV)
PROMPT
PROMPT PLEASE VERIFY THESE SCHEMA NUMBERS!
PROMPT
PROMPT If these versions are not sequencing then execution of this script
PROMPT should be stopped by pressing Ctrl-C right now!
PROMPT
PROMPT Only run this script when no users or processes are using Facilitor
PROMPT
PROMPT ************************************************************************
PROMPT
PROMPT Press Enter to continue
SET DEFINE ON
PROMPT EVALCONCAT(&&ACCEPT_DB, _DBV)
PROMPT
PROMPT The upgrade continues, be patient. You will be notified when we are done...
PROMPT
SET DEFINE OFF /* Pas na de accept! */
SET HEADING OFF
SET FEEDBACK ON
SET LINESIZE 1000
SET TIME ON
SET SERVEROUTPUT ON SIZE UNLIMITED;
variable update_start number
exec :update_start := dbms_utility.get_time
/* om zeker te weten dat eventuele conversies goed gaan */
ALTER SESSION SET nls_territory='america';
SELECT adm.systeminfo FROM DUAL;
PROMPT This script was run in user:
SHOW USER
SELECT 'The version of Facilitor@' || USER || ' was ' || fac.getdbversion()
FROM DUAL;
SET HEADING OFF
SET LINESIZE 132
/* first compile all views, triggers etc */
BEGIN DBMS_UTILITY.COMPILE_SCHEMA(USER, FALSE); END;
/
PROMPT List of all invalid objects *before* Facilitor upgrade.
SELECT 'OR'||'A-'||'DB'||_DBV_STRING||' Warning: ' || object_type || ' ' || object_name || ' was ' || status || ' before the upgrade.'
FROM user_objects
WHERE object_type IN ('VIEW', 'TRIGGER', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'PACKAGE BODY')
AND status <> 'VALID'
ORDER BY object_name;
SET ECHO ON