Ai
5 Star 13 Fork 5

快鸟/tiny-apps

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sqlTransferTool.html 2.84 KB
一键复制 编辑 原始数据 按行查看 历史
zhiyuan 提交于 2017-07-06 14:11 +08:00 . sqltransfertool
<html>
<head>
<title>sqlTransferTool</title>
<style>
.area {width:500px;height:300px;}
</style>
</head>
<body>
<div style="float:left;"><textarea id="origin" class="area"></textarea></div>
<div style="float:left;"><input type="button" value="Transfer" onclick="transfer();"/></div>
<div style="float:left;"><textarea id="result" class="area"></textarea></div>
<pre style="float:left;">
<div><p>示例:</p></div>
<div style="border:red solid 1px;">
select
product_code, product_name, product_title, product_status, product_type,
face_value, dividend_method, min_customer_num, max_customer_num, market_start_date,
market_end_date, found_date, first_interest_date, life_cycle, life_cycle_unit, expect_end_date,
product_category, currency_type, product_source, tail_mode, vol_precision, subs_type,
year_days, check_status, create_user_id, create_user_name, create_time, update_user_id,
update_user_name, update_time
from tf_product
where product_code = #{productCode,jdbcType=VARCHAR}
</div>
</pre>
</body>
<script>
function transfer(){
var origin = document.getElementById("origin").value;
var prefix = "";
var suffix = "";
// 将select 去掉
if(origin.indexOf("select") != -1 || origin.indexOf("SELECT") != -1){
origin = origin.replace("select", "");
origin = origin.replace("SELECT", "");
prefix = origin.indexOf("select") != -1 ? "select" : "SELECT";
}
// 将from 后面的去掉
if(origin.indexOf("from") != -1 || origin.indexOf("FROM") != -1){
var p = origin.indexOf("from") != -1 ? origin.indexOf("from") : origin.indexOf("FROM");
suffix = origin.substr(p);
origin = origin.substr(0, p);
//console.log("suffix=" + suffix);
//console.log("after clean=" + origin);
}
//console.log(origin);
var sqlSnaps = origin.split(",");
//console.log(sqlSnaps);
var result = ""; // 转换结果
for(var index in sqlSnaps){
result += handleColumn(sqlSnaps[index]);
if(index != sqlSnaps.length - 1) result += ",";
}
result = prefix + result + suffix;
document.getElementById("result").value = result;
}
function handleColumn(columnStr){
var handleRlt = ""; // 处理结果
var t_colum_arr = columnStr.split(".");
if(t_colum_arr.length == 1){
handleRlt += columnStr.replace(/([a-zA-Z]+_?)+[a-zA-Z]+/, function(word){
return doTransfer(word);
});
} else if(t_colum_arr.length == 2){
handleRlt += t_colum_arr[0] + "." + t_colum_arr[1].replace(/([a-zA-Z]+_?)+[a-zA-Z]+/, function(word){
return doTransfer(word);
});
} else {
alert("sql异常:" + columnStr);
}
return handleRlt;
}
function doTransfer(word){
var rlt = "";
var arr = word.split("_");
for(var i=0; i<arr.length; i++){
if(i==0){rlt=arr[0];continue;}
rlt += arr[i].charAt(0).toUpperCase() + arr[i].substr(1);
}
return word + " as " + rlt;
}
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kkk001/tiny-apps.git
git@gitee.com:kkk001/tiny-apps.git
kkk001
tiny-apps
tiny-apps
master

搜索帮助