{ This file is the bootstrap file for DataBlade module management.									}
{ It is properly executed by issuing the following SQL command:										}
{																									}
{ create function SYSBldPrepare (CHAR(18)) returns integer											}
{ external name '$INFORMIXDIR/extend/'%SYSBLDNAME%'/ifxmngr.bld(SYSBldPrepare)' language c;			}
{																									}
{ execute function SYSBldInit('sysblderrorlog');  -- or SYSBldPrepare('') will use default table.	}
{																									}
{ 'sysblderrorlog' is an error output table.  The return value is 0 for success,					}
{ and -1 for a fatal error (note that most SQL errors should be ignored).							}
{																									}
{ Note that this is called automatically every time BladeManager									}
{ connects to a database.  Many of the commands fail the second time,								}
{ but the errors are correctly ignored by BladeManager.												}


-- Start by clearing out log table.
delete from %SYSBLDERRORLOG% where bld_id = '%SYSBLDNAME%';

-- This creates the trace entry for BladeManager error reporting.
insert into informix.systraceclasses(name) select 'blademgr' from systables where tabid = 1 and (not exists (select * from informix.systraceclasses where name = 'blademgr'));

-- Create our custom type SYSBldSQLText for use in our sysbldobjects table.

create opaque type if not exists SYSBldSQLText(
	internallength = variable,
	maxlen = 24000,
	alignment = 1
);

grant usage on type SYSBldSQLText to public;

create function if not exists SYSBldSQLTextIn (lvarchar)
returns SYSBldSQLText
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextIn)'
language c;

grant execute on function SYSBldSQLTextIn (lvarchar) to public;

create implicit cast if not exists
(
	lvarchar as SYSBldSQLText
	with  SYSBldSQLTextIn
);

create function if not exists SYSBldSQLTextOut (SYSBldSQLText)
returns lvarchar
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextIn)'
language c;

grant execute on function SYSBldSQLTextOut (SYSBldSQLText) to public;

create cast if not exists 
(
	SYSBldSQLText as lvarchar
	with  SYSBldSQLTextOut
);

create function if not exists SYSBldSQLTextSend (SYSBldSQLText)
returns sendrecv
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextOut)'
language c;

grant execute on function SYSBldSQLTextSend (SYSBldSQLText) to public;

create cast if not exists
(
	SYSBldSQLText as sendrecv
	with  SYSBldSQLTextSend
);

create function if not exists SYSBldSQLTextRecv (sendrecv)
returns SYSBldSQLText
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextIn)'
language c;

grant execute on function SYSBldSQLTextRecv (sendrecv) to public;

create implicit cast if not exists
(
	sendrecv as SYSBldSQLText
	with  SYSBldSQLTextRecv
);

create function if not exists SYSBldSQLTextImpT (impexp)
returns SYSBldSQLText
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextIn)'
language c;

grant execute on function SYSBldSQLTextImpT (impexp) to public;

create implicit cast if not exists
(
	impexp as SYSBldSQLText
	with  SYSBldSQLTextImpT
);

create function if not exists SYSBldSQLTextExpT (SYSBldSQLText)
returns impexp
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextOut)'
language c;

grant execute on function SYSBldSQLTextExpT (SYSBldSQLText) to public;

create cast if not exists
(
	SYSBldSQLText as impexp
	with  SYSBldSQLTextExpT
);

create function if not exists SYSBldSQLTextImpB (impexpbin)
returns SYSBldSQLText
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextIn)'
language c;

grant execute on function SYSBldSQLTextImpB (impexpbin) to public;

create implicit cast if not exists
(
	impexpbin as SYSBldSQLText
	with  SYSBldSQLTextImpB
);

create function if not exists SYSBldSQLTextExpB (SYSBldSQLText)
returns impexpbin
external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSQLTextOut)'
language c;

grant execute on function SYSBldSQLTextExpB (SYSBldSQLText) to public;

create cast if not exists
(
	SYSBldSQLText as impexpbin
	with  SYSBldSQLTextExpB
);


create function if not exists Equal (SYSBldSQLText,SYSBldSQLText)
returns boolean
external name '$INFORMIXDIR/extend/%SYSBLDNAME%/ifxmngr.bld(SYSBldSQLTextEqual)'
language c;

grant execute on function Equal (SYSBldSQLText,SYSBldSQLText) to public;

create function if not exists SysBldLike (SYSBldSQLText,SYSBldSQLText)
returns boolean
external name '$INFORMIXDIR/extend/%SYSBLDNAME%/ifxmngr.bld(SYSBldSQLTextLike)'
language c;

