From 22add550dcf5ad97416fb747cbe7ba0f0271032a Mon Sep 17 00:00:00 2001 From: SwallowGG <1558143046@qq.com> Date: Wed, 27 Dec 2023 20:05:38 +0800 Subject: [PATCH] Fix oracle io close bug --- .../chat2db/plugin/oracle/OracleMetaData.java | 27 +++++++++++++++++-- .../chat2db/spi/jdbc/DefaultValueHandler.java | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java index 9108b637a..d280a90f2 100644 --- a/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java +++ b/chat2db-server/chat2db-plugins/chat2db-oracle/src/main/java/ai/chat2db/plugin/oracle/OracleMetaData.java @@ -1,5 +1,6 @@ package ai.chat2db.plugin.oracle; +import java.io.Reader; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -73,7 +74,7 @@ public List tables(Connection connection, String databaseName, String sch }); } - private static String SELECT_TAB_COLS = "SELECT atc.column_id , atc.column_name as COLUMN_NAME, atc.data_type as DATA_TYPE , atc.data_length as DATA_LENGTH , atc.data_type_mod , atc.nullable , atc.data_default , acc.comments , atc.DATA_PRECISION , atc.DATA_SCALE , atc.CHAR_USED FROM all_tab_columns atc, all_col_comments acc WHERE atc.owner = acc.owner AND atc.table_name = acc.table_name AND atc.column_name = acc.column_name AND atc.owner = '%s' AND atc.table_name = '%s' order by atc.column_id"; + private static String SELECT_TAB_COLS = "SELECT atc.column_id , atc.column_name as COLUMN_NAME, atc.data_type as DATA_TYPE , atc.data_length as DATA_LENGTH , atc.data_type_mod , atc.nullable , atc.data_default as DATA_DEFAULT, acc.comments , atc.DATA_PRECISION , atc.DATA_SCALE , atc.CHAR_USED FROM all_tab_columns atc, all_col_comments acc WHERE atc.owner = acc.owner AND atc.table_name = acc.table_name AND atc.column_name = acc.column_name AND atc.owner = '%s' AND atc.table_name = '%s' order by atc.column_id"; @Override public List columns(Connection connection, String databaseName, String schemaName, String tableName) { @@ -84,6 +85,21 @@ public List columns(Connection connection, String databaseName, Str TableColumn tableColumn = new TableColumn(); tableColumn.setTableName(tableName); tableColumn.setSchemaName(schemaName); + try { + // + // Fields of the LONG type cannot be retrieved using getObject. They need to be accessed using getCharacterStream, and must be read first in the sequence. + Reader reader = resultSet.getCharacterStream("DATA_DEFAULT"); + if(reader != null){ + StringBuilder sb = new StringBuilder(); + int charValue; + while ((charValue = reader.read()) != -1) { + sb.append((char) charValue); + } + tableColumn.setDefaultValue(sb.toString()); + } + }catch (Exception e){ + e.printStackTrace(); + } tableColumn.setName(resultSet.getString("COLUMN_NAME")); tableColumn.setColumnType(resultSet.getString("DATA_TYPE")); Integer dataPrecision = resultSet.getInt("DATA_PRECISION"); @@ -92,7 +108,14 @@ public List columns(Connection connection, String databaseName, Str }else { tableColumn.setColumnSize(resultSet.getInt("DATA_LENGTH")); } - tableColumn.setDefaultValue(resultSet.getString("DATA_DEFAULT")); +// Object dataDefault = resultSet.getObject(7); +// if(dataDefault!=null) { +// tableColumn.setDefaultValue(dataDefault.toString()); +// } + + + + tableColumn.setComment(resultSet.getString("COMMENTS")); tableColumn.setNullable("Y".equalsIgnoreCase(resultSet.getString("NULLABLE")) ? 1 : 0); tableColumn.setOrdinalPosition(resultSet.getInt("COLUMN_ID")); diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java index 7886d46a9..13ea1f384 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/jdbc/DefaultValueHandler.java @@ -36,7 +36,7 @@ public String getString(ResultSet rs, int index, boolean limitSize) throws SQLEx } else if (obj instanceof Blob blob) { return largeStringBlob(blob, limitSize); } - return rs.getString(index); + return obj.toString(); } catch (Exception e) { log.warn("解析数失败:{},{}", index, obj, e); return obj.toString();