{ ************************************************************************* }
{                                                                           }
{  Licensed Materials - Property of IBM and/or HCL                                     }
{                                                                           }
{  IBM Informix Dynamic Server                                              }
{  (c) Copyright IBM Corporation 2015 All rights reserved.                  }
{  (c) Copyright HCL Technologies Ltd. 2017.  All Rights Reserved.                  }
{                                                                           }
{   Title:      boot1110.sql                                                }
{                                                                           }
{   Description:                                                            }
{       Bootstrapping script for a 11.10 database                           }
{                                                                           }
{ ************************************************************************* }
{                                                                           }
{  ** IMPORTANT - PLEASE READ                                               } 
{                                                                           }
{     All types and routines referenced in this file must be prefixed       }
{     with the user name "informix". E.g., use "informix.boolean"           }
{     and not "boolean"                                                     }
{									    }
{     Also, please follow the formatting conventions!!!                     }
{                                                                           }
{     Please ensure that the identifiers that you choose are <= 18          }
{     characters in length. Otherwise the changes would affect database     }
{     reversion.                                                            }
{                                                                           }
{ ************************************************************************* }

{  --- Create CDR exposed checksum functions  }

create dba function informix.ifx_checksum(informix.lvarchar, informix.integer)
 returns informix.integer
 with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
 external name '(lvarchar_checksum)'
 language C;

grant execute on function informix.ifx_checksum(informix.lvarchar, informix.integer) to public as informix;

