Index: openacs-4/packages/acs-kernel/acs-kernel.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/acs-kernel.info,v diff -u -r1.149 -r1.150 --- openacs-4/packages/acs-kernel/acs-kernel.info 28 Nov 2018 09:01:45 -0000 1.149 +++ openacs-4/packages/acs-kernel/acs-kernel.info 28 Jan 2019 21:44:12 -0000 1.150 @@ -9,15 +9,15 @@ f t - + OpenACS Core Team Routines and data models providing the foundation for OpenACS-based Web services. 2017-08-06 OpenACS The OpenACS kernel contains the core datamodel create and drop scripts for such things as objects, groups, partiies and the supporting PL/SQL and PL/pgSQL procedures. 3 - + Index: openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql,v diff -u -r1.11 -r1.12 --- openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql 5 Oct 2017 09:35:57 -0000 1.11 +++ openacs-4/packages/acs-kernel/sql/postgresql/utilities-create.sql 28 Jan 2019 21:44:12 -0000 1.12 @@ -94,8 +94,8 @@ BEGIN return exists ( select 1 from information_schema.columns c - where c.table_name = t_name - and c.column_name = c_name); + where c.table_name = lower(t_name) + and c.column_name = lower(c_name)); END; $$ LANGUAGE plpgsql; @@ -164,10 +164,10 @@ and ccu.table_catalog = kcu.table_catalog and ccu.table_schema = kcu.table_schema and tc.constraint_type = 'FOREIGN KEY' - and tc.table_name = p_table - and kcu.column_name = p_column - and ccu.table_name = p_reftable - and ccu.column_name = p_refcolumn); + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) + and ccu.table_name = lower(p_reftable) + and ccu.column_name = lower(p_refcolumn)); END; $$ LANGUAGE plpgsql; @@ -194,8 +194,8 @@ and tc.table_catalog = kcu.table_catalog and tc.table_schema = kcu.table_schema and tc.constraint_type = 'UNIQUE' - and tc.table_name = p_table - and kcu.column_name = p_column + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) and (not p_single_p or ( -- this to ensure the constraint involves only one -- column @@ -229,8 +229,8 @@ and tc.table_catalog = kcu.table_catalog and tc.table_schema = kcu.table_schema and tc.constraint_type = 'PRIMARY KEY' - and tc.table_name = p_table - and kcu.column_name = p_column + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) and (not p_single_p or ( -- this to ensure the constraint involves only one -- column @@ -258,8 +258,8 @@ coalesce(( select is_nullable = 'NO' from information_schema.columns - where table_name = p_table - and column_name = p_column), false)); + where table_name = lower(p_table) + and column_name = lower(p_column)), false)); END; $$ LANGUAGE plpgsql; @@ -278,8 +278,8 @@ return ( select column_default from information_schema.columns - where table_name = p_table - and column_name = p_column); + where table_name = lower(p_table) + and column_name = lower(p_column)); END; $$ LANGUAGE plpgsql; Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d10-5.10.0d11.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d10-5.10.0d11.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d10-5.10.0d11.sql 28 Jan 2019 21:44:12 -0000 1.1 @@ -0,0 +1,157 @@ +-- +-- Make sure, that table_name and column_name work +-- case-insensitive (similar to function_args) +-- + +-- +-- procedure util__table_column_exists/1 +-- +CREATE OR REPLACE FUNCTION util__table_column_exists( + c_name text + t_name text, +) RETURNS boolean AS $$ +DECLARE +BEGIN + return exists ( + select 1 from information_schema.columns c + where c.table_name = lower(t_name) + and c.column_name = lower(c_name)); +END; +$$ LANGUAGE plpgsql; + + +-- +-- procedure util__foreign_key_exists/4 +-- +CREATE OR REPLACE FUNCTION util__foreign_key_exists( + p_table text, + p_column text, + p_reftable text, + p_refcolumn text +) RETURNS boolean AS $$ +DECLARE +BEGIN + return exists ( + select 1 from + information_schema.table_constraints AS tc, + information_schema.key_column_usage AS kcu, + information_schema.constraint_column_usage AS ccu + where tc.constraint_name = kcu.constraint_name + and tc.constraint_catalog = kcu.constraint_catalog + and tc.constraint_schema = kcu.constraint_schema + and tc.table_catalog = kcu.table_catalog + and tc.table_schema = kcu.table_schema + and ccu.constraint_name = tc.constraint_name + and ccu.constraint_catalog = kcu.constraint_catalog + and ccu.constraint_schema = kcu.constraint_schema + and ccu.table_catalog = kcu.table_catalog + and ccu.table_schema = kcu.table_schema + and tc.constraint_type = 'FOREIGN KEY' + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) + and ccu.table_name = lower(p_reftable) + and ccu.column_name = lower(p_refcolumn)); +END; +$$ LANGUAGE plpgsql; + +-- +-- procedure util__unique_exists/3 +-- +CREATE OR REPLACE FUNCTION util__unique_exists( + p_table text, + p_column text, + p_single_p boolean default true +) RETURNS boolean AS $$ +DECLARE +BEGIN + return exists (select 1 + from + information_schema.table_constraints AS tc, + information_schema.key_column_usage AS kcu + where tc.constraint_name = kcu.constraint_name + and tc.constraint_catalog = kcu.constraint_catalog + and tc.constraint_schema = kcu.constraint_schema + and tc.table_catalog = kcu.table_catalog + and tc.table_schema = kcu.table_schema + and tc.constraint_type = 'UNIQUE' + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) + and (not p_single_p or ( + -- this to ensure the constraint involves only one + -- column + select count(*) from information_schema.key_column_usage + where constraint_name = kcu.constraint_name + and constraint_catalog = kcu.constraint_catalog + and constraint_schema = kcu.constraint_schema) = 1)); +END; +$$ LANGUAGE plpgsql; + +-- +-- procedure util__unique_exists/3 +-- +CREATE OR REPLACE FUNCTION util__primary_key_exists( + p_table text, + p_column text, + p_single_p boolean default true +) RETURNS boolean AS $$ +DECLARE +BEGIN + return exists (select 1 + from + information_schema.table_constraints AS tc, + information_schema.key_column_usage AS kcu + where tc.constraint_name = kcu.constraint_name + and tc.constraint_catalog = kcu.constraint_catalog + and tc.constraint_schema = kcu.constraint_schema + and tc.table_catalog = kcu.table_catalog + and tc.table_schema = kcu.table_schema + and tc.constraint_type = 'PRIMARY KEY' + and tc.table_name = lower(p_table) + and kcu.column_name = lower(p_column) + and (not p_single_p or ( + -- this to ensure the constraint involves only one + -- column + select count(*) from information_schema.key_column_usage + where constraint_name = kcu.constraint_name + and constraint_catalog = kcu.constraint_catalog + and constraint_schema = kcu.constraint_schema) = 1)); +END; +$$ LANGUAGE plpgsql; + + +-- +-- procedure util__not_null_exists/2 +-- +CREATE OR REPLACE FUNCTION util__not_null_exists( + p_table text, + p_column text +) RETURNS boolean AS $$ +DECLARE +BEGIN + return ( + coalesce(( + select is_nullable = 'NO' + from information_schema.columns + where table_name = lower(p_table) + and column_name = lower(p_column)), false)); +END; +$$ LANGUAGE plpgsql; + + +-- +-- procedure util__get_default/2 +-- +CREATE OR REPLACE FUNCTION util__get_default( + p_table text, + p_column text +) RETURNS information_schema.columns.column_default%TYPE AS $$ +DECLARE +BEGIN + return ( + select column_default + from information_schema.columns + where table_name = lower(p_table) + and column_name = lower(p_column)); +END; +$$ LANGUAGE plpgsql; +