OSDN Git Service

20170625
authorkuboryu <kuboryu@yahoo.co.jp>
Sat, 24 Jun 2017 23:08:13 +0000 (08:08 +0900)
committerkuboryu <kuboryu@yahoo.co.jp>
Sat, 24 Jun 2017 23:08:13 +0000 (08:08 +0900)
com/rapide_act/CmnProps.java
com/rapide_act/RapideMetaLoader.java
com/rapide_act/RapideMetaUnloader.java

index 7a68cf2..075fb33 100644 (file)
@@ -68,14 +68,6 @@ public class CmnProps{
                ";" + System.getProperty("line.separator"), 
                ";" + System.getProperty("line.separator")
        };
-       protected static final String [] SQL_TERMINATOR2 = {
-               ";",  
-               System.getProperty("line.separator") + "GO", 
-               ";", 
-               ";", 
-               ";", 
-               ";"
-       };
        protected static final String [] SQL_PREFIX = {
                "@", 
                ":r ", 
@@ -793,6 +785,129 @@ public class CmnProps{
                     + "  and a.constraint_name = b.constraint_name "
                     + "  and b.referenced_table_name = c.table_name "
                     + "  and b.referenced_column_name = c.column_name "
+               },
+               {       //DB2
+               "select "
+                    + " a.tabname,"
+                    + " 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.length as data_length, "
+                    + " b.length as data_precision, "
+                    + " b.scale as data_scale, "
+                    + " case b.nulls"
+                    + "  when '0' then '\81Z'"
+                    + "  else null "
+                    + " end as nullable,"
+                    + " b.default as data_default "
+                    + " from"
+                    + "  syscat.tables a,"
+                    + "  syscat.columns b"
+                    + " where"
+                    + "  a.tabschema = current_schema"
+                    + "  and a.tabschema = b.tabschema"
+                    + "  and a.tabname = b.tabname"
+                    + "  and a.ownertype = 'U'"
+                    + "  and a.type = 'T'"
+                    + " order by a.tabname,b.colno",
+               "select "
+                    + " a.tabname as table_name,"
+                    + " a.indname as index_name,"
+                    + " '' as index_type,"
+                    + " case a.uniquerule"
+                    + "  when 'P' then 'P'"
+                    + "  when 'U' then 'U'"
+                    + "  else null "
+                    + " end as constraint_type,"
+                    + " b.colname as column_name,"
+                    + " b.colseq as column_position"
+                    + " from"
+                    + " syscat.indexes a,"
+                    + " syscat.indexcoluse b"
+                    + " where"
+                    + "  a.indschema = current_schema"
+                    + "  and a.indschema = b.indschema"
+                    + "  and a.indname = b.indname"
+                    + " order by"
+                    + " a.tabname,"
+                    + " a.indname,"
+                    + " b.colseq",
+               "select "
+                    + " tabname as view_name,"
+                    + " replace(replace(remarks, chr(13), ''), chr(10), '') as comments "
+                    + " from"
+                    + "  syscat.tables "
+                    + " where"
+                    + "  tabschema = current_schema"
+                    + "  and type='V' "
+                    + " order by"
+                    + " tabname",
+           "select "
+                    + " routinename as object_name, "
+                    + " case routinetype"
+                    + "  when 'F' then 'FUNCTION'"
+                    + "  when 'P' then 'PROCEDURE'"
+                    + " end as object_type "
+                    + " from "
+                    + " syscat.routines "
+                    + " where "
+                    + " routineschema = current_schema "
+                    + "union all "
+                    + "select "
+                    + " trigname as object_name, "
+                    + " 'TRIGGER' as object_type "
+                    + "from "
+                    + " syscat.triggers "
+                    + "where "
+                    + " trigschema = current_schema "
+                    + " order by object_name",
+               "select "
+                    + " seqname as sequence_name,"
+                    + " to_char(minvalue) as min_value,"
+                    + " to_char(maxvalue) as max_value,"
+                    + " to_char(increment) as increment_by,"
+                    + " cycle as cycle_flag,"
+                    + " order as order_flag,"
+                    + " to_char(cache) as cache_size,"
+                    + " to_char(nextcachefirstvalue) as last_number "
+                    + " from syscat.sequences "
+                    + " where "
+                    + " seqschema = current_schema "
+                    + " order by seqname",
+               "select "
+                    + "  tabname as synonym_name,"
+                    + "  base_tabschema as table_owner,"
+                    + "  base_tabname as table_name,"
+                    + "  '' as db_link "
+                    + "from syscat.tables "
+                    + " where type = 'A' "
+                    + "  and ownertype = 'U'"
+                    + "  and tabschema = current_schema "
+                    + "order by synonym_name,table_owner,table_name",
+               "",
+               "select distinct "
+                    + " a.tabname as table_name, "
+                    + " a.constname as constraint_name, "
+                    + " b.colname as column_name, "
+                    + " b.colseq as position,"
+                    + " c.tabname as r_table_name, "
+                    + " c.colname as r_column_name, "
+                    + " c.colseq as r_position "
+                    + " from "
+                    + "   syscat.references a, "
+                    + "   syscat.keycoluse b,"
+                    + "   syscat.keycoluse c"
+                    + " where "
+                    + "   a.tabschema = current_schema"
+                    + "   and a.constname = b.constname"
+                    + "   and a.tabschema = b.tabschema"
+                    + "   and a.tabname = b.tabname"
+                    + "   and a.refkeyname = c.constname"
+                    + "   and a.reftabschema = c.tabschema"
+                    + "   and a.reftabname = c.tabname"
+                    + " order by"
+                    + "   a.tabname,a.constname,b.colseq,c.colseq"
                }
        };
        protected static String sql_view_text[] = {
@@ -804,7 +919,8 @@ public class CmnProps{
                     + "inner join sys.sql_modules c "
                     + "on  c.object_id = b.object_id "
                     + "where a.name = ?",
-               "select view_definition from information_schema.views where table_name = ?"
+               "select view_definition from information_schema.views where table_name = ?",
+               "select text from syscat.views where viewname= ?"
        };
        protected static String sql_view_column_and_comment[] = {
                "select "
@@ -836,7 +952,16 @@ public class CmnProps{
             + " information_schema.columns "
             + " where"
             + "  table_name = ? "
-            + " order by ordinal_position"
+            + " order by ordinal_position",
+               "select "
+            + " colname as column_name,"
+            + " replace(replace(remarks, chr(13), ''), chr(10), '') as column_comments "
+            + " from"
+            + "  syscat.columns "
+            + " where"
+            + "  tabschema = current_schema"
+            + "  and tabname = ?"
+            + " order by colno"
        };
        protected static String sql_proc[] = {
                "select text from user_source where type = ? and name = ? order by line",
@@ -885,6 +1010,34 @@ public class CmnProps{
                     + ") a "
                     + "where "
                     + " a.object_type = ? "
+                    + " and a.object_name = ? ",
+               "select "
+                    + " a.definition "
+                    + " from "
+                    + "( "
+                    + "select "
+                    + " routinename as object_name, "
+                    + " case routinetype"
+                    + "  when 'F' then 'FUNCTION'"
+                    + "  when 'P' then 'PROCEDURE'"
+                    + " end as object_type, "
+                    + " text as definition "
+                    + " from "
+                    + " syscat.routines "
+                    + " where "
+                    + " routineschema = current_schema "
+                    + "union all "
+                    + "select "
+                    + " trigname as object_name, "
+                    + " 'TRIGGER' as object_type, "
+                    + " text as definition "
+                    + "from "
+                    + " syscat.triggers "
+                    + "where "
+                    + " trigschema = current_schema "
+                    + ") a "
+                    + "where "
+                    + " a.object_type = ? "
                     + " and a.object_name = ? "
        };
        
index 473534c..6645624 100644 (file)
@@ -191,6 +191,7 @@ public class RapideMetaLoader{
                                        strMltLine += _cp.inColLineSeparator + strLine;
                                }
                        }
+                       strMltLine += _cp.lineSeparator;
                        if(_isReplace){
                                if(!strMltLine.equals("")){
                                        try {
@@ -211,14 +212,11 @@ public class RapideMetaLoader{
                                        }
                                }
                        } else {
-                               if (_cp.dbType == _cp.DB_TYPE_MYSQL){
-                                       sqlLine = CmnUtils.split(strMltLine, _cp.SQL_TERMINATOR[_cp.dbType]);
-                               } else {
-                                       sqlLine = CmnUtils.split(strMltLine, _cp.SQL_TERMINATOR2[_cp.dbType]);
-                               }
+                               sqlLine = CmnUtils.split(strMltLine, _cp.SQL_TERMINATOR[_cp.dbType]);
                                for(int l = 0;l<sqlLine.length;l++){
-                                       if(!sqlLine[l].equals("")){
+                                       if(!sqlLine[l].equals("") && !sqlLine[l].equals(_cp.lineSeparator)){
                                                try {
+                                                       CmnUtils.debugPrint("'" + sqlLine[l] + "'");
                                                        if (_cp.dbType == _cp.DB_TYPE_ORACLE){
                                                                _stmt = _dao.prepareSql(sqlLine[l].replaceAll("\r",""));
                                                        } else {
index e146e66..4060a53 100644 (file)
@@ -169,7 +169,7 @@ public class RapideMetaUnloader{
                        cp = new CmnProps();
                        cp.setProperty(database);
                        
-                       if (cp.dbType > cp.DB_TYPE_MYSQL || cp.dbType <0){
+                       if (cp.dbType > cp.DB_TYPE_DB2 || 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){