create dba function informix.ifx_checksum(informix.integer, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(integer_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.integer, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.smallint, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(short_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.smallint, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(p1 references byte,informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(classicBlob_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.byte, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(p1 references text,informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(classicBlob_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.text, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.blob, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(sblob_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.blob, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.clob, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(sblob_checksum)'
    language C;


grant execute on function informix.ifx_checksum(informix.clob, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.int8, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(int8_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.int8, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.decimal, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(decimal_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.decimal, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.money, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(money_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.money, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.float, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(double_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.float, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.real, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(real_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.real, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.date, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(date_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.date, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(datetime year to fraction, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(datetime_checksum)'
    language C;

grant execute on function informix.ifx_checksum(datetime, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(interval year to month,informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(interval_checksum)'
    language C;

grant execute on function informix.ifx_checksum(interval, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.set, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(collection_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.set, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.multiset, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(collection_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.multiset, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(list, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(collection_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.list, informix.integer)
    to public as informix;

create dba function informix.ifx_checksum(informix.row, informix.integer)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(row_checksum)'
    language C;

grant execute on function informix.ifx_checksum(informix.row, informix.integer) to public as informix;

{ --- Create new systdist procedure  }
create dba procedure informix.systdist (table_id int, column_no int)
   returning int, datetime year to fraction (5), char(1), 
             smallfloat, smallfloat, float , stat, char(1);

   define v_tabauth      char(8);
   define v_colauth      char(3);
   define is_allowed     int;
   define search_columns int;
   define v_colno        smallint;
   define v_seqno        int;
   define v_constr_time  datetime year to fraction(5);
   define v_mode         char(1);
   define v_resolution   smallfloat;
   define v_confidence   smallfloat;
   define v_encdat       stat;
   define v_owner        char(8);
   define user           procedure;
   define v_stattype	 char(1);
   define v_smplsize	 float;
   define v_rolename	 varchar(32);

-- First verify that the current user has select privileges on this column

   let is_allowed = 0;
   let search_columns = 0;

   if user = 'informix' then
      let is_allowed = 1;
   else
      -- Check sysusers to see if the usertype is 'D', ie., the
      -- current user has dba privileges and may see any columns.
      select usertype
         into v_mode
         from informix.sysusers
         where username = user;
      if v_mode = 'D' then
         let is_allowed = 1;
      else
         -- See if the user owns the table, and therefore can see the columns.
         select owner
            into v_owner
	    from informix.systables
	    where tabid = table_id;
         if v_owner = user then
            let is_allowed = 1;
         end if
      end if
   end if

   if is_allowed = 0 then
      foreach 
         select tabauth 
            into v_tabauth
            from informix.systabauth
            where tabid = table_id and
                  (grantee = user or
                   grantee = 'public')
         if substr(v_tabauth, 1, 1) = 's' or substr(v_tabauth, 1, 1) = 'S' then
            let is_allowed = 1;
            exit foreach;
         elif substr(v_tabauth, 3, 1) = '*' then
            let search_columns = 1;
         end if
      end foreach
   end if

-- Search syscolauth only if user does not have select 
-- privileges on all columns.  If the user has no select
-- privileges on any column, then we need search no further.

   if is_allowed = 0 and search_columns = 1 then
      foreach
         select colauth
            into v_colauth
            from informix.syscolauth
            where tabid = table_id and
                  colno = column_no and
                  (grantee = user or
                   grantee = 'public')
         if substr(v_colauth, 1, 1) = 's' or substr(v_colauth, 1, 1) = 'S' then
            let is_allowed = 1;
            exit foreach;
         end if
      end foreach
   end if

-- Check user's current role for privileges on table and columns
   if is_allowed = 0 then
      select CURRENT_ROLE
         into v_rolename
         from informix.systables
         where tabid = 1;

      if v_rolename is NOT NULL then
         -- Check if user's current role has select privilege on table,
         -- and hence can see the columns
         foreach
            select tabauth 
               into v_tabauth
               from informix.systabauth
               where tabid = table_id and
                     grantee = v_rolename
               if substr(v_tabauth, 1, 1) = 's' or
                  substr(v_tabauth, 1, 1) = 'S' then
                  let is_allowed = 1;
                  exit foreach;
               elif substr(v_tabauth, 3, 1) = '*' then
                  let search_columns = 1;
               end if
         end foreach

         -- Search syscolauth only if user's current role does not have select 
         -- privileges on all columns. If the user's current role has no select
         -- privileges on any column, then we need search no further.

         if is_allowed = 0 and search_columns = 1 then
            foreach
               select colauth
                  into v_colauth
                  from informix.syscolauth
                  where tabid = table_id and
                        colno = column_no and
                        grantee = v_rolename
                  if substr(v_colauth, 1, 1) = 's' or
                     substr(v_colauth, 1, 1) = 'S' then
                     let is_allowed = 1;
                     exit foreach;
                  end if
            end foreach
         end if
      end if
   end if

-- Return with no rows found if not allowed to select from
-- the column designated by (tabid,colno).

   if is_allowed = 0 then
      raise exception -272;
   end if

-- Now find the distribution rows

   foreach
      select  seqno, constr_time, mode, 
              resolution, confidence, smplsize, encdat, type
         into v_seqno, v_constr_time, v_mode, 
              v_resolution, v_confidence, v_smplsize, v_encdat, v_stattype
         from informix.sysdistrib
         where tabid = table_id and
               colno = column_no
         order by seqno
      return v_seqno, v_constr_time, v_mode, 
             v_resolution, v_confidence, v_smplsize, v_encdat, v_stattype
         with resume;
   end foreach

-- Engine will return 100 to user

end procedure;

grant execute on informix.systdist to public as informix;

{ ********************** LBAC types, casts, functions *********************** }

{ Distinct types for LBAC }
create distinct type informix.IDSSECURITYLABEL as varchar(128);
create distinct type informix.IDSELEMENTENC as char(8);
create distinct type informix.IDSCOVERINGINFO as varchar(128);

{ Drop the explicit casts created for the LBAC distinct types }
drop cast (informix.IDSSECURITYLABEL as varchar(128));
drop cast (varchar(128) as informix.IDSSECURITYLABEL);
drop cast (informix.IDSELEMENTENC as char(8));
drop cast (char(8) as informix.IDSELEMENTENC);
drop cast (informix.IDSCOVERINGINFO as varchar(128));
drop cast (varchar(128) as informix.IDSCOVERINGINFO);

{ Create the implicit casts for the LBAC distinct types }
create function informix.SeclabelInput(informix.lvarchar) 
    returns informix.IDSSECURITYLABEL
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(seclabel_in)'
    language C;
grant execute on function informix.SeclabelInput(informix.lvarchar)
    to public as informix;
create implicit cast(informix.lvarchar as informix.IDSSECURITYLABEL 
    with informix.SeclabelInput);

create function informix.SeclabelOutput(informix.IDSSECURITYLABEL) 
    returns informix.lvarchar
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(seclabel_out)'
    language C;
grant execute on function informix.SeclabelOutput(informix.IDSSECURITYLABEL)
    to public as informix;
create implicit cast(informix.IDSSECURITYLABEL as informix.lvarchar 
    with informix.SeclabelOutput);

create function informix.ElementencInput(informix.lvarchar) 
    returns informix.IDSELEMENTENC
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(elementenc_in)'
    language C;
grant execute on function informix.ElementencInput(informix.lvarchar)
    to public as informix;
create implicit cast(informix.lvarchar as informix.IDSELEMENTENC 
    with informix.ElementencInput);

create function informix.ElementencOutput(informix.IDSELEMENTENC) 
    returns informix.lvarchar
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(elementenc_out)'
    language C;
grant execute on function informix.ElementencOutput(informix.IDSELEMENTENC)
    to public as informix;
create implicit cast(informix.IDSELEMENTENC as informix.lvarchar 
    with informix.ElementencOutput);

create function informix.CoveringinfoInput(informix.lvarchar) 
    returns informix.IDSCOVERINGINFO
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(coveringinfo_in)'
    language C;
grant execute on function informix.CoveringinfoInput(informix.lvarchar)
    to public as informix;
create implicit cast(informix.lvarchar as informix.IDSCOVERINGINFO 
    with informix.CoveringinfoInput);

create function informix.CoveringinfoOutput(informix.IDSCOVERINGINFO) 
    returns informix.lvarchar
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(coveringinfo_out)'
    language C;
grant execute on function informix.CoveringinfoOutput(informix.IDSCOVERINGINFO)
    to public as informix;
create implicit cast(informix.IDSCOVERINGINFO as informix.lvarchar 
    with informix.CoveringinfoOutput);

{ LBAC SQL function SECLABEL_BY_COMP }
create function informix.SECLABEL_BY_COMP(informix.lvarchar, 
    informix.lvarchar)
    returns informix.IDSSECURITYLABEL
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(ifx_seclabel_by_comp)'
    language C;
grant execute on function informix.SECLABEL_BY_COMP(informix.lvarchar,
    informix.lvarchar) to public as informix;

{ LBAC SQL function SECLABEL_BY_NAME }
create function informix.SECLABEL_BY_NAME(informix.lvarchar, 
    informix.lvarchar)
    returns informix.IDSSECURITYLABEL
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(ifx_seclabel_by_name)'
    language C;
grant execute on function informix.SECLABEL_BY_NAME(informix.lvarchar,
    informix.lvarchar) to public as informix;

{ LBAC SQL function SECLABEL_TO_CHAR }
create function informix.SECLABEL_TO_CHAR(informix.lvarchar, 
    informix.IDSSECURITYLABEL)
    returns informix.lvarchar
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(ifx_seclabel_to_char)'
    language C;
grant execute on function informix.SECLABEL_TO_CHAR(informix.lvarchar,
    informix.IDSSECURITYLABEL) to public as informix;

{ LBAC SQL function ELEMENTENC_TO_DECIMAL }
create function informix.ELEMENTENC_TO_DECIMAL(informix.IDSELEMENTENC)
    returns informix.decimal
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE)
    external name '(ifx_elementenc_to_decimal)'
    language C;
grant execute on function informix.ELEMENTENC_TO_DECIMAL(informix.IDSELEMENTENC)
    to public as informix;

{ *************************************************************************** }

create dba function informix.extract(informix.lvarchar,informix.lvarchar)
    returns informix.lvarchar(32739)
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextract)'
    language C;

grant execute on function informix.extract(informix.lvarchar,informix.lvarchar)
to public as informix;

create dba function informix.extract(informix.clob,informix.lvarchar)
    returns informix.lvarchar(32739)
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextractinputclob)'
    language C;

grant execute on function informix.extract(informix.clob,informix.lvarchar)
to public as informix;

create dba function informix.extractclob(informix.clob,informix.lvarchar)
    returns informix.clob
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextractclob)'
    language C;

grant execute on function informix.extractclob(informix.clob,informix.lvarchar)
to public as informix;

create dba function informix.extractvalue(informix.lvarchar,informix.lvarchar)
    returns informix.lvarchar(32739)
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextractvalue)'
    language C;

grant execute on function informix.extractvalue(informix.lvarchar,informix.lvarchar)
to public as informix;

create dba function informix.extractvalue(informix.clob,informix.lvarchar)
    returns informix.lvarchar(32739)
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextractvalueinputclob)'
    language C;

grant execute on function informix.extractvalue(informix.clob,informix.lvarchar)
to public as informix;

create dba function informix.existsnode(informix.lvarchar,informix.lvarchar)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlexistnode)'
    language C;

grant execute on function informix.existsnode(informix.lvarchar,informix.lvarchar)
to public as informix;

create dba function informix.existsnode(informix.clob,informix.lvarchar)
    returns informix.integer
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlexistnodeinputclob)'
    language C;

grant execute on function informix.existsnode(informix.clob,informix.lvarchar)
to public as informix;

create dba function informix.idsxmlparse(informix.lvarchar)
    returns informix.lvarchar(32739)
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlparse)'
    language C;

grant execute on function informix.idsxmlparse(informix.lvarchar)
to public as informix;

create dba function informix.idsxmlparse(informix.clob)
    returns informix.clob
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlparseclob)'
    language C;

grant execute on function informix.idsxmlparse(informix.clob)
to public as informix;

create dba function informix.extractvalueclob(informix.clob,informix.lvarchar)
    returns informix.clob
    with (NOT VARIANT, HANDLESNULLS, PARALLELIZABLE, CLASS = 'idsxmlvp',
          PERCALL_COST = 32768 )
    external name '$INFORMIXDIR/lib/libxml.udr(xmlextractvalueclob)'
    language C;

grant execute on function informix.extractvalueclob(informix.clob,informix.lvarchar)
to public as informix;

create AGGREGATE informix.genxml
with (
      INIT = init_aggrxml,
      ITER = iter_aggrxml,
      COMBINE = comb_aggrxml,
      FINAL = final_aggrxml,
      HANDLESNULLS
      );

create dba function informix.init_aggrxml(informix.ROW, informix.lvarchar)
returns  informix.pointer
external name '(init_aggrxml)'
language C;
grant execute on function informix.init_aggrxml(informix.ROW, informix.lvarchar) to public as informix;
alter function informix.init_aggrxml (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrxml(informix.pointer, informix.ROW)
returns  informix.pointer
external name '(iter_aggrxml)'
language C;
grant execute on function informix.iter_aggrxml(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrxml (informix.pointer, informix.ROW)
        with (add handlesnulls);


create dba function informix.comb_aggrxml(informix.pointer,informix.pointer)
returns  informix.pointer
external name '(comb_aggrxml)'
language C;
grant execute on function informix.comb_aggrxml(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrxml (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrxml(informix.pointer)
returns  informix.lvarchar(32739)
external name '(final_aggrxml)'
language C;
grant execute on function informix.final_aggrxml(informix.pointer)
     to public as informix;
alter function informix.final_aggrxml (informix.pointer)
        with (add handlesnulls);


create AGGREGATE informix.genxmlelem
with (
      INIT = init_aggrelem,
      ITER = iter_aggrelem,
      COMBINE = comb_aggrelem,
      FINAL = final_aggrelem,
      HANDLESNULLS
      );
create dba function informix.init_aggrelem(informix.ROW, informix.lvarchar)
returns informix.pointer
external name '(init_aggrelem)'
language C;
grant execute on function informix.init_aggrelem(informix.ROW, informix.lvarchar)
     to public as informix;
alter function informix.init_aggrelem (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrelem(informix.pointer, informix.ROW)
returns informix.pointer
external name '(iter_aggrelem)'
language C;
grant execute on function informix.iter_aggrelem(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrelem (informix.pointer, informix.ROW)
        with (add handlesnulls);


create dba function informix.comb_aggrelem(informix.pointer,informix.pointer)
returns informix.pointer
external name '(comb_aggrelem)'
language C;
grant execute on function informix.comb_aggrelem(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrelem (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrelem(informix.pointer)
returns  informix.lvarchar(32739)
external name '(final_aggrelem)'
language C;
grant execute on function informix.final_aggrelem(informix.pointer)
     to public as informix;
alter function informix.final_aggrelem (informix.pointer)
        with (add handlesnulls);

create AGGREGATE informix.genxmlschema
with (
      INIT = init_aggrschema,
      ITER = iter_aggrschema,
      COMBINE = comb_aggrschema,
      FINAL = final_aggrschema,
      HANDLESNULLS
      );
create dba function informix.init_aggrschema(informix.ROW, informix.lvarchar)
returns informix.pointer
external name '(init_aggrschema)'
language C;
grant execute on function informix.init_aggrschema(informix.ROW, informix.lvarchar)
     to public as informix;
alter function informix.init_aggrschema (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrschema(informix.pointer, informix.ROW)
returns informix.pointer
external name '(iter_aggrschema)'
language C;
grant execute on function informix.iter_aggrschema(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrschema (informix.pointer, informix.ROW)
        with (add handlesnulls);


create dba function informix.comb_aggrschema(informix.pointer,informix.pointer)
returns informix.pointer
external name '(comb_aggrschema)'
language C;
grant execute on function informix.comb_aggrschema(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrschema (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrschema(informix.pointer)
returns  informix.lvarchar(32739)
external name '(final_aggrschema)'
language C;
grant execute on function informix.final_aggrschema(informix.pointer)
     to public as informix;
alter function informix.final_aggrschema (informix.pointer)
        with (add handlesnulls);



create dba function informix.genxmlqueryhdr(informix.LVARCHAR, informix.LVARCHAR)
returns informix.lvarchar(32739)
with(NOT VARIANT)
external name '(genxmlqueryhdr)'
language C;
grant execute on function informix.genxmlqueryhdr(informix.LVARCHAR, informix.LVARCHAR)
    to public as informix;

create dba function informix.genxmlquery(informix.LVARCHAR, informix.lvarchar)
returns informix.lvarchar(32739)
with(NOT VARIANT)
external name '(genxmlquery)'
language C;
grant execute on function informix.genxmlquery(informix.LVARCHAR, informix.lvarchar)
    to public as informix;

create AGGREGATE informix.genxmlclob
with (
      INIT = init_aggrxmlc,
      ITER = iter_aggrxmlc,
      COMBINE = comb_aggrxmlc,
      FINAL = final_aggrxmlc,
      HANDLESNULLS
      );

create dba function informix.init_aggrxmlc(informix.ROW, informix.lvarchar)
returns  informix.pointer
external name '(init_aggrxmlc)'
language C;
grant execute on function informix.init_aggrxmlc(informix.ROW, informix.lvarchar) to public as informix;
alter function informix.init_aggrxmlc (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrxmlc(informix.pointer, informix.ROW)
returns  informix.pointer
external name '(iter_aggrxmlc)'
language C;
grant execute on function informix.iter_aggrxmlc(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrxmlc (informix.pointer, informix.ROW)
        with (add handlesnulls);


create dba function informix.comb_aggrxmlc(informix.pointer,informix.pointer)
returns  informix.pointer
external name '(comb_aggrxmlc)'
language C;
grant execute on function informix.comb_aggrxmlc(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrxmlc (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrxmlc(informix.pointer)
returns  informix.clob
external name '(final_aggrxmlc)'
language C;
grant execute on function informix.final_aggrxmlc(informix.pointer)
     to public as informix;
alter function informix.final_aggrxmlc (informix.pointer)
        with (add handlesnulls);

create AGGREGATE informix.genxmlelemclob
with (
      INIT = init_aggrelemc,
      ITER = iter_aggrelemc,
      COMBINE = comb_aggrelemc,
      FINAL = final_aggrelemc,
      HANDLESNULLS
      );

create dba function informix.init_aggrelemc(informix.ROW, informix.lvarchar)
returns  informix.pointer
external name '(init_aggrelemc)'
language C;
grant execute on function informix.init_aggrelemc(informix.ROW, informix.lvarchar) to public as informix;
alter function informix.init_aggrelemc (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrelemc(informix.pointer, informix.ROW)
returns  informix.pointer
external name '(iter_aggrelemc)'
language C;
grant execute on function informix.iter_aggrelemc(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrelemc (informix.pointer, informix.ROW)
        with (add handlesnulls);
create dba function informix.comb_aggrelemc(informix.pointer,informix.pointer)
returns  informix.pointer
external name '(comb_aggrelemc)'
language C;
grant execute on function informix.comb_aggrelemc(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrelemc (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrelemc(informix.pointer)
returns  informix.clob
external name '(final_aggrelemc)'
language C;
grant execute on function informix.final_aggrelemc(informix.pointer)
     to public as informix;
alter function informix.final_aggrelemc (informix.pointer)
        with (add handlesnulls);

create AGGREGATE informix.genxmlschemaclob
with (
      INIT = init_aggrschemac,
      ITER = iter_aggrschemac,
      COMBINE = comb_aggrschemac,
      FINAL = final_aggrschemac,
      HANDLESNULLS
      );

create dba function informix.init_aggrschemac(informix.ROW, informix.lvarchar)
returns  informix.pointer
external name '(init_aggrschemac)'
language C;
grant execute on function informix.init_aggrschemac(informix.ROW, informix.lvarchar) to public as informix;
alter function informix.init_aggrschemac (informix.ROW, informix.lvarchar)
        with (add handlesnulls);


create dba function informix.iter_aggrschemac(informix.pointer, informix.ROW)
returns  informix.pointer
external name '(iter_aggrschemac)'
language C;
grant execute on function informix.iter_aggrschemac(informix.pointer, informix.ROW)
     to public as informix;
alter function informix.iter_aggrschemac (informix.pointer, informix.ROW)
        with (add handlesnulls);
create dba function informix.comb_aggrschemac(informix.pointer,informix.pointer)
returns  informix.pointer
external name '(comb_aggrschemac)'
language C;
grant execute on function informix.comb_aggrschemac(informix.pointer,informix.pointer)
     to public as informix;
alter function informix.comb_aggrschemac (informix.pointer,informix.pointer)
        with (add handlesnulls);

create dba function informix.final_aggrschemac(informix.pointer)
returns  informix.clob
external name '(final_aggrschemac)'
language C;
grant execute on function informix.final_aggrschemac(informix.pointer)
     to public as informix;
alter function informix.final_aggrschemac (informix.pointer)
        with (add handlesnulls);

create dba function informix.genxmlqueryhdrclob(informix.LVARCHAR, informix.LVARCHAR)
returns informix.clob
with(NOT VARIANT)
external name '(genxmlqueryhdrclob)'
language C;
grant execute on function informix.genxmlqueryhdrclob(informix.LVARCHAR, informix.LVARCHAR)
    to public as informix;

create dba function informix.genxmlqueryclob(informix.LVARCHAR, informix.LVARCHAR)
returns informix.clob
with(NOT VARIANT)
external name '(genxmlqueryclob)'
language C;
grant execute on function informix.genxmlqueryclob(informix.LVARCHAR, informix.LVARCHAR)
    to public as informix;

{Changing the cast from explicit to implicit for bytetoblob and texttoclob routines. defect#134359}

drop cast (byte as blob);

create implicit cast (byte as informix.blob with informix.bytetoblob);

drop cast (text as clob);

create implicit cast (text as informix.clob with informix.texttoclob);
