sql执行增加动态参数功能

This commit is contained in:
暮光:城中城
2021-06-27 22:45:30 +08:00
parent 6da66fac7c
commit 03dff7620e
12 changed files with 532 additions and 124 deletions

View File

@@ -1,6 +1,7 @@
package com.zyplayer.doc.db.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.annotation.AuthMan;
@@ -18,8 +19,10 @@ import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteParam;
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteResult;
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteType;
import com.zyplayer.doc.db.framework.db.mapper.base.SqlExecutor;
import com.zyplayer.doc.db.framework.db.transfer.SqlParseUtil;
import com.zyplayer.doc.db.framework.json.DocDbResponseJson;
import com.zyplayer.doc.db.framework.utils.JSONUtil;
import com.zyplayer.doc.db.framework.utils.SqlLogUtil;
import com.zyplayer.doc.db.service.DatabaseServiceFactory;
import com.zyplayer.doc.db.service.DbBaseService;
import org.apache.commons.lang.StringUtils;
@@ -30,10 +33,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.*;
/**
* sql执行器
@@ -71,6 +71,8 @@ public class DbSqlExecutorController {
String useDbSql = dbBaseService.getUseDbSql(dbName);
// 保留历史记录
dbHistoryService.saveHistory(sql.trim(), sourceId);
// 参数处理
Map<String, Object> paramMap = JSON.parseObject(params);
List<String> resultList = new LinkedList<>();
// 支持;分割的多个sql执行
String[] sqlArr = sql.split(";");
@@ -79,23 +81,25 @@ public class DbSqlExecutorController {
continue;
}
sqlItem = sqlItem.trim();
ExecuteResult executeResult;
ExecuteParam executeParam = new ExecuteParam();
try {
ExecuteType executeType = (manageAuth || update) ? ExecuteType.ALL : ExecuteType.SELECT;
ExecuteParam executeParam = new ExecuteParam();
executeParam = SqlParseUtil.getSingleExecuteParam(sqlItem, paramMap);
executeParam.setDatasourceId(sourceId);
executeParam.setExecuteId(executeId);
executeParam.setExecuteType(executeType);
executeParam.setSql(sqlItem);
executeParam.setPrefixSql(useDbSql);
executeParam.setMaxRows(1000);
ExecuteResult executeResult = sqlExecutor.execute(executeParam);
String resultJsonStr = JSON.toJSONString(executeResult, JSONUtil.serializeConfig, SerializerFeature.WriteMapNullValue);
resultList.add(resultJsonStr);
executeResult = sqlExecutor.execute(executeParam);
} catch (Exception e) {
logger.error("执行出错", e);
ExecuteResult executeResult = ExecuteResult.error(e.getMessage(), sqlItem);
resultList.add(JSON.toJSONString(executeResult));
executeResult = ExecuteResult.error(e.getMessage(), sqlItem);
}
// 执行的sql处理
String executeSqlLog = SqlLogUtil.parseLogSql(executeParam.getSql(), executeParam.getParameterMappings(), executeParam.getParamList());
executeResult.setSql(executeSqlLog);
resultList.add(JSON.toJSONString(executeResult, JSONUtil.serializeConfig, SerializerFeature.WriteMapNullValue));
}
return DocDbResponseJson.ok(resultList);
}

View File

@@ -0,0 +1,17 @@
package com.zyplayer.doc.db.framework.db.parser;
import cn.hutool.core.date.DateTime;
public interface FillParamParser {
/**
* 执行时间处理
*
* @param dateTime 时间
* @param paramOne 第一个参数
* @param paramThree 第三个参数
* @return 时间格式化
*/
String parser(DateTime dateTime, String paramOne, String paramTwo, String paramThree);
}

View File

