diff --git a/backend/src/main/java/io/dataease/datasource/dto/SqlServerConfigration.java b/backend/src/main/java/io/dataease/datasource/dto/SqlServerConfigration.java index 7282704586..1cbe90c83a 100644 --- a/backend/src/main/java/io/dataease/datasource/dto/SqlServerConfigration.java +++ b/backend/src/main/java/io/dataease/datasource/dto/SqlServerConfigration.java @@ -8,6 +8,7 @@ import lombok.Setter; @Setter public class SqlServerConfigration extends JdbcDTO { private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; + private String schema; public String getJdbc(){ return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE".replace("HOSTNAME", getHost()).replace("PORT", getPort().toString()).replace("DATABASE", getDataBase()); diff --git a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java index 45f4854820..a3e4c0deff 100644 --- a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java +++ b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java @@ -42,20 +42,25 @@ public class JdbcProvider extends DatasourceProvider { public List getData(DatasourceRequest dsr) throws Exception { List list = new LinkedList<>(); Connection connection = null; - try { - connection = getConnectionFromPool(dsr); - Statement stat = connection.createStatement(); - ResultSet rs = stat.executeQuery(dsr.getQuery()); - list = fetchResult(rs); - } catch (SQLException e) { - DataEaseException.throwException(e); - } catch (Exception e) { - DataEaseException.throwException(e); - } finally { - if(connection != null){ - connection.close(); - } - } + connection = getConnectionFromPool(dsr); + Statement stat = connection.createStatement(); + ResultSet rs = stat.executeQuery(dsr.getQuery()); + System.out.println(rs == null); + list = fetchResult(rs); +// try { +// connection = getConnectionFromPool(dsr); +// Statement stat = connection.createStatement(); +// ResultSet rs = stat.executeQuery(dsr.getQuery()); +// list = fetchResult(rs); +// } catch (SQLException e) { +// DataEaseException.throwException(e); +// } catch (Exception e) { +// DataEaseException.throwException(e); +// } finally { +// if(connection != null){ +// connection.close(); +// } +// } return list; } @@ -102,18 +107,23 @@ public class JdbcProvider extends DatasourceProvider { List list = new LinkedList<>(); ResultSetMetaData metaData = rs.getMetaData(); int columnCount = metaData.getColumnCount(); + System.out.println("columnCount: " + columnCount); while (rs.next()) { String[] row = new String[columnCount]; for (int j = 0; j < columnCount; j++) { int columType = metaData.getColumnType(j + 1); + switch (columType) { case Types.DATE: - row[j] = rs.getDate(j + 1).toString(); + if(rs.getDate(j + 1) != null){ + row[j] = rs.getDate(j + 1).toString(); + } break; default: row[j] = rs.getString(j + 1); break; } + System.out.println(j + " " + columType + " " + row[j]); } list.add(row); } @@ -506,7 +516,9 @@ public class JdbcProvider extends DatasourceProvider { return "show tables;"; case sqlServer: SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfigration.class); - return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';".replace("DATABASE", sqlServerConfigration.getDataBase()); + return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'DS_SCHEMA' ;" + .replace("DATABASE", sqlServerConfigration.getDataBase()) + .replace("DS_SCHEMA", sqlServerConfigration.getSchema()); case oracle: OracleConfigration oracleConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfigration.class); if(StringUtils.isEmpty(oracleConfigration.getSchema())){ @@ -523,6 +535,8 @@ public class JdbcProvider extends DatasourceProvider { switch (datasourceType) { case oracle: return "select * from all_users"; + case sqlServer: + return "select name from sys.schemas;"; default: return "show tables;"; } diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 2bb34dce5b..c8ae09aad9 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -378,6 +378,7 @@ public class DataSetTableService { String table = dataTableInfoDTO.getTable(); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize, false)); + System.out.println(datasourceRequest.getQuery()); map.put("sql", datasourceRequest.getQuery()); try { data.addAll(datasourceProvider.getData(datasourceRequest)); diff --git a/frontend/src/views/system/datasource/form.vue b/frontend/src/views/system/datasource/form.vue index bc8fb00755..e2ee45c109 100644 --- a/frontend/src/views/system/datasource/form.vue +++ b/frontend/src/views/system/datasource/form.vue @@ -63,6 +63,23 @@ + + + + {{ $t('datasource.get_schema') }} + + + + + + + +