提交 e8d48dff 编写于 作者: L LonwoLonwo

#10261 table DDL refactoring


Former-commit-id: 59647ae8
上级 47cf8875
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册