feat: sqlserver
This commit is contained in:
parent
74b849d0b9
commit
c983b661ff
@ -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());
|
||||
|
||||
@ -42,20 +42,25 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
public List<String[]> getData(DatasourceRequest dsr) throws Exception {
|
||||
List<String[]> 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<String[]> 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;";
|
||||
}
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -63,6 +63,23 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
|
||||
<el-form-item v-if="form.type=='sqlServer'">
|
||||
<el-button icon="el-icon-plus" size="mini" @click="getSchema()">
|
||||
{{ $t('datasource.get_schema') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type=='sqlServer'" :label="$t('datasource.schema')">
|
||||
<el-select filterable v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width">
|
||||
<el-option
|
||||
v-for="item in schemas"
|
||||
:key="item"
|
||||
:label="item"
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
<div v-if="canEdit" slot="footer" class="dialog-footer">
|
||||
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button>
|
||||
@ -107,7 +124,7 @@ export default {
|
||||
},
|
||||
allTypes: [{ name: 'mysql', label: 'MySQL', type: 'jdbc' },
|
||||
{ name: 'oracle', label: 'Oracle', type: 'jdbc' },
|
||||
{ name: 'sqlserver', label: 'SQLSERVER', type: 'jdbc' }],
|
||||
{ name: 'sqlServer', label: 'SQLSERVER', type: 'jdbc' }],
|
||||
schemas: [],
|
||||
canEdit: false,
|
||||
originConfiguration: {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user