Index: openacs-4/packages/acs-kernel/sql/oracle/utilities-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/utilities-create.sql,v
diff -u -r1.3 -r1.3.2.1
--- openacs-4/packages/acs-kernel/sql/oracle/utilities-create.sql	27 Oct 2014 16:39:35 -0000	1.3
+++ openacs-4/packages/acs-kernel/sql/oracle/utilities-create.sql	20 Dec 2016 20:28:49 -0000	1.3.2.1
@@ -35,6 +35,35 @@
     function index_exists (
 	name in varchar2)
 	return boolean;
+
+    function foreign_key_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	reftable  IN varchar2,
+	refcolumn IN varchar2)
+    return boolean;
+
+    function unique_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	single_p  IN boolean default true)
+    return boolean;
+
+    function primary_key_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	single_p  IN boolean default true)
+    return boolean;
+
+    function not_null_exists (
+        table     IN varchar2,
+	column    IN varchar2)
+    return boolean;
+
+    function get_default (
+        table     IN varchar2,
+	column    IN varchar2)
+    return LONG;
 end util;
 /
 show errors
@@ -111,6 +140,93 @@
       return exists (select 1 from user_indexes where index_name = name);
     END index_exists;
 
+    function foreign_key_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	reftable  IN varchar2,
+	refcolumn IN varchar2)
+    return boolean
+    as
+    begin
+      return exists (
+      SELECT 1 FROM USER_CONSTRAINTS CONS
+      LEFT JOIN USER_CONS_COLUMNS COLS ON COLS.CONSTRAINT_NAME = CONS.CONSTRAINT_NAME
+      LEFT JOIN USER_CONSTRAINTS CONS_R ON CONS_R.CONSTRAINT_NAME = CONS.R_CONSTRAINT_NAME
+      LEFT JOIN USER_CONS_COLUMNS COLS_R ON COLS_R.CONSTRAINT_NAME = CONS.R_CONSTRAINT_NAME
+      WHERE CONS.CONSTRAINT_TYPE = 'R'
+        AND CONS.TABLE_NAME = table
+	AND COLS.COLUMN_NAME = column
+  	AND CONS_R.TABLE_NAME = reftable
+  	AND COLS_R.COLUMN_NAME = refcolumn);
+    END foreign_key_exists;
+
+    function unique_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	single_p  IN boolean default true)
+    return boolean
+    as
+    begin
+      return exists (
+      SELECT 1
+       FROM all_constraints c
+       JOIN all_cons_columns cc ON (c.owner = cc.owner
+	                                 AND c.constraint_name = cc.constraint_name)
+       WHERE c.constraint_type = 'U'
+	 AND c.table_name = table
+	 AND cc.column_name = column
+	 and (not single_p or (
+	    select count(*) from all_cons_columns
+	     where constraint_name = c.constraint_name) = 1));
+    END unique_exists;
+
+    function primary_key_exists (
+        table     IN varchar2,
+	column    IN varchar2,
+	single_p  IN boolean default true)
+    return boolean
+    as
+    begin
+      return exists (
+      SELECT 1
+       FROM all_constraints c
+       JOIN all_cons_columns cc ON (c.owner = cc.owner
+	                                 AND c.constraint_name = cc.constraint_name)
+       WHERE c.constraint_type = 'P'
+	 AND c.table_name = table
+	 AND cc.column_name = column
+	 and (not single_p or (
+	    select count(*) from all_cons_columns
+	     where constraint_name = c.constraint_name
+	       and owner = c.owner) = 1));
+    END primary_key_exists;
+
+    function not_null_exists (
+        table     IN varchar2,
+	column    IN varchar2)
+    return boolean
+    as
+    begin
+      return (
+      SELECT nullable = 'N'
+        FROM ALL_TAB_COLUMNS
+	 WHERE table_name = table
+	   AND column_name = column);
+    END not_null_exists;
+
+    function get_default (
+        table     IN varchar2,
+	column    IN varchar2)
+    return LONG
+    as
+    begin
+      return (
+      SELECT DATA_DEFAULT
+        FROM ALL_TAB_COLUMNS
+	 WHERE table_name = table
+	   AND column_name = column);
+    END get_default;    
+
 end util;
 /
 show errors
