<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

select case action
	case "sqlexe" : headAdmin "执行sql语句" : sqlexe
	case else :  headAdmin "执行sql语句" : main
end select
dispseObj()

sub sqlexe()
	dim Sql,FiledObj
	dim ExeSELECTTF,ExeResult,ExeResultNum,ErrorTF
	Sql = be("post","sql")
	if Sql <>"" then
		ExeSELECTTF = (LCase(Left(Trim(Sql),6)) = "select")
		Sql = replace(Sql,"{pre}",app_tablepre)
		objdb.dbConn.Errors.Clear
		
		On Error Resume Next
		if ExeSELECTTF = true then
			Set ExeResult =objdb.dbConn.execute(Sql,ExeResultNum)
		else
			objdb.dbConn.execute Sql,ExeResultNum
		end if
		if Err.number <> 0 Then
			ErrorTF = True
			set ExeResult = objdb.dbConn.Errors
		else
			ErrorTF = False
		end if
	end if
	if ErrorTF = True then
%>
<table class="tb">
    <tr>
      <td width="15%">错误号</td>
      <td width="20%">来源</td>
      <td>描述</td>
      <td width="15%">帮助</td>
      <td width="15%">帮助文档</td>
    </tr>
	<%
	For sql_i=1 To objdb.dbConn.Errors.Count
	Set ErrObj=objdb.dbConn.Errors(sql_i-1)
	%>
    <tr>
      <td><%= ErrObj.Number %></td>
      <td><%= ErrObj.Description %></td>
      <td><%= ErrObj.Source %></td>
	  <td><%= ErrObj.Helpcontext %></td>
	  <td><%= ErrObj.HelpFile %></td>
    </tr>
	<%next%>
</table>
	<%else%>
<table class="tb">
	<%if ExeSELECTTF = true then%>
      <tr>
	  <%For Each FiledObj In ExeResult.Fields%>
        <td><strong><% = FiledObj.name %></strong></td>
	  <%next%>
      </tr>
	  <%do while Not ExeResult.Eof%>
      <tr align="center">
	  <%For Each FiledObj In ExeResult.Fields%>
        <td><%if IsNull(FiledObj.value) or  FiledObj.value="" then
							writeA("&nbsp;")
					 	else
							writeA(FiledObj.value)
						end if%></td><%next%>
      </tr>
	  <%ExeResult.MoveNext
		loop
		else%>
      <tr>
        <td><strong>执行结果</strong></td>
      </tr>
      <tr>
        <td><% = ExeResultNum & "条纪录被影响"%></td>
      </tr>
	  <%end if%>
</table>
<%end if
set FiledObj = nothing
objdb.c(ExeResult)
end sub

sub main()
%>
<script language="javascript">
	$(document).ready(function(){
		$("#form1").validate({
			rules:{
				sql:{
					required:true
				}
			}
		});
	});
</script>
<form action="?action=sqlexe" method="post" name="form1" id="form1">
<table class="tb">
    <tr>
      <td>
      	<textarea name="sql" type="text" id="sql" rows="10" style="width:90%"></textarea>
      </td>
      </tr>
    <tr>
      <td><input class="input" type="submit" value="执行" name="Submit"></td>
    </tr>
    <tr>
	<td valign="top" >
	<strong><br>常用语句对照<br></strong><br>
	<strong>1.查询数据</strong><br>
	SELECT * FROM {pre}vod&nbsp;&nbsp; 查询所有数据<br>
	SELECT * FROM {pre}vod WHERE d_id=1000&nbsp;&nbsp; 查询指定ID数据<br>
    <strong>2.删除数据</strong><br>
    DELETE FROM {pre}vod&nbsp;&nbsp; 删除所有数据<br>
	DELETE FROM {pre}vod WHERE d_id=1000 &nbsp; 删除指定的第几条数据<br>
	DELETE FROM {pre}vod WHERE d_starring LIKE '%刘德华%'&nbsp;&nbsp; 删除d_starring字段里有&quot;刘德华&quot;的数据<br>
	<strong>&nbsp;3.修改数据</strong><br>
	UPDATE {pre}vod SET d_hits=1&nbsp;&nbsp; 将所有d_hits字段里的值修改成&quot;1&quot;<br>
	UPDATE {pre}vod SET d_hits=1 WHERE d_id=1000&nbsp; 指定的第几条数据把d_hits字段里的值修改成&quot;1&quot; <br>
	</td>
</tr>
</table>
</form>
<%
end sub
%>
</body>
</html>