From e8d48dff3540a117f04cc23379d6e55c42b5bc91 Mon Sep 17 00:00:00 2001 From: LonwoLonwo Date: Fri, 6 Nov 2020 12:47:57 +0300 Subject: [PATCH] #10261 table DDL refactoring Former-commit-id: 59647ae80930d75a8e28e3712e98ff884868dcfd --- .../dbeaver/ext/exasol/tools/ExasolUtils.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/tools/ExasolUtils.java b/plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/tools/ExasolUtils.java index b4fcacc5f5..dd438ac3e0 100644 --- a/plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/tools/ExasolUtils.java +++ b/plugins/org.jkiss.dbeaver.ext.exasol/src/org/jkiss/dbeaver/ext/exasol/tools/ExasolUtils.java @@ -31,6 +31,7 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef; import org.jkiss.utils.CommonUtils; +import java.math.BigDecimal; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; @@ -91,24 +92,28 @@ public class ExasolUtils { // double quotation mark for column as the name could be a // reserved word - columnString.append("\n\t\t\"").append(rs.getString("COLUMN_NAME")).append("\" ").append(rs.getString("COLUMN_TYPE")).append(" "); + columnString.append("\n\t\t").append(DBUtils.getQuotedIdentifier(dataSource, CommonUtils.notEmpty(rs.getString("COLUMN_NAME")))). + append(" ").append(rs.getString("COLUMN_TYPE")); // has default value? - if (rs.getString("COLUMN_DEFAULT") != null) - columnString.append("DEFAULT ").append(rs.getString("COLUMN_DEFAULT")).append(" "); + String columnDefault = rs.getString("COLUMN_DEFAULT"); + if (columnDefault != null) + columnString.append(" DEFAULT ").append(columnDefault); // has identity - if (rs.getBigDecimal("COLUMN_IDENTITY") != null) - columnString.append("IDENTITY ").append(rs.getBigDecimal("COLUMN_IDENTITY").toString()).append(" "); + BigDecimal bigDecimal = rs.getBigDecimal("COLUMN_IDENTITY"); + if (bigDecimal != null) + columnString.append(" IDENTITY ").append(bigDecimal.toString()); // has identity if (!rs.getBoolean("COLUMN_IS_NULLABLE")) - columnString.append("NOT NULL "); + columnString.append(" NOT NULL"); // comment - if (rs.getString("COLUMN_COMMENT") != null) + String columnComment = rs.getString("COLUMN_COMMENT"); + if (columnComment != null) // replace ' to double ' -> escape for SQL - columnString.append("COMMENT IS '").append(rs.getString("COLUMN_COMMENT").replaceAll("'", "''")).append("'"); + columnString.append(" COMMENT IS '").append(columnComment.replaceAll("'", "''")).append("'"); // if distkey add column to distkey if (rs.getBoolean("COLUMN_IS_DISTRIBUTION_KEY")) @@ -173,7 +178,7 @@ public class ExasolUtils { return String.format ( - "ALTER TABLE %s PARTITION BY %s;", + "ALTER TABLE %s PARTITION BY %s;\n", DBUtils.getObjectFullName(table, DBPEvaluationContext.DDL), colList ); @@ -191,10 +196,10 @@ public class ExasolUtils { for (DBSEntityAttributeRef c : fk.getReferencedConstraint().getAttributeReferences(monitor)) { refColumns.add(DBUtils.getQuotedIdentifier(c.getAttribute())); } - String fk_enabled = " DISABLE "; + String fk_enabled = " DISABLE"; if (fk.getEnabled()) - fk_enabled = " ENABLE "; + fk_enabled = " ENABLE"; return "ALTER TABLE " + DBUtils.getObjectFullName(exasolTable, DBPEvaluationContext.DDL) + " ADD CONSTRAINT " + DBUtils.getQuotedIdentifier(fk) + @@ -210,7 +215,7 @@ public class ExasolUtils { for (DBSEntityAttributeRef c : pk.getAttributeReferences(monitor)) { columns.add("\"" + c.getAttribute().getName() + "\""); } - return "ALTER TABLE " + DBUtils.getObjectFullName(exasolTable, DBPEvaluationContext.DDL) + " ADD CONSTRAINT " + DBUtils.getQuotedIdentifier(pk) + " PRIMARY KEY (" + CommonUtils.joinStrings(",", columns) + ") " + (pk.getEnabled() ? " ENABLE " : " DISABLE "); + return "ALTER TABLE " + DBUtils.getObjectFullName(exasolTable, DBPEvaluationContext.DDL) + " ADD CONSTRAINT " + DBUtils.getQuotedIdentifier(pk) + " PRIMARY KEY (" + CommonUtils.joinStrings(",", columns) + ") " + (pk.getEnabled() ? "ENABLE" : "DISABLE"); } public static String getConnectionDdl(ExasolConnection con, DBRProgressMonitor monitor) throws DBException { -- GitLab