Home  >  Article  >  Web Front-end  >  Javascript makes a small tool for converting sql to stringBuffer_javascript skills

Javascript makes a small tool for converting sql to stringBuffer_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:05:511436browse

A small tool for converting sql to stringBuffer. Splicing sql at the dao layer is very troublesome. You can use this small tool to quickly splice the sql. Format the written sql in the sql tool and then copy it in.

Demo address: http://runjs.cn/detail/fj14tpyu It’s a bit ugly, it is recommended to view it in full screen, but you can download it and modify it yourself

Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>change SQL</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
 
<script>
  var ie = !-[1,];  
  function changeSQL(){
    var srcSQL = document.getElementById("srcSQL");
    var srcInner = srcSQL.value;
    var sqlBuf = "sqlBuf"
    var BufObj = "StringBuffer sqlBuf = new StringBuffer();"
    var newSrc = "";
    if(ie){
      var newSrc = srcInner.split("\r\n");
    }else{
      var patt = new RegExp(/.+/g);
      var newSrc = srcInner.match(patt);
    }
    var len = newSrc.length;
    for(var i=0;i<len;i++){
      var temp=newSrc[i];
      if(i < len-1){
      sqlBuf += ".append(\" " + temp + " \")" + "\r\n";
      }
      if(i == len-1){
      sqlBuf += ".append(\" " + temp + " \");";
      }
    }
     
    var showSQL = document.getElementById("showSQL");
    showSQL.innerText = BufObj + "\n" + sqlBuf;
  }
   
   
</script>
</HEAD>
<BODY>
<table border="1" width="100%" >
  <tr align="center">
    <td width="45%"><textarea id="srcSQL" rows="40" cols="85" ></textarea></td>
    <td>
      <button onclick="changeSQL()" style="cursor:hand;"><font color="blue" size="5"><b>转换</b></button><p>
       
    </td>
    <td width="45%"><textarea id="showSQL" rows="40" cols="85" ></textarea></td>
  </tr>
</table>
</BODY>
</HTML>

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn