Index: openacs-4/contrib/obsolete-packages/acs-util/acs-util.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/acs-util.info,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/obsolete-packages/acs-util/acs-util.info 5 Apr 2001 18:23:38 -0000 1.2
+++ openacs-4/contrib/obsolete-packages/acs-util/acs-util.info 29 Apr 2001 20:08:31 -0000 1.3
@@ -24,6 +24,11 @@
+
+
+
+
+
Index: openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-create.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-create.sql 29 Apr 2001 20:08:31 -0000 1.1
@@ -0,0 +1,3 @@
+
+\i acs-util-package.sql
+\i string-package.sql
Index: openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-drop.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-drop.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-drop.sql 29 Apr 2001 20:08:31 -0000 1.1
@@ -0,0 +1 @@
+select drop_package('acs_util');
Index: openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-package.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-package.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/acs-util-package.sql 29 Apr 2001 20:08:31 -0000 1.1
@@ -0,0 +1,71 @@
+---------------------------------------------------------------------
+-- A set of utilities dealing with various aspects of the repository
+---------------------------------------------------------------------
+
+-- Determine if an item in some sort of hierarchy has children
+create function acs_util__has_children(varchar,varchar,varchar)
+returns boolean as '
+declare
+ item_id_in alias for $1;
+ table_name_in alias for $2;
+ parent_column_in alias for $3;
+ v_row_count integer;
+begin
+ execute ''select 1 where exists (select 1 from ''
+ || quote_ident(table_name_in)
+ || '' where ''
+ || quote_ident(parent_column_in)
+ || '' = ''
+ || quote_literal(item_id_in)
+ || '')'';
+ get diagnostics v_row_count = ROW_COUNT;
+ if v_row_count = 1 then
+ return ''t'';
+ else
+ return ''f'';
+ end if;
+end;' language 'plpgsql';
+
+
+-- Perform a SQL query which will return some values
+-- or NULL. Return 't' if a value was returned, 'f' otherwise
+create function acs_util__boolean_query(varchar,boolean)
+returns boolean as '
+declare
+ query_in alias for $1;
+ not_flag_in alias for $2;
+ v_sql_query varchar;
+ v_row_count integer;
+begin
+ v_sql_query := ''select 1 where '';
+
+ if not_flag_in then
+ v_sql_query := v_sql_query || ''not '';
+ end if;
+
+ execute v_sql_query || ''exists ('' || query_in || '')'';
+
+ get diagnostics v_row_count = ROW_COUNT;
+
+ if v_row_count = 1 then
+ return ''t'';
+ else
+ return ''f'';
+ end if;
+
+end;' language 'plpgsql';
+
+
+-- Convert a SQL string to a TCL string: surround the string with
+-- {} if it contains spaces
+create function acs_util__sql_to_tcl_string(varchar)
+returns varchar as '
+declare
+ string_in alias for $1;
+begin
+ if instr(string_in, '' '') <> 0 then
+ return ''{'' || string_in || ''}'';
+ else
+ return string_in;
+ end if;
+end;' language 'plpgsql';
Index: openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/string-package.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/string-package.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/string-package.sql 29 Apr 2001 20:08:31 -0000 1.1
@@ -0,0 +1,116 @@
+--------------------------------------------------------
+-- Some generic functions and types to work with strings
+--------------------------------------------------------
+
+-- create or replace package str
+-- is
+
+-- -- A record for tokenizing strings
+-- type token_info is record (
+-- string varchar2(4000), -- The string we will be tokenizing
+-- length integer, -- The length of the string
+-- token_start integer, -- Start of last token
+-- separators varchar2(4000) -- Characters which can separate tokens
+-- );
+
+-- -- Return the first token in a string, or null if there are
+-- -- no more tokens
+-- function first_token (
+-- string_in IN varchar2,
+-- token_rec_in IN OUT NOCOPY token_info,
+-- separators_in IN varchar2 := ' '
+-- ) return varchar2;
+
+-- -- Get the next token in the string, or null if there are
+-- -- no more tokens
+-- function next_token (
+-- token_rec_in IN OUT NOCOPY token_info
+-- ) return varchar2;
+
+-- -- Determine if a string has more tokens to be returned
+-- function has_more_tokens (
+-- token_rec_in IN OUT NOCOPY token_info
+-- ) return char;
+
+-- end str;
+-- /
+-- show errors
+
+-- create or replace package body str
+-- is
+
+-- function first_token (
+-- string_in IN varchar2,
+-- token_rec_in IN OUT NOCOPY token_info,
+-- separators_IN IN varchar2 := ' '
+-- ) return varchar2
+-- is
+-- begin
+
+-- token_rec_in.string := string_in;
+-- token_rec_in.length := length(string_in);
+-- token_rec_in.token_start := 1;
+-- token_rec_in.separators := separators_in;
+
+-- return next_token(token_rec_in);
+-- end first_token;
+
+
+-- function next_token (
+-- token_rec_in IN OUT NOCOPY token_info
+-- ) return varchar2
+-- is
+-- v_token_start integer;
+-- begin
+
+-- -- Check for string end
+-- if token_rec_in.token_start > token_rec_in.length then
+-- return null;
+-- end if;
+
+-- -- Skip separators
+-- while instr(token_rec_in.separators,
+-- substr(token_rec_in.string,
+-- token_rec_in.token_start, 1)) <> 0
+-- loop
+
+-- token_rec_in.token_start := token_rec_in.token_start + 1;
+-- if token_rec_in.token_start > token_rec_in.length then
+-- return null;
+-- end if;
+
+-- end loop;
+
+-- v_token_start := token_rec_in.token_start;
+
+-- -- Skip until the next separator
+-- while instr(token_rec_in.separators,
+-- substr(token_rec_in.string,
+-- token_rec_in.token_start, 1)) = 0
+-- loop
+-- token_rec_in.token_start := token_rec_in.token_start + 1;
+-- if token_rec_in.token_start > token_rec_in.length then
+-- return substr(token_rec_in.string, v_token_start);
+-- end if;
+-- end loop;
+
+-- return substr(token_rec_in.string, v_token_start,
+-- token_rec_in.token_start - v_token_start);
+
+-- end next_token;
+
+-- function has_more_tokens (
+-- token_rec_in IN OUT NOCOPY token_info
+-- ) return char
+-- is
+-- begin
+-- if token_rec_in.token_start > token_rec_in.length then
+-- return 'f';
+-- else
+-- return 't';
+-- end if;
+-- end has_more_tokens;
+
+-- end str;
+-- /
+-- show errors
Index: openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/test/acs-util-test.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/test/acs-util-test.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/obsolete-packages/acs-util/sql/postgresql/test/acs-util-test.sql 29 Apr 2001 20:08:31 -0000 1.1
@@ -0,0 +1,36 @@
+create function run()
+returns integer as'
+declare
+ v_bool boolean;
+begin
+ if not acs_util__has_children(''acs_object'', ''acs_object_types'', ''supertype'') then
+ raise notice ''Type "acs_object" should have children'';
+ end if;
+
+ if acs_util__has_children(''made_up_type'', ''acs_object_types'', ''supertype'') then
+ raise notice ''Type "made_up_type" should not have children'';
+ end if;
+
+ if not acs_util__boolean_query(''select * from acs_objects'', ''f'') then
+ raise notice ''Query 1 should be true'';
+ end if;
+
+ if acs_util__boolean_query(''select * from acs_objects'', ''t'') then
+ raise notice ''Query 2 should be false'';
+ end if;
+
+ if acs_util__boolean_query(''select * from acs_objects where 1=2'', ''f'') then
+ raise notice ''Query 3 should be false'';
+ end if;
+
+ if not acs_util__boolean_query(''select * from acs_objects where 1=2'', ''t'') then
+ raise notice ''Query 4 should be true'';
+ end if;
+
+ return null;
+end;' language 'plpgsql';
+
+select run();
+select acs_util__sql_to_tcl_string('This_string_should_not_have_braces');
+select acs_util__sql_to_tcl_string('This string should have braces');
+drop function run();