@@ -0,0 +1,128 @@
package com.zyplayer.doc.db.framework.db.parser;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 参数填充帮助类
*
* @author 暮光:城中城
* @since 2019-10-10
*/
public class FillParamUtil {
// 填充时参数map里传入的当前时间的key
public static final String PARAM_NOW = "_now";
public static String fillSqlParam(String sql, Map<String, Object> paramMap) {
return FillParamUtil.fillSqlParam(sql, paramMap, (dateTime, paramOne, format, paramThree) -> {
int addInt = NumberUtils.toInt(paramThree);
if (Objects.equals("now", paramOne)) {
dateTime.offset(DateField.DAY_OF_MONTH, addInt);
format = (format == null) ? "yyyy-MM-dd HH:mm:ss" : format;
} else if (Objects.equals("dt", paramOne)) {
dateTime.offset(DateField.DAY_OF_MONTH, addInt);
format = (format == null) ? "yyyyMMdd" : format;
} else if (Objects.equals("now_d", paramOne)) {
dateTime.offset(DateField.DAY_OF_MONTH, addInt);
format = (format == null) ? "yyyyMMdd" : format;
} else if (Objects.equals("now_m", paramOne)) {
dateTime.offset(DateField.MONTH, addInt);
format = (format == null) ? "yyyyMM" : format;
}
return format;
});
}
/**
* 解析${column}预处理的参数,支持内置参数和动态参数
* 内置参数格式:
* ${now}
* ${now, yyyy-MM-dd 00:00:00}
* ${now, yyyy-MM-dd 00:00:00, 1}
* 内置参数说明:
* 参数1、now当前时间 now_d当前天 now_m当前月
* 参数2、加减天数负数为减。参数1为 now/now_d 时,按天加减,为 now_m 时按月加减
* 参数3、日期格式yyyy-MM-dd HH:mm:ss
*
* @param sql
* @param paramMap
* @return
* @author 暮光:城中城
* @since 2019-10-10
*/
public static String fillSqlParam(String sql, Map<String, Object> paramMap, FillParamParser paramParser) {
// 组装参数
GenericTokenParser parser = new GenericTokenParser("${", "}", content -> {
Object o = paramMap.get(content);
if (o == null) {
Object nowDate = paramMap.get(FillParamUtil.PARAM_NOW);
String[] keyArr = content.split(",");
if (keyArr.length == 1) {
o = getFillParam(paramParser, nowDate, keyArr[0].trim(), null, null);
} else if (keyArr.length == 2) {
o = getFillParam(paramParser, nowDate, keyArr[0].trim(), keyArr[1].trim(), null);
} else if (keyArr.length == 3) {
o = getFillParam(paramParser, nowDate, keyArr[0].trim(), keyArr[1].trim(), keyArr[2].trim());
}
}
return (o == null) ? null : String.valueOf(o);
});
return parser.parse(sql);
}
/**
* 内置参数填充
* ${now, 'yyyy-MM-dd 00:00:00', 1}
*
* @param name
* @param format
* @param add
* @return
* @author 暮光:城中城
* @since 2019-10-10
*/
private static String getFillParam(FillParamParser parser, Object nowDate, String name, String format, String add) {
DateTime dateTime;
// 格式化加不加单引号都支持
if (format != null && format.startsWith("'") && format.endsWith("'")) {
format = format.substring(1, format.length() - 1);
}
// 使用系统时间还是传入的时间作为初始值
if (nowDate instanceof Date) {
dateTime = DateTime.of((Date) nowDate);
} else {
dateTime = DateTime.now();
}
format = (format == null) ? null : format.trim();
if (parser != null) {
format = parser.parser(dateTime, name, format, add);
}
if (StringUtils.isNotBlank(format)) {
return dateTime.toString(format);
}
return null;
// 内置参数格式:
// ${now}
// ${now, yyyy-MM-dd 00:00:00}
// ${now, yyyy-MM-dd 00:00:00, 1}
// 内置参数说明:
// 参数1、now当前时间 now_d当前天 now_m当前月 dt当前年月日默认yyyyMMdd格式
// 参数2、加减天数负数为减。参数1为 now/now_d 时,按天加减,为 now_m 时按月加减
// 参数3、日期格式yyyy-MM-dd HH:mm:ss
}
public static void main(String[] args) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("day", 4);
String s = fillSqlParam("${now, yyyy-MM-dd 00:00:00, 2}\n dasda", paramMap);
System.out.println(s);
}
}

View File

@@ -0,0 +1,89 @@
/**
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zyplayer.doc.db.framework.db.parser;
import org.apache.ibatis.parsing.TokenHandler;
/**
* 参数预处理类
* @author Clinton Begin
* @author 暮光:城中城
* @since 2019-10-10
*/
public class GenericTokenParser {
private final String openToken;
private final String closeToken;
private final TokenHandler handler;
public GenericTokenParser(String openToken, String closeToken, TokenHandler handler) {
this.openToken = openToken;
this.closeToken = closeToken;
this.handler = handler;
}
public String parse(String text) {
if (text == null || text.isEmpty()) {
return "";
}
int start = text.indexOf(openToken, 0);
if (start == -1) {
return text;
}
char[] src = text.toCharArray();
int offset = 0;
final StringBuilder builder = new StringBuilder();
StringBuilder expression = null;
while (start > -1) {
if (start > 0 && src[start - 1] == '\\') {
builder.append(src, offset, start - offset - 1).append(openToken);
offset = start + openToken.length();
} else {
if (expression == null) {
expression = new StringBuilder();
} else {
expression.setLength(0);
}
builder.append(src, offset, start - offset);
offset = start + openToken.length();
int end = text.indexOf(closeToken, offset);
while (end > -1) {
if (end > offset && src[end - 1] == '\\') {
expression.append(src, offset, end - offset - 1).append(closeToken);
offset = end + closeToken.length();
end = text.indexOf(closeToken, offset);
} else {
expression.append(src, offset, end - offset);
offset = end + closeToken.length();
break;
}
}
if (end == -1) {
builder.append(src, start, src.length - start);
offset = src.length;
} else {
builder.append(handler.handleToken(expression.toString()));
offset = end + closeToken.length();
}
}
start = text.indexOf(openToken, offset);
}
if (offset < src.length) {
builder.append(src, offset, src.length - offset);
}
return builder.toString();
}
}

View File

