Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/odc-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,9 @@
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
</dependency>
<dependency>
<groupId>com.oceanbase</groupId>
<artifactId>db-browser</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.text.StringSubstitutor;
import org.springframework.util.CollectionUtils;

import com.google.common.primitives.Chars;
import com.oceanbase.tools.dbbrowser.model.DBTable;
import com.oceanbase.tools.dbbrowser.model.DBTableColumn;
import com.oceanbase.tools.dbbrowser.model.datatype.DataTypeUtil;

import lombok.NonNull;

Expand Down Expand Up @@ -163,6 +168,31 @@ public static String unquoteSqlValue(final String str, final char wrapChar, fina
return unescapeUseDouble(unwrap, escapeChars);
}

public static void quoteColumnDefaultValues(DBTable table) {
Comment thread
PeachThinking marked this conversation as resolved.
Outdated
if (!CollectionUtils.isEmpty(table.getColumns())) {
table.getColumns().forEach(column -> {
String defaultValue = column.getDefaultValue();
if (StringUtils.isNotEmpty(defaultValue)) {
if (!isDefaultValueBuiltInFunction(column)) {
column.setDefaultValue("'".concat(defaultValue.replace("'", "''")).concat("'"));
}
}
});
}
}

/**
* Check whether the data_default contain built in function. Any of the synonyms for
* CURRENT_TIMESTAMP have the same meaning as CURRENT_TIMESTAMP. These are CURRENT_TIMESTAMP(),
* NOW(), LOCALTIME, LOCALTIME(), LOCALTIMESTAMP, and LOCALTIMESTAMP().
*/
private static boolean isDefaultValueBuiltInFunction(DBTableColumn column) {
return com.oceanbase.tools.dbbrowser.util.StringUtils.isEmpty(column.getDefaultValue())
|| (!DataTypeUtil.isStringType(column.getTypeName())
&& column.getDefaultValue().trim().toUpperCase(Locale.getDefault())
.startsWith("CURRENT_TIMESTAMP"));
}

public static String singleLine(final String str) {
if (StringUtils.isEmpty(str)) {
return str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public Void call() {
dbTableService.getTables(connectionSession, schemaName).entrySet().stream()
.filter(entry -> allRealTableNames.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (connectionSession.getDialectType().isMysql()) {
tableName2Tables.values().forEach(StringUtils::quoteColumnDefaultValues);
}

} catch (Exception ex) {
log.warn("fetch table meta information failed, ex={}", ex);
comparingEntities.forEach(tableComparingEntity -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.sql.DataSource;

import com.oceanbase.odc.common.util.JdbcOperationsUtil;
import com.oceanbase.odc.common.util.StringUtils;
import com.oceanbase.odc.core.shared.constant.ConnectType;
import com.oceanbase.odc.core.shared.constant.DialectType;
import com.oceanbase.odc.service.db.browser.DBSchemaAccessors;
Expand Down Expand Up @@ -87,6 +88,11 @@ public List<DBObjectComparisonResult> compare(@NonNull DBStructureComparisonConf
long startTimestamp = System.currentTimeMillis();
Map<String, DBTable> srcTableName2Table = srcAccessor.getTables(srcConfig.getSchemaName(), null);
Map<String, DBTable> tgtTableName2Table = tgtAccessor.getTables(tgtConfig.getSchemaName(), null);

if (srcConfig.getConnectType().getDialectType().isMysql()) {
srcTableName2Table.values().forEach(StringUtils::quoteColumnDefaultValues);
tgtTableName2Table.values().forEach(StringUtils::quoteColumnDefaultValues);
}
log.info(
"DefaultDBStructureComparator build source and target schema tables success, time consuming={} seconds",
(System.currentTimeMillis() - startTimestamp) / 1000);
Expand Down