grant execute on function SysBldLike (SYSBldSQLText,SYSBldSQLText) to public;

-- This table contains the list of available DataBlade modules.
create temp table sysbldmodules
				(bld_id CHAR(64) not null primary key,
				 bld_server_type CHAR(32),
				 bld_inst_state SMALLINT
				);

-- This creates some entries for the locale, but these are not the only
-- entries uesd.
create temp table sysbldlocales
				(blocale_id CHAR(32) not null primary key
				);

insert into sysbldlocales
				values ('en_us.8859-1');

insert into sysbldlocales
				values ('en_us.819');

insert into sysbldlocales
				values ('en_us.1252');

insert into sysbldlocales
				values ('ja_jp.euc');

insert into sysbldlocales
				values ('ja_jp.sjis');

-- This lists the scripts registered by the DataBlade module.
create temp table sysbldscripts 
				(bld_id CHAR(64) not null, 
				 blocale_id CHAR(32) not null, 
				 bscr_type SMALLINT  not null, 
				 bscr_sequence SMALLINT  not null, 
				 bscr_sql_script CHAR(64) not null, 
				 bscr_old_bld CHAR(64), 
				 primary key (bld_id, blocale_id, bscr_type, bscr_sequence)
				);

-- This lists the vendor who built the DataBlade module.
create temp table sysbldvendors
				(bvendor_id CHAR(32) not null,
				 bvendor_name CHAR(32) not null,
				 blocale_id CHAR(32) not null,
				 bvendor_format SMALLINT not null,
				 bvendor_desc CHAR(255),
				 primary key (bvendor_id, blocale_id, bvendor_format)
				);

-- This is a description of the DataBlade module.
create temp table sysblddescription
				(bld_id CHAR(64) not null, 
				 blocale_id CHAR(32) not null, 
				 bdesc_format SMALLINT not null, 
				 bvendor_id CHAR(32), 
				 bdesc_desc CHAR(255), 
				 bdesc_copyright CHAR(255), 
				 primary key (bld_id, blocale_id, bdesc_format)
				);

-- This is a list of client files used by the DataBlade module.
create temp table sysbldclientfiles
				(clntfile_id CHAR(192) not null primary key,
				 clntfile_type SMALLINT not null,
				 clntfile_name CHAR(128) not null,
				 clntfile_path CHAR(128) not null,
				 clntfile_icon_text CHAR(64));

-- This is a list of known client operating systems, prep scripts may add more.
create temp table sysbldclientos
				(clntos_id CHAR(32) not null unique,
				 clntos_name CHAR(32) not null,
				 clntos_ver CHAR(32) not null,
				 clntos_arch CHAR(32) not null,
				 primary key (clntos_id, clntos_ver, clntos_arch));

insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver, clntos_arch)
				 values ('any/any/any', 'any', 'any', 'any');


insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver, clntos_arch)
				 values ('NT/3.51/x86', 'WinNT', '3.51', 'INTEL');

insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver, clntos_arch)
				 values ('NT/4.0/x86', 'WinNT', '4.0', 'INTEL');

insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver, clntos_arch)
				 values ('Win95/4.0/x86', 'Win95', '4.0', 'INTEL');

insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver, clntos_arch)
				 values ('solaris/2.5/sparc', 'solaris', '2.5', 'sparc');

insert into sysbldclientos
				(clntos_id, clntos_name, clntos_ver,clntos_arch)
				 values ('HPUX/10.01/hp','HPUX','10.01','hp');

insert into sysbldclientos
			(clntos_id, clntos_name, clntos_ver, clntos_arch)
			 values ('IRIX32/6.2/mips', 'IRIX32', '6.2', 'mips');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('PTX/4.4/Sequent', 'PTX', '4.4','Sequent');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('SCO_SV/5.0.5/i386', 'SCO_SV', '5.0.5','i386');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('SINIX/5.43/RM600','SINIX','5.43','RM600');
        
insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('SINIX/5.44/RM600','SINIX','5.44','RM600');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('AIX/4.2/ibmrs6000', 'AIX', '4.2', 'ibmrs6000');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('MP-RAS/3.01/NCR', 'MP-RAS', '3.01', 'NCR');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('HPUX/10.20/hp','HPUX','10.20','hp');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('OSF1/4.0/decalpha', 'OSF1', '4.0', 'decalpha');

