OSDN Git Service

20170730 master
authorkuboryu <kuboryu@yahoo.co.jp>
Sun, 30 Jul 2017 10:55:50 +0000 (19:55 +0900)
committerkuboryu <kuboryu@yahoo.co.jp>
Sun, 30 Jul 2017 10:55:50 +0000 (19:55 +0900)
com/rapide_act/CmnAccessObjects.java
com/rapide_act/CmnProps.java
com/rapide_act/RapideMetaUnloader.java

index fdbda14..4c505f6 100644 (file)
@@ -407,7 +407,7 @@ public class CmnAccessObjects{
                colBoolean = null;
                ByteArrayOutputStream baos = null;
                InputStream is = null;
-
+               CmnUtils.deepPrint("colType=" + _colTypeName);
                if (CmnUtils.isColString(_colTypeName)) {
                        colString = _rst.getString(_rec_cnt);
                        if (colString != null) {
index 4936a8a..02ed65b 100644 (file)
@@ -73,7 +73,7 @@ public class CmnProps{
                ":r ", 
                "source ", 
                "", 
-               "", 
+               "\\i ", 
                ""
        };
        protected static final String [] SQL_COMMENT_MARK = {
@@ -675,9 +675,9 @@ public class CmnProps{
                     + " a.table_name,"
                     + " replace(replace(a.table_comment, char(13), ''), char(10), '') as table_comments, "
                     + " b.column_name,"
-                    + " replace(replace(b.column_comment, char(13), ''), char(10), '') as column_comment, "
-                    + " b.column_type,"
-                    + " b.character_maximum_length as data_precision,"
+                    + " replace(replace(b.column_comment, char(13), ''), char(10), '') as column_comments, "
+                    + " b.column_type as data_type,"
+                    + " b.character_maximum_length as data_length,"
                     + " b.numeric_precision as data_precision,"
                     + " b.numeric_scale as data_scale,"
                     + " case b.is_nullable"
@@ -794,7 +794,7 @@ public class CmnProps{
                     + " replace(replace(a.remarks, chr(13), ''), chr(10), '') as table_comments, "
                     + " b.colname,"
                     + " replace(replace(b.remarks, chr(13), ''), chr(10), '') as column_comments, "
-                    + " b.typename,"
+                    + " b.typename as data_type,"
                     + " b.length as data_length, "
                     + " b.length as data_precision, "
                     + " b.scale as data_scale, "
@@ -911,6 +911,174 @@ public class CmnProps{
                     + "   and b.colseq = c.colseq"
                     + " order by"
                     + "   a.tabname,a.constname,b.colseq,c.colseq"
+               },
+               {       //PostgreSQL
+               "select "
+                    + "  a.table_name,"
+                    + "  e.description as table_comments,"
+                    + "  b.column_name,"
+                    + "  f.description as column_comments,"
+                    + "  data_type,"
+                    + "  b.character_maximum_length as data_length,"
+                    + "  b.numeric_precision as data_precision,"
+                    + "  b.numeric_scale as data_scale,"
+                    + "  case b.is_nullable"
+                    + "   when 'NO' then '\81Z'"
+                    + "   else null "
+                    + "  end as nullable,"
+                    + "  b.column_default as data_default "
+                    + " from "
+                    + "  information_schema.tables a,"
+                    + "  information_schema.columns b,"
+                    + "  pg_stat_user_tables c"
+                    + "  left outer join pg_description e"
+                    + "  on c.relid=e.objoid and e.objsubid=0,"
+                    + "  pg_attribute d"
+                    + "  left outer join pg_description f"
+                    + "  on f.objoid=d.attrelid and f.objsubid=d.attnum"
+                    + " where "
+                    + "  a.table_schema = current_schema()"
+                    + "  and a.table_type = 'BASE TABLE'"
+                    + "  and a.table_schema = b.table_schema "
+                    + "  and a.table_name = b.table_name "
+                    + "  and a.table_schema = c.schemaname "
+                    + "  and a.table_name = c.relname"
+                    + "  and c.relid = d.attrelid"
+                    + "  and b.column_name = d.attname"
+                    + " order by a.table_name,b.ordinal_position",
+               "select "
+                    + "  a.table_name, "
+                    + "  b.constraint_name as index_name,"
+                    + "  ''::text as index_type, "
+                    + "  case b.constraint_type "
+                    + "    when 'PRIMARY KEY' then 'P' "
+                    + "    when 'UNIQUE' then 'U' "
+                    + "  end as constraint_type,"
+                    + "  c.column_name,"
+                    + "  c.ordinal_position as column_position"
+                    + "  from"
+                    + "   information_schema.tables a,"
+                    + "   information_schema.table_constraints b,"
+                    + "   information_schema.key_column_usage c"
+                    + "  where"
+                    + "   a.table_schema = current_schema()"
+                    + "   and a.table_type = 'BASE TABLE'"
+                    + "   and a.table_schema = b.table_schema"
+                    + "   and a.table_name = b.table_name"
+                    + "   and b.table_schema = c.table_schema"
+                    + "   and b.table_name = c.table_name"
+                    + "   and b.constraint_name = c.constraint_name"
+                    + "   and b.constraint_type in('PRIMARY KEY','UNIQUE')"
+                    + "  union select"
+                    + "    e.tablename::text as table_name,"
+                    + "    e.indexname::text as index_name,"
+                    + "    ''::text as index_type,"
+                    + "    ''::text as constraint_type,"
+                    + "    f.column_name,"
+                    + "    e.column_position"
+                    + "   from"
+                    + "   ("
+                    + "        select"
+                    + "         d.schemaname,"
+                    + "         d.tablename,"
+                    + "         d.indexname,"
+                    + "         d.indkey,"
+                    + "         row_number() over() as column_position"
+                    + "        from"
+                    + "        ("
+                    + "        select"
+                    + "         a.schemaname,"
+                    + "         a.tablename,"
+                    + "         a.indexname,"
+                    + "         unnest(string_to_array(c.indkey::text, ' '))::int indkey"
+                    + "        from"
+                    + "         pg_indexes a,"
+                    + "         pg_stat_user_indexes b,"
+                    + "         pg_index c"
+                    + "        where"
+                    + "         a.schemaname = current_schema()"
+                    + "         and a.schemaname = b.schemaname"
+                    + "         and a.tablename = b.relname"
+                    + "         and a.indexname = b.indexrelname"
+                    + "         and b.relid = c.indrelid"
+                    + "         and b.indexrelid  = c.indexrelid"
+                    + "         and c.indisunique = false"
+                    + "         and c.indisprimary = false"
+                    + "        ) d"
+                    + "   ) e,"
+                    + "   information_schema.columns f"
+                    + "   where "
+                    + "   e.schemaname = current_schema()"
+                    + "   and e.schemaname = f.table_schema"
+                    + "   and e.tablename = f.table_name"
+                    + "   and e.indkey = f.ordinal_position"
+                    + "   order by table_name,index_name,column_position",
+               "select "
+                    + " a.table_name as view_name, "
+                    + " ''::text as comments "
+                    + "from "
+                    + " information_schema.views a "
+                    + " where"
+                    + " table_schema = current_schema()"
+                    + " order by "
+                    + " a.table_name",
+               "select "
+                    + " routine_name as object_name, "
+                    + " routine_type as object_type, "
+                    + " '' as action_timing, "
+                    + " '' as event_action, "
+                    + " '' as event_object "
+                    + " from "
+                    + " information_schema.routines "
+                    + " where"
+                    + " routine_schema = current_schema()"
+                    + " and (routine_type = 'PROCEDURE' or routine_type = 'FUNCTION') "
+                    + " union select "
+                    + " trigger_name as object_name, "
+                    + " 'TRIGGER' as object_type, "
+                    + " action_timing as action_timing, "
+                    + " event_manipulation as event_action, "
+                    + " event_object_table as event_object "
+                    + " from "
+                    + " information_schema.triggers "
+                    + " where"
+                    + " trigger_schema = current_schema()"
+                    + " order by object_name,object_type ",
+               "",
+               "",
+               "",
+               "select "
+                    + "  a.table_name,"
+                    + "  a.constraint_name,"
+                    + "  c.column_name,"
+                    + "  d.table_name as r_table_name,"
+                    + "  e.column_name as r_column_name,"
+                    + "  f.ordinal_position as position,"
+                    + "  g.ordinal_position  as r_position"
+                    + "  from"
+                    + "  information_schema.table_constraints a,"
+                    + "  information_schema.referential_constraints b,"
+                    + "  information_schema.constraint_column_usage c,"
+                    + "  information_schema.table_constraints d,"
+                    + "  information_schema.constraint_column_usage e,"
+                    + "  information_schema.columns f,"
+                    + "  information_schema.columns g"
+                    + "  where "
+                    + "  a.constraint_schema = current_schema()"
+                    + "  and a.constraint_schema = b.constraint_schema"
+                    + "  and a.constraint_schema = c.constraint_schema"
+                    + "  and a.constraint_name = b.constraint_name"
+                    + "  and a.constraint_name = c.constraint_name"
+                    + "  and a.constraint_type = 'FOREIGN KEY'"
+                    + "  and b.constraint_schema = d.constraint_schema"
+                    + "  and b.unique_constraint_name = d.constraint_name"
+                    + "  and d.constraint_schema = e.constraint_schema"
+                    + "  and d.constraint_name = e.constraint_name"
+                    + "  and a.table_schema = f.table_schema"
+                    + "  and c.table_name = f.table_name"
+                    + "  and c.column_name = f.column_name"
+                    + "  and e.table_name = g.table_name"
+                    + "  and e.column_name = g.column_name"
                }
        };
        protected static String sql_view_text[] = {
@@ -923,7 +1091,8 @@ public class CmnProps{
                     + "on  c.object_id = b.object_id "
                     + "where a.name = ?",
                "select view_definition from information_schema.views where table_name = ?",
-               "select text from syscat.views where viewname= ?"
+               "select text from syscat.views where viewname= ?",
+               "select view_definition from information_schema.views where table_name = ?"
        };
        protected static String sql_view_column_and_comment[] = {
                "select "
@@ -964,7 +1133,15 @@ public class CmnProps{
             + " where"
             + "  tabschema = current_schema"
             + "  and tabname = ?"
-            + " order by colno"
+            + " order by colno",
+               " select "
+            + " column_name,"
+            + " ''::text as column_comment "
+            + " from"
+            + " information_schema.columns "
+            + " where"
+            + "  table_name = ? "
+            + " order by ordinal_position"
        };
        protected static String sql_proc[] = {
                "select text from user_source where type = ? and name = ? order by line",
@@ -1041,6 +1218,29 @@ public class CmnProps{
                     + ") a "
                     + "where "
                     + " a.object_type = ? "
+                    + " and a.object_name = ? ",
+               "select a.definition "
+                    + "from "
+                    + "( "
+                    + "select "
+                    + " routine_name as object_name, "
+                    + " routine_type as object_type, "
+                    + " routine_definition as definition "
+                    + "from "
+                    + " information_schema.routines "
+                    + "where "
+                    + " routine_schema = current_schema() "
+                    + "union select "
+                    + " trigger_name as object_name, "
+                    + " 'TRIGGER' as object_type, "
+                    + " action_statement as definition "
+                    + "from "
+                    + " information_schema.triggers "
+                    + "where "
+                    + " trigger_schema = current_schema() "
+                    + ") a "
+                    + "where "
+                    + " a.object_type = ? "
                     + " and a.object_name = ? "
        };
        
index d69e1d2..07a6733 100644 (file)
@@ -169,7 +169,7 @@ public class RapideMetaUnloader{
                        cp = new CmnProps();
                        cp.setProperty(database);
                        
-                       if (cp.dbType > cp.DB_TYPE_DB2 || cp.dbType <0){
+                       if (cp.dbType > cp.DB_TYPE_POSTGRESQL || cp.dbType <0){
                                throw new Exception("\83f\81[\83^\83x\81[\83X\82ª\91Î\8fÛ\8aO\82Å\82·\81B[" + cp.DB_TYPE_NAME[cp.dbType] + "]");
                        }
                        if(cp.outFolder != null){