Skip to content

Commit

Permalink
Fix oracle io close bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Chat2DB-Pro committed Dec 27, 2023
1 parent eb9ff6e commit 22add55
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -73,7 +74,7 @@ public List<Table> 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<TableColumn> columns(Connection connection, String databaseName, String schemaName, String tableName) {
Expand All @@ -84,6 +85,21 @@ public List<TableColumn> 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");
Expand All @@ -92,7 +108,14 @@ public List<TableColumn> 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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 22add55

Please sign in to comment.