OSDN Git Service

20170615
authorkuboryu <kuboryu@yahoo.co.jp>
Thu, 15 Jun 2017 12:04:00 +0000 (21:04 +0900)
committerkuboryu <kuboryu@yahoo.co.jp>
Thu, 15 Jun 2017 12:04:00 +0000 (21:04 +0900)
com/rapide_act/CmnProps.java
com/rapide_act/CmnUtils.java
com/rapide_act/RapideMetaUnloader.java

index 5a51e47..2488f21 100644 (file)
@@ -40,7 +40,7 @@ public class CmnProps{
        protected static final String [] DB_SQL_QUOTEDS = {"\"", "[", "`", "\"", "\"", "\""};
        protected static final String [] DB_SQL_QUOTEDE = {"\"", "]", "`", "\"", "\"", "\""};
        protected static final String [] SQL_TERMINATOR = {";",  System.getProperty("line.separator") + "GO", ";", ";", ";", ";"};
-       protected static final String [] SQL_PREFIX = {"@", ":r ", "", "", "", ""};
+       protected static final String [] SQL_PREFIX = {"@", ":r ", "source ", "", "", ""};
        protected static final String [] SQL_COMMENT_MARK = {"--", "--", "--", "--", "--", "--"};
        protected static final int MASK_PTN_ALL = 0;
        protected static final int MASK_PTN_ALT = 1;
@@ -594,22 +594,7 @@ public class CmnProps{
                     + " inner join sys.schemas as b "
                     + " on a.schema_id = b.schema_id "
                     + "order by synonym_name,table_owner,table_name",
-               "select "
-                    + " c.name as table_name, "
-                    + " b.index_id, "
-                    + " d.name as index_name , "
-                    + " a.type_desc as allocation_type, "
-                    + " a.data_pages, "
-                    + " partition_number "
-                    + "from "
-                    + " sys.allocation_units as a "
-                    + " inner join sys.partitions as b "
-                    + " on a.container_id = b.partition_id "
-                    + " inner join sys.objects as c "
-                    + " on b.object_id = c.object_id and c.type = 'U' "
-                    + " inner join sys.indexes as d "
-                    + " on b.index_id = d.index_id and d.object_id = b.object_id "
-                    + "order by c.name, b.index_id",
+               "",
                "select distinct "
                     + " c.name as table_name, "
                     + " a.name as constraint_name, "
@@ -634,6 +619,123 @@ public class CmnProps{
                     + " inner join sys.key_constraints as g "
                     + "     on a.referenced_object_id = g.parent_object_id "
                     + "order by table_name,constraint_name, position"
+               },
+               {       //MYSQL
+               "select "
+                    + " 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,"
+                    + " 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,"
+                    + " column_default as data_default "
+                    + "from "
+                    + " information_schema.tables a,"
+                    + " information_schema.columns b "
+                    + "where "
+                    + " a.table_schema = database()"
+                    + " and a.table_type = 'BASE TABLE'"
+                    + " and a.table_schema = b.table_schema "
+                    + " and a.table_name = b.table_name "
+                    + "order by a.table_name,b.ordinal_position",
+               "select "
+                    + "  a.table_name, "
+                    + "  b.constraint_name as index_name,"
+                    + "  '' 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 = database()"
+                    + "   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"
+                    + "  a.table_name,"
+                    + "  a.index_name,"
+                    + "  b.index_type as index_type, "
+                    + "  '' as constraint_type,"
+                    + "  a.column_name,"
+                    + "  a.seq_in_index as column_position"
+                    + "  from"
+                    + "  information_schema.statistics a,"
+                    + "    information_schema.statistics b"
+                    + "  where"
+                    + "  a.table_schema = database()"
+                    + "  and a.table_schema = b.table_schema"
+                    + "  and a.table_name = b.table_name"
+                    + "  and a.index_name = b.index_name"
+                    + "  and a.non_unique = 1"
+                    + "  order by table_name,index_name,column_position",
+               "select "
+                    + " a.table_name as view_name, "
+                    + " '' as comments "
+                    + "from "
+                    + " information_schema.views a "
+                    + " where"
+                    + " table_schema = database()"
+                    + " 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 = database()"
+                    + " 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 = database()"
+                    + " order by object_name,object_type ",
+               "",
+               "",
+               "",
+               "select distinct "
+                    + "  b.table_name, "
+                    + "  b.constraint_name, "
+                    + "  b.column_name, "
+                    + "  b.ordinal_position as position, "
+                    + "  b.referenced_table_name as r_table_name, "
+                    + "  b.referenced_column_name as r_column_name, "
+                    + "  c.ordinal_position  as r_position "
+                    + " from "
+                    + "  information_schema.referential_constraints a, "
+                    + "  information_schema.key_column_usage b, "
+                    + "  information_schema.columns c "
+                    + " where  "
+                    + "  a.constraint_schema = database() "
+                    + "  and a.constraint_schema = b.constraint_schema "
+                    + "  and a.constraint_name = b.constraint_name "
+                    + "  and b.referenced_table_name = c.table_name "
+                    + "  and b.referenced_column_name = c.column_name "
                }
        };
        protected static String sql_view_text[] = {
@@ -644,7 +746,8 @@ public class CmnProps{
                     + "on  b.object_id = a.object_id "
                     + "inner join sys.sql_modules c "
                     + "on  c.object_id = b.object_id "
-                    + "where a.name = ?"
+                    + "where a.name = ?",
+               "select view_definition from information_schema.views where table_name = ?"
        };
        protected static String sql_view_column_and_comment[] = {
                "select "
@@ -668,7 +771,15 @@ public class CmnProps{
             + " inner join sys.types c on b.system_type_id = c.system_type_id "
             + " where a.type = 'V' "
             + " and c.user_type_id <> 256 "
-            + " order by b.column_id"
+            + " order by b.column_id",
+           " select "
+            + " column_name,"
+            + " replace(replace(column_comment, char(13), ''), char(10), '') 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",
@@ -694,7 +805,30 @@ public class CmnProps{
                     + "on  b.object_id = a.object_id "
                     + "inner join sys.sql_modules c "
                     + "on  c.object_id = b.object_id) d "
-                    + "where d.type = ? and d.name = ?"
+                    + "where d.type = ? and d.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 = database() "
+                    + "union select "
+                    + " trigger_name as object_name, "
+                    + " 'TRIGGER' as object_type, "
+                    + " action_statement as definition "
+                    + "from "
+                    + " information_schema.triggers "
+                    + "where "
+                    + " trigger_schema = database() "
+                    + ") a "
+                    + "where "
+                    + " a.object_type = ? "
+                    + " and a.object_name = ? "
        };
        
        protected String user                                   = null;
index 4f28d69..4734afc 100644 (file)
@@ -35,6 +35,17 @@ import java.nio.charset.Charset;
 
 public class CmnUtils{
        
+       protected static void emptyFile(String _file) throws Exception{
+               PrintWriter pw = null;
+               try {
+                       pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
+                       pw.close();
+               }
+               catch (Exception e){
+                       throw e;
+               }
+       }
+
        protected static void writeCsv(String _file, int _columnCount, ArrayList<String> _alData) throws Exception{
                PrintWriter pw = null;
                try {
@@ -573,6 +584,21 @@ public class CmnUtils{
                return retVal;
        }
 
+       protected static boolean isReserved(String _str) throws Exception{
+               if(
+                       _str.toUpperCase().equals("CURRENT_DATE") ||
+                       _str.toUpperCase().equals("CURRENT_TIME") ||
+                       _str.toUpperCase().equals("CURRENT_TIMESTAMP") ||
+                       _str.toUpperCase().equals("CURRENT_USER") ||
+                       _str.toUpperCase().equals("LOCALTIME") ||
+                       _str.toUpperCase().equals("LOCALTIMESTAMP") ||
+                       _str.toUpperCase().equals("NULL")){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
        protected static String[] getSystemProperty(String _str) throws Exception{
                String [] retValue = null;
                if(System.getProperty(_str)!=null){
index 1b21f05..410d938 100644 (file)
@@ -169,7 +169,7 @@ public class RapideMetaUnloader{
                        cp = new CmnProps();
                        cp.setProperty(database);
                        
-                       if (cp.dbType > cp.DB_TYPE_SQLSERVER || cp.dbType <0){
+                       if (cp.dbType > cp.DB_TYPE_MYSQL || 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){
@@ -191,8 +191,12 @@ public class RapideMetaUnloader{
                        conn = dao.connect();
                        // Def tsv Writing start
                        for(int i=0;i<cp.meta_sql[cp.dbType].length;i++){
-                               dao.select(cp.meta_sql[cp.dbType][i]);
-                               CmnUtils.writeSeparator(folder + "/" + cp.WK_FILE_NAME[i] + "_" + database +"." + cp.fileExtension, dao.getColumnCount(), dao.getArrayList(), cp.delimiter);
+                               if(!cp.meta_sql[cp.dbType][i].equals("")){
+                                       dao.select(cp.meta_sql[cp.dbType][i]);
+                                       CmnUtils.writeSeparator(folder + "/" + cp.WK_FILE_NAME[i] + "_" + database +"." + cp.fileExtension, dao.getColumnCount(), dao.getArrayList(), cp.delimiter);
+                               } else {
+                                       CmnUtils.emptyFile(folder + "/" + cp.WK_FILE_NAME[i] + "_" + database +"." + cp.fileExtension);
+                               }
                        }
                        // Def tsv Writing end
 
@@ -227,7 +231,7 @@ public class RapideMetaUnloader{
                                                if(!colCmnt.equals(""))sbTbCmnt.append(cp.lineSeparator);
                                                if(CmnUtils.isColPrec(colType, colPrec)){
                                                        sbTbCnts.append("(" + colPrec);
-                                                       if (!colScale.equals("") && !colScale.equals("0"))sbTbCnts.append("," + colScale);
+                                                       if (!CmnUtils.isEmpty(colScale) && !colScale.equals("0"))sbTbCnts.append("," + colScale);
                                                        sbTbCnts.append(")");
                                                } else if (CmnUtils.isColLength(colType)){
                                                        if(colLen.equals("-1")){
@@ -236,15 +240,23 @@ public class RapideMetaUnloader{
                                                                sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
                                                        }
                                                }
-                                               if (!colDflt.equals("")){
+                                               if (!CmnUtils.isEmpty(colDflt)){
                                                        if(CmnUtils.split(strLine, cp.SQL_COMMENT_MARK[cp.dbType]).length > 0){
                                                                String [] colDfltAry = CmnUtils.split(colDflt, cp.SQL_COMMENT_MARK[cp.dbType]);
-                                                               sbTbCnts.append(" DEFAULT " + colDfltAry[0].trim());
+                                                               if (cp.dbType == cp.DB_TYPE_MYSQL && !CmnUtils.isReserved(colDfltAry[0].trim())){
+                                                                       sbTbCnts.append(" DEFAULT '" + colDfltAry[0].trim() + "'");
+                                                               } else {
+                                                                       sbTbCnts.append(" DEFAULT " + colDfltAry[0].trim());
+                                                               }
                                                        } else {
-                                                               sbTbCnts.append(" DEFAULT " + colDflt.trim());
+                                                               if (cp.dbType == cp.DB_TYPE_MYSQL && !CmnUtils.isReserved(colDflt.trim())){
+                                                                       sbTbCnts.append(" DEFAULT " + colDflt.trim() + "'");
+                                                               } else {
+                                                                       sbTbCnts.append(" DEFAULT " + colDflt.trim());
+                                                               }
                                                        }
                                                }
-                                               if (!colNoN.equals("")){
+                                               if (!CmnUtils.isEmpty(colNoN)){
                                                        sbTbCnts.append(" NOT NULL");
                                                } else {
                                                        sbTbCnts.append(" NULL");
@@ -270,8 +282,8 @@ public class RapideMetaUnloader{
                                                        sbTbCnts.append(cp.lineSeparator);
                                                        sbTbCnts.append("(");
                                                        sbTbCnts.append(cp.lineSeparator);
-                                                       if(!strSplit[LINE][COL02].equals(""))sbTbCmnt.append(commentOnTable(cp, strSplit[LINE][COL01], strSplit[LINE][COL02], cp.TYPE_TABLE));
-                                                       if(!strSplit[LINE][COL02].equals(""))sbTbCmnt.append(cp.lineSeparator);
+                                                       if(!CmnUtils.isEmpty(strSplit[LINE][COL02]))sbTbCmnt.append(commentOnTable(cp, strSplit[LINE][COL01], strSplit[LINE][COL02], cp.TYPE_TABLE));
+                                                       if(!CmnUtils.isEmpty(strSplit[LINE][COL02]))sbTbCmnt.append(cp.lineSeparator);
                                                } else {
                                                        sbTbCnts.append(",");
                                                        sbTbCnts.append(cp.lineSeparator);
@@ -282,8 +294,8 @@ public class RapideMetaUnloader{
                                                sbTbCnts.append(cp.lineSeparator);
                                                sbTbCnts.append("(");
                                                sbTbCnts.append(cp.lineSeparator);
-                                               if(!strSplit[LINE][COL02].equals(""))sbTbCmnt.append(commentOnTable(cp, strSplit[LINE][COL01], strSplit[LINE][COL02], cp.TYPE_TABLE));
-                                               if(!strSplit[LINE][COL02].equals(""))sbTbCmnt.append(cp.lineSeparator);
+                                               if(!CmnUtils.isEmpty(strSplit[LINE][COL02]))sbTbCmnt.append(commentOnTable(cp, strSplit[LINE][COL01], strSplit[LINE][COL02], cp.TYPE_TABLE));
+                                               if(!CmnUtils.isEmpty(strSplit[LINE][COL02]))sbTbCmnt.append(cp.lineSeparator);
                                        }
                                        for(int i=0;i<strSplit[LINE].length;i++)CmnUtils.debugPrint("'" + strSplit[LINE][i] + "'");
 
@@ -309,7 +321,7 @@ public class RapideMetaUnloader{
                                }
                                if(CmnUtils.isColPrec(colType, colPrec)){
                                        sbTbCnts.append("(" + colPrec);
-                                       if (!colScale.equals("") && !colScale.equals("0"))sbTbCnts.append("," + colScale);
+                                       if (!CmnUtils.isEmpty(colScale) && !CmnUtils.isEmpty(colScale))sbTbCnts.append("," + colScale);
                                        sbTbCnts.append(")");
                                } else if (CmnUtils.isColLength(colType)){
                                        if(colLen.equals("-1")){
@@ -318,8 +330,14 @@ public class RapideMetaUnloader{
                                                sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
                                        }
                                }
-                               if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
-                               if (!colNoN.equals("")){
+                               if (!CmnUtils.isEmpty(colDflt)){
+                                       if (cp.dbType == cp.DB_TYPE_MYSQL && !CmnUtils.isReserved(colDflt.trim())){
+                                               sbTbCnts.append(" DEFAULT '" + colDflt.trim() + "'");
+                                       } else {
+                                               sbTbCnts.append(" DEFAULT " + colDflt.trim());
+                                       }
+                               }
+                               if (!CmnUtils.isEmpty(colNoN)){
                                        sbTbCnts.append(" NOT NULL");
                                } else {
                                        sbTbCnts.append(" NULL");
@@ -375,7 +393,7 @@ public class RapideMetaUnloader{
                                        strSplit[LINE] = CmnUtils.split(strLine, cp.delimiter);
                                        //Not 1st Line Process
                                        if (!indexName.equals("")){
-                                               if (!strSplit[LINE][COL02].equals(indexName)){
+                                               if (!strSplit[LINE][COL02].equals(indexName) || !strSplit[LINE][COL01].equals(tableName)){
                                                        //Post Process
                                                        if (colPos.equals("1")){
                                                                sbIxCnts.append(cp.DB_SQL_QUOTEDS[cp.dbType]+ colName + cp.DB_SQL_QUOTEDE[cp.dbType]);
@@ -401,7 +419,7 @@ public class RapideMetaUnloader{
                                                                for(int i=0;i<strSplit[IDX_CONTENTS_1].length;i++)if(!strSplit[IDX_CONTENTS_1][i].trim().equals(""))pw[W_CREATE_UKEY].println(strSplit[IDX_CONTENTS_1][i]);
                                                                strSplit[IDX_CONTENTS_2] = CmnUtils.split(sbIx2Cnts.toString(), cp.lineSeparator);
                                                                for(int i=0;i<strSplit[IDX_CONTENTS_2].length;i++)if(!strSplit[IDX_CONTENTS_2][i].trim().equals(""))pw[W_DROP_UKEY].println(strSplit[IDX_CONTENTS_2][i]);
-                                                       } else if (constraintType.equals("")){
+                                                       } else {
                                                                strSplit[IDX_CONTENTS_1] = CmnUtils.split(sbIxCnts.toString(), cp.lineSeparator);
                                                                for(int i=0;i<strSplit[IDX_CONTENTS_1].length;i++)if(!strSplit[IDX_CONTENTS_1][i].trim().equals(""))pw[W_CREATE_INDEX].println(strSplit[IDX_CONTENTS_1][i]);
                                                        }
@@ -415,16 +433,25 @@ public class RapideMetaUnloader{
 
                                                        //Index Changed Process
                                                        if (strSplit[LINE][COL04].equals("P")){
-                                                               sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " PRIMARY KEY(");
-                                                               sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                                               if (cp.dbType == cp.DB_TYPE_MYSQL){
+                                                                       sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT PRIMARY KEY(");
+                                                                       sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP PRIMARY KEY" + cp.SQL_TERMINATOR[cp.dbType]);
+                                                               } else {
+                                                                       sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " PRIMARY KEY(");
+                                                                       sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                                               }
                                                        } else if (strSplit[LINE][COL04].equals("U")){
                                                                sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " UNIQUE(");
                                                                sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP UNIQUE(");
-                                                       } else if (strSplit[LINE][COL04].equals("")){
-                                                               sbIxCnts.append("CREATE INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + strSplit[LINE][COL01] + "(");
+                                                       } else {
+                                                               if (cp.dbType == cp.DB_TYPE_MYSQL && !strSplit[LINE][COL03].equals("") && !strSplit[LINE][COL03].equals("BTREE")){
+                                                                       sbIxCnts.append("CREATE " + strSplit[LINE][COL03] + " INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + strSplit[LINE][COL01] + "(");
+                                                               } else {
+                                                                       sbIxCnts.append("CREATE INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + strSplit[LINE][COL01] + "(");
+                                                               }
                                                        }
                                                        sbIx3Cnts.append("DROP INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
-                                               } else if (strSplit[LINE][COL02].equals(indexName)){
+                                               } else if (strSplit[LINE][COL02].equals(indexName) && strSplit[LINE][COL01].equals(tableName)){
                                                        if (colPos.equals("1")){
                                                                sbIxCnts.append(cp.DB_SQL_QUOTEDS[cp.dbType]+ colName + cp.DB_SQL_QUOTEDE[cp.dbType]);
                                                                if (constraintType.equals("U"))sbIx2Cnts.append(cp.DB_SQL_QUOTEDS[cp.dbType]+ colName + cp.DB_SQL_QUOTEDE[cp.dbType]);
@@ -438,13 +465,22 @@ public class RapideMetaUnloader{
                                        //1st Line Process
                                        else {
                                                if (strSplit[LINE][COL04].equals("P")){
-                                                       sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " PRIMARY KEY(");
-                                                       sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                                       if (cp.dbType == cp.DB_TYPE_MYSQL){
+                                                               sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT  PRIMARY KEY(");
+                                                               sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP PRIMARY KEY" + cp.SQL_TERMINATOR[cp.dbType]);
+                                                       } else {
+                                                               sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " PRIMARY KEY(");
+                                                               sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                                       }
                                                } else if (strSplit[LINE][COL04].equals("U")){
                                                        sbIxCnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " UNIQUE(");
                                                        sbIx2Cnts.append("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP UNIQUE(");
-                                               } else if (strSplit[LINE][COL04].equals("")){
-                                                       sbIxCnts.append("CREATE INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ "(");
+                                               } else {
+                                                       if (cp.dbType == cp.DB_TYPE_MYSQL && !strSplit[LINE][COL03].equals("") && !strSplit[LINE][COL03].equals("BTREE")){
+                                                               sbIxCnts.append("CREATE " + strSplit[LINE][COL03] + " INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ "(");
+                                                       } else {
+                                                               sbIxCnts.append("CREATE INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ON " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]+ "(");
+                                                       }
                                                }
                                                sbIx3Cnts.append("DROP INDEX " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL02] + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
                                        }
@@ -484,7 +520,7 @@ public class RapideMetaUnloader{
                                        for(int i=0;i<strSplit[IDX_CONTENTS_1].length;i++)if(!strSplit[IDX_CONTENTS_1][i].trim().equals(""))pw[W_CREATE_UKEY].println(strSplit[IDX_CONTENTS_1][i]);
                                        strSplit[IDX_CONTENTS_2] = CmnUtils.split(sbIx2Cnts.toString(), cp.lineSeparator);
                                        for(int i=0;i<strSplit[IDX_CONTENTS_2].length;i++)if(!strSplit[IDX_CONTENTS_2][i].trim().equals(""))pw[W_DROP_UKEY].println(strSplit[IDX_CONTENTS_2][i]);
-                               } else if (constraintType.equals("")){
+                               } else {
                                        strSplit[IDX_CONTENTS_1] = CmnUtils.split(sbIxCnts.toString(), cp.lineSeparator);
                                        for(int i=0;i<strSplit[IDX_CONTENTS_1].length;i++)if(!strSplit[IDX_CONTENTS_1][i].trim().equals(""))pw[W_CREATE_INDEX].println(strSplit[IDX_CONTENTS_1][i]);
                                }
@@ -522,9 +558,13 @@ public class RapideMetaUnloader{
                                dao.executeSql();
                                alData = dao.getArrayList();
                                columnCount = dao.getColumnCount();
-                               if (cp.dbType == cp.DB_TYPE_ORACLE){
+                               if (cp.dbType == cp.DB_TYPE_ORACLE || cp.dbType == cp.DB_TYPE_MYSQL){
                                        pw[CONTENTS].println("/* " + strSplit[LINE][COL01] + " */");
-                                       pw[CONTENTS].println("CREATE OR REPLACE VIEW " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]);
+                                       if (cp.dbType == cp.DB_TYPE_ORACLE){
+                                               pw[CONTENTS].println("CREATE OR REPLACE VIEW " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]);
+                                       } else {
+                                               pw[CONTENTS].println("CREATE VIEW " + cp.DB_SQL_QUOTEDS[cp.dbType]+ strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]);
+                                       }
                                        pw[CONTENTS].println("(");
                                        for(int i=0;i<alData.size();i++){
                                                if ((i+1) % columnCount == 1){
@@ -585,12 +625,18 @@ public class RapideMetaUnloader{
                                strSplit[LINE] = CmnUtils.split(strLine, cp.delimiter);
                                CmnUtils.debugPrint("'" + strSplit[LINE][COL01] + "'");
                                pw[CREATE].println(cp.SQL_PREFIX[cp.dbType] + "PROCEDURES/" + strSplit[LINE][COL01] + ".sql");
-                               pw[DROP].println("DROP " + strSplit[LINE][COL02] + " " + strSplit[LINE][COL01] + cp.SQL_TERMINATOR[cp.dbType]);
+                               pw[DROP].println("DROP " + strSplit[LINE][COL02] + " " + cp.DB_SQL_QUOTEDS[cp.dbType] + strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType] + cp.SQL_TERMINATOR[cp.dbType]);
                                if (strSplit[LINE].length>1)CmnUtils.debugPrint("'" + strSplit[LINE][COL02] + "'");
                                pw[CONTENTS] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + strSplit[LINE][COL01] + ".sql"))));
                                if (cp.dbType == cp.DB_TYPE_ORACLE){
                                        pw[CONTENTS].println("/* " + strSplit[LINE][COL01] + " */");
                                        pw[CONTENTS].print("CREATE OR REPLACE ");
+                               } else if (cp.dbType == cp.DB_TYPE_MYSQL){
+                                       if(strSplit[LINE][COL02].equals("TRIGGER")){
+                                               pw[CONTENTS].println("CREATE " + strSplit[LINE][COL02] + " " + cp.DB_SQL_QUOTEDS[cp.dbType] + strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType] + " " + strSplit[LINE][COL03] + " " + strSplit[LINE][COL04] + " ON " + cp.DB_SQL_QUOTEDS[cp.dbType] + strSplit[LINE][COL05] + cp.DB_SQL_QUOTEDE[cp.dbType] + " FOR EACH ROW");
+                                       } else {
+                                               pw[CONTENTS].println("CREATE " + strSplit[LINE][COL02] + " " + cp.DB_SQL_QUOTEDS[cp.dbType] + strSplit[LINE][COL01] + cp.DB_SQL_QUOTEDE[cp.dbType]);
+                                       }
                                }
                                stmt = dao.prepareSql(cp.sql_proc[cp.dbType]);
                                stmt.setString(1,strSplit[LINE][COL02]);
@@ -729,7 +775,11 @@ public class RapideMetaUnloader{
                                        strSplit[LINE] = CmnUtils.split(strLine, cp.delimiter);
                                        if(!fkName.equals(strSplit[LINE][COL02]) && !fkName.equals("")){
                                                pw[CREATE].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " FOREIGN KEY (" + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkCol + cp.DB_SQL_QUOTEDE[cp.dbType]+ ") REFERENCES " + cp.DB_SQL_QUOTEDS[cp.dbType]+ rtbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " (" + cp.DB_SQL_QUOTEDS[cp.dbType]+ rfkCol + cp.DB_SQL_QUOTEDE[cp.dbType]+ ")" + cp.SQL_TERMINATOR[cp.dbType]);
-                                               pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                               if(cp.dbType == cp.DB_TYPE_MYSQL){
+                                                       pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP FOREIGN KEY " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                               } else {
+                                                       pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                                               }
                                                for(int i=0;i<strSplit[LINE].length;i++)CmnUtils.debugPrint("'" + strSplit[LINE][i] + "'");
                                                tbName = strSplit[LINE][COL01];
                                                fkName = strSplit[LINE][COL02];
@@ -760,8 +810,12 @@ public class RapideMetaUnloader{
                                        
                                }
                                pw[CREATE].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " ADD CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " FOREIGN KEY (" + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkCol + cp.DB_SQL_QUOTEDE[cp.dbType]+ ") REFERENCES " + cp.DB_SQL_QUOTEDS[cp.dbType]+ rtbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " (" + cp.DB_SQL_QUOTEDS[cp.dbType]+ rfkCol + cp.DB_SQL_QUOTEDE[cp.dbType]+ ")" + cp.SQL_TERMINATOR[cp.dbType]);
-                               pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
-                               for(int i=0;i<pw.length;i++){
+                               if(cp.dbType == cp.DB_TYPE_MYSQL){
+                                       pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP FOREIGN KEY " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                               } else {
+                                       pw[DROP].println("ALTER TABLE " + cp.DB_SQL_QUOTEDS[cp.dbType]+ tbName + cp.DB_SQL_QUOTEDE[cp.dbType]+ " DROP CONSTRAINT " + cp.DB_SQL_QUOTEDS[cp.dbType]+ fkName + cp.DB_SQL_QUOTEDE[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
+                               }
+                                       for(int i=0;i<pw.length;i++){
                                        if(pw[i]!=null){
                                                pw[i].close();
                                                pw[i]=null;