insert into sysbldclientos
       (clntos_id, clntos_name, clntos_ver, clntos_arch)
        values ('dgux/4.11MU03/dgintel', 'dgux', '4.11MU03','dgintel');

-- This table contains a temporary list of error files.
create temp table sysblderrorfiles
				(bld_id CHAR(64) not null,
				 error_file varchar(255));

-- This is a relationship table between client files and the OS they run on.
create temp table sysbldclientfileos
				(bld_id CHAR(64) not null,
				 blocale_id CHAR(32) not null,
				 clntos_id CHAR(32) not null,
				 clntfile_id CHAR(192) not null,
				 primary key (bld_id, blocale_id, clntos_id, clntfile_id));

-- This is a list of interfaces available, or used by any DataBlade module.
create temp table sysbldinterfaces
				(bldi_id CHAR(64) not null,
				 bldi_name CHAR(64) not null,
				 bldi_desc CHAR(255));

-- This is a relationship table between a DataBlade module and an interface it provides.
create temp table sysbldifacprovided
				(bldi_id CHAR(64) not null,
				 bld_id CHAR(64) not null,
				 primary key (bld_id, bldi_id));

-- This is a relationship table between a DataBlade module and an interface it requires.
create temp table sysbldifacrequired
				(bldi_id CHAR(64) not null,
				 bld_id CHAR(64) not null,
				 primary key (bld_id, bldi_id));

-- This table lists possible upgrades between DataBlade modules.  The second column
-- stores a like clause for prefixs for DataBlades which a current module can upgrade.
create temp table sysbldupgrades
				(bld_id CHAR(64) not null,
				 bld_upgrade_like CHAR(64) not null);



-- These are the public SQL routines which can be used to perform DataBlade registrations.
-- All of these operations take CHAR(64) which is a DataBlade module name, or a CHAR(18)
-- which is a table to output errors (must be of a format similar to sysblderrorlog).
-- the return value of these functions is always 0 for success and -1 for failure.

-- this must already be there since we are running this script.
-- create function SYSBldPrepare(CHAR(18)) returns integer 
--				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldPrepare)' 
--				language C not variant;

-- note that upgrades and downgrades are automatically executed if appropriate.
create function if not exists SYSBldPrepare() returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldPrepare2)' 
				language C variant;

create function if not exists SYSBldRegister(CHAR(64), CHAR(18)) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldRegister)' 
				language C variant;

create function if not exists SYSBldRegister(CHAR(64)) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldRegister2)' 
				language C variant;

create function if not exists SYSBldUnregister(CHAR(64), CHAR(18)) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldUnregister)' 
				language C variant;

create function if not exists SYSBldUnregister(CHAR(64)) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldUnregister2)' 
				language C variant;

create function if not exists SYSBldTrace(CHAR(64), integer) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSetTraceFile)' 
				language C variant;

create function if not exists SYSBldTrace(integer) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldSetTraceFile2)' 
				language C variant;

create function if not exists SYSBldCleanupTables() returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldCleanupTables)' 
				language C variant;

-- These are some routines which are called only by BladeManager
create function if not exists SYSBldRelease() returns lvarchar 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(MackRelease)' 
				language C not variant;
grant execute on function SYSBldRelease() to public;

create function if not exists SYSBldGetSrvrFile(lvarchar, lvarchar) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(FetchSrvrFile)' 
				language C variant;
grant execute on function SYSBldGetSrvrFile(lvarchar, lvarchar) to public;

create function if not exists SYSBldLstBldToPrep() returns lvarchar 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(LstBldToPrep)' 
				language C variant;
grant execute on function SYSBldLstBldToPrep() to public;

create function if not exists SYSBldPrepBlade(lvarchar) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(PrepBlade)' 
				language C variant;

grant execute on function SYSBldPrepBlade(lvarchar) to public;

create function if not exists SYSBldTstSBSpace (lvarchar) returns integer
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldTstSBSpace)'
				language c variant;
grant execute on function SYSBldTstSBSpace(lvarchar) to public;

create function if not exists SYSBldTstVP (lvarchar) returns integer
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldTstVP)'
				language c variant;
grant execute on function SYSBldTstVP(lvarchar) to public;

create function if not exists SYSBldUnPrepare() returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldUnPrepare)' 
				language C variant;
grant execute on function SYSBldUnPrepare() to public;

create function if not exists SYSBldAddBldDir(lvarchar, lvarchar) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldAddBldDir)' 
				language C variant;
grant execute on function SYSBldAddBldDir(lvarchar, lvarchar) to public;