@@ -1,6 +1,7 @@
package com.zyplayer.doc.db.framework.db.transfer;
import com.zyplayer.doc.db.framework.db.mapper.base.ExecuteParam;
import com.zyplayer.doc.db.framework.db.parser.FillParamUtil;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
@@ -152,8 +153,8 @@ public class SqlParseUtil {
* @return
*/
public static ExecuteParam getSingleExecuteParam(String sql, Map<String, Object> paramMap) {
sql = FillParamUtil.fillSqlParam(sql, paramMap);
ExecuteParam executeParam = new ExecuteParam();
SqlSourceBuilder sqlSourceBuilder = new SqlSourceBuilder(new Configuration());
StaticSqlSource parse = (StaticSqlSource) sqlSourceBuilder.parse(sql, Object.class, paramMap);
BoundSql boundSql = parse.getBoundSql(new Object());

View File

@@ -0,0 +1,71 @@
package com.zyplayer.doc.db.framework.utils;
import org.apache.ibatis.mapping.ParameterMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* SQL日志工具
* @author 暮光:城中城
* @since 2019-08-19
*/
public class SqlLogUtil {
private static final Logger logger = LoggerFactory.getLogger(SqlLogUtil.class);
private static String getParameterValue(Object obj) {
String value;
if (obj instanceof String) {
value = "'" + obj.toString() + "'";
} else if (obj instanceof Number) {
value = obj.toString();
} else if (obj instanceof Date) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
value = "'" + formatter.format(obj) + "'";
} else {
value = (obj != null) ? obj.toString() : "'null'";
}
return value;
}
public static String parseLogSql(String sql, List<ParameterMapping> parameterMappings, List<Object> paramList) {
StringBuilder sqlSb = new StringBuilder(sql.replaceAll("[\\s]+", " "));
int fromIndex = 0;
if (parameterMappings.size() > 0) {
for (int i = 0; i < parameterMappings.size(); i++) {
Object obj = paramList.get(i);
fromIndex = replacePlaceholder(sqlSb, fromIndex, getParameterValue(obj));
}
}
// 最多返回300的长度
// String logSql = sqlSb.toString();
// if (sqlSb.length() > 300) {
// logSql = sqlSb.substring(0, 300) + "...";
// }
// logger.info("sql ==> {}", logSql);
return sqlSb.toString();
}
/**
* 替换?占位符
*
* @param sql
* @param fromIndex
* @param replaceStr
* @return
* @author 暮光:城中城
* @since 2018年10月27日
*/
private static int replacePlaceholder(StringBuilder sql, int fromIndex, String replaceStr) {
int index = sql.indexOf("?", fromIndex);
if (index >= 0) {
sql.replace(index, index + 1, replaceStr);
}
return index + replaceStr.length();
}
}

View File

@@ -1 +1 @@
#app,.el-container,.el-menu{height:100%}.el-header{background-color:#1d4e89!important}.database-list-tree{background-color:#fafafa}.database-list-tree .el-tree-node>.el-tree-node__children{overflow:unset}.el-tree-node__content .el-icon-more{margin-left:5px;color:#606266;font-size:12px;display:none;padding:2px 5px}.el-tree-node__content:hover .el-icon-more{display:inline-block}.login-container{border-radius:5px;-moz-border-radius:5px;background-clip:padding-box;margin:0 auto;width:350px;padding:35px 35px 15px 35px;background:#fff;border:1px solid #eaeaea;-webkit-box-shadow:0 0 25px #cac6c6;box-shadow:0 0 25px #cac6c6}.title{margin:0 auto 40px auto;text-align:center;color:#505458}.remember{margin:0 0 35px 0}.my-info-vue .box-card{margin:10px}.table-info-vue{padding:0 20px}.table-info-vue .el-dialog__body{padding:0 20px 10px}.table-info-vue .el-form-item{margin-bottom:5px}.table-info-vue .edit-table-desc{cursor:pointer;color:#409eff}.table-info-vue .description{cursor:pointer;min-height:23px}.table-info-vue .el-table td,.table-info-vue .el-table th{padding:5px 0}.table-info-vue .status-info-row{padding:8px 0}.table-info-vue .status-info-row .label{width:80px;display:inline-block;text-align:right;color:#606266}.table-database-vue .el-table td,.table-database-vue .el-table th{padding:5px 0}.table-database-vue .label{width:140px;text-align:right}.table-database-vue .el-table th,.table-procedure-edit-vue .el-table td,.table-procedure-vue .el-table td{padding:5px 0}body,html{margin:0;padding:0;height:100%}.header-right-user-name{color:#fff;padding-right:5px}.el-menu-vertical{border-right:0}.el-menu-vertical,.el-menu-vertical .el-menu{background:#fafafa}.el-header{background-color:#409eff;color:#333;line-height:40px;text-align:right;height:40px!important}.data-executor-vue .ace-monokai .ace_print-margin{display:none}.data-executor-vue .el-card__body{padding:10px}.data-executor-vue .el-table td,.el-table th{padding:6px 0}.data-executor-vue .execute-result-table .el-input__inner{height:25px;line-height:25px;padding:0 5px}.data-executor-vue .execute-result-table .el-textarea__inner{height:27px;min-height:27px;line-height:25px;padding:0 5px;resize:none}.data-executor-vue .execute-use-time{font-size:12px;margin-right:10px}.data-executor-vue-out .el-tabs__nav-scroll{padding-left:20px}.data-executor-vue-out .el-button+.el-button{margin-left:0}.data-executor-vue-out .el-table__body-wrapper{height:calc(100vh - 180px);overflow-y:auto}.data-transfer-vue .el-button+.el-button{margin-left:4px}
#app,.el-container,.el-menu{height:100%}.el-header{background-color:#1d4e89!important}.database-list-tree{background-color:#fafafa}.database-list-tree .el-tree-node>.el-tree-node__children{overflow:unset}.el-tree-node__content .el-icon-more{margin-left:5px;color:#606266;font-size:12px;display:none;padding:2px 5px}.el-tree-node__content:hover .el-icon-more{display:inline-block}.login-container{border-radius:5px;-moz-border-radius:5px;background-clip:padding-box;margin:0 auto;width:350px;padding:35px 35px 15px 35px;background:#fff;border:1px solid #eaeaea;-webkit-box-shadow:0 0 25px #cac6c6;box-shadow:0 0 25px #cac6c6}.title{margin:0 auto 40px auto;text-align:center;color:#505458}.remember{margin:0 0 35px 0}.my-info-vue .box-card{margin:10px}.table-info-vue{padding:0 20px}.table-info-vue .el-dialog__body{padding:0 20px 10px}.table-info-vue .el-form-item{margin-bottom:5px}.table-info-vue .edit-table-desc{cursor:pointer;color:#409eff}.table-info-vue .description{cursor:pointer;min-height:23px}.table-info-vue .el-table td,.table-info-vue .el-table th{padding:5px 0}.table-info-vue .status-info-row{padding:8px 0}.table-info-vue .status-info-row .label{width:80px;display:inline-block;text-align:right;color:#606266}.table-database-vue .el-table td,.table-database-vue .el-table th{padding:5px 0}.table-database-vue .label{width:140px;text-align:right}.table-database-vue .el-table th,.table-procedure-edit-vue .el-table td,.table-procedure-vue .el-table td{padding:5px 0}body,html{margin:0;padding:0;height:100%}.header-right-user-name{color:#fff;padding-right:5px}.el-menu-vertical{border-right:0}.el-menu-vertical,.el-menu-vertical .el-menu{background:#fafafa}.el-header{background-color:#409eff;color:#333;line-height:40px;text-align:right;height:40px!important}.data-executor-vue .ace-monokai .ace_print-margin{display:none}.data-executor-vue .el-card__body{padding:10px}.data-executor-vue .sql-params .el-input-group{width:auto;margin:10px 10px 0 0}.data-executor-vue .sql-params .el-input__inner{width:200px}.data-executor-vue .el-table td,.el-table th{padding:6px 0}.data-executor-vue .execute-result-table .el-input__inner{height:25px;line-height:25px;padding:0 5px}.data-executor-vue .execute-result-table .el-textarea__inner{height:27px;min-height:27px;line-height:25px;padding:0 5px;resize:none}.data-executor-vue .execute-use-time{font-size:12px;margin-right:10px}.data-executor-vue-out .el-tabs__nav-scroll{padding-left:20px}.data-executor-vue-out .el-button+.el-button{margin-left:0}.data-executor-vue-out .el-table__body-wrapper{height:calc(100vh - 180px);overflow-y:auto}.data-transfer-vue .el-button+.el-button{margin-left:4px}

View File

@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.f232fb4e.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.1c02b763.js rel=preload as=script><link href=js/chunk-vendors.22b87709.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.f232fb4e.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.22b87709.js></script><script src=js/app.1c02b763.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/app.1fc1ba16.css rel=preload as=style><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=js/app.53122d91.js rel=preload as=script><link href=js/chunk-vendors.22b87709.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/app.1fc1ba16.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.22b87709.js></script><script src=js/app.53122d91.js></script></body></html>

View File

@@ -1902,7 +1902,7 @@
},
"asn1.js": {
"version": "4.10.1",
"resolved": "https://registry.npm.taobao.org/asn1.js/download/asn1.js-4.10.1.tgz",
"resolved": "http://registry.npm.taobao.org/asn1.js/download/asn1.js-4.10.1.tgz",
"integrity": "sha1-ucK/WAXx5kqt7tbfOiv6+1pz9aA=",
"dev": true,
"requires": {
@@ -1923,7 +1923,7 @@
"dependencies": {
"inherits": {
"version": "2.0.1",
"resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Finherits%2Fdownload%2Finherits-2.0.1.tgz",
"resolved": "http://registry.npm.taobao.org/inherits/download/inherits-2.0.1.tgz",
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=",
"dev": true
},
@@ -2065,7 +2065,7 @@
},
"babel-helper-vue-jsx-merge-props": {
"version": "2.0.3",
"resolved": "https://registry.npm.taobao.org/babel-helper-vue-jsx-merge-props/download/babel-helper-vue-jsx-merge-props-2.0.3.tgz",
"resolved": "http://registry.npm.taobao.org/babel-helper-vue-jsx-merge-props/download/babel-helper-vue-jsx-merge-props-2.0.3.tgz",
"integrity": "sha1-Iq69OzOQIyjlEyk6jkmSs4T58bY="
},
"babel-loader": {
@@ -2104,7 +2104,7 @@
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz",
"resolved": "http://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"requires": {
"core-js": "^2.4.0",
@@ -2237,7 +2237,7 @@
},
"bn.js": {
"version": "4.11.8",
"resolved": "https://registry.npm.taobao.org/bn.js/download/bn.js-4.11.8.tgz",
"resolved": "http://registry.npm.taobao.org/bn.js/download/bn.js-4.11.8.tgz",
"integrity": "sha1-LN4J617jQfSEdGuwMJsyU7GxRC8=",
"dev": true
},
@@ -3020,7 +3020,7 @@
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-1.9.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcolor-convert%2Fdownload%2Fcolor-convert-1.9.3.tgz",
"resolved": "http://registry.npm.taobao.org/color-convert/download/color-convert-1.9.3.tgz",
"integrity": "sha1-u3GFBpDh8TZWfeYp0tVHHe2kweg=",
"dev": true,
"requires": {
@@ -3672,7 +3672,7 @@
},
"deepmerge": {
"version": "1.5.2",
"resolved": "https://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz?cache=0&sync_timestamp=1572279812893&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdeepmerge%2Fdownload%2Fdeepmerge-1.5.2.tgz",
"resolved": "https://registry.npm.taobao.org/deepmerge/download/deepmerge-1.5.2.tgz",
"integrity": "sha1-EEmdhohEza1P7ghC34x/bwyVp1M="
},
"default-gateway": {
@@ -4027,19 +4027,19 @@
},
"domain-browser": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/domain-browser/download/domain-browser-1.2.0.tgz?cache=0&sync_timestamp=1574051269386&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdomain-browser%2Fdownload%2Fdomain-browser-1.2.0.tgz",
"resolved": "http://registry.npm.taobao.org/domain-browser/download/domain-browser-1.2.0.tgz",
"integrity": "sha1-PTH1AZGmdJ3RN1p/Ui6CPULlTto=",
"dev": true
},
"domelementtype": {
"version": "1.3.1",
"resolved": "https://registry.npm.taobao.org/domelementtype/download/domelementtype-1.3.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdomelementtype%2Fdownload%2Fdomelementtype-1.3.1.tgz",
"resolved": "http://registry.npm.taobao.org/domelementtype/download/domelementtype-1.3.1.tgz",
"integrity": "sha1-0EjESzew0Qp/Kj1f7j9DM9eQSB8=",
"dev": true
},
"domhandler": {
"version": "2.4.2",
"resolved": "https://registry.npm.taobao.org/domhandler/download/domhandler-2.4.2.tgz",
"resolved": "http://registry.npm.taobao.org/domhandler/download/domhandler-2.4.2.tgz",
"integrity": "sha1-iAUJfpM9ZehVRvcm1g9euItE+AM=",
"dev": true,
"requires": {
@@ -4178,7 +4178,7 @@
},
"emojis-list": {
"version": "2.1.0",
"resolved": "https://registry.npm.taobao.org/emojis-list/download/emojis-list-2.1.0.tgz",
"resolved": "http://registry.npm.taobao.org/emojis-list/download/emojis-list-2.1.0.tgz",
"integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=",
"dev": true
},
@@ -4666,7 +4666,7 @@
},
"faye-websocket": {
"version": "0.10.0",
"resolved": "https://registry.npm.taobao.org/faye-websocket/download/faye-websocket-0.10.0.tgz",
"resolved": "http://registry.npm.taobao.org/faye-websocket/download/faye-websocket-0.10.0.tgz",
"integrity": "sha1-TkkvjQTftviQA1B/btvy1QHnxvQ=",
"dev": true,
"requires": {
@@ -5531,7 +5531,7 @@
},
"glob-parent": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/glob-parent/download/glob-parent-3.1.0.tgz?cache=0&sync_timestamp=1569136652060&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglob-parent%2Fdownload%2Fglob-parent-3.1.0.tgz",
"resolved": "https://registry.npm.taobao.org/glob-parent/download/glob-parent-3.1.0.tgz",
"integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=",
"dev": true,
"requires": {
@@ -5635,7 +5635,7 @@
},
"has-ansi": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/has-ansi/download/has-ansi-2.0.0.tgz",
"resolved": "http://registry.npm.taobao.org/has-ansi/download/has-ansi-2.0.0.tgz",
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
"dev": true,
"requires": {
@@ -5706,7 +5706,7 @@
},
"hash-sum": {
"version": "1.0.2",
"resolved": "https://registry.npm.taobao.org/hash-sum/download/hash-sum-1.0.2.tgz",
"resolved": "http://registry.npm.taobao.org/hash-sum/download/hash-sum-1.0.2.tgz",
"integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=",
"dev": true
},
@@ -5868,7 +5868,7 @@
},
"htmlparser2": {
"version": "3.10.1",
"resolved": "https://registry.npm.taobao.org/htmlparser2/download/htmlparser2-3.10.1.tgz",
"resolved": "http://registry.npm.taobao.org/htmlparser2/download/htmlparser2-3.10.1.tgz",
"integrity": "sha1-vWedw/WYl7ajS7EHSchVu1OpOS8=",
"dev": true,
"requires": {
@@ -5945,7 +5945,7 @@
},
"http-proxy-middleware": {
"version": "0.19.1",
"resolved": "https://registry.npm.taobao.org/http-proxy-middleware/download/http-proxy-middleware-0.19.1.tgz",
"resolved": "http://registry.npm.taobao.org/http-proxy-middleware/download/http-proxy-middleware-0.19.1.tgz",
"integrity": "sha1-GDx9xKoUeRUDBkmMIQza+WCApDo=",
"dev": true,
"requires": {
@@ -6154,13 +6154,13 @@
},
"ipaddr.js": {
"version": "1.9.0",
"resolved": "https://registry.npm.taobao.org/ipaddr.js/download/ipaddr.js-1.9.0.tgz",
"resolved": "http://registry.npm.taobao.org/ipaddr.js/download/ipaddr.js-1.9.0.tgz",
"integrity": "sha1-N9905DCg5HVQ/lSi3v4w2KzZX2U=",
"dev": true
},
"is-absolute-url": {
"version": "2.1.0",
"resolved": "https://registry.npm.taobao.org/is-absolute-url/download/is-absolute-url-2.1.0.tgz?cache=0&sync_timestamp=1569736493122&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-absolute-url%2Fdownload%2Fis-absolute-url-2.1.0.tgz",
"resolved": "https://registry.npm.taobao.org/is-absolute-url/download/is-absolute-url-2.1.0.tgz",
"integrity": "sha1-UFMN+4T8yap9vnhS6Do3uTufKqY=",
"dev": true
},
@@ -6207,7 +6207,7 @@
},
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npm.taobao.org/is-buffer/download/is-buffer-1.1.6.tgz?cache=0&sync_timestamp=1569905495687&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-buffer%2Fdownload%2Fis-buffer-1.1.6.tgz",
"resolved": "http://registry.npm.taobao.org/is-buffer/download/is-buffer-1.1.6.tgz",
"integrity": "sha1-76ouqdqg16suoTqXsritUf776L4=",
"dev": true
},
@@ -6432,7 +6432,7 @@
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz?cache=0&sync_timestamp=1562592096220&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fisarray%2Fdownload%2Fisarray-1.0.0.tgz",
"resolved": "http://registry.npm.taobao.org/isarray/download/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true
},
@@ -7048,7 +7048,7 @@
},
"memory-fs": {
"version": "0.4.1",
"resolved": "https://registry.npm.taobao.org/memory-fs/download/memory-fs-0.4.1.tgz?cache=0&sync_timestamp=1570537491040&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmemory-fs%2Fdownload%2Fmemory-fs-0.4.1.tgz",
"resolved": "http://registry.npm.taobao.org/memory-fs/download/memory-fs-0.4.1.tgz",
"integrity": "sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=",
"dev": true,
"requires": {
@@ -7528,7 +7528,7 @@
},
"normalize-wheel": {
"version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz",
"resolved": "https://registry.npm.taobao.org/normalize-wheel/download/normalize-wheel-1.0.1.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnormalize-wheel%2Fdownload%2Fnormalize-wheel-1.0.1.tgz",
"integrity": "sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU="
},
"npm-run-path": {
@@ -7802,7 +7802,7 @@
},
"p-limit": {
"version": "1.3.0",
"resolved": "https://registry.npm.taobao.org/p-limit/download/p-limit-1.3.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fp-limit%2Fdownload%2Fp-limit-1.3.0.tgz",
"resolved": "http://registry.npm.taobao.org/p-limit/download/p-limit-1.3.0.tgz",
"integrity": "sha1-uGvV8MJWkJEcdZD8v8IBDVSzzLg=",
"dev": true,
"requires": {
@@ -7915,7 +7915,7 @@
},
"pascalcase": {
"version": "0.1.1",
"resolved": "https://registry.npm.taobao.org/pascalcase/download/pascalcase-0.1.1.tgz",
"resolved": "http://registry.npm.taobao.org/pascalcase/download/pascalcase-0.1.1.tgz",
"integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=",
"dev": true
},
@@ -7963,7 +7963,7 @@
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-0.1.7.tgz?cache=0&sync_timestamp=1574278262588&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fpath-to-regexp%2Fdownload%2Fpath-to-regexp-0.1.7.tgz",
"resolved": "http://registry.npm.taobao.org/path-to-regexp/download/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=",
"dev": true
},
@@ -8591,7 +8591,7 @@
},
"postcss-value-parser": {
"version": "3.3.1",
"resolved": "https://registry.npm.taobao.org/postcss-value-parser/download/postcss-value-parser-3.3.1.tgz",
"resolved": "http://registry.npm.taobao.org/postcss-value-parser/download/postcss-value-parser-3.3.1.tgz",
"integrity": "sha1-n/giVH4okyE88cMO+lGsX9G6goE=",
"dev": true
},
@@ -8835,13 +8835,13 @@
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz",
"resolved": "https://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fqs%2Fdownload%2Fqs-6.5.2.tgz",
"integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY=",
"dev": true
},
"query-string": {
"version": "4.3.4",
"resolved": "https://registry.npm.taobao.org/query-string/download/query-string-4.3.4.tgz?cache=0&sync_timestamp=1573620418700&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fquery-string%2Fdownload%2Fquery-string-4.3.4.tgz",
"resolved": "https://registry.npm.taobao.org/query-string/download/query-string-4.3.4.tgz",
"integrity": "sha1-u7aTucqRXCMlFbIosaArYJBD2+s=",
"dev": true,
"requires": {
@@ -8947,7 +8947,7 @@
},
"readdirp": {
"version": "2.2.1",
"resolved": "https://registry.npm.taobao.org/readdirp/download/readdirp-2.2.1.tgz?cache=0&sync_timestamp=1571011714883&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freaddirp%2Fdownload%2Freaddirp-2.2.1.tgz",
"resolved": "https://registry.npm.taobao.org/readdirp/download/readdirp-2.2.1.tgz",
"integrity": "sha1-DodiKjMlqjPokihcr4tOhGUppSU=",
"dev": true,
"requires": {
@@ -9295,12 +9295,12 @@
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz?cache=0&sync_timestamp=1562377642757&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsafe-buffer%2Fdownload%2Fsafe-buffer-5.1.2.tgz",
"resolved": "http://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz",
"integrity": "sha1-mR7GnSluAxN0fVm9/St0XDX4go0="
},
"safe-regex": {
"version": "1.1.0",
"resolved": "https://registry.npm.taobao.org/safe-regex/download/safe-regex-1.1.0.tgz?cache=0&sync_timestamp=1571687334026&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsafe-regex%2Fdownload%2Fsafe-regex-1.1.0.tgz",
"resolved": "http://registry.npm.taobao.org/safe-regex/download/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true,
"requires": {
@@ -10000,7 +10000,7 @@
},
"stream-http": {
"version": "2.8.3",
"resolved": "https://registry.npm.taobao.org/stream-http/download/stream-http-2.8.3.tgz",
"resolved": "http://registry.npm.taobao.org/stream-http/download/stream-http-2.8.3.tgz",
"integrity": "sha1-stJCRpKIpaJ+xP6JM6z2I95lFPw=",
"dev": true,
"requires": {
@@ -10458,7 +10458,7 @@
"dependencies": {
"commander": {
"version": "2.19.0",
"resolved": "https://registry.npm.taobao.org/commander/download/commander-2.19.0.tgz?cache=0&sync_timestamp=1573464045808&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.19.0.tgz",
"resolved": "https://registry.npm.taobao.org/commander/download/commander-2.19.0.tgz",
"integrity": "sha1-9hmKqE5bg8RgVLlN3tv+1e6f8So=",
"dev": true
},
@@ -10867,7 +10867,7 @@
},
"wangeditor": {
"version": "3.1.1",
"resolved": "http://registry.npm.taobao.org/wangeditor/download/wangeditor-3.1.1.tgz",
"resolved": "https://registry.npm.taobao.org/wangeditor/download/wangeditor-3.1.1.tgz",
"integrity": "sha1-+9PB1JdpI8nt67hbKdMLNVEq0Dk="
},
"watchpack": {

View File

@@ -10,13 +10,7 @@
</el-tooltip>
<el-button icon="el-icon-brush" size="small" @click="formatterSql">SQL美化</el-button>
<el-button v-on:click="addFavorite('')" plain size="small" icon="el-icon-star-off">收藏</el-button>
<el-button v-on:click="loadHistoryAndFavoriteList" plain size="small" icon="el-icon-tickets">收藏及历史</el-button>
<div style="float: right;">
<!-- 增加了选择数据库后分组加上就太长了先去掉感觉用处不大 -->
<!-- <el-select v-model="choiceDatasourceGroup" @change="sourceGroupChangeEvents" size="small" filterable placeholder="请先选择分组" style="width: 200px;">-->
<!-- <el-option value="" label="全部分组"></el-option>-->
<!-- <el-option v-for="item in datasourceGroupList" :key="item" :value="item"></el-option>-->
<!-- </el-select>-->
<el-select v-model="choiceDatasourceId" @change="datasourceChangeEvents" size="small" filterable placeholder="请选择数据源" style="width: 300px;margin-left: 10px;">
<el-option v-for="item in datasourceOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
@@ -25,11 +19,14 @@
</el-select>
</div>
</div>
<div v-if="sqlParams.length > 0" class="sql-params">
<el-input :placeholder="'请输入'+param.key+'的值'" v-model="param.value" v-for="param in sqlParams">
<template slot="prepend">{{param.key}}</template>
</el-input>
</div>
</el-card>
<el-card>
<div v-if="!!executeError" style="color: #f00;">{{executeError}}</div>
<div v-else-if="executeResultList.length <= 0" v-loading="sqlExecuting">暂无数据</div>
<div v-else style="position: relative;">
<div style="position: relative;">
<div style="position: absolute;right: 0;z-index: 1;">
<!-- 复制选中行 -->
<el-dropdown @command="handleCopyCheckLineCommand" v-show="this.choiceResultObj[this.executeShowTable] && this.choiceResultObj[this.executeShowTable].length > 0">
@@ -44,9 +41,45 @@
</el-dropdown>
</div>
<el-tabs v-model="executeShowTable">
<el-tab-pane label="信息" name="table0">
<el-tab-pane label="执行历史" name="tabHistory">
<el-table :data="myHistoryListList" stripe border style="width: 100%; margin-bottom: 5px;">
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
<el-table-column prop="content" label="SQL">
<template slot-scope="scope">
<pre style="margin: 0;" @dblclick="inputFavoriteSql(scope.row.content)">{{scope.row.content}}</pre>
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button size="mini" type="primary" @click="inputFavoriteSql(scope.row.content)">输入</el-button>
<el-button size="mini" type="success" @click="addFavorite(scope.row.content)" style="margin-left: 10px;">收藏</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="我的收藏" name="tabFavorite">
<el-table :data="myFavoriteList" stripe border style="width: 100%; margin-bottom: 5px;" v-infinite-scroll>
<el-table-column prop="createTime" label="执行时间" width="160px"></el-table-column>
<el-table-column prop="content" label="SQL">
<template slot-scope="scope">
<pre style="margin: 0;" @dblclick="inputFavoriteSql(scope.row.content)">{{scope.row.content}}</pre>
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)" style="margin-left: 10px;">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="信息" name="tabInfo" v-if="!!executeResultInfo">
<pre>{{executeResultInfo}}</pre>
</el-tab-pane>
<el-tab-pane label="错误" name="tabError" v-if="!!executeError">
<div style="color: #f00;">{{executeError}}</div>
</el-tab-pane>
<template v-else>
<el-tab-pane :label="'结果'+resultItem.index" :name="resultItem.name" v-for="resultItem in executeResultList" v-if="!!resultItem.index">
<div v-if="!!resultItem.errMsg" style="color: #f00;">{{resultItem.errMsg}}</div>
<div v-else-if="resultItem.dataList.length <= 0" style="text-align: center; color: #aaa; padding: 20px 0;">暂无数据</div>
@@ -61,46 +94,11 @@
</el-table-column>
</el-table>
</el-tab-pane>
</template>
</el-tabs>
</div>
</el-card>
</div>
<el-drawer title="收藏及历史" :visible.sync="historyDrawerVisible" size="50%" class="data-executor-vue-out">
<div style="padding: 10px;">
<el-tabs value="favorite">
<el-tab-pane label="我的收藏" name="favorite">
<el-table :data="myFavoriteList" stripe border style="width: 100%; margin-bottom: 5px;" v-infinite-scroll>
<el-table-column prop="content" label="SQL">
<template slot-scope="scope">
<pre style="margin: 0;">{{scope.row.content}}</pre>
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
<el-button size="mini" type="danger" v-on:click="delFavorite(scope.row)" style="margin-left: 10px;">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="历史记录" name="history">
<el-table :data="myHistoryListList" stripe border style="width: 100%; margin-bottom: 5px;">
<el-table-column prop="content" label="SQL">
<template slot-scope="scope">
<pre style="margin: 0;">{{scope.row.content}}</pre>
</template>
</el-table-column>
<el-table-column label="操作" width="160px">
<template slot-scope="scope">
<el-button size="mini" type="primary" v-on:click="inputFavoriteSql(scope.row.content)">输入</el-button>
<el-button size="mini" type="success" v-on:click="addFavorite(scope.row.content)" style="margin-left: 10px;">收藏</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
</el-tabs>
</div>
</el-drawer>
<!--选择导出为update的条件列弹窗-->
<el-dialog :visible.sync="exportConditionVisible" width="500px" title="选择更新语句条件">
<div>
@@ -123,6 +121,7 @@
import sqlFormatter from "sql-formatter"
import datasourceApi from '../../common/api/datasource'
import aceEditor from "../../common/lib/ace-editor";
import sqlParser from "./parser/SqlParser";
export default {
data() {
@@ -143,12 +142,11 @@
sqlExecuting: false,
executeResultList: [],
executeResultInfo: "",
executeShowTable: "table1",
executeShowTable: "tabHistory",
sqlExecutorEditor: {},
nowExecutorId: 1,
executeError: "",
// 收藏及历史
historyDrawerVisible: false,
myFavoriteList: [],
myHistoryListList: [],
// 选择复制
@@ -169,6 +167,10 @@
maxLines: 40,
},
executorSource: {},
// sql参数
sqlParams: [],
sqlParamWaiting: false,
sqlParamHistory: {},
}
},
components: {
@@ -189,6 +191,22 @@
that.doExecutorSql();
}
});
editor.on('change', () => {
if (!this.sqlParamWaiting) {
this.sqlParamWaiting = true;
setTimeout(() => {
let content = editor.getValue();
let paramArr = sqlParser.parserArr(content, [
{start: '${', end: '}'}, {start: '#{', end: '}'}
]);
this.sqlParams = [];
paramArr.forEach(item => {
this.sqlParams.push({key: item, value: this.sqlParamHistory[item] || ''});
});
this.sqlParamWaiting = false;
}, 1000);
}
});
},
cancelExecutorSql() {
datasourceApi.executeSqlCancel({executeId: this.nowExecutorId}).then(() => {
@@ -196,7 +214,6 @@
});
},
loadHistoryAndFavoriteList() {
this.historyDrawerVisible = true;
this.loadHistoryList();
this.loadFavoriteList();
},
@@ -231,7 +248,6 @@
},
inputFavoriteSql(content) {
this.sqlExecutorEditor.setValue(content, 1);
this.historyDrawerVisible = false;
},
formatterSql() {
let dataSql = this.sqlExecutorEditor.getSelectedText();
@@ -255,9 +271,15 @@
this.executeError = "";
this.executeUseTime = "";
this.executeResultList = [];
let sqlParamObj = {};
this.sqlParams.forEach(item => {
if (!!item.value) {
sqlParamObj[item.key] = item.value;
this.sqlParamHistory[item.key] = item.value;
}
});
this.nowExecutorId = (new Date()).getTime() + Math.ceil(Math.random() * 1000);
var sqlValue = this.sqlExecutorEditor.getSelectedText();
let sqlValue = this.sqlExecutorEditor.getSelectedText();
if (!sqlValue) {
sqlValue = this.sqlExecutorEditor.getValue();
}
@@ -267,30 +289,31 @@
dbName: this.choiceDatabase,
executeId: this.nowExecutorId,
sql: sqlValue,
params: '',
params: JSON.stringify(sqlParamObj),
}).then(json => {
this.sqlExecuting = false;
if (json.errCode != 200) {
this.executeError = json.errMsg;
return;
}
var resultList = json.data || [];
var executeResultList = [];
var executeResultInfo = "", itemIndex = 1;
for (var i = 0; i < resultList.length; i++) {
var objItem = JSON.parse(resultList[i]);
let resultList = json.data || [];
let executeResultList = [];
let executeResultInfo = "", itemIndex = 1;
for (let i = 0; i < resultList.length; i++) {
let objItem = JSON.parse(resultList[i]);
executeResultInfo += this.getExecuteInfoStr(objItem);
var resultItem = this.dealExecuteResult(objItem);
let resultItem = this.dealExecuteResult(objItem);
if (resultItem.updateCount < 0) {
resultItem.index = itemIndex;
resultItem.name = 'table' + itemIndex;
resultItem.name = 'tab' + itemIndex;
itemIndex++;
}
executeResultList.push(resultItem);
}
this.executeShowTable = (itemIndex === 1) ? "table0" : "table1";
this.executeShowTable = (itemIndex === 1) ? "tabInfo" : "tab1";
this.executeResultInfo = executeResultInfo;
this.executeResultList = executeResultList;
this.loadHistoryList();
});
},
loadDatasourceList() {
@@ -305,6 +328,7 @@
this.executorSource = {sourceId: this.choiceDatasourceId};
this.loadDatabaseList();
this.loadSourceBaseInfo();
this.loadHistoryAndFavoriteList();
}
});
},
@@ -340,12 +364,14 @@
this.executorSource = {sourceId: this.choiceDatasourceId};
this.loadDatabaseList();
this.loadSourceBaseInfo();
this.loadHistoryAndFavoriteList();
}
},
datasourceChangeEvents() {
this.executorSource = {sourceId: this.choiceDatasourceId};
this.loadDatabaseList();
this.loadSourceBaseInfo();
this.loadHistoryAndFavoriteList();
},
databaseChangeEvents() {
this.executorSource = {sourceId: this.choiceDatasourceId, dbName: this.choiceDatabase};
@@ -429,6 +455,14 @@
.data-executor-vue .el-card__body{
padding: 10px;
}
.data-executor-vue .sql-params{
}
.data-executor-vue .sql-params .el-input-group{
width: auto;margin: 10px 10px 0 0;
}
.data-executor-vue .sql-params .el-input__inner{
width: 200px;
}
.data-executor-vue .el-table td, .el-table th{
padding: 6px 0;
}

View File

@@ -0,0 +1,64 @@
/**
* 从字符串中找到以开始和结束字符包含的字符串数组
* @author 暮光:城中城
* @param text 待查找字符串
* @param openToken 开始符号
* @param closeToken 结束符号
* @returns {[]} 结果
*/
export default {
parser(text, openToken, closeToken) {
let expressionArr = [];
if (!text) {
return expressionArr;
}
let start = text.indexOf(openToken, 0);
if (start == -1) {
return expressionArr;
}
let offset = 0;
let expression = '';
while (start > -1) {
if (start > 0 && text[start - 1] == '\\') {
offset = start + openToken.length;
} else {
expression = '';
offset = start + openToken.length;
let end = text.indexOf(closeToken, offset);
while (end > -1) {
if (end > offset && text[end - 1] == '\\') {
expression += text.substr(offset, end - offset - 1);
offset = end + closeToken.length;
end = text.indexOf(closeToken, offset);
} else {
expression += text.substr(offset, end - offset);
offset = end + closeToken.length;
break;
}
}
if (end == -1) {
offset = text.length;
} else {
if (!!expression) {
expressionArr.push(expression);
}
offset = end + closeToken.length;
}
}
start = text.indexOf(openToken, offset);
}
return expressionArr;
},
parserArr(text, rules) {
let expressionObj = {};
rules.forEach(rule => {
let expression = this.parser(text, rule.start, rule.end);
expression.forEach(item => expressionObj[item] = 1);
});
let expressionArr = [];
for (let key in expressionObj) {
expressionArr.push(key);
}
return expressionArr;
}
}