Skip to content

Commit

Permalink
0006127: Dbfill of nchar/nvarchar and avoid timestamp/rowversion
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Nov 27, 2023
1 parent 484dc5b commit fe40e76
Showing 1 changed file with 23 additions and 1 deletion.
Expand Up @@ -170,6 +170,7 @@ public void fillTables(String[] tableNames, Map<String, DmlWeight> tableProperti
Table table = platform.readTableFromDatabase(getCatalogToUse(), getSchemaToUse(),
tableName);
if (table != null) {
table = filterColumns(table);
tablesToFill.add(table);
} else if (!ignoreMissingTables) {
throw new RuntimeException("Cannot find table " + tableName + " in catalog "
Expand Down Expand Up @@ -889,7 +890,8 @@ private Object generateRandomValueForColumn(Table table, Column column) {
objectValue = randomBytes(randomSize(column, size));
} else if (type == Types.ARRAY) {
objectValue = null;
} else if (type == Types.VARCHAR || type == Types.LONGVARCHAR || type == Types.CHAR || type == Types.CLOB) {
} else if (type == Types.VARCHAR || type == Types.NVARCHAR || type == Types.NCHAR || type == Types.LONGVARCHAR || type == Types.CHAR
|| type == Types.CLOB) {
if (column.getJdbcTypeName() != null
&& (column.getJdbcTypeName().equals("JSON") || column.getJdbcTypeName().equals("jsonb"))) {
objectValue = "{\"jumpmind\":\"symmetricds\"}";
Expand Down Expand Up @@ -1054,6 +1056,7 @@ protected Map<String, Table> getAllDbTables() {
allDbTablesCache = new TreeMap<String, Table>(String.CASE_INSENSITIVE_ORDER);
Table[] allTables = platform.readDatabase(getCatalogToUse(), getSchemaToUse(), null).getTables();
for (Table table : allTables) {
table = filterColumns(table);
allDbTablesCache.put(table.getName(), table);
}
}
Expand All @@ -1064,6 +1067,25 @@ protected Table getDbTable(String catalogName, String schemaName, String tableNa
Table table = getAllDbTables().get(tableName);
if (table == null) {
table = platform.readTableFromDatabase(catalogName, schemaName, tableName);
table = filterColumns(table);
}
return table;
}

protected Table filterColumns(Table table) {
if (platform.getName().startsWith("mssql")) {
List<Column> columnsToRemove = new ArrayList<Column>();
for (Column column : table.getColumns()) {
if (column.getJdbcTypeName().equalsIgnoreCase("timestamp") || column.getJdbcTypeName().equalsIgnoreCase("rowversion")) {
columnsToRemove.add(column);
}
}
if (columnsToRemove.size() > 0) {
table = table.copy();
for (Column column : columnsToRemove) {
table.removeColumn(column);
}
}
}
return table;
}
Expand Down

0 comments on commit fe40e76

Please sign in to comment.