当前位置: 代码迷 >> SQL >> SQL占位符轮换工具 Fix placeholder
  详细解决方案

SQL占位符轮换工具 Fix placeholder

热度:349   发布时间:2016-05-05 15:23:02.0
SQL占位符替换工具 Fix placeholder
SQL语句中占位符的替换,界面如下;



代码如下:
<script>		//Created:2012-6-9 	function bind()	{		if(parameters.value && preparedStmt.value)			{			 //reset notice			 noticeArea.innerText="";			 //replace special character			 var reg=new RegExp("\r\n","g");			 var paramArray = parameters.value.replace(reg,"").split(parameterSep.value);				 nativeSQL.value = preparedStmt.value;			 //foreach			 for(var i=0;i<paramArray.length;i++)			 {			 		nativeSQL.value = nativeSQL.value.replace("?","'"+paramArray[i]+"'");			 }			 			 			 if(nativeSQL.value.indexOf("?") != -1)			 {			 		noticeArea.innerText="Not all placeholder be binded !";				 }			 		}	}	</script>		<h2 style="color:blue" align="center">Bind parameters for prepared SQL statement </h2>	<table align="center">    <tr>			<td>Parameter Separater:</td>			<td><input id="parameterSep" value=","> &nbsp;<span id="noticeArea" style="color:red"></span></td>    </tr>	  <tr>			<td>Prepared Statement:</td>			<td><textarea id="preparedStmt" cols=100% rows=7></textarea></td>    </tr> 	  <tr>			<td>Parameters:</td>			<td><textarea id="parameters" cols=100% rows=3></textarea></td>    </tr>   	<tr>			<td>Native SQL:</td>			<td><textarea id="nativeSQL" cols=100% rows=10 style="color:blue"></textarea></td>    </tr>    	<tr>			<td colspan=2 align="center"><input type="button" value="Bind" onclick="bind();"></td>		</tr></table>

  相关解决方案