create function if not exists SYSBldPutSrvrFile(lvarchar, lvarchar) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldPutSrvrFile)' 
				language C variant;
grant execute on function SYSBldPutSrvrFile(lvarchar, lvarchar) to public;

create function if not exists SYSBldGetAnySrvrFile(lvarchar, lvarchar) returns integer 
				external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldGetAnySrvrFile)' 
				language C variant;
grant execute on function SYSBldGetAnySrvrFile(lvarchar, lvarchar) to public;

-- These are some routines which are called by DBDK Dependency Tools

create function if not exists SYSBldHTMLTableize(lvarchar,lvarchar) returns integer
	external name '$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLTableize)' language c;
grant execute on function SYSBldHTMLTableize (lvarchar,lvarchar) to public;

create function if not exists SYSBldHTMLObjDependents(lvarchar,lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLObjDependents)" language c;
grant execute on function SYSBldHTMLObjDependents (lvarchar,lvarchar) to public;

create function if not exists SYSBldHTMLObjDependencies(lvarchar,lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLObjDependencies)" language c;
grant execute on function SYSBldHTMLObjDependencies (lvarchar,lvarchar) to public;

create function if not exists SYSBldHTMLBldDependencies(lvarchar,lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLBldDependencies)" language c;
grant execute on function SYSBldHTMLBldDependencies (lvarchar,lvarchar) to public;

create function if not exists SYSBldHTMLBeginFile(lvarchar,lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLBeginFile)" language c;
grant execute on function SYSBldHTMLBeginFile (lvarchar,lvarchar) to public;

create function if not exists SYSBldHTMLEndFile(lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLEndFile)" language c;
grant execute on function SYSBldHTMLEndFile (lvarchar) to public;

create function if not exists SYSBldHTMLBldObjs(lvarchar,lvarchar) returns integer
	external name "$INFORMIXDIR/extend/%SYSBLDDIR%/ifxmngr.bld(SYSBldHTMLBldObjs)" language c;
grant execute on function SYSBldHTMLBldObjs (lvarchar,lvarchar) to public;

-- Create the "permanent" database tables, this fails if they are already there.
create table if not exists sysbldobjects
				(create_order serial8, bld_id CHAR(64) not null,
				 obj_kind integer default 0,
				 obj_signature lvarchar not null,
				 obj_owner CHAR(64) default 'informix',
				 sequence integer default 0,
				 create_sql SYSBldSQLText, create_can_fail boolean default 'f',
				 drop_sql lvarchar, drop_can_fail boolean default 'f',
				 alter_sql lvarchar, alter_can_fail boolean default 'f',
				 state char default 'U',
				 temp_state char default 'U',
				 final_state char default 'U',
				 metadata lvarchar,
				 reserved1 varchar(255),
				 reserved2 integer,
				 reserved3 integer
				);

create index if not exists sysbldobjindex on sysbldobjects (create_order);

-- create object dependency table.
create table if not exists sysbldobjdepends
				(bld_id CHAR(64) not null,
				 obj_kind integer default 0,
				 obj_signature lvarchar not null,
				 obj_owner CHAR(64) default 'informix',
				 need_obj_kind integer default 0,
				 need_obj_signature lvarchar not null,
				 need_obj_owner CHAR(64) default 'informix',
				 state char default 'U',
				 temp_state char default 'U',
				 final_state char default 'U',
				 reserved1 varchar(255),
				 reserved2 integer,
				 reserved3 integer
				);

create table if not exists sysbldobjkinds
				(obj_kind integer not null primary key,
				 description varchar (32),
				 format varchar (64)
				);

insert into sysbldobjkinds (obj_kind, description, format)
	select 0, 'unknown', '<any>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 0));
insert into sysbldobjkinds (obj_kind, description, format)
	select 1, 'error', '<code>-<locale>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 1));
insert into sysbldobjkinds (obj_kind, description, format)
	select 2, 'aggregate', '<name>(<type>)'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 2));
insert into sysbldobjkinds (obj_kind, description, format)
	select 3, 'cast', '<from_type>-><to_type>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 3));
insert into sysbldobjkinds (obj_kind, description, format)
	select 4, 'operator', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 4));
insert into sysbldobjkinds (obj_kind, description, format)
	select 5, 'function', '<name> (<arg1>[, <arg2>] ... [, <arg20>])'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 5));
insert into sysbldobjkinds (obj_kind, description, format)
	select 6, 'procedure', '<name> (<arg1>[, <arg2>] ... [, <arg20>])'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 6));
insert into sysbldobjkinds (obj_kind, description, format)
	select 7, 'type', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 7));
insert into sysbldobjkinds (obj_kind, description, format)
	select 8, 'table', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 8));
insert into sysbldobjkinds (obj_kind, description, format)
	select 9, 'access method', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 9));
insert into sysbldobjkinds (obj_kind, description, format)
	select 10, 'DataBlade module', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 10));
insert into sysbldobjkinds (obj_kind, description, format)
	select 11, 'database', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 11));
insert into sysbldobjkinds (obj_kind, description, format)
	select 12, 'operator class', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 12));
insert into sysbldobjkinds (obj_kind, description, format)
	select 13, 'index', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 13));
insert into sysbldobjkinds (obj_kind, description, format)
	select 14, 'trigger', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 14));
insert into sysbldobjkinds (obj_kind, description, format)
	select 15, 'interface', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 15));
insert into sysbldobjkinds (obj_kind, description, format)
	select 16, 'script', '<file name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 16));
insert into sysbldobjkinds (obj_kind, description, format)
	select 64, 'privilege', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 64));
insert into sysbldobjkinds (obj_kind, description, format)
	select 69, 'privilege-function', '<name> (<arg1>[, <arg2>] ... [, <arg20>])'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 69));
insert into sysbldobjkinds (obj_kind, description, format)
	select 70, 'privilege-procedure', '<name> (<arg1>[, <arg2>] ... [, <arg20>])'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 70));
insert into sysbldobjkinds (obj_kind, description, format)
	select 71, 'privilege-type', '<name>'
	  from systables
	 where tabid = 1
	   and (not exists (select obj_kind from sysbldobjkinds where obj_kind = 71));

create table if not exists sysbldregistered
				(bld_id CHAR(64) not null primary key);

create table if not exists sysbldirequired
				(bldi_id CHAR(64) not null,
				 bld_id CHAR(64) not null,
				 primary key (bld_id, bldi_id));

create table if not exists sysbldiprovided
				(bldi_id CHAR(64) not null primary key,
				 bld_id CHAR(64) not null);

-- Create old style tables, for backward compatability.
create temp table bld_modules
				(bld_id CHAR(64) not null primary key,
				 bld_server_type CHAR(32),
				 bld_inst_state SMALLINT
				);

create temp table bld_scripts 
				(bld_id CHAR(64) not null, 
				 blocale_id CHAR(32) not null, 
				 bscr_type SMALLINT  not null, 
				 bscr_sequence SMALLINT  not null, 
				 bscr_sql_script CHAR(64) not null, 
				 bscr_old_bld CHAR(64), 
				 primary key (bld_id, blocale_id, bscr_type, bscr_sequence)
				);

create temp table bld_vendors
				(bvendor_id CHAR(32) not null,
				 bvendor_name CHAR(32) not null,
				 blocale_id CHAR(32) not null,
				 bvendor_format SMALLINT not null,
				 bvendor_desc CHAR(255),
				 primary key (bvendor_id, blocale_id, bvendor_format)
				);

create temp table bld_desc 
				(bld_id CHAR(64) not null, 
				 blocale_id CHAR(32) not null, 
				 bdesc_format SMALLINT not null, 
				 bvendor_id CHAR(32), 
				 bdesc_desc CHAR(255), 
				 bdesc_copyright CHAR(255), 
				 primary key (bld_id, blocale_id, bdesc_format)
				);

create temp table client_files
				(clntfile_id CHAR(64) not null primary key,
				 clntfile_type SMALLINT not null,
				 clntfile_name CHAR(32) not null,
				 clntfile_path CHAR(64) not null,
				 clntfile_icon_text CHAR(64));

create temp table clntfile_os_rel
				(bld_id CHAR(64) not null,
				 blocale_id CHAR(32) not null,
				 clntos_id CHAR(32) not null,
				 clntfile_id CHAR(64) not null,
				 primary key (bld_id, blocale_id, clntos_id, clntfile_id));

create temp table bld_interfaces
				(bldi_id CHAR(64) not null,
				 bldi_name CHAR(64) not null,
				 bldi_desc CHAR(255));

create temp table dbi_provided
				(bldi_id CHAR(64) not null,
				 bld_id CHAR(64) not null,
				 primary key (bld_id, bldi_id));

create temp table dbi_required
				(bldi_id CHAR(64) not null,
				 bld_id CHAR(64) not null,
				 primary key (bld_id, bldi_id));
