mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-30 11:12:55 +08:00
fix myql tinyint error
This commit is contained in:
@ -31,6 +31,35 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
}
|
||||
|
||||
|
||||
private static String TABLES_SQL
|
||||
= "SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE, VERSION, TABLE_ROWS, DATA_LENGTH, AUTO_INCREMENT, CREATE_TIME, UPDATE_TIME, TABLE_COLLATION, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = '%s'";
|
||||
@Override
|
||||
public List<Table> tables(Connection connection, @NotEmpty String databaseName, String schemaName, String tableName) {
|
||||
String sql = String.format(TABLES_SQL, databaseName);
|
||||
if(StringUtils.isNotBlank(tableName)){
|
||||
sql += " AND TABLE_NAME = '" + tableName + "'";
|
||||
}
|
||||
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
|
||||
List<Table> tables = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
Table table = new Table();
|
||||
table.setDatabaseName(databaseName);
|
||||
table.setSchemaName(schemaName);
|
||||
table.setName(resultSet.getString("TABLE_NAME"));
|
||||
table.setEngine(resultSet.getString("ENGINE"));
|
||||
table.setRows(resultSet.getLong("TABLE_ROWS"));
|
||||
table.setDataLength(resultSet.getLong("DATA_LENGTH"));
|
||||
table.setCreateTime(resultSet.getString("CREATE_TIME"));
|
||||
table.setUpdateTime(resultSet.getString("UPDATE_TIME"));
|
||||
table.setCollate(resultSet.getString("TABLE_COLLATION"));
|
||||
table.setComment(resultSet.getString("TABLE_COMMENT"));
|
||||
tables.add(table);
|
||||
}
|
||||
return tables;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String tableDDL(Connection connection, @NotEmpty String databaseName, String schemaName,
|
||||
@NotEmpty String tableName) {
|
||||
@ -70,12 +99,12 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
}
|
||||
return f;
|
||||
});
|
||||
String functionDDlSql =String.format("SHOW CREATE FUNCTION %s", functionName);
|
||||
SQLExecutor.getInstance().execute(connection,functionDDlSql, resultSet -> {
|
||||
String functionDDlSql = String.format("SHOW CREATE FUNCTION %s", functionName);
|
||||
SQLExecutor.getInstance().execute(connection, functionDDlSql, resultSet -> {
|
||||
if (resultSet.next()) {
|
||||
function.setFunctionBody(resultSet.getString("Create Function"));
|
||||
}
|
||||
} );
|
||||
});
|
||||
return function;
|
||||
|
||||
}
|
||||
@ -103,6 +132,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName,
|
||||
String triggerName) {
|
||||
@ -123,15 +153,15 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
@Override
|
||||
public List<Procedure> procedures(Connection connection, String databaseName, String schemaName) {
|
||||
String sql = "SHOW PROCEDURE STATUS WHERE Db = DATABASE()";
|
||||
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
|
||||
ArrayList<Procedure> procedures = new ArrayList<>();
|
||||
while (resultSet.next()){
|
||||
Procedure procedure = new Procedure();
|
||||
procedure.setProcedureName(resultSet.getString("Name"));
|
||||
procedures.add(procedure);
|
||||
}
|
||||
return procedures;
|
||||
});
|
||||
return SQLExecutor.getInstance().execute(connection, sql, resultSet -> {
|
||||
ArrayList<Procedure> procedures = new ArrayList<>();
|
||||
while (resultSet.next()) {
|
||||
Procedure procedure = new Procedure();
|
||||
procedure.setProcedureName(resultSet.getString("Name"));
|
||||
procedures.add(procedure);
|
||||
}
|
||||
return procedures;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -214,7 +244,7 @@ public class MysqlMetaData extends DefaultMetaService implements MetaData {
|
||||
}
|
||||
}
|
||||
|
||||
private static String VIEW_DDL_SQL="show create view %s";
|
||||
private static String VIEW_DDL_SQL = "show create view %s";
|
||||
|
||||
@Override
|
||||
public Table view(Connection connection, String databaseName, String schemaName, String viewName) {
|
||||
|
@ -17,24 +17,28 @@ public class MysqlValueHandler extends DefaultValueHandler {
|
||||
|
||||
@Override
|
||||
public String getString(ResultSet rs, int index, boolean limitSize) throws SQLException {
|
||||
Object obj = rs.getObject(index);
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
String columnTypeName = rs.getMetaData().getColumnTypeName(index);
|
||||
if (MysqlColumnTypeEnum.GEOMETRY.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.POINT.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.LINESTRING.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.POLYGON.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTIPOINT.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTILINESTRING.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTIPOLYGON.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.GEOMETRYCOLLECTION.name().equalsIgnoreCase(columnTypeName)
|
||||
) {
|
||||
ValueHandler handler = VALUE_HANDLER_MAP.get(MysqlColumnTypeEnum.GEOMETRY.name());
|
||||
return handler.getString(rs, index, limitSize);
|
||||
} else {
|
||||
return super.getString(rs, index, limitSize);
|
||||
try {
|
||||
Object obj = rs.getObject(index);
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
String columnTypeName = rs.getMetaData().getColumnTypeName(index);
|
||||
if (MysqlColumnTypeEnum.GEOMETRY.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.POINT.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.LINESTRING.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.POLYGON.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTIPOINT.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTILINESTRING.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.MULTIPOLYGON.name().equalsIgnoreCase(columnTypeName)
|
||||
|| MysqlColumnTypeEnum.GEOMETRYCOLLECTION.name().equalsIgnoreCase(columnTypeName)
|
||||
) {
|
||||
ValueHandler handler = VALUE_HANDLER_MAP.get(MysqlColumnTypeEnum.GEOMETRY.name());
|
||||
return handler.getString(rs, index, limitSize);
|
||||
} else {
|
||||
return super.getString(rs, index, limitSize);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return rs.getString(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,11 @@
|
||||
"key": "zeroDateTimeBehavior",
|
||||
"value": "convertToNull",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"key": "tinyInt1isBit",
|
||||
"value": "false",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -34,6 +39,11 @@
|
||||
"key": "characterEncoding",
|
||||
"value": "UTF-8",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"key": "tinyInt1isBit",
|
||||
"value": "false",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
|
||||
|
||||
BIT("BIT", true, false, true, false, false, false, true, true, false, false),
|
||||
|
||||
TINYINT("TINYINT", true, false, true, true, false, false, true, true, false, false),
|
||||
TINYINT("TINYINT", false, false, true, true, false, false, true, true, false, false),
|
||||
|
||||
TINYINT_UNSIGNED("TINYINT UNSIGNED", true, false, true, true, false, false, true, true, false, false),
|
||||
TINYINT_UNSIGNED("TINYINT UNSIGNED", false, false, true, true, false, false, true, true, false, false),
|
||||
|
||||
SMALLINT("SMALLINT", false, false, true, true, false, false, true, true, false, false),
|
||||
|
||||
@ -284,7 +284,7 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
|
||||
}
|
||||
|
||||
|
||||
if (Arrays.asList(DECIMAL, FLOAT, DOUBLE,TINYINT).contains(type)) {
|
||||
if (Arrays.asList(DECIMAL, FLOAT, DOUBLE).contains(type)) {
|
||||
if (column.getColumnSize() == null || column.getDecimalDigits() == null) {
|
||||
return columnType;
|
||||
}
|
||||
@ -296,7 +296,7 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (Arrays.asList(DECIMAL_UNSIGNED, FLOAT_UNSIGNED, DECIMAL_UNSIGNED,TINYINT_UNSIGNED).contains(type)) {
|
||||
if (Arrays.asList(DECIMAL_UNSIGNED, FLOAT_UNSIGNED, DECIMAL_UNSIGNED).contains(type)) {
|
||||
if (column.getColumnSize() == null || column.getDecimalDigits() == null) {
|
||||
return columnType;
|
||||
}
|
||||
|
Reference in New Issue
Block a user