From 6b7b2214ef457a953381226dc42354d237d6b295 Mon Sep 17 00:00:00 2001 From: liulin <lin.liu@aliyun.com> Date: 星期二, 13 八月 2024 00:39:26 +0800 Subject: [PATCH] 导出mysql --- src/test/java/com/lunhan/xxx/host/GenCodeGauss.java | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java b/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java index 89ff2a8..8b089c9 100644 --- a/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java +++ b/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java @@ -1602,7 +1602,7 @@ Map<String, String> mapColumnDesc = new HashMap<>(); int idx = 0; - list.add("-- \"" + tableName + "\" - \"" + tableDesc + "\"\nDROP TABLE IF EXISTS \"public\".\"" + tableName + "\";\n"); + list.add("-- " + tableName + " - " + tableDesc + "\nDROP TABLE IF EXISTS \"public\".\"" + tableName + "\";\n"); // 遍历列,构建sql for (Map<String, Object> column : listColumn) { @@ -1614,13 +1614,15 @@ mapColumnDesc.put(name, ParameterUtil.dealNullStr(desc)); - sql += "\t\"" + name + "\" " + GenCodeGauss.mysqlType2Gauss(type); + sql += "\t\"" + name + "\" " + GenCodeGauss.dbType2Gauss(type); switch (type) { case "char": case "varchar": case "nvarchar": - String length = column.get("length").toString(); - sql += "(" + length + ")"; + if (Objects.nonNull(column.get("length"))) { + String length = column.get("length").toString(); + sql += "(" + length + ")"; + } if ("1".equals(isNullable)) { sql += " NULL DEFAULT NULL"; } else { @@ -1671,8 +1673,7 @@ } sql += "\n"; } - sql += ")\n" + - ";\n"; + sql += ");\n"; list.add(sql); sql = ""; @@ -1712,7 +1713,7 @@ return list; } - private static String mysqlType2Gauss(String type) { + private static String dbType2Gauss(String type) { String result = ""; switch (type) { case "char": @@ -1829,13 +1830,13 @@ public static List<String> insertAll(List<Map<String, Object>> list, String tableName, Integer onceCount) { List<String> result = new ArrayList<>(); - String insertSql = "INSERT INTO public." + tableName + "(\""; + String insertSql = "INSERT INTO public.\"" + tableName + "\"(\""; List<String> listColumn = new ArrayList<>(); for (String column : list.get(0).keySet()) { if ("update_time".equalsIgnoreCase(column)) { continue; } - listColumn.add(column); + listColumn.add("\"" + column + "\""); } insertSql += StringUtil.join(listColumn, "\",\"") + "\") VALUES"; @@ -1956,4 +1957,7 @@ } return listTable; } + public static List<String> export(Connection connect, String dbSchema) { + return GenCodeGauss.export(connect, dbSchema, Boolean.TRUE, Boolean.TRUE); + } } -- Gitblit v1.9.3