<!–#include file =conn.asp–>
<!– #include file=”../inc/const.asp” –>
<title><%=txl_info(0)%>–管理页面</title>
<!–#include file=”admin_css.asp”–>
<meta NAME=GENERATOR Content=”Microsoft FrontPage 3.0″ CHARSET=GB2312>
<body leftmargin=”0″ topmargin=”0″ marginheight=”0″ marginwidth=”0″>
<%
if not supermaster or session(“flag”)=”” then
Errmsg=Errmsg+”<br />”+”<li>本页面为管理员专用,请<a href=admin_index.asp target=_top>登陆</a>后进入。<br /><li>您没有管理本页面的权限。”
call txl_error()
else
call main()
end if
Sub main()
Dim SQL_Statement,RecordsAffected,RetRs,oField,Page_Count,TotalRec,i,abgcolor,CurPage,PCount,EndPage
Response.Write “<table width=’95%’ border=’0′ cellspacing=’1′ cellpadding=’3′ align=center class=’tableBorder’><tr><th colspan=2>论坛数据库管理</th></tr><tr><td align=right Width=200><b>SQL语句执行操作:</b></td><td><blockquote><br />本操作仅限高级、对SQL编程比较熟悉的用户,您可以直接输入SQL执行语句。<br />比如 DELETE FROM USER WHERE UserName=’test’,进行删除某用户帖子操作。<br /><font color=#ff0000>在操作前请慎重考虑您的执行语句是否正确和完整,执行后不可恢复。</font></blockquote></td></tr>”
If Request(“action”) = “sql_done” Then
SQL_Statement=Request(“SQL_Statement”)
If SQL_Statement<>”” then
On Error Resume Next
Server.ScriptTimeOut=999999
Set RetRs=Conn.Execute(SQL_Statement,RecordsAffected)
If Err.number=”0″ then
On Error Goto 0
Response.write “<tr><th colspan=2><b>执行结果</b></th></tr><tr><td align=center colspan=2>”
If RetRs.State=0 Then
If RecordsAffected>0 Then
Response.write “执行成功,共有 “&RecordsAffected&” 条记录被处理。<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
Else
Response.write “执行成功,没有任何记录被处理。<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
End If
Else
RetRs.Close
RetRs.Open SQL_Statement,Conn,1,1
If RetRs.Bof And RetRs.Eof Then
Response.write “执行成功,没有任何记录被返回。<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
Else
CurPage=request(“page”)
If CurPage=”” or not IsNumeric(CurPage) Then
CurPage=1
Else
CurPage=CLng(CurPage)
End If
RetRs.PageSize = 10
If RetRs.RecordCount>0 Then
RetRs.AbsolutePage=CurPage
Page_Count=0
TotalRec=RetRs.RecordCount
Response.write “执行成功,共返回 “&TotalRec&” 条记录。<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
Response.Write “<br /><table width=95% border=’0′ cellspacing=’1′ cellpadding=’3′ align=center><tr>”
For Each oField In RetRs.Fields
Response.Write “<th>” & oField.Name &”</th>”
Next
Do While (not RetRs.eof) And (not Page_Count = Cint(10))
Response.Write “<tr>”
If Page_Count mod 2 = 0 Then
abgcolor=”ForumRow”
Else
abgcolor=”ForumRowHilight”
End If
For i=0 To RetRs.Fields.Count-1
Response.write “<td class=”&abgcolor&”>”
If IsNull(RetRs(i)) Then
Response.Write “”
Else
Response.Write Server.HTMLEncode(RetRs(i))
End If
Response.write “</td>”
Next
Response.Write “</tr>”
Page_count = Page_Count + 1
RetRs.MoveNext
Loop
Response.Write “<tr><td colspan=”&RetRs.Fields.Count&” align=align>分页:”
Pcount=RetRs.PageCount
If CurPage > 4 Then
Response.write “<a href=””?page=1&action=sql_done&sql_statement=”&SQL_Statement&”””>[1]</a> …”
End If
If PCount>CurPage+3 Then
EndPage=CurPage+3
Else
EndPage=PCount
End If
For i=CurPage-3 To EndPage
If i>=1 Then
If i = CLng(CurPage) Then
Response.write ” <font color=red>[“&i&”]</font>”
Else
Response.write ” <a href=””?page=”&i&”&action=sql_done&sql_statement=”&SQL_Statement&”””>[“&i&”]</a>”
End If
End If
Next
If CurPage+3 < PCount Then
Response.write “… <a href=””?page=”&PCount&”&action=sql_done&sql_statement=”&SQL_Statement&”””>[“&PCount&”]</a>”
End If
Else
Response.write “执行成功,返回如下记录:<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
Response.Write “<br /><table width=95% border=’0′ cellspacing=’1′ cellpadding=’3′ align=center><tr>”
For Each oField In RetRs.Fields
If oField.Name<>”” Then
Response.Write “<th>” & oField.Name &”</th>”
Else
Response.Write “<th>执行结果:</th>”
End If
Next
Do While not RetRs.eof
Response.Write “<tr>”
If Page_Count mod 2 = 0 Then
abgcolor=”ForumRow”
Else
abgcolor=”ForumRowHilight”
End If
For i=0 To RetRs.Fields.Count-1
Response.write “<td class=”&abgcolor&”>”
If IsNull(RetRs(i)) Then
Response.Write “”
Else
Response.Write RetRs(i)
End If
Response.write “</td>”
Next
Response.Write “</tr>”
RetRs.MoveNext
Loop
End If
Response.Write “</table></td></tr></table>”
End If
RetRs.Close
End If
Else
Response.write “<tr><th colspan=2><b>执行结果</b></th></tr><tr><td align=center colspan=2>SQL语句有问题,具体错误信息如下:<br />”&Err.Description&”<br /><br />[ <a href=# onclick=history.go(-1)>返回上一页</a> ]</td></tr></table>”
Err.clear
End if
On Error Goto 0
Set RetRs=Nothing
End If
Else
Response.Write “<tr><th colspan=2><b></b>请输入SQL语句</th></tr><form Name=SQLForm Method=Post Action=’?action=sql_done’><tr><td align=center colspan=2><fieldSet><legend>请输入SQL语句</legend>指令:<input type=’text’ name=’SQL_Statement’ Size=60><br /><input type=’Submit’ Value=’ 执 行 ‘></fieldSet></td></tr></form>”
response.Write “<tr><td colspan=2>”
response.Write “(1)数据记录筛选:<br />select * from 数据表 where 字段名=字段值 order by 字段名 [desc]<br />select * from 数据表 where 字段名 like ‘%字段值%’ order by 字段名 [desc]<br />select top 10 * from 数据表 where 字段名 order by 字段名 [desc]<br />select * from 数据表 where 字段名 in (‘值1′,’值2′,’值3’)<br />select * from 数据表 where 字段名 between 值1 and 值2<br /><br />(2) 更新数据记录:<br />update 数据表 set 字段名=字段值 where 条件表达式<br />update 数据表 set 字段1=值1,字段2=值2 字段n=值n where 条件表达式<br /><br />(3) 删除数据记录:<br />delete from 数据表 where 条件表达式<br />delete from 数据表(将数据表所有记录删除)<br /><br />(4) 添加数据记录:<br />insert into 数据表 (字段1,字段2,字段3) values (值1,值2,值3)<br />insert into 目标数据表 select * from 源数据表(把源数据表的记录添加到目标数据表)”
response.Write “<br /><br />(5) 数据表的建立和删除:<br />CREATE TABLE 数据表名称(字段1 类型1(长度),字段2 类型2(长度) …… )例:CREATE TABLE tab01(name varchar(50),datetime default now())DROP TABLE 数据表名称 (永久性删除一个数据表)<br /><br />”
response.Write “(6)更改表格:<br />ALTER TABLE table_name ADD COLUMN column_name DATATYPE 说明:增加一个栏位(没有删除某个栏位的语法)。<br />例:向表中增加一个 VARCHAR 列 ALTER TABLE distributors ADD COLUMN address VARCHAR(30);<br />对现存列改名:ALTER TABLE distributors RENAME COLUMN address TO city;<br />对现存表改名:ALTER TABLE distributors RENAME TO suppliers;<br />更改列类型:ALTER TABLE table_name MODIFY column_name datatype 或者 ALTER TABLE table_name CHANGE column_name new_column_name datatype CHANGE还可以一起改列名”
response.Write “ALTER TABLE table_name ADD PRIMARY KEY (column_name)说明:更改表得的定义把某个栏位设为主键。<br />ALTER TABLE table_name DROP PRIMARY KEY (column_name)说明:把主键的定义删除。<br /><br />(7)、建立索引:<br />CREATE INDEX index_name ON table_name (column_name)说明:对某个表格的栏位建立索引以增加查询时的速度。”
response.Write “”
response.Write “<br /><br />smallint 16 位元的整数。interger 32 位元的整数。decimal(p,s) p 精确值和 s 大小的十进位整数,精确值p是指全部有几个数(digits)大小值,s是指小数点後有几位数。如果没有特别指定,则系统会设为 p=5; s=0 。 float 32位元的实数。double64位元的实数。char(n) n 长度的字串,n不能超过 254。varchar(n) 长度不固定且其最大长度为 n 的字串,n不能超过 4000。graphic(n) 和 char(n) 一样,不过其单位是两个字元 double-bytes, n不能超过127。这个形态是为了支援两个字元长度的字体,例如中文字。vargraphic(n) 可变长度且其最大长度为 n 的双字元字串,n不能超过 2000。date 包含了 年份、月份、日期。time 包含了 小时、分钟、秒。timestamp 包含了 年、月、日、时、分、秒、千分之一秒。”
response.Write “</td></tr></table>”
End If
End Sub
%>