made the map from sql types to column types mutable and added public method to update
@@ -25,6 +25,8 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
/**
* Creates a Relation from the result of a SQL query, by passing the jdbc resultset to the constructor
@@ -32,7 +34,10 @@ import java.sql.Types;
public class SqlResultSetReader {
// Maps from supported SQL types to their Tablesaw equivalents'
- private static final ImmutableMap<Integer, ColumnType> SQL_TYPE_TO_TABLESAW_TYPE =
+ private static final Map<Integer, ColumnType> SQL_TYPE_TO_TABLESAW_TYPE = initializeMap();
+
+ private static Map<Integer, ColumnType> initializeMap() {
+ return new HashMap<>(
new ImmutableMap.Builder<Integer, ColumnType>()
.put(Types.BINARY, ColumnType.BOOLEAN)
.put(Types.BOOLEAN, ColumnType.BOOLEAN)
@@ -59,7 +64,18 @@ public class SqlResultSetReader {
.put(Types.NCHAR, ColumnType.STRING)
.put(Types.NVARCHAR, ColumnType.STRING)
.put(Types.VARCHAR, ColumnType.STRING)
- .build();
+ .build());
+ }
+
+ /**
+ * Change or add a mapping between the given Jdbc type and column type.
+ * When reading from a database, the db column type is automatically assigned to the associated tablesaw column type
+ * @param jdbc an int representing a legal value from java.sql.types;
+ * @param columnType a tablesaw column type
+ */
+ public static void mapJdbcTypeToColumnType(Integer jdbc, ColumnType columnType) {
+ SQL_TYPE_TO_TABLESAW_TYPE.put(jdbc, columnType);
+ }
/**
* Returns a new table with the given tableName, constructed from the given result set
