fix the error log does not contain table name

This commit is contained in:
kangzhidong
2019-03-13 16:55:38 +08:00
parent 7dab5ac6c2
commit 078673c6a9
2 changed files with 8 additions and 8 deletions

View File

@@ -76,7 +76,7 @@ public class JdbcTypeUtil {
|| "TEXT".equalsIgnoreCase(columnType) || "TINYTEXT".equalsIgnoreCase(columnType); || "TEXT".equalsIgnoreCase(columnType) || "TINYTEXT".equalsIgnoreCase(columnType);
} }
public static Object typeConvert(String columnName, String value, int sqlType, String mysqlType) { public static Object typeConvert(String tableName ,String columnName, String value, int sqlType, String mysqlType) {
if (value == null if (value == null
|| (value.equals("") && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) { || (value.equals("") && !(isText(mysqlType) || sqlType == Types.CHAR || sqlType == Types.VARCHAR || sqlType == Types.LONGVARCHAR))) {
return null; return null;
@@ -161,7 +161,7 @@ public class JdbcTypeUtil {
} }
return res; return res;
} catch (Exception e) { } catch (Exception e) {
logger.error("table: {} column: {}, failed convert type {} to {}", columnName, value, sqlType); logger.error("table: {} column: {}, failed convert type {} to {}", tableName, columnName, value, sqlType);
return value; return value;
} }
} }

View File

@@ -77,7 +77,7 @@ public class MessageUtil {
} }
} }
row.put(column.getName(), row.put(column.getName(),
JdbcTypeUtil.typeConvert(column.getName(), JdbcTypeUtil.typeConvert(dml.getTable(),column.getName(),
column.getValue(), column.getValue(),
column.getSqlType(), column.getSqlType(),
column.getMysqlType())); column.getMysqlType()));
@@ -95,7 +95,7 @@ public class MessageUtil {
for (CanalEntry.Column column : rowData.getBeforeColumnsList()) { for (CanalEntry.Column column : rowData.getBeforeColumnsList()) {
if (updateSet.contains(column.getName())) { if (updateSet.contains(column.getName())) {
rowOld.put(column.getName(), rowOld.put(column.getName(),
JdbcTypeUtil.typeConvert(column.getName(), JdbcTypeUtil.typeConvert(dml.getTable(),column.getName(),
column.getValue(), column.getValue(),
column.getSqlType(), column.getSqlType(),
column.getMysqlType())); column.getMysqlType()));
@@ -153,16 +153,16 @@ public class MessageUtil {
// } // }
List<Map<String, String>> data = flatMessage.getData(); List<Map<String, String>> data = flatMessage.getData();
if (data != null) { if (data != null) {
dml.setData(changeRows(data, flatMessage.getSqlType(), flatMessage.getMysqlType())); dml.setData(changeRows(dml.getTable(), data, flatMessage.getSqlType(), flatMessage.getMysqlType()));
} }
List<Map<String, String>> old = flatMessage.getOld(); List<Map<String, String>> old = flatMessage.getOld();
if (old != null) { if (old != null) {
dml.setOld(changeRows(old, flatMessage.getSqlType(), flatMessage.getMysqlType())); dml.setOld(changeRows(dml.getTable(), old, flatMessage.getSqlType(), flatMessage.getMysqlType()));
} }
return dml; return dml;
} }
private static List<Map<String, Object>> changeRows(List<Map<String, String>> rows, Map<String, Integer> sqlTypes, private static List<Map<String, Object>> changeRows(String table, List<Map<String, String>> rows, Map<String, Integer> sqlTypes,
Map<String, String> mysqlTypes) { Map<String, String> mysqlTypes) {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
for (Map<String, String> row : rows) { for (Map<String, String> row : rows) {
@@ -181,7 +181,7 @@ public class MessageUtil {
continue; continue;
} }
Object finalValue = JdbcTypeUtil.typeConvert(columnName, columnValue, sqlType, mysqlType); Object finalValue = JdbcTypeUtil.typeConvert(table, columnName, columnValue, sqlType, mysqlType);
resultRow.put(columnName, finalValue); resultRow.put(columnName, finalValue);
} }
result.add(resultRow); result.add(resultRow);