MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/drdaas/admin/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/drdaas/admin/drdapkg_db2.sql

Rem
Rem $Header: rdbms/src/client/dps/protocol/drda/admin/drdapkg_db2.sql
Rem
Rem drdapkg_db2.sql
Rem
Rem Copyright (c) 2012, 2017, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      drdapkg_db2.sql  - Initialize DRDA-AS environment so that
Rem                          packages can be bound and correct datatypes
Rem                          are returned for various SQL constructs
Rem
Rem    DESCRIPTION
Rem      The DRDA-AS environment needs to be initialized so that the initial
Rem      packages (usually with an RDBCOLID of NULLID) can be bound.	
Rem      Using the DataDirect driver, those package names look like
Rem          NULLID.DDOC510A, NULLID.DDOC510B, and NULLID.DDOC510C
Rem      Using the IBM driver (libdb2.so), the package names look like
Rem          NULLID.SYSTAT and NULLID.SYSshyxx (where s is one of L or S,
Rem                    h is one of H or N, y is 1, 2, 3, or 4 and
Rem                                          xx is somwhere in 00 thru FF)
Rem      Also, various columns must be TYPEMAPped -- their normal
Rem      attributes must be altered.
Rem 
Rem      The initial package bindings should
Rem      be done under the id that runs this script. That is, if we
Rem      run this script under the Oracle ID of xxxx, then the 
Rem      initial connection via an ODBC driver should be using that same
Rem      id, namely xxxx.
Rem
Rem      Some AS-400 specific packages are specified also; namely
Rem      QSQL400.QSQL1000.
Rem    NOTES
Rem      The following is relevant when using the IBM driver: libdb2.so ...
Rem        Note that the normal set of packages produced by the jdbcbinder 
Rem        process (db2jdbcbinder in DB2/LUW) defines packages with names like
Rem        SYSSTAT and SYSLNmnn and SYSLHmnn. Thus, before running the
Rem        jdbcbinder on DB2/LUW specifying the Oracle Id accepted in the prompt
Rem        for this script, one needs to inform DRDA-AS that the id has the
Rem        required privilege, namely to create ANY package in the NULLID
Rem        schema. That is part of what we are doing here.
Rem 
Rem      This script can be run ONLY by a user that has the ability to use
Rem      the DRDAAS_ADMIN_ROLE which must be GRANTed to the user; also this
Rem      role must be active either by being set as a default ROLE or
Rem      by actively doing a SET ROLE DRDAAS_ADMIN_ROLE.
Rem
Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: rdbms/src/client/dps/protocol/drda/admin/drdapkg_db2.sql
Rem    SQL_SHIPPED_FILE: drdaas/admin/drdapkg_db2.sql
Rem    SQL_PHASE: UTILITY
Rem    SQL_STARTUP_MODE: NONE
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    END SQL_FILE_METADATA
Rem
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    pcastro     03/31/14 - add more DataDirect TYPEMAPs for Catalog queries
Rem    cbenet      02/04/13 - add some i5 (QSQL400) items
Rem    cbenet      03/25/12 - Created
Rem

SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100

SET SERVEROUTPUT ON 

SHOW USER

/* The following  will work even if DRDAAS_ADMIN_ROLE is not one of the */
/* DEFAULT Roles, but HAS been GRANTed to the user running this script. */
/* (A prerequisite of setting a DEFAULT ROLE for a user is that the user*/
/*  has been GRANTed that ROLE).                                        */

SET ROLE DRDAAS_ADMIN_ROLE;

