用于转换Sql的一个小工具
程序员文章站
2022-05-26 14:05:48
...
因为要在java中写大量的经过格式化后的sql脚本, 于是写了一个小工具, 用来将sql脚本转换成java中的字符串
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Resolve SQL </title>
</head>
<script language="JavaScript">
<!--
function simpleParse(){
// 做替换操作
var rgexp = new RegExp("^(.)","mg");
sql.value = sql.value.replace(rgexp, "sql.append(\"$1");
sql.value = sql.value.replace(/(.)\r/g, "$1\");\r");
sql.value = sql.value + "\");";
//sql.value = "sql = new SqlBuilder();\n" + sql.value;
copyAll();
}
function parseAddNewSqlBuilder(){
// 做替换操作
var rgexp = new RegExp("^(.)","mg");
sql.value = sql.value.replace(rgexp, "sql.append(\"$1");
sql.value = sql.value.replace(/(.)\r/g, "$1\");\r");
sql.value = sql.value + "\");";
sql.value = "StringBuffer sql = new StringBuffer();\n" + sql.value;
copyAll();
}
function unparse(){
sql.value = sql.value.replace(/^ *sql.append\(\"/mg, "");
sql.value +="\n";
sql.value = sql.value.replace(/\"\);\r/g, "");
copyAll();
}
function copyAll(){
// copy格式化后的东东
sql.select();
sql.createTextRange().execCommand("Copy");
}
//-->
</script>
<body>
<div style='text-align:center;'><textarea id="sql" rows="30" cols="150"></textarea></div>
<div style='text-align:center;'><button onclick = 'sql.select();sql.value = "";sql.createTextRange().execCommand("Paste")' style='width:100'>Paste</button>
<button onclick = 'simpleParse()' style='width:200'>Simple Parse SQL</button> <button onclick = 'parseAddNewSqlBuilder()' style='width:200'>Parse Add New SqlBuilder</button>
<button onclick = 'unparse()' style='width:100'>Unparse SQL</button></div>
</body>
</html>