File packages/acs-kernel/sql/postgresql/postgresql.sql
File packages/acs-kernel/sql/postgresql/lob.sql
[PG]
create sequence lob_sequence
[MSSQL]
CREATE TABLE lob_sequence ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC lob_sequence__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO lob_sequence VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create table lobs (

	lob_id			integer not null primary key,

	refcount		integer not null default 0

)
[MSSQL]
create table lobs ( lob_id			integer not null primary key,

	refcount		integer not null default 0

)

GO


 
[PG]
create function on_lobs_delete() returns opaque as '

begin

	delete from lob_data where lob_id = old.lob_id;

	return old;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger lobs_delete_trig before delete on lobs

for each row execute procedure on_lobs_delete()
[MSSQL]
/* Skipped */

 
[PG]
create table lob_data (

	lob_id			integer not null references lobs,

	segment			integer not null,

	byte_len		integer not null,

	data			bytea not null,

	primary key (lob_id, segment)

)
[MSSQL]
create table lob_data ( lob_id			integer not null references lobs,

	segment			integer not null,

	byte_len		integer not null,

	data			image not null,

	primary key (lob_id, segment)

)




 
[PG]
create index lob_data_index on lob_data(lob_id)
[MSSQL]
create index lob_data_index on lob_data(lob_id)

 
[PG]
create function on_lob_ref() returns opaque as '

begin

	if TG_OP = 'UPDATE' then

		if new.lob = old.lob then

			return new;

		end if;

	end if;



	if TG_OP = 'INSERT' or TG_OP = 'UPDATE' then

		if new.lob is not null then

			insert into lobs select new.lob, 0

				where 0 = (select count(*) from lobs where lob_id = new.lob);

			update lobs set refcount = refcount + 1 where lob_id = new.lob;

		end if;

	end if;



	if TG_OP <> 'INSERT' then

		if old.lob is not null then

			update lobs set refcount = refcount - 1 where lob_id = old.lob;

			delete from lobs where lob_id = old.lob and refcount = 0;

		end if;

	end if;



	if TG_OP = 'INSERT' or TG_OP = 'UPDATE' then return new;

	else return old;

	end if;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function empty_lob() returns integer as '

begin

	return nextval('lob_sequence');

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function lob_get_data(integer) returns text as '

declare

        lob_id  integer;

        v_rec   record;

        v_data  text default '';

begin

        for v_rec in select data, segment from lob_data order by segment;

            v_data := v_data + v_rec.data;

        end if;



        return v_data;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function lob_copy(integer, integer) returns integer as '

declare

        from_id         alias for $1;

        to_id           alias for $2;

begin

        insert into lobs (lob_id,refcount) values (to_id,0);



        insert into lob_data

             select to_id as lob_id, segment, byte_len, data

               from lob_data

              where lob_id = from_id;



        return null;



end;' language 'plpgsql'
[MSSQL]
CREATE PROC lob_copy

	@from_id		integer,

	@to_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into lobs ( lob_id, refcount ) values ( @to_id  , 0   )

   

  insert into lob_data 

  select  @to_id  as lob_id, segment  , byte_len  , data   

     

    from lob_data  

     WHERE lob_id  = @from_id  

     

     

   

  SET @ms_return_value = null  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function lob_length(integer) returns integer as '

declare

        id  alias for $1;

begin

        return sum(byte_len) from lob_data where lob_id = id;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-logs-create.sql
[PG]
create sequence t_acs_log_id_seq
[MSSQL]
CREATE TABLE t_acs_log_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC acs_log_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_acs_log_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view acs_log_id_seq as

select nextval('t_acs_log_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create table acs_logs (

	log_id		integer

			constraint acs_logs_pk

			primary key,

	log_date	timestamp default now() not null,

	log_level	varchar(20) not null

			constraint acs_logs_log_level_ck

			check (log_level in ('notice', 'warn', 'error',

					     'debug')),

	log_key		varchar(100) not null,

	message		text not null

)
[MSSQL]
create table acs_logs ( log_id		integer

			constraint acs_logs_pk

			primary key,

	log_date	datetime default getdate() not null,

	log_level	varchar(20) not null

			constraint acs_logs_log_level_ck

			check (log_level in ('notice', 'warn', 'error',

					     'debug')),

	log_key		varchar(100) not null,

	message		text not null

)

GO


 
[PG]
create function acs_log__notice (varchar,varchar)

returns integer as '

declare

  notice__log_key                alias for $1;  

  notice__message                alias for $2;  

begin

    insert into acs_logs

     (log_id, log_level, log_key, message)

    values

     (acs_log_id_seq.nextval, 'notice', notice__log_key, notice__message);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_log__notice

	@notice__log_key		varchar(8000),

	@notice__message		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int



exec acs_log_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  insert into acs_logs ( log_id, log_level, log_key, message ) values ( @retval  , 'notice'  , @notice__log_key  , @notice__message   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_log__warn (varchar,varchar)

returns integer as '

declare

  warn__log_key                alias for $1;  

  warn__message                alias for $2;  

begin

    insert into acs_logs

     (log_id, log_level, log_key, message)

    values

     (acs_log_id_seq.nextval, 'warn', warn__log_key, warn__message);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_log__warn

	@warn__log_key		varchar(8000),

	@warn__message		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int



exec acs_log_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  insert into acs_logs ( log_id, log_level, log_key, message ) values ( @retval  , 'warn'  , @warn__log_key  , @warn__message   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_log__error (varchar,varchar)

returns integer as '

declare

  error__log_key                alias for $1;  

  error__message                alias for $2;  

begin

    insert into acs_logs

     (log_id, log_level, log_key, message)

    values

     (acs_log_id_seq.nextval, 'error', error__log_key, error__message);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_log__error

	@error__log_key		varchar(8000),

	@error__message		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int



exec acs_log_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  insert into acs_logs ( log_id, log_level, log_key, message ) values ( @retval  , 'error'  , @error__log_key  , @error__message   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_log__debug (varchar,varchar)

returns integer as '

declare

  debug__log_key                alias for $1;  

  debug__message                alias for $2;  

begin

    insert into acs_logs

     (log_id, log_level, log_key, message)

    values

     (acs_log_id_seq.nextval, 'debug', debug__log_key, debug__message);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_log__debug

	@debug__log_key		varchar(8000),

	@debug__message		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int



exec acs_log_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  insert into acs_logs ( log_id, log_level, log_key, message ) values ( @retval  , 'debug'  , @debug__log_key  , @debug__message   )

   RETURN 0

  

END -- stored proc


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-metadata-create.sql
[PG]
create table acs_object_types (

	object_type	varchar(100) not null

			constraint acs_object_types_pk primary key,

	supertype	varchar(100) constraint acs_object_types_supertype_fk

			references acs_object_types (object_type),

	abstract_p	boolean default 'f' not null,

	pretty_name	varchar(100) not null

			constraint acs_obj_types_pretty_name_un

			unique,

	pretty_plural	varchar(100) not null

			constraint acs_obj_types_pretty_plural_un

			unique,

	table_name	varchar(30) not null

			constraint acs_object_types_tbl_name_un unique,

	id_column	varchar(30) not null,

	package_name	varchar(30) not null

			constraint acs_object_types_pkg_name_un unique,

	name_method	varchar(30),

	type_extension_table varchar(30),

        dynamic_p       boolean default 'f',

        tree_sortkey    varchar(4000)

)
[MSSQL]
create table acs_object_types ( object_type	varchar(100) not null

			constraint acs_object_types_pk primary key,

	supertype	varchar(100) constraint acs_object_types_supertype_fk

			references acs_object_types (object_type),

	abstract_p	boolean default 'f' not null,

	pretty_name	varchar(100) not null

			constraint acs_obj_types_pretty_name_un

			unique,

	pretty_plural	varchar(100) not null

			constraint acs_obj_types_pretty_plural_un

			unique,

	table_name	varchar(30) not null

			constraint acs_object_types_tbl_name_un unique,

	id_column	varchar(30) not null,

	package_name	varchar(30) not null

			constraint acs_object_types_pkg_name_un unique,

	name_method	varchar(30),

	type_extension_table varchar(30),

        dynamic_p       boolean default 'f',

        tree_sortkey    varchar(4000)

)

GO


 
[PG]
create index acs_obj_types_supertype_idx on acs_object_types (supertype)
[MSSQL]
create index acs_obj_types_supertype_idx on acs_object_types (supertype)

 
[PG]
create index acs_obj_types_tree_skey_idx on acs_object_types (tree_sortkey)
[MSSQL]
create index acs_obj_types_tree_skey_idx on acs_object_types (tree_sortkey)

 
[PG]
create function acs_object_type_insert_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

begin

        select max(tree_sortkey) into max_key 

          from acs_object_types 

         where supertype = new.supertype;



        select coalesce(max(tree_sortkey),'') into v_parent_sk 

          from acs_object_types 

         where object_type = new.supertype;



        new.tree_sortkey := v_parent_sk + '/' + tree_next_key(max_key);



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_object_type_insert_tr before insert 

on acs_object_types for each row 

execute procedure acs_object_type_insert_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object_type_update_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

        v_rec           record;

        clr_keys_p      boolean default 't';

begin

        if new.object_type = old.object_type and 

           ((new.supertype = old.supertype) or 

            (new.supertype is null and old.supertype is null)) then



           return new;



        end if;



        for v_rec in select object_type

                       from acs_object_types 

                      where tree_sortkey like new.tree_sortkey + '%'

                   order by tree_sortkey

        LOOP

            if clr_keys_p then

               update acs_object_types set tree_sortkey = null

               where tree_sortkey like new.tree_sortkey + '%';

               clr_keys_p := 'f';

            end if;

            

            select max(tree_sortkey) into max_key

              from acs_object_types 

              where supertype = (select supertype 

                                   from acs_object_types 

                                  where object_type = v_rec.object_type);



            select coalesce(max(tree_sortkey),'') into v_parent_sk 

              from acs_object_types 

             where object_type = (select supertype 

                                   from acs_object_types 

                                  where object_type = v_rec.object_type);



            update acs_object_types 

               set tree_sortkey = v_parent_sk + '/' + tree_next_key(max_key)

             where object_type = v_rec.object_type;



        end LOOP;



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_object_type_update_tr after update 

on acs_object_types

for each row 

execute procedure acs_object_type_update_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create view acs_object_type_supertype_map

as select ot1.object_type, ot2.object_type as ancestor_type

     from acs_object_types ot1,

	  acs_object_types ot2

    where ot1.object_type <> ot2.object_type

      and ot2.tree_sortkey <= ot1.tree_sortkey

      and ot1.tree_sortkey like (ot2.tree_sortkey + '%')
[MSSQL]
create view acs_object_type_supertype_map as 

select  ot1.object_type  , ot2.object_type  as ancestor_type 

   

  from acs_object_types ot1,

	acs_object_types ot2 

   WHERE ot1.object_type  <> ot2.object_type  and ot2.tree_sortkey  <= ot1.tree_sortkey  and ot1.tree_sortkey  like ( ot2.tree_sortkey  + '%'  ) 

   

   

 
[PG]
create table acs_object_type_tables (

	object_type	varchar(100) not null 

                        constraint acs_obj_type_tbls_obj_type_fk

			references acs_object_types (object_type),

	table_name	varchar(30) not null,

	id_column	varchar(30),

	constraint acs_object_type_tables_pk

	primary key (object_type, table_name)

)
[MSSQL]
create table acs_object_type_tables ( object_type	varchar(100) not null 

                        constraint acs_obj_type_tbls_obj_type_fk

			references acs_object_types (object_type),

	table_name	varchar(30) not null,

	id_column	varchar(30),

	constraint acs_object_type_tables_pk

	primary key (object_type, table_name)

)

GO


 
[PG]
create index acs_objtype_tbls_objtype_idx on acs_object_type_tables (object_type)
[MSSQL]
create index acs_objtype_tbls_objtype_idx on acs_object_type_tables (object_type)

 
[PG]
create table acs_datatypes (

	datatype	varchar(50) not null

			constraint acs_datatypes_pk primary key,

	max_n_values	integer default 1

			constraint acs_datatypes_max_n_ck

			check (max_n_values > 0)

)
[MSSQL]
create table acs_datatypes ( datatype	varchar(50) not null

			constraint acs_datatypes_pk primary key,

	max_n_values	integer default 1

			constraint acs_datatypes_max_n_ck

			check (max_n_values > 0)

)

GO


 
[PG]
create function inline_0 ()

returns integer as '

begin

 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('string', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('boolean', 1);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('number', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('integer', 1);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('money', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('date', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('timestamp', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('time_of_day', null);



 insert into acs_datatypes

  (datatype, max_n_values)

 values

  ('enumeration', null);





  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_datatypes ( datatype, max_n_values ) values ( 'string'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'boolean'  , 1   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'number'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'integer'  , 1   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'money'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'date'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'timestamp'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'time_of_day'  , null   )

   

  insert into acs_datatypes ( datatype, max_n_values ) values ( 'enumeration'  , null   )

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create sequence t_acs_attribute_id_seq
[MSSQL]
CREATE TABLE t_acs_attribute_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC acs_attribute_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_acs_attribute_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view acs_attribute_id_seq as

select nextval('t_acs_attribute_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create table acs_attributes (

	attribute_id	integer not null

			constraint acs_attributes_pk

			primary key,

	object_type	varchar(100) not null

			constraint acs_attributes_object_type_fk

			references acs_object_types (object_type),

	table_name	varchar(30),

	constraint acs_attrs_obj_type_tbl_name_fk

	foreign key (object_type, table_name) 

        references acs_object_type_tables,

	attribute_name	varchar(100) not null,

	pretty_name	varchar(100) not null,

	pretty_plural	varchar(100),

	sort_order	integer not null,

	datatype	varchar(50) not null

			constraint acs_attributes_datatype_fk

			references acs_datatypes (datatype),

	default_value	text,

	min_n_values	integer default 1 not null

			constraint acs_attributes_min_n_ck

			check (min_n_values >= 0),

	max_n_values	integer default 1 not null

			constraint acs_attributes_max_n_ck

			check (max_n_values >= 0),

	storage 	varchar(13) default 'type_specific'

			constraint acs_attributes_storage_ck

			check (storage in ('type_specific',

					   'generic')),

        static_p        boolean default 'f',

	column_name	varchar(30),

	constraint acs_attributes_attr_name_un

	unique (attribute_name, object_type),

	constraint acs_attributes_pretty_name_un

	unique (pretty_name, object_type),

	constraint acs_attributes_sort_order_un

	unique (attribute_id, sort_order),

	constraint acs_attributes_n_values_ck

	check (min_n_values <= max_n_values)

)
[MSSQL]
create table acs_attributes ( attribute_id	integer not null

			constraint acs_attributes_pk

			primary key,

	object_type	varchar(100) not null

			constraint acs_attributes_object_type_fk

			references acs_object_types (object_type),

	table_name	varchar(30),

	constraint acs_attrs_obj_type_tbl_name_fk

	foreign key (object_type, table_name) 

        references acs_object_type_tables,

	attribute_name	varchar(100) not null,

	pretty_name	varchar(100) not null,

	pretty_plural	varchar(100),

	sort_order	integer not null,

	datatype	varchar(50) not null

			constraint acs_attributes_datatype_fk

			references acs_datatypes (datatype),

	default_value	text,

	min_n_values	integer default 1 not null

			constraint acs_attributes_min_n_ck

			check (min_n_values >= 0),

	max_n_values	integer default 1 not null

			constraint acs_attributes_max_n_ck

			check (max_n_values >= 0),

	storage 	varchar(13) default 'type_specific'

			constraint acs_attributes_storage_ck

			check (storage in ('type_specific',

					   'generic')),

        static_p        boolean default 'f',

	column_name	varchar(30),

	constraint acs_attributes_attr_name_un

	unique (attribute_name, object_type),

	constraint acs_attributes_pretty_name_un

	unique (pretty_name, object_type),

	constraint acs_attributes_sort_order_un

	unique (attribute_id, sort_order),

	constraint acs_attributes_n_values_ck

	check (min_n_values <= max_n_values)

)

GO


 
[PG]
create index acs_attrs_obj_type_idx on acs_attributes (object_type)
[MSSQL]
create index acs_attrs_obj_type_idx on acs_attributes (object_type)

GO

create unique index acs_attrs_obj_type_attr_name_idx on acs_attributes (object_type, attribute_name)


 
[PG]
create index acs_attrs_tbl_name_idx on acs_attributes (table_name)
[MSSQL]
create index acs_attrs_tbl_name_idx on acs_attributes (table_name)

 
[PG]
create index acs_attrs_datatype_idx on acs_attributes (datatype)
[MSSQL]
create index acs_attrs_datatype_idx on acs_attributes (datatype)

 
[PG]
create table acs_enum_values (

	attribute_id	integer not null

			constraint asc_enum_values_attr_id_fk

			references acs_attributes (attribute_id),

	enum_value	varchar(1000),

	pretty_name	varchar(100) not null,

	sort_order	integer not null,

	constraint acs_enum_values_pk

	primary key (attribute_id, enum_value),

	constraint acs_enum_values_pretty_name_un

	unique (attribute_id, pretty_name),

	constraint acs_enum_values_sort_order_un

	unique (attribute_id, sort_order)

)
[MSSQL]
create table acs_enum_values ( attribute_id	integer not null

			constraint asc_enum_values_attr_id_fk

			references acs_attributes (attribute_id),

	enum_value	varchar(1000),

	pretty_name	varchar(100) not null,

	sort_order	integer not null,

	constraint acs_enum_values_pk

	primary key (attribute_id, enum_value),

	constraint acs_enum_values_pretty_name_un

	unique (attribute_id, pretty_name),

	constraint acs_enum_values_sort_order_un

	unique (attribute_id, sort_order)

)

GO


 
[PG]
create index acs_enum_values_attr_id_idx on acs_enum_values (attribute_id)
[MSSQL]
create index acs_enum_values_attr_id_idx on acs_enum_values (attribute_id)

 
[PG]
create table acs_attribute_descriptions (

	object_type	varchar(100) not null constraint acs_attr_descs_obj_type_fk

			references acs_object_types (object_type),

	attribute_name  varchar(100) not null,

	constraint acs_attr_descs_ob_tp_at_na_fk

	foreign key (object_type, attribute_name)

	references acs_attributes (object_type, attribute_name),

	description_key varchar(100),

	constraint acs_attribute_descriptions_pk

	primary key (object_type, attribute_name, description_key),

	description	text not null

)
[MSSQL]
create table acs_attribute_descriptions ( object_type	varchar(100) not null constraint acs_attr_descs_obj_type_fk

			references acs_object_types (object_type),

	attribute_name  varchar(100) not null,

	constraint acs_attr_descs_ob_tp_at_na_fk

	foreign key (object_type, attribute_name)

	references acs_attributes (object_type, attribute_name),

	description_key varchar(100),

	constraint acs_attribute_descriptions_pk

	primary key (object_type, attribute_name, description_key),

	description	text not null

)

GO


 
[PG]
create index acs_attr_desc_obj_type_idx on acs_attribute_descriptions (object_type)
[MSSQL]
create index acs_attr_desc_obj_type_idx on acs_attribute_descriptions (object_type)

 
[PG]
create index acs_attr_desc_attr_name_idx on acs_attribute_descriptions (attribute_name)
[MSSQL]
create index acs_attr_desc_attr_name_idx on acs_attribute_descriptions (attribute_name)

 
[PG]
create view acs_object_type_attributes as 

select all_types.object_type, all_types.ancestor_type, 

       attr.attribute_id, attr.table_name, attr.attribute_name, 

       attr.pretty_name, attr.pretty_plural, attr.sort_order, 

       attr.datatype, attr.default_value, attr.min_n_values, 

       attr.max_n_values, attr.storage, attr.static_p, attr.column_name

from acs_attributes attr,

     (select map.object_type, map.ancestor_type

      from acs_object_type_supertype_map map, acs_object_types t

      where map.object_type=t.object_type

      UNION ALL

      select t.object_type, t.object_type as ancestor_type

        from acs_object_types t) all_types

where attr.object_type = all_types.ancestor_type
[MSSQL]
create view acs_object_type_attributes as 

select  all_types.object_type  , all_types.ancestor_type  , attr.attribute_id  , attr.table_name  , attr.attribute_name  , attr.pretty_name  , attr.pretty_plural  , attr.sort_order  , attr.datatype  , attr.default_value  , attr.min_n_values  , attr.max_n_values  , attr.storage  , attr.static_p  , attr.column_name   

   

  from acs_attributes attr,

	( 

select  map.object_type  , map.ancestor_type   

   

  from acs_object_type_supertype_map map,

	acs_object_types t 

   WHERE map.object_type  = t.object_type  

   

   UNION ALL 

select  t.object_type  , t.object_type  as ancestor_type 

   

  from acs_object_types t 

   

   

     ) all_types 

   WHERE attr.object_type  = all_types.ancestor_type  

   

   

 
[PG]
create function acs_object_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,boolean,varchar,varchar)

returns integer as '

declare

  create_type__object_type            alias for $1;  

  create_type__pretty_name            alias for $2;  

  create_type__pretty_plural          alias for $3;  

  create_type__supertype              alias for $4;  

  create_type__table_name             alias for $5;  

  create_type__id_column              alias for $6;  

  create_type__package_name           alias for $7;  

  create_type__abstract_p             alias for $8;  

  create_type__type_extension_table   alias for $9;  

  create_type__name_method            alias for $10; 

  v_package_name acs_object_types.package_name%TYPE;

  v_name_method                       varchar;

  v_idx                               integer;

begin

    v_idx := position('.' in create_type__name_method);

    if v_idx <> 0 then

         v_name_method := substr(create_type__name_method,1,v_idx - 1) + 

                       '__' + substr(create_type__name_method, v_idx + 1);

    else 

         v_name_method := create_type__name_method;

    end if;



    if create_type__package_name is null or create_type__package_name = '' then

      v_package_name := create_type__object_type;

    else

      v_package_name := create_type__package_name;

    end if;



    insert into acs_object_types

      (object_type, pretty_name, pretty_plural, supertype, table_name,

       id_column, abstract_p, type_extension_table, package_name,

       name_method)

    values

      (create_type__object_type, create_type__pretty_name, 

       create_type__pretty_plural, create_type__supertype, 

       create_type__table_name, create_type__id_column, 

       create_type__abstract_p, create_type__type_extension_table, 

       v_package_name, v_name_method);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object_type__create_type

	@create_type__object_type		varchar(8000),

	@create_type__pretty_name		varchar(8000),

	@create_type__pretty_plural		varchar(8000),

	@create_type__supertype		varchar(8000),

	@create_type__table_name		varchar(8000),

	@create_type__id_column		varchar(8000),

	@create_type__package_name		varchar(8000),

	@create_type__abstract_p		boolean,

	@create_type__type_extension_table		varchar(8000),

	@create_type__name_method		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_package_name	varchar(8000)

declare @v_idx	integer

declare @v_name_method	varchar(8000)



SET @v_idx = charindex ( '.'  , @create_type__name_method  ) 

  

   IF @v_idx  <> 0  BEGIN

  SET @v_name_method = substring ( @create_type__name_method  , 1 , @v_idx  - 1  )  + '__'  + substring ( @create_type__name_method  , @v_idx  + 1, datalength(@create_type__name_method)    ) 

    

    END

  ELSE BEGIN

  SET @v_name_method = @create_type__name_method 

    

    

  END --IF

  

  

   IF @create_type__package_name  is null  or @create_type__package_name  = ''  BEGIN

  SET @v_package_name = @create_type__object_type 

    

    END

  ELSE BEGIN

  SET @v_package_name = @create_type__package_name 

    

    

  END --IF

  

  

   

  insert into acs_object_types ( object_type, pretty_name, pretty_plural, supertype, table_name, id_column, abstract_p, type_extension_table, package_name, name_method ) values ( @create_type__object_type  , @create_type__pretty_name  , @create_type__pretty_plural  , @create_type__supertype  , @create_type__table_name  , @create_type__id_column  , @create_type__abstract_p  , @create_type__type_extension_table  , @v_package_name  , @v_name_method   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_object_type__drop_type (varchar,boolean)

returns integer as '

declare

  drop_type__object_type            alias for $1;  

  drop_type__cascade_p              alias for $2;  

  row                               record;

begin



    

    for row in select attribute_name 

                 from acs_attributes 

                where object_type = drop_type__object_type 

    loop

       PERFORM acs_attribute__drop_attribute (drop_type__object_type, 

                                              row.attribute_name);

    end loop;



    delete from acs_attributes

    where object_type = drop_type__object_type;



    delete from acs_object_types

    where object_type = drop_type__object_type;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object_type__drop_type

	@drop_type__object_type		varchar(8000),

	@drop_type__cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @row__attribute_name  	varchar(8000)





  DECLARE cursor_1 CURSOR FOR

    

  select  attribute_name   

     

    from acs_attributes  

     WHERE object_type  = @drop_type__object_type  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__attribute_name  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.acs_attribute__drop_attribute @drop_type__object_type ,

    	@row__attribute_name  

    

  

    FETCH NEXT FROM cursor_1 INTO @row__attribute_name  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   delete from acs_attributes  WHERE object_type  = @drop_type__object_type 

   delete from acs_object_types  WHERE object_type  = @drop_type__object_type 

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_object_type__pretty_name (varchar)

returns varchar as '

declare

  pretty_name__object_type            alias for $1;  

  v_pretty_name                       acs_object_types.pretty_name%TYPE;

begin

    select t.pretty_name into v_pretty_name

      from acs_object_types t

     where t.object_type = pretty_name__object_type;



    return v_pretty_name;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_object_type__pretty_name(@pretty_name__object_type		varchar(8000)) 

RETURNS varchar

AS

BEGIN

declare @v_pretty_name	varchar(8000)





  select   @v_pretty_name = t.pretty_name   

     

    from acs_object_types t 

     WHERE t.object_type  = @pretty_name__object_type  

     

     

   RETURN CONVERT (varchar, @v_pretty_name )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_object_type__is_subtype_p (varchar,varchar)

returns boolean as '

declare

  is_subtype_p__object_type_1          alias for $1;  

  is_subtype_p__object_type_2          alias for $2;  

  v_result                             integer;       

begin

    

    

    

    

    

    



    select count(*) into v_result

     where exists (select 1 

                     from acs_object_types t 

                    where t.object_type = is_subtype_p__object_type_2

                      and tree_sortkey like

                        (select tree_sortkey + '%' 

                           from acs_object_types 

                           where object_type = is_subtype_p__object_type_1 ));



    if v_result > 0 then

       return 't';

    end if;



    return 'f';

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_object_type__is_subtype_p(@is_subtype_p__object_type_1		varchar(8000),

	@is_subtype_p__object_type_2		varchar(8000)) 

RETURNS boolean

AS

BEGIN

declare @v_result	integer





     

   IF exists ( 

  select  1   

     

    from acs_object_types t 

     WHERE t.object_type  = @is_subtype_p__object_type_2  and tree_sortkey  like ( 

  select  tree_sortkey  + '%'   

     

    from acs_object_types  

     WHERE object_type  = @is_subtype_p__object_type_1  

     

      ) 

     

      )  

     BEGIN

  RETURN 't'

    

  END --IF

  

  

   RETURN 'f'

  





END -- function


 
[PG]
create function acs_attribute__create_attribute (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,integer,varchar,boolean)

returns integer as '

declare

  create_attribute__object_type            alias for $1;  

  create_attribute__attribute_name         alias for $2;  

  create_attribute__datatype               alias for $3;  

  create_attribute__pretty_name            alias for $4;  

  create_attribute__pretty_plural          alias for $5;  

  create_attribute__table_name             alias for $6;  

  create_attribute__column_name            alias for $7;  

  create_attribute__default_value          alias for $8;  

  create_attribute__min_n_values           alias for $9;  

  create_attribute__max_n_values           alias for $10; 

  create_attribute__sort_order             alias for $11; 

  create_attribute__storage                alias for $12; 

  create_attribute__static_p               alias for $13; 



  v_sort_order           acs_attributes.sort_order%TYPE;

  v_attribute_id         acs_attributes.attribute_id%TYPE;

begin

    if create_attribute__sort_order is null then

      select coalesce(max(sort_order), 1) into v_sort_order

      from acs_attributes

      where object_type = create_attribute__object_type

      and attribute_name = create_attribute__attribute_name;

    else

      v_sort_order := create_attribute__sort_order;

    end if;



    select acs_attribute_id_seq.nextval into v_attribute_id;



    insert into acs_attributes

      (attribute_id, object_type, table_name, column_name, attribute_name,

       pretty_name, pretty_plural, sort_order, datatype, default_value,

       min_n_values, max_n_values, storage, static_p)

    values

      (v_attribute_id, create_attribute__object_type, 

       create_attribute__table_name, create_attribute__column_name, 

       create_attribute__attribute_name, create_attribute__pretty_name,

       create_attribute__pretty_plural, v_sort_order, 

       create_attribute__datatype, create_attribute__default_value,

       create_attribute__min_n_values, create_attribute__max_n_values, 

       create_attribute__storage, create_attribute__static_p);



    return v_attribute_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_attribute__create_attribute

	@create_attribute__object_type		varchar(8000),

	@create_attribute__attribute_name		varchar(8000),

	@create_attribute__datatype		varchar(8000),

	@create_attribute__pretty_name		varchar(8000),

	@create_attribute__pretty_plural		varchar(8000),

	@create_attribute__table_name		varchar(8000),

	@create_attribute__column_name		varchar(8000),

	@create_attribute__default_value		varchar(8000),

	@create_attribute__min_n_values		integer,

	@create_attribute__max_n_values		integer,

	@create_attribute__sort_order		integer,

	@create_attribute__storage		varchar(8000),

	@create_attribute__static_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_sort_order	varchar(8000)

declare @v_attribute_id	int



IF @create_attribute__sort_order  is null  BEGIN

  

    select   @v_sort_order = coalesce ( max ( sort_order  ) ,

    	1  )   

       

      from acs_attributes  

       WHERE object_type  = @create_attribute__object_type  and attribute_name  = @create_attribute__attribute_name  

       

       

    END

  ELSE BEGIN

  SET @v_sort_order = @create_attribute__sort_order 

    

    

  END --IF

  

  

   exec acs_attribute_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  select   @v_attribute_id = @retval   

     

     

     

     

     

   

  insert into acs_attributes ( attribute_id, object_type, table_name, column_name, attribute_name, pretty_name, pretty_plural, sort_order, datatype, default_value, min_n_values, max_n_values, storage, static_p ) values ( @v_attribute_id  , @create_attribute__object_type  , @create_attribute__table_name  , @create_attribute__column_name  , @create_attribute__attribute_name  , @create_attribute__pretty_name  , @create_attribute__pretty_plural  , @v_sort_order  , @create_attribute__datatype  , @create_attribute__default_value  , @create_attribute__min_n_values  , @create_attribute__max_n_values  , @create_attribute__storage  , @create_attribute__static_p   )

   

  SET @ms_return_value = @v_attribute_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_attribute__drop_attribute (varchar,varchar)

returns integer as '

declare

  drop_attribute__object_type            alias for $1;  

  drop_attribute__attribute_name         alias for $2;  

begin

    

    delete from acs_enum_values

      where attribute_id in (select a.attribute_id 

                               from acs_attributes a 

                              where a.object_type = drop_attribute__object_type

                                and a.attribute_name = drop_attribute__attribute_name);



    delete from acs_attributes

     where object_type = drop_attribute__object_type

       and attribute_name = drop_attribute__attribute_name;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_attribute__drop_attribute

	@drop_attribute__object_type		varchar(8000),

	@drop_attribute__attribute_name		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_enum_values  WHERE attribute_id in ( 

  select  a.attribute_id   

     

    from acs_attributes a 

     WHERE a.object_type  = @drop_attribute__object_type  and a.attribute_name  = @drop_attribute__attribute_name  

     

      )

   delete from acs_attributes  WHERE object_type  = @drop_attribute__object_type  and attribute_name  = @drop_attribute__attribute_name 

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_attribute__add_description (varchar,varchar,varchar,text)

returns integer as '

declare

  add_description__object_type            alias for $1;  

  add_description__attribute_name         alias for $2;  

  add_description__description_key        alias for $3;  

  add_description__description            alias for $4;  

begin

    insert into acs_attribute_descriptions

     (object_type, attribute_name, description_key, description)

    values

     (add_description__object_type, add_description__attribute_name,

      add_description__description_key, add_description__description);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_attribute__add_description

	@add_description__object_type		varchar(8000),

	@add_description__attribute_name		varchar(8000),

	@add_description__description_key		varchar(8000),

	@add_description__description		text, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_attribute_descriptions ( object_type, attribute_name, description_key, description ) values ( @add_description__object_type  , @add_description__attribute_name  , @add_description__description_key  , @add_description__description   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_attribute__drop_description (varchar,varchar,varchar)

returns integer as '

declare

  drop_description__object_type            alias for $1;  

  drop_description__attribute_name         alias for $2;  

  drop_description__description_key        alias for $3;  

begin

    delete from acs_attribute_descriptions

    where object_type = drop_description__object_type

    and attribute_name = drop_description__attribute_name

    and description_key = drop_description__description_key;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_attribute__drop_description

	@drop_description__object_type		varchar(8000),

	@drop_description__attribute_name		varchar(8000),

	@drop_description__description_key		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_attribute_descriptions  WHERE object_type  = @drop_description__object_type  and attribute_name  = @drop_description__attribute_name  and description_key  = @drop_description__description_key 

   RETURN 0

  

END -- stored proc


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-objects-create.sql
[PG]
create function inline_0 ()

returns integer as '

declare

 attr_id acs_attributes.attribute_id%TYPE;

begin

 

 

 

 PERFORM acs_object_type__create_type (

   'acs_object',

   'Object',

   'Objects',

   null,

   'acs_objects',

   'object_id',

   'acs_object',

   'f',

   null,

   'acs_object.default_name'

   );



 attr_id := acs_attribute__create_attribute (

   'acs_object',

   'object_type',

   'string',

   'Object Type',

   'Object Types',

   null,

   null,

   null,   

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'acs_object',

   'creation_date',

   'date',

   'Created Date',

   null,

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'acs_object',

   'creation_ip',

   'string',

   'Creation IP Address',

   null,

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'acs_object',

   'last_modified',

   'date',

   'Last Modified On',

   null,

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'acs_object',

   'modifying_ip',

   'string',

   'Modifying IP Address',

   null,

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

	'acs_object',

	'creation_user',

	'integer',

	'Creation user',

	'Creation users',

	null,

	null,

	null,

	0,

	1,

	null,

	'type_specific',

	'f'

	);



 attr_id := acs_attribute__create_attribute (

	'acs_object',

	'context_id',

	'integer',

	'Context ID',

	'Context IDs',

	null,

	null,

	null,

	0,

	1,

	null,

	'type_specific',

	'f'

	);



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'acs_object' ,

  	'Object' ,

  	'Objects' ,

  	null ,

  	'acs_objects' ,

  	'object_id' ,

  	'acs_object' ,

  	'f' ,

  	null ,

  	'acs_object.default_name'  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'object_type' ,

  	'string' ,

  	'Object Type' ,

  	'Object Types' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'creation_date' ,

  	'date' ,

  	'Created Date' ,

  	null ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'creation_ip' ,

  	'string' ,

  	'Creation IP Address' ,

  	null ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'last_modified' ,

  	'date' ,

  	'Last Modified On' ,

  	null ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'modifying_ip' ,

  	'string' ,

  	'Modifying IP Address' ,

  	null ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'creation_user' ,

  	'integer' ,

  	'Creation user' ,

  	'Creation users' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'acs_object' ,

  	'context_id' ,

  	'integer' ,

  	'Context ID' ,

  	'Context IDs' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create sequence t_acs_object_id_seq
[MSSQL]
CREATE TABLE t_acs_object_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC acs_object_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_acs_object_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view acs_object_id_seq as

select nextval('t_acs_object_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create table acs_objects (

	object_id		integer not null

				constraint acs_objects_pk primary key,

	object_type		varchar(100) not null

				constraint acs_objects_object_type_fk

				references acs_object_types (object_type),

        context_id		integer constraint acs_objects_context_id_fk

				references acs_objects(object_id),

	security_inherit_p	boolean default 't' not null,

	creation_user		integer,

	creation_date		timestamp default now() not null,

	creation_ip		varchar(50),

	last_modified		timestamp default now() not null,

	modifying_user		integer,

	modifying_ip		varchar(50),

        tree_sortkey            varchar(4000),

        constraint acs_objects_context_object_un

	unique (context_id, object_id)

)
[MSSQL]
create table acs_objects ( object_id		integer not null

				constraint acs_objects_pk primary key,

	object_type		varchar(100) not null

				constraint acs_objects_object_type_fk

				references acs_object_types (object_type),

        context_id		integer constraint acs_objects_context_id_fk

				references acs_objects(object_id),

	security_inherit_p	boolean default 't' not null,

	creation_user		integer,

	creation_date		datetime default getdate() not null,

	creation_ip		varchar(50),

	last_modified		datetime default getdate() not null,

	modifying_user		integer,

	modifying_ip		varchar(50),

        tree_sortkey            varchar(4000),

        constraint acs_objects_context_object_un

	unique (context_id, object_id)

)

GO


 
[PG]
create index acs_objects_context_object_idx on

       acs_objects (context_id, object_id)
[MSSQL]
create index acs_objects_context_object_idx on

       acs_objects (context_id, object_id)

 
[PG]
create index acs_objs_tree_skey_idx on acs_objects (tree_sortkey)
[MSSQL]
create index acs_objs_tree_skey_idx on acs_objects (tree_sortkey)

 
[PG]
create index acs_objects_creation_user_idx on acs_objects (creation_user)
[MSSQL]
create index acs_objects_creation_user_idx on acs_objects (creation_user)

 
[PG]
create index acs_objects_modify_user_idx on acs_objects (modifying_user)
[MSSQL]
create index acs_objects_modify_user_idx on acs_objects (modifying_user)

 
[PG]
create index acs_objects_object_type_idx on acs_objects (object_type)
[MSSQL]
create index acs_objects_object_type_idx on acs_objects (object_type)

 
[PG]
create function acs_objects_mod_ip_insert_tr () returns opaque as '

begin

  new.modifying_ip := new.creation_ip;



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_mod_ip_insert_tr before insert on acs_objects

for each row execute procedure acs_objects_mod_ip_insert_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_objects_last_mod_update_tr () returns opaque as '

begin

  new.last_modified := now();



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_last_mod_update_tr before update on acs_objects

for each row execute procedure acs_objects_last_mod_update_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_objects_insert_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

begin

        if new.context_id is null then 

            select max(tree_sortkey) into max_key 

              from acs_objects 

             where context_id is null;



            v_parent_sk := '';

        else 

            select max(tree_sortkey) into max_key 

              from acs_objects 

             where context_id = new.context_id;



            select coalesce(max(tree_sortkey),'') into v_parent_sk 

              from acs_objects 

             where object_id = new.context_id;

        end if;





        new.tree_sortkey := v_parent_sk + '/' + tree_next_key(max_key);



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_insert_tr before insert 

on acs_objects for each row 

execute procedure acs_objects_insert_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_objects_update_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

        ctx_id          integer;

        v_rec           record;

        clr_keys_p      boolean default 't';

begin

        if new.object_id = old.object_id and 

           ((new.context_id = old.context_id) or

            (new.context_id is null and old.context_id is null)) then



           return new;



        end if;



        for v_rec in select object_id

                       from acs_objects 

                      where tree_sortkey like new.tree_sortkey + '%'

                   order by tree_sortkey

        LOOP

            if clr_keys_p then

               update acs_objects set tree_sortkey = null

               where tree_sortkey like new.tree_sortkey + '%';

               clr_keys_p := 'f';

            end if;

            

            select context_id into ctx_id

              from acs_objects 

             where object_id = v_rec.object_id;



            if ctx_id is null then 

                select max(tree_sortkey) into max_key

                  from acs_objects 

                 where context_id is null;



                v_parent_sk := '';

            else 

                select max(tree_sortkey) into max_key

                  from acs_objects 

                 where context_id = ctx_id;



                select coalesce(max(tree_sortkey),'') into v_parent_sk 

                  from acs_objects 

                 where object_id = ctx_id;

            end if;



            update acs_objects 

               set tree_sortkey = v_parent_sk + '/' + tree_next_key(max_key)

             where object_id = v_rec.object_id;



        end LOOP;



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_update_tr after update 

on acs_objects

for each row 

execute procedure acs_objects_update_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create table acs_object_context_index (

	object_id	integer not null

                        constraint acs_obj_context_idx_obj_id_fk

			references acs_objects(object_id),

	ancestor_id	integer not null

                        constraint acs_obj_context_idx_anc_id_fk

			references acs_objects(object_id),

	n_generations	integer not null

			constraint acs_obj_context_idx_n_gen_ck

			check (n_generations >= 0),

        constraint acs_object_context_index_pk

	primary key (object_id, ancestor_id)

)
[MSSQL]
create table acs_object_context_index ( object_id	integer not null

                        constraint acs_obj_context_idx_obj_id_fk

			references acs_objects(object_id),

	ancestor_id	integer not null

                        constraint acs_obj_context_idx_anc_id_fk

			references acs_objects(object_id),

	n_generations	integer not null

			constraint acs_obj_context_idx_n_gen_ck

			check (n_generations >= 0),

        constraint acs_object_context_index_pk

	primary key (object_id, ancestor_id)

)

GO


 
[PG]
create index acs_obj_ctx_idx_ancestor_idx on acs_object_context_index (ancestor_id)
[MSSQL]
create index acs_obj_ctx_idx_ancestor_idx on acs_object_context_index (ancestor_id)

 
[PG]
create view acs_object_paths

as select object_id, ancestor_id, n_generations

   from acs_object_context_index
[MSSQL]
create view acs_object_paths as 

select  object_id  , ancestor_id  , n_generations   

   

  from acs_object_context_index  

   

   

   

 
[PG]
create view acs_object_contexts

as select object_id, ancestor_id, n_generations

   from acs_object_context_index

   where object_id != ancestor_id
[MSSQL]
create view acs_object_contexts as 

select  object_id  , ancestor_id  , n_generations   

   

  from acs_object_context_index  

   WHERE object_id  != ancestor_id  

   

   

 
[PG]
create function acs_objects_context_id_in_tr () returns opaque as '

begin

  insert into acs_object_context_index

   (object_id, ancestor_id, n_generations)

  values

   (new.object_id, new.object_id, 0);



  if new.context_id is not null and new.security_inherit_p = 't' then

    insert into acs_object_context_index

     (object_id, ancestor_id, n_generations)

    select

     new.object_id as object_id, ancestor_id,

     n_generations + 1 as n_generations

    from acs_object_context_index

    where object_id = new.context_id;

  else if new.object_id != 0 then

    

    insert into acs_object_context_index

     (object_id, ancestor_id, n_generations)

    values

     (new.object_id, 0, 1);

  end if; end if;



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_context_id_in_tr after insert on acs_objects

for each row execute procedure acs_objects_context_id_in_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_objects_context_id_up_tr () returns opaque as '

declare

        pair    record;

begin

  if new.object_id = old.object_id and

     new.context_id = old.context_id and

     new.security_inherit_p = old.security_inherit_p then

    return new;

  end if;



  

  delete from acs_object_context_index

  where object_id in (select object_id

                      from acs_object_contexts

                      where ancestor_id = old.object_id)

  and ancestor_id in (select ancestor_id

		      from acs_object_contexts

		      where object_id = old.object_id);



  

  delete from acs_object_context_index

  where object_id = old.object_id;



  insert into acs_object_context_index

   (object_id, ancestor_id, n_generations)

  values

   (new.object_id, new.object_id, 0);



  if new.context_id is not null and new.security_inherit_p = 't' then

     

    for pair in select *

		 from acs_object_context_index

		 where ancestor_id = new.object_id 

    LOOP

      insert into acs_object_context_index

       (object_id, ancestor_id, n_generations)

      select

       pair.object_id, ancestor_id,

       n_generations + pair.n_generations + 1 as n_generations

      from acs_object_context_index

      where object_id = new.context_id;

    end loop;

  else if new.object_id != 0 then

    

    

    for pair in  select *

		 from acs_object_context_index

		 where ancestor_id = new.object_id 

    LOOP

      insert into acs_object_context_index

       (object_id, ancestor_id, n_generations)

      values

       (pair.object_id, 0, pair.n_generations + 1);

    end loop;

  end if; end if;



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_context_id_up_tr after update on acs_objects

for each row execute procedure acs_objects_context_id_up_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_objects_context_id_del_tr () returns opaque as '

begin

  delete from acs_object_context_index

  where object_id = old.object_id;



  return old;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_objects_context_id_del_tr before delete on acs_objects

for each row execute procedure acs_objects_context_id_del_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create sequence t_acs_attribute_value_id_seq
[MSSQL]
CREATE TABLE t_acs_attribute_value_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC acs_attribute_value_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_acs_attribute_value_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view acs_attribute_value_id_seq as

select nextval('t_acs_attribute_value_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create table acs_attribute_values (

	object_id	integer not null

			constraint acs_attr_values_obj_id_fk

			references acs_objects (object_id) on delete cascade,

	attribute_id	integer not null

			constraint acs_attr_values_attr_id_fk

			references acs_attributes (attribute_id),

	attr_value	text,

	constraint acs_attribute_values_pk primary key

	(object_id, attribute_id)

)
[MSSQL]
create table acs_attribute_values ( object_id	integer not null

			constraint acs_attr_values_obj_id_fk

			references acs_objects (object_id) ,

	attribute_id	integer not null

			constraint acs_attr_values_attr_id_fk

			references acs_attributes (attribute_id),

	attr_value	text,

	constraint acs_attribute_values_pk primary key

	(object_id, attribute_id)

)

GO


 
[PG]
create index acs_attr_values_attr_id_idx on acs_attribute_values (attribute_id)
[MSSQL]
create index acs_attr_values_attr_id_idx on acs_attribute_values (attribute_id)

 
[PG]
create table acs_static_attr_values (

	object_type	varchar(100) not null

			constraint acs_static_a_v_obj_id_fk

			references acs_object_types (object_type) on delete cascade,

	attribute_id	integer not null

			constraint acs_static_a_v_attr_id_fk

			references acs_attributes (attribute_id),

	attr_value	text,

	constraint acs_static_a_v_pk primary key

	(object_type, attribute_id)

)
[MSSQL]
create table acs_static_attr_values ( object_type	varchar(100) not null

			constraint acs_static_a_v_obj_id_fk

			references acs_object_types (object_type) ,

	attribute_id	integer not null

			constraint acs_static_a_v_attr_id_fk

			references acs_attributes (attribute_id),

	attr_value	text,

	constraint acs_static_a_v_pk primary key

	(object_type, attribute_id)

)

GO


 
[PG]
create index acs_stat_attrs_attr_id_idx on acs_static_attr_values (attribute_id)
[MSSQL]
create index acs_stat_attrs_attr_id_idx on acs_static_attr_values (attribute_id)

 
[PG]
create function acs_object__initialize_attributes (integer)

returns integer as '

declare

  initialize_attributes__object_id              alias for $1;  

  v_object_type                                 acs_objects.object_type%TYPE;

begin

   



   

   insert into acs_attribute_values

    (object_id, attribute_id, attr_value)

   select

    initialize_attributes__object_id, a.attribute_id, a.default_value

   from acs_attributes a, acs_objects o

   where a.object_type = o.object_type

   and o.object_id = initialize_attributes__object_id

   and a.storage = 'generic'

   and a.static_p = 'f';



   

   select object_type into v_object_type from acs_objects

     where object_id = initialize_attributes__object_id;



   

   

     insert into acs_static_attr_values

      (object_type, attribute_id, attr_value)

     select

      v_object_type, a.attribute_id, a.default_value

     from acs_attributes a, acs_objects o

     where a.object_type = o.object_type

       and o.object_id = initialize_attributes__object_id

       and a.storage = 'generic'

       and a.static_p = 't'

       and not exists (select 1 from acs_static_attr_values

                       where object_type = a.object_type);

   



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object__initialize_attributes

	@initialize_attributes__object_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_object_type	varchar(8000)





  insert into acs_attribute_values ( object_id, attribute_id, attr_value ) 

  select  @initialize_attributes__object_id  , a.attribute_id  , a.default_value   

     

    from acs_attributes a,

  	acs_objects o 

     WHERE a.object_type  = o.object_type  and o.object_id  = @initialize_attributes__object_id  and a.storage  = 'generic'  and a.static_p  = 'f'  

     

     

   

  select   @v_object_type = object_type   

     

    from acs_objects  

     WHERE object_id  = @initialize_attributes__object_id  

     

     

   

  insert into acs_static_attr_values ( object_type, attribute_id, attr_value ) 

  select  @v_object_type  , a.attribute_id  , a.default_value   

     

    from acs_attributes a,

  	acs_objects o 

     WHERE a.object_type  = o.object_type  and o.object_id  = @initialize_attributes__object_id  and a.storage  = 'generic'  and a.static_p  = 't'  and not exists ( 

  select  1   

     

    from acs_static_attr_values  

     WHERE object_type  = a.object_type  

     

      )  

     

     

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_object__new (integer,varchar,timestamp,integer,varchar,integer)

returns integer as '

declare

  new__object_id              alias for $1;  

  new__object_type            alias for $2;  

  new__creation_date          alias for $3;  

  new__creation_user          alias for $4;  

  new__creation_ip            alias for $5;  

  new__context_id             alias for $6;  

  v_object_id                 acs_objects.object_id%TYPE;

begin

  if new__object_id is null then

   select acs_object_id_seq.nextval

   into v_object_id from dual;

  else

    v_object_id := new__object_id;

  end if;



  insert into acs_objects

   (object_id, object_type, context_id,

    creation_date, creation_user, creation_ip)

  values

   (v_object_id, new__object_type, new__context_id,

    new__creation_date, new__creation_user, new__creation_ip);



  PERFORM acs_object__initialize_attributes(v_object_id);



  return v_object_id;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object__new

	@new__object_id		integer,

	@new__object_type		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_object_id	int

declare @retval	int



IF @new__object_id  is null  BEGIN

  exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

    select   @v_object_id = @retval   

       

        

       

       

       

    END

  ELSE BEGIN

  SET @v_object_id = @new__object_id 

    

    

  END --IF

  

  

   

  insert into acs_objects ( object_id, object_type, context_id, creation_date, creation_user, creation_ip ) values ( @v_object_id  , @new__object_type  , @new__context_id  , @new__creation_date  , @new__creation_user  , @new__creation_ip   )

   EXEC dbo.acs_object__initialize_attributes @v_object_id  

   

  SET @ms_return_value = @v_object_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_object__new (integer,varchar) returns integer as '

declare

        object_id       alias for $1; 

        object_type     alias for $2; 

begin

        return acs_object__new(object_id,object_type,now(),null,null,null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object__new_2

	@object_id		integer,

	@object_type		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.acs_object__new ( @object_id ,

  	@object_type ,

  	getdate() ,

  	null ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_object__delete (integer)

returns integer as '

declare

  delete__object_id              alias for $1;  

  obj_type                       record;

begin

  

  

  delete from acs_attribute_values where object_id = delete__object_id;



  

  

  

  

  

  



  for obj_type

  in select o2.table_name, o2.id_column

        from acs_object_types o1, acs_object_types o2

       where o1.object_type = (select object_type

                                 from acs_objects o

                                where o.object_id = delete__object_id)

         and o2.tree_sortkey <= o1.tree_sortkey

         and o1.tree_sortkey like (o2.tree_sortkey + '%') 

    order by o2.tree_sortkey desc

  loop

    



    

    

    

    



    execute 'delete from ' + obj_type.table_name +

        ' where ' + obj_type.id_column + ' =  ' + delete__object_id;

  end loop;



  return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__name (integer)

returns varchar as '

declare

  name__object_id        alias for $1;  

  object_name            varchar;  

  v_object_id            integer;

  obj_type               record;  

  obj                    record;      

begin

  

  

  

  

  

  

  

  

  

  

  



  for obj_type

  in select o2.name_method

        from acs_object_types o1, acs_object_types o2

       where o1.object_type = (select object_type

                                 from acs_objects o

                                where o.object_id = name__object_id)

         and o2.tree_sortkey <= o1.tree_sortkey

         and o1.tree_sortkey like (o2.tree_sortkey + '%') 

    order by o2.tree_sortkey desc

  loop

   if obj_type.name_method != '' and obj_type.name_method is NOT null then



    

    

    

    

    



    for obj in execute 'select ' + obj_type.name_method + '(' + name__object_id + ')::varchar as object_name' loop

        object_name := obj.object_name;

        exit;

    end loop;



    exit;

   end if;

  end loop;



  return object_name;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__default_name (integer)

returns varchar as '

declare

  default_name__object_id   alias for $1;  

  object_type_pretty_name   acs_object_types.pretty_name%TYPE;

begin

  select ot.pretty_name

  into object_type_pretty_name

  from acs_objects o, acs_object_types ot

  where o.object_id = default_name__object_id

  and o.object_type = ot.object_type;



  return object_type_pretty_name + ' ' + default_name__object_id;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__get_attribute_storage (integer,varchar)

returns text as '

declare

  object_id_in           alias for $1;  

  attribute_name_in      alias for $2;  





  v_column               varchar;  

  v_table_name           varchar;  

  v_key_sql              text;

  

  v_object_type          acs_attributes.object_type%TYPE;

  v_static               acs_attributes.static_p%TYPE;

  v_attr_id              acs_attributes.attribute_id%TYPE;

  v_storage              acs_attributes.storage%TYPE;

  v_attr_name            acs_attributes.attribute_name%TYPE;

  v_id_column            varchar(200);   

  v_sql                  text;  

  v_return               text;  

  v_rec                  record;

begin

   

   

   

   

   

   

   

   

   



   

   select

     a.attribute_id, a.static_p, a.storage, a.table_name, a.attribute_name,

     a.object_type, a.column_name, t.id_column 

   into 

     v_attr_id, v_static, v_storage, v_table_name, v_attr_name, 

     v_object_type, v_column, v_id_column

   from 

     acs_attributes a,

     (select o2.object_type, o2.id_column

       from acs_object_types o1, acs_object_types o2

      where o1.object_type = (select object_type

                                from acs_objects o

                               where o.object_id = object_id_in)

        and o2.tree_sortkey <= o1.tree_sortkey

        and o1.tree_sortkey like (o2.tree_sortkey + '%') 

     ) t

   where   

     a.attribute_name = attribute_name_in

   and

     a.object_type = t.object_type;



   if NOT FOUND then 

      raise EXCEPTION '-20000: No such attribute %::% in acs_object.get_attribute_storage.', v_object_type, attribute_name_in;

   end if;



   

   



   

   

   if v_table_name is null or v_table_name = '' then



     

     if v_storage = 'generic' then

       



       v_column := 'attr_value';



       if v_static = 'f' then

         v_table_name := 'acs_attribute_values';

         v_key_sql := '(object_id = ' + object_id_in + ' and ' +

                      'attribute_id = ' + v_attr_id + ')';

       else

         v_table_name := 'acs_static_attr_values';

         v_key_sql := '(object_type = ''' + v_object_type + ''' and ' +

                      'attribute_id = ' + v_attr_id + ')';

       end if;



     else

       

 

       if v_static = 'f' then

         select 

           table_name, id_column 

         into 

           v_table_name, v_id_column

         from 

           acs_object_types 

         where 

           object_type = v_object_type;

         if NOT FOUND then 

            raise EXCEPTION '-20000: No data found for attribute %::% in acs_object.get_attribute_storage', v_object_type, attribute_name_in;

         end if;

       else

         raise EXCEPTION '-20000: No table name specified for storage specific static attribute %::% in acs_object.get_attribute_storage.',v_object_type, attribute_name_in;

       end if;

  

     end if;

   else 

     

     

     

     select id_column into v_id_column from acs_object_type_tables

       where object_type = v_object_type 

       and table_name = v_table_name;

       if NOT FOUND then 

          raise EXCEPTION '-20000: No data found for attribute %::% in acs_object.get_attribute_storage', v_object_type, attribute_name_in;

       end if;

   end if;



   if v_column is null or v_column = '' then



     if v_storage = 'generic' then

       v_column := 'attr_value';

     else

       v_column := v_attr_name;

     end if;



   end if;



   if v_key_sql is null or v_key_sql = '' then

     if v_static = 'f' then   

       v_key_sql := v_id_column + ' = ' + object_id_in ; 

     else

       v_key_sql := v_id_column + ' = ''' + v_object_type + '''';

     end if;

   end if;



   return v_column + ',' + v_table_name + ',' + v_key_sql; 



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__get_attr_storage_column(text) 

returns text as '

declare

        v_vals  alias for $1;

        v_idx   integer;

begin

        v_idx := strpos(v_vals,',');

        if v_idx = 0 then 

           raise exception 'invalid storage format: acs_object.get_attr_storage_column';

        end if;



        return substr(v_vals,1,v_idx - 1);



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__get_attr_storage_table(text) 

returns text as '

declare

        v_vals  alias for $1;

        v_idx   integer;

        v_tmp   varchar;

begin

        v_idx := strpos(v_vals,',');

        if v_idx = 0 then 

           raise exception 'invalid storage format: acs_object.get_attr_storage_table';

        end if;

        v_tmp := substr(v_vals,v_idx + 1);

        v_idx := strpos(v_tmp,',');

        if v_idx = 0 then 

           raise exception 'invalid storage format: acs_object.get_attr_storage_table';

        end if;



        return substr(v_tmp,1,v_idx - 1);



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__get_attr_storage_sql(text) 

returns text as '

declare

        v_vals  alias for $1;

        v_idx   integer;

        v_tmp   varchar;

begin

        v_idx := strpos(v_vals, ',');

        if v_idx = 0 then 

           raise exception 'invalid storage format: acs_object.get_attr_storage_sql';

        end if;

        v_tmp := substr(v_vals, v_idx + 1);

        v_idx := strpos(v_tmp, ',');

        if v_idx = 0 then 

           raise exception 'invalid storage format: acs_object.get_attr_storage_sql';

        end if;



        return substr(v_tmp, v_idx + 1);



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__get_attribute (integer,varchar)

returns text as '

declare

  object_id_in           alias for $1;  

  attribute_name_in      alias for $2;  

  v_table_name           varchar(200);  

  v_column               varchar(200);  

  v_key_sql              text; 

  v_return               text; 

  v_storage              text;

  v_rec                  record;

begin



   v_storage := acs_object__get_attribute_storage(object_id_in, attribute_name_in);



   v_column     := acs_object__get_attr_storage_column(v_storage);

   v_table_name := acs_object__get_attr_storage_table(v_storage);

   v_key_sql    := acs_object__get_attr_storage_sql(v_storage);



   for v_rec in execute 'select ' + quote_ident(v_column) + '::text as return from ' + quote_ident(v_table_name) + ' where ' + v_key_sql

      LOOP

        v_return := v_rec.return;

        exit;

   end loop;

   if not FOUND then 

       return null;

   end if;



   return v_return;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__set_attribute (integer,varchar,varchar)

returns integer as '

declare

  object_id_in           alias for $1;  

  attribute_name_in      alias for $2;  

  value_in               alias for $3;  

  v_table_name           varchar;  

  v_column               varchar;  

  v_key_sql              text; 

  v_return               text; 

  v_storage              text;

begin



   v_storage := acs_object__get_attribute_storage(object_id_in, attribute_name_in);



   v_column     := acs_object__get_attr_storage_column(v_storage);

   v_table_name := acs_object__get_attr_storage_table(v_storage);

   v_key_sql    := acs_object__get_attr_storage_sql(v_storage);



   execute 'update ' + v_table_name + ' set ' + quote_ident(v_column) + ' = ' + quote_literal(value_in) + ' where ' + v_key_sql;



   return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__check_context_index (integer,integer,integer)

returns boolean as '

declare

  check_context_index__object_id              alias for $1;  

  check_context_index__ancestor_id            alias for $2;  

  check_context_index__n_generations          alias for $3;  

  n_rows                                      integer;       

  n_gens                                      integer;       

begin

   

   select case when count(*) = 0 then 0 else 1 end into n_rows

   from acs_object_context_index

   where object_id = check_context_index__object_id

   and ancestor_id = check_context_index__ancestor_id;



   if n_rows = 1 then

     

     select n_generations into n_gens

     from acs_object_context_index

     where object_id = check_context_index__object_id

     and ancestor_id = check_context_index__ancestor_id;



     if n_gens != check_context_index__n_generations then

       PERFORM acs_log__error('acs_object.check_representation', 

                              'Ancestor ' +

                     check_context_index__ancestor_id + ' of object ' + 

                     check_context_index__object_id +

		     ' reports being generation ' + n_gens +

		     ' when it is actually generation ' + 

                     check_context_index__n_generations +

		     '.');

       return 'f';

     else

       return 't';

     end if;

   else

     PERFORM acs_log__error('acs_object.check_representation', 

                            'Ancestor ' +

                            check_context_index__ancestor_id + 

                            ' of object ' + check_context_index__object_id 

                            + ' is missing an entry in acs_object_context_index.');

     return 'f';

   end if;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__check_object_ancestors (integer,integer,integer)

returns boolean as '

declare

  check_object_ancestors__object_id              alias for $1;  

  check_object_ancestors__ancestor_id            alias for $2;  

  check_object_ancestors__n_generations          alias for $3;  

  check_object_ancestors__context_id             acs_objects.context_id%TYPE;

  check_object_ancestors__security_inherit_p     acs_objects.security_inherit_p%TYPE;

  n_rows                                         integer;       

  n_gens                                         integer;       

  result                                         boolean;       

begin

   

   

   



   

   

   

   

   



   result := 't';



   

   

   select context_id, security_inherit_p 

   into check_object_ancestors__context_id, 

        check_object_ancestors__security_inherit_p

   from acs_objects

   where object_id = check_object_ancestors__ancestor_id;



   if check_object_ancestors__ancestor_id = 0 then

     if check_object_ancestors__context_id is null then

       result := 't';

     else

       

       PERFORM acs_log__error('acs_object.check_representation',

                     'Object 0 doesn''t have a null context_id');

       result := 'f';

     end if;

   else

     if check_object_ancestors__context_id is null or 

        check_object_ancestors__security_inherit_p = 'f' 

     THEN

       check_object_ancestors__context_id := 0;

     end if;



     if acs_object__check_context_index(check_object_ancestors__object_id, 

                                        check_object_ancestors__ancestor_id, 

                                        check_object_ancestors__n_generations) = 'f' then

       result := 'f';

     end if;



     if acs_object__check_object_ancestors(check_object_ancestors__object_id, 

                                           check_object_ancestors__context_id,

	                      check_object_ancestors__n_generations + 1) = 'f' then

       result := 'f';

     end if;

   end if;



   return result;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object__check_object_descendants (integer,integer,integer)

returns boolean as '

declare

  object_id              alias for $1;  

  descendant_id          alias for $2;  

  n_generations          alias for $3;  

  result                 boolean;     

  obj                    record;  

begin

   

   

   

   



   

   

   

   



   result := 't';



   

   

   if acs_object__check_context_index(descendant_id, object_id, n_generations) = 'f' then

     result := 'f';

   end if;



   

   

   for obj in  select *

	       from acs_objects

	       where context_id = descendant_id

	       and security_inherit_p = 't' loop

     if acs_object__check_object_descendants(object_id, obj.object_id,

       n_generations + 1) = 'f' then

       result := 'f';

     end if;

   end loop;



   return result;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_object__check_object_descendants

	@object_id		integer,

	@descendant_id		integer,

	@n_generations		integer, 

	@ms_return_value	boolean =  OUTPUT 

AS

BEGIN

declare @result	boolean

declare @obj__object_id int



SET @result = 't' 

  

   IF dbo.acs_object__check_context_index ( @descendant_id ,

  	@object_id ,

  	@n_generations  )  = 'f'  BEGIN

  SET @result = 'f' 

    

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  object_id  

     

    from acs_objects  

     WHERE context_id  = @descendant_id  and security_inherit_p  = 't'  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @obj__object_id

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.acs_object__check_object_descendants ( @object_id ,

    	@obj__object_id ,

    	@n_generations  + 1  )  = 'f'  BEGIN

    SET @result = 'f' 

      

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @obj__object_id

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  SET @ms_return_value = @result  

  RETURN @ms_return_value

  

  

END -- stored proc






 
[PG]
create function acs_object__check_path (integer,integer)

returns boolean as '

declare

  check_path__object_id              alias for $1;  

  check_path__ancestor_id            alias for $2;  

  check_path__context_id             acs_objects.context_id%TYPE;

  check_path__security_inherit_p     acs_objects.security_inherit_p%TYPE;

begin

   if check_path__object_id = check_path__ancestor_id then

     return 't';

   end if;



   select context_id, security_inherit_p 

   into check_path__context_id, check_path__security_inherit_p

   from acs_objects

   where object_id = check_path__object_id;



   

   



   if check_path__object_id = 0 and check_path__context_id is null then 

      return 'f';

   end if;



   if check_path__context_id is null or check_path__security_inherit_p = 'f' 

   then

     check_path__context_id := 0;

   end if;



   return acs_object__check_path(check_path__context_id, 

                                 check_path__ancestor_id);

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_object__check_path(@check_path__object_id		integer,

	@check_path__ancestor_id		integer) 

RETURNS boolean

AS

BEGIN

declare @check_path__context_id	int

declare @check_path__security_inherit_p	varchar(8000)



IF @check_path__object_id  = @check_path__ancestor_id  BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  select   @check_path__context_id = context_id  ,

   @check_path__security_inherit_p = security_inherit_p   

     

    from acs_objects  

     WHERE object_id  = @check_path__object_id  

     

     

   IF @check_path__object_id  = 0  and @check_path__context_id  is null  BEGIN

  RETURN 'f'

    

  END --IF

  

  

   IF @check_path__context_id  is null  or @check_path__security_inherit_p  = 'f'  BEGIN

  SET @check_path__context_id = 0 

    

    

  END --IF

  

  

   RETURN dbo.acs_object__check_path ( @check_path__context_id ,

  	@check_path__ancestor_id  )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_object__check_representation (integer)

returns boolean as '

declare

  check_representation__object_id              alias for $1;  

  result                                       boolean;       

  check_representation__object_type            acs_objects.object_type%TYPE;

  n_rows                                       integer;    

  v_rec                                        record;  

  row                                          record; 

begin

   result := 't';

   PERFORM acs_log__notice('acs_object.check_representation',

                  'Running acs_object.check_representation on object_id = ' 

                  + check_representation__object_id + '.');



   select object_type into check_representation__object_type

   from acs_objects

   where object_id = check_representation__object_id;



   PERFORM acs_log__notice('acs_object.check_representation',

                  'OBJECT STORAGE INTEGRITY TEST');



   for v_rec in  select t.object_type, t.table_name, t.id_column

             from acs_object_type_supertype_map m, acs_object_types t

	     where m.ancestor_type = t.object_type

	     and m.object_type = check_representation__object_type

	     union

	     select object_type, table_name, id_column

	     from acs_object_types

	     where object_type = check_representation__object_type 

     LOOP



        for row in execute 'select case when count(*) = 0 then 0 else 1 end as n_rows from ' + quote_ident(v_rec.table_name) + ' where ' + quote_ident(v_rec.id_column) + ' = ' + check_representation__object_id

        LOOP

            n_rows := row.n_rows;

            exit;

        end LOOP;



        if n_rows = 0 then

           result := 'f';

           PERFORM acs_log__error('acs_object.check_representation',

                     'Table ' + v_rec.table_name + 

                     ' (primary storage for ' +

		     v_rec.object_type + 

                     ') doesn''t have a row for object ' +

		     check_representation__object_id + ' of type ' + 

                     check_representation__object_type + '.');

        end if;



   end loop;



   PERFORM acs_log__notice('acs_object.check_representation',

                  'OBJECT CONTEXT INTEGRITY TEST');



   if acs_object__check_object_ancestors(check_representation__object_id, 

                                         check_representation__object_id, 0) = 'f' then

     result := 'f';

   end if;



   if acs_object__check_object_descendants(check_representation__object_id, 

                                           check_representation__object_id, 0) = 'f' then

     result := 'f';

   end if;

   for row in  select object_id, ancestor_id, n_generations

	       from acs_object_context_index

	       where object_id = check_representation__object_id

	       or ancestor_id = check_representation__object_id 

   LOOP

     if acs_object__check_path(row.object_id, row.ancestor_id) = 'f' then

       PERFORM acs_log__error('acs_object.check_representation',

		     'acs_object_context_index contains an extraneous row: '

                     + 'object_id = ' + row.object_id + 

                     ', ancestor_id = ' + row.ancestor_id + 

                     ', n_generations = ' + row.n_generations + '.');

       result := 'f';

     end if;

   end loop;



   PERFORM acs_log__notice('acs_object.check_representation',

		  'Done running acs_object.check_representation ' + 

		  'on object_id = ' + check_representation__object_id + '.');



   return result;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create table general_objects (

	object_id		integer not null

				constraint general_objects_object_id_fk

				references acs_objects (object_id)

				constraint general_objects_pk

				primary key,

	on_which_table		varchar(30) not null,

	on_what_id		integer not null,

	constraint general_objects_un

		unique (on_which_table, on_what_id)

)
[MSSQL]
create table general_objects ( object_id		integer not null

				constraint general_objects_object_id_fk

				references acs_objects (object_id)

				constraint general_objects_pk

				primary key,

	on_which_table		varchar(30) not null,

	on_what_id		integer not null,

	constraint general_objects_un

		unique (on_which_table, on_what_id)

)

GO


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-object-util.sql
[PG]
create function acs_object_util__object_type_exist_p (varchar)

returns boolean as '

declare

    p_object_type       alias for $1;

    v_exist_p           boolean := 't';

begin





    select (case when count(*)=1 then 't' else 'f' end) into v_exist_p

    from   acs_object_types 

    where  object_type = p_object_type;

 

    return v_exist_p;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object_util__get_object_type (integer)

returns varchar as '

declare

    p_object_id         alias for $1;

    v_object_type       varchar(100);

begin

    select object_type into v_object_type

    from acs_objects

    where object_id = p_object_id;



    return v_object_type;



    if not found then

        raise exception 'Invalid Object id: % ', p_object_id;

    end if;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object_util__type_ancestor_type_p (varchar,varchar)

returns boolean as '

declare

    p_object_type1      alias for $1;

    p_object_type2      alias for $2;

    v_exist_p           boolean := 'f';

    v_count             integer := 0;

begin

    v_exist_p := acs_object_util__object_type_exist_p(p_object_type1);



    if v_exist_p = 'f' then

        raise exception 'Object type % does not exist', p_object_type1;

    end if;



    v_exist_p := acs_object_util__object_type_exist_p(p_object_type2);



    if v_exist_p = 'f' then

        raise exception 'Object type % does not exist', p_object_type2;

    end if;

        

    select count(*) into v_count

    from dual 

    where p_object_type2 in (select o2.object_type

                           from acs_object_types o1, acs_object_types o2

                          where o1.object_type = p_object_type1

                            and o2.tree_sortkey <= o1.tree_sortkey

                            and o1.tree_sortkey like (o2.tree_sortkey + '%'));



    select (case when v_count=1 then 't' else 'f' end) into v_exist_p;



    return v_exist_p;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_object_util__object_ancestor_type_p (integer,varchar)

returns boolean as '

declare

    p_object_id         alias for $1;

    p_object_type       alias for $2;

    v_exist_p           boolean := 'f';

    v_object_type       varchar(100);

begin

    v_object_type := acs_object_util__get_object_type (p_object_id);



    v_exist_p := acs_object_util__type_ancestor_type_p (v_object_type, p_object_type);

    return v_exist_p;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_object_util__object_ancestor_type_p(@p_object_id		integer,

	@p_object_type		varchar(8000)) 

RETURNS boolean

AS

BEGIN

declare @v_object_type	varchar ( 100 )

declare @v_exist_p	boolean



SET @v_object_type = dbo.acs_object_util__get_object_type ( @p_object_id  ) 

  

   SET @v_exist_p = dbo.acs_object_util__type_ancestor_type_p ( @v_object_type ,

  	@p_object_type  ) 

  

   RETURN @v_exist_p

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_object_util__object_type_p (integer,varchar)

returns boolean as '

declare

    p_object_id         alias for $1;

    p_object_type       alias for $2;

    v_exist_p           boolean := 'f';

begin

    v_exist_p := acs_object_util__object_ancestor_type_p(p_object_id, p_object_type);

    return v_exist_p;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_object_util__object_type_p(@p_object_id		integer,

	@p_object_type		varchar(8000)) 

RETURNS boolean

AS

BEGIN

declare @v_exist_p	boolean



SET @v_exist_p = dbo.acs_object_util__object_ancestor_type_p ( @p_object_id ,

  	@p_object_type  ) 

  

   RETURN @v_exist_p

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-relationships-create.sql
[PG]
create table acs_rel_roles (

	role		varchar(100) not null

			constraint acs_rel_roles_pk primary key,

        pretty_name	varchar(100) not null,

        pretty_plural	varchar(100) not null

)
[MSSQL]
create table acs_rel_roles ( role		varchar(100) not null

			constraint acs_rel_roles_pk primary key,

        pretty_name	varchar(100) not null,

        pretty_plural	varchar(100) not null

)

GO


 
[PG]
create table acs_rel_types (

	rel_type	varchar(100) not null

			constraint acs_rel_types_pk primary key

			constraint acs_rel_types_rel_type_fk

			references acs_object_types(object_type),

	object_type_one	varchar(100) not null

			constraint acs_rel_types_obj_type_1_fk

			references acs_object_types (object_type),

	role_one	varchar(100) constraint acs_rel_types_role_1_fk

			references acs_rel_roles (role),

	min_n_rels_one	integer default 0 not null

			constraint acs_rel_types_min_n_1_ck

			check (min_n_rels_one >= 0),

	max_n_rels_one	integer

			constraint acs_rel_types_max_n_1_ck

			check (max_n_rels_one >= 0),

	object_type_two	varchar(100) not null

			constraint acs_rel_types_obj_type_2_fk

			references acs_object_types (object_type),

	role_two	varchar(100) constraint acs_rel_types_role_2_fk

			references acs_rel_roles (role),

	min_n_rels_two	integer default 0 not null

			constraint acs_rel_types_min_n_2_ck

			check (min_n_rels_two >= 0),

	max_n_rels_two	integer

			constraint acs_rel_types_max_n_2_ck

			check (max_n_rels_two >= 0),

	constraint acs_rel_types_n_rels_one_ck

	check (min_n_rels_one <= max_n_rels_one),

	constraint acs_rel_types_n_rels_two_ck

	check (min_n_rels_two <= max_n_rels_two)

)
[MSSQL]
create table acs_rel_types ( rel_type	varchar(100) not null

			constraint acs_rel_types_pk primary key

			constraint acs_rel_types_rel_type_fk

			references acs_object_types(object_type),

	object_type_one	varchar(100) not null

			constraint acs_rel_types_obj_type_1_fk

			references acs_object_types (object_type),

	role_one	varchar(100) constraint acs_rel_types_role_1_fk

			references acs_rel_roles (role),

	min_n_rels_one	integer default 0 not null

			constraint acs_rel_types_min_n_1_ck

			check (min_n_rels_one >= 0),

	max_n_rels_one	integer

			constraint acs_rel_types_max_n_1_ck

			check (max_n_rels_one >= 0),

	object_type_two	varchar(100) not null

			constraint acs_rel_types_obj_type_2_fk

			references acs_object_types (object_type),

	role_two	varchar(100) constraint acs_rel_types_role_2_fk

			references acs_rel_roles (role),

	min_n_rels_two	integer default 0 not null

			constraint acs_rel_types_min_n_2_ck

			check (min_n_rels_two >= 0),

	max_n_rels_two	integer

			constraint acs_rel_types_max_n_2_ck

			check (max_n_rels_two >= 0),

	constraint acs_rel_types_n_rels_one_ck

	check (min_n_rels_one <= max_n_rels_one),

	constraint acs_rel_types_n_rels_two_ck

	check (min_n_rels_two <= max_n_rels_two)

)

GO


 
[PG]
create index acs_rel_types_objtypeone_idx on acs_rel_types (object_type_one)
[MSSQL]
create index acs_rel_types_objtypeone_idx on acs_rel_types (object_type_one)

 
[PG]
create index acs_rel_types_role_one_idx on acs_rel_types (role_one)
[MSSQL]
create index acs_rel_types_role_one_idx on acs_rel_types (role_one)

 
[PG]
create index acs_rel_types_objtypetwo_idx on acs_rel_types (object_type_two)
[MSSQL]
create index acs_rel_types_objtypetwo_idx on acs_rel_types (object_type_two)

 
[PG]
create index acs_rel_types_role_two_idx on acs_rel_types (role_two)
[MSSQL]
create index acs_rel_types_role_two_idx on acs_rel_types (role_two)

 
[PG]
create function acs_rel_type__create_role (varchar,varchar,varchar)

returns integer as '

declare

  create_role__role                   alias for $1;  

  create_role__pretty_name            alias for $2;  

  create_role__pretty_plural          alias for $3;  

begin

    insert into acs_rel_roles

     (role, pretty_name, pretty_plural)

    values

     (create_role__role, coalesce(create_role__pretty_name,create_role__role), coalesce(create_role__pretty_plural,create_role__role));



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__create_role

	@create_role__role		varchar(8000),

	@create_role__pretty_name		varchar(8000),

	@create_role__pretty_plural		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_rel_roles ( role, pretty_name, pretty_plural ) values ( @create_role__role  , coalesce ( @create_role__pretty_name ,

  	@create_role__role  )  , coalesce ( @create_role__pretty_plural ,

  	@create_role__role  )   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_rel_type__create_role (varchar)

returns integer as '

declare

  create_role__role                   alias for $1;  

begin

    perform acs_rel_type__create_role(create_role__role, NULL, NULL);

    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__create_role_1

	@create_role__role		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_rel_type__create_role @create_role__role ,

  	NULL ,

  	NULL  

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_rel_type__drop_role (varchar)

returns integer as '

declare

  drop_role__role                   alias for $1;  

begin

    delete from acs_rel_roles

    where role = drop_role__role;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__drop_role

	@drop_role__role		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_rel_roles  WHERE role  = @drop_role__role 

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_rel_type__role_pretty_name (varchar)

returns varchar as '

declare

  role_pretty_name__role        alias for $1;  

  v_pretty_name                 acs_rel_roles.pretty_name%TYPE;

begin

    select r.pretty_name into v_pretty_name

      from acs_rel_roles r

     where r.role = role_pretty_name__role;



    return v_pretty_name;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_rel_type__role_pretty_name(@role_pretty_name__role		varchar(8000)) 

RETURNS varchar

AS

BEGIN

declare @v_pretty_name	varchar(8000)





  select   @v_pretty_name = r.pretty_name   

     

    from acs_rel_roles r 

     WHERE r.role  = @role_pretty_name__role  

     

     

   RETURN CONVERT (varchar, @v_pretty_name )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_rel_type__role_pretty_plural (varchar)

returns varchar as '

declare

  role_pretty_plural__role      alias for $1;  

  v_pretty_plural               acs_rel_roles.pretty_plural%TYPE;

begin

    select r.pretty_plural into v_pretty_plural

      from acs_rel_roles r

     where r.role = role_pretty_plural__role;



    return v_pretty_plural;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_rel_type__role_pretty_plural(@role_pretty_plural__role		varchar(8000)) 

RETURNS varchar

AS

BEGIN

declare @v_pretty_plural	varchar(8000)





  select   @v_pretty_plural = r.pretty_plural   

     

    from acs_rel_roles r 

     WHERE r.role  = @role_pretty_plural__role  

     

     

   RETURN CONVERT (varchar, @v_pretty_plural )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_rel_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,varchar,varchar,integer,integer)

returns integer as '

declare

  create_type__rel_type               alias for $1;  

  create_type__pretty_name            alias for $2;  

  create_type__pretty_plural          alias for $3;  

  create_type__supertype              alias for $4;  

  create_type__table_name             alias for $5;  

  create_type__id_column              alias for $6;  

  create_type__package_name           alias for $7;  

  create_type__object_type_one        alias for $8; 

  create_type__role_one               alias for $9;  

  create_type__min_n_rels_one         alias for $10; 

  create_type__max_n_rels_one         alias for $11; 

  create_type__object_type_two        alias for $12; 

  create_type__role_two               alias for $13; 

  create_type__min_n_rels_two         alias for $14; 

  create_type__max_n_rels_two         alias for $15; 



  type_extension_table acs_object_types.type_extension_table%TYPE default null;

  abstract_p   acs_object_types.abstract_p%TYPE      default 'f';

  name_method  acs_object_types.name_method%TYPE     default null;     

begin

    PERFORM acs_object_type__create_type(

      create_type__rel_type,

      create_type__pretty_name,

      create_type__pretty_plural,

      create_type__supertype,

      create_type__table_name,

      create_type__id_column,

      create_type__package_name,

      abstract_p,

      type_extension_table,

      name_method

    );



    insert into acs_rel_types

     (rel_type,

      object_type_one, role_one,

      min_n_rels_one, max_n_rels_one,

      object_type_two, role_two,

      min_n_rels_two, max_n_rels_two)

    values

     (create_type__rel_type,

      create_type__object_type_one, create_type__role_one,

      create_type__min_n_rels_one, create_type__max_n_rels_one,

      create_type__object_type_two, create_type__role_two,

      create_type__min_n_rels_two, create_type__max_n_rels_two);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__create_type

	@create_type__rel_type		varchar(8000),

	@create_type__pretty_name		varchar(8000),

	@create_type__pretty_plural		varchar(8000),

	@create_type__supertype		varchar(8000),

	@create_type__table_name		varchar(8000),

	@create_type__id_column		varchar(8000),

	@create_type__package_name		varchar(8000),

	@create_type__object_type_one		varchar(8000),

	@create_type__role_one		varchar(8000),

	@create_type__min_n_rels_one		integer,

	@create_type__max_n_rels_one		integer,

	@create_type__object_type_two		varchar(8000),

	@create_type__role_two		varchar(8000),

	@create_type__min_n_rels_two		integer,

	@create_type__max_n_rels_two		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @abstract_p	varchar(8000)

declare @type_extension_table	varchar(8000)

declare @name_method	varchar(8000)



EXEC dbo.acs_object_type__create_type @create_type__rel_type ,

  	@create_type__pretty_name ,

  	@create_type__pretty_plural ,

  	@create_type__supertype ,

  	@create_type__table_name ,

  	@create_type__id_column ,

  	@create_type__package_name ,

  	@abstract_p ,

  	@type_extension_table ,

  	@name_method  

   

  insert into acs_rel_types ( rel_type, object_type_one, role_one, min_n_rels_one, max_n_rels_one, object_type_two, role_two, min_n_rels_two, max_n_rels_two ) values ( @create_type__rel_type  , @create_type__object_type_one  , @create_type__role_one  , @create_type__min_n_rels_one  , @create_type__max_n_rels_one  , @create_type__object_type_two  , @create_type__role_two  , @create_type__min_n_rels_two  , @create_type__max_n_rels_two   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_rel_type__create_type (varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer,varchar,integer,integer)

returns integer as '

declare

  create_type__rel_type               alias for $1;  

  create_type__pretty_name            alias for $2;  

  create_type__pretty_plural          alias for $3;  

  create_type__supertype              alias for $4;  

  create_type__table_name             alias for $5;  

  create_type__id_column              alias for $6;  

  create_type__package_name           alias for $7;  

  create_type__type_extension_table   alias for $8;  

  create_type__object_type_one        alias for $9; 

  create_type__min_n_rels_one         alias for $10; 

  create_type__max_n_rels_one         alias for $11; 

  create_type__object_type_two        alias for $12; 

  create_type__min_n_rels_two         alias for $13; 

  create_type__max_n_rels_two         alias for $14; 



  abstract_p   acs_object_types.abstract_p%TYPE      default 'f';

  name_method  acs_object_types.name_method%TYPE     default null;     

  create_type__role_one  acs_rel_types.role_one%TYPE default null;           

  create_type__role_two  acs_rel_types.role_two%TYPE default null;

begin



    PERFORM acs_object_type__create_type(

      create_type__rel_type,

      create_type__pretty_name,

      create_type__pretty_plural,

      create_type__supertype,

      create_type__table_name,

      create_type__id_column,

      create_type__package_name,

      abstract_p,

      create_type__type_extension_table,

      name_method

    );



    insert into acs_rel_types

     (rel_type,

      object_type_one, role_one,

      min_n_rels_one, max_n_rels_one,

      object_type_two, role_two,

      min_n_rels_two, max_n_rels_two)

    values

     (create_type__rel_type,

      create_type__object_type_one, create_type__role_one,

      create_type__min_n_rels_one, create_type__max_n_rels_one,

      create_type__object_type_two, create_type__role_two,

      create_type__min_n_rels_two, create_type__max_n_rels_two);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__create_type_14

	@create_type__rel_type		varchar(8000),

	@create_type__pretty_name		varchar(8000),

	@create_type__pretty_plural		varchar(8000),

	@create_type__supertype		varchar(8000),

	@create_type__table_name		varchar(8000),

	@create_type__id_column		varchar(8000),

	@create_type__package_name		varchar(8000),

	@create_type__type_extension_table		varchar(8000),

	@create_type__object_type_one		varchar(8000),

	@create_type__min_n_rels_one		integer,

	@create_type__max_n_rels_one		integer,

	@create_type__object_type_two		varchar(8000),

	@create_type__min_n_rels_two		integer,

	@create_type__max_n_rels_two		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @abstract_p	varchar(8000)

declare @create_type__role_two	varchar(8000)

declare @create_type__role_one	varchar(8000)

declare @name_method	varchar(8000)



EXEC dbo.acs_object_type__create_type @create_type__rel_type ,

  	@create_type__pretty_name ,

  	@create_type__pretty_plural ,

  	@create_type__supertype ,

  	@create_type__table_name ,

  	@create_type__id_column ,

  	@create_type__package_name ,

  	@abstract_p ,

  	@create_type__type_extension_table ,

  	@name_method  

   

  insert into acs_rel_types ( rel_type, object_type_one, role_one, min_n_rels_one, max_n_rels_one, object_type_two, role_two, min_n_rels_two, max_n_rels_two ) values ( @create_type__rel_type  , @create_type__object_type_one  , @create_type__role_one  , @create_type__min_n_rels_one  , @create_type__max_n_rels_one  , @create_type__object_type_two  , @create_type__role_two  , @create_type__min_n_rels_two  , @create_type__max_n_rels_two   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_rel_type__drop_type (varchar,boolean)

returns integer as '

declare

  drop_type__rel_type               alias for $1;  

  drop_type__cascade_p              alias for $2;  

begin

    

    delete from acs_rel_types

    where rel_type = drop_type__rel_type;



    PERFORM acs_object_type__drop_type(drop_type__rel_type, 

                                       drop_type__cascade_p);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel_type__drop_type

	@drop_type__rel_type		varchar(8000),

	@drop_type__cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_rel_types  WHERE rel_type  = @drop_type__rel_type 

   EXEC dbo.acs_object_type__drop_type @drop_type__rel_type ,

  	@drop_type__cascade_p  

   RETURN 0

  

END -- stored proc


 
[PG]
select acs_rel_type__create_type (

   'relationship',

   'Relationship',

   'Relationships',

   'acs_object',

   'acs_rels',

   'rel_id',

   'acs_rel',

   'acs_rel_types',

   'acs_object',

   0,

   null::integer,

   'acs_object',

   0,

   null::integer

 )
[MSSQL]
/* Skipped */

 
[PG]
create sequence t_acs_rel_id_seq
[MSSQL]
CREATE TABLE t_acs_rel_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC acs_rel_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_acs_rel_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view acs_rel_id_seq as

select nextval('t_acs_rel_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create table acs_rels (

	rel_id		integer not null

			constraint acs_rels_rel_id_fk

			references acs_objects (object_id)

			constraint acs_rels_pk primary key,

	rel_type	varchar(100) not null

			constraint acs_rels_rel_type_fk

			references acs_rel_types (rel_type),

	object_id_one	integer not null

			constraint acs_object_rels_one_fk

			references acs_objects (object_id),

	object_id_two	integer not null

			constraint acs_object_rels_two_fk

			references acs_objects (object_id),

	constraint acs_object_rels_un unique

	(rel_type, object_id_one, object_id_two)

)
[MSSQL]
create table acs_rels ( rel_id		integer not null

			constraint acs_rels_rel_id_fk

			references acs_objects (object_id)

			constraint acs_rels_pk primary key,

	rel_type	varchar(100) not null

			constraint acs_rels_rel_type_fk

			references acs_rel_types (rel_type),

	object_id_one	integer not null

			constraint acs_object_rels_one_fk

			references acs_objects (object_id),

	object_id_two	integer not null

			constraint acs_object_rels_two_fk

			references acs_objects (object_id),

	constraint acs_object_rels_un unique

	(rel_type, object_id_one, object_id_two)

)

GO


 
[PG]
create index acs_rels_object_id_one_idx on acs_rels (object_id_one)
[MSSQL]
create index acs_rels_object_id_one_idx on acs_rels (object_id_one)

 
[PG]
create index acs_rels_object_id_two_idx on acs_rels (object_id_two)
[MSSQL]
create index acs_rels_object_id_two_idx on acs_rels (object_id_two)

 
[PG]
create function acs_rels_in_tr () returns opaque as '

declare

  dummy integer;

  target_object_type_one acs_object_types.object_type%TYPE;

  target_object_type_two acs_object_types.object_type%TYPE;

  actual_object_type_one acs_object_types.object_type%TYPE;

  actual_object_type_two acs_object_types.object_type%TYPE;

begin

    select 1 into dummy

    from acs_rel_types rt,

         acs_objects o1, 

         acs_objects o2

    where exists (select 1 

                    from acs_object_types t

                   where t.object_type = o1.object_type

                     and t.tree_sortkey 

                         like (select o.tree_sortkey + '%' 

                                 from acs_object_types o

                                where o.object_type = rt.object_type_one))

      and exists (select 1 

                    from acs_object_types t

                   where t.object_type = o2.object_type

                     and t.tree_sortkey 

                         like (select o.tree_sortkey + '%' 

                                 from acs_object_types o

                                where o.object_type = rt.object_type_two))

      and rt.rel_type = new.rel_type

      and o1.object_id = new.object_id_one

      and o2.object_id = new.object_id_two;



    if NOT FOUND then



      

      

      select rt.object_type_one, rt.object_type_two,

             o1.object_type, o2.object_type

      into target_object_type_one, target_object_type_two,

           actual_object_type_one, actual_object_type_two

      from acs_rel_types rt, acs_objects o1, acs_objects o2

      where rt.rel_type = new.rel_type

        and o1.object_id = new.object_id_one

        and o2.object_id = new.object_id_two;



      raise EXCEPTION '-20001: %  violation: Invalid object types. Object % (%) must be of type % Object % (%) must be of type %', new.rel_type, 

                                         new.object_id_one,

                                         actual_object_type_one,

                                         target_object_type_one,

                                         new.object_id_two,

                                         actual_object_type_two,

                                         target_object_type_two;



    end if;



    return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_rels_in_tr before insert or update on acs_rels

for each row execute procedure acs_rels_in_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_rel__new (integer,varchar,integer,integer,integer,integer,varchar)

returns integer as '

declare

  new__rel_id            alias for $1;  

  new__rel_type          alias for $2;  

  new__object_id_one     alias for $3;  

  new__object_id_two     alias for $4;  

  context_id             alias for $5;  

  creation_user          alias for $6;  

  creation_ip            alias for $7;  

  v_rel_id               acs_rels.rel_id%TYPE;

begin

    

    

    v_rel_id := acs_object__new (

      new__rel_id,

      new__rel_type,

      now(),

      creation_user,

      creation_ip,

      context_id

    );



    insert into acs_rels

     (rel_id, rel_type, object_id_one, object_id_two)

    values

     (v_rel_id, new__rel_type, new__object_id_one, new__object_id_two);



    return v_rel_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel__new

	@new__rel_id		integer,

	@new__rel_type		varchar(8000),

	@new__object_id_one		integer,

	@new__object_id_two		integer,

	@context_id		integer,

	@creation_user		integer,

	@creation_ip		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_rel_id	int



EXEC dbo.acs_object__new @new__rel_id ,

  	@new__rel_type ,

  	getdate ,

  	@creation_user ,

  	@creation_ip ,

  	@context_id , @ms_return_value = @v_rel_id OUTPUT

  

   

  insert into acs_rels ( rel_id, rel_type, object_id_one, object_id_two ) values ( @v_rel_id  , @new__rel_type  , @new__object_id_one  , @new__object_id_two   )

   

  SET @ms_return_value = @v_rel_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_rel__delete (integer)

returns integer as '

declare

  rel_id                 alias for $1;  

begin

    PERFORM acs_object__delete(rel_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_rel__delete

	@rel_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object__delete @rel_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create view rel_types_valid_obj_one_types as

select rt.rel_type, th.object_type

from acs_rel_types rt,

     (select object_type, ancestor_type

      from acs_object_type_supertype_map

      UNION ALL

      select object_type, object_type as ancestor_type 

      from acs_object_types) th

where rt.object_type_one = th.ancestor_type
[MSSQL]
create view rel_types_valid_obj_one_types as 

select  rt.rel_type  , th.object_type   

   

  from acs_rel_types rt,

	( 

select  object_type  , ancestor_type   

   

  from acs_object_type_supertype_map  

   

   

   UNION ALL 

select  object_type  , object_type  as ancestor_type 

   

  from acs_object_types  

   

   

     ) th 

   WHERE rt.object_type_one  = th.ancestor_type  

   

   

 
[PG]
create view rel_types_valid_obj_two_types as

select rt.rel_type, th.object_type

from acs_rel_types rt,

     (select object_type, ancestor_type

      from acs_object_type_supertype_map

      UNION ALL

      select object_type, object_type as ancestor_type 

      from acs_object_types) th

where rt.object_type_two = th.ancestor_type
[MSSQL]
create view rel_types_valid_obj_two_types as 

select  rt.rel_type  , th.object_type   

   

  from acs_rel_types rt,

	( 

select  object_type  , ancestor_type   

   

  from acs_object_type_supertype_map  

   

   

   UNION ALL 

select  object_type  , object_type  as ancestor_type 

   

  from acs_object_types  

   

   

     ) th 

   WHERE rt.object_type_two  = th.ancestor_type  

   

   

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/utilities-create.sql
[PG]
create function util__multiple_nextval (varchar,integer)

returns varchar as '

declare

  v_sequence_name        alias for $1;  

  v_count                alias for $2;  

  a_sequence_values      text default ''; 

  v_rec                  record;

begin

    for counter in 1..v_count loop

        for v_rec in EXECUTE 'select ' + quote_ident(v_sequence_name) '.nextval as a_seq_val'

        LOOP

           a_sequence_values := a_sequence_values + '','' + v_rec.a_seq_val;

          exit;

        end loop;

    end loop;



    return substr(a_sequence_values, 2);

 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function RAWTOHEX(text) returns text as '

declare

        arg     alias for $1;

begin

        raise exception 'not implemented yet: depends on java code in acs classic';

        return '';

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function util__computehash_raw(text) returns text as '

declare

        arg     alias for $1;

begin

        raise exception 'not implemented yet: depends on java code in acs classic';

        return '';

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function util__computehash (varchar) returns varchar as '

declare 

        v_value alias for $1;

	v_hashed      char(40);

begin

	select RAWTOHEX(util__computehash_raw(v_value)) into v_hashed;



	return v_hashed;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function util__logical_negation (boolean) returns boolean as '

declare

        true_or_false alias for $1;

begin

      IF true_or_false is null THEN

        return null;

      ELSE IF true_or_false = 'f' THEN

        return 't';   

      ELSE 

        return 'f';   

      END IF; END IF;

END;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION util__logical_negation(@true_or_false		boolean) 

RETURNS boolean

AS

BEGIN



IF @true_or_false  is null  BEGIN

  RETURN null

    END

  ELSE BEGIN

  IF @true_or_false  = 'f'  BEGIN

    RETURN 't'

      END

    ELSE BEGIN

    RETURN 'f'

      

    END --IF

    

    

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/community-core-create.sql
[PG]
create function inline_0 ()

returns integer as '

declare

  attr_id acs_attributes.attribute_id%TYPE;

begin

 

 

 

 PERFORM acs_object_type__create_type (

   'party',

   'Party',

   'Parties',

   'acs_object',

   'parties',

   'party_id',

   'party',

   'f',

   null,

   'party.name'

   );



 attr_id := acs_attribute__create_attribute (

	'party',

	'email',

	'string',

	'Email Address',

	'Email Addresses',

	null,

	null,

	null,

	0,

	1,

	null,

	'type_specific',

	'f'

	);



 attr_id := acs_attribute__create_attribute (

	'party',

	'url',

	'string',

	'URL',

	'URLs',

	null,

	null,

	null,

	0,

	1,

	null,

	'type_specific',

	'f'

	);



 

 

 

 attr_id := acs_object_type__create_type (

   'person',

   'Person',

   'People',

   'party',

   'persons',

   'person_id',

   'person',

   'f',

   null,

   'person.name'

   );



 attr_id := acs_attribute__create_attribute (

        'person',

        'first_names',

        'string',

        'First Names',

        'First Names',

        null,

        null,

        null,

	0,

	1,

        null,

        'type_specific',

        'f'

      );



 attr_id := acs_attribute__create_attribute (

        'person',

        'last_name',

        'string',

        'Last Name',

        'Last Names',

        null,

        null,

        null,

	0,

	1,

        null,

        'type_specific',

        'f'

      );

  

 

 

 attr_id := acs_object_type__create_type (

   'user',

   'User',

   'Users',

   'person',

   'users',

   'user_id',

   'acs_user',

   'f',

   null,

   null

   );





  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'party' ,

  	'Party' ,

  	'Parties' ,

  	'acs_object' ,

  	'parties' ,

  	'party_id' ,

  	'party' ,

  	'f' ,

  	null ,

  	'party.name'  

   EXEC dbo.acs_attribute__create_attribute 'party' ,

  	'email' ,

  	'string' ,

  	'Email Address' ,

  	'Email Addresses' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'party' ,

  	'url' ,

  	'string' ,

  	'URL' ,

  	'URLs' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_object_type__create_type 'person' ,

  	'Person' ,

  	'People' ,

  	'party' ,

  	'persons' ,

  	'person_id' ,

  	'person' ,

  	'f' ,

  	null ,

  	'person.name' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'person' ,

  	'first_names' ,

  	'string' ,

  	'First Names' ,

  	'First Names' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'person' ,

  	'last_name' ,

  	'string' ,

  	'Last Name' ,

  	'Last Names' ,

  	null ,

  	null ,

  	null ,

  	0 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_object_type__create_type 'user' ,

  	'User' ,

  	'Users' ,

  	'person' ,

  	'users' ,

  	'user_id' ,

  	'acs_user' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table parties (

	party_id	integer not null

			constraint parties_party_id_fk references

			acs_objects (object_id)

			constraint parties_pk primary key,

	email		varchar(100)

			constraint parties_email_un unique,

	url		varchar(200)

)
[MSSQL]
create table parties ( party_id	integer not null

			constraint parties_party_id_fk references

			acs_objects (object_id)

			constraint parties_pk primary key,

	email		varchar(100)

			constraint parties_email_un unique,

	url		varchar(200)

)

GO


 
[PG]
create function party__new (integer,varchar,timestamp,integer,varchar,varchar,varchar,integer)

returns integer as '

declare

  new__party_id               alias for $1;  

  new__object_type            alias for $2;  

  new__creation_date          alias for $3;  

  new__creation_user          alias for $4;  

  new__creation_ip            alias for $5;  

  new__email                  alias for $6;  

  new__url                    alias for $7;  

  new__context_id             alias for $8;  

  v_party_id                  parties.party_id%TYPE;

begin

  v_party_id :=

   acs_object__new(new__party_id, new__object_type, new__creation_date, 

                   new__creation_user, new__creation_ip, new__context_id);



  insert into parties

   (party_id, email, url)

  values

   (v_party_id, lower(new__email), new__url);



  return v_party_id;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function party__delete (integer)

returns integer as '

declare

  party_id               alias for $1;  

begin

  PERFORM acs_object__delete(party_id);



  return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC party__delete

	@party_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object__delete @party_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function party__name (integer)

returns varchar as '

declare

  party_id               alias for $1;  

begin

  if party_id = -1 then

   return 'The Public';

  else

   return null;

  end if;

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION party__name(@party_id		integer) 

RETURNS varchar

AS

BEGIN



IF @party_id  = -1  BEGIN

  RETURN CONVERT (varchar, 'The Public' )

    END

  ELSE BEGIN

  RETURN CONVERT (varchar, null )

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create table persons (

	person_id	integer not null

			constraint persons_person_id_fk

			references parties (party_id)

			constraint persons_pk primary key,

	first_names	varchar(100) not null,

	last_name	varchar(100) not null

)
[MSSQL]
create table persons ( person_id	integer not null

			constraint persons_person_id_fk

			references parties (party_id)

			constraint persons_pk primary key,

	first_names	varchar(100) not null,

	last_name	varchar(100) not null

)

GO


 
[PG]
create function person__new (integer,varchar,timestamp,integer,varchar,varchar,varchar,varchar,varchar,integer)

returns integer as '

declare

  new__person_id              alias for $1;  

  new__object_type            alias for $2;  

  new__creation_date          alias for $3;  

  new__creation_user          alias for $4;  

  new__creation_ip            alias for $5;  

  new__email                  alias for $6;  

  new__url                    alias for $7;  

  new__first_names            alias for $8; 

  new__last_name              alias for $9;  

  new__context_id             alias for $10; 

  v_person_id                 persons.person_id%TYPE;

begin

  v_person_id :=

   party__new(new__person_id, new__object_type,

             new__creation_date, new__creation_user, new__creation_ip,

             new__email, new__url, new__context_id);



  insert into persons

   (person_id, first_names, last_name)

  values

   (v_person_id, new__first_names, new__last_name);



  return v_person_id;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC person__new

	@new__person_id		integer,

	@new__object_type		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__email		varchar(8000),

	@new__url		varchar(8000),

	@new__first_names		varchar(8000),

	@new__last_name		varchar(8000),

	@new__context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_person_id	int



EXEC dbo.party__new @new__person_id ,

  	@new__object_type ,

  	@new__creation_date ,

  	@new__creation_user ,

  	@new__creation_ip ,

  	@new__email ,

  	@new__url ,

  	@new__context_id , @ms_return_value = @v_person_id OUTPUT

  

   

  insert into persons ( person_id, first_names, last_name ) values ( @v_person_id  , @new__first_names  , @new__last_name   )

   

  SET @ms_return_value = @v_person_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function person__delete (integer)

returns integer as '

declare

  delete__person_id     alias for $1;  

begin

  delete from persons

  where person_id = delete__person_id;



  PERFORM party__delete(delete__person_id);



  return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC person__delete

	@delete__person_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from persons  WHERE person_id  = @delete__person_id 

   EXEC dbo.party__delete @delete__person_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function person__name (integer)

returns varchar as '

declare

  name__person_id        alias for $1;  

  person_name            varchar(200);  

begin

  select first_names + ' ' + last_name

  into person_name

  from persons

  where person_id = name__person_id;



  return person_name;

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION person__name(@name__person_id		integer) 

RETURNS varchar

AS

BEGIN

declare @person_name	varchar ( 200 )





  select   @person_name = first_names  + ' '  + last_name   

     

    from persons  

     WHERE person_id  = @name__person_id  

     

     

   RETURN CONVERT (varchar, @person_name )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create table users (

	user_id			integer not null

				constraint users_user_id_fk

				references persons (person_id)

				constraint users_pk primary key,

	password		char(40),

	salt			char(40),

	screen_name		varchar(100)

				constraint users_screen_name_un

				unique,

	priv_name		integer default 0 not null,

	priv_email		integer default 5 not null,

	email_verified_p	boolean default 't',

	email_bouncing_p	boolean default 'f' not null,

	no_alerts_until		timestamp,

	last_visit		timestamp,

	second_to_last_visit	timestamp,

	n_sessions		integer default 1 not null,

	password_question	varchar(1000),

	password_answer		varchar(1000)

)
[MSSQL]
create table users ( user_id			integer not null

				constraint users_user_id_fk

				references persons (person_id)

				constraint users_pk primary key,

	password		char(40),

	salt			char(40),

	screen_name		varchar(100)

				constraint users_screen_name_un

				unique,

	priv_name		integer default 0 not null,

	priv_email		integer default 5 not null,

	email_verified_p	boolean default 't',

	email_bouncing_p	boolean default 'f' not null,

	no_alerts_until		datetime,

	last_visit		datetime,

	second_to_last_visit	datetime,

	n_sessions		integer default 1 not null,

	password_question	varchar(1000),

	password_answer		varchar(1000)

)

GO


 
[PG]
create table user_preferences (

	user_id			integer constraint user_prefs_user_id_fk

				references users (user_id)

				constraint user_preferences_pk

				primary key,

	prefer_text_only_p	boolean default 'f',

	

	language_preference	char(2) default 'en',

	dont_spam_me_p		boolean default 'f',

	email_type		varchar(64)

)
[MSSQL]
create table user_preferences ( user_id			integer constraint user_prefs_user_id_fk

				references users (user_id)

				constraint user_preferences_pk

				primary key,

	prefer_text_only_p	boolean default 'f',

	

	language_preference	char(2) default 'en',

	dont_spam_me_p		boolean default 'f',

	email_type		varchar(64)

)

GO


 
[PG]
create function inline_1 ()

returns integer as '

begin



  insert into acs_object_type_tables

    (object_type, table_name, id_column)

    values

    ('user', 'user_preferences', 'user_id');

  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_1

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_object_type_tables ( object_type, table_name, id_column ) values ( 'user'  , 'user_preferences'  , 'user_id'   )

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_1 ()
[MSSQL]
 dbo.inline_1 

 
[PG]
drop function inline_1 ()
[MSSQL]
drop proc inline_1

 
[PG]
alter table acs_objects add

  constraint acs_objects_creation_user_fk

  foreign key (creation_user) references users(user_id)
[MSSQL]
alter table acs_objects add

  constraint acs_objects_creation_user_fk

  foreign key (creation_user) references users(user_id)

 
[PG]
alter table acs_objects add

  constraint acs_objects_modifying_user_fk

  foreign key (modifying_user) references users(user_id)
[MSSQL]
alter table acs_objects add

  constraint acs_objects_modifying_user_fk

  foreign key (modifying_user) references users(user_id)

 
[PG]
create function acs_user__new (integer,varchar,timestamp,integer,varchar,varchar,varchar,varchar,varchar,char,char,varchar,varchar,varchar,boolean,integer)

returns integer as '

declare

  new__user_id                  alias for $1;  

  new__object_type              alias for $2;  

  new__creation_date            alias for $3;  

  new__creation_user            alias for $4;  

  new__creation_ip              alias for $5;  

  new__email                    alias for $6;  

  new__url                      alias for $7;  

  new__first_names              alias for $8;  

  new__last_name                alias for $9;  

  new__password                 alias for $10; 

  new__salt                     alias for $11; 

  new__password_question        alias for $12; 

  new__password_answer          alias for $13; 

  new__screen_name              alias for $14; 

  new__email_verified_p         alias for $15; 

  new__context_id               alias for $16; 

  v_user_id                     users.user_id%TYPE;

begin

  v_user_id :=

   person__new(new__user_id, new__object_type,

               new__creation_date, new__creation_user, new__creation_ip,

               new__email, new__url, new__first_names, new__last_name, 

               new__context_id);



  insert into users

   (user_id, password, salt, password_question, password_answer, screen_name,

    email_verified_p)

  values

   (v_user_id, new__password, new__salt, new__password_question, 

    new__password_answer, new__screen_name, new__email_verified_p);



  insert into user_preferences

    (user_id)

    values

    (v_user_id);



  return v_user_id;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_user__new

	@new__user_id		integer,

	@new__object_type		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__email		varchar(8000),

	@new__url		varchar(8000),

	@new__first_names		varchar(8000),

	@new__last_name		varchar(8000),

	@new__password		char,

	@new__salt		char,

	@new__password_question		varchar(8000),

	@new__password_answer		varchar(8000),

	@new__screen_name		varchar(8000),

	@new__email_verified_p		boolean,

	@new__context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_user_id	int



EXEC dbo.person__new @new__user_id ,

  	@new__object_type ,

  	@new__creation_date ,

  	@new__creation_user ,

  	@new__creation_ip ,

  	@new__email ,

  	@new__url ,

  	@new__first_names ,

  	@new__last_name ,

  	@new__context_id , @ms_return_value = @v_user_id OUTPUT

  

   

  insert into users ( user_id, password, salt, password_question, password_answer, screen_name, email_verified_p ) values ( @v_user_id  , @new__password  , @new__salt  , @new__password_question  , @new__password_answer  , @new__screen_name  , @new__email_verified_p   )

   

  insert into user_preferences ( user_id ) values ( @v_user_id   )

   

  SET @ms_return_value = @v_user_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_user__new(varchar,varchar,varchar,char,char) 

returns integer as '

declare

        email   alias for $1;

        fname   alias for $2;

        lname   alias for $3;

        pword   alias for $4;

        salt    alias for $5;

begin

        return acs_user__new(null,

                             'user',

                             now(),

                             null,

                             null,                

                             email,

                             null,

                             fname,

                             lname,

                             pword,

                             salt,

                             null,

                             null,

                             null,

                             't',

                             null

                             );



end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_user__new_5

	@email		varchar(8000),

	@fname		varchar(8000),

	@lname		varchar(8000),

	@pword		char,

	@salt		char, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.acs_user__new ( null ,

  	'user' ,

  	getdate() ,

  	null ,

  	null ,

  	@email ,

  	null ,

  	@fname ,

  	@lname ,

  	@pword ,

  	@salt ,

  	null ,

  	null ,

  	null ,

  	't' ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_user__receives_alerts_p (integer)

returns boolean as '

declare

  receives_alerts_p__user_id                alias for $1;  

  counter                                   boolean;       

begin

  select case when count(*) = 0 then 'f' else 't' end into counter

   from users

   where no_alerts_until >= now()

   and user_id = receives_alerts_p__user_id;



  return counter;

  

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_user__approve_email (integer)

returns integer as '

declare

  approve_email__user_id        alias for $1;  

begin

    update users

    set email_verified_p = 't'

    where user_id = approve_email__user_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_user__unapprove_email (integer)

returns integer as '

declare

  unapprove_email__user_id      alias for $1;  

begin

    update users

    set email_verified_p = 'f'

    where user_id = unapprove_email__user_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_user__delete (integer)

returns integer as '

declare

  delete__user_id       alias for $1;  

begin

  delete from user_preferences

  where user_id = delete__user_id;



  delete from users

  where user_id = delete__user_id;



  PERFORM person__delete(delete__user_id);



  return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_user__delete

	@delete__user_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from user_preferences  WHERE user_id  = @delete__user_id 

   delete from users  WHERE user_id  = @delete__user_id 

   EXEC dbo.person__delete @delete__user_id  

   RETURN 0

  

END -- stored proc


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/groups-create.sql
[PG]
create table composition_rels (

        rel_id          integer constraint composition_rel_rel_id_fk

                        references acs_rels (rel_id)

                        constraint composition_rel_rel_id_pk

                        primary key

)
[MSSQL]
create table composition_rels ( rel_id          integer constraint composition_rel_rel_id_fk

                        references acs_rels (rel_id)

                        constraint composition_rel_rel_id_pk

                        primary key

)

GO


 
[PG]
create table membership_rels (

        rel_id          integer constraint membership_rel_rel_id_fk

                        references acs_rels (rel_id)

                        constraint membership_rel_rel_id_pk

                        primary key,

        

        member_state    varchar(20) constraint membership_rel_mem_ck

                        check (member_state in ('approved', 'needs approval',

                                              'banned', 'rejected', 'deleted'))

)
[MSSQL]
create table membership_rels ( rel_id          integer constraint membership_rel_rel_id_fk

                        references acs_rels (rel_id)

                        constraint membership_rel_rel_id_pk

                        primary key,

        

        member_state    varchar(20) constraint membership_rel_mem_ck

                        check (member_state in ('approved', 'needs approval',

                                              'banned', 'rejected', 'deleted'))

)

GO


 
[PG]
create function inline_0 ()

returns integer as '

declare

  attr_id acs_attributes.attribute_id%TYPE;

begin

 

 

 

 attr_id := acs_object_type__create_type (

   'group',

   'Group',

   'Groups',

   'party',

   'groups',

   'group_id',

   'acs_group',

   'f',

   'group_types',

   'acs_group.name'

   );



 attr_id := acs_attribute__create_attribute (

	'group',

	'group_name',

	'string',

	'Group name',

	'Group names',

	null,

	null,

	null,

	1,

	1,

	null,

	'type_specific',

	'f'

	);



 

 

 

 attr_id := acs_rel_type__create_role ('composite', 'Composite', 'Composites');

 attr_id := acs_rel_type__create_role ('component', 'Component', 'Components');



 attr_id := acs_rel_type__create_type (

   'composition_rel',

   'Composition Relation',

   'Composition Relationships',

   'relationship',

   'composition_rels',

   'rel_id',

   'composition_rel',

   'group',

   'composite',

    0, 

    null,

   'group',

   'component',

   0,

   null

   );





 

 

 

 attr_id := acs_rel_type__create_role ('member', 'Member', 'Members');



 attr_id := acs_rel_type__create_type (

   'membership_rel',

   'Membership Relation',

   'Membership Relationships',

   'relationship',

   'membership_rels',

   'rel_id',

   'membership_rel',

   'group',

   null,

   0, 

   null,

   'person',

   'member',

   0, 

   null

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'group' ,

  	'Group' ,

  	'Groups' ,

  	'party' ,

  	'groups' ,

  	'group_id' ,

  	'acs_group' ,

  	'f' ,

  	'group_types' ,

  	'acs_group.name' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'group' ,

  	'group_name' ,

  	'string' ,

  	'Group name' ,

  	'Group names' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_rel_type__create_role 'composite' ,

  	'Composite' ,

  	'Composites' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_rel_type__create_role 'component' ,

  	'Component' ,

  	'Components' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_rel_type__create_type 'composition_rel' ,

  	'Composition Relation' ,

  	'Composition Relationships' ,

  	'relationship' ,

  	'composition_rels' ,

  	'rel_id' ,

  	'composition_rel' ,

  	'group' ,

  	'composite' ,

  	0 ,

  	null ,

  	'group' ,

  	'component' ,

  	0 ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_rel_type__create_role 'member' ,

  	'Member' ,

  	'Members' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_rel_type__create_type 'membership_rel' ,

  	'Membership Relation' ,

  	'Membership Relationships' ,

  	'relationship' ,

  	'membership_rels' ,

  	'rel_id' ,

  	'membership_rel' ,

  	'group' ,

  	null ,

  	0 ,

  	null ,

  	'person' ,

  	'member' ,

  	0 ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'abstract_p', table 'openacs.dbo.acs_object_types'; column does not allow nulls. INSERT fails.

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table group_types (

        group_type              varchar(100) not null

                                constraint group_types_pk primary key

                                constraint group_types_obj_type_fk

                                references acs_object_types (object_type),

	

	

        default_join_policy     varchar(30) default 'open' not null

                                constraint group_types_join_policy_ck

                                check (default_join_policy in 

                                ('open', 'needs approval', 'closed'))

)
[MSSQL]
create table group_types ( group_type              varchar(100) not null

                                constraint group_types_pk primary key

                                constraint group_types_obj_type_fk

                                references acs_object_types (object_type),

	

	

        default_join_policy     varchar(30) default 'open' not null

                                constraint group_types_join_policy_ck

                                check (default_join_policy in 

                                ('open', 'needs approval', 'closed'))

)

GO


 
[PG]
create table groups (

        group_id        integer not null

                        constraint groups_group_id_fk

                        references parties (party_id)

                        constraint groups_pk primary key,

        group_name      varchar(100) not null,

        join_policy     varchar(30) default 'open' not null

                        constraint groups_join_policy_ck

                        check (join_policy in 

                               ('open', 'needs approval', 'closed'))

)
[MSSQL]
create table groups ( group_id        integer not null

                        constraint groups_group_id_fk

                        references parties (party_id)

                        constraint groups_pk primary key,

        group_name      varchar(100) not null,

        join_policy     varchar(30) default 'open' not null

                        constraint groups_join_policy_ck

                        check (join_policy in 

                               ('open', 'needs approval', 'closed'))

)

GO


 
[PG]
create table group_type_rels (

       group_rel_type_id      integer constraint gtr_group_rel_type_id_pk primary key,

       rel_type		      varchar(100) not null 

                              constraint gtr_rel_type_fk

                              references acs_rel_types (rel_type)

                              on delete cascade,

       group_type	      varchar(100) not null 

                              constraint gtr_group_type_fk

                              references acs_object_types (object_type)

                              on delete cascade,

       constraint gtr_group_rel_types_un unique (group_type, rel_type)

)
[MSSQL]
create table group_type_rels ( group_rel_type_id      integer constraint gtr_group_rel_type_id_pk primary key,

       rel_type		      varchar(100) not null 

                              constraint gtr_rel_type_fk

                              references acs_rel_types (rel_type)

                              ,

       group_type	      varchar(100) not null 

                              constraint gtr_group_type_fk

                              references acs_object_types (object_type)

                              ,

       constraint gtr_group_rel_types_un unique (group_type, rel_type)

)

GO


 
[PG]
create index group_type_rels_rel_type_idx on group_type_rels(rel_type)
[MSSQL]
create index group_type_rels_rel_type_idx on group_type_rels(rel_type)

 
[PG]
create table group_rels (

       group_rel_id           integer constraint group_rels_group_rel_id_pk primary key,

       rel_type		      varchar(100) not null 

                              constraint group_rels_rel_type_fk

                              references acs_rel_types (rel_type)

                              on delete cascade,

       group_id	              integer not null 

                              constraint group_rels_group_id_fk

                              references groups (group_id)

                              on delete cascade,

       constraint group_rels_group_rel_type_un unique (group_id, rel_type)

)
[MSSQL]
create table group_rels ( group_rel_id           integer constraint group_rels_group_rel_id_pk primary key,

       rel_type		      varchar(100) not null 

                              constraint group_rels_rel_type_fk

                              references acs_rel_types (rel_type)

                              ,

       group_id	              integer not null 

                              constraint group_rels_group_id_fk

                              references groups (group_id)

                              ,

       constraint group_rels_group_rel_type_un unique (group_id, rel_type)

)

GO


 
[PG]
create index group_rels_rel_type_idx on group_rels(rel_type)
[MSSQL]
create index group_rels_rel_type_idx on group_rels(rel_type)

 
[PG]
create table group_element_index (

	group_id	integer not null

			constraint group_element_index_grp_id_fk

			references groups (group_id),

	element_id	integer not null

			constraint group_element_index_elem_id_fk

			references parties (party_id),

	rel_id		integer not null

			constraint group_element_index_rel_id_fk

			references acs_rels (rel_id),

	container_id	integer not null

			constraint group_element_index_cont_id_fk

			references groups (group_id),

        rel_type        varchar(100) not null

                        constraint group_elem_index_rel_type_fk

                        references acs_rel_types (rel_type),

        ancestor_rel_type varchar(100) not null

                        constraint grp_el_idx_ancstr_rel_type_ck

                        check (ancestor_rel_type in ('composition_rel','membership_rel')),

	constraint group_element_index_pk

	primary key (element_id, group_id, rel_id)

)
[MSSQL]
create table group_element_index ( group_id	integer not null

			constraint group_element_index_grp_id_fk

			references groups (group_id),

	element_id	integer not null

			constraint group_element_index_elem_id_fk

			references parties (party_id),

	rel_id		integer not null

			constraint group_element_index_rel_id_fk

			references acs_rels (rel_id),

	container_id	integer not null

			constraint group_element_index_cont_id_fk

			references groups (group_id),

        rel_type        varchar(100) not null

                        constraint group_elem_index_rel_type_fk

                        references acs_rel_types (rel_type),

        ancestor_rel_type varchar(100) not null

                        constraint grp_el_idx_ancstr_rel_type_ck

                        check (ancestor_rel_type in ('composition_rel','membership_rel')),

	constraint group_element_index_pk

	primary key (element_id, group_id, rel_id)

)

GO


 
[PG]
create index group_elem_idx_group_idx on group_element_index (group_id)
[MSSQL]
create index group_elem_idx_group_idx on group_element_index (group_id)

 
[PG]
create index group_elem_idx_element_idx on group_element_index (element_id)
[MSSQL]
create index group_elem_idx_element_idx on group_element_index (element_id)

 
[PG]
create index group_elem_idx_rel_id_idx on group_element_index (rel_id)
[MSSQL]
create index group_elem_idx_rel_id_idx on group_element_index (rel_id)

 
[PG]
create index group_elem_idx_container_idx on group_element_index (container_id)
[MSSQL]
create index group_elem_idx_container_idx on group_element_index (container_id)

 
[PG]
create index group_elem_idx_rel_type_idx on group_element_index (rel_type)
[MSSQL]
create index group_elem_idx_rel_type_idx on group_element_index (rel_type)

 
[PG]
create view group_element_map

as select group_id, element_id, rel_id, container_id, 

          rel_type, ancestor_rel_type

   from group_element_index
[MSSQL]
create view group_element_map as 

select  group_id  , element_id  , rel_id  , container_id  , rel_type  , ancestor_rel_type   

   

  from group_element_index  

   

   

   

 
[PG]
create view group_component_map

as select group_id, element_id as component_id, rel_id, container_id, rel_type

   from group_element_map

   where ancestor_rel_type='composition_rel'
[MSSQL]
create view group_component_map as 

select  group_id  , element_id  as component_id, rel_id  , container_id  , rel_type   

   

  from group_element_map  

   WHERE ancestor_rel_type  = 'composition_rel'  

   

   

 
[PG]
create view group_member_map

as select group_id, element_id as member_id, rel_id, container_id, rel_type

   from group_element_map

   where ancestor_rel_type='membership_rel'
[MSSQL]
create view group_member_map as 

select  group_id  , element_id  as member_id, rel_id  , container_id  , rel_type   

   

  from group_element_map  

   WHERE ancestor_rel_type  = 'membership_rel'  

   

   

 
[PG]
create view group_approved_member_map

as select gm.group_id, gm.member_id, gm.rel_id, gm.container_id, gm.rel_type

   from group_member_map gm, membership_rels mr

   where gm.rel_id = mr.rel_id

   and mr.member_state = 'approved'
[MSSQL]
create view group_approved_member_map as 

select  gm.group_id  , gm.member_id  , gm.rel_id  , gm.container_id  , gm.rel_type   

   

  from group_member_map gm,

	membership_rels mr 

   WHERE gm.rel_id  = mr.rel_id  and mr.member_state  = 'approved'  

   

   

 
[PG]
create view group_distinct_member_map

as select distinct group_id, member_id

   from group_approved_member_map
[MSSQL]
create view group_distinct_member_map as 

select DISTINCT group_id  , member_id   

   

  from group_approved_member_map  

   

   

   

 
[PG]
create view group_component_index as select * from group_component_map
[MSSQL]
create view group_component_index as 

select  *  

   

  from group_component_map  

   

   

   

 
[PG]
create view group_member_index as select * from group_member_map
[MSSQL]
create view group_member_index as 

select  *  

   

  from group_member_map  

   

   

   

 
[PG]
create function group_contains_p (integer, integer, integer) 

returns boolean as '

declare 

        group_contains_p__group_id        alias for $1;

        group_contains_p__component_id    alias for $2;

        group_contains_p__rel_id          alias for $3;

        map                               record;

begin

  if group_contains_p__group_id = group_contains_p__component_id then

    return 't';

  else

    if group_contains_p__rel_id is null then

      for map in  select *

                  from group_component_map

                  where component_id = group_contains_p__component_id

                  and group_id = container_id 

      LOOP

        if group_contains_p(group_contains_p__group_id, map.group_id, null) = 't' then

          return 't';

        end if;

      end loop;

    else

      for map in  select *

                  from group_component_map

                  where component_id = group_contains_p__component_id

                  and rel_id = group_contains_p__rel_id

                  and group_id = container_id 

      LOOP

        if group_contains_p(group_contains_p__group_id, map.group_id, null) = 't' then

          return 't';

        end if;

      end loop;

    end if;

    return 'f';

  end if;

end;' language 'plpgsql'
[MSSQL]


  CREATE FUNCTION group_contains_p(@group_contains_p__group_id		integer,

	@group_contains_p__component_id		integer,

	@group_contains_p__rel_id		integer) 

RETURNS boolean

AS

BEGIN

declare @map__group_id 	int



IF @group_contains_p__group_id  = @group_contains_p__component_id  BEGIN

  RETURN 't'

    END

  ELSE BEGIN

  IF @group_contains_p__rel_id  is null  BEGIN

    

      DECLARE cursor_1 CURSOR FOR

        

      select  group_id

         

        from group_component_map  

         WHERE component_id  = @group_contains_p__component_id  and group_id  = container_id  

         

         

      

      OPEN cursor_1

      

      FETCH NEXT FROM cursor_1 INTO @map__group_id 

      

      WHILE (@@FETCH_STATUS = 0)

      BEGIN

      IF dbo.group_contains_p ( @group_contains_p__group_id ,

        	@map__group_id ,

        	null  )  = 't'  BEGIN

        RETURN 't'

          

        END --IF

        

        

        

      

        FETCH NEXT FROM cursor_1 INTO @map__group_id

      END --while

      

      CLOSE cursor_1

      

      DEALLOCATE cursor_1

      

      

      END

    ELSE BEGIN

    

      DECLARE cursor_2 CURSOR FOR

        

      select  group_id

         

        from group_component_map  

         WHERE component_id  = @group_contains_p__component_id  and rel_id  = @group_contains_p__rel_id  and group_id  = container_id  

         

         

      

      OPEN cursor_2

      

      FETCH NEXT FROM cursor_2 INTO @map__group_id

      

      WHILE (@@FETCH_STATUS = 0)

      BEGIN

      IF dbo.group_contains_p ( @group_contains_p__group_id ,

        	@map__group_id ,

        	null  )  = 't'  BEGIN

        RETURN 't'

          

        END --IF

        

        

        

      

        FETCH NEXT FROM cursor_2 INTO @map__group_id

      END --while

      

      CLOSE cursor_2

      

      DEALLOCATE cursor_2

      

      

      

    END --IF

    

    

     RETURN 'f'

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function




 
[PG]
create function membership_rels_in_tr () returns opaque as '

declare

begin

  raise EXCEPTION '-20000: Insert to membership rels not yet supported';



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger  membership_rels_in_tr after insert  on membership_rels

for each row  execute procedure membership_rels_in_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function composition_rels_in_tr () returns opaque as '

declare

begin

  raise EXCEPTION '-20000: Insert to membership rels not yet supported';



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger composition_rels_in_tr  after insert on composition_rels

for each row  execute procedure  composition_rels_in_tr()
[MSSQL]
/* Skipped */

 
[PG]
insert into group_type_rels 

(group_rel_type_id, rel_type, group_type)

values

(acs_object_id_seq.nextval, 'membership_rel', 'group')
[MSSQL]
exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

insert into group_type_rels ( group_rel_type_id, rel_type, group_type ) values ( @retval  , 'membership_rel'  , 'group'   )
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@retval'.

 
[PG]
insert into group_type_rels 

(group_rel_type_id, rel_type, group_type)

values

(acs_object_id_seq.nextval, 'composition_rel', 'group')
[MSSQL]
exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

insert into group_type_rels ( group_rel_type_id, rel_type, group_type ) values ( @retval  , 'composition_rel'  , 'group'   )
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@retval'.

 
[PG]
  
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@retval'.

 
File packages/acs-kernel/sql/postgresql/rel-segments-create.sql
[PG]
create function inline_0 ()

returns integer as '

begin

 

 

 

 

 

 PERFORM acs_object_type__create_type (

   'rel_segment',

   'Relational Party Segment',

   'Relational Party Segments',

   'party',

   'rel_segments',

   'segment_id',

   'rel_segment',

   'f',

   'rel_segment',

   'rel_segment.name'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object_type__create_type 'rel_segment' ,

  	'Relational Party Segment' ,

  	'Relational Party Segments' ,

  	'party' ,

  	'rel_segments' ,

  	'segment_id' ,

  	'rel_segment' ,

  	'f' ,

  	'rel_segment' ,

  	'rel_segment.name'  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table rel_segments (

        segment_id      integer not null

                        constraint rel_segments_segment_id_fk

                        references parties (party_id)

                        constraint rel_segments_pk primary key,

        segment_name    varchar(230) not null,

        group_id        integer not null

                        constraint rel_segments_group_id_fk

                        references groups (group_id),

        rel_type        varchar(100) not null

                        constraint rel_segments_rel_type_fk

                        references acs_rel_types (rel_type),

        constraint rel_segments_grp_rel_type_uq unique(group_id, rel_type)

)
[MSSQL]
create table rel_segments ( segment_id      integer not null

                        constraint rel_segments_segment_id_fk

                        references parties (party_id)

                        constraint rel_segments_pk primary key,

        segment_name    varchar(230) not null,

        group_id        integer not null

                        constraint rel_segments_group_id_fk

                        references groups (group_id),

        rel_type        varchar(100) not null

                        constraint rel_segments_rel_type_fk

                        references acs_rel_types (rel_type),

        constraint rel_segments_grp_rel_type_uq unique(group_id, rel_type)

)

GO


 
[PG]
create index rel_segments_rel_type_idx on rel_segments(rel_type)
[MSSQL]
create index rel_segments_rel_type_idx on rel_segments(rel_type)

 
[PG]
create view rel_segment_party_map

as select rs.segment_id, gem.element_id as party_id, gem.rel_id, gem.rel_type, 

          gem.group_id, gem.container_id, gem.ancestor_rel_type

   from rel_segments rs, 

        group_element_map gem 

   where gem.group_id = rs.group_id

     and rs.rel_type in (select o2.object_type

                           from acs_object_types o1, acs_object_types o2

                          where o1.object_type = gem.rel_type 

                            and o2.tree_sortkey <= o1.tree_sortkey

                            and o1.tree_sortkey like (o2.tree_sortkey + '%'))
[MSSQL]
create view rel_segment_party_map as 

select  rs.segment_id  , gem.element_id  as party_id, gem.rel_id  , gem.rel_type  , gem.group_id  , gem.container_id  , gem.ancestor_rel_type   

   

  from rel_segments rs,

	group_element_map gem 

   WHERE gem.group_id  = rs.group_id  and rs.rel_type in ( 

select  o2.object_type   

   

  from acs_object_types o1,

	acs_object_types o2 

   WHERE o1.object_type  = gem.rel_type  and o2.tree_sortkey  <= o1.tree_sortkey  and o1.tree_sortkey  like ( o2.tree_sortkey  + '%'  ) 

   

    ) 

   

   

 
[PG]
create view rel_segment_distinct_party_map

as select distinct segment_id, party_id, ancestor_rel_type

   from rel_segment_party_map
[MSSQL]
create view rel_segment_distinct_party_map as 

select DISTINCT segment_id  , party_id  , ancestor_rel_type   

   

  from rel_segment_party_map  

   

   

   

 
[PG]
create view rel_segment_member_map

as select segment_id, party_id as member_id, rel_id, rel_type, 

          group_id, container_id

   from rel_segment_party_map

   where ancestor_rel_type = 'membership_rel'
[MSSQL]
create view rel_segment_member_map as 

select  segment_id  , party_id  as member_id, rel_id  , rel_type  , group_id  , container_id   

   

  from rel_segment_party_map  

   WHERE ancestor_rel_type  = 'membership_rel'  

   

   

 
[PG]
create view rel_seg_approved_member_map

as select rs.segment_id, gem.element_id as member_id, gem.rel_id, 

          gem.rel_type, gem.group_id, gem.container_id

    from membership_rels mr, group_element_map gem, rel_segments rs

   where rs.group_id = gem.group_id 

     and rs.rel_type in (select o2.object_type

                           from acs_object_types o1, acs_object_types o2

                          where o1.object_type = gem.rel_type 

                            and o2.tree_sortkey <= o1.tree_sortkey

                            and o1.tree_sortkey like (o2.tree_sortkey + '%'))

     and mr.rel_id = gem.rel_id and mr.member_state = 'approved'
[MSSQL]
create view rel_seg_approved_member_map as 

select  rs.segment_id  , gem.element_id  as member_id, gem.rel_id  , gem.rel_type  , gem.group_id  , gem.container_id   

   

  from membership_rels mr,

	group_element_map gem,

	rel_segments rs 

   WHERE rs.group_id  = gem.group_id  and rs.rel_type in ( 

select  o2.object_type   

   

  from acs_object_types o1,

	acs_object_types o2 

   WHERE o1.object_type  = gem.rel_type  and o2.tree_sortkey  <= o1.tree_sortkey  and o1.tree_sortkey  like ( o2.tree_sortkey  + '%'  ) 

   

    ) and mr.rel_id  = gem.rel_id  and mr.member_state  = 'approved'  

   

   

 
[PG]
create view rel_seg_distinct_member_map

as select distinct segment_id, member_id

   from rel_seg_approved_member_map
[MSSQL]
create view rel_seg_distinct_member_map as 

select DISTINCT segment_id  , member_id   

   

  from rel_seg_approved_member_map  

   

   

   

 
[PG]
create view party_member_map

as select segment_id as party_id, member_id

   from rel_seg_distinct_member_map

   union

   select group_id as party_id, member_id

   from group_distinct_member_map

   union

   select party_id, party_id as member_id

   from parties
[MSSQL]
create view party_member_map as 

select  segment_id  as party_id, member_id   

   

  from rel_seg_distinct_member_map  

   

   

   union 

select  group_id  as party_id, member_id   

   

  from group_distinct_member_map  

   

   

    union 

select  party_id  , party_id  as member_id 

   

  from parties  

   

   

    

 
[PG]
create view party_approved_member_map

as select distinct segment_id as party_id, member_id

   from rel_seg_approved_member_map

   union

   select distinct group_id as party_id, member_id

   from group_approved_member_map

   union

   select party_id, party_id as member_id

   from parties
[MSSQL]
create view party_approved_member_map as 

select DISTINCT segment_id  as party_id, member_id   

   

  from rel_seg_approved_member_map  

   

   

   union 

select DISTINCT group_id  as party_id, member_id   

   

  from group_approved_member_map  

   

   

    union 

select  party_id  , party_id  as member_id 

   

  from parties  

   

   

    

 
[PG]
create view party_element_map

as select distinct group_id as party_id, element_id

   from group_element_map

   union

   select distinct segment_id as party_id, party_id as element_id

   from rel_segment_party_map

   union

   select party_id, party_id as element_id

   from parties
[MSSQL]
create view party_element_map as 

select DISTINCT group_id  as party_id, element_id   

   

  from group_element_map  

   

   

   union 

select DISTINCT segment_id  as party_id, party_id  as element_id 

   

  from rel_segment_party_map  

   

   

    union 

select  party_id  , party_id  as element_id 

   

  from parties  

   

   

    

 
[PG]
create view rel_segment_group_rel_type_map as

select s.segment_id, 

       gcm.component_id as group_id, 

       acs_rel_types.rel_type as rel_type

from rel_segments s,

     (select group_id, component_id

      from group_component_map

      UNION ALL

      select group_id, group_id as component_id

      from groups) gcm,

     acs_rel_types

where s.group_id = gcm.group_id

  and s.rel_type in (select o2.object_type

                       from acs_object_types o1, acs_object_types o2

                      where o1.object_type = acs_rel_types.rel_type

                        and o2.tree_sortkey <= o1.tree_sortkey

                        and o1.tree_sortkey like (o2.tree_sortkey + '%'))
[MSSQL]
create view rel_segment_group_rel_type_map as 

select  s.segment_id  , gcm.component_id  as group_id, acs_rel_types.rel_type  as rel_type 

   

  from rel_segments s,

	( 

select  group_id  , component_id   

   

  from group_component_map  

   

   

   UNION ALL 

select  group_id  , group_id  as component_id 

   

  from groups  

   

   

     ) gcm,

	acs_rel_types  

   WHERE s.group_id  = gcm.group_id  and s.rel_type in ( 

select  o2.object_type   

   

  from acs_object_types o1,

	acs_object_types o2 

   WHERE o1.object_type  = acs_rel_types.rel_type  and o2.tree_sortkey  <= o1.tree_sortkey  and o1.tree_sortkey  like ( o2.tree_sortkey  + '%'  ) 

   

    ) 

   

   

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/rel-constraints-create.sql
[PG]
create function inline_0 ()

returns integer as '

begin

    PERFORM acs_object_type__create_type (

      'rel_constraint',

      'Relational Constraint',

      'Relational Constraints',

      'acs_object',

      'rel_constraints',

      'constraint_id',

      'rel_constraint',

      'f',

      null,

      null

      );



      return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object_type__create_type 'rel_constraint' ,

  	'Relational Constraint' ,

  	'Relational Constraints' ,

  	'acs_object' ,

  	'rel_constraints' ,

  	'constraint_id' ,

  	'rel_constraint' ,

  	'f' ,

  	null ,

  	null  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table rel_constraints (

    constraint_id		integer

				constraint rel_constraints_pk

					primary key

				constraint rc_constraint_id_fk

					references acs_objects(object_id),

    constraint_name		varchar(100) not null,

    rel_segment 		integer not null

				constraint rc_rel_segment_fk

					references rel_segments (segment_id),

    rel_side                    char(3) default 'two' not null

				constraint rc_rel_side_ck

					check (rel_side in

					('one', 'two')),

    required_rel_segment	integer not null

				constraint rc_required_rel_segment

					references rel_segments (segment_id),

    constraint rel_constraints_uq

	unique (rel_segment, rel_side, required_rel_segment)

)
[MSSQL]
create table rel_constraints ( constraint_id		integer

				constraint rel_constraints_pk

					primary key

				constraint rc_constraint_id_fk

					references acs_objects(object_id),

    constraint_name		varchar(100) not null,

    rel_segment 		integer not null

				constraint rc_rel_segment_fk

					references rel_segments (segment_id),

    rel_side                    char(3) default 'two' not null

				constraint rc_rel_side_ck

					check (rel_side in

					('one', 'two')),

    required_rel_segment	integer not null

				constraint rc_required_rel_segment

					references rel_segments (segment_id),

    constraint rel_constraints_uq

	unique (rel_segment, rel_side, required_rel_segment)

)

GO


 
[PG]
create index rel_constraint_req_rel_seg_idx on rel_constraints(required_rel_segment)
[MSSQL]
create index rel_constraint_req_rel_seg_idx on rel_constraints(required_rel_segment)

 
[PG]
create view constrained_rels1 as 

select rel.constraint_id, rel.constraint_name, 

       r.rel_id, r.container_id, r.party_id, r.rel_type, 

       rel.rel_segment,

       rel.rel_side, 

       rel.required_rel_segment

  from rel_constraints rel, rel_segment_party_map r

 where rel.rel_side = 'one'

   and rel.rel_segment = r.segment_id
[MSSQL]
create view constrained_rels1 as 

select  rel.constraint_id  , rel.constraint_name  , r.rel_id  , r.container_id  , r.party_id  , r.rel_type  , rel.rel_segment  , rel.rel_side  , rel.required_rel_segment   

   

  from rel_constraints rel,

	rel_segment_party_map r 

   WHERE rel.rel_side  = 'one'  and rel.rel_segment  = r.segment_id  

   

   

 
[PG]
create view rel_constraints_violated_one as

select c.*

from   constrained_rels1 c left outer join rel_segment_party_map rspm 

       on (rspm.segment_id = c.required_rel_segment and 

           rspm.party_id = c.container_id)

where rspm.party_id is null
[MSSQL]
create view rel_constraints_violated_one as 

select  c.*   

   

  from constrained_rels1 c left outer join rel_segment_party_map rspm on ( rspm.segment_id  = c.required_rel_segment  and rspm.party_id  = c.container_id  ) 

   WHERE rspm.party_id  is null  

   

   

 
[PG]
create view constrained_rels2 as 

select rel.constraint_id, rel.constraint_name, 

       r.rel_id, r.container_id, r.party_id, r.rel_type, 

       rel.rel_segment,

       rel.rel_side, 

       rel.required_rel_segment

  from rel_constraints rel, rel_segment_party_map r

 where rel.rel_side = 'two'

   and rel.rel_segment = r.segment_id
[MSSQL]
create view constrained_rels2 as 

select  rel.constraint_id  , rel.constraint_name  , r.rel_id  , r.container_id  , r.party_id  , r.rel_type  , rel.rel_segment  , rel.rel_side  , rel.required_rel_segment   

   

  from rel_constraints rel,

	rel_segment_party_map r 

   WHERE rel.rel_side  = 'two'  and rel.rel_segment  = r.segment_id  

   

   

 
[PG]
create view rel_constraints_violated_two as

select c.*

from  constrained_rels2 c left outer join rel_segment_party_map rspm 

       on (rspm.segment_id = c.required_rel_segment and

           rspm.party_id = c.party_id)

where rspm.party_id is null
[MSSQL]
create view rel_constraints_violated_two as 

select  c.*   

   

  from constrained_rels2 c left outer join rel_segment_party_map rspm on ( rspm.segment_id  = c.required_rel_segment  and rspm.party_id  = c.party_id  ) 

   WHERE rspm.party_id  is null  

   

   

 
[PG]
create view rc_all_constraints as

select group_rel_types.group_id, 

       group_rel_types.rel_type,

       rel_constraints.rel_segment,

       rel_constraints.rel_side,

       required_rel_segment

  from rel_constraints,

       rel_segment_group_rel_type_map group_rel_types,

       rel_segments req_seg

 where rel_constraints.rel_segment = group_rel_types.segment_id

   and rel_constraints.required_rel_segment = req_seg.segment_id

   and not (req_seg.group_id = group_rel_types.group_id and

            req_seg.rel_type = group_rel_types.rel_type)
[MSSQL]
create view rc_all_constraints as 

select  group_rel_types.group_id  , group_rel_types.rel_type  , rel_constraints.rel_segment  , rel_constraints.rel_side  , required_rel_segment   

   

  from rel_constraints ,

	rel_segment_group_rel_type_map group_rel_types,

	rel_segments req_seg 

   WHERE rel_constraints.rel_segment  = group_rel_types.segment_id  and rel_constraints.required_rel_segment  = req_seg.segment_id  

   

   

 
[PG]
create view rc_all_distinct_constraints as

select distinct 

       group_id, rel_type, rel_segment, rel_side, required_rel_segment

from rc_all_constraints
[MSSQL]
create view rc_all_distinct_constraints as 

select DISTINCT group_id  , rel_type  , rel_segment  , rel_side  , required_rel_segment   

   

  from rc_all_constraints  

   

   

   

 
[PG]
create view rc_required_rel_segments as

select distinct group_id, rel_type, required_rel_segment

from rc_all_constraints

where rel_side = 'two'
[MSSQL]
create view rc_required_rel_segments as 

select DISTINCT group_id  , rel_type  , required_rel_segment   

   

  from rc_all_constraints  

   WHERE rel_side  = 'two'  

   

   

 
[PG]
create view comp_or_member_rel_types as 

select object_type as rel_type 

  from acs_object_types

 where tree_sortkey like (select o.tree_sortkey + '%' 

                            from acs_object_types o

                           where o.object_type = 'composition_rel')

    or tree_sortkey like (select o.tree_sortkey + '%' 

                            from acs_object_types o

                           where o.object_type = 'membership_rel')
[MSSQL]
create view comp_or_member_rel_types as 

select  object_type  as rel_type 

   

  from acs_object_types  

   WHERE tree_sortkey  like ( 

select  o.tree_sortkey  + '%'   

   

  from acs_object_types o 

   WHERE o.object_type  = 'composition_rel'  

   

    ) or tree_sortkey  like ( 

select  o.tree_sortkey  + '%'   

   

  from acs_object_types o 

   WHERE o.object_type  = 'membership_rel'  

   

    ) 

   

   

 
[PG]
create view group_rel_type_combos as 

select groups.group_id, comp_or_member_rel_types.rel_type

       from groups, comp_or_member_rel_types
[MSSQL]
create view group_rel_type_combos as 

select  groups.group_id  , comp_or_member_rel_types.rel_type   

   

  from groups ,

	comp_or_member_rel_types  

   

   

   

 
[PG]
create view parties_in_required_segs as 

select required_segs.group_id, 

           required_segs.rel_type, 

           seg_parties.party_id,

           count(*) as num_matching_segs

    from rc_required_rel_segments required_segs,

         rel_segment_party_map seg_parties

    where required_segs.required_rel_segment = seg_parties.segment_id

    group by required_segs.group_id, 

             required_segs.rel_type, 

             seg_parties.party_id
[MSSQL]
create view parties_in_required_segs as 

select  required_segs.group_id  , required_segs.rel_type  , seg_parties.party_id  , count ( * )  as num_matching_segs 

   

  from rc_required_rel_segments required_segs,

	rel_segment_party_map seg_parties 

   WHERE required_segs.required_rel_segment  = seg_parties.segment_id  

  group by required_segs.group_id ,

	required_segs.rel_type ,

	seg_parties.party_id  

   

 
[PG]
create view total_num_required_segs as 

select group_id, rel_type, count(*) as total

  from rc_required_rel_segments

 group by group_id, rel_type
[MSSQL]
create view total_num_required_segs as 

select  group_id  , rel_type  , count ( * )  as total 

   

  from rc_required_rel_segments  

   

  group by group_id ,

	rel_type  

   

 
[PG]
create view rc_parties_in_required_segs as

select parties_in_required_segs.group_id,

       parties_in_required_segs.rel_type,

       parties_in_required_segs.party_id

from

    parties_in_required_segs,

    total_num_required_segs

where

      parties_in_required_segs.group_id = total_num_required_segs.group_id

  and parties_in_required_segs.rel_type = total_num_required_segs.rel_type

  and parties_in_required_segs.num_matching_segs = total_num_required_segs.total

UNION ALL

select group_rel_type_combos.group_id,

       group_rel_type_combos.rel_type,

       parties.party_id

from (rc_required_rel_segments right outer join group_rel_type_combos 

      on 

        (rc_required_rel_segments.group_id = group_rel_type_combos.group_id 

         and 

         rc_required_rel_segments.rel_type = group_rel_type_combos.rel_type)),

         parties

where rc_required_rel_segments.group_id is null
[MSSQL]
create view rc_parties_in_required_segs as 

select  parties_in_required_segs.group_id  , parties_in_required_segs.rel_type  , parties_in_required_segs.party_id   

   

  from parties_in_required_segs ,

	total_num_required_segs  

   WHERE parties_in_required_segs.group_id  = total_num_required_segs.group_id  and parties_in_required_segs.rel_type  = total_num_required_segs.rel_type  and parties_in_required_segs.num_matching_segs  = total_num_required_segs.total  

   

   UNION ALL 

select  group_rel_type_combos.group_id  , group_rel_type_combos.rel_type  , parties.party_id   

   

  from ( rc_required_rel_segments  right outer join group_rel_type_combos  on ( rc_required_rel_segments.group_id  = group_rel_type_combos.group_id  and rc_required_rel_segments.rel_type  = group_rel_type_combos.rel_type  ) ),

	parties  

   WHERE rc_required_rel_segments.group_id  is null  

   

    

 
[PG]
create view side_one_constraints as 

select required_segs.group_id, 

               required_segs.rel_type, 

               count(*) as num_satisfied

          from rc_all_constraints required_segs,

               rel_segment_party_map map

         where required_segs.rel_side = 'one'

           and required_segs.required_rel_segment = map.segment_id

           and required_segs.group_id = map.party_id

        group by required_segs.group_id, 

                 required_segs.rel_type
[MSSQL]
create view side_one_constraints as 

select  required_segs.group_id  , required_segs.rel_type  , count ( * )  as num_satisfied 

   

  from rc_all_constraints required_segs,

	rel_segment_party_map map 

   WHERE required_segs.rel_side  = 'one'  and required_segs.required_rel_segment  = map.segment_id  and required_segs.group_id  = map.party_id  

  group by required_segs.group_id ,

	required_segs.rel_type  

   

 
[PG]
create view total_side_one_constraints as 

select group_id, rel_type, count(*) as total

  from rc_all_constraints

 where rel_side = 'one'

 group by group_id, rel_type
[MSSQL]
create view total_side_one_constraints as 

select  group_id  , rel_type  , count ( * )  as total 

   

  from rc_all_constraints  

   WHERE rel_side  = 'one'  

  group by group_id ,

	rel_type  

   

 
[PG]
create view rc_all_constraints_view as 

select * from rc_all_constraints where rel_side='one'
[MSSQL]
create view rc_all_constraints_view as 

select  *  

   

  from rc_all_constraints  

   WHERE rel_side  = 'one'  

   

   

 
[PG]
create view rc_valid_rel_types as

select side_one_constraints.group_id, 

       side_one_constraints.rel_type

  from side_one_constraints,

       total_side_one_constraints

 where side_one_constraints.group_id = total_side_one_constraints.group_id

   and side_one_constraints.rel_type = total_side_one_constraints.rel_type

   and side_one_constraints.num_satisfied = total_side_one_constraints.total

UNION ALL

select group_rel_type_combos.group_id,

       group_rel_type_combos.rel_type

from rc_all_constraints_view right outer join group_rel_type_combos

      on 

     (rc_all_constraints_view.group_id = group_rel_type_combos.group_id and 

      rc_all_constraints_view.rel_type = group_rel_type_combos.rel_type)

where rc_all_constraints_view.group_id is null
[MSSQL]
create view rc_valid_rel_types as 

select  side_one_constraints.group_id  , side_one_constraints.rel_type   

   

  from side_one_constraints ,

	total_side_one_constraints  

   WHERE side_one_constraints.group_id  = total_side_one_constraints.group_id  and side_one_constraints.rel_type  = total_side_one_constraints.rel_type  and side_one_constraints.num_satisfied  = total_side_one_constraints.total  

   

   UNION ALL 

select  group_rel_type_combos.group_id  , group_rel_type_combos.rel_type   

   

  from rc_all_constraints_view  right outer join group_rel_type_combos  on ( rc_all_constraints_view.group_id  = group_rel_type_combos.group_id  and rc_all_constraints_view.rel_type  = group_rel_type_combos.rel_type  ) 

   WHERE rc_all_constraints_view.group_id  is null  

   

    

 
[PG]
create view rc_violations_by_removing_rel as

select r.rel_type as viol_rel_type, r.rel_id as viol_rel_id, 

       r.object_id_one as viol_object_id_one, r.object_id_two as viol_object_id_two,

       s.rel_id,

       cons.constraint_id, cons.constraint_name,

       map.segment_id, map.party_id, map.group_id, map.container_id, map.ancestor_rel_type

  from acs_rels r, rel_segment_party_map map, rel_constraints cons,

               (select s.segment_id, r.rel_id, r.object_id_two

                  from rel_segments s, acs_rels r

                 where r.object_id_one = s.group_id

                   and r.rel_type = s.rel_type) s

 where map.party_id = r.object_id_two

   and map.rel_id = r.rel_id

   and r.object_id_two = s.object_id_two

   and cons.rel_segment = map.segment_id

   and cons.required_rel_segment = s.segment_id
[MSSQL]
create view rc_violations_by_removing_rel as 

select  r.rel_type  as viol_rel_type, r.rel_id  as viol_rel_id, r.object_id_one  as viol_object_id_one, r.object_id_two  as viol_object_id_two, s.rel_id  , cons.constraint_id  , cons.constraint_name  , map.segment_id  , map.party_id  , map.group_id  , map.container_id  , map.ancestor_rel_type   

   

  from acs_rels r,

	rel_segment_party_map map,

	rel_constraints cons,

	( 

select  s.segment_id  , r.rel_id  , r.object_id_two   

   

  from rel_segments s,

	acs_rels r 

   WHERE r.object_id_one  = s.group_id  and r.rel_type  = s.rel_type  

   

    ) s 

   WHERE map.party_id  = r.object_id_two  and map.rel_id  = r.rel_id  and r.object_id_two  = s.object_id_two  and cons.rel_segment  = map.segment_id  and cons.required_rel_segment  = s.segment_id  

   

   

 
[PG]
create table rc_segment_required_seg_map (

    rel_segment 		integer not null

				constraint rc_rel_segment_fk

					references rel_segments (segment_id),

    rel_side                    char(3) not null

				constraint rc_rel_side_ck

					check (rel_side in

					('one', 'two')),

    required_rel_segment	integer not null

				constraint rc_required_rel_segment

					references rel_segments (segment_id),

    constraint rc_segment_required_seg_map_uq

	unique (rel_segment, rel_side, required_rel_segment)

)
[MSSQL]
create table rc_segment_required_seg_map ( rel_segment 		integer not null

				constraint rc_segment_required_rel_segment_fk

					references rel_segments (segment_id),

    rel_side                    char(3) not null

				constraint rc_segment_rel_side_ck

					check (rel_side in

					('one', 'two')),

    required_rel_segment	integer not null

				constraint rc_segment_required_rel_segment

					references rel_segments (segment_id),

    constraint rc_segment_required_seg_map_uq

	unique (rel_segment, rel_side, required_rel_segment)

)




 
[PG]
create index rc_segment_required_seg_idx on 

rc_segment_required_seg_map(required_rel_segment)
[MSSQL]
create index rc_segment_required_seg_idx on 

rc_segment_required_seg_map(required_rel_segment)

 
[PG]
create function rel_constraints_ins_tr () returns opaque as '

declare

        v_rec   record;

begin

        



        insert into rc_segment_required_seg_map

               (rel_segment, rel_side, required_rel_segment)

               values

               (new.rel_segment, new.rel_side, new.required_rel_segment);



        



        insert into rc_segment_required_seg_map

             select new.rel_segment, new.rel_side, required_rel_segment

               from rc_segment_required_seg_map

              where rel_segment = new.required_rel_segment

                and rel_side = new.rel_side;



        

        

        for v_rec in select rel_segment 

                       from rc_segment_required_seg_map

                      where required_rel_segment = new.rel_segment 

                        and rel_side = new.rel_side

        LOOP

                insert into rc_segment_required_seg_map

                     select v_rec.rel_segment, new.rel_side, 

                            required_rel_segment

                       from rc_segment_required_seg_map

                      where rel_segment = new.rel_segment

                        and rel_side = new.rel_side;

                

        end LOOP;



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger rel_constraints_ins_tr after insert 

on rel_constraints for each row 

execute procedure rel_constraints_ins_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function rel_constraints_del_tr () returns opaque as '

declare

        v_rec   record;

begin



        

        

        for v_rec in select rel_segment 

                       from rc_segment_required_seg_map

                      where required_rel_segment = old.rel_segment 

                        and rel_side = old.rel_side

        LOOP



                delete from rc_segment_required_seg_map

                      where rel_segment = v_rec.rel_segment

                        and rel_side = old.rel_side

                        and required_rel_segment 

                            in (select required_rel_segment

                                  from rc_segment_required_seg_map

                                 where rel_segment = old.rel_segment

                                   and rel_side = old.rel_side);

                

        end LOOP;



        



        delete from rc_segment_required_seg_map

              where rel_segment = old.rel_segment

                and rel_side = old.rel_side

                and required_rel_segment 

                    in (select required_rel_segment

                          from rc_segment_required_seg_map

                         where rel_segment = old.required_rel_segment

                           and rel_side = old.rel_side);



        



        delete from rc_segment_required_seg_map

              where rel_segment = old.rel_segment

                and rel_side = old.rel_side 

                and required_rel_segment = old.required_rel_segment;



        return old;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger rel_constraints_del_tr after delete

on rel_constraints for each row 

execute procedure rel_constraints_del_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create view rc_segment_dependency_levels as 

  select rel_segment as segment_id, count(*) as dependency_level

    from rc_segment_required_seg_map

   where rel_side = 'two'

group by segment_id
[MSSQL]
create view rc_segment_dependency_levels as 

select  rel_segment as segment_id, count ( * ) as dependency_level 

   

  from rc_segment_required_seg_map  

   WHERE rel_side = 'two' 

  group by rel_segment 

   

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/groups-body-create.sql
[PG]
drop trigger membership_rels_in_tr on membership_rels
[MSSQL]
drop trigger membership_rels_in_tr
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the trigger 'membership_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
drop function membership_rels_in_tr ()
[MSSQL]
drop proc membership_rels_in_tr
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'membership_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create function membership_rels_in_tr () returns opaque as '

declare

  v_object_id_one acs_rels.object_id_one%TYPE;

  v_object_id_two acs_rels.object_id_two%TYPE;

  v_rel_type      acs_rels.rel_type%TYPE;

  v_error         text;

  map             record;

begin

  

  

  v_error := rel_constraint__violation(new.rel_id);

  if v_error is not null then

      raise EXCEPTION '-20000: %', v_error;

  end if;



  select object_id_one, object_id_two, rel_type

  into v_object_id_one, v_object_id_two, v_rel_type

  from acs_rels

  where rel_id = new.rel_id;



  

  insert into group_element_index

   (group_id, element_id, rel_id, container_id, 

    rel_type, ancestor_rel_type)

  values

   (v_object_id_one, v_object_id_two, new.rel_id, v_object_id_one, 

    v_rel_type, 'membership_rel');



  

  

  for map in select distinct group_id

	      from group_component_map

	      where component_id = v_object_id_one 

  LOOP

    insert into group_element_index

     (group_id, element_id, rel_id, container_id,

      rel_type, ancestor_rel_type)

    values

     (map.group_id, v_object_id_two, new.rel_id, v_object_id_one,

      v_rel_type, 'membership_rel');

  end loop;



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'membership_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create trigger membership_rels_in_tr after insert on membership_rels

for each row execute procedure membership_rels_in_tr ()
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'membership_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
drop trigger composition_rels_in_tr on composition_rels
[MSSQL]
drop trigger composition_rels_in_tr
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the trigger 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
drop function composition_rels_in_tr()
[MSSQL]
drop proc composition_rels_in_tr
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create function composition_rels_in_tr () returns opaque as '

declare

  v_object_id_one acs_rels.object_id_one%TYPE;

  v_object_id_two acs_rels.object_id_two%TYPE;

  v_rel_type      acs_rels.rel_type%TYPE;

  v_error         text;

  map             record;

begin

  

  

  v_error := rel_constraint__violation(new.rel_id);



  if v_error is not null then

      raise EXCEPTION '-20000: %', v_error;

  end if;



  select object_id_one, object_id_two, rel_type

  into v_object_id_one, v_object_id_two, v_rel_type

  from acs_rels

  where rel_id = new.rel_id;



  

  insert into group_element_index

   (group_id, element_id, rel_id, container_id,

    rel_type, ancestor_rel_type)

  values

   (v_object_id_one, v_object_id_two, new.rel_id, v_object_id_one,

    v_rel_type, 'composition_rel');



  

  insert into group_element_index

   (group_id, element_id, rel_id, container_id,

    rel_type, ancestor_rel_type)

  select distinct

   v_object_id_one, element_id, rel_id, container_id,

   rel_type, ancestor_rel_type

  from group_element_map m

  where group_id = v_object_id_two

  and not exists (select 1

		  from group_element_map

		  where group_id = v_object_id_one

		  and element_id = m.element_id

		  and rel_id = m.rel_id);



  

  

  for map in  select distinct group_id

	      from group_component_map

	      where component_id = v_object_id_one 

  LOOP



    

    insert into group_element_index

     (group_id, element_id, rel_id, container_id,

      rel_type, ancestor_rel_type)

    values

     (map.group_id, v_object_id_two, new.rel_id, v_object_id_one,

      v_rel_type, 'composition_rel');



    

    insert into group_element_index

     (group_id, element_id, rel_id, container_id,

      rel_type, ancestor_rel_type)

    select distinct

     map.group_id, element_id, rel_id, container_id,

     rel_type, ancestor_rel_type

    from group_element_map m

    where group_id = v_object_id_two

    and not exists (select 1

		    from group_element_map

		    where group_id = map.group_id

		    and element_id = m.element_id

		    and rel_id = m.rel_id);

  end loop;



  return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create trigger composition_rels_in_tr after insert on composition_rels

for each row execute procedure composition_rels_in_tr ()
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create function membership_rels_del_tr () returns opaque as '

declare

  v_error text;

begin

  

  v_error := rel_constraint__violation_if_removed(old.rel_id);

  if v_error is not null then

      raise EXCEPTION '-20000: %', v_error;

  end if;



  delete from group_element_index

  where rel_id = old.rel_id;



  return old;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create trigger membership_rels_del_tr before delete on membership_rels

for each row execute procedure membership_rels_del_tr ()
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create function composition_rels_del_tr () returns opaque as '

declare

  v_object_id_one acs_rels.object_id_one%TYPE;

  v_object_id_two acs_rels.object_id_two%TYPE;

  n_rows          integer;

  v_error         text;

  map             record;

begin

  

  v_error := rel_constraint__violation_if_removed(old.rel_id);

  if v_error is not null then

      raise EXCEPTION '-20000: %', v_error;

  end if;



  select object_id_one, object_id_two into v_object_id_one, v_object_id_two

  from acs_rels

  where rel_id = old.rel_id;



  for map in  select *

	      from group_component_map

	      where rel_id = old.rel_id 

  LOOP



    delete from group_element_index

    where rel_id = old.rel_id;



    select count(*) into n_rows

    from group_component_map

    where group_id = map.group_id

    and component_id = map.component_id;



    if n_rows = 0 then

      delete from group_element_index

      where group_id = map.group_id

      and container_id = map.component_id

      and ancestor_rel_type = 'membership_rel';

    end if;



  end loop;





  for map in  select *

              from group_component_map

	      where group_id in (select group_id

		               from group_component_map

		               where component_id = v_object_id_one

			       union

			       select v_object_id_one

			       from dual)

              and component_id in (select component_id

			           from group_component_map

			           where group_id = v_object_id_two

				   union

				   select v_object_id_two

				   from dual)

              and group_contains_p(group_id, component_id, rel_id) = 'f' 

  LOOP



    delete from group_element_index

    where group_id = map.group_id

    and element_id = map.component_id

    and rel_id = map.rel_id;



    select count(*) into n_rows

    from group_component_map

    where group_id = map.group_id

    and component_id = map.component_id;



    if n_rows = 0 then

      delete from group_element_index

      where group_id = map.group_id

      and container_id = map.component_id

      and ancestor_rel_type = 'membership_rel';

    end if;



  end loop;



  return old;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create trigger composition_rels_del_tr before delete on composition_rels

for each row execute procedure composition_rels_del_tr ()
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the procedure 'composition_rels_in_tr', because it does not exist in the system catalog.

 
[PG]
create function composition_rel__new (integer,varchar,integer,integer,integer,varchar)

returns integer as '

declare

  new__rel_id            alias for $1;  

  rel_type               alias for $2;  

  object_id_one          alias for $3;  

  object_id_two          alias for $4;  

  creation_user          alias for $5;  

  creation_ip            alias for $6;  

  v_rel_id               integer;       

begin

    v_rel_id := acs_rel__new (

      new__rel_id,

      rel_type,

      object_id_one,

      object_id_two,

      object_id_one,

      creation_user,

      creation_ip

    );



    insert into composition_rels

     (rel_id)

    values

     (v_rel_id);



    return v_rel_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC composition_rel__new

	@new__rel_id		integer,

	@rel_type		varchar(8000),

	@object_id_one		integer,

	@object_id_two		integer,

	@creation_user		integer,

	@creation_ip		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_rel_id	integer



EXEC dbo.acs_rel__new @new__rel_id ,

  	@rel_type ,

  	@object_id_one ,

  	@object_id_two ,

  	@object_id_one ,

  	@creation_user ,

  	@creation_ip , @ms_return_value = @v_rel_id OUTPUT

  

   

  insert into composition_rels ( rel_id ) values ( @v_rel_id   )

   

  SET @ms_return_value = @v_rel_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function composition_rel__new (integer,integer)

returns integer as '

declare

  object_id_one          alias for $1;  

  object_id_two          alias for $2;  

begin

        return composition_rel__new(null,

                                    'composition_rel',

                                    object_id_one,

                                    object_id_two,

                                    null,

                                    null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC composition_rel__new_2

	@object_id_one		integer,

	@object_id_two		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.composition_rel__new ( null ,

  	'composition_rel' ,

  	@object_id_one ,

  	@object_id_two ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function composition_rel__delete (integer)

returns integer as '

declare

  rel_id                 alias for $1;  

begin

    PERFORM acs_rel__delete(rel_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC composition_rel__delete

	@rel_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_rel__delete @rel_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function composition_rel__check_path_exists_p (integer,integer)

returns boolean as '

declare

  component_id           alias for $1;  

  container_id           alias for $2;  

  row                    record;

begin

    if component_id = container_id then

      return 't';

    end if;



    for row in  select r.object_id_one as parent_id

                from acs_rels r, composition_rels c

                where r.rel_id = c.rel_id

                and r.object_id_two = component_id 

    LOOP

      if composition_rel__check_path_exists_p(row.parent_id, container_id) = 't' then

        return 't';

      end if;

    end loop;



    return 'f';

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION composition_rel__check_path_exists_p(@component_id		integer,

	@container_id		integer) 

RETURNS boolean

AS

BEGIN

declare @row__r.object_id_one  as parent_id	int



IF @component_id  = @container_id  BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  r.object_id_one  as parent_id 

     

    from acs_rels r,

  	composition_rels c 

     WHERE r.rel_id  = c.rel_id  and r.object_id_two  = @component_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__r.object_id_one  as parent_id

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.composition_rel__check_path_exists_p ( row.parent_id ,

    	@container_id  )  = 't'  BEGIN

    RETURN 't'

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @row__r.object_id_one  as parent_id

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   RETURN 'f'

  



RETURN NULL -- placeholder required by tsql

END -- function

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 7: Incorrect syntax near '.'.

 
[PG]
create function composition_rel__check_index (integer,integer)

returns boolean as '

declare

  check_index__component_id           alias for $1;  

  check_index__container_id           alias for $2;  

  result                              boolean;       

  n_rows                              integer;       

  dc                                  record;

  r1                                  record;

  r2                                  record;

begin

    result := 't';



    

    

    

    

    for dc in  select r.rel_id, r.object_id_one as container_id

               from acs_rels r, composition_rels c

               where r.rel_id = c.rel_id

               and r.object_id_two = check_index__component_id 

    LOOP



      if composition_rel__check_path_exists_p(dc.container_id,

                             check_index__container_id) = 't' then

        select case when count(*) = 0 then 0 else 1 end into n_rows

        from group_component_index

        where group_id = check_index__container_id

        and component_id = check_index__component_id

        and rel_id = dc.rel_id;



        if n_rows = 0 then

          result := 'f';

          PERFORM acs_log__error('composition_rel.check_representation',

                        'Row missing from group_component_index for (' +

                        'group_id = ' + check_index__container_id + ', ' +

                        'component_id = ' + check_index__component_id + ', ' +

                        'rel_id = ' + dc.rel_id + ')');

        end if;



      end if;



    end loop;



    

    for r1 in  select r.object_id_one as container_id

               from acs_rels r, composition_rels c

               where r.rel_id = c.rel_id

               and r.object_id_two = check_index__container_id

               union

               select check_index__container_id as container_id

               from dual 

    LOOP

      

      

      for r2 in  select r.object_id_two as component_id

                 from acs_rels r, composition_rels c

                 where r.rel_id = c.rel_id

                 and r.object_id_one = check_index__component_id

                 union

                 select check_index__component_id as component_id

                 from dual 

      LOOP

        if (r1.container_id != check_index__container_id or

            r2.component_id != check_index__component_id) and

           composition_rel__check_index(r2.component_id, r1.container_id) = 'f' then

          result := 'f';

        end if;

      end loop;

    end loop;



    return result;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 7: Incorrect syntax near '.'.

 
[PG]
create function composition_rel__check_representation (integer)

returns boolean as '

declare

  check_representation__rel_id                 alias for $1;  

  container_id                                 groups.group_id%TYPE;

  component_id                                 groups.group_id%TYPE;

  result                                       boolean;     

  row                                          record;  

begin

    result := 't';



    if acs_object__check_representation(check_representation__rel_id) = 'f' then

      result := 'f';

    end if;



    select object_id_one, object_id_two

    into container_id, component_id

    from acs_rels

    where rel_id = check_representation__rel_id;



    

    if composition_rel__check_index(component_id, container_id) = 'f' then

      result := 'f';

    end if;



    

    

    for row in  select *

                from group_component_index

                where rel_id = check_representation__rel_id  

    LOOP

      if composition_rel__check_path_exists_p(row.component_id, row.group_id) = 'f' then

        result := 'f';

        PERFORM acs_log__error('composition_rel.check_representation',

                      'Extraneous row in group_component_index: ' +

                      'group_id = ' + row.group_id + ', ' +

                      'component_id = ' + row.component_id + ', ' +

                      'rel_id = ' + row.rel_id + ', ' +

                      'container_id = ' + row.container_id + '.');

      end if;

    end loop;



    return result;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC composition_rel__check_representation

	@check_representation__rel_id		integer, 

	@ms_return_value	boolean =  OUTPUT 

AS

BEGIN

declare @result	boolean

declare @row__object_id_one  	int

declare @component_id	int

declare @row__object_id_two  	int

declare @container_id	int



SET @result = 't' 

  

   IF dbo.acs_object__check_representation ( @check_representation__rel_id  )  = 'f'  BEGIN

  SET @result = 'f' 

    

    

  END --IF

  

  

   

  select   @container_id = object_id_one  ,

   @component_id = object_id_two   

     

    from acs_rels  

     WHERE rel_id  = @check_representation__rel_id  

     

     

   IF dbo.composition_rel__check_index ( @component_id ,

  	@container_id  )  = 'f'  BEGIN

  SET @result = 'f' 

    

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  *  

     

    from group_component_index  

     WHERE rel_id  = @check_representation__rel_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__object_id_one  , @row__object_id_two  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.composition_rel__check_path_exists_p ( row.component_id ,

    	row.group_id  )  = 'f'  BEGIN

    SET @result = 'f' 

      

       EXEC dbo.acs_log__error 'composition_rel.check_representation' ,

      	'Extraneous row in group_component_index: '  + 'group_id = '  + row.group_id  + ', '  + 'component_id = '  + row.component_id  + ', '  + 'rel_id = '  + row.rel_id  + ', '  + 'container_id = '  + row.container_id  + '.'  

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @row__object_id_one  , @row__object_id_two  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  SET @ms_return_value = @result  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 59: Incorrect syntax near '+'.

 
[PG]
create function membership_rel__new (integer,varchar,integer,integer,varchar,integer,varchar)

returns integer as '

declare

  new__rel_id            alias for $1;  

  rel_type               alias for $2;  

  object_id_one          alias for $3;  

  object_id_two          alias for $4;  

  new__member_state      alias for $5;  

  creation_user          alias for $6;  

  creation_ip            alias for $7;  

  v_rel_id               integer;       

begin

    v_rel_id := acs_rel__new (

      new__rel_id,

      rel_type,

      object_id_one,

      object_id_two,

      object_id_one,

      creation_user,

      creation_ip

    );



    insert into membership_rels

     (rel_id, member_state)

    values

     (v_rel_id, new__member_state);



    return v_rel_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC membership_rel__new

	@new__rel_id		integer,

	@rel_type		varchar(8000),

	@object_id_one		integer,

	@object_id_two		integer,

	@new__member_state		varchar(8000),

	@creation_user		integer,

	@creation_ip		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_rel_id	integer



EXEC dbo.acs_rel__new @new__rel_id ,

  	@rel_type ,

  	@object_id_one ,

  	@object_id_two ,

  	@object_id_one ,

  	@creation_user ,

  	@creation_ip , @ms_return_value = @v_rel_id OUTPUT

  

   

  insert into membership_rels ( rel_id, member_state ) values ( @v_rel_id  , @new__member_state   )

   

  SET @ms_return_value = @v_rel_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function membership_rel__new (integer,integer)

returns integer as '

declare

  object_id_one          alias for $1;  

  object_id_two          alias for $2;  

begin

        return membership_rel__new(null,

                                   'membership_rel',

                                   object_id_one,

                                   object_id_two,

                                   'approved',

                                   null,

                                   null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC membership_rel__new_2

	@object_id_one		integer,

	@object_id_two		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.membership_rel__new ( null ,

  	'membership_rel' ,

  	@object_id_one ,

  	@object_id_two ,

  	'approved' ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function membership_rel__ban (integer)

returns integer as '

declare

  ban__rel_id           alias for $1;  

begin

    update membership_rels

    set member_state = 'banned'

    where rel_id = ban__rel_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function membership_rel__approve (integer)

returns integer as '

declare

  approve__rel_id               alias for $1;  

begin

    update membership_rels

    set member_state = 'approved'

    where rel_id = approve__rel_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function membership_rel__reject (integer)

returns integer as '

declare

  reject__rel_id                alias for $1;  

begin

    update membership_rels

    set member_state = 'rejected'

    where rel_id = reject__rel_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function membership_rel__unapprove (integer)

returns integer as '

declare

  unapprove__rel_id             alias for $1;  

begin

    update membership_rels

    set member_state = 'need approval'

    where rel_id = unapprove__rel_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function membership_rel__deleted (integer)

returns integer as '

declare

  deleted__rel_id               alias for $1;  

begin

    update membership_rels

    set member_state = 'deleted'

    where rel_id = deleted__rel_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function membership_rel__delete (integer)

returns integer as '

declare

  rel_id                 alias for $1;  

begin

    PERFORM acs_rel__delete(rel_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC membership_rel__delete

	@rel_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_rel__delete @rel_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function membership_rel__check_index (integer,integer,integer)

returns boolean as '

declare

  check_index__group_id               alias for $1;  

  check_index__member_id              alias for $2;  

  check_index__container_id           alias for $3;  

  result                              boolean;       

  n_rows                              integer;       

  row                                 record;

begin



    select count(*) into n_rows

    from group_member_index

    where group_id = check_index__group_id

    and member_id = check_index__member_id

    and container_id = check_index__container_id;



    if n_rows = 0 then

      result := 'f';

      PERFORM acs_log__error('membership_rel.check_representation',

                    'Row missing from group_member_index: ' +

                    'group_id = ' + check_index__group_id + ', ' +

                    'member_id = ' + check_index__member_id + ', ' +

                    'container_id = ' + check_index__container_id + '.');

    end if;



    for row in  select r.object_id_one as container_id

                from acs_rels r, composition_rels c

                where r.rel_id = c.rel_id

                and r.object_id_two = check_index__group_id  

    LOOP

      if membership_rel__check_index(row.container_id, check_index__member_id, check_index__container_id) = 'f' then

        result := 'f';

      end if;

    end loop;



    return result;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC membership_rel__check_index

	@check_index__group_id		integer,

	@check_index__member_id		integer,

	@check_index__container_id		integer, 

	@ms_return_value	boolean =  OUTPUT 

AS

BEGIN

declare @result	boolean

declare @n_rows	integer

declare @row__count ( * )  	varchar(8000)





  select   @n_rows = count ( * )   

     

    from group_member_index  

     WHERE group_id  = @check_index__group_id  and member_id  = @check_index__member_id  and container_id  = @check_index__container_id  

     

     

   IF @n_rows  = 0  BEGIN

  SET @result = 'f' 

    

     EXEC dbo.acs_log__error 'membership_rel.check_representation' ,

    	'Row missing from group_member_index: '  + 'group_id = '  + @check_index__group_id  + ', '  + 'member_id = '  + @check_index__member_id  + ', '  + 'container_id = '  + @check_index__container_id  + '.'  

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  r.object_id_one  as container_id 

     

    from acs_rels r,

  	composition_rels c 

     WHERE r.rel_id  = c.rel_id  and r.object_id_two  = @check_index__group_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__count ( * )  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.membership_rel__check_index ( row.container_id ,

    	@check_index__member_id ,

    	@check_index__container_id  )  = 'f'  BEGIN

    SET @result = 'f' 

      

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @row__count ( * )  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  SET @ms_return_value = @result  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 11: Incorrect syntax near '('.

 
[PG]
create function membership_rel__check_representation (integer)

returns boolean as '

declare

  check_representation__rel_id  alias for $1;  

  group_id                      groups.group_id%TYPE;

  member_id                     parties.party_id%TYPE;

  result                        boolean;  

  row                           record;     

begin

    result := 't';



    if acs_object__check_representation(check_representation__rel_id) = 'f' then

      result := 'f';

    end if;



    select r.object_id_one, r.object_id_two

    into group_id, member_id

    from acs_rels r, membership_rels m

    where r.rel_id = m.rel_id

    and m.rel_id = check_representation__rel_id;



    if membership_rel__check_index(group_id, member_id, group_id) = 'f' then

      result := 'f';

    end if;



    for row in  select *

                from group_member_index

                where rel_id = check_representation__rel_id 

    LOOP

      if composition_rel__check_path_exists_p(row.container_id,

                                             row.group_id) = 'f' then

        result := 'f';

        PERFORM acs_log__error('membership_rel.check_representation',

                      'Extra row in group_member_index: ' +

                      'group_id = ' + row.group_id + ', ' +

                      'member_id = ' + row.member_id + ', ' +

                      'container_id = ' + row.container_id + '.');

      end if;

    end loop;



    return result;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC membership_rel__check_representation

	@check_representation__rel_id		integer, 

	@ms_return_value	boolean =  OUTPUT 

AS

BEGIN

declare @row__r.object_id_two  	int

declare @result	boolean

declare @row__r.object_id_one  	int

declare @member_id	int

declare @group_id	int



SET @result = 't' 

  

   IF dbo.acs_object__check_representation ( @check_representation__rel_id  )  = 'f'  BEGIN

  SET @result = 'f' 

    

    

  END --IF

  

  

   

  select   @group_id = r.object_id_one  ,

   @member_id = r.object_id_two   

     

    from acs_rels r,

  	membership_rels m 

     WHERE r.rel_id  = m.rel_id  and m.rel_id  = @check_representation__rel_id  

     

     

   IF dbo.membership_rel__check_index ( @group_id ,

  	@member_id ,

  	@group_id  )  = 'f'  BEGIN

  SET @result = 'f' 

    

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  *  

     

    from group_member_index  

     WHERE rel_id  = @check_representation__rel_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__r.object_id_one  , @row__r.object_id_two  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.composition_rel__check_path_exists_p ( row.container_id ,

    	row.group_id  )  = 'f'  BEGIN

    SET @result = 'f' 

      

       EXEC dbo.acs_log__error 'membership_rel.check_representation' ,

      	'Extra row in group_member_index: '  + 'group_id = '  + row.group_id  + ', '  + 'member_id = '  + row.member_id  + ', '  + 'container_id = '  + row.container_id  + '.'  

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @row__r.object_id_one  , @row__r.object_id_two  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  SET @ms_return_value = @result  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 7: Incorrect syntax near '.'.

 
[PG]
create function acs_group__new (integer,varchar,timestamp,integer,varchar,varchar,varchar,varchar,varchar,integer)

returns integer as '

declare

  new__group_id              alias for $1;  

  new__object_type           alias for $2;  

  new__creation_date         alias for $3;  

  new__creation_user         alias for $4;  

  new__creation_ip           alias for $5;  

  new__email                 alias for $6;  

  new__url                   alias for $7;  

  new__group_name            alias for $8;  

  new__join_policy           alias for $9;  

  new__context_id            alias for $10; 

  v_group_id                 groups.group_id%TYPE;

  v_group_type_exists_p      integer;

  v_join_policy              groups.join_policy%TYPE;

begin

  v_group_id :=

   party__new(new__group_id, new__object_type, new__creation_date, 

              new__creation_user, new__creation_ip, new__email, 

              new__url, new__context_id);



  v_join_policy := new__join_policy;



  

  if v_join_policy is null or v_join_policy = '' then

      select count(*) into v_group_type_exists_p

      from group_types

      where group_type = new__object_type;



      if v_group_type_exists_p = 1 then

          select default_join_policy into v_join_policy

          from group_types

          where group_type = new__object_type;

      else

          v_join_policy := 'open';

      end if;

  end if;



  insert into groups

   (group_id, group_name, join_policy)

  values

   (v_group_id, new__group_name, v_join_policy);



  

  insert into group_rels

  (group_rel_id, group_id, rel_type)

  select acs_object_id_seq.nextval, v_group_id, g.rel_type

    from group_type_rels g

   where g.group_type = new__object_type;



  return v_group_id;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_group__new

	@new__group_id		integer,

	@new__object_type		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__email		varchar(8000),

	@new__url		varchar(8000),

	@new__group_name		varchar(8000),

	@new__join_policy		varchar(8000),

	@new__context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_join_policy	varchar(8000)

declare @v_group_type_exists_p	integer

declare @v_group_id	int

declare @retval	int



EXEC dbo.party__new @new__group_id ,

  	@new__object_type ,

  	@new__creation_date ,

  	@new__creation_user ,

  	@new__creation_ip ,

  	@new__email ,

  	@new__url ,

  	@new__context_id , @ms_return_value = @v_group_id OUTPUT

  

   SET @v_join_policy = @new__join_policy 

  

   IF @v_join_policy  is null  or @v_join_policy  = ''  BEGIN

  

    select   @v_group_type_exists_p = count ( * )   

       

      from group_types  

       WHERE group_type  = @new__object_type  

       

       

     IF @v_group_type_exists_p  = 1  BEGIN

    

      select   @v_join_policy = default_join_policy   

         

        from group_types  

         WHERE group_type  = @new__object_type  

         

         

      END

    ELSE BEGIN

    SET @v_join_policy = 'open' 

      

      

    END --IF

    

    

    

  END --IF

  

  

   

  insert into groups ( group_id, group_name, join_policy ) values ( @v_group_id  , @new__group_name  , @v_join_policy   )

   

  insert into group_rels ( group_rel_id, group_id, rel_type ) exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  select  @retval  , @v_group_id  , g.rel_type   

     

    from group_type_rels g 

     WHERE g.group_type  = @new__object_type  

     

     

   

  SET @ms_return_value = @v_group_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_group__new (varchar) returns integer as '

declare

        gname   alias for $1;

begin

        return acs_group__new(null,

                              'group',

                              now(),

                              null,

                              null,

                              null,

                              null,

                              gname,

                              null,

                              null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_group__new_1

	@gname		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.acs_group__new ( null ,

  	'group' ,

  	getdate() ,

  	null ,

  	null ,

  	null ,

  	null ,

  	@gname ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_group__delete (integer)

returns integer as '

declare

  delete__group_id              alias for $1;  

  row                           record;

begin

 

   

   for row in  select segment_id 

                 from rel_segments 

                where group_id = delete__group_id 

   LOOP

       PERFORM rel_segment__delete(row.segment_id);

   end loop;



   

   for row in select r.rel_id, t.package_name

                 from acs_rels r, acs_object_types t

                where r.rel_type = t.object_type

                  and (r.object_id_one = delete__group_id

                       or r.object_id_two = delete__group_id) 

   LOOP

      execute 'select ' +  row.package_name + '__delete(' + row.rel_id + ')';

   end loop;

 

   PERFORM party__delete(delete__group_id);



   return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_group__name (integer)

returns varchar as '

declare

  name__group_id         alias for $1;  

  name__group_name       varchar(200);  

begin

  select group_name

  into name__group_name

  from groups

  where group_id = name__group_id;



  return name__group_name;

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_group__name(@name__group_id		integer) 

RETURNS varchar

AS

BEGIN

declare @name__group_name	varchar ( 200 )





  select   @name__group_name = group_name   

     

    from groups  

     WHERE group_id  = @name__group_id  

     

     

   RETURN CONVERT (varchar, @name__group_name )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_group__member_p (integer)

returns boolean as '

declare

  party_id               alias for $1;  

begin

  

  return 't';

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_group__member_p(@party_id		integer) 

RETURNS boolean

AS

BEGIN



RETURN 't'

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function acs_group__check_representation (integer)

returns boolean as '

declare

  group_id               alias for $1;  

  res                    boolean; 

  comp                   record;

  memb                   record;      

begin

   res := 't';

   PERFORM acs_log__notice('acs_group.check_representation',

                  'Running check_representation on group ' + group_id);



   if acs_object__check_representation(group_id) = 'f' then

     res := 'f';

   end if;



   for comp in select c.rel_id

             from acs_rels r, composition_rels c

             where r.rel_id = c.rel_id

             and r.object_id_one = group_id 

   LOOP

     if composition_rel__check_representation(comp.rel_id) = 'f' then

       res := 'f';

     end if;

   end loop;



   for memb in  select m.rel_id

             from acs_rels r, membership_rels m

             where r.rel_id = m.rel_id

             and r.object_id_one = group_id 

   LOOP

     if membership_rel__check_representation(memb.rel_id) = 'f' then

       res := 'f';

     end if;

   end loop;



   PERFORM acs_log__notice('acs_group.check_representation',

                  'Done running check_representation on group ' + group_id);



   return res;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_group__check_representation

	@group_id		integer, 

	@ms_return_value	boolean =  OUTPUT 

AS

BEGIN

declare @res	boolean

declare @memb__m.rel_id  	int

declare @comp__c.rel_id  	int



SET @res = 't' 

  

   EXEC dbo.acs_log__notice 'acs_group.check_representation' ,

  	'Running check_representation on group '  + @group_id  

   IF dbo.acs_object__check_representation ( @group_id  )  = 'f'  BEGIN

  SET @res = 'f' 

    

    

  END --IF

  

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  c.rel_id   

     

    from acs_rels r,

  	composition_rels c 

     WHERE r.rel_id  = c.rel_id  and r.object_id_one  = @group_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @comp__c.rel_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.composition_rel__check_representation ( comp.rel_id  )  = 'f'  BEGIN

    SET @res = 'f' 

      

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_1 INTO @comp__c.rel_id  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  DECLARE cursor_2 CURSOR FOR

    

  select  m.rel_id   

     

    from acs_rels r,

  	membership_rels m 

     WHERE r.rel_id  = m.rel_id  and r.object_id_one  = @group_id  

     

     

  

  OPEN cursor_2

  

  FETCH NEXT FROM cursor_2 INTO @memb__m.rel_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  IF dbo.membership_rel__check_representation ( memb.rel_id  )  = 'f'  BEGIN

    SET @res = 'f' 

      

      

    END --IF

    

    

    

  

    FETCH NEXT FROM cursor_2 INTO @memb__m.rel_id  

  END --while

  

  CLOSE cursor_2

  

  DEALLOCATE cursor_2

  

  

   EXEC dbo.acs_log__notice 'acs_group.check_representation' ,

  	'Done running check_representation on group '  + @group_id  

   

  SET @ms_return_value = @res  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 8: Incorrect syntax near '.'.

 
[PG]
  
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 8: Incorrect syntax near '.'.

 
File packages/acs-kernel/sql/postgresql/rel-segments-body-create.sql
[PG]
create function rel_segment__new (integer,varchar,timestamp,integer,varchar,varchar,varchar,varchar,integer,varchar,integer)

returns integer as '

declare

  new__segment_id        alias for $1;  

  object_type            alias for $2;  

  creation_date          alias for $3;  

  creation_user          alias for $4;  

  creation_ip            alias for $5;  

  email                  alias for $6;  

  url                    alias for $7;  

  new__segment_name      alias for $8;  

  new__group_id          alias for $9;  

  new__rel_type          alias for $10; 

  context_id             alias for $11; 

  v_segment_id           rel_segments.segment_id%TYPE;

begin

  v_segment_id :=

   party__new(new__segment_id, object_type, creation_date, creation_user,

             creation_ip, email, url, context_id);



  insert into rel_segments

   (segment_id, segment_name, group_id, rel_type)

  values

   (v_segment_id, new__segment_name, new__group_id, new__rel_type);



  return v_segment_id;

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_segment__new

	@new__segment_id		integer,

	@object_type		varchar(8000),

	@creation_date		varchar(50),

	@creation_user		integer,

	@creation_ip		varchar(8000),

	@email		varchar(8000),

	@url		varchar(8000),

	@new__segment_name		varchar(8000),

	@new__group_id		integer,

	@new__rel_type		varchar(8000),

	@context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_segment_id	int



EXEC dbo.party__new @new__segment_id ,

  	@object_type ,

  	@creation_date ,

  	@creation_user ,

  	@creation_ip ,

  	@email ,

  	@url ,

  	@context_id , @ms_return_value = @v_segment_id OUTPUT

  

   

  insert into rel_segments ( segment_id, segment_name, group_id, rel_type ) values ( @v_segment_id  , @new__segment_name  , @new__group_id  , @new__rel_type   )

   

  SET @ms_return_value = @v_segment_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function rel_segment__delete (integer)

returns integer as '

declare

  delete__segment_id            alias for $1;  

  row                           record;

begin



   

   for row in  select constraint_id 

                 from rel_constraints 

                where rel_segment = delete__segment_id 

   LOOP



       PERFORM rel_constraint__delete(row.constraint_id);



   end loop;



   PERFORM party__delete(delete__segment_id);



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_segment__delete

	@delete__segment_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @row__constraint_id  	int





  DECLARE cursor_1 CURSOR FOR

    

  select  constraint_id   

     

    from rel_constraints  

     WHERE rel_segment  = @delete__segment_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @row__constraint_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.rel_constraint__delete @row__constraint_id  

    

  

    FETCH NEXT FROM cursor_1 INTO @row__constraint_id  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   EXEC dbo.party__delete @delete__segment_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function rel_segment__get (integer,varchar)

returns integer as '

declare

  get__group_id         alias for $1;  

  get__rel_type         alias for $2;  

  v_segment_id          rel_segments.segment_id%TYPE;

begin

   select min(segment_id) into v_segment_id

   from rel_segments

   where group_id = get__group_id

     and rel_type = get__rel_type;



   return v_segment_id;

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION rel_segment__get(@get__group_id		integer,

	@get__rel_type		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_segment_id	int





  select   @v_segment_id = min ( segment_id  )   

     

    from rel_segments  

     WHERE group_id  = @get__group_id  and rel_type  = @get__rel_type  

     

     

   RETURN CONVERT (integer, @v_segment_id )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function rel_segment__get_or_new(integer,varchar) returns integer as '

declare

        gid     alias for $1;

        typ     alias for $2;

begin

        return rel_segment__get_or_new(gid,typ,null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_segment__get_or_new

	@gid		integer,

	@typ		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.rel_segment__get_or_new ( @gid ,

  	@typ ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function rel_segment__get_or_new (integer,varchar,varchar)

returns integer as '

declare

  get_or_new__group_id          alias for $1;  

  get_or_new__rel_type          alias for $2;  

  segment_name                  alias for $3;  

  v_segment_id                  rel_segments.segment_id%TYPE;

  v_segment_name                rel_segments.segment_name%TYPE;

begin



   v_segment_id := rel_segment__get(get_or_new__group_id,get_or_new__rel_type);



   if v_segment_id is null then



      if segment_name is not null then

         v_segment_name := segment_name;

      else

         select groups.group_name + ' - ' + acs_object_types.pretty_name +

                  ' segment'

         into v_segment_name

         from groups, acs_object_types

         where groups.group_id = get_or_new__group_id

           and acs_object_types.object_type = get_or_new__rel_type;



      end if;



      v_segment_id := rel_segment__new (

          null,

          'rel_segment',

          now(),

          null,

          null,

          null,

          null,

          v_segment_name,

          get_or_new__group_id,

          get_or_new__rel_type,

          get_or_new__group_id

      );



   end if;



   return v_segment_id;



  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_segment__get_or_new_3

	@get_or_new__group_id		integer,

	@get_or_new__rel_type		varchar(8000),

	@segment_name		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_segment_id	int

declare @v_segment_name	varchar(8000)



SET @v_segment_id = dbo.rel_segment__get ( @get_or_new__group_id ,

  	@get_or_new__rel_type  ) 

  

   IF @v_segment_id  is null  BEGIN

  IF @segment_name  is not null  BEGIN

    SET @v_segment_name = @segment_name 

      

      END

    ELSE BEGIN

    

      select   @v_segment_name = groups.group_name  + ' - '  + acs_object_types.pretty_name  + ' segment'   

         

        from groups ,

      	acs_object_types  

         WHERE groups.group_id  = @get_or_new__group_id  and acs_object_types.object_type  = @get_or_new__rel_type  

         

         

      

    END --IF

    

    

     EXEC dbo.rel_segment__new null ,

    	'rel_segment' ,

    	getdate ,

    	null ,

    	null ,

    	null ,

    	null ,

    	@v_segment_name ,

    	@get_or_new__group_id ,

    	@get_or_new__rel_type ,

    	@get_or_new__group_id , @ms_return_value = @v_segment_id OUTPUT

    

    

  END --IF

  

  

   

  SET @ms_return_value = @v_segment_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function rel_segment__name (integer)

returns varchar as '

declare

  name__segment_id             alias for $1;  

  name__segment_name           varchar(200);  

begin

  select segment_name

  into name__segment_name

  from rel_segments

  where segment_id = name__segment_id;



  return name__segment_name;

  

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION rel_segment__name(@name__segment_id		integer) 

RETURNS varchar

AS

BEGIN

declare @name__segment_name	varchar ( 200 )





  select   @name__segment_name = segment_name   

     

    from rel_segments  

     WHERE segment_id  = @name__segment_id  

     

     

   RETURN CONVERT (varchar, @name__segment_name )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/rel-constraints-body-create.sql
[PG]
create function rel_constraint__new(varchar,integer,varchar,integer) 

returns integer as '

declare

        nam     alias for $1;

        sid1    alias for $2;

        side    alias for $3;

        sid2    alias for $4;

begin

        return rel_constraint__new(null,

                                   'rel_constraint',

                                   nam,

                                   sid1,

                                   side,

                                   sid2,

                                   null,

                                   null,

                                   null

                                   );                                   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_constraint__new

	@nam		varchar(8000),

	@sid1		integer,

	@side		varchar(8000),

	@sid2		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.rel_constraint__new ( null ,

  	'rel_constraint' ,

  	@nam ,

  	@sid1 ,

  	@side ,

  	@sid2 ,

  	null ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function rel_constraint__new (integer,varchar,varchar,integer,char,integer,integer,integer,varchar)

returns integer as '

declare

  new__constraint_id          alias for $1;  

  new__constraint_type        alias for $2;  

  new__constraint_name        alias for $3;  

  new__rel_segment            alias for $4;  

  new__rel_side               alias for $5;  

  new__required_rel_segment   alias for $6;  

  new__context_id             alias for $7;  

  new__creation_user          alias for $8;  

  new__creation_ip            alias for $9;  

  v_constraint_id             rel_constraints.constraint_id%TYPE;

begin

    v_constraint_id := acs_object__new (

      new__constraint_id,

      new__constraint_type,

      now(),

      new__creation_user,

      new__creation_ip,

      new__context_id

    );



    insert into rel_constraints

     (constraint_id, constraint_name, 

      rel_segment, rel_side, required_rel_segment)

    values

     (v_constraint_id, new__constraint_name, 

      new__rel_segment, new__rel_side, new__required_rel_segment);



     return v_constraint_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_constraint__new_9

	@new__constraint_id		integer,

	@new__constraint_type		varchar(8000),

	@new__constraint_name		varchar(8000),

	@new__rel_segment		integer,

	@new__rel_side		char,

	@new__required_rel_segment		integer,

	@new__context_id		integer,

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_constraint_id	int



EXEC dbo.acs_object__new @new__constraint_id ,

  	@new__constraint_type ,

  	getdate ,

  	@new__creation_user ,

  	@new__creation_ip ,

  	@new__context_id , @ms_return_value = @v_constraint_id OUTPUT

  

   

  insert into rel_constraints ( constraint_id, constraint_name, rel_segment, rel_side, required_rel_segment ) values ( @v_constraint_id  , @new__constraint_name  , @new__rel_segment  , @new__rel_side  , @new__required_rel_segment   )

   

  SET @ms_return_value = @v_constraint_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function rel_constraint__delete (integer)

returns integer as '

declare

  constraint_id          alias for $1;  

begin

    PERFORM acs_object__delete(constraint_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC rel_constraint__delete

	@constraint_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object__delete @constraint_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function rel_constraint__get_constraint_id (integer,char,integer)

returns integer as '

declare

  get_constraint_id__rel_segment            alias for $1;  

  get_constraint_id__rel_side               alias for $2;  

  get_constraint_id__required_rel_segment   alias for $3;  

  v_constraint_id                           rel_constraints.constraint_id%TYPE;

begin

    select constraint_id into v_constraint_id

    from rel_constraints

    where rel_segment = get_constraint_id__rel_segment

      and rel_side = get_constraint_id__rel_side

      and required_rel_segment = get_constraint_id__required_rel_segment;



    return v_constraint_id;



end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION rel_constraint__get_constraint_id(@get_constraint_id__rel_segment		integer,

	@get_constraint_id__rel_side		char,

	@get_constraint_id__required_rel_segment		integer) 

RETURNS integer

AS

BEGIN

declare @v_constraint_id	int





  select   @v_constraint_id = constraint_id   

     

    from rel_constraints  

     WHERE rel_segment  = @get_constraint_id__rel_segment  and rel_side  = @get_constraint_id__rel_side  and required_rel_segment  = @get_constraint_id__required_rel_segment  

     

     

   RETURN CONVERT (integer, @v_constraint_id )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function rel_constraint__violation (integer)

returns varchar as '

declare

  violation__rel_id                 alias for $1;  

  v_error                           text; 

  constraint_violated               record;

begin



    v_error := null;



    for constraint_violated in

     select constraint_id, constraint_name

       from rel_constraints_violated_one

       where rel_id = violation__rel_id

       LIMIT 1 

    LOOP



	  v_error := coalesce(v_error,'') + 

                     'Relational Constraint Violation: ' +

                     constraint_violated.constraint_name + 

                     ' (constraint_id=' +

                     constraint_violated.constraint_id + '). ';



          return v_error;

    end loop;



    for constraint_violated in

     select constraint_id, constraint_name

       from rel_constraints_violated_two

      where rel_id = violation__rel_id

      LIMIT 1 

    LOOP



           v_error := coalesce(v_error,'') + 

                      'Relational Constraint Violation: ' +

                      constraint_violated.constraint_name + 

                      ' (constraint_id=' +

                      constraint_violated.constraint_id + '). ';



           return v_error;

    end loop;



    return v_error;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION rel_constraint__violation(@violation__rel_id		integer) 

RETURNS varchar

AS

BEGIN

declare @v_error	varchar(8000)

declare @constraint_violated__constraint_name  	varchar(8000)

declare @constraint_violated__constraint_id  	int



SET @v_error = null 

  

   

  DECLARE cursor_1 CURSOR FOR

    

  select  TOP 1   constraint_id  , constraint_name   

     

    from rel_constraints_violated_one  

     WHERE rel_id  = @violation__rel_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @constraint_violated__constraint_id  , @constraint_violated__constraint_name  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  SET @v_error = coalesce ( @v_error ,

    	''  )  + 'Relational Constraint Violation: '  + @constraint_violated__constraint_name  + ' (constraint_id='  + @constraint_violated__constraint_id  + '). ' 

    

     RETURN CONVERT (varchar, @v_error )

    

  

    FETCH NEXT FROM cursor_1 INTO @constraint_violated__constraint_id  , @constraint_violated__constraint_name  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   

  DECLARE cursor_2 CURSOR FOR

    

  select  TOP 1   constraint_id  , constraint_name   

     

    from rel_constraints_violated_two  

     WHERE rel_id  = @violation__rel_id  

     

     

  

  OPEN cursor_2

  

  FETCH NEXT FROM cursor_2 INTO @constraint_violated__constraint_id  , @constraint_violated__constraint_name  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  SET @v_error = coalesce ( @v_error ,

    	''  )  + 'Relational Constraint Violation: '  + @constraint_violated__constraint_name  + ' (constraint_id='  + @constraint_violated__constraint_id  + '). ' 

    

     RETURN CONVERT (varchar, @v_error )

    

  

    FETCH NEXT FROM cursor_2 INTO @constraint_violated__constraint_id  , @constraint_violated__constraint_name  

  END --while

  

  CLOSE cursor_2

  

  DEALLOCATE cursor_2

  

  

   RETURN CONVERT (varchar, @v_error )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function rel_constraint__violation_if_removed (integer)

returns varchar as '

declare

  violation_if_removed__rel_id                 alias for $1;  

  v_count                                      integer;       

  v_error                                      text; 

  constraint_violated                          record;

begin

    v_error := null;



    select count(*) into v_count

      from dual

     where exists (select 1 

                     from rc_violations_by_removing_rel r 

                    where r.rel_id = violation_if_removed__rel_id);



    if v_count > 0 then

      

      

      for constraint_violated in select constraint_id, constraint_name

                                   from rc_violations_by_removing_rel r

                                  where r.rel_id = violation_if_removed__rel_id 

      LOOP



          v_error := v_error + 'Relational Constraint Violation: ' +

                     constraint_violated.constraint_name + 

                     ' (constraint_id=' +

                     constraint_violated.constraint_id + '). ';



      end loop;



    end if;



    return v_error;



   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION rel_constraint__violation_if_removed(@violation_if_removed__rel_id		integer) 

RETURNS varchar

AS

BEGIN

declare @constraint_violated__1  	varchar(8000)

declare @v_error	varchar(8000)

declare @v_count	integer



SET @v_error = null 

  

   

  select   @v_count = 1   

     

      

     WHERE  exists ( 

  select  1   

     

    from rc_violations_by_removing_rel r 

     WHERE r.rel_id  = @violation_if_removed__rel_id  

     

      )  

     

     

   IF @v_count  > 0  BEGIN

  

    DECLARE cursor_1 CURSOR FOR

      

    select  constraint_id  , constraint_name   

       

      from rc_violations_by_removing_rel r 

       WHERE r.rel_id  = @violation_if_removed__rel_id  

       

       

    

    OPEN cursor_1

    

    FETCH NEXT FROM cursor_1 INTO @constraint_violated__1  

    

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    SET @v_error = @v_error  + 'Relational Constraint Violation: '  + constraint_violated.constraint_name  + ' (constraint_id='  + constraint_violated.constraint_id  + '). ' 

      

      

    

      FETCH NEXT FROM cursor_1 INTO @constraint_violated__1  

    END --while

    

    CLOSE cursor_1

    

    DEALLOCATE cursor_1

    

    

    

  END --IF

  

  

   RETURN CONVERT (varchar, @v_error )

  



RETURN NULL -- placeholder required by tsql

END -- function

[Microsoft][ODBC SQL Server Driver][SQL Server]The column prefix 'constraint_violated' does not match with a table name or alias name used in the query.

 
[PG]
  
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]The column prefix 'constraint_violated' does not match with a table name or alias name used in the query.

 
File packages/acs-kernel/sql/postgresql/acs-permissions-create.sql
[PG]
create table acs_privileges (

	privilege	varchar(100) not null constraint acs_privileges_pk

			primary key,

	pretty_name	varchar(100),

	pretty_plural	varchar(100)

)
[MSSQL]
create table acs_privileges ( privilege	varchar(100) not null constraint acs_privileges_pk

			primary key,

	pretty_name	varchar(100),

	pretty_plural	varchar(100)

)

GO


 
[PG]
create table acs_privilege_hierarchy (

	privilege	varchar(100) not null 

                        constraint acs_priv_hier_priv_fk

			references acs_privileges (privilege),

        child_privilege	varchar(100) not null 

                        constraint acs_priv_hier_child_priv_fk

			references acs_privileges (privilege),

	constraint acs_privilege_hierarchy_pk

	primary key (privilege, child_privilege)

)
[MSSQL]
create table acs_privilege_hierarchy ( privilege	varchar(100) not null 

                        constraint acs_priv_hier_priv_fk

			references acs_privileges (privilege),

        child_privilege	varchar(100) not null 

                        constraint acs_priv_hier_child_priv_fk

			references acs_privileges (privilege),

	constraint acs_privilege_hierarchy_pk

	primary key (privilege, child_privilege)

)

GO


 
[PG]
create index acs_priv_hier_child_priv_idx on acs_privilege_hierarchy (child_privilege)
[MSSQL]
create index acs_priv_hier_child_priv_idx on acs_privilege_hierarchy (child_privilege)

 
[PG]
create table acs_privilege_hierarchy_index (

	privilege       varchar(100) not null 

                        constraint acs_priv_hier_priv_fk

			references acs_privileges (privilege),

        child_privilege varchar(100) not null 

                        constraint acs_priv_hier_child_priv_fk

			references acs_privileges (privilege),

        tree_sortkey    varchar(4000)

)
[MSSQL]
create table acs_privilege_hierarchy_index ( privilege       varchar(100) not null 

                        constraint acs_priv_hier_ndx_priv_fk

			references acs_privileges (privilege),

        child_privilege varchar(100) not null 

                        constraint acs_priv_hier_ndx_child_priv_fk

			references acs_privileges (privilege),

        tree_sortkey    varchar(4000)

)


 
[PG]
create index priv_hier_sortkey_idx on 

acs_privilege_hierarchy_index (tree_sortkey)
[MSSQL]
create index priv_hier_sortkey_idx on 

acs_privilege_hierarchy_index (tree_sortkey)

 
[PG]
create function acs_priv_hier_ins_del_tr () returns opaque as '

declare

        new_key         varchar;

        deleted_p       boolean;

        v_rec           record;

begin

        

        



        if TG_OP = 'DELETE' then 

            select count(*) = 0 into deleted_p

              from acs_privilege_hierarchy_index 

             where old.privilege = privilege

               and old.child_privilege = child_privilege;     

       

            if deleted_p then



                return new;



            end if;

        end if;



        



        delete from acs_privilege_hierarchy_index;



        



        for v_rec in select privilege, child_privilege

                       from acs_privilege_hierarchy

                      where privilege 

                            NOT in (select distinct child_privilege

                                      from acs_privilege_hierarchy)

                                           

        LOOP



            



            select '/' + tree_next_key(max(tree_sortkey)) into new_key 

              from acs_privilege_hierarchy_index

             where tree_level(tree_sortkey) = 1;



             



            insert into acs_privilege_hierarchy_index 

                        (privilege, child_privilege, tree_sortkey)

                        values

                        (v_rec.privilege, v_rec.child_privilege, new_key);



            



            PERFORM priv_recurse_subtree(new_key, v_rec.child_privilege);



        end LOOP;



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_priv_hier_ins_del_tr after insert or delete

on acs_privilege_hierarchy for each row

execute procedure acs_priv_hier_ins_del_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function priv_recurse_subtree(varchar, varchar) 

returns integer as '

declare

        nkey            alias for $1;

        child_priv      alias for $2;

        new_key         varchar;

        v_rec           record;

begin



        

        

        

        for v_rec in select privilege, child_privilege

                       from acs_privilege_hierarchy

                      where privilege = child_priv



        LOOP



            



            select tree_next_key(max(tree_sortkey)) into new_key

              from acs_privilege_hierarchy_index

             where tree_sortkey like nkey + '/%'

               and tree_sortkey not like  nkey + '/%/%';



            new_key := nkey + '/' + new_key;



            



            insert into acs_privilege_hierarchy_index

                        (privilege, child_privilege, tree_sortkey)

                        values

                        (v_rec.privilege, v_rec.child_privilege, new_key);



            



            PERFORM priv_recurse_subtree(new_key, v_rec.child_privilege);



        end LOOP;



        

        



        if NOT FOUND then

           insert into acs_privilege_hierarchy_index

                       (privilege, child_privilege, tree_sortkey)

                       values 

                       (child_priv, child_priv, nkey + '/00');

        end if;



        return null;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_privilege__create_privilege (varchar,varchar,varchar)

returns integer as '

declare

  create_privilege__privilege              alias for $1;  

  create_privilege__pretty_name            alias for $2;  

  create_privilege__pretty_plural          alias for $3;  

begin

    insert into acs_privileges

     (privilege, pretty_name, pretty_plural)

    values

     (create_privilege__privilege, 

      create_privilege__pretty_name, 

      create_privilege__pretty_plural);

      

    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_privilege__create_privilege

	@create_privilege__privilege		varchar(8000),

	@create_privilege__pretty_name		varchar(8000),

	@create_privilege__pretty_plural		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_privileges ( privilege, pretty_name, pretty_plural ) values ( @create_privilege__privilege  , @create_privilege__pretty_name  , @create_privilege__pretty_plural   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_privilege__create_privilege (varchar)

returns integer as '

declare

  create_privilege__privilege              alias for $1;

begin

    return acs_privilege__create_privilege(create_privilege__privilege, null, null);

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_privilege__create_privilege_1

	@create_privilege__privilege		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.acs_privilege__create_privilege ( @create_privilege__privilege ,

  	null ,

  	null  )  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function acs_privilege__drop_privilege (varchar)

returns integer as '

declare

  drop_privilege__privilege     alias for $1;  

begin

    delete from acs_privileges

    where privilege = drop_privilege__privilege;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_privilege__drop_privilege

	@drop_privilege__privilege		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_privileges  WHERE privilege  = @drop_privilege__privilege 

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_privilege__add_child (varchar,varchar)

returns integer as '

declare

  add_child__privilege              alias for $1;  

  add_child__child_privilege        alias for $2;  

begin

    insert into acs_privilege_hierarchy

     (privilege, child_privilege)

    values

     (add_child__privilege, add_child__child_privilege);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_privilege__add_child

	@add_child__privilege		varchar(8000),

	@add_child__child_privilege		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into acs_privilege_hierarchy ( privilege, child_privilege ) values ( @add_child__privilege  , @add_child__child_privilege   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs_privilege__remove_child (varchar,varchar)

returns integer as '

declare

  remove_child__privilege              alias for $1;  

  remove_child__child_privilege        alias for $2;  

begin

    delete from acs_privilege_hierarchy

    where privilege = remove_child__privilege

    and child_privilege = remove_child__child_privilege;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs_privilege__remove_child

	@remove_child__privilege		varchar(8000),

	@remove_child__child_privilege		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from acs_privilege_hierarchy  WHERE privilege  = @remove_child__privilege  and child_privilege  = @remove_child__child_privilege 

   RETURN 0

  

END -- stored proc


 
[PG]
create table acs_permissions (

	object_id		integer not null

				constraint acs_permissions_on_what_id_fk

				references acs_objects (object_id),

	grantee_id		integer not null

				constraint acs_permissions_grantee_id_fk

				references parties (party_id),

	privilege		varchar(100) not null 

                                constraint acs_permissions_priv_fk

				references acs_privileges (privilege),

	constraint acs_permissions_pk

	primary key (object_id, grantee_id, privilege)

)
[MSSQL]
create table acs_permissions ( object_id		integer not null

				constraint acs_permissions_on_what_id_fk

				references acs_objects (object_id),

	grantee_id		integer not null

				constraint acs_permissions_grantee_id_fk

				references parties (party_id),

	privilege		varchar(100) not null 

                                constraint acs_permissions_priv_fk

				references acs_privileges (privilege),

	constraint acs_permissions_pk

	primary key (object_id, grantee_id, privilege)

)

GO


 
[PG]
create index acs_permissions_grantee_idx on acs_permissions (grantee_id)
[MSSQL]
create index acs_permissions_grantee_idx on acs_permissions (grantee_id)

 
[PG]
create index acs_permissions_privilege_idx on acs_permissions (privilege)
[MSSQL]
create index acs_permissions_privilege_idx on acs_permissions (privilege)

 
[PG]
create view acs_privilege_descendant_map

as select p1.privilege, p2.privilege as descendant

   from acs_privileges p1, acs_privileges p2

   where exists (select h2.child_privilege

                   from

                     acs_privilege_hierarchy_index h1,

                     acs_privilege_hierarchy_index h2

                   where

                     h1.privilege = p1.privilege

                     and h2.privilege = p2.privilege

                     and h2.tree_sortkey like h1.tree_sortkey + '%')
[MSSQL]
create view acs_privilege_descendant_map as 

select  p1.privilege  , p2.privilege  as descendant 

   

  from acs_privileges p1,

	acs_privileges p2 

   WHERE  exists ( 

select  h2.child_privilege   

   

  from acs_privilege_hierarchy_index h1,

	acs_privilege_hierarchy_index h2 

   WHERE h1.privilege  = p1.privilege  and h2.privilege  = p2.privilege  and h2.tree_sortkey  like h1.tree_sortkey  + '%'  

   

    )  

   

   

 
[PG]
create view acs_permissions_all

as select op.object_id, p.grantee_id, p.privilege

   from acs_object_paths op, acs_permissions p

   where op.ancestor_id = p.object_id
[MSSQL]
create view acs_permissions_all as 

select  op.object_id  , p.grantee_id  , p.privilege   

   

  from acs_object_paths op,

	acs_permissions p 

   WHERE op.ancestor_id  = p.object_id  

   

   

 
[PG]
create view acs_object_grantee_priv_map

as select a.object_id, a.grantee_id, m.descendant as privilege

   from acs_permissions_all a, acs_privilege_descendant_map m

   where a.privilege = m.privilege
[MSSQL]
create view acs_object_grantee_priv_map as 

select  a.object_id  , a.grantee_id  , m.descendant  as privilege 

   

  from acs_permissions_all a,

	acs_privilege_descendant_map m 

   WHERE a.privilege  = m.privilege  

   

   

 
[PG]
create view acs_object_party_privilege_map

as select ogpm.object_id, gmm.member_id as party_id, ogpm.privilege

   from acs_object_grantee_priv_map ogpm, group_approved_member_map gmm

   where ogpm.grantee_id = gmm.group_id

   union

   select ogpm.object_id, rsmm.member_id as party_id, ogpm.privilege

   from acs_object_grantee_priv_map ogpm, rel_seg_approved_member_map rsmm

   where ogpm.grantee_id = rsmm.segment_id

   union

   select object_id, grantee_id as party_id, privilege

   from acs_object_grantee_priv_map

   union

   select object_id, u.user_id as party_id, privilege

   from acs_object_grantee_priv_map m, users u

   where m.grantee_id = -1

   union

   select object_id, 0 as party_id, privilege

   from acs_object_grantee_priv_map

   where grantee_id = -1
[MSSQL]
create view acs_object_party_privilege_map as 

select  ogpm.object_id  , gmm.member_id  as party_id, ogpm.privilege   

   

  from acs_object_grantee_priv_map ogpm,

	group_approved_member_map gmm 

   WHERE ogpm.grantee_id  = gmm.group_id  

   

   union 

select  ogpm.object_id  , rsmm.member_id  as party_id, ogpm.privilege   

   

  from acs_object_grantee_priv_map ogpm,

	rel_seg_approved_member_map rsmm 

   WHERE ogpm.grantee_id  = rsmm.segment_id  

   

    union 

select  object_id  , grantee_id  as party_id, privilege   

   

  from acs_object_grantee_priv_map  

   

   

    union 

select  object_id  , u.user_id  as party_id, privilege   

   

  from acs_object_grantee_priv_map m,

	users u 

   WHERE m.grantee_id  = -1  

   

    union 

select  object_id  , 0  as party_id, privilege   

   

  from acs_object_grantee_priv_map  

   WHERE grantee_id  = -1  

   

    

 
[PG]
create view acs_grantee_party_map as

   select -1 as grantee_id, 0 as party_id from dual

   union all

   select -1 as grantee_id, user_id as party_id

   from users

   union all

   select party_id as grantee_id, party_id

   from parties

   union all

   select segment_id as grantee_id, member_id

   from rel_seg_approved_member_map

   union all

   select group_id as grantee_id, member_id as party_id

   from group_approved_member_map
[MSSQL]
create view acs_grantee_party_map as 

select  -1  as grantee_id, 0  as party_id 

   

    

   

   

   union all 

select  -1  as grantee_id, user_id  as party_id 

   

  from users  

   

   

    union all 

select  party_id  as grantee_id, party_id   

   

  from parties  

   

   

    union all 

select  segment_id  as grantee_id, member_id   

   

  from rel_seg_approved_member_map  

   

   

    union all 

select  group_id  as grantee_id, member_id  as party_id 

   

  from group_approved_member_map  

   

   

    

 
[PG]
create view all_object_party_privilege_map as

select         op.object_id,

               pdm.descendant as privilege,

               gpm.party_id as party_id

        from acs_object_paths op, 

             acs_permissions p, 

             acs_privilege_descendant_map pdm,

             acs_grantee_party_map gpm

        where op.ancestor_id = p.object_id 

          and pdm.privilege = p.privilege

          and gpm.grantee_id = p.grantee_id
[MSSQL]
create view all_object_party_privilege_map as 

select  op.object_id  , pdm.descendant  as privilege, gpm.party_id  as party_id 

   

  from acs_object_paths op,

	acs_permissions p,

	acs_privilege_descendant_map pdm,

	acs_grantee_party_map gpm 

   WHERE op.ancestor_id  = p.object_id  and pdm.privilege  = p.privilege  and gpm.grantee_id  = p.grantee_id  

   

   

 
[PG]
create table acs_permissions_lock (

       lck  integer

)
[MSSQL]
create table acs_permissions_lock ( lck  integer

)

GO


 
[PG]
create function acs_permissions_lock_tr () returns opaque as '

begin

        raise EXCEPTION 'FOR LOCKING ONLY, NO DML STATEMENTS ALLOWED';

        return null;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger acs_permissions_lock_tr 

before insert or update or delete on acs_permissions_lock

for each row execute procedure acs_permissions_lock_tr()
[MSSQL]
/* Skipped */

 
[PG]
create function acs_permission__grant_permission (integer, integer, varchar)

returns integer as '

declare

    grant_permission__object_id         alias for $1;

    grant_permission__grantee_id        alias for $2;

    grant_permission__privilege         alias for $3;

    exists_p                            boolean;

begin

    lock table acs_permissions_lock;



    select count(*) > 0 into exists_p

      from acs_permissions

     where object_id = grant_permission__object_id

       and grantee_id = grant_permission__grantee_id

       and privilege = grant_permission__privilege;



    if not exists_p then



        insert into acs_permissions

          (object_id, grantee_id, privilege)

          values

          (grant_permission__object_id, grant_permission__grantee_id, 

          grant_permission__privilege);



    end if;



    

    

    



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_permission__revoke_permission (integer, integer, varchar)

returns integer as '

declare

    revoke_permission__object_id         alias for $1;

    revoke_permission__grantee_id        alias for $2;

    revoke_permission__privilege         alias for $3;

begin

    lock table acs_permissions_lock;



    delete from acs_permissions

    where object_id = revoke_permission__object_id

    and grantee_id = revoke_permission__grantee_id

    and privilege = revoke_permission__privilege;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function acs_permission__permission_p (integer,integer,varchar)

returns boolean as '

declare

    permission_p__object_id           alias for $1;

    permission_p__party_id            alias for $2;

    permission_p__privilege           alias for $3;

    exists_p                          boolean;

begin

    

    

    select 1 into exists_p

     where exists (

          select 1

          from acs_object_grantee_priv_map ogpm,

               group_approved_member_map gmm

         where object_id = permission_p__object_id

           and gmm.member_id = permission_p__party_id

           and privilege = permission_p__privilege

           and ogpm.grantee_id = gmm.group_id);

    if FOUND then

        return 't';

    end if;

    

    

    select 1 into exists_p

     where exists (

        select 1

          from acs_object_grantee_priv_map ogpm,

               rel_seg_approved_member_map rsmm

         where object_id = permission_p__object_id

           and rsmm.member_id = permission_p__party_id

           and privilege = permission_p__privilege

           and ogpm.grantee_id = rsmm.segment_id);

    if FOUND then

        return 't';

    end if;

    

    

    select 1 into exists_p

     where exists (

        select 1

          from acs_object_grantee_priv_map

         where object_id = permission_p__object_id

           and grantee_id = permission_p__party_id

           and privilege = permission_p__privilege);

    if FOUND then

        return 't';

    end if;

    

    

    select 1 into exists_p

     where exists (

        select 1

          from acs_object_grantee_priv_map m, users u

         where object_id = permission_p__object_id

           and u.user_id = permission_p__party_id

           and privilege = permission_p__privilege

           and m.grantee_id = -1);

    if FOUND then

        return 't';

    end if;

    

    

    select 1 into exists_p

     where exists (

        select 1

          from acs_object_grantee_priv_map

         where object_id = permission_p__object_id

           and 0 = permission_p__party_id

           and privilege = permission_p__privilege

           and grantee_id = -1);

    

    if FOUND then

       return 't';

    else

       return 'f';

    end if;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs_permission__permission_p(@permission_p__object_id		integer,

	@permission_p__party_id		integer,

	@permission_p__privilege		varchar(8000)) 

RETURNS boolean

AS

BEGIN

declare @exists_p	boolean





  select   @exists_p = 1   

     

     

     WHERE  exists ( 

  select  1   

     

    from acs_object_grantee_priv_map ogpm,

  	group_approved_member_map gmm 

     WHERE object_id  = @permission_p__object_id  and gmm.member_id  = @permission_p__party_id  and privilege  = @permission_p__privilege  and ogpm.grantee_id  = gmm.group_id  

     

      )  

     

     

   IF  @@ROWCOUNT > 0   BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  select   @exists_p = 1   

     

     

     WHERE  exists ( 

  select  1   

     

    from acs_object_grantee_priv_map ogpm,

  	rel_seg_approved_member_map rsmm 

     WHERE object_id  = @permission_p__object_id  and rsmm.member_id  = @permission_p__party_id  and privilege  = @permission_p__privilege  and ogpm.grantee_id  = rsmm.segment_id  

     

      )  

     

     

   IF  @@ROWCOUNT > 0   BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  select   @exists_p = 1   

     

     

     WHERE  exists ( 

  select  1   

     

    from acs_object_grantee_priv_map  

     WHERE object_id  = @permission_p__object_id  and grantee_id  = @permission_p__party_id  and privilege  = @permission_p__privilege  

     

      )  

     

     

   IF  @@ROWCOUNT > 0   BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  select   @exists_p = 1   

     

     

     WHERE  exists ( 

  select  1   

     

    from acs_object_grantee_priv_map m,

  	users u 

     WHERE object_id  = @permission_p__object_id  and u.user_id  = @permission_p__party_id  and privilege  = @permission_p__privilege  and m.grantee_id  = -1  

     

      )  

     

     

   IF  @@ROWCOUNT > 0   BEGIN

  RETURN 't'

    

  END --IF

  

  

   

  select   @exists_p = 1   

     

     

     WHERE  exists ( 

  select  1   

     

    from acs_object_grantee_priv_map  

     WHERE object_id  = @permission_p__object_id  and 0  = @permission_p__party_id  and privilege  = @permission_p__privilege  and grantee_id  = -1  

     

      )  

     

     

   IF  @@ROWCOUNT > 0   BEGIN

  RETURN 't'

    END

  ELSE BEGIN

  RETURN 'f'

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/security-create.sql
[PG]
create table sec_session_properties (

    session_id     integer

                   constraint sec_session_prop_session_id_nn

                   not null,

    module         varchar(50)

                   constraint sec_session_prop_module_nn

                   not null,

    property_name  varchar(50) 

                   constraint sec_session_prop_prop_name_nn

                   not null,

    property_value text,

    

    secure_p       boolean,

    last_hit	   integer

                   constraint sec_session_date_nn

                   not null,

    primary key(session_id, module, property_name)

)
[MSSQL]
create table sec_session_properties ( session_id     integer

                   constraint sec_session_prop_session_id_nn

                   not null,

    module         varchar(50)

                   constraint sec_session_prop_module_nn

                   not null,

    property_name  varchar(50) 

                   constraint sec_session_prop_prop_name_nn

                   not null,

    property_value text,

    

    secure_p       boolean,

    last_hit	   integer

                   constraint sec_session_date_nn

                   not null,

    primary key(session_id, module, property_name)

)

GO


 
[PG]
create index sec_property_names on sec_session_properties(property_name)
[MSSQL]
create index sec_property_names on sec_session_properties(property_name)

 
[PG]
create table secret_tokens (

    token_id                    integer

                                constraint secret_tokens_token_id_pk primary key,

    token                       char(40),

    timestamp                    timestamp

)
[MSSQL]
create table secret_tokens ( token_id                    integer

                                constraint secret_tokens_token_id_pk primary key,

    token                       char(40),

    datetime                    datetime

)

GO


 
[PG]
create sequence t_sec_security_token_id_seq cache 100
[MSSQL]
CREATE TABLE t_sec_security_token_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC sec_security_token_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_sec_security_token_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view sec_security_token_id_seq as

select nextval('t_sec_security_token_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
create sequence t_sec_id_seq cache 100 increment 100
[MSSQL]
CREATE TABLE t_sec_id_seq ( sequence int identity(1,1), dummy bit default 0 );

GO

CREATE PROC sec_id_seq__nextval @ms_return_value int = 0 OUTPUT

as

INSERT INTO t_sec_id_seq VALUES (default)

SET @ms_return_value = @@IDENTITY

RETURN @ms_return_value




 
[PG]
create view sec_id_seq as

select nextval('t_sec_id_seq') as nextval
[MSSQL]
/* Skipped */

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/journal-create.sql
[PG]
create function inline_0 ()

returns integer as '

begin

  PERFORM acs_object_type__create_type (

    'journal_entry',

    'Journal Entry',

    'Journal Entries',

    'acs_object',

    'journal_entries',

    'journal_id',

    'journal_entry',

    'f',

    null,

    null

    );



  

  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object_type__create_type 'journal_entry' ,

  	'Journal Entry' ,

  	'Journal Entries' ,

  	'acs_object' ,

  	'journal_entries' ,

  	'journal_id' ,

  	'journal_entry' ,

  	'f' ,

  	null ,

  	null  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table journal_entries (

  journal_id		integer constraint journal_entries_journal_id_fk

			references acs_objects (object_id)

			constraint journal_entries_pk

			primary key,

  object_id 		integer

			constraint journal_entries_object_fk

			references acs_objects on delete cascade,

  action                varchar(100),

  action_pretty         text,

  msg    		text

)
[MSSQL]
create table journal_entries ( journal_id		integer constraint journal_entries_journal_id_fk

			references acs_objects (object_id)

			constraint journal_entries_pk

			primary key,

  object_id 		integer

			constraint journal_entries_object_fk

			references acs_objects ,

  action                varchar(100),

  action_pretty         text,

  msg    		text

)

GO


 
[PG]
create index journal_entries_object_idx on journal_entries (object_id)
[MSSQL]
create index journal_entries_object_idx on journal_entries (object_id)

 
[PG]
create function journal_entry__new (integer,integer,varchar,varchar,timestamp,integer,varchar,varchar)

returns integer as '

declare

  new__journal_id             alias for $1;  

  new__object_id              alias for $2;  

  new__action                 alias for $3;  

  new__action_pretty          alias for $4;  

  new__creation_date          alias for $5;  

  new__creation_user          alias for $6;  

  new__creation_ip            alias for $7;  

  new__msg                    alias for $8;  

  v_journal_id                journal_entries.journal_id%TYPE;

begin

	v_journal_id := acs_object__new (

	  new__journal_id,

	  'journal_entry',

	  new__creation_date,

	  new__creation_user,

	  new__creation_ip,

	  new__object_id

	);



        insert into journal_entries (

            journal_id, object_id, action, action_pretty, msg

        ) values (

            v_journal_id, new__object_id, new__action, 

            new__action_pretty, new__msg

        );



        return v_journal_id;

     

end;' language 'plpgsql'
[MSSQL]
CREATE PROC journal_entry__new

	@new__journal_id		integer,

	@new__object_id		integer,

	@new__action		varchar(8000),

	@new__action_pretty		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__msg		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_journal_id	int



EXEC dbo.acs_object__new @new__journal_id ,

  	'journal_entry' ,

  	@new__creation_date ,

  	@new__creation_user ,

  	@new__creation_ip ,

  	@new__object_id , @ms_return_value = @v_journal_id OUTPUT

  

   

  insert into journal_entries ( journal_id, object_id, action, action_pretty, msg ) values ( @v_journal_id  , @new__object_id  , @new__action  , @new__action_pretty  , @new__msg   )

   

  SET @ms_return_value = @v_journal_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function journal_entry__delete (integer)

returns integer as '

declare

  delete__journal_id             alias for $1;  

begin

	delete from journal_entries where journal_id = delete__journal_id;

	PERFORM acs_object__delete(delete__journal_id);



        return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC journal_entry__delete

	@delete__journal_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from journal_entries  WHERE journal_id  = @delete__journal_id 

   EXEC dbo.acs_object__delete @delete__journal_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function journal_entry__delete_for_object (integer)

returns integer as '

declare

  delete_for_object__object_id          alias for $1;  

  journal_rec                           record;

begin

        for journal_rec in select journal_id 

                             from journal_entries 

                            where object_id = delete_for_object__object_id  

        LOOP

	    PERFORM journal_entry__delete(journal_rec.journal_id);

	end loop;



        return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC journal_entry__delete_for_object

	@delete_for_object__object_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @journal_rec__journal_id  	int





  DECLARE cursor_1 CURSOR FOR

    

  select  journal_id   

     

    from journal_entries  

     WHERE object_id  = @delete_for_object__object_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @journal_rec__journal_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.journal_entry__delete @journal_rec__journal_id  

    

  

    FETCH NEXT FROM cursor_1 INTO @journal_rec__journal_id  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   RETURN 0

  

END -- stored proc


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/site-nodes-create.sql
[PG]
create function inline_0 ()

returns integer as '

declare

        dummy   integer;

begin

  PERFORM acs_object_type__create_type (

    'site_node',

    'Site Node',

    'Site Nodes',

    'acs_object',

    'site_nodes',

    'node_id',

    'site_node',

    'f',

    null,

    null

    );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @dummy	integer



EXEC dbo.acs_object_type__create_type 'site_node' ,

  	'Site Node' ,

  	'Site Nodes' ,

  	'acs_object' ,

  	'site_nodes' ,

  	'node_id' ,

  	'site_node' ,

  	'f' ,

  	null ,

  	null  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create table site_nodes (

        node_id         integer constraint site_nodes_node_id_fk

                        references acs_objects (object_id)

                        constraint site_nodes_node_id_pk

                        primary key,

        parent_id       integer constraint site_nodes_parent_id_fk

                        references site_nodes (node_id),

        name            varchar(100)

                        constraint site_nodes_name_ck

                        check (name not like '%/%'),

        constraint site_nodes_un

        unique (parent_id, name),

        

        directory_p     boolean not null,

        

        

        pattern_p       boolean default 'f' not null,

        object_id       integer constraint site_nodes_object_id_fk

                        references acs_objects (object_id),

        tree_sortkey    varchar(4000)

)
[MSSQL]
create table site_nodes ( node_id         integer constraint site_nodes_node_id_fk

                        references acs_objects (object_id)

                        constraint site_nodes_node_id_pk

                        primary key,

        parent_id       integer constraint site_nodes_parent_id_fk

                        references site_nodes (node_id),

        name            varchar(100)

                        constraint site_nodes_name_ck

                        check (name not like '%/%'),

        constraint site_nodes_un

        unique (parent_id, name),

        

        directory_p     boolean not null,

        

        

        pattern_p       boolean default 'f' not null,

        object_id       integer constraint site_nodes_object_id_fk

                        references acs_objects (object_id),

        tree_sortkey    varchar(4000)

)

GO


 
[PG]
create index site_nodes_object_id_idx on site_nodes (object_id)
[MSSQL]
create index site_nodes_object_id_idx on site_nodes (object_id)

 
[PG]
create index site_nodes_tree_skey_idx on site_nodes (tree_sortkey)
[MSSQL]
create index site_nodes_tree_skey_idx on site_nodes (tree_sortkey)

 
[PG]
create function site_node_insert_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

begin

        if new.parent_id is null then

            select max(tree_sortkey) into max_key 

              from site_nodes 

             where parent_id is null;



            v_parent_sk := '';

        else

            select max(tree_sortkey) into max_key 

              from site_nodes 

             where parent_id = new.parent_id;



            select coalesce(max(tree_sortkey),'') into v_parent_sk 

              from site_nodes 

             where node_id = new.parent_id;

        end if;



        new.tree_sortkey := v_parent_sk + '/' + tree_next_key(max_key);



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger site_node_insert_tr before insert 

on site_nodes for each row 

execute procedure site_node_insert_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function site_node_update_tr () returns opaque as '

declare

        v_parent_sk     varchar;

        max_key         varchar;

        p_id            integer;

        v_rec           record;

        clr_keys_p      boolean default 't';

begin

        if new.node_id = old.node_id and 

           ((new.parent_id = old.parent_id) or 

            (new.parent_id is null and old.parent_id is null)) then



           return new;



        end if;



        for v_rec in select node_id

                       from site_nodes 

                      where tree_sortkey like new.tree_sortkey + '%'

                   order by tree_sortkey

        LOOP

            if clr_keys_p then

               update site_nodes set tree_sortkey = null

               where tree_sortkey like new.tree_sortkey + '%';

               clr_keys_p := 'f';

            end if;

            

            select parent_id into p_id

              from site_nodes 

             where node_id = v_rec.node_id;



            if p_id is null then

                select max(tree_sortkey) into max_key

                  from site_nodes

                 where parent_id is null;



                v_parent_sk := '';

            else

                select max(tree_sortkey) into max_key

                  from site_nodes 

                 where parent_id = p_id;



                select coalesce(max(tree_sortkey),'') into v_parent_sk 

                  from site_nodes 

                 where node_id = p_id;

            end if;



            update site_nodes 

               set tree_sortkey = v_parent_sk + '/' + tree_next_key(max_key)

             where node_id = v_rec.node_id;



        end LOOP;



        return new;



end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create trigger site_node_update_tr after update 

on site_nodes

for each row 

execute procedure site_node_update_tr ()
[MSSQL]
/* Skipped */

 
[PG]
create function site_node__new (integer,integer,varchar,integer,boolean,boolean,integer,varchar)

returns integer as '

declare

  new__node_id                alias for $1;  

  new__parent_id              alias for $2;  

  new__name                   alias for $3;  

  new__object_id              alias for $4;   

  new__directory_p            alias for $5;  

  new__pattern_p              alias for $6;   

  new__creation_user          alias for $7;   

  new__creation_ip            alias for $8;   

  v_node_id                   site_nodes.node_id%TYPE;

  v_directory_p               site_nodes.directory_p%TYPE;

begin

    if new__parent_id is not null then

      select directory_p into v_directory_p

      from site_nodes

      where node_id = new__parent_id;



      if v_directory_p = 'f' then

        raise EXCEPTION '-20000: Node % is not a directory', new__parent_id;

      end if;

    end if;



    v_node_id := acs_object__new (

      new__node_id,

      'site_node',

      now(),

      new__creation_user,

      new__creation_ip,

      null

    );



    insert into site_nodes

     (node_id, parent_id, name, object_id, directory_p, pattern_p)

    values

     (v_node_id, new__parent_id, new__name, new__object_id,

      new__directory_p, new__pattern_p);



     return v_node_id;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function site_node__delete (integer)

returns integer as '

declare

  delete__node_id                alias for $1;  

begin

    delete from site_nodes

    where node_id = delete__node_id;



    PERFORM acs_object__delete(delete__node_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC site_node__delete

	@delete__node_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from site_nodes  WHERE node_id  = @delete__node_id 

   EXEC dbo.acs_object__delete @delete__node_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function site_node__find_pattern (integer)

returns integer as '

declare

  find_pattern__node_id         alias for $1;  

  v_pattern_p                   site_nodes.pattern_p%TYPE;

  v_parent_id                   site_nodes.node_id%TYPE;

begin

    if find_pattern__node_id is null then



        raise exception 'NO DATA FOUND';

    end if;



    select pattern_p, parent_id into v_pattern_p, v_parent_id

    from site_nodes

    where node_id = find_pattern__node_id;



    if v_pattern_p = 't' then

      return find_pattern__node_id;

    else

      return site_node__find_pattern(v_parent_id);

    end if;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function site_node__node_id (varchar,integer)

returns integer as '

declare

  node_id__url           alias for $1;  

  node_id__parent_id     alias for $2;  

  v_pos                  integer;       

  v_first                site_nodes.name%TYPE;

  v_rest                 text; 

  v_node_id              integer;       

  v_pattern_p            site_nodes.pattern_p%TYPE;

  v_url                  text; 

  v_directory_p          site_nodes.directory_p%TYPE;

  v_trailing_slash_p     boolean;       

begin

    v_url := node_id__url;



    if substr(v_url, length(v_url), 1) = '/' then

      

      v_trailing_slash_p := 't';

      v_url := substr(v_url, 1, length(v_url) - 1);

    end if;



    v_pos := 1;



    while v_pos <= length(v_url) and substr(v_url, v_pos, 1) <> '/' loop

      v_pos := v_pos + 1;

    end loop;



    if v_pos = length(v_url) then

      v_first := v_url;

      v_rest := null;

    else

      v_first := substr(v_url, 1, v_pos - 1);

      v_rest := substr(v_url, v_pos + 1);

    end if;



    

      

      select node_id, directory_p into v_node_id, v_directory_p

      from site_nodes

      where coalesce(parent_id, 3.14) = coalesce(node_id__parent_id, 3.14)

      and coalesce(name, chr(10)) = coalesce(v_first, chr(10));

    if NOT FOUND then 

        return site_node__find_pattern(node_id__parent_id);

    end if;



    if v_rest is null then

      if v_trailing_slash_p = 't' and v_directory_p = 'f' then

        return site_node__find_pattern(node_id__parent_id);

      else

        return v_node_id;

      end if;

    else

      return site_node__node_id(v_rest, v_node_id);

    end if;





end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function site_node__url (integer)

returns varchar as '

declare

  url__node_id           alias for $1;  

  v_parent_id            site_nodes.node_id%TYPE;

  v_name                 site_nodes.name%TYPE;

  v_directory_p          site_nodes.directory_p%TYPE;

begin

    if url__node_id is null then

      return '';

    end if;



    select parent_id, name, directory_p into

           v_parent_id, v_name, v_directory_p

    from site_nodes

    where node_id = url__node_id;



    if v_directory_p = 't' then

      return site_node__url(v_parent_id) + v_name + '/';

    else

      return site_node__url(v_parent_id) + v_name;

    end if;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/apm-create.sql
[PG]
create table apm_package_types (

    package_key			varchar(100)

				constraint apm_package_types_p_key_pk primary key,

    pretty_name			varchar(100)

    	    	    	    	constraint apm_package_types_pretty_n_nn not null

				constraint apm_package_types_pretty_n_un unique,

    pretty_plural	        varchar(100)

				constraint apm_package_types_pretty_pl_un unique,

    package_uri			varchar(1500)

				constraint apm_packages_types_p_uri_nn not null

				constraint apm_packages_types_p_uri_un unique,

    package_type		varchar(300)

				constraint apm_packages_pack_type_ck 

				check (package_type in ('apm_application', 'apm_service')),

    spec_file_path		varchar(1500),

    spec_file_mtime		integer,

    initial_install_p		boolean default 'f' not null,

    singleton_p			boolean default 'f' not null

)
[MSSQL]
create table apm_package_types ( package_key			varchar(100)

				constraint apm_package_types_p_key_pk primary key,

    pretty_name			varchar(100)

    	    	    	    	constraint apm_package_types_pretty_n_nn not null

				constraint apm_package_types_pretty_n_un unique,

    pretty_plural	        varchar(100)

				constraint apm_package_types_pretty_pl_un unique,

    package_uri			varchar(1500)

				constraint apm_packages_types_p_uri_nn not null

				constraint apm_packages_types_p_uri_un unique,

    package_type		varchar(300)

				constraint apm_packages_pack_type_ck 

				check (package_type in ('apm_application', 'apm_service')),

    spec_file_path		varchar(1500),

    spec_file_mtime		integer,

    initial_install_p		boolean default 'f' not null,

    singleton_p			boolean default 'f' not null

)

GO


 
[PG]
create function inline_0 ()

returns integer as '

begin



 PERFORM acs_object_type__create_type (

   'apm_package',

   'Package',

   'Packages',

   'acs_object',

   'APM_PACKAGES',

   'package_id',

   'apm_package',

   'f',

   'apm_package_types',

   'apm_package.name'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.acs_object_type__create_type 'apm_package' ,

  	'Package' ,

  	'Packages' ,

  	'acs_object' ,

  	'APM_PACKAGES' ,

  	'package_id' ,

  	'apm_package' ,

  	'f' ,

  	'apm_package_types' ,

  	'apm_package.name'  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
create function inline_1 ()

returns integer as '

declare

 attr_id acs_attributes.attribute_id%TYPE;

begin



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'package_key',

   'string',

   'Package Key',

   'Package Keys',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'package_uri',

   'string',

   'Package URI',

   'Package URIs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'spec_file_path',

   'string',

   'Specification File Path',

   'Specification File Paths',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'spec_file_mtime',

   'number',

   'Specification File Modified Time',

   'Specification File Modified Times',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'initial_install_p',

   'boolean',

   'Initial Install',

   'Initial Installs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package',

   'singleton_p',

   'boolean',

   'Singleton',

   'Singletons',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_1

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'package_key' ,

  	'string' ,

  	'Package Key' ,

  	'Package Keys' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'package_uri' ,

  	'string' ,

  	'Package URI' ,

  	'Package URIs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'spec_file_path' ,

  	'string' ,

  	'Specification File Path' ,

  	'Specification File Paths' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'spec_file_mtime' ,

  	'number' ,

  	'Specification File Modified Time' ,

  	'Specification File Modified Times' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'initial_install_p' ,

  	'boolean' ,

  	'Initial Install' ,

  	'Initial Installs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package' ,

  	'singleton_p' ,

  	'boolean' ,

  	'Singleton' ,

  	'Singletons' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_1 ()
[MSSQL]
 dbo.inline_1 

 
[PG]
drop function inline_1 ()
[MSSQL]
drop proc inline_1

 
[PG]
create table apm_packages (

    package_id			integer constraint apm_packages_package_id_fk

				references acs_objects(object_id)

				constraint apm_packages_pack_id_pk primary key,

    package_key			varchar(100) constraint apm_packages_package_key_fk

				references apm_package_types(package_key),

    instance_name		varchar(300)

			        constraint apm_packages_inst_name_nn not null,

    enabled_p			boolean default 'f'

)
[MSSQL]
create table apm_packages ( package_id			integer constraint apm_packages_package_id_fk

				references acs_objects(object_id)

				constraint apm_packages_pack_id_pk primary key,

    package_key			varchar(100) constraint apm_packages_package_key_fk

				references apm_package_types(package_key),

    instance_name		varchar(300)

			        constraint apm_packages_inst_name_nn not null,

    enabled_p			boolean default 'f'

)

GO


 
[PG]
create index apm_packages_package_key_idx on apm_packages (package_key)
[MSSQL]
create index apm_packages_package_key_idx on apm_packages (package_key)

 
[PG]
create table apm_package_versions (

    version_id         integer

                       constraint apm_package_vers_id_pk primary key

		       constraint apm_package_vers_id_fk	

		         references acs_objects(object_id),

    package_key        varchar(100) 

		       constraint apm_package_vers_pack_key_nn not null

		       constraint apm_package_vers_pack_key_fk 

		         references apm_package_types(package_key),

    version_name       varchar(100)

                       constraint apm_package_vers_ver_name_nn not null,

    version_uri        varchar(1500)

                       constraint apm_package_vers_ver_uri_nn not null

                       constraint apm_package_vers_ver_uri_un unique,

    summary 	       varchar(3000),

    description_format varchar(100)

		       constraint apm_package_vers_desc_for_ck

		         check (description_format in ('text/html', 'text/plain')),

    description        text,

    release_date       timestamp,

    vendor             varchar(500),

    vendor_uri         varchar(1500),

    enabled_p          boolean default 'f'

                       constraint apm_package_vers_enabled_p_nn not null,

    installed_p        boolean default 'f'

                       constraint apm_package_vers_inst_p_nn not null,

    tagged_p           boolean default 'f'

                       constraint apm_package_vers_tagged_p_nn not null,

    imported_p         boolean default 'f'

                       constraint apm_package_vers_imp_p_nn not null,

    data_model_loaded_p boolean default 'f'

                       constraint apm_package_vers_dml_p_nn not null,

    cvs_import_results text,

    activation_date    timestamp,

    deactivation_date  timestamp,

    

    

    item_id            integer,

    

    

                       

                       

    content_length     integer,

    distribution_uri   varchar(1500),

    distribution_date  timestamp,

    constraint apm_package_vers_id_name_un unique(package_key, version_name)

)
[MSSQL]
create table apm_package_versions ( version_id         integer

                       constraint apm_package_vers_id_pk primary key

		       constraint apm_package_vers_id_fk	

		         references acs_objects(object_id),

    package_key        varchar(100) 

		       constraint apm_package_vers_pack_key_nn not null

		       constraint apm_package_vers_pack_key_fk 

		         references apm_package_types(package_key),

    version_name       varchar(100)

                       constraint apm_package_vers_ver_name_nn not null,

    version_uri        varchar(1500)

                       constraint apm_package_vers_ver_uri_nn not null

                       constraint apm_package_vers_ver_uri_un unique,

    summary 	       varchar(3000),

    description_format varchar(100)

		       constraint apm_package_vers_desc_for_ck

		         check (description_format in ('text/html', 'text/plain')),

    description        text,

    release_date       datetime,

    vendor             varchar(500),

    vendor_uri         varchar(1500),

    enabled_p          boolean default 'f'

                       constraint apm_package_vers_enabled_p_nn not null,

    installed_p        boolean default 'f'

                       constraint apm_package_vers_inst_p_nn not null,

    tagged_p           boolean default 'f'

                       constraint apm_package_vers_tagged_p_nn not null,

    imported_p         boolean default 'f'

                       constraint apm_package_vers_imp_p_nn not null,

    data_model_loaded_p boolean default 'f'

                       constraint apm_package_vers_dml_p_nn not null,

    cvs_import_results text,

    activation_date    datetime,

    deactivation_date  datetime,

    

    

    item_id            integer,

    

    

                       

                       

    content_length     integer,

    distribution_uri   varchar(1500),

    distribution_date  datetime,

    constraint apm_package_vers_id_name_un unique(package_key, version_name)

)

GO


 
[PG]
create function inline_2 ()

returns integer as '

declare

 attr_id acs_attributes.attribute_id%TYPE;

begin

 attr_id := acs_object_type__create_type (

   'apm_package_version',

   'Package Version',

   'Package Versions',

   'acs_object',

   'APM_PACKAGE_VERSIONS',

   'version_id',

   'APM_PACKAGE_VERSION',

   'f',

   null,

   null

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'package_key',

   'string',

   'Package Key',

   'Package Keys',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'version_name',

   'string',

   'Version Name',

   'Version Names',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'version_uri',

   'string',

   'Version URI',

   'Version URIs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'summary',

   'string',

   'Summary',

   'Summaries',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'description_format',

   'string',

   'Description Format',

   'Description Formats',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'description',

   'string',

   'Description',

   'Descriptions',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'vendor',

   'string',

   'Vendor',

   'Vendors',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'vendor_uri',

   'string',

   'Vendor URI',

   'Vendor URIs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'enabled_p',

   'string',

   'Enabled',

   'Enabled',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'activation_date',

   'date',

   'Activation Date',

   'Activation Dates',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'deactivation_date',

   'string',

   'Deactivation Date',

   'Deactivation Dates',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'distribution_uri',

   'string',

   'Distribution URI',

   'Distribution URIs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_package_version',

   'distribution_date',

   'date',

   'Distribution Date',

   'Distribution Dates',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_2

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'apm_package_version' ,

  	'Package Version' ,

  	'Package Versions' ,

  	'acs_object' ,

  	'APM_PACKAGE_VERSIONS' ,

  	'version_id' ,

  	'APM_PACKAGE_VERSION' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'package_key' ,

  	'string' ,

  	'Package Key' ,

  	'Package Keys' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'version_name' ,

  	'string' ,

  	'Version Name' ,

  	'Version Names' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'version_uri' ,

  	'string' ,

  	'Version URI' ,

  	'Version URIs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'summary' ,

  	'string' ,

  	'Summary' ,

  	'Summaries' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'description_format' ,

  	'string' ,

  	'Description Format' ,

  	'Description Formats' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'description' ,

  	'string' ,

  	'Description' ,

  	'Descriptions' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'vendor' ,

  	'string' ,

  	'Vendor' ,

  	'Vendors' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'vendor_uri' ,

  	'string' ,

  	'Vendor URI' ,

  	'Vendor URIs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'enabled_p' ,

  	'string' ,

  	'Enabled' ,

  	'Enabled' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'activation_date' ,

  	'date' ,

  	'Activation Date' ,

  	'Activation Dates' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'deactivation_date' ,

  	'string' ,

  	'Deactivation Date' ,

  	'Deactivation Dates' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'distribution_uri' ,

  	'string' ,

  	'Distribution URI' ,

  	'Distribution URIs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_package_version' ,

  	'distribution_date' ,

  	'date' ,

  	'Distribution Date' ,

  	'Distribution Dates' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_2 ()
[MSSQL]
 dbo.inline_2 

 
[PG]
drop function inline_2 ()
[MSSQL]
drop proc inline_2

 
[PG]
create table apm_package_owners (

    version_id         integer constraint apm_package_owners_ver_id_fk references apm_package_versions on delete cascade,

    

    owner_uri          varchar(1500),

    owner_name         varchar(200)

                       constraint apm_package_owners_name_nn not null,

    sort_key           integer

)
[MSSQL]
create table apm_package_owners ( version_id         integer constraint apm_package_owners_ver_id_fk references apm_package_versions ,

    

    owner_uri          varchar(1500),

    owner_name         varchar(200)

                       constraint apm_package_owners_name_nn not null,

    sort_key           integer

)

GO


 
[PG]
create index apm_pkg_owners_version_idx on apm_package_owners (version_id)
[MSSQL]
create index apm_pkg_owners_version_idx on apm_package_owners (version_id)

 
[PG]
create view apm_package_version_info as

    select v.package_key, t.package_uri, t.pretty_name, t.singleton_p, t.initial_install_p,

           v.version_id, v.version_name,

           v.version_uri, v.summary, v.description_format, v.description, v.release_date,

           v.vendor, v.vendor_uri, v.enabled_p, v.installed_p, v.tagged_p, v.imported_p, v.data_model_loaded_p,

           v.activation_date, v.deactivation_date,

           coalesce(v.content_length,0) as tarball_length,

           distribution_uri, distribution_date

    from   apm_package_types t, apm_package_versions v 

    where  v.package_key = t.package_key
[MSSQL]
create view apm_package_version_info as 

select  v.package_key  , t.package_uri  , t.pretty_name  , t.singleton_p  , t.initial_install_p  , v.version_id  , v.version_name  , v.version_uri  , v.summary  , v.description_format  , v.description  , v.release_date  , v.vendor  , v.vendor_uri  , v.enabled_p  , v.installed_p  , v.tagged_p  , v.imported_p  , v.data_model_loaded_p  , v.activation_date  , v.deactivation_date  , coalesce ( v.content_length ,

	0  )  as tarball_length, distribution_uri  , distribution_date   

   

  from apm_package_types t,

	apm_package_versions v 

   WHERE v.package_key  = t.package_key  

   

   

 
[PG]
create view apm_enabled_package_versions as

    select * from apm_package_version_info

    where  enabled_p = 't'
[MSSQL]
create view apm_enabled_package_versions as 

select  *  

   

  from apm_package_version_info  

   WHERE enabled_p  = 't'  

   

   

 
[PG]
create table apm_package_file_types (

    file_type_key      varchar(50)

                       constraint apm_package_file_types_pk primary key,

    pretty_name        varchar(200)

                       constraint apm_package_file_types_name_nn not null

)
[MSSQL]
create table apm_package_file_types ( file_type_key      varchar(50)

                       constraint apm_package_file_types_pk primary key,

    pretty_name        varchar(200)

                       constraint apm_package_file_types_name_nn not null

)

GO


 
[PG]
create function inline_3 ()

returns integer as '

begin

  insert into apm_package_file_types(file_type_key, pretty_name) values('documentation', 'Documentation');

  insert into apm_package_file_types(file_type_key, pretty_name) values('tcl_procs', 'Tcl procedure library');

  insert into apm_package_file_types(file_type_key, pretty_name) values('tcl_init', 'Tcl initialization');

  insert into apm_package_file_types(file_type_key, pretty_name) values('tcl_util', 'Tcl utility script');

  insert into apm_package_file_types(file_type_key, pretty_name) values('content_page', 'Content page');

  insert into apm_package_file_types(file_type_key, pretty_name) values('package_spec', 'Package specification');

  insert into apm_package_file_types(file_type_key, pretty_name) values('data_model', 'Data model');

  insert into apm_package_file_types(file_type_key, pretty_name) values('data_model_create', 'Data model installation');

  insert into apm_package_file_types(file_type_key, pretty_name) values('data_model_drop', 'Data model deinstallation');

  insert into apm_package_file_types(file_type_key, pretty_name) values('data_model_upgrade', 'Data model upgrade');

  insert into apm_package_file_types(file_type_key, pretty_name) values('java_code', 'Java code');

  insert into apm_package_file_types(file_type_key, pretty_name) values('java_archive', 'Java archive');

  insert into apm_package_file_types(file_type_key, pretty_name) values('query_file', 'Query file');

  insert into apm_package_file_types(file_type_key, pretty_name) values('template', 'Template file');

  insert into apm_package_file_types(file_type_key, pretty_name) values('shell', 'Shell utility');

  insert into apm_package_file_types(file_type_key, pretty_name) values('sqlj_code', 'SQLJ library');



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_3

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'documentation'  , 'Documentation'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'tcl_procs'  , 'Tcl procedure library'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'tcl_init'  , 'Tcl initialization'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'tcl_util'  , 'Tcl utility script'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'content_page'  , 'Content page'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'package_spec'  , 'Package specification'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'data_model'  , 'Data model'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'data_model_create'  , 'Data model installation'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'data_model_drop'  , 'Data model deinstallation'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'data_model_upgrade'  , 'Data model upgrade'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'java_code'  , 'Java code'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'java_archive'  , 'Java archive'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'query_file'  , 'Query file'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'template'  , 'Template file'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'shell'  , 'Shell utility'   )

   

  insert into apm_package_file_types ( file_type_key, pretty_name ) values ( 'sqlj_code'  , 'SQLJ library'   )

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_3 ()
[MSSQL]
 dbo.inline_3 

 
[PG]
drop function inline_3 ()
[MSSQL]
drop proc inline_3

 
[PG]
create table apm_package_db_types (

    db_type_key      varchar(50)

                       constraint apm_package_db_types_pk primary key,

    pretty_db_name   varchar(200)

                       constraint apm_package_db_types_name_nn not null

)
[MSSQL]
create table apm_package_db_types ( db_type_key      varchar(50)

                       constraint apm_package_db_types_pk primary key,

    pretty_db_name   varchar(200)

                       constraint apm_package_db_types_name_nn not null

)

GO


 
[PG]
create table apm_package_files (

    file_id            integer

                       constraint apm_package_files_id_pk primary key,

    version_id         integer constraint apm_package_files_ver_id_fk references apm_package_versions 

		       on delete cascade

                       constraint apm_package_files_ver_id_nn not null,

    path               varchar(1500)

                       constraint apm_package_files_path_nn not null,

    file_type          varchar(50) constraint apm_package_files_type_fk references apm_package_file_types,

    db_type            varchar(50) constraint apm_package_files_db_type_fk references apm_package_db_types,

    constraint apm_package_files_un unique(version_id, path)

)
[MSSQL]
create table apm_package_files ( file_id            integer

                       constraint apm_package_files_id_pk primary key,

    version_id         integer constraint apm_package_files_ver_id_fk references apm_package_versions 

		       

                       constraint apm_package_files_ver_id_nn not null,

    path               varchar(1500)

                       constraint apm_package_files_path_nn not null,

    file_type          varchar(50) constraint apm_package_files_type_fk references apm_package_file_types,

    db_type            varchar(50) constraint apm_package_files_db_type_fk references apm_package_db_types,

    constraint apm_package_files_un unique(version_id, path)

)

GO


 
[PG]
create index apm_pkg_files_file_type_idx on apm_package_files (file_type)
[MSSQL]
create index apm_pkg_files_file_type_idx on apm_package_files (file_type)

 
[PG]
create index apm_pkg_files_db_type_idx on apm_package_files (db_type)
[MSSQL]
create index apm_pkg_files_db_type_idx on apm_package_files (db_type)

 
[PG]
create view apm_file_info as

    select f.*, p.package_key, 'packages/' + p.package_key + '/' + f.path as full_path

    from   apm_package_files f, apm_package_versions v, apm_package_types p

    where  f.version_id = v.version_id

    and    v.package_key = p.package_key
[MSSQL]
create view apm_file_info as 

select  f.*  , p.package_key  , 'packages/'  + p.package_key  + '/'  + f.path  as full_path 

   

  from apm_package_files f,

	apm_package_versions v,

	apm_package_types p 

   WHERE f.version_id  = v.version_id  and v.package_key  = p.package_key  

   

   

 
[PG]
create table apm_parameters (

	parameter_id		integer constraint apm_parameters_fk 

				references acs_objects(object_id)

			        constraint apm_parameters_pk primary key,

	package_key		varchar(100)

				constraint apm_pack_param_pack_key_nn not null 	

				constraint apm_pack_param_type_fk

			        references apm_package_types (package_key),

	parameter_name		varchar(100) 

				constraint apm_pack_params_name_nn not null,

        description		varchar(2000),

	section_name		varchar(200),

	datatype	        varchar(100) not null

			        constraint apm_parameter_datatype_ck 

				check(datatype in ('number', 'string')),

	default_value		text,

	min_n_values		integer default 1 not null

			        constraint apm_paramters_min_n_ck

			        check (min_n_values >= 0),

	max_n_values		integer default 1 not null

			        constraint apm_paramters_max_n_ck

			        check (max_n_values >= 0),

	constraint apm_paramters_attr_name_un

	unique (parameter_name, package_key),

	constraint apm_paramters_n_values_ck

	check (min_n_values <= max_n_values)

)
[MSSQL]
create table apm_parameters ( parameter_id		integer constraint apm_parameters_fk 

				references acs_objects(object_id)

			        constraint apm_parameters_pk primary key,

	package_key		varchar(100)

				constraint apm_pack_param_pack_key_nn not null 	

				constraint apm_pack_param_type_fk

			        references apm_package_types (package_key),

	parameter_name		varchar(100) 

				constraint apm_pack_params_name_nn not null,

        description		varchar(2000),

	section_name		varchar(200),

	datatype	        varchar(100) not null

			        constraint apm_parameter_datatype_ck 

				check(datatype in ('number', 'string')),

	default_value		text,

	min_n_values		integer default 1 not null

			        constraint apm_paramters_min_n_ck

			        check (min_n_values >= 0),

	max_n_values		integer default 1 not null

			        constraint apm_paramters_max_n_ck

			        check (max_n_values >= 0),

	constraint apm_paramters_attr_name_un

	unique (parameter_name, package_key),

	constraint apm_paramters_n_values_ck

	check (min_n_values <= max_n_values)

)

GO


 
[PG]
create index apm_parameters_package_idx on apm_parameters (package_key)
[MSSQL]
create index apm_parameters_package_idx on apm_parameters (package_key)

 
[PG]
create table apm_parameter_values (

	value_id		integer constraint apm_parameter_values_fk

				references acs_objects(object_id)

				constraint apm_parameter_values_pk primary key,

	package_id		integer constraint apm_pack_values_obj_id_fk

				references apm_packages (package_id) on delete cascade,

	parameter_id		integer constraint apm_pack_values_parm_id_fk

				references apm_parameters (parameter_id),

	attr_value		text,

	constraint apm_parameter_values_un 

	unique (package_id, parameter_id)

)
[MSSQL]
create table apm_parameter_values ( value_id		integer constraint apm_parameter_values_fk

				references acs_objects(object_id)

				constraint apm_parameter_values_pk primary key,

	package_id		integer constraint apm_pack_values_obj_id_fk

				references apm_packages (package_id) ,

	parameter_id		integer constraint apm_pack_values_parm_id_fk

				references apm_parameters (parameter_id),

	attr_value		text,

	constraint apm_parameter_values_un 

	unique (package_id, parameter_id)

)

GO


 
[PG]
create index apm_par_vals_parameter_idx on apm_parameter_values (parameter_id)
[MSSQL]
create index apm_par_vals_parameter_idx on apm_parameter_values (parameter_id)

 
[PG]
create function inline_4 ()

returns integer as '

declare

 attr_id acs_attributes.attribute_id%TYPE;

begin

 attr_id := acs_object_type__create_type (

   'apm_parameter',

   'Package Parameter',

   'Package Parameters',

   'acs_object',

   'APM_PARAMETERS',

   'parameter_id',

   'apm_parameter',

   'f',

   null,

   null

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'package_key',

   'string',

   'Package Key',

   'Package Keys',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'parameter_name',

   'string',

   'Parameter Name',

   'Parameter Name',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'datatype',

   'string',

   'Datatype',

   'Datatypes',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'default_value',

   'string',

   'Default Value',

   'Default Values',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'min_n_values',

   'number',

   'Minimum Number of Values',

   'Minimum Numer of Values Settings',

   null,

   null,

   1,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter',

   'max_n_values',

   'string',

   'Maximum Number of Values',

   'Maximum Number of Values Settings',

   null,

   null,

   1,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_4

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'apm_parameter' ,

  	'Package Parameter' ,

  	'Package Parameters' ,

  	'acs_object' ,

  	'APM_PARAMETERS' ,

  	'parameter_id' ,

  	'apm_parameter' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'package_key' ,

  	'string' ,

  	'Package Key' ,

  	'Package Keys' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'parameter_name' ,

  	'string' ,

  	'Parameter Name' ,

  	'Parameter Name' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'datatype' ,

  	'string' ,

  	'Datatype' ,

  	'Datatypes' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'default_value' ,

  	'string' ,

  	'Default Value' ,

  	'Default Values' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'min_n_values' ,

  	'number' ,

  	'Minimum Number of Values' ,

  	'Minimum Numer of Values Settings' ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter' ,

  	'max_n_values' ,

  	'string' ,

  	'Maximum Number of Values' ,

  	'Maximum Number of Values Settings' ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_4 ()
[MSSQL]
 dbo.inline_4 

 
[PG]
drop function inline_4 ()
[MSSQL]
drop proc inline_4

 
[PG]
create function inline_5 ()

returns integer as '

declare

 attr_id acs_attributes.attribute_id%TYPE;

begin

 attr_id := acs_object_type__create_type (

   'apm_parameter_value',

   'APM Package Parameter Value',

   'APM Package Parameter Values',

   'acs_object',

   'apm_parameter_values',

   'value_id',

   'apm_parameter_value',

   'f',

   null,

   null

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter_value',

   'package_id',

   'number',

   'Package ID',

   'Package IDs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter_value',

   'parameter_id',

   'number',

   'Parameter ID',

   'Parameter IDs',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



 attr_id := acs_attribute__create_attribute (

   'apm_parameter_value',

   'attr_value',

   'string',

   'Parameter Value',

   'Parameter Values',

   null,

   null,

   null,

   1,

   1,

   null,

   'type_specific',

   'f'

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_5

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @attr_id	int



EXEC dbo.acs_object_type__create_type 'apm_parameter_value' ,

  	'APM Package Parameter Value' ,

  	'APM Package Parameter Values' ,

  	'acs_object' ,

  	'apm_parameter_values' ,

  	'value_id' ,

  	'apm_parameter_value' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter_value' ,

  	'package_id' ,

  	'number' ,

  	'Package ID' ,

  	'Package IDs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter_value' ,

  	'parameter_id' ,

  	'number' ,

  	'Parameter ID' ,

  	'Parameter IDs' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   EXEC dbo.acs_attribute__create_attribute 'apm_parameter_value' ,

  	'attr_value' ,

  	'string' ,

  	'Parameter Value' ,

  	'Parameter Values' ,

  	null ,

  	null ,

  	null ,

  	1 ,

  	1 ,

  	null ,

  	'type_specific' ,

  	'f' , @ms_return_value = @attr_id OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_5 ()
[MSSQL]
 dbo.inline_5 

 
[PG]
drop function inline_5 ()
[MSSQL]
drop proc inline_5

 
[PG]
create table apm_package_dependencies (

    dependency_id      integer 

                       constraint apm_package_deps_id_pk primary key,

    version_id         integer constraint apm_package_deps_version_id_fk references apm_package_versions on delete cascade

                       constraint apm_package_deps_version_id_nn not null,

    dependency_type    varchar(20)

                       constraint apm_package_deps_type_nn not null

                       constraint apm_package_deps_type_ck check(dependency_type in ('provides','requires')),

    service_uri        varchar(1500)

                       constraint apm_package_deps_uri_nn not null,

    service_version    varchar(100)

                       constraint apm_package_deps_ver_name_nn not null,

    constraint apm_package_deps_un unique(version_id, service_uri)

)
[MSSQL]
create table apm_package_dependencies ( dependency_id      integer 

                       constraint apm_package_deps_id_pk primary key,

    version_id         integer constraint apm_package_deps_version_id_fk references apm_package_versions 

                       constraint apm_package_deps_version_id_nn not null,

    dependency_type    varchar(20)

                       constraint apm_package_deps_type_nn not null

                       constraint apm_package_deps_type_ck check(dependency_type in ('provides','requires')),

    service_uri        varchar(1500)

                       constraint apm_package_deps_uri_nn not null,

    service_version    varchar(100)

                       constraint apm_package_deps_ver_name_nn not null,

    constraint apm_package_deps_un unique(version_id, service_uri)

)

GO


 
[PG]
create table apm_applications (

       application_id		integer

				constraint applications_application_id_fk

				references apm_packages(package_id)

				constraint applications_pk primary key

)
[MSSQL]
create table apm_applications ( application_id		integer

				constraint applications_application_id_fk

				references apm_packages(package_id)

				constraint applications_pk primary key

)

GO


 
[PG]
create table apm_services (

       service_id			integer

					constraint services_service_id_fk

					references apm_packages(package_id)

				        constraint services_pk primary key

)
[MSSQL]
create table apm_services ( service_id			integer

					constraint services_service_id_fk

					references apm_packages(package_id)

				        constraint services_pk primary key

)

GO


 
[PG]
create function inline_6 ()

returns integer as '

declare 

        dummy   integer;

begin



 dummy :=  acs_object_type__create_type (

   'apm_application',

   'Application',

   'Applications',

   'apm_package',

   'apm_applications',

   'application_id',

   'apm_application',

   'f',

   null,

   null

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_6

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @dummy	integer



EXEC dbo.acs_object_type__create_type 'apm_application' ,

  	'Application' ,

  	'Applications' ,

  	'apm_package' ,

  	'apm_applications' ,

  	'application_id' ,

  	'apm_application' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @dummy OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_6 ()
[MSSQL]
 dbo.inline_6 

 
[PG]
drop function inline_6 ()
[MSSQL]
drop proc inline_6

 
[PG]
create function inline_7 ()

returns integer as '

declare

        dummy   integer;

begin



 dummy := acs_object_type__create_type (

   'apm_service',

   'Service',

   'Services',

   'apm_package',

   'apm_services',

   'service_id',

   'apm_service',

   'f',

   null,

   null

   );



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_7

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @dummy	integer



EXEC dbo.acs_object_type__create_type 'apm_service' ,

  	'Service' ,

  	'Services' ,

  	'apm_package' ,

  	'apm_services' ,

  	'service_id' ,

  	'apm_service' ,

  	'f' ,

  	null ,

  	null , @ms_return_value = @dummy OUTPUT

  

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_7 ()
[MSSQL]
 dbo.inline_7 

 
[PG]
drop function inline_7 ()
[MSSQL]
drop proc inline_7

 
[PG]
create function apm__register_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns integer as '

declare

  package_key            alias for $1;  

  pretty_name            alias for $2;  

  pretty_plural          alias for $3;  

  package_uri            alias for $4;  

  package_type           alias for $5;  

  initial_install_p      alias for $6;  

  singleton_p            alias for $7;  

  spec_file_path         alias for $8;  

  spec_file_mtime        alias for $9;  

begin

    PERFORM apm_package_type__create_type(

    	package_key,

	pretty_name,

	pretty_plural,

	package_uri,

	package_type,

	initial_install_p,

	singleton_p,

	spec_file_path,

	spec_file_mtime

    );



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__register_package

	@package_key		varchar(8000),

	@pretty_name		varchar(8000),

	@pretty_plural		varchar(8000),

	@package_uri		varchar(8000),

	@package_type		varchar(8000),

	@initial_install_p		boolean,

	@singleton_p		boolean,

	@spec_file_path		varchar(8000),

	@spec_file_mtime		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm_package_type__create_type @package_key ,

  	@pretty_name ,

  	@pretty_plural ,

  	@package_uri ,

  	@package_type ,

  	@initial_install_p ,

  	@singleton_p ,

  	@spec_file_path ,

  	@spec_file_mtime  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__update_package (varchar,varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns varchar as '

declare

  package_key            alias for $1;  

  pretty_name            alias for $2;  

  pretty_plural          alias for $3;  

  package_uri            alias for $4;  

  package_type           alias for $5;  

  initial_install_p      alias for $6;  

  singleton_p            alias for $7;  

  spec_file_path         alias for $8;  

  spec_file_mtime        alias for $9;  

begin

 

    return apm_package_type__update_type(

    	package_key,

	pretty_name,

	pretty_plural,

	package_uri,

	package_type,

	initial_install_p,

	singleton_p,

	spec_file_path,

	spec_file_mtime

    );

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__update_package

	@package_key		varchar(8000),

	@pretty_name		varchar(8000),

	@pretty_plural		varchar(8000),

	@package_uri		varchar(8000),

	@package_type		varchar(8000),

	@initial_install_p		boolean,

	@singleton_p		boolean,

	@spec_file_path		varchar(8000),

	@spec_file_mtime		integer, 

	@ms_return_value	varchar =  OUTPUT 

AS

BEGIN





  SET @ms_return_value = dbo.apm_package_type__update_type ( @package_key ,

  	@pretty_name ,

  	@pretty_plural ,

  	@package_uri ,

  	@package_type ,

  	@initial_install_p ,

  	@singleton_p ,

  	@spec_file_path ,

  	@spec_file_mtime  )  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Parameter '@ms_return_value' has an invalid data type.

 
[PG]
create function apm__unregister_package (varchar,boolean)

returns integer as '

declare

  package_key            alias for $1;  

  cascade_p              alias for $2;  

begin

   PERFORM apm_package_type__drop_type(

	package_key,

	cascade_p

   );



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__unregister_package

	@package_key		varchar(8000),

	@cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm_package_type__drop_type @package_key ,

  	@cascade_p  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__register_p (varchar)

returns integer as '

declare

  register_p__package_key            alias for $1;  

  v_register_p                       integer;       

begin

    select case when count(*) = 0 then 0 else 1 end into v_register_p 

    from apm_package_types 

    where package_key = register_p__package_key;



    return v_register_p;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm__register_application (varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns integer as '

declare

  package_key            alias for $1;  

  pretty_name            alias for $2;  

  pretty_plural          alias for $3;  

  package_uri            alias for $4;  

  initial_install_p      alias for $5;  

  singleton_p            alias for $6;  

  spec_file_path         alias for $7;  

  spec_file_mtime        alias for $8;  

begin

   PERFORM apm__register_package(

	package_key,

	pretty_name,

	pretty_plural,

	package_uri,

	'apm_application',

	initial_install_p,

	singleton_p,

	spec_file_path,

	spec_file_mtime

   ); 



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__register_application

	@package_key		varchar(8000),

	@pretty_name		varchar(8000),

	@pretty_plural		varchar(8000),

	@package_uri		varchar(8000),

	@initial_install_p		boolean,

	@singleton_p		boolean,

	@spec_file_path		varchar(8000),

	@spec_file_mtime		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm__register_package @package_key ,

  	@pretty_name ,

  	@pretty_plural ,

  	@package_uri ,

  	'apm_application' ,

  	@initial_install_p ,

  	@singleton_p ,

  	@spec_file_path ,

  	@spec_file_mtime  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__unregister_application (varchar,boolean)

returns integer as '

declare

  package_key            alias for $1;  

  cascade_p              alias for $2;  

begin

   PERFORM apm__unregister_package (

	package_key,

	cascade_p

   );



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__unregister_application

	@package_key		varchar(8000),

	@cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm__unregister_package @package_key ,

  	@cascade_p  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__register_service (varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns integer as '

declare

  package_key            alias for $1;  

  pretty_name            alias for $2;  

  pretty_plural          alias for $3;  

  package_uri            alias for $4;  

  initial_install_p      alias for $5;  

  singleton_p            alias for $6;  

  spec_file_path         alias for $7;  

  spec_file_mtime        alias for $8;  

begin

   PERFORM apm__register_package(

	package_key,

	pretty_name,

	pretty_plural,

	package_uri,

	'apm_service',

	initial_install_p,

	singleton_p,

	spec_file_path,

	spec_file_mtime

   );  

 

   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__register_service

	@package_key		varchar(8000),

	@pretty_name		varchar(8000),

	@pretty_plural		varchar(8000),

	@package_uri		varchar(8000),

	@initial_install_p		boolean,

	@singleton_p		boolean,

	@spec_file_path		varchar(8000),

	@spec_file_mtime		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm__register_package @package_key ,

  	@pretty_name ,

  	@pretty_plural ,

  	@package_uri ,

  	'apm_service' ,

  	@initial_install_p ,

  	@singleton_p ,

  	@spec_file_path ,

  	@spec_file_mtime  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__unregister_service (varchar,boolean)

returns integer as '

declare

  package_key            alias for $1;  

  cascade_p              alias for $2;  

begin

   PERFORM apm__unregister_package (

	package_key,

	cascade_p

   );



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__unregister_service

	@package_key		varchar(8000),

	@cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



EXEC dbo.apm__unregister_package @package_key ,

  	@cascade_p  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__register_parameter (integer,varchar,varchar,varchar,varchar,varchar,varchar,integer,integer)

returns integer as '

declare

  register_parameter__parameter_id           alias for $1;  

  register_parameter__package_key            alias for $2;  

  register_parameter__parameter_name         alias for $3;  

  register_parameter__description            alias for $4;  

  register_parameter__datatype               alias for $5;  

  register_parameter__default_value          alias for $6;  

  register_parameter__section_name           alias for $7;  

  register_parameter__min_n_values           alias for $8;  

  register_parameter__max_n_values           alias for $9;  



  v_parameter_id         apm_parameters.parameter_id%TYPE;

  cur_val                record;

begin

    

    v_parameter_id := acs_object__new(

       register_parameter__parameter_id,

       'apm_parameter',

       now(),

       null,

       null,

       null

    );

    

    insert into apm_parameters 

    (parameter_id, parameter_name, description, package_key, datatype, 

    default_value, section_name, min_n_values, max_n_values)

    values

    (v_parameter_id, register_parameter__parameter_name, 

     register_parameter__description, register_parameter__package_key, 

     register_parameter__datatype, register_parameter__default_value, 

     register_parameter__section_name, register_parameter__min_n_values, 

     register_parameter__max_n_values);



    

    for cur_val in select ap.package_id, p.parameter_id, p.default_value 

       from apm_parameters p left outer join apm_parameter_values v 

             using (parameter_id), apm_packages ap

      where p.package_key = ap.package_key

        and v.attr_value = ''

        and p.package_key = register_parameter__package_key

      loop

      	PERFORM apm__set_value(

	    cur_val.parameter_id, 

	    cur_val.package_id,

	    cur_val.default_value

	    ); 	

      end loop;	

	

    return v_parameter_id;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm__update_parameter (integer,varchar,varchar,varchar,varchar,varchar,integer,integer)

returns varchar as '

declare

  update_parameter__parameter_id           alias for $1;  

  update_parameter__parameter_name         alias for $2;  

  update_parameter__description            alias for $3;  

  update_parameter__datatype               alias for $4;  

  update_parameter__default_value          alias for $5;  

  update_parameter__section_name           alias for $6;  

  update_parameter__min_n_values           alias for $7;  

  update_parameter__max_n_values           alias for $8;  

begin

    update apm_parameters 

	set parameter_name = coalesce(update_parameter__parameter_name, parameter_name),

            default_value  = coalesce(update_parameter__default_value, default_value),

            datatype       = coalesce(update_parameter__datatype, datatype), 

	    description	   = coalesce(update_parameter__description, description),

	    section_name   = coalesce(update_parameter__section_name, section_name),

            min_n_values   = coalesce(update_parameter__min_n_values, min_n_values),

            max_n_values   = coalesce(update_parameter__max_n_values, max_n_values)

      where parameter_id = update_parameter__parameter_id;



    return parameter_id;

     

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm__parameter_p (varchar,varchar)

returns integer as '

declare

  parameter_p__package_key            alias for $1;  

  parameter_p__parameter_name         alias for $2;  

  v_parameter_p                       integer;       

begin

    select case when count(*) = 0 then 0 else 1 end into v_parameter_p 

    from apm_parameters

    where package_key = parameter_p__package_key

    and parameter_name = parameter_p__parameter_name;



    return v_parameter_p;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm__unregister_parameter (integer)

returns integer as '

declare

  unregister_parameter__parameter_id           alias for $1;  

begin

    delete from apm_parameter_values 

    where parameter_id = unregister_parameter__parameter_id;

    delete from apm_parameters 

    where parameter_id = unregister_parameter__parameter_id;

    PERFORM acs_object__delete(unregister_parameter__parameter_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm__unregister_parameter

	@unregister_parameter__parameter_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_parameter_values  WHERE parameter_id  = @unregister_parameter__parameter_id 

   delete from apm_parameters  WHERE parameter_id  = @unregister_parameter__parameter_id 

   EXEC dbo.acs_object__delete @unregister_parameter__parameter_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm__id_for_name (varchar,varchar)

returns integer as '

declare

  id_for_name__parameter_name         alias for $1;  

  id_for_name__package_key            alias for $2;  

  a_parameter_id                      apm_parameters.parameter_id%TYPE;

begin

    select parameter_id into a_parameter_id

    from apm_parameters p

    where p.parameter_name = id_for_name__parameter_name and

          p.package_key = id_for_name__package_key;



    return a_parameter_id;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm__id_for_name(@id_for_name__parameter_name		varchar(8000),

	@id_for_name__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @a_parameter_id	int





  select   @a_parameter_id = parameter_id   

     

    from apm_parameters p 

     WHERE p.parameter_name  = @id_for_name__parameter_name  and p.package_key  = @id_for_name__package_key  

     

     

   RETURN CONVERT (integer, @a_parameter_id )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm__get_value (integer,integer)

returns varchar as '

declare

  get_value__parameter_id           alias for $1;  

  get_value__package_id             alias for $2;  

  value                             apm_parameter_values.attr_value%TYPE;

begin

    select attr_value into value from apm_parameter_values v

    where v.package_id = get_value__package_id

    and parameter_id = get_value__parameter_id;



    return value;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm__get_value(@get_value__parameter_id		integer,

	@get_value__package_id		integer) 

RETURNS varchar

AS

BEGIN

declare @value	varchar(8000)





  select   @value = attr_value   

     

    from apm_parameter_values v 

     WHERE v.package_id  = @get_value__package_id  and parameter_id  = @get_value__parameter_id  

     

     

   RETURN CONVERT (varchar, @value )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm__get_value (integer,varchar)

returns varchar as '

declare

  get_value__package_id             alias for $1;  

  get_value__parameter_name         alias for $2;  

  v_parameter_id                    apm_parameter_values.parameter_id%TYPE;

begin

    select parameter_id into v_parameter_id 

    from apm_parameters 

    where parameter_name = get_value__parameter_name

    and package_key = (select package_key  from apm_packages

			where package_id = get_value__package_id);

    return apm__get_value(

	v_parameter_id,

	get_value__package_id

    );	

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm__get_value_2(@get_value__package_id		integer,

	@get_value__parameter_name		varchar(8000)) 

RETURNS varchar

AS

BEGIN

declare @v_parameter_id	int





  select   @v_parameter_id = package_key   

     

    from apm_parameters  

     WHERE parameter_name  = @get_value__parameter_name  and package_key  = ( 

  select  package_key   

     

    from apm_packages  

     WHERE package_id  = @get_value__package_id  

     

      ) 

     

     

   RETURN CONVERT (varchar, dbo.apm__get_value ( @v_parameter_id ,

  	@get_value__package_id  ) )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm__set_value (integer,integer,varchar)

returns integer as '

declare

  set_value__parameter_id           alias for $1;  

  set_value__package_id             alias for $2;  

  set_value__attr_value             alias for $3;  

  v_value_id                        apm_parameter_values.value_id%TYPE;

begin

    

    select value_id into v_value_id from apm_parameter_values 

     where parameter_id = set_value__parameter_id 

     and package_id = set_value__package_id;

    update apm_parameter_values set attr_value = set_value__attr_value

     where parameter_id = set_value__parameter_id 

     and package_id = set_value__package_id;    

   

     if NOT FOUND

       then

         v_value_id := apm_parameter_value__new(

            null,

            set_value__package_id,

            set_value__parameter_id,

            set_value__attr_value

         );

     end if;



     return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm__set_value (integer,varchar,varchar)

returns integer as '

declare

  set_value__package_id             alias for $1;  

  set_value__parameter_name         alias for $2;  

  set_value__attr_value             alias for $3;  

  v_parameter_id                    apm_parameter_values.parameter_id%TYPE;

begin

    select parameter_id into v_parameter_id 

    from apm_parameters 

    where parameter_name = set_value__parameter_name

    and package_key = (select package_key  from apm_packages

			where package_id = set_value__package_id);



    if NOT FOUND

      then

      	raise EXCEPTION '-20000: The specified package % does not exist in the system.', set_value__package_id;

    end if;



    PERFORM apm__set_value(

	v_parameter_id,

	set_value__package_id,

	set_value__attr_value

    );



    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package__initialize_parameters (integer,varchar)

returns integer as '

declare

  ip__package_id             alias for $1;  

  ip__package_key            alias for $2;  

  v_value_id                 apm_parameter_values.value_id%TYPE;

  cur_val                    record;

begin

    

    for cur_val in select parameter_id, default_value

       from apm_parameters

       where package_key = ip__package_key

      loop

        v_value_id := apm_parameter_value__new(

          null,

          ip__package_id,

          cur_val.parameter_id,

          cur_val.default_value

        ); 

      end loop;   



      return 0; 

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__initialize_parameters(@ip__package_id		integer,

	@ip__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @cur_val__parameter_id  	int

declare @v_value_id	int

declare @cur_val__default_value  	varchar(8000)





  DECLARE cursor_1 CURSOR FOR

    

  select  parameter_id  , default_value   

     

    from apm_parameters  

     WHERE package_key  = @ip__package_key  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @cur_val__parameter_id  , @cur_val__default_value  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.apm_parameter_value__new null ,

    	@ip__package_id ,

    	cur_val.parameter_id ,

    	cur_val.default_value , @ms_return_value = @v_value_id OUTPUT

    

    

  

    FETCH NEXT FROM cursor_1 INTO @cur_val__parameter_id  , @cur_val__default_value  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   RETURN 0

  



RETURN NULL -- placeholder required by tsql

END -- function

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 29: Incorrect syntax near '.'.

 
[PG]
create function apm_package__new (integer,varchar,varchar,varchar,timestamp,integer,varchar,integer)

returns integer as '

declare

  new__package_id             alias for $1;  

  new__instance_name          alias for $2;  

  new__package_key            alias for $3;  

  new__object_type            alias for $4;  

  new__creation_date          alias for $5;  

  new__creation_user          alias for $6;  

  new__creation_ip            alias for $7;  

  new__context_id             alias for $8;  

  v_singleton_p               integer;       

  v_package_type              apm_package_types.package_type%TYPE;

  v_num_instances             integer;       

  v_package_id                apm_packages.package_id%TYPE;

  v_instance_name             apm_packages.instance_name%TYPE;

begin

   v_singleton_p := apm_package__singleton_p(

			new__package_key

		    );

   v_num_instances := apm_package__num_instances(

			new__package_key

		    );

  

   if v_singleton_p = 1 and v_num_instances >= 1 then

       select package_id into v_package_id 

       from apm_packages

       where package_key = new__package_key;



       return v_package_id;

   else

       v_package_id := acs_object__new(

          new__package_id,

          new__object_type,

          new__creation_date,

          new__creation_user,

	  new__creation_ip,

	  new__context_id

	 );

       if new__instance_name is null or new__instance_name = '' then 

	 v_instance_name := new__package_key + ' ' + v_package_id;

       else

	 v_instance_name := new__instance_name;

       end if;



       select package_type into v_package_type

       from apm_package_types

       where package_key = new__package_key;



       insert into apm_packages

       (package_id, package_key, instance_name)

       values

       (v_package_id, new__package_key, v_instance_name);



       if v_package_type = 'apm_application' then

	   insert into apm_applications

	   (application_id)

	   values

	   (v_package_id);

       else

	   insert into apm_services

	   (service_id)

	   values

	   (v_package_id);

       end if;



       PERFORM apm_package__initialize_parameters(

	   v_package_id,

	   new__package_key

       );



       return v_package_id;



  end if;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package__new

	@new__package_id		integer,

	@new__instance_name		varchar(8000),

	@new__package_key		varchar(8000),

	@new__object_type		varchar(8000),

	@new__creation_date		varchar(50),

	@new__creation_user		integer,

	@new__creation_ip		varchar(8000),

	@new__context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_singleton_p	integer

declare @v_package_id	int

declare @v_package_type	varchar(8000)

declare @v_instance_name	varchar(8000)

declare @perform	integer

declare @v_num_instances	integer



SET @v_singleton_p = dbo.apm_package__singleton_p ( @new__package_key  ) 

  

   SET @v_num_instances = dbo.apm_package__num_instances ( @new__package_key  ) 

  

   IF @v_singleton_p  = 1  and @v_num_instances  >= 1  BEGIN

  

    select   @v_package_id = package_id   

       

      from apm_packages  

       WHERE package_key  = @new__package_key  

       

       

     

    SET @ms_return_value = @v_package_id  

    RETURN @ms_return_value

    

    END

  ELSE BEGIN

  EXEC dbo.acs_object__new @new__package_id ,

    	@new__object_type ,

    	@new__creation_date ,

    	@new__creation_user ,

    	@new__creation_ip ,

    	@new__context_id , @ms_return_value = @v_package_id OUTPUT

    

     IF @new__instance_name  is null  or @new__instance_name  = ''  BEGIN

    SET @v_instance_name = @new__package_key  + ' '  + @v_package_id 

      

      END

    ELSE BEGIN

    SET @v_instance_name = @new__instance_name 

      

      

    END --IF

    

    

     

    select   @v_package_type = package_type   

       

      from apm_package_types  

       WHERE package_key  = @new__package_key  

       

       

     

    insert into apm_packages ( package_id, package_key, instance_name ) values ( @v_package_id  , @new__package_key  , @v_instance_name   )

     IF @v_package_type  = 'apm_application'  BEGIN

    

      insert into apm_applications ( application_id ) values ( @v_package_id   )

      END

    ELSE BEGIN

    

      insert into apm_services ( service_id ) values ( @v_package_id   )

      

    END --IF

    

    

     SELECT @perform = dbo.apm_package__initialize_parameters ( @v_package_id ,

    	@new__package_key  )

     

    SET @ms_return_value = @v_package_id  

    RETURN @ms_return_value

    

    

  END --IF

  

  

  

END -- stored proc


 
[PG]
create function apm_package__delete (integer) returns integer as '

declare

   delete__package_id   alias for $1;

   cur_val              record;

begin

    

    for cur_val in select value_id from apm_parameter_values

	where package_id = delete__package_id loop

    	PERFORM apm_parameter_value__delete(cur_val.value_id);

    end loop;    



    delete from apm_applications where application_id = delete__package_id;

    delete from apm_services where service_id = delete__package_id;

    delete from apm_packages where package_id = delete__package_id;

    

    for cur_val in select node_id from site_nodes

	where object_id = delete__package_id loop

    	PERFORM site_node__delete(cur_val.node_id);

    end loop;

    

    PERFORM acs_object__delete (

       delete__package_id

    );   



    return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package__delete

	@delete__package_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @cur_val__node_id  	int

declare @cur_val__value_id  	int





  DECLARE cursor_1 CURSOR FOR

    

  select  value_id   

     

    from apm_parameter_values  

     WHERE package_id  = @delete__package_id  

     

     

  

  OPEN cursor_1

  

  FETCH NEXT FROM cursor_1 INTO @cur_val__value_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.apm_parameter_value__delete @cur_val__value_id  

    

  

    FETCH NEXT FROM cursor_1 INTO @cur_val__value_id  

  END --while

  

  CLOSE cursor_1

  

  DEALLOCATE cursor_1

  

  

   delete from apm_applications  WHERE application_id  = @delete__package_id 

   delete from apm_services  WHERE service_id  = @delete__package_id 

   delete from apm_packages  WHERE package_id  = @delete__package_id 

   

  DECLARE cursor_2 CURSOR FOR

    

  select  node_id   

     

    from site_nodes  

     WHERE object_id  = @delete__package_id  

     

     

  

  OPEN cursor_2

  

  FETCH NEXT FROM cursor_2 INTO @cur_val__node_id  

  

  WHILE (@@FETCH_STATUS = 0)

  BEGIN

  EXEC dbo.site_node__delete @cur_val__node_id  

    

  

    FETCH NEXT FROM cursor_2 INTO @cur_val__node_id  

  END --while

  

  CLOSE cursor_2

  

  DEALLOCATE cursor_2

  

  

   EXEC dbo.acs_object__delete @delete__package_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package__initial_install_p (varchar) returns integer as '

declare

	initial_install_p__package_key  alias for $1;

        v_initial_install_p             integer;

begin

        select 1 into v_initial_install_p

	from apm_package_types

	where package_key = initial_install_p__package_key

        and initial_install_p = 't';

	

        if NOT FOUND then 

           return 0;

        else

           return v_initial_install_p;

        end if;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__initial_install_p(@initial_install_p__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_initial_install_p	integer





  select   @v_initial_install_p = 1   

     

    from apm_package_types  

     WHERE package_key  = @initial_install_p__package_key  and initial_install_p  = 't'  

     

     

   IF  @@ROWCOUNT = 0   BEGIN

  RETURN 0

    END

  ELSE BEGIN

  RETURN CONVERT (integer, @v_initial_install_p )

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_package__singleton_p (varchar) returns integer as '

declare

	singleton_p__package_key        alias for $1;

        v_singleton_p                   integer;

begin

        select 1 into v_singleton_p

	from apm_package_types

	where package_key = singleton_p__package_key

        and singleton_p = 't';

	

        if NOT FOUND then 

           return 0;

        else

           return v_singleton_p;

        end if;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__singleton_p(@singleton_p__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_singleton_p	integer





  select   @v_singleton_p = 1   

     

    from apm_package_types  

     WHERE package_key  = @singleton_p__package_key  and singleton_p  = 't'  

     

     

   IF  @@ROWCOUNT = 0   BEGIN

  RETURN 0

    END

  ELSE BEGIN

  RETURN CONVERT (integer, @v_singleton_p )

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_package__num_instances (varchar) returns integer as '

declare

        num_instances__package_key     alias for $1;

        v_num_instances                integer;

begin

        select count(*) into v_num_instances

	from apm_packages

	where package_key = num_instances__package_key;

	

	

	if NOT FOUND then

           return 0;

        else 

           return v_num_instances;

        end if;

        

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__num_instances(@num_instances__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_num_instances	integer





  select   @v_num_instances = count ( * )   

     

    from apm_packages  

     WHERE package_key  = @num_instances__package_key  

     

     

   IF  @@ROWCOUNT = 0   BEGIN

  RETURN 0

    END

  ELSE BEGIN

  RETURN CONVERT (integer, @v_num_instances )

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_package__name (integer) returns varchar as '

declare

    name__package_id       alias for $1;

    v_result               apm_packages.instance_name%TYPE;

begin

    select instance_name into v_result

    from apm_packages

    where package_id = name__package_id;



    return v_result;



end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__name(@name__package_id		integer) 

RETURNS varchar

AS

BEGIN

declare @v_result	varchar(8000)





  select   @v_result = instance_name   

     

    from apm_packages  

     WHERE package_id  = @name__package_id  

     

     

   RETURN CONVERT (varchar, @v_result )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_package__enable (integer) returns integer as '

declare

       enable__package_id       alias for $1;

begin

      update apm_packages 

      set enabled_p = 't'

      where package_id = enable__package_id;	



      return 0;

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package__disable (integer) returns integer as '

declare

       disable__package_id           alias for $1;

begin

      update apm_packages 

      set enabled_p = 'f'

      where package_id = disable__package_id;



      returns 0;	

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package__highest_version (varchar) returns integer as '

declare

     highest_version__package_key    alias for $1;

     v_version_id                    apm_package_versions.version_id%TYPE;

begin

     select version_id into v_version_id

	from apm_package_version_info i 

	where apm_package_version__sortable_version_name(version_name) = 

             (select max(apm_package_version__sortable_version_name(v.version_name))

	             from apm_package_version_info v where v.package_key = highest_version__package_key)

	and package_key = highest_version__package_key;

      if NOT FOUND then 

         return 0;

      else

         return v_version_id;

      end if;

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package__highest_version(@highest_version__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_version_id	int





  select   @v_version_id = max ( dbo.apm_package_version__sortable_version_name ( v.version_name  )  )   

     

    from apm_package_version_info i 

     WHERE dbo.apm_package_version__sortable_version_name ( version_name  )  = ( 

  select  max ( dbo.apm_package_version__sortable_version_name ( v.version_name  )  )   

     

    from apm_package_version_info v 

     WHERE v.package_key  = @highest_version__package_key  

     

      ) and package_key  = @highest_version__package_key  

     

     

   IF  @@ROWCOUNT = 0   BEGIN

  RETURN 0

    END

  ELSE BEGIN

  RETURN CONVERT (integer, @v_version_id )

    

  END --IF

  

  

  



RETURN NULL -- placeholder required by tsql

END -- function

[Microsoft][ODBC SQL Server Driver][SQL Server]The column prefix 'v' does not match with a table name or alias name used in the query.

 
[PG]
create function apm_package_version__new (integer,varchar,varchar,varchar,varchar,varchar,varchar,timestamp,varchar,varchar,boolean,boolean) returns integer as '

declare

      apm_pkg_ver__version_id           alias for $1;  

      apm_pkg_ver__package_key		alias for $2;

      apm_pkg_ver__version_name		alias for $3;  

      apm_pkg_ver__version_uri		alias for $4;

      apm_pkg_ver__summary              alias for $5;

      apm_pkg_ver__description_format	alias for $6;

      apm_pkg_ver__description		alias for $7;

      apm_pkg_ver__release_date		alias for $8;

      apm_pkg_ver__vendor               alias for $9;

      apm_pkg_ver__vendor_uri		alias for $10;

      apm_pkg_ver__installed_p		alias for $11; 

      apm_pkg_ver__data_model_loaded_p	alias for $12; 

      v_version_id                      apm_package_versions.version_id%TYPE;

begin

      if apm_pkg_ver__version_id = '' or apm_pkg_ver__version_id is null then

         select acs_object_id_seq.nextval

	 into v_version_id

	 from dual;

      else

         v_version_id := apm_pkg_ver__version_id;

      end if;



      v_version_id := acs_object__new(

		v_version_id,

		'apm_package_version',

                now(),

                null,

                null,

                null

        );



      insert into apm_package_versions

      (version_id, package_key, version_name, version_uri, summary, description_format, description,

      release_date, vendor, vendor_uri, installed_p, data_model_loaded_p)

      values

      (v_version_id, apm_pkg_ver__package_key, apm_pkg_ver__version_name, 

       apm_pkg_ver__version_uri, apm_pkg_ver__summary, 

       apm_pkg_ver__description_format, apm_pkg_ver__description,

       apm_pkg_ver__release_date, apm_pkg_ver__vendor, apm_pkg_ver__vendor_uri,

       apm_pkg_ver__installed_p, apm_pkg_ver__data_model_loaded_p);



      return v_version_id;		

  

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__new

	@apm_pkg_ver__version_id		integer,

	@apm_pkg_ver__package_key		varchar(8000),

	@apm_pkg_ver__version_name		varchar(8000),

	@apm_pkg_ver__version_uri		varchar(8000),

	@apm_pkg_ver__summary		varchar(8000),

	@apm_pkg_ver__description_format		varchar(8000),

	@apm_pkg_ver__description		varchar(8000),

	@apm_pkg_ver__release_date		varchar(50),

	@apm_pkg_ver__vendor		varchar(8000),

	@apm_pkg_ver__vendor_uri		varchar(8000),

	@apm_pkg_ver__installed_p		boolean,

	@apm_pkg_ver__data_model_loaded_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_version_id	int



IF @apm_pkg_ver__version_id  = ''  or @apm_pkg_ver__version_id  is null  BEGIN

  exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

    select   @v_version_id = @retval   

       

        

       

       

       

    END

  ELSE BEGIN

  SET @v_version_id = @apm_pkg_ver__version_id 

    

    

  END --IF

  

  

   EXEC dbo.acs_object__new @v_version_id ,

  	'apm_package_version' ,

  	getdate ,

  	null ,

  	null ,

  	null , @ms_return_value = @v_version_id OUTPUT

  

   

  insert into apm_package_versions ( version_id, package_key, version_name, version_uri, summary, description_format, description, release_date, vendor, vendor_uri, installed_p, data_model_loaded_p ) values ( @v_version_id  , @apm_pkg_ver__package_key  , @apm_pkg_ver__version_name  , @apm_pkg_ver__version_uri  , @apm_pkg_ver__summary  , @apm_pkg_ver__description_format  , @apm_pkg_ver__description  , @apm_pkg_ver__release_date  , @apm_pkg_ver__vendor  , @apm_pkg_ver__vendor_uri  , @apm_pkg_ver__installed_p  , @apm_pkg_ver__data_model_loaded_p   )

   

  SET @ms_return_value = @v_version_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_package_version__delete (integer)

returns integer as '

declare

  delete__version_id             alias for $1;  

begin

      delete from apm_package_owners 

      where version_id = delete__version_id; 



      delete from apm_package_files

      where version_id = delete__version_id;



      delete from apm_package_dependencies

      where version_id = delete__version_id;



      delete from apm_package_versions 

	where version_id = delete__version_id;



      PERFORM acs_object__delete(delete__version_id);



      return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__delete

	@delete__version_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_package_owners  WHERE version_id  = @delete__version_id 

   delete from apm_package_files  WHERE version_id  = @delete__version_id 

   delete from apm_package_dependencies  WHERE version_id  = @delete__version_id 

   delete from apm_package_versions  WHERE version_id  = @delete__version_id 

   EXEC dbo.acs_object__delete @delete__version_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_version__enable (integer)

returns integer as '

declare

  enable__version_id             alias for $1;  

begin

      update apm_package_versions set enabled_p = 't'

      where version_id = enable__version_id;	



      return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package_version__disable (integer)

returns integer as '

declare

  disable__version_id             alias for $1;  

begin

      update apm_package_versions 

      set enabled_p = 'f'

      where version_id = disable__version_id;	



      return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package_version__copy (integer,integer,varchar,varchar)

returns integer as '

declare

  copy__version_id             alias for $1;  

  copy__new_version_id         alias for $2;  

  copy__new_version_name       alias for $3;  

  copy__new_version_uri        alias for $4;  

  v_version_id                 integer;       

begin

	v_version_id := acs_object__new(

		copy__new_version_id,

		'apm_package_version',

                now(),

                null,

                null,

                null

        );    



	insert into apm_package_versions(version_id, package_key, version_name,

					version_uri, summary, description_format, description,

					release_date, vendor, vendor_uri)

	    select v_version_id, package_key, copy__new_version_name,

		   copy__new_version_uri, summary, description_format, description,

		   release_date, vendor, vendor_uri

	    from apm_package_versions

	    where version_id = copy__version_id;

    

	insert into apm_package_dependencies(dependency_id, version_id, dependency_type, service_uri, service_version)

	    select acs_object_id_seq.nextval, v_version_id, dependency_type, service_uri, service_version

	    from apm_package_dependencies

	    where version_id = copy__version_id;

    

	insert into apm_package_files(file_id, version_id, path, file_type)

	    select acs_object_id_seq.nextval, v_version_id, path, file_type

	    from apm_package_files

	    where version_id = copy__version_id;

    

	insert into apm_package_owners(version_id, owner_uri, owner_name, sort_key)

	    select v_version_id, owner_uri, owner_name, sort_key

	    from apm_package_owners

	    where version_id = copy__version_id;

    

	return v_version_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__copy

	@copy__version_id		integer,

	@copy__new_version_id		integer,

	@copy__new_version_name		varchar(8000),

	@copy__new_version_uri		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_version_id	integer



EXEC dbo.acs_object__new @copy__new_version_id ,

  	'apm_package_version' ,

  	getdate ,

  	null ,

  	null ,

  	null , @ms_return_value = @v_version_id OUTPUT

  

   

  insert into apm_package_versions ( version_id, package_key, version_name, version_uri, summary, description_format, description, release_date, vendor, vendor_uri ) 

  select  @v_version_id  , package_key  , @copy__new_version_name  , @copy__new_version_uri  , summary  , description_format  , description  , release_date  , vendor  , vendor_uri   

     

    from apm_package_versions  

     WHERE version_id  = @copy__version_id  

     

     

   

  insert into apm_package_dependencies ( dependency_id, version_id, dependency_type, service_uri, service_version ) exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

  select  @retval  , @v_version_id  , dependency_type  , service_uri  , service_version   

     

    from apm_package_dependencies  

     WHERE version_id  = @copy__version_id  

     

     

   

  insert into apm_package_files ( file_id, version_id, path, file_type ) 

  select  @retval  , @v_version_id  , path  , file_type   

     

    from apm_package_files  

     WHERE version_id  = @copy__version_id  

     

     

   

  insert into apm_package_owners ( version_id, owner_uri, owner_name, sort_key ) 

  select  @v_version_id  , owner_uri  , owner_name  , sort_key   

     

    from apm_package_owners  

     WHERE version_id  = @copy__version_id  

     

     

   

  SET @ms_return_value = @v_version_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_package_version__edit (integer,integer,varchar,varchar,varchar,varchar,varchar,timestamp,varchar,varchar,boolean,boolean)

returns integer as '

declare

  edit__new_version_id         alias for $1;  

  edit__version_id             alias for $2;  

  edit__version_name           alias for $3;  

  edit__version_uri            alias for $4;  

  edit__summary                alias for $5;  

  edit__description_format     alias for $6;  

  edit__description            alias for $7;  

  edit__release_date           alias for $8;  

  edit__vendor                 alias for $9;  

  edit__vendor_uri             alias for $10; 

  edit__installed_p            alias for $11; 

  edit__data_model_loaded_p    alias for $12; 

  v_version_id                 apm_package_versions.version_id%TYPE;

  version_unchanged_p          integer;       

begin

       

       select case when count(*) = 0 then 0 else 1 end into version_unchanged_p

       from apm_package_versions

       where version_id = edit__version_id

       and version_name = edit__version_name;

       if version_unchanged_p <> 1 then

         v_version_id := apm_package_version__copy(

			 edit__version_id,

			 edit__new_version_id,

			 edit__version_name,

			 edit__version_uri

			);

         else 

	   v_version_id := edit__version_id;			

       end if;

       

       update apm_package_versions 

		set version_uri = edit__version_uri,

		summary = edit__summary,

		description_format = edit__description_format,

		description = edit__description,

		release_date = date_trunc('days',now()),

		vendor = edit__vendor,

		vendor_uri = edit__vendor_uri,

		installed_p = edit__installed_p,

		data_model_loaded_p = edit__data_model_loaded_p

	    where version_id = v_version_id;



	return v_version_id;

     

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package_version__add_file (integer,integer,varchar,varchar, varchar)

returns integer as '

declare

  add_file__file_id                alias for $1;  

  add_file__version_id             alias for $2;  

  add_file__path                   alias for $3;  

  add_file__file_type              alias for $4;  

  add_file__db_type                alias for $5;  

  v_file_id                        apm_package_files.file_id%TYPE;

  v_file_exists_p                  integer;       

begin

	select file_id into v_file_id from apm_package_files

  	where version_id = add_file__version_id 

	and path = add_file__path;



	if NOT FOUND 

	       then

	       	if add_file__file_id is null then

	          select acs_object_id_seq.nextval into v_file_id from dual;

	        else

	          v_file_id := add_file__file_id;

	        end if;



  	        insert into apm_package_files 

		(file_id, version_id, path, file_type, db_type) 

		values 

		(v_file_id, add_file__version_id, add_file__path, add_file__file_type, add_file__db_type);

        end if;



        return v_file_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__add_file

	@add_file__file_id		integer,

	@add_file__version_id		integer,

	@add_file__path		varchar(8000),

	@add_file__file_type		varchar(8000),

	@add_file__db_type		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_file_exists_p	integer

declare @v_file_id	int





  select   @v_file_id = [file_id]   

     

    from apm_package_files  

     WHERE version_id  = @add_file__version_id  and path  = @add_file__path  

     

     

   IF  @@ROWCOUNT = 0   BEGIN

  IF @add_file__file_id  is null  BEGIN

    exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

      select   @v_file_id = @retval   

         

          

         

         

         

      END

    ELSE BEGIN

    SET @v_file_id = @add_file__file_id 

      

      

    END --IF

    

    

     

    insert into apm_package_files (  [file_id], version_id, path, file_type, db_type ) values ( @v_file_id  , @add_file__version_id  , @add_file__path  , @add_file__file_type  , @add_file__db_type   )

    

  END --IF

  

  

   

  SET @ms_return_value = @v_file_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_package_version__remove_file (integer,varchar)

returns integer as '

declare

  remove_file__version_id             alias for $1;  

  remove_file__path                   alias for $2;  

begin

    delete from apm_package_files 

    where version_id = remove_file__version_id

    and path = remove_file__path;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__remove_file

	@remove_file__version_id		integer,

	@remove_file__path		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_package_files  WHERE version_id  = @remove_file__version_id  and path  = @remove_file__path 

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_version__add_interface (integer,integer,varchar,varchar)

returns integer as '

declare

  add_interface__interface_id         alias for $1;  

  add_interface__version_id           alias for $2;  

  add_interface__interface_uri        alias for $3;  

  add_interface__interface_version    alias for $4;  

  v_dep_id                            apm_package_dependencies.dependency_id%TYPE;

begin

      if add_interface__interface_id is null then

          select acs_object_id_seq.nextval into v_dep_id from dual;

      else

          v_dep_id := add_interface__interface_id;

      end if;

  

      insert into apm_package_dependencies

      (dependency_id, version_id, dependency_type, service_uri, service_version)

      values

      (v_dep_id, add_interface__version_id, 'provides', add_interface__interface_uri,

	add_interface__interface_version);



      return v_dep_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__add_interface

	@add_interface__interface_id		integer,

	@add_interface__version_id		integer,

	@add_interface__interface_uri		varchar(8000),

	@add_interface__interface_version		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_dep_id	int



IF @add_interface__interface_id  is null  BEGIN

  exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

    select   @v_dep_id = @retval   

       

        

       

       

       

    END

  ELSE BEGIN

  SET @v_dep_id = @add_interface__interface_id 

    

    

  END --IF

  

  

   

  insert into apm_package_dependencies ( dependency_id, version_id, dependency_type, service_uri, service_version ) values ( @v_dep_id  , @add_interface__version_id  , 'provides'  , @add_interface__interface_uri  , @add_interface__interface_version   )

   

  SET @ms_return_value = @v_dep_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_package_version__remove_interface (integer)

returns integer as '

declare

  remove_interface__interface_id           alias for $1;  

begin

    delete from apm_package_dependencies 

    where dependency_id = remove_interface__interface_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__remove_interface

	@remove_interface__interface_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_package_dependencies  WHERE dependency_id  = @remove_interface__interface_id 

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_version__remove_interface (varchar,varchar,integer)

returns integer as '

declare

  remove_interface__interface_uri          alias for $1;  

  remove_interface__interface_version      alias for $2;  

  remove_interface__version_id             alias for $3;  

  v_dep_id                           apm_package_dependencies.dependency_id%TYPE;

begin

      select dependency_id into v_dep_id from apm_package_dependencies

      where service_uri = remove_interface__interface_uri 

      and interface_version = remove_interface__interface_version;

      PERFORM apm_package_version__remove_interface(v_dep_id);



      return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__remove_interface_3

	@remove_interface__interface_uri		varchar(8000),

	@remove_interface__interface_version		varchar(8000),

	@remove_interface__version_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_dep_id	int





  select   @v_dep_id = dependency_id   

     

    from apm_package_dependencies  

     WHERE service_uri  = @remove_interface__interface_uri  and interface_version  = @remove_interface__interface_version  

     

     

   EXEC dbo.apm_package_version__remove_interface @v_dep_id  

   RETURN 0

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'interface_version'.

 
[PG]
create function apm_package_version__add_dependency (integer,integer,varchar,varchar)

returns integer as '

declare

  add_dependency__dependency_id          alias for $1;  

  add_dependency__version_id             alias for $2;  

  add_dependency__dependency_uri         alias for $3;  

  add_dependency__dependency_version     alias for $4;  

  v_dep_id                            apm_package_dependencies.dependency_id%TYPE;

begin

      if add_dependency__dependency_id is null then

          select acs_object_id_seq.nextval into v_dep_id from dual;

      else

          v_dep_id := add_dependency__dependency_id;

      end if;

  

      insert into apm_package_dependencies

      (dependency_id, version_id, dependency_type, service_uri, service_version)

      values

      (v_dep_id, add_dependency__version_id, 'requires', add_dependency__dependency_uri,

	add_dependency__dependency_version);



      return v_dep_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__add_dependency

	@add_dependency__dependency_id		integer,

	@add_dependency__version_id		integer,

	@add_dependency__dependency_uri		varchar(8000),

	@add_dependency__dependency_version		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @retval	int

declare @v_dep_id	int



IF @add_dependency__dependency_id  is null  BEGIN

  exec acs_object_id_seq__nextval    @ms_return_value = @retval OUTPUT 

    select   @v_dep_id = @retval   

       

        

       

       

       

    END

  ELSE BEGIN

  SET @v_dep_id = @add_dependency__dependency_id 

    

    

  END --IF

  

  

   

  insert into apm_package_dependencies ( dependency_id, version_id, dependency_type, service_uri, service_version ) values ( @v_dep_id  , @add_dependency__version_id  , 'requires'  , @add_dependency__dependency_uri  , @add_dependency__dependency_version   )

   

  SET @ms_return_value = @v_dep_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_package_version__remove_dependency (integer)

returns integer as '

declare

  remove_dependency__dependency_id          alias for $1;  

begin

    delete from apm_package_dependencies 

    where dependency_id = remove_dependency__dependency_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__remove_dependency

	@remove_dependency__dependency_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_package_dependencies  WHERE dependency_id  = @remove_dependency__dependency_id 

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_version__remove_dependency (varchar,varchar,integer)

returns integer as '

declare

  remove_dependency__dependency_uri         alias for $1;  

  remove_dependency__dependency_version     alias for $2;  

  remove_dependency__version_id             alias for $3;  

  v_dep_id                           apm_package_dependencies.dependency_id%TYPE;

begin

      select dependency_id into v_dep_id from apm_package_dependencies 

      where service_uri = remove_dependency__dependency_uri 

      and service_version = remove_dependency__dependency_version;

      PERFORM apm_package_version__remove_dependency(v_dep_id);



      return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_version__remove_dependency_3

	@remove_dependency__dependency_uri		varchar(8000),

	@remove_dependency__dependency_version		varchar(8000),

	@remove_dependency__version_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_dep_id	int





  select   @v_dep_id = dependency_id   

     

    from apm_package_dependencies  

     WHERE service_uri  = @remove_dependency__dependency_uri  and service_version  = @remove_dependency__dependency_version  

     

     

   EXEC dbo.apm_package_version__remove_dependency @v_dep_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_version__sortable_version_name (varchar)

returns varchar as '

declare

  version_name           alias for $1;  

  a_start                integer;       

  a_end                  integer;       

  a_order                varchar(1000) default ''; 

  a_char                 char(1);       

  a_seen_letter          boolean default 'f';        

begin

	a_start := 1;

	loop

	    a_end := a_start;

    

	    

	    while substr(version_name, a_end, 1) >= '0' and substr(version_name, a_end, 1) <= '9' loop

		a_end := a_end + 1;

	    end loop;

	    if a_end = a_start then

	    	return -1;

		

	    end if;

	    if a_end - a_start > 4 then

	    	return -1;

		

	    end if;

    

	    

	    a_order := a_order + substr('0000', 1, 4 - (a_end - a_start)) +

		substr(version_name, a_start, a_end - a_start) + '.';

	    if a_end > length(version_name) then

		

		if a_seen_letter = 'f' then

		    

		    

		    a_order := a_order + '  3F.';

		end if;

		return a_order;

	    end if;

    

	    

	    a_char := substr(version_name, a_end, 1);

	    if a_char = '.' then

	    else

		

		if a_char = 'd' then

		    a_order := a_order + '  0D.';

		else if a_char = 'a' then

		    a_order := a_order + '  1A.';

		else if a_char = 'b' then

		    a_order := a_order + '  2B.';

		end if; end if; end if;

    

		

		if a_seen_letter = 't' then

		    return -1;

		    

		    

		end if;

		a_seen_letter := 't';

    

		

		if a_end = length(version_name) then

		    return a_order;

		end if;

	    end if;

	    a_start := a_end + 1;

	end loop;

    

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package_version__version_name_greater (varchar,varchar)

returns integer as '

declare

  version_name_one       alias for $1;  

  version_name_two       alias for $2;

  a_order_a		 varchar(250);

  a_order_b		 varchar(250);  

begin

	a_order_a := apm_package_version__sortable_version_name(version_name_one);

	a_order_b := apm_package_version__sortable_version_name(version_name_two);

	if a_order_a < a_order_b then

	    return -1;

	else if a_order_a > a_order_b then

	    return 1;

	end if; end if;



	return 0;   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package_version__version_name_greater(@version_name_one		varchar(8000),

	@version_name_two		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @a_order_b	varchar ( 250 )

declare @a_order_a	varchar ( 250 )



SET @a_order_a = dbo.apm_package_version__sortable_version_name ( @version_name_one  ) 

  

   SET @a_order_b = dbo.apm_package_version__sortable_version_name ( @version_name_two  ) 

  

   IF @a_order_a  < @a_order_b  BEGIN

  RETURN CONVERT (integer, -1 )

    END

  ELSE BEGIN

  IF @a_order_a  > @a_order_b  BEGIN

    RETURN CONVERT (integer, 1 )

      

    END --IF

    

    

    

  END --IF

  

  

   RETURN 0

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_package_version__upgrade_p (varchar,varchar,varchar)

returns integer as '

declare

  upgrade_p__path                   alias for $1;  

  upgrade_p__initial_version_name   alias for $2;  

  upgrade_p__final_version_name     alias for $3;  

  v_pos1                            integer;       

  v_pos2                            integer;       

  v_tmp                             apm_package_files.path%TYPE;

  v_path                            apm_package_files.path%TYPE;

  v_version_from                    apm_package_versions.version_name%TYPE;

  v_version_to                      apm_package_versions.version_name%TYPE;

begin



	

	v_path := substr(upgrade_p__path, instr(upgrade_p__path, '/', -1) + 1);



	

	v_pos1 := position('.' in v_path);

	if v_pos1 > 0 and substr(v_path, v_pos1) = '.sql' then

	    v_path := substr(v_path, 1, v_pos1 - 1);

	end if;



	

	v_pos1 := instr(v_path, '-', -1, 2);

	v_pos2 := instr(v_path, '-', -1);

	if v_pos1 = 0 or v_pos2 = 0 then

	    

	    return 0;

	end if;



	v_version_from := substr(v_path, v_pos1 + 1, v_pos2 - v_pos1 - 1);

	v_version_to := substr(v_path, v_pos2 + 1);



	if apm_package_version__version_name_greater(upgrade_p__initial_version_name, v_version_from) <= 0 and

	   apm_package_version__version_name_greater(upgrade_p__final_version_name, v_version_to) >= 0 then

	    return 1;

	end if;



	return 0;

        

	

	

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package_version__upgrade_p(@upgrade_p__path		varchar(8000),

	@upgrade_p__initial_version_name		varchar(8000),

	@upgrade_p__final_version_name		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_version_to	varchar(8000)

declare @v_tmp	varchar(8000)

declare @v_version_from	varchar(8000)

declare @v_pos1	integer

declare @v_path	varchar(8000)

declare @v_pos2	integer



SET @v_path = substring ( @upgrade_p__path  , dbo.instr( @upgrade_p__path ,

  	'/' ,

  	-1  )  + 1  , datalength ( @upgrade_p__path  )  ) 

  

   SET @v_pos1 = charindex ( '.'  , @v_path  ) 

  

   IF @v_pos1  > 0  and substring ( @v_path  , @v_pos1  , datalength ( @v_path  )  )  = '.sql'  BEGIN

  SET @v_path = substring ( @v_path  , 1  , @v_pos1  - 1  ) 

    

    

  END --IF

  

  

   SET @v_pos1 = dbo.instr( @v_path ,

  	'-' ,

  	-1 ,

  	2  ) 

  

   SET @v_pos2 = dbo.instr( @v_path ,

  	'-' ,

  	-1  ) 

  

   IF @v_pos1  = 0  or @v_pos2  = 0  BEGIN

  RETURN 0

    

  END --IF

  

  

   SET @v_version_from = substring ( @v_path  , @v_pos1  + 1  , @v_pos2  - @v_pos1  - 1  ) 

  

   SET @v_version_to = substring ( @v_path  , @v_pos2  + 1  , datalength ( @v_path  )  ) 

  

   IF dbo.apm_package_version__version_name_greater ( @upgrade_p__initial_version_name ,

  	@v_version_from  )  <= 0  and dbo.apm_package_version__version_name_greater ( @upgrade_p__final_version_name ,

  	@v_version_to  )  >= 0  BEGIN

  RETURN CONVERT (integer, 1 )

    

  END --IF

  

  

   RETURN 0

  



RETURN NULL -- placeholder required by tsql

END -- function

[Microsoft][ODBC SQL Server Driver][SQL Server]An insufficient number of arguments were supplied for the procedure or function dbo.instr.

 
[PG]
create function apm_package_version__upgrade (integer)

returns integer as '

declare

  upgrade__version_id             alias for $1;  

begin

    update apm_package_versions

    	set enabled_p = 'f',

	    installed_p = 'f'

	where package_key = (select package_key from apm_package_versions

	    	    	     where version_id = upgrade__version_id);

    update apm_package_versions

    	set enabled_p = 't',

	    installed_p = 't'

	where version_id = upgrade__version_id;			  

    

    return 0; 

end;' language 'plpgsql'
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]An insufficient number of arguments were supplied for the procedure or function dbo.instr.

 
[PG]
create function apm_package_type__create_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns integer as '

declare

  create_type__package_key            alias for $1;  

  create_type__pretty_name            alias for $2;  

  create_type__pretty_plural          alias for $3;  

  create_type__package_uri            alias for $4;  

  create_type__package_type           alias for $5;  

  create_type__initial_install_p      alias for $6;  

  create_type__singleton_p            alias for $7;  

  create_type__spec_file_path         alias for $8;  

  create_type__spec_file_mtime        alias for $9;  

begin

   insert into apm_package_types

    (package_key, pretty_name, pretty_plural, package_uri, package_type,

    spec_file_path, spec_file_mtime, initial_install_p, singleton_p)

   values

    (create_type__package_key, create_type__pretty_name, create_type__pretty_plural,

     create_type__package_uri, create_type__package_type, create_type__spec_file_path, 

     create_type__spec_file_mtime, create_type__initial_install_p, create_type__singleton_p);



   return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_type__create_type

	@create_type__package_key		varchar(8000),

	@create_type__pretty_name		varchar(8000),

	@create_type__pretty_plural		varchar(8000),

	@create_type__package_uri		varchar(8000),

	@create_type__package_type		varchar(8000),

	@create_type__initial_install_p		boolean,

	@create_type__singleton_p		boolean,

	@create_type__spec_file_path		varchar(8000),

	@create_type__spec_file_mtime		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN





  insert into apm_package_types ( package_key, pretty_name, pretty_plural, package_uri, package_type, spec_file_path, spec_file_mtime, initial_install_p, singleton_p ) values ( @create_type__package_key  , @create_type__pretty_name  , @create_type__pretty_plural  , @create_type__package_uri  , @create_type__package_type  , @create_type__spec_file_path  , @create_type__spec_file_mtime  , @create_type__initial_install_p  , @create_type__singleton_p   )

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_type__update_type (varchar,varchar,varchar,varchar,varchar,boolean,boolean,varchar,integer)

returns varchar as '

declare

  update_type__package_key            alias for $1;  

  update_type__pretty_name            alias for $2;  

  update_type__pretty_plural          alias for $3;  

  update_type__package_uri            alias for $4;  

  update_type__package_type           alias for $5;  

  update_type__initial_install_p      alias for $6;  

  update_type__singleton_p            alias for $7;  

  update_type__spec_file_path         alias for $8;  

  update_type__spec_file_mtime        alias for $9;  

begin

      UPDATE apm_package_types SET

      	pretty_name = coalesce(update_type__pretty_name, pretty_name),

    	pretty_plural = coalesce(update_type__pretty_plural, pretty_plural),

    	package_uri = coalesce(update_type__package_uri, package_uri),

    	package_type = coalesce(update_type__package_type, package_type),

    	spec_file_path = coalesce(update_type__spec_file_path, spec_file_path),

    	spec_file_mtime = coalesce(update_type__spec_file_mtime, spec_file_mtime),

    	singleton_p = coalesce(update_type__singleton_p, singleton_p)

    	initial_install_p = coalesce(update_type__initial_install_p, initial_install_p)

      where package_key = update_type__package_key;



      return update_type__package_key;

   

end;' language 'plpgsql'
[MSSQL]
/* Skipped */

 
[PG]
create function apm_package_type__drop_type (varchar,boolean)

returns integer as '

declare

  drop_type__package_key            alias for $1;  

  drop_type__cascade_p              alias for $2;  

  cur_val                           record; 

begin

    if drop_type__cascade_p = 't' then

        for cur_val in select package_id

       from apm_packages

       where package_key = drop_type__package_key

        loop

            PERFORM apm_package__delete(

	        cur_val.package_id

	    );

        end loop;

	

        for cur_val in select parameter_id from apm_parameters

       where package_key = drop_type__package_key

	loop

	    PERFORM apm__unregister_parameter(cur_val.parameter_id);

	end loop;

  

        

	for cur_val in select version_id from apm_package_versions

       where package_key = drop_type__package_key

	loop

	    PERFORM apm_package_version__delete(cur_val.version_id);

        end loop;

    end if;

    delete from apm_package_types

    where package_key = drop_type__package_key;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_package_type__drop_type

	@drop_type__package_key		varchar(8000),

	@drop_type__cascade_p		boolean, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @cur_val__parameter_id  	int

declare @cur_val__package_id  	int

declare @cur_val__version_id  	int



IF @drop_type__cascade_p  = 't'  BEGIN

  

    DECLARE cursor_1 CURSOR FOR

      

    select  package_id   

       

      from apm_packages  

       WHERE package_key  = @drop_type__package_key  

       

       

    

    OPEN cursor_1

    

    FETCH NEXT FROM cursor_1 INTO @cur_val__package_id  

    

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    EXEC dbo.apm_package__delete @cur_val__package_id  

      

    

      FETCH NEXT FROM cursor_1 INTO @cur_val__package_id  

    END --while

    

    CLOSE cursor_1

    

    DEALLOCATE cursor_1

    

    

     

    DECLARE cursor_2 CURSOR FOR

      

    select  parameter_id   

       

      from apm_parameters  

       WHERE package_key  = @drop_type__package_key  

       

       

    

    OPEN cursor_2

    

    FETCH NEXT FROM cursor_2 INTO @cur_val__parameter_id  

    

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    EXEC dbo.apm__unregister_parameter @cur_val__parameter_id  

      

    

      FETCH NEXT FROM cursor_2 INTO @cur_val__parameter_id  

    END --while

    

    CLOSE cursor_2

    

    DEALLOCATE cursor_2

    

    

     

    DECLARE cursor_3 CURSOR FOR

      

    select  version_id   

       

      from apm_package_versions  

       WHERE package_key  = @drop_type__package_key  

       

       

    

    OPEN cursor_3

    

    FETCH NEXT FROM cursor_3 INTO @cur_val__version_id  

    

    WHILE (@@FETCH_STATUS = 0)

    BEGIN

    EXEC dbo.apm_package_version__delete @cur_val__version_id  

      

    

      FETCH NEXT FROM cursor_3 INTO @cur_val__version_id  

    END --while

    

    CLOSE cursor_3

    

    DEALLOCATE cursor_3

    

    

    

  END --IF

  

  

   delete from apm_package_types  WHERE package_key  = @drop_type__package_key 

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_package_type__num_parameters (varchar)

returns integer as '

declare

  num_parameters__package_key            alias for $1;  

  v_count                                integer;       

begin

    select count(*) into v_count

    from apm_parameters

    where package_key = num_parameters__package_key;



    return v_count;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION apm_package_type__num_parameters(@num_parameters__package_key		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @v_count	integer





  select   @v_count = count ( * )   

     

    from apm_parameters  

     WHERE package_key  = @num_parameters__package_key  

     

     

   RETURN CONVERT (integer, @v_count )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create function apm_parameter_value__new (integer,integer,integer,varchar)

returns integer as '

declare

  new__value_id               alias for $1;  

  new__package_id             alias for $2;  

  new__parameter_id           alias for $3;  

  new__attr_value             alias for $4;  

  v_value_id                  apm_parameter_values.value_id%TYPE;

begin

   v_value_id := acs_object__new(

     new__value_id,

     'apm_parameter_value',

     now(),

     null,

     null,

     null

   );

   insert into apm_parameter_values 

    (value_id, package_id, parameter_id, attr_value)

     values

    (v_value_id, new__package_id, new__parameter_id, new__attr_value);



   return v_value_id;

    

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_parameter_value__new

	@new__value_id		integer,

	@new__package_id		integer,

	@new__parameter_id		integer,

	@new__attr_value		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_value_id	int



EXEC dbo.acs_object__new @new__value_id ,

  	'apm_parameter_value' ,

  	getdate ,

  	null ,

  	null ,

  	null , @ms_return_value = @v_value_id OUTPUT

  

   

  insert into apm_parameter_values ( value_id, package_id, parameter_id, attr_value ) values ( @v_value_id  , @new__package_id  , @new__parameter_id  , @new__attr_value   )

   

  SET @ms_return_value = @v_value_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_parameter_value__delete (integer)

returns integer as '

declare

  delete__value_id               alias for $1;  

begin

    delete from apm_parameter_values 

    where value_id = delete__value_id;

    PERFORM acs_object__delete(delete__value_id);



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_parameter_value__delete

	@delete__value_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_parameter_values  WHERE value_id  = @delete__value_id 

   EXEC dbo.acs_object__delete @delete__value_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_application__new (integer,varchar,varchar,varchar,timestamp,integer,varchar,integer)

returns integer as '

declare

  application_id         alias for $1;  

  instance_name          alias for $2;  

  package_key            alias for $3;  

  object_type            alias for $4;  

  creation_date          alias for $5;  

  creation_user          alias for $6;  

  creation_ip            alias for $7;  

  context_id             alias for $8;  

  v_application_id       integer;       

begin

    v_application_id := apm_package__new (

      application_id,

      instance_name,

      package_key,

      object_type,

      creation_date,

      creation_user,

      creation_ip,

      context_id

    );



    return v_application_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_application__new

	@application_id		integer,

	@instance_name		varchar(8000),

	@package_key		varchar(8000),

	@object_type		varchar(8000),

	@creation_date		varchar(50),

	@creation_user		integer,

	@creation_ip		varchar(8000),

	@context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_application_id	integer



EXEC dbo.apm_package__new @application_id ,

  	@instance_name ,

  	@package_key ,

  	@object_type ,

  	@creation_date ,

  	@creation_user ,

  	@creation_ip ,

  	@context_id , @ms_return_value = @v_application_id OUTPUT

  

   

  SET @ms_return_value = @v_application_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_application__delete (integer)

returns integer as '

declare

  delete__application_id         alias for $1;  

begin

    delete from apm_applications

    where application_id = delete__application_id;

    PERFORM apm_package__delete(

        delete__application_id

    );



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_application__delete

	@delete__application_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_applications  WHERE application_id  = @delete__application_id 

   EXEC dbo.apm_package__delete @delete__application_id  

   RETURN 0

  

END -- stored proc


 
[PG]
create function apm_service__new (integer,varchar,varchar,varchar,timestamp,integer,varchar,integer)

returns integer as '

declare

  service_id             alias for $1;  

  instance_name          alias for $2;  

  package_key            alias for $3;  

  object_type            alias for $4;  

  creation_date          alias for $5;  

  creation_user          alias for $6;  

  creation_ip            alias for $7;  

  context_id             alias for $8;  

  v_service_id           integer;       

begin

    v_service_id := apm_package__new (

      service_id,

      instance_name,

      package_key,

      object_type,

      creation_date,

      creation_user,

      creation_ip,

      context_id

    );



    return v_service_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_service__new

	@service_id		integer,

	@instance_name		varchar(8000),

	@package_key		varchar(8000),

	@object_type		varchar(8000),

	@creation_date		varchar(50),

	@creation_user		integer,

	@creation_ip		varchar(8000),

	@context_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_service_id	integer



EXEC dbo.apm_package__new @service_id ,

  	@instance_name ,

  	@package_key ,

  	@object_type ,

  	@creation_date ,

  	@creation_user ,

  	@creation_ip ,

  	@context_id , @ms_return_value = @v_service_id OUTPUT

  

   

  SET @ms_return_value = @v_service_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
create function apm_service__delete (integer)

returns integer as '

declare

  delete__service_id    alias for $1;  

begin

    delete from apm_services

    where service_id = delete__service_id;

    PERFORM apm_package__delete(

	delete__service_id

    );



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC apm_service__delete

	@delete__service_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from apm_services  WHERE service_id  = @delete__service_id 

   EXEC dbo.apm_package__delete @delete__service_id  

   RETURN 0

  

END -- stored proc


 
[PG]
  
[MSSQL]
/* Skipped */

 
File packages/acs-kernel/sql/postgresql/acs-create.sql
[PG]
create table acs_magic_objects (

	name		varchar(100)

			constraint acs_magic_objects_pk primary key,

	object_id	integer not null constraint acs_magic_objects_object_id_fk

                        references acs_objects(object_id)

)
[MSSQL]
create table acs_magic_objects ( name		varchar(100)

			constraint acs_magic_objects_pk primary key,

	object_id	integer not null constraint acs_magic_objects_object_id_fk

                        references acs_objects(object_id)

)

GO


 
[PG]
create index acs_mo_object_id_idx on acs_magic_objects (object_id)
[MSSQL]
create index acs_mo_object_id_idx on acs_magic_objects (object_id)

 
[PG]
create function acs__add_user (integer,varchar,timestamp,integer,varchar,varchar,varchar,varchar,varchar,char,char,varchar,varchar,varchar,boolean,varchar)

returns integer as '

declare

  user_id                alias for $1;  

  object_type            alias for $2;  

  creation_date          alias for $3;  

  creation_user          alias for $4;  

  creation_ip            alias for $5;  

  email                  alias for $6;  

  url                    alias for $7;  

  first_names            alias for $8;  

  last_name              alias for $9;  

  password               alias for $10; 

  salt                   alias for $11; 

  password_question      alias for $12; 

  password_answer        alias for $13; 

  screen_name            alias for $14; 

  email_verified_p       alias for $15; 

  member_state           alias for $16; 

  v_user_id              users.user_id%TYPE;

  v_rel_id               membership_rels.rel_id%TYPE;

begin

    v_user_id := acs_user__new (user_id, object_type, creation_date,

				creation_user, creation_ip, email,

				url, first_names, last_name, password,

				salt, password_question, password_answer,

				screen_name, email_verified_p,null);

   

    v_rel_id := membership_rel__new (

      null,

      'membership_rel',

      acs__magic_object_id('registered_users'),      

      v_user_id,

      member_state,

      null,

      null);



    PERFORM acs_permission__grant_permission (

      v_user_id,

      v_user_id,

      'read'

      );



    PERFORM acs_permission__grant_permission (

      v_user_id,

      v_user_id,

      'write'

      );



    return v_user_id;

   

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs__add_user

	@user_id		integer,

	@object_type		varchar(8000),

	@creation_date		varchar(50),

	@creation_user		integer,

	@creation_ip		varchar(8000),

	@email		varchar(8000),

	@url		varchar(8000),

	@first_names		varchar(8000),

	@last_name		varchar(8000),

	@password		char,

	@salt		char,

	@password_question		varchar(8000),

	@password_answer		varchar(8000),

	@screen_name		varchar(8000),

	@email_verified_p		boolean,

	@member_state		varchar(8000), 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_rel_id	int

declare @v_user_id	int



EXEC dbo.acs_user__new @user_id ,

  	@object_type ,

  	@creation_date ,

  	@creation_user ,

  	@creation_ip ,

  	@email ,

  	@url ,

  	@first_names ,

  	@last_name ,

  	@password ,

  	@salt ,

  	@password_question ,

  	@password_answer ,

  	@screen_name ,

  	@email_verified_p ,

  	null , @ms_return_value = @v_user_id OUTPUT

  

   EXEC dbo.membership_rel__new null ,

  	'membership_rel' ,

  	dbo.acs__magic_object_id ( 'registered_users'  ) ,

  	@v_user_id ,

  	@member_state ,

  	null ,

  	null , @ms_return_value = @v_rel_id OUTPUT

  

   EXEC dbo.acs_permission__grant_permission @v_user_id ,

  	@v_user_id ,

  	'read'  

   EXEC dbo.acs_permission__grant_permission @v_user_id ,

  	@v_user_id ,

  	'write'  

   

  SET @ms_return_value = @v_user_id  

  RETURN @ms_return_value

  

  

END -- stored proc

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 44: Incorrect syntax near '.'.

 
[PG]
create function acs__remove_user (integer)

returns integer as '

declare

  remove_user__user_id                alias for $1;  

begin

    delete from users

    where user_id = remove_user__user_id;



    return 0; 

end;' language 'plpgsql'
[MSSQL]
CREATE PROC acs__remove_user

	@remove_user__user_id		integer, 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN



delete from users  WHERE user_id  = @remove_user__user_id 

   RETURN 0

  

END -- stored proc


 
[PG]
create function acs__magic_object_id (varchar)

returns integer as '

declare

  magic_object_id__name                   alias for $1;  

  magic_object_id__object_id              acs_objects.object_id%TYPE;

begin

    select object_id

    into magic_object_id__object_id

    from acs_magic_objects

    where name = magic_object_id__name;



    return magic_object_id__object_id;

   

end;' language 'plpgsql'
[MSSQL]
  CREATE FUNCTION acs__magic_object_id(@magic_object_id__name		varchar(8000)) 

RETURNS integer

AS

BEGIN

declare @magic_object_id__object_id	int





  select   @magic_object_id__object_id = object_id   

     

    from acs_magic_objects  

     WHERE name  = @magic_object_id__name  

     

     

   RETURN CONVERT (integer, @magic_object_id__object_id )

  



RETURN NULL -- placeholder required by tsql

END -- function


 
[PG]
create view registered_users

as

  select p.email, p.url, pe.first_names, pe.last_name, u.*, mr.member_state

  from parties p, persons pe, users u, group_member_map m, membership_rels mr

  where party_id = person_id

  and person_id = user_id

  and u.user_id = m.member_id

  and m.rel_id = mr.rel_id

  and m.group_id = acs__magic_object_id('registered_users')

  and mr.member_state = 'approved'

  and u.email_verified_p = 't'
[MSSQL]
create view registered_users as 

select  p.email  , p.url  , pe.first_names  , pe.last_name  , u.*  , mr.member_state   

   

  from parties p,

	persons pe,

	users u,

	group_member_map m,

	membership_rels mr 

   WHERE party_id  = person_id  and person_id  = user_id  and u.user_id  = m.member_id  and m.rel_id  = mr.rel_id  and m.group_id  = dbo.acs__magic_object_id ( 'registered_users'  )  and mr.member_state  = 'approved'  and u.email_verified_p  = 't'  

   

   

 
[PG]
create view cc_users

as

select o.*, pa.*, pe.*, u.*, mr.member_state, mr.rel_id

from acs_objects o, parties pa, persons pe, users u, group_member_map m, membership_rels mr

where o.object_id = pa.party_id

and pa.party_id = pe.person_id

and pe.person_id = u.user_id

and u.user_id = m.member_id

and m.group_id = acs__magic_object_id('registered_users')

and m.rel_id = mr.rel_id

and m.container_id = m.group_id
[MSSQL]
create view cc_users as 

select  o.*  , pa.*  , pe.*  , u.*  , mr.member_state  , mr.rel_id   

   

  from acs_objects o,

	parties pa,

	persons pe,

	users u,

	group_member_map m,

	membership_rels mr 

   WHERE o.object_id  = pa.party_id  and pa.party_id  = pe.person_id  and pe.person_id  = u.user_id  and u.user_id  = m.member_id  and m.group_id  = dbo.acs__magic_object_id ( 'registered_users'  )  and m.rel_id  = mr.rel_id  and m.container_id  = m.group_id  

   

   

 
[PG]
create function inline_0 ()

returns integer as '

declare

  root_id integer;

begin

  

  root_id := acs_object__new (

    0,

    'acs_object',

    now(),

    null,

    null,

    null

    );



  insert into acs_magic_objects

   (name, object_id)

  values

   ('security_context_root', 0);





  return root_id;



end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_0

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @root_id	integer



EXEC dbo.acs_object__new 0 ,

  	'acs_object' ,

  	getdate ,

  	null ,

  	null ,

  	null , @ms_return_value = @root_id OUTPUT

  

   

  insert into acs_magic_objects ( name, object_id ) values ( 'security_context_root'  , 0   )

   

  SET @ms_return_value = @root_id  

  RETURN @ms_return_value

  

  

END -- stored proc


 
[PG]
select inline_0 ()
[MSSQL]
 dbo.inline_0 
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting datetime from character string.

 
[PG]
drop function inline_0 ()
[MSSQL]
drop proc inline_0

 
[PG]
begin
[MSSQL]
/* Skipped */

 
[PG]
select acs_privilege__create_privilege('read', null, null)
[MSSQL]
 dbo.acs_privilege__create_privilege 'read' ,

	null ,

	null 

 
[PG]
select acs_privilege__create_privilege('write', null, null)
[MSSQL]
 dbo.acs_privilege__create_privilege 'write' ,

	null ,

	null 

 
[PG]
select acs_privilege__create_privilege('create', null, null)
[MSSQL]
 dbo.acs_privilege__create_privilege 'create' ,

	null ,

	null 

 
[PG]
select acs_privilege__create_privilege('delete', null, null)
[MSSQL]
 dbo.acs_privilege__create_privilege 'delete' ,

	null ,

	null 

 
[PG]
select acs_privilege__create_privilege('admin', null, null)
[MSSQL]
 dbo.acs_privilege__create_privilege 'admin' ,

	null ,

	null 

 
[PG]
drop trigger acs_priv_hier_ins_del_tr on acs_privilege_hierarchy
[MSSQL]
drop trigger acs_priv_hier_ins_del_tr
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot drop the trigger 'acs_priv_hier_ins_del_tr', because it does not exist in the system catalog.

 
[PG]
select acs_privilege__add_child('admin', 'read')
[MSSQL]
 dbo.acs_privilege__add_child 'admin' ,

	'read' 

 
[PG]
select acs_privilege__add_child('admin', 'write')
[MSSQL]
 dbo.acs_privilege__add_child 'admin' ,

	'write' 

 
[PG]
select acs_privilege__add_child('admin', 'create')
[MSSQL]
 dbo.acs_privilege__add_child 'admin' ,

	'create' 

 
[PG]
create trigger acs_priv_hier_ins_del_tr after insert or delete

 on acs_privilege_hierarchy for each row

 execute procedure acs_priv_hier_ins_del_tr ()
[MSSQL]
/* Skipped */

 
[PG]
select acs_privilege__add_child('admin', 'delete')
[MSSQL]
 dbo.acs_privilege__add_child 'admin' ,

	'delete' 

 
[PG]
end
[MSSQL]
/* Skipped */

 
[PG]
create function inline_2 ()

returns integer as '

declare

  v_object_id integer;

begin



 insert into acs_objects

  (object_id, object_type)

 values

  (-1, 'party');



 insert into parties

  (party_id)

 values

  (-1);



 insert into acs_magic_objects

  (name, object_id)

 values

  ('the_public', -1);



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_2

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @v_object_id	integer





  insert into acs_objects ( object_id, object_type ) values ( -1  , 'party'   )

   

  insert into parties ( party_id ) values ( -1   )

   

  insert into acs_magic_objects ( name, object_id ) values ( 'the_public'  , -1   )

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_2 ()
[MSSQL]
 dbo.inline_2 

 
[PG]
drop function inline_2 ()
[MSSQL]
drop proc inline_2

 
[PG]
create function inline_3 ()

returns integer as '

declare

  group_id integer;

begin



  group_id := acs_group__new (

    -2,

    'group',

    now(),

    null,

    null,

    null,

    null,

    'Registered Users',

    null,

    null

  );



 insert into acs_magic_objects

  (name, object_id)

 values

  ('registered_users', -2);



  return 0;

end;' language 'plpgsql'
[MSSQL]
CREATE PROC inline_3

	 

	@ms_return_value	integer = 0 OUTPUT 

AS

BEGIN

declare @group_id	integer



EXEC dbo.acs_group__new -2 ,

  	'group' ,

  	getdate ,

  	null ,

  	null ,

  	null ,

  	null ,

  	'Registered Users' ,

  	null ,

  	null , @ms_return_value = @group_id OUTPUT

  

   

  insert into acs_magic_objects ( name, object_id ) values ( 'registered_users'  , -2   )

   RETURN 0

  

END -- stored proc


 
[PG]
select inline_3 ()
[MSSQL]
 dbo.inline_3 
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not find stored procedure 'dbo.party__new'.

 
[PG]
drop function inline_3 ()
[MSSQL]
drop proc inline_3

 
[PG]
select acs_object__new (

    -3,

    'acs_object',

    now(),

    null,

    null,

    null

  )
[MSSQL]
 dbo.acs_object__new -3 ,

	'acs_object' ,

	getdate() ,

	null ,

	null ,

	null 
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 3: Incorrect syntax near ')'.

 
[PG]
insert into acs_magic_objects

  (name, object_id)

 values

  ('default_context', -3)
[MSSQL]
insert into acs_magic_objects ( name, object_id ) values ( 'default_context'  , -3   )
[Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'acs_magic_objects_object_id_fk'. The conflict occurred in database 'openacs', table 'acs_objects', column 'object_id'.

 
[PG]
  
[MSSQL]
/* Skipped */
[Microsoft][ODBC SQL Server Driver][SQL Server]INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'acs_magic_objects_object_id_fk'. The conflict occurred in database 'openacs', table 'acs_objects', column 'object_id'.