Prompt Enter the OracleID under which the initial package BINDs will be made
Prompt Use quotes (') if needed.
Accept OracleID
Define BindID = &OracleID
Prompt Enter default collection ID for package binding (usually NULLID)
Prompt Use quotes (') if needed.
Accept DefaultCollection
Define DfltCollid = &DefaultCollection

declare 
 id_passed CONSTANT VARCHAR2(128) := '&&BindId';
 collid_passed CONSTANT VARCHAR2(128) := '&&DfltCollid';
 id_to_use VARCHAR2(128);
 collid_to_use VARCHAR2(128);
 id_len PLS_INTEGER;
 collid_len PLS_INTEGER;
 quote CONSTANT CHAR := '''';
begin
 id_len := LENGTH(id_passed);
 collid_len := LENGTH(collid_passed);

 IF SUBSTR(id_passed, 1, 1) = quote AND SUBSTR(id_passed, id_len, 1) = quote 
      THEN
    /* Use Id exactly as passed */
    id_to_use := SUBSTR(id_passed, 2, id_len - 2);
 ELSE
    id_to_use := UPPER(id_passed) ;
 END IF;
 IF SUBSTR(collid_passed, 1, 1) = quote AND 
    SUBSTR(collid_passed, collid_len, 1) = quote THEN
    /* Use Collection ID  exactly as passed */
    collid_to_use :=  SUBSTR(collid_passed, 2, collid_len-2) ;
 ELSE
    collid_to_use :=  UPPER(collid_passed) ;
 END IF;

 -- The following section is pertinent to ALL flavors of DB2
 -- =========================================================

  -- The id of the specified  user will have ALL privileges for ANY Package in
  -- RDBCOLID=collid_to_use

  DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE( DBMS_DRDAAS_ADMIN.ALL_PRIVILEGE,
                                     collid_to_use,'*', id_to_use);

  commit;

  -- If you might want the id specified to create packages in rcbcolid= SCOTT,
  -- then you need to do the following:

  -- DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE(DBMS_DRDAAS_ADMIN.ALL_PRIVILEGE,
  --                                   'SCOTT','*', id_to_use);
  -- commit;

  -- Typemaps ...

  -- The described "type" for "COUNT(*)" columns in any package in the 
  -- collid_to_use schema should be INTEGER

  -- General "COUNT(*)" case
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'*','COUNT(*)',
                               'NUMBER=INTEGER');



  -- ==================================================
  -- The following section is pertinent ONLY to DB2/zOS
  -- ==================================================

  -- To use DB2 z/OS SPUFI asgainst DRDAAS, the given oracle-id must be able to 
  -- define packages in the DSNESPCS and DSNESPRR schemas

  -- DB2 z/OS SPUFI Packages

  DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE( DBMS_DRDAAS_ADMIN.ALL_PRIVILEGE, 
                                    'DSNESPCS','*', id_to_use);
  DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE( DBMS_DRDAAS_ADMIN.ALL_PRIVILEGE, 
                                    'DSNESPRR','*', id_to_use);
  commit;

  -- ======================================================================
  -- Specific DataDirect ODBC package discovery queries for DB2 z/OS
  -- (that is, if the identity of the DRDAAS is ZOS)

  -- When accessing the collid_to_use.DDOC510A package, the
  -- "column" MAX(SECTNO) referencing table SYSIBM.SYSPACKSTMT (which is a
  --  NUMBER in Oracle terms) should be described as a SMALLINT to the 
  -- application

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510A',
                                'SYSIBM.SYSPACKSTMT:MAX(SECTNO)',
                                'NUMBER=SMALL');

  -- Same as above but for package collid_to_use.DDOC510B

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510B',
                                'SYSIBM.SYSPACKSTMT:MAX(SECTNO)',
                                'NUMBER=SMALL');


  -- When accessing the collid_to_use.DDOC510A  package, the 
  -- "column" COUNT(DISTINCT(NAME)) referencing table SYSIBM.SYSPACKSTMT 
  -- (which is  a NUMBER in Oracle terms) should be described as a SMALLINT to
  --  the  application

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510A',
                                'SYSIBM.SYSPACKSTMT:COUNT(DISTINCT(NAME))',
                                'NUMBER=INTEGER');

  -- Same as above but for package collid_to_use.DDOC510B

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510B',
                                'SYSIBM.SYSPACKSTMT:COUNT(DISTINCT(NAME))',
                                'NUMBER=INTEGER');

  -- Some of the metadata functions (ei: SQLColumns, SQLStatistics)
  -- presume a specific datatype for certain numeric columns being
  -- returned by the underlying SQL used to implement these calls.

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSCOLUMNS:CASEWHENRTRIM(COLTYPE)LIKE''ROWID''THENLENGTH2ELSELENGTHEND',
                                'NUMBER=INTEGER');
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSCOLUMNS:10',
                                'NUMBER=INTEGER');
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSINDEXES:CASECLUSTEREDWHEN''Y''THEN1ELSE3END',
                                'NUMBER=INTEGER');
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSKEYS:COLSEQ',
                                'NUMBER=SMALL');
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSINDEXES:BIGINT(FULLKEYCARDF)',
                                'NUMBER=BIGINT');

  -- Some additional metadata transforms when SwisSQL transforms applied.

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSINDEXES:DECODE(CLUSTERED,''Y'',1,3)',
                                'NUMBER=INTEGER');
  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOU510A',
                                'SYSIBM.SYSINDEXES:CAST(FULLKEYCARDFASINTEGER)',
                                'NUMBER=BIGINT');

  -- ======================================================================
  -- Specific DataDirect JDBC package discovery queries for DB2 z/OS
  -- (that is, if the identity of the DRDAAS is ZOS)

  -- When accessing the collid_to_use.DDJC360B package, the "column"
  -- COUNT(*)-1 referencing table SYSIBM.SYSPACKSTMT (which is  a NUMBER in
  -- Oracle terms) should be described as an INTEGER to the application

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDJC360B',
                               'SYSIBM.SYSPACKSTMT:COUNT(*)-1', 
                               'NUMBER=INTEGER');

  -- When accessing the collid_to_use.DDJC360B package, the "column"
  -- COUNT(*)-1 referencing table SYSIBM.SYSPACKSTMT (which  might be described
  -- as NUMBER(0,-127) in Oracle terms) describe the column as an INTEGER
  -- to the application.

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDJC360B',
                                'SYSIBM.SYSPACKSTMT:COUNT(*)-1', 
                                'NUMBER(0,-127)=INTEGER');
  commit;


  -- =====================================================
  --  the following section is pertinent ONLY to DB2/LUW
  -- =====================================================

  -- ======================================================================
  -- Specific DataDirect ODBC package discovery queries for DB2/LUW
  -- (that is, if the identity of the DRDAAS is LUW)

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510A',
                                'SYSIBM.SYSPLAN:MIN(TOTALSECT)',
                                'NUMBER=SMALL');

  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510A',
                                'SYSIBM.SYSPLAN:COUNT(*)', 
                                'NUMBER=INTEGER');
  --  DBMS_DRDAAS_ADMIN.SET_TYPEMAP(collid_to_use,'DDOC510A',
  --                                'MIN(TOTALSECT)', 'NUMBER=SMALL');
  commit;

  --  ==================================================
  --  The following section is pertinent ONLY to DB2/iOS
  --  ==================================================

  -- if the identity of the AR is ios

  /* "id_to_use" can do the BINDs for packages in QSQL400 */
  DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE( DBMS_DRDAAS_ADMIN.ALL_PRIVILEGE,
                                    'QSQL400','*', id_to_use);
  /* anyone can execute these packages */
  DBMS_DRDAAS_ADMIN.GRANT_PRIVILEGE( DBMS_DRDAAS_ADMIN.EXECUTE_PRIVILEGE,
                                    'QSQL400','*', 'PUBLIC');

  commit;

end;
/


OHA YOOOO