代码有点多,下载:http://download.csdn.net/source/337848
另外程序还有点Bug,还没来得及改,如果谁完善一下,别忘了发给我一份(jyh_jack@163.com)
by 鞠勇鸿
conn.asp 内容:
<%
dim conn
set conn = server.createobject( " adodb.connection " )
connString = " Driver={Microsoft Access Driver (*.mdb)}; DBQ= " & server.mappath( " data.mdb " )
conn.open connString
%>
<%
dim conn
set conn = server.createobject( " adodb.connection " )
connString = " Driver={Microsoft Access Driver (*.mdb)}; DBQ= " & server.mappath( " data.mdb " )
conn.open connString
%>
index.asp 内容:
<!-- #include file=conn.asp -->
<% ' 得到ACCESS数据表的列表存入Tables()数组
set adoxCatalogx = server.createobject( " ADOX.Catalog " )
dim adoxCatalogx
set adoxCatalogx.ActiveConnection = conn
dim adoTable
set adoTable = server.createobject( " ADOX.Table " )
dim Tables()
Redim Tables(adoxCatalogx.Tables.count)
i = 1
for each adoTable in adoxCatalogx.Tables
' response.write adoTable.Name+"<br>"
Tables(i) = adoTable.Name
i = i + 1
next
%>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" >
< title > SQL Query </ title >
< style type ="text/css" >
.f1 {
font-size : 9pt ;
color : black ;
font-family : 宋体 ;
}
.f2 {
font-size : 9pt ;
color : #929292 ;
font-family : 宋体 ;
}
.f3 {
font-size : 9pt ;
color : #000000 ;
font-family : 宋体 ;
font-weight : bold ;
}
a {
font-size : 9pt ;
color : blue ;
font-family : 宋体 ;
text-decoration : none ;
}
.table1 {
border-collapse : collapse ;
border-style : solid ;
border-width : 1px ;
width : 150px ;
}
input {
font-size : 9pt ;
font-family : 宋体 ;
}
</ style >
< script type ="text/javascript" >
function showHide(objId)
{
obj = document.getElementById(objId);
if (obj.style.display == ' block ' )
{
obj.style.display = ' none ' ;
}
else
{
obj.style.display = ' block ' ;
}
}
function getSqlText(QueryType,Table)
{
obj = document.getElementById( " QueryText " );
switch (QueryType)
{
case " select " :
str = " select * from [ " + Table + " ] " ;
break ;
case " select10 " :
str = " select top 10 * from [ " + Table + " ] " ;
break ;
case " update " :
str = " update [ " + Table + " ] " ;
str += " set = " ;
str += " where = "
break ;
case " delete " :
str = " delete from [ " + Table + " ] where = " ;
break ;
}
obj.value = str;
obj.focus();
obj.select();
}
function getStructure(Table)
{
obj = document.getElementById( " QueryText " );
obj.value = " [ " + Table + " ] "
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=structure " ;
document.QueryForm.submit();
}
function runQuery(IfNewWindow)
{
document.QueryForm.QueryText.value = document.QueryForm.QueryText.value.replace( /^ s */ , "" ); // 去左空格
document.QueryForm.QueryText.value = document.QueryForm.QueryText.value.replace( / s * $ / , "" ); // 去右空格
if (document.QueryForm.toClipBoard.checked)
{
window.clipboardData.setData( " Text " ,document.QueryForm.QueryText.value); // 存入clipboard
}
str = document.QueryForm.QueryText.value;
if (str.length < 7 )
{
alert( " 请输入正常的SQL! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
if (str.indexOf( " ; " ) >= 0 )
{
alert( " 正常的SQL中不应包含';'! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
if (str.indexOf( " " " ) >= 0 )
{
alert( " 正常的SQL中不应包含'"'! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
queryType = str.substr( 0 , 6 ).toLowerCase();
switch (queryType)
{
case " select " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=select " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=select " ;
document.QueryForm.submit();
}
break ;
case " update " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=update " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=update " ;
document.QueryForm.submit();
}
break ;
case " delete " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=delete " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=delete " ;
document.QueryForm.submit();
}
break ;
}
}
function runGouYinQuery()
{
alert( " 请在执行前备份数据库! " );
if ( ! confirm( " 是否要进行强制执行SQL操作? " )){ return ;}
if ( ! confirm( " 强执行SQL后,数据无法恢复。是否继续? " )){ return ;}
if ( ! confirm( " 最后一次确认。是否继续? " )){ return ;}
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=GouInSQL " ;
document.QueryForm.submit();
}
</ script >
</ head >
< body >
< form action ="query.asp" method ="post" name ="QueryForm" >
< table style ="width: 930px" >
< tr >
< td rowspan ="2" style ="width: 155px" >
< table width ="940" border ="1" bordercolor ="black" cellspacing ="2" cellpadding ="3" class ="table1" >
< tr style ="text-align: center; height: 28px;" >
< td style ="border-width: 1px" width ="150" >
< font class ="f3" > 表名 </ font ></ td >
</ tr >
<%
for i = 1 to ubound (Tables)
%>
< tr >
< td style ="border-width: 1px" width ="150" >
< label onclick ="showHide('div<%=i%>')" style ="cursor:pointer " >
<% if UCASE ( left (Tables(i), 4 )) = " MSYS " then %>
< font class ="f2" > <% = Tables(i) %> </ font >
<% else %>
< font class ="f1" > <% = Tables(i) %> </ font >
<% end if %>
</ label >
< div align ="center" id ="div<%=i%>" style ="display:none;" >
< a href ="javascript:" onclick ="getStructure('<%=Tables(i)%>')" title ="查看表结构" > 结构 </ a >
< a href ="javascript:" onclick ="getSqlText('select','<%=Tables(i)%>')" title ="查询记录" > 查询 </ a >< a href ="javascript:" onclick ="getSqlText('select10','<%=Tables(i)%>')" title ="查询前10条记录" > 10 </ a >
< a href ="javascript:" onclick ="getSqlText('update','<%=Tables(i)%>')" title ="修改记录内容" > 修改 </ a >
< a href ="javascript:" onclick ="getSqlText('delete','<%=Tables(i)%>')" title ="删除记录" > 删除 </ a >
</ div >
</ td >
</ tr >
<%
next
%>
</ table >
</ td >
< td style ="height: 150px" valign ="top" >< font class ="f3" > 查询分析器: </ font >< br >
< textarea style ="width: 753px; height: 121px" id ="QueryText" name ="QueryText" ></ textarea >< br >
< input type ="button" value ="运行(r)" onclick ="runQuery(0)" accesskey ="r" >
< input type ="button" value ="新窗口中运行(n)" onclick ="runQuery(1)" accesskey ="n" >
< input type ="button" value ="无判断,强执行" onclick ="runGouYinQuery()" accesskey ="n" style ="color:red" >
< input type ="checkbox" accesskey ="c" id ="toClipBoard" name ="toClipBoard" checked ="checked" >< label for ="toClipBoard" class ="f1" > 自动将查询存入剪切版 </ label >
</ td >
</ tr >
< tr >
< td valign ="top" > </ td >
</ tr >
</ table >
</ form >
</ body >
</ html >
<!-- #include file=conn.asp -->
<% ' 得到ACCESS数据表的列表存入Tables()数组
set adoxCatalogx = server.createobject( " ADOX.Catalog " )
dim adoxCatalogx
set adoxCatalogx.ActiveConnection = conn
dim adoTable
set adoTable = server.createobject( " ADOX.Table " )
dim Tables()
Redim Tables(adoxCatalogx.Tables.count)
i = 1
for each adoTable in adoxCatalogx.Tables
' response.write adoTable.Name+"<br>"
Tables(i) = adoTable.Name
i = i + 1
next
%>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" >
< title > SQL Query </ title >
< style type ="text/css" >
.f1 {
font-size : 9pt ;
color : black ;
font-family : 宋体 ;
}
.f2 {
font-size : 9pt ;
color : #929292 ;
font-family : 宋体 ;
}
.f3 {
font-size : 9pt ;
color : #000000 ;
font-family : 宋体 ;
font-weight : bold ;
}
a {
font-size : 9pt ;
color : blue ;
font-family : 宋体 ;
text-decoration : none ;
}
.table1 {
border-collapse : collapse ;
border-style : solid ;
border-width : 1px ;
width : 150px ;
}
input {
font-size : 9pt ;
font-family : 宋体 ;
}
</ style >
< script type ="text/javascript" >
function showHide(objId)
{
obj = document.getElementById(objId);
if (obj.style.display == ' block ' )
{
obj.style.display = ' none ' ;
}
else
{
obj.style.display = ' block ' ;
}
}
function getSqlText(QueryType,Table)
{
obj = document.getElementById( " QueryText " );
switch (QueryType)
{
case " select " :
str = " select * from [ " + Table + " ] " ;
break ;
case " select10 " :
str = " select top 10 * from [ " + Table + " ] " ;
break ;
case " update " :
str = " update [ " + Table + " ] " ;
str += " set = " ;
str += " where = "
break ;
case " delete " :
str = " delete from [ " + Table + " ] where = " ;
break ;
}
obj.value = str;
obj.focus();
obj.select();
}
function getStructure(Table)
{
obj = document.getElementById( " QueryText " );
obj.value = " [ " + Table + " ] "
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=structure " ;
document.QueryForm.submit();
}
function runQuery(IfNewWindow)
{
document.QueryForm.QueryText.value = document.QueryForm.QueryText.value.replace( /^ s */ , "" ); // 去左空格
document.QueryForm.QueryText.value = document.QueryForm.QueryText.value.replace( / s * $ / , "" ); // 去右空格
if (document.QueryForm.toClipBoard.checked)
{
window.clipboardData.setData( " Text " ,document.QueryForm.QueryText.value); // 存入clipboard
}
str = document.QueryForm.QueryText.value;
if (str.length < 7 )
{
alert( " 请输入正常的SQL! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
if (str.indexOf( " ; " ) >= 0 )
{
alert( " 正常的SQL中不应包含';'! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
if (str.indexOf( " " " ) >= 0 )
{
alert( " 正常的SQL中不应包含'"'! " );
document.QueryForm.QueryText.select();
document.QueryForm.QueryText.focus();
return ;
}
queryType = str.substr( 0 , 6 ).toLowerCase();
switch (queryType)
{
case " select " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=select " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=select " ;
document.QueryForm.submit();
}
break ;
case " update " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=update " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=update " ;
document.QueryForm.submit();
}
break ;
case " delete " :
if (IfNewWindow == 0 )
{
document.QueryForm.action = " Query.asp?action=delete " ;
document.QueryForm.target = window.name;
document.QueryForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=delete " ;
document.QueryForm.submit();
}
break ;
}
}
function runGouYinQuery()
{
alert( " 请在执行前备份数据库! " );
if ( ! confirm( " 是否要进行强制执行SQL操作? " )){ return ;}
if ( ! confirm( " 强执行SQL后,数据无法恢复。是否继续? " )){ return ;}
if ( ! confirm( " 最后一次确认。是否继续? " )){ return ;}
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.QueryForm.target = winName;
document.QueryForm.action = " Query.asp?action=GouInSQL " ;
document.QueryForm.submit();
}
</ script >
</ head >
< body >
< form action ="query.asp" method ="post" name ="QueryForm" >
< table style ="width: 930px" >
< tr >
< td rowspan ="2" style ="width: 155px" >
< table width ="940" border ="1" bordercolor ="black" cellspacing ="2" cellpadding ="3" class ="table1" >
< tr style ="text-align: center; height: 28px;" >
< td style ="border-width: 1px" width ="150" >
< font class ="f3" > 表名 </ font ></ td >
</ tr >
<%
for i = 1 to ubound (Tables)
%>
< tr >
< td style ="border-width: 1px" width ="150" >
< label onclick ="showHide('div<%=i%>')" style ="cursor:pointer " >
<% if UCASE ( left (Tables(i), 4 )) = " MSYS " then %>
< font class ="f2" > <% = Tables(i) %> </ font >
<% else %>
< font class ="f1" > <% = Tables(i) %> </ font >
<% end if %>
</ label >
< div align ="center" id ="div<%=i%>" style ="display:none;" >
< a href ="javascript:" onclick ="getStructure('<%=Tables(i)%>')" title ="查看表结构" > 结构 </ a >
< a href ="javascript:" onclick ="getSqlText('select','<%=Tables(i)%>')" title ="查询记录" > 查询 </ a >< a href ="javascript:" onclick ="getSqlText('select10','<%=Tables(i)%>')" title ="查询前10条记录" > 10 </ a >
< a href ="javascript:" onclick ="getSqlText('update','<%=Tables(i)%>')" title ="修改记录内容" > 修改 </ a >
< a href ="javascript:" onclick ="getSqlText('delete','<%=Tables(i)%>')" title ="删除记录" > 删除 </ a >
</ div >
</ td >
</ tr >
<%
next
%>
</ table >
</ td >
< td style ="height: 150px" valign ="top" >< font class ="f3" > 查询分析器: </ font >< br >
< textarea style ="width: 753px; height: 121px" id ="QueryText" name ="QueryText" ></ textarea >< br >
< input type ="button" value ="运行(r)" onclick ="runQuery(0)" accesskey ="r" >
< input type ="button" value ="新窗口中运行(n)" onclick ="runQuery(1)" accesskey ="n" >
< input type ="button" value ="无判断,强执行" onclick ="runGouYinQuery()" accesskey ="n" style ="color:red" >
< input type ="checkbox" accesskey ="c" id ="toClipBoard" name ="toClipBoard" checked ="checked" >< label for ="toClipBoard" class ="f1" > 自动将查询存入剪切版 </ label >
</ td >
</ tr >
< tr >
< td valign ="top" > </ td >
</ tr >
</ table >
</ form >
</ body >
</ html >
Query.asp 内容:
< ! -- #include file = conn.asp -->
< %
Response.Buffer = True
Response.ExpiresAbsolute = Now () - 1
Response.Expires = 0
Response.CacheControl = " no-cache "
Response.AddHeader " Pragma " , " No-Cache " ' 以上代码防止使用缓存
Action = request( " Action " )
SQL = trim (request( " QueryText " ))
' response.write sql
select case Action
case " select " ' 简单查询、单表查询
title = " Select查询 "
case " update "
title = " Update更新--第一步,确认 "
case " update2 "
title = " update更新--第二步,更新完成 "
case " delete "
title = " Delete删除--第一步,确认 "
case " delete2 "
title = " Delete删除--第二步,删除完成 "
case " GouInSQL "
title = " 强制执行SQL "
case " structure "
title = " 得到表 " + sql + " 结构 "
end select
% >
< html >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " >
< title >< % = title% ></ title >
< style type = " text/css " >
.f1{
font - size:9pt;
color:black;
font - family:宋体;
}
.f2{
font - size:9pt;
color:# 929292 ;
font - family:宋体;
}
.f3{
font - size:9pt;
color:# 000000 ;
font - family:宋体;
font - weight:bold;
}
a{
font - size:9pt;
color:blue;
font - family:宋体;
text - decoration:none;
}
.style1 {
border - collapse: collapse;
border: 1px solid # 000000 ;
}
</ style >
< script type = " text/javascript " >
function showDetail(objId)
{
obj = document.getElementById(objId);
str = obj.innerHTML;
document.DetailForm.action = " ViewDetail.asp " ;
document.DetailForm.AllText.value = str;
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.DetailForm.target = winName;
document.DetailForm.submit();
}
function setSQLTextSubmit(sql,querystring)
{
document.DetailForm.QueryText.value = sql;
document.DetailForm.action = " Query.asp " + querystring;
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
function update2Submit()
{
alert( " 请在更新前备份数据库! " );
if (confirm( " 更新数据后不可恢复,是否确认更新数据? " ))
{
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
}
function delete2Submit()
{
alert( " 请在删除前备份数据库! " );
if (confirm( " 删除后不可恢复,确认删除数据? " ))
{
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
}
/******************************
***** SQL生成控制面版 函数 *******
*******************************/
var TableName = "" ; // 当前表名
var CurrentSubText = "" ; // 当前设置子句
function showSqlPane() // 显示、关闭面版
{
if (document.getElementById( " ControlPane " ).style.display == ' block')
{
document.getElementById( " ControlPane " ).style.display = ' none';
}
else
{
document.getElementById( " ControlPane " ).style.display = " block " ;
}
}
function actionSelectChage() // 选择Radio
{
if (document.getElementById( " actionSelect " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = false ;
document.ControlPaneForm.SubSQLOrder.disabled = false ;
document.ControlPaneForm.SetText.disabled = true ;
document.ControlPaneForm.SubSQLSet.disabled = true ;
}
if (document.getElementById( " actionUpdate " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = true ;
document.ControlPaneForm.SubSQLOrder.disabled = true ;
document.ControlPaneForm.SetText.disabled = false ;
document.ControlPaneForm.SubSQLSet.disabled = false ;
}
if (document.getElementById( " actionDelete " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = true ;
document.ControlPaneForm.SubSQLOrder.disabled = true ;
document.ControlPaneForm.SetText.disabled = true ;
document.ControlPaneForm.SubSQLSet.disabled = true ;
}
}
function chooseTitle(type) // 选择子句
{
CurrentSubText = type;
obj = document.getElementById( " hinter " );
switch(type)
{
case " where " :
obj.innerHTML = " 请设置 <Where> 字句字段,点击标题>> " ;
break;
case " order " :
obj.innerHTML = " 请设置 <Order> 字句字段,点击标题>> " ;
break;
case " set " :
obj.innerHTML = " 请设置 <Set> 字句字段,点击标题>> " ;
break;
case " clear " :
obj.innerHTML = "" ;
break;
}
}
function titleClick(title) // 选择字段
{
obj = document.getElementById( " hinter " );
switch(CurrentSubText)
{
case " where " :
obj.innerHTML = " 请设置 <Where> 字句字段,点击标题>> " ;
document.ControlPaneForm.WhereText.value = title + " = " ;
document.ControlPaneForm.WhereText.focus;
document.ControlPaneForm.WhereText.select();
obj.innerHTML = "" ;
break;
case " order " :
obj.innerHTML = " 请设置 <Order> 字句字段,点击标题>> " ;
document.ControlPaneForm.OrderText.value = title;
document.ControlPaneForm.OrderText.focus;
document.ControlPaneForm.OrderText.select();
obj.innerHTML = "" ;
break;
case " set " :
obj.innerHTML = " 请设置 <Set> 字句字段,点击标题>> " ;
document.ControlPaneForm.SetText.value = title + " = " ;
document.ControlPaneForm.SetText.focus;
document.ControlPaneForm.SetText.select();
obj.innerHTML = "" ;
break;
}
}
function establishSQL()
{
var sql = "" ;
if (document.getElementById( " actionSelect " ).checked) // select
{
sql = " select * from " + TableName;
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
if (document.ControlPaneForm.SubSQLOrder.checked)
{
sql += " order by " + document.ControlPaneForm.OrderText.value;
if (document.ControlPaneForm.orderDesc.checked)
{
sql += " Desc " ;
}
else
{
sql += " Asc " ;
}
}
}
if (document.getElementById( " actionUpdate " ).checked) // update
{
sql = " update " + TableName;
if (document.ControlPaneForm.SubSQLSet.checked)
{
sql += " set " + document.ControlPaneForm.SetText.value;
}
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
}
if (document.getElementById( " actionDelete " ).checked) // delete
{
sql = " delete from " + TableName;
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
}
document.ControlPaneForm.QueryText.value = sql;
}
function returnSQL()
{
obj = window.opener.document.getElementById( " QueryText " );
obj.value = document.ControlPaneForm.QueryText.value;
}
function runSQL(IfNewWindow)
{
document.ControlPaneForm.QueryText.value = document.ControlPaneForm.QueryText.value.replace( /^ s */ , "" ); // 去左空格
document.ControlPaneForm.QueryText.value = document.ControlPaneForm.QueryText.value.replace( / s * $ / , "" ); // 去右空格
str = document.ControlPaneForm.QueryText.value;
if (str.length < 7 )
{
alert( " 请输入正常的SQL! " );
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
if (str.indexOf( " ; " ) >= 0 )
{
alert( " 正常的SQL中不应包含';'! " );
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
if (str.indexOf( " "")>=0)
{
alert( " 正常的SQL中不应包含' " ' !");
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
queryType = str.substr( 0 , 6 ).toLowerCase();
switch(queryType)
{
case " select " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=select " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=select " ;
document.ControlPaneForm.submit();
}
break;
case " update " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=update " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=update " ;
document.ControlPaneForm.submit();
}
break;
case " delete " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=delete " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=delete " ;
document.ControlPaneForm.submit();
}
break;
}
}
</ script >
</ head >
< body class = " f1 " >
< form name = " ControlPaneForm " action = " query.asp " method = " post " >
< div id = " ControlPane " style = " <%= " display:none; " %> " >
SQL生成控制面版: < font id = " hinter " style = " color:red;font-size:9pt;font-weight:bold; " ></ font >
< table style = " width: 100% " cellspacing = " 3 " cellpadding = " 4 " class = " style1 " >
< tr >
< td style = " border: 1px solid #000000; width: 70px; " valign = " top " >
< table style = " width: 100% " >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " select " name = " sqlType " id = " actionSelect " onclick = " actionSelectChage() " >< label for = " actionSelect " class = " f1 " > SELECT </ label >
</ td >
</ tr >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " Update " name = " sqlType " id = " actionUpdate " onclick = " actionSelectChage() " >< label for = " actionUpdate " class = " f1 " > UPDATE </ label >
</ td >
</ tr >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " Delete " name = " sqlType " id = " actionDelete " onclick = " actionSelectChage() " >< label for = " actionDelete " class = " f1 " > DELETE </ label >
</ td >
</ tr >
</ table >
</ td >
< td style = " width: 360px " >
< table style = " width: 100% " >
< tr >
< td style = " width: 80px " >
< input type = " checkbox " name = " SubSQL " id = " SubSQLWhere " disabled = " disabled " onclick = " if (this.checked){chooseTitle('where');} else {chooseTitle('clear')} " >< label for = " SubSQLWhere " class = " f1 " > Where子句 </ label >
</ td >
< td >
< input type = " text " name = " WhereText " size = " 40 " disabled = " disabled " >
</ td >
</ tr >
< tr >
< td >
< input type = " checkbox " name = " SubSQL " id = " SubSQLOrder " disabled = " disabled " onclick = " if (this.checked){chooseTitle('order');} else {chooseTitle('clear')} " >< label for = " SubSQLOrder " class = " f1 " > Order子句 </ label >
</ td >
< td >
< input type = " text " name = " OrderText " size = " 20 " disabled = " disabled " >
< input type = " radio " name = " orderType " id = " orderAsc " >< label for = " orderAsc " class = " f1 " > 升序 </ label >
< input type = " radio " name = " orderType " id = " orderDesc " checked = " checked " >< label for = " orderDesc " class = " f1 " > 降序 </ label >
</ td >
</ tr >
< tr >
< td >
< input type = " checkbox " name = " SubSQL " id = " SubSQLSet " disabled = " disabled " onclick = " if (this.checked){chooseTitle('set');} else {chooseTitle('clear')} " >< label for = " SubSQLSet " class = " f1 " > Set子句 </ label >
</ td >
< td >
< input type = " text " name = " SetText " size = " 40 " disabled = " disabled " ></ td >
</ tr >
</ table >
</ td >
< td style = " width: 40px " >
< input type = " button " value = " 生成SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " establishSQL() " >
< input type = " button " value = " 返回SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " returnSQL() " >
< input type = " button " value = " 运行SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " runSQL(0) " >
< input type = " button " value = " 新开SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " runSQL(1) " >
</ td >
< td >
< textarea name = " QueryText " style = " height: 76px; width: 441px " ></ textarea >
</ td >
</ tr >
</ table >
</ div >
</ form >
< %
function CutString(str) ' 截取字符串
if len (str) > 40 then
' 存字符串
Randomize
SaveId = cstr ( int ( rnd () * 10000 )) + cstr ( int ( rnd () * 10000 )) + cstr ( int ( rnd () * 10000 )) ' 防止ID重复
SaveString = " <font id=' " + SaveId + " ' style='display:none'> " + str + " </font> "
' 显示部份内容及超链
CutString = left (str, 30 )
CutString = CutString + " ... "
CutString = CutString + " <a href='javascript:' οnclick='showDetail( " + chr ( 34 ) + SaveId + chr ( 34 ) + " )'> "
CutString = CutString + " [未完,查看全部] "
CutString = CutString + " </a> "
CutString = CutString + SaveString
else
CutString = Str
end if
end function
Function FormatHTML(fString) ' 过滤特殊字符
If fString <> "" Then
fString = trim (fString)
fString = replace (fString, " ; " , " ; " ) ' 分号过滤
fString = replace (fString, " -- " , " —— " ) ' --过滤
fString = replace (fString, " %20 " , "" ) ' 特殊字符过滤
fString = replace (fString, " == " , "" ) ' ==过滤
fString = replace (fString, " > " , " > " )
fString = replace (fString, " < " , " < " )
fString = Replace (fString, CHR ( 32 ), " " ) '
fString = Replace (fString, CHR ( 9 ), " " ) '
fString = Replace (fString, CHR ( 34 ), " " " )
fString = Replace (fString, CHR ( 39 ), " ' " ) ' 单引号过滤
fString = Replace (fString, CHR ( 13 ), "" )
fString = Replace (fString, CHR ( 10 ) & CHR ( 10 ), " </P><P> " )
fString = Replace (fString, CHR ( 10 ), " <BR> " )
FormatHTML = fString
End If
End Function
Function WriteFieldRecord(sql) ' 写表格函数
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
strTmp = ""
strTmp = strTmp + " <table style='width: 100%;border-collapse: collapse;' cellpadding='3'> "
strTmp = strTmp + " <tr> "
' **写字段名**
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap> "
strTmp = strTmp + " <font class='f3'> "
if ( instr (rs.fields(i).name, " * " ) > 0 ) then
strTmp = strTmp + " <font color='red'> " + rs.fields(i).name + " </font> "
else
strTmp = strTmp + rs.fields(i).name
end if
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
strTmp = strTmp + " </tr> "
' **写记录**
do while not rs.eof
strTmp = strTmp + " <tr> "
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000; ' nowrap> "
strTmp = strTmp + " <font class='f1'> "
strTmp = strTmp + CutString(FormatHTML(rs(i)))
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
rs.movenext
strTmp = strTmp + " </tr> "
loop
strTmp = strTmp + " </table> "
rs.close
set rs = nothing
WriteFieldRecord = strTmp
End Function
Function WriteFieldRecord2(sql) ' 写表格函数2 写标题点击函数
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
strTmp = ""
strTmp = strTmp + " <table style='width: 100%;border-collapse: collapse;' cellpadding='3'> "
strTmp = strTmp + " <tr> "
' **写字段名**
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;cursor:pointer' align='center' nowrap οnclick='titleClick( " + chr ( 34 ) + rs.fields(i).name + chr ( 34 ) + " )'> "
strTmp = strTmp + " <font class='f3'> "
if ( instr (rs.fields(i).name, " * " ) > 0 ) then
strTmp = strTmp + " <font color='red'> " + rs.fields(i).name + " </font> "
else
strTmp = strTmp + rs.fields(i).name
end if
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
strTmp = strTmp + " </tr> "
' **写记录**
do while not rs.eof
strTmp = strTmp + " <tr> "
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000; ' nowrap> "
strTmp = strTmp + " <font class='f1'> "
strTmp = strTmp + CutString(FormatHTML(rs(i)))
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
rs.movenext
strTmp = strTmp + " </tr> "
loop
strTmp = strTmp + " </table> "
rs.close
set rs = nothing
WriteFieldRecord2 = strTmp
End Function
' *******************----------------*********************
' ******************|简单查询、单表查询|*********************
' *******************----------------*********************
if Action = " select " then
on error resume next
fromPos = instr ( ucase (sql), ucase ( " from " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
if wherePos = 0 then
TableName = trim ( mid (sql,fromPos + 5 , len (sql)))
else
TableName = trim ( mid (sql,fromPos + 5 ,wherePos - fromPos - 4 ))
end if
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
RecordCount = rs.recordcount
response.write " <form method='post' action='ViewDetail.asp' name='DetailForm'> " ' 用来查询显示不全的字段内容
response.write " <input name='AllText' type='hidden'> "
response.write " <input name='QueryText' type='hidden'> "
response.write " 查询的SQL为: "
response.write " <font class='f2'> " & SQL & " </font> "
response.write " <br><br> "
response.write " 共有记录数:<font color='red'> " & cstr (RecordCount) & " </font> "
response.write " <a href='javascript:' οnclick='showSqlPane()'>[打开/关闭SQL生成控制面版]</a> "
response.write " <a href='javascript:history.back(-1)'>[返回]</a> "
response.write " <a href='#' οnclick='window.close()'>[关闭]</a><br><br> "
if request.querystring( " Continue " ) <> " 1 " then
if recordcount > 100 then
response.write " <font color='red'>一次性查询数据最好不要超过100条,请选择:</font> "
sqltmp = " select top 10 " + mid (sql, 7 , len (sql))
querystring = " ?Action=select "
response.write " <a href=# οnclick='setSQLTextSubmit( " + chr ( 34 ) + sqltmp + chr ( 34 ) + " , " + chr ( 34 ) + querystring + chr ( 34 ) + " )'>[查询前10条数据]</a> "
response.write " "
querystring = " ?Action=select&Continue=1 "
response.write " <a href='#' οnclick='setSQLTextSubmit( " + chr ( 34 ) + sql + chr ( 34 ) + " , " + chr ( 34 ) + querystring + chr ( 34 ) + " )'>[继续查询]</a> "
response.end
end if
end if
strTmp = WriteFieldRecord2(sql) ' 调用画表格函数
response.write strTmp
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据更新 |*********************
' *******************----------------*********************
if Action = " update " then
on error resume next
response.write " <form method='post' action='Query.asp' name='DetailForm'> " ' 用来查询显示不全的字段内容
response.write " <input name='AllText' type='hidden'> "
response.write " <input name='action' type='hidden' value='update2'> "
response.write sql
response.write " <input name='QueryText' type='hidden' value= " + chr ( 34 ) + sql + chr ( 34 ) + " > "
response.write " 查询的SQL为: "
response.write " <font class='f2'> " & SQL & " </font><br><br> "
' 各字句的划分
sql = trim (sql)
setPos = instr ( ucase (sql), ucase ( " set " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
setStr = trim ( mid (sql,setPos,wherePos - setPos))
whereStr = trim ( mid (sql,wherePos, len (sql)))
TableName = trim ( mid (sql, 7 ,setPos - 6 ))
' 要更改的字段显示
response.write " <br><br> "
response.write " <font style='color:red;font-weight:bold'> "
response.write " 您要改的数据内容: "
response.write " </font> "
response.write " <font class='f2'>表名: " + TableName + " </font> "
response.write " <font class='f2'> 条件: " + whereStr + " </font> "
response.write " <font class='f2'>Set字句为: " + setStr + " </font> "
response.write " <br><br> "
tmpsql = " select * from " + TableName + whereStr ' 生成查询SQL
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br><br> "
' *******************************************************************
' *当set字句没有个逗号(,),只有一个等号(=)时,可以进行未来数据分析,且可以预览*
' *******************************************************************
denghaoOK = instr (setStr, " = " )
if denghaoOK > 0 then ' 是否只有一个等号,如果denghaoOK=True
if instr (denghaoOK + 1 ,setStr, " = " ) > 0 then
denghaoOK = false
else
denghaoOK = true
end if
else
denghaoOk = false
end if
if instr (setStr, " , " ) > 0 then ' 是否只有一个逗号,如果douhaoOK=True
douhaoOK = False
else
douhaoOK = true
end if
if douhaoOK and denghaoOK then
' 显示未来数据
' --要改的字段名及值
setFieldStr = trim ( mid (setStr, 4 , instr (setStr, " = " ) - 4 )) ' 要改的字段名
setValueStr = trim ( mid (setStr, instr (setStr, " = " ) + 1 , len (setStr))) ' 得到值
' --生成字段表
tmpsql = " select top 1 * from " + TableName + whereStr ' 生成查询SQL
set rs = server.createobject( " adodb.recordset " )
rs.open tmpsql,conn, 1
FieldsList = ""
for each field in rs.fields
if ucase (setFieldStr) = ucase (field.name) then
FieldsList = FieldsList + " ( " + setValueStr + " ) as [* " + field.name + " *], "
else
FieldsList = FieldsList + field.name + " , "
end if
next
FieldsList = left (FieldsList, len (FieldsList) - 1 )
rs.close
set rs = nothing
' --生成SQL
tmpsql = " select " + FieldsList + " from " + TableName + " " + whereStr
response.write " <br><br> "
' --画出表格
response.write " <font style='color:blue;font-weight:bold'>未来数据:</font> "
response.write " <font class='f2'>Set字句为: " + setStr + " </font> "
response.write " <br><br> "
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br><br> "
else
response.write " 当set字句没有个逗号(,),只有一个等号(=)时,可以进行未来数据分析,且可以预览 "
end if
querystring = " ?action=update2 "
response.write " <p align='center'> "
response.write " <a href='#' οnclick='update2Submit()'>[确认无误,执行查询]</a> "
response.write " <a href='javascript:history.back(-1)'>[取消更新,返回]</a> "
response.write " </p> "
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据更新 第二步 |*******************
' *******************----------------*********************
if Action = " update2 " then
on error resume next
' 各字句的划分
sql = trim (sql)
setPos = instr ( ucase (sql), ucase ( " set " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
setStr = trim ( mid (sql,setPos,wherePos - setPos))
whereStr = trim ( mid (sql,wherePos, len (sql)))
TableName = trim ( mid (sql, 7 ,setPos - 6 ))
response.write sql + " <br><br> "
conn.execute(sql)
if err.number = 0 then
response.write " <font color='red'>更新记录操作成功!</font><br><br> "
response.write " <font color='blue'>表 " + trim (TableName) + " 更新后的记录内容为:</font><br> "
tmpsql = " select * from " + TableName + " " + whereStr
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br> "
response.write " <p align='center'><a href='index.asp'>[返回]</a></p> "
end if
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据删除 |*******************
' *******************----------------*********************
if Action = " delete " then
on error resume next
response.write " <form method='post' action='Query.asp' name='DetailForm'> " ' 写form
response.write " <input name='action' type='hidden' value='delete2'> "
response.write " <input name='QueryText' type='hidden' value= " + chr ( 34 ) + sql + chr ( 34 ) + " > "
' 各字句的划分
sql = trim (sql)
wherePos = instr ( ucase (sql), ucase ( " where " ))
fromPos = instr ( ucase (sql), ucase ( " from " ))
if wherePos = 0 then
TableName = trim ( mid (sql,fromPos + 5 , len (sql)))
tmpSql = " select * from " + TableName
tmpCountSql = " select Count(*) from " + TableName
else
TableName = trim ( mid (sql,fromPos + 5 ,wherePos - fromPos - 4 ))
whereStr = mid (sql,wherePos, len (sql))
tmpSql = " select * from " + TableName + " " + whereStr
tmpCountSql = " select Count(*) from " + TableName + " " + whereStr
end if
set rs = conn.execute(tmpCountSql)
deleteRecordCount = cstr (rs( 0 ))
rs.close
set rs = nothing
response.write " 查除SQL为: "
response.write " <font class='f2'> " + sql + " </font><br><br> "
response.write " <font style='color:red'>删除的数据内容如下:(共计: " + deleteRecordCount + " 条记录)</font> "
if wherePos = 0 then
response.write " <a href='javascript:history.back(-1)'>[**没有设置Where字句,返回设置**]</a> "
end if
response.write " <br> "
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><p align='center'><a href='#' οnclick='delete2Submit()'>[确认删除]</a> <a href='#' οnclick='history.back(-1)'>[返回]</a></p> "
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 删除 第二步 |*********************
' *******************----------------*********************
if Action = " delete2 " then
on error resume next
response.write sql + " <br><br> "
conn.execute ( trim (sql))
if err.number = 0 then
response.write " <p align='center'> "
response.write " <a href='index.asp'>[数据删除完成,返回]</a> "
response.write " </p> "
end if
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href='index.asp' style='color:red'>SQL数据删除完成,返回</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 表结构 |*********************
' *******************----------------*********************
function getType(num)
getType = num
select case num
case " 202 " :
getType = " 文本 "
case " 203 " :
getType = " 备注 "
case " 3 " :
getType = " 长整型 "
case " 2 " :
getType = " 整型 "
case " 17 " :
getType = " 字节 "
case " 3 " :
getType = " 长整型 "
case " 4 " :
getType = " 单精浮点 "
case " 5 " :
getType = " 双精浮点 "
case " 3 " :
getType = " 长整型 "
case " 72 " :
getType = " 同步复制ID "
case " 131 " :
getType = " 小数 "
case " 135 " :
getType = " 日期/时间 "
case " 6 " :
getType = " 货币 "
case " 11 " :
getType = " 是/否 "
case " 205 " :
getType = " OLE对象 "
end select
end function
if Action = " structure " then
on error resume next
response.write " 表: " + sql + " <br><br> "
set rs = conn.execute ( trim (sql))
response.write " <table style='border-collapse: collapse;' cellpadding='3'> "
response.write " <tr> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>字段名</font></td> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>类型</font></td> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>字段大小</font></td> "
response.write " </tr> "
for each field in rs.fields
response.write " <tr> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write field.name
response.write " </font> "
response.write " </td> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write getType(field.type )
response.write " </font> "
response.write " </td> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write field.DefinedSize
response.write " </font> "
response.write " </td> "
response.write " </tr> "
next
response.write " </table> "
rs.close
set rs = nothing
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()' style='color:red'>得到表结构失败,关闭</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| SQL强执行 |*********************
' *******************----------------*********************
if Action = " GouInSQL " then
on error resume next
response.write sql + " <br><br> "
conn.execute ( trim (sql))
if err.number = 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()'>[SQL强执行成功,关闭]</a> "
response.write " </p> "
end if
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()' style='color:red'>SQL强执行失败,关闭</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
% >
< script type = " text/javascript " >
TableName = " <%=trim(replace(TableName,chr(10),""))%> " ;
</ script >
</ body >
</ html >
< ! -- #include file = conn.asp -->
< %
Response.Buffer = True
Response.ExpiresAbsolute = Now () - 1
Response.Expires = 0
Response.CacheControl = " no-cache "
Response.AddHeader " Pragma " , " No-Cache " ' 以上代码防止使用缓存
Action = request( " Action " )
SQL = trim (request( " QueryText " ))
' response.write sql
select case Action
case " select " ' 简单查询、单表查询
title = " Select查询 "
case " update "
title = " Update更新--第一步,确认 "
case " update2 "
title = " update更新--第二步,更新完成 "
case " delete "
title = " Delete删除--第一步,确认 "
case " delete2 "
title = " Delete删除--第二步,删除完成 "
case " GouInSQL "
title = " 强制执行SQL "
case " structure "
title = " 得到表 " + sql + " 结构 "
end select
% >
< html >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " >
< title >< % = title% ></ title >
< style type = " text/css " >
.f1{
font - size:9pt;
color:black;
font - family:宋体;
}
.f2{
font - size:9pt;
color:# 929292 ;
font - family:宋体;
}
.f3{
font - size:9pt;
color:# 000000 ;
font - family:宋体;
font - weight:bold;
}
a{
font - size:9pt;
color:blue;
font - family:宋体;
text - decoration:none;
}
.style1 {
border - collapse: collapse;
border: 1px solid # 000000 ;
}
</ style >
< script type = " text/javascript " >
function showDetail(objId)
{
obj = document.getElementById(objId);
str = obj.innerHTML;
document.DetailForm.action = " ViewDetail.asp " ;
document.DetailForm.AllText.value = str;
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.DetailForm.target = winName;
document.DetailForm.submit();
}
function setSQLTextSubmit(sql,querystring)
{
document.DetailForm.QueryText.value = sql;
document.DetailForm.action = " Query.asp " + querystring;
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
function update2Submit()
{
alert( " 请在更新前备份数据库! " );
if (confirm( " 更新数据后不可恢复,是否确认更新数据? " ))
{
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
}
function delete2Submit()
{
alert( " 请在删除前备份数据库! " );
if (confirm( " 删除后不可恢复,确认删除数据? " ))
{
document.DetailForm.target = window.name;
document.DetailForm.submit();
}
}
/******************************
***** SQL生成控制面版 函数 *******
*******************************/
var TableName = "" ; // 当前表名
var CurrentSubText = "" ; // 当前设置子句
function showSqlPane() // 显示、关闭面版
{
if (document.getElementById( " ControlPane " ).style.display == ' block')
{
document.getElementById( " ControlPane " ).style.display = ' none';
}
else
{
document.getElementById( " ControlPane " ).style.display = " block " ;
}
}
function actionSelectChage() // 选择Radio
{
if (document.getElementById( " actionSelect " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = false ;
document.ControlPaneForm.SubSQLOrder.disabled = false ;
document.ControlPaneForm.SetText.disabled = true ;
document.ControlPaneForm.SubSQLSet.disabled = true ;
}
if (document.getElementById( " actionUpdate " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = true ;
document.ControlPaneForm.SubSQLOrder.disabled = true ;
document.ControlPaneForm.SetText.disabled = false ;
document.ControlPaneForm.SubSQLSet.disabled = false ;
}
if (document.getElementById( " actionDelete " ).checked)
{
document.ControlPaneForm.WhereText.disabled = false ;
document.ControlPaneForm.SubSQLWhere.disabled = false ;
document.ControlPaneForm.OrderText.disabled = true ;
document.ControlPaneForm.SubSQLOrder.disabled = true ;
document.ControlPaneForm.SetText.disabled = true ;
document.ControlPaneForm.SubSQLSet.disabled = true ;
}
}
function chooseTitle(type) // 选择子句
{
CurrentSubText = type;
obj = document.getElementById( " hinter " );
switch(type)
{
case " where " :
obj.innerHTML = " 请设置 <Where> 字句字段,点击标题>> " ;
break;
case " order " :
obj.innerHTML = " 请设置 <Order> 字句字段,点击标题>> " ;
break;
case " set " :
obj.innerHTML = " 请设置 <Set> 字句字段,点击标题>> " ;
break;
case " clear " :
obj.innerHTML = "" ;
break;
}
}
function titleClick(title) // 选择字段
{
obj = document.getElementById( " hinter " );
switch(CurrentSubText)
{
case " where " :
obj.innerHTML = " 请设置 <Where> 字句字段,点击标题>> " ;
document.ControlPaneForm.WhereText.value = title + " = " ;
document.ControlPaneForm.WhereText.focus;
document.ControlPaneForm.WhereText.select();
obj.innerHTML = "" ;
break;
case " order " :
obj.innerHTML = " 请设置 <Order> 字句字段,点击标题>> " ;
document.ControlPaneForm.OrderText.value = title;
document.ControlPaneForm.OrderText.focus;
document.ControlPaneForm.OrderText.select();
obj.innerHTML = "" ;
break;
case " set " :
obj.innerHTML = " 请设置 <Set> 字句字段,点击标题>> " ;
document.ControlPaneForm.SetText.value = title + " = " ;
document.ControlPaneForm.SetText.focus;
document.ControlPaneForm.SetText.select();
obj.innerHTML = "" ;
break;
}
}
function establishSQL()
{
var sql = "" ;
if (document.getElementById( " actionSelect " ).checked) // select
{
sql = " select * from " + TableName;
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
if (document.ControlPaneForm.SubSQLOrder.checked)
{
sql += " order by " + document.ControlPaneForm.OrderText.value;
if (document.ControlPaneForm.orderDesc.checked)
{
sql += " Desc " ;
}
else
{
sql += " Asc " ;
}
}
}
if (document.getElementById( " actionUpdate " ).checked) // update
{
sql = " update " + TableName;
if (document.ControlPaneForm.SubSQLSet.checked)
{
sql += " set " + document.ControlPaneForm.SetText.value;
}
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
}
if (document.getElementById( " actionDelete " ).checked) // delete
{
sql = " delete from " + TableName;
if (document.ControlPaneForm.SubSQLWhere.checked)
{
sql += " where " + document.ControlPaneForm.WhereText.value;
}
}
document.ControlPaneForm.QueryText.value = sql;
}
function returnSQL()
{
obj = window.opener.document.getElementById( " QueryText " );
obj.value = document.ControlPaneForm.QueryText.value;
}
function runSQL(IfNewWindow)
{
document.ControlPaneForm.QueryText.value = document.ControlPaneForm.QueryText.value.replace( /^ s */ , "" ); // 去左空格
document.ControlPaneForm.QueryText.value = document.ControlPaneForm.QueryText.value.replace( / s * $ / , "" ); // 去右空格
str = document.ControlPaneForm.QueryText.value;
if (str.length < 7 )
{
alert( " 请输入正常的SQL! " );
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
if (str.indexOf( " ; " ) >= 0 )
{
alert( " 正常的SQL中不应包含';'! " );
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
if (str.indexOf( " "")>=0)
{
alert( " 正常的SQL中不应包含' " ' !");
document.ControlPaneForm.QueryText.select();
document.ControlPaneForm.QueryText.focus();
return;
}
queryType = str.substr( 0 , 6 ).toLowerCase();
switch(queryType)
{
case " select " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=select " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=select " ;
document.ControlPaneForm.submit();
}
break;
case " update " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=update " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=update " ;
document.ControlPaneForm.submit();
}
break;
case " delete " :
if (IfNewWindow == 0 )
{
document.ControlPaneForm.action = " Query.asp?action=delete " ;
document.ControlPaneForm.target = window.name;
document.ControlPaneForm.submit();
}
else
{
var winName = (Math.round(Math.random() * 1000 )).toString();
window.open( "" ,winName);
document.ControlPaneForm.target = winName;
document.ControlPaneForm.action = " Query.asp?action=delete " ;
document.ControlPaneForm.submit();
}
break;
}
}
</ script >
</ head >
< body class = " f1 " >
< form name = " ControlPaneForm " action = " query.asp " method = " post " >
< div id = " ControlPane " style = " <%= " display:none; " %> " >
SQL生成控制面版: < font id = " hinter " style = " color:red;font-size:9pt;font-weight:bold; " ></ font >
< table style = " width: 100% " cellspacing = " 3 " cellpadding = " 4 " class = " style1 " >
< tr >
< td style = " border: 1px solid #000000; width: 70px; " valign = " top " >
< table style = " width: 100% " >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " select " name = " sqlType " id = " actionSelect " onclick = " actionSelectChage() " >< label for = " actionSelect " class = " f1 " > SELECT </ label >
</ td >
</ tr >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " Update " name = " sqlType " id = " actionUpdate " onclick = " actionSelectChage() " >< label for = " actionUpdate " class = " f1 " > UPDATE </ label >
</ td >
</ tr >
< tr >
< td style = " text-align: center " >
< input type = " radio " value = " Delete " name = " sqlType " id = " actionDelete " onclick = " actionSelectChage() " >< label for = " actionDelete " class = " f1 " > DELETE </ label >
</ td >
</ tr >
</ table >
</ td >
< td style = " width: 360px " >
< table style = " width: 100% " >
< tr >
< td style = " width: 80px " >
< input type = " checkbox " name = " SubSQL " id = " SubSQLWhere " disabled = " disabled " onclick = " if (this.checked){chooseTitle('where');} else {chooseTitle('clear')} " >< label for = " SubSQLWhere " class = " f1 " > Where子句 </ label >
</ td >
< td >
< input type = " text " name = " WhereText " size = " 40 " disabled = " disabled " >
</ td >
</ tr >
< tr >
< td >
< input type = " checkbox " name = " SubSQL " id = " SubSQLOrder " disabled = " disabled " onclick = " if (this.checked){chooseTitle('order');} else {chooseTitle('clear')} " >< label for = " SubSQLOrder " class = " f1 " > Order子句 </ label >
</ td >
< td >
< input type = " text " name = " OrderText " size = " 20 " disabled = " disabled " >
< input type = " radio " name = " orderType " id = " orderAsc " >< label for = " orderAsc " class = " f1 " > 升序 </ label >
< input type = " radio " name = " orderType " id = " orderDesc " checked = " checked " >< label for = " orderDesc " class = " f1 " > 降序 </ label >
</ td >
</ tr >
< tr >
< td >
< input type = " checkbox " name = " SubSQL " id = " SubSQLSet " disabled = " disabled " onclick = " if (this.checked){chooseTitle('set');} else {chooseTitle('clear')} " >< label for = " SubSQLSet " class = " f1 " > Set子句 </ label >
</ td >
< td >
< input type = " text " name = " SetText " size = " 40 " disabled = " disabled " ></ td >
</ tr >
</ table >
</ td >
< td style = " width: 40px " >
< input type = " button " value = " 生成SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " establishSQL() " >
< input type = " button " value = " 返回SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " returnSQL() " >
< input type = " button " value = " 运行SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " runSQL(0) " >
< input type = " button " value = " 新开SQL " style = " width:60px;height:25px;font-size:9pt; " onclick = " runSQL(1) " >
</ td >
< td >
< textarea name = " QueryText " style = " height: 76px; width: 441px " ></ textarea >
</ td >
</ tr >
</ table >
</ div >
</ form >
< %
function CutString(str) ' 截取字符串
if len (str) > 40 then
' 存字符串
Randomize
SaveId = cstr ( int ( rnd () * 10000 )) + cstr ( int ( rnd () * 10000 )) + cstr ( int ( rnd () * 10000 )) ' 防止ID重复
SaveString = " <font id=' " + SaveId + " ' style='display:none'> " + str + " </font> "
' 显示部份内容及超链
CutString = left (str, 30 )
CutString = CutString + " ... "
CutString = CutString + " <a href='javascript:' οnclick='showDetail( " + chr ( 34 ) + SaveId + chr ( 34 ) + " )'> "
CutString = CutString + " [未完,查看全部] "
CutString = CutString + " </a> "
CutString = CutString + SaveString
else
CutString = Str
end if
end function
Function FormatHTML(fString) ' 过滤特殊字符
If fString <> "" Then
fString = trim (fString)
fString = replace (fString, " ; " , " ; " ) ' 分号过滤
fString = replace (fString, " -- " , " —— " ) ' --过滤
fString = replace (fString, " %20 " , "" ) ' 特殊字符过滤
fString = replace (fString, " == " , "" ) ' ==过滤
fString = replace (fString, " > " , " > " )
fString = replace (fString, " < " , " < " )
fString = Replace (fString, CHR ( 32 ), " " ) '
fString = Replace (fString, CHR ( 9 ), " " ) '
fString = Replace (fString, CHR ( 34 ), " " " )
fString = Replace (fString, CHR ( 39 ), " ' " ) ' 单引号过滤
fString = Replace (fString, CHR ( 13 ), "" )
fString = Replace (fString, CHR ( 10 ) & CHR ( 10 ), " </P><P> " )
fString = Replace (fString, CHR ( 10 ), " <BR> " )
FormatHTML = fString
End If
End Function
Function WriteFieldRecord(sql) ' 写表格函数
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
strTmp = ""
strTmp = strTmp + " <table style='width: 100%;border-collapse: collapse;' cellpadding='3'> "
strTmp = strTmp + " <tr> "
' **写字段名**
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap> "
strTmp = strTmp + " <font class='f3'> "
if ( instr (rs.fields(i).name, " * " ) > 0 ) then
strTmp = strTmp + " <font color='red'> " + rs.fields(i).name + " </font> "
else
strTmp = strTmp + rs.fields(i).name
end if
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
strTmp = strTmp + " </tr> "
' **写记录**
do while not rs.eof
strTmp = strTmp + " <tr> "
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000; ' nowrap> "
strTmp = strTmp + " <font class='f1'> "
strTmp = strTmp + CutString(FormatHTML(rs(i)))
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
rs.movenext
strTmp = strTmp + " </tr> "
loop
strTmp = strTmp + " </table> "
rs.close
set rs = nothing
WriteFieldRecord = strTmp
End Function
Function WriteFieldRecord2(sql) ' 写表格函数2 写标题点击函数
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
strTmp = ""
strTmp = strTmp + " <table style='width: 100%;border-collapse: collapse;' cellpadding='3'> "
strTmp = strTmp + " <tr> "
' **写字段名**
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;cursor:pointer' align='center' nowrap οnclick='titleClick( " + chr ( 34 ) + rs.fields(i).name + chr ( 34 ) + " )'> "
strTmp = strTmp + " <font class='f3'> "
if ( instr (rs.fields(i).name, " * " ) > 0 ) then
strTmp = strTmp + " <font color='red'> " + rs.fields(i).name + " </font> "
else
strTmp = strTmp + rs.fields(i).name
end if
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
strTmp = strTmp + " </tr> "
' **写记录**
do while not rs.eof
strTmp = strTmp + " <tr> "
for i = 0 to FieldsCount - 1
strTmp = strTmp + " <td style='height: 23px; border: 1px solid #000000; ' nowrap> "
strTmp = strTmp + " <font class='f1'> "
strTmp = strTmp + CutString(FormatHTML(rs(i)))
strTmp = strTmp + " </font> "
strTmp = strTmp + " </td> "
next
rs.movenext
strTmp = strTmp + " </tr> "
loop
strTmp = strTmp + " </table> "
rs.close
set rs = nothing
WriteFieldRecord2 = strTmp
End Function
' *******************----------------*********************
' ******************|简单查询、单表查询|*********************
' *******************----------------*********************
if Action = " select " then
on error resume next
fromPos = instr ( ucase (sql), ucase ( " from " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
if wherePos = 0 then
TableName = trim ( mid (sql,fromPos + 5 , len (sql)))
else
TableName = trim ( mid (sql,fromPos + 5 ,wherePos - fromPos - 4 ))
end if
set rs = server.createobject( " adodb.recordset " )
rs.open sql,conn, 1
FieldsCount = rs.fields.count
RecordCount = rs.recordcount
response.write " <form method='post' action='ViewDetail.asp' name='DetailForm'> " ' 用来查询显示不全的字段内容
response.write " <input name='AllText' type='hidden'> "
response.write " <input name='QueryText' type='hidden'> "
response.write " 查询的SQL为: "
response.write " <font class='f2'> " & SQL & " </font> "
response.write " <br><br> "
response.write " 共有记录数:<font color='red'> " & cstr (RecordCount) & " </font> "
response.write " <a href='javascript:' οnclick='showSqlPane()'>[打开/关闭SQL生成控制面版]</a> "
response.write " <a href='javascript:history.back(-1)'>[返回]</a> "
response.write " <a href='#' οnclick='window.close()'>[关闭]</a><br><br> "
if request.querystring( " Continue " ) <> " 1 " then
if recordcount > 100 then
response.write " <font color='red'>一次性查询数据最好不要超过100条,请选择:</font> "
sqltmp = " select top 10 " + mid (sql, 7 , len (sql))
querystring = " ?Action=select "
response.write " <a href=# οnclick='setSQLTextSubmit( " + chr ( 34 ) + sqltmp + chr ( 34 ) + " , " + chr ( 34 ) + querystring + chr ( 34 ) + " )'>[查询前10条数据]</a> "
response.write " "
querystring = " ?Action=select&Continue=1 "
response.write " <a href='#' οnclick='setSQLTextSubmit( " + chr ( 34 ) + sql + chr ( 34 ) + " , " + chr ( 34 ) + querystring + chr ( 34 ) + " )'>[继续查询]</a> "
response.end
end if
end if
strTmp = WriteFieldRecord2(sql) ' 调用画表格函数
response.write strTmp
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据更新 |*********************
' *******************----------------*********************
if Action = " update " then
on error resume next
response.write " <form method='post' action='Query.asp' name='DetailForm'> " ' 用来查询显示不全的字段内容
response.write " <input name='AllText' type='hidden'> "
response.write " <input name='action' type='hidden' value='update2'> "
response.write sql
response.write " <input name='QueryText' type='hidden' value= " + chr ( 34 ) + sql + chr ( 34 ) + " > "
response.write " 查询的SQL为: "
response.write " <font class='f2'> " & SQL & " </font><br><br> "
' 各字句的划分
sql = trim (sql)
setPos = instr ( ucase (sql), ucase ( " set " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
setStr = trim ( mid (sql,setPos,wherePos - setPos))
whereStr = trim ( mid (sql,wherePos, len (sql)))
TableName = trim ( mid (sql, 7 ,setPos - 6 ))
' 要更改的字段显示
response.write " <br><br> "
response.write " <font style='color:red;font-weight:bold'> "
response.write " 您要改的数据内容: "
response.write " </font> "
response.write " <font class='f2'>表名: " + TableName + " </font> "
response.write " <font class='f2'> 条件: " + whereStr + " </font> "
response.write " <font class='f2'>Set字句为: " + setStr + " </font> "
response.write " <br><br> "
tmpsql = " select * from " + TableName + whereStr ' 生成查询SQL
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br><br> "
' *******************************************************************
' *当set字句没有个逗号(,),只有一个等号(=)时,可以进行未来数据分析,且可以预览*
' *******************************************************************
denghaoOK = instr (setStr, " = " )
if denghaoOK > 0 then ' 是否只有一个等号,如果denghaoOK=True
if instr (denghaoOK + 1 ,setStr, " = " ) > 0 then
denghaoOK = false
else
denghaoOK = true
end if
else
denghaoOk = false
end if
if instr (setStr, " , " ) > 0 then ' 是否只有一个逗号,如果douhaoOK=True
douhaoOK = False
else
douhaoOK = true
end if
if douhaoOK and denghaoOK then
' 显示未来数据
' --要改的字段名及值
setFieldStr = trim ( mid (setStr, 4 , instr (setStr, " = " ) - 4 )) ' 要改的字段名
setValueStr = trim ( mid (setStr, instr (setStr, " = " ) + 1 , len (setStr))) ' 得到值
' --生成字段表
tmpsql = " select top 1 * from " + TableName + whereStr ' 生成查询SQL
set rs = server.createobject( " adodb.recordset " )
rs.open tmpsql,conn, 1
FieldsList = ""
for each field in rs.fields
if ucase (setFieldStr) = ucase (field.name) then
FieldsList = FieldsList + " ( " + setValueStr + " ) as [* " + field.name + " *], "
else
FieldsList = FieldsList + field.name + " , "
end if
next
FieldsList = left (FieldsList, len (FieldsList) - 1 )
rs.close
set rs = nothing
' --生成SQL
tmpsql = " select " + FieldsList + " from " + TableName + " " + whereStr
response.write " <br><br> "
' --画出表格
response.write " <font style='color:blue;font-weight:bold'>未来数据:</font> "
response.write " <font class='f2'>Set字句为: " + setStr + " </font> "
response.write " <br><br> "
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br><br> "
else
response.write " 当set字句没有个逗号(,),只有一个等号(=)时,可以进行未来数据分析,且可以预览 "
end if
querystring = " ?action=update2 "
response.write " <p align='center'> "
response.write " <a href='#' οnclick='update2Submit()'>[确认无误,执行查询]</a> "
response.write " <a href='javascript:history.back(-1)'>[取消更新,返回]</a> "
response.write " </p> "
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据更新 第二步 |*******************
' *******************----------------*********************
if Action = " update2 " then
on error resume next
' 各字句的划分
sql = trim (sql)
setPos = instr ( ucase (sql), ucase ( " set " ))
wherePos = instr ( ucase (sql), ucase ( " where " ))
setStr = trim ( mid (sql,setPos,wherePos - setPos))
whereStr = trim ( mid (sql,wherePos, len (sql)))
TableName = trim ( mid (sql, 7 ,setPos - 6 ))
response.write sql + " <br><br> "
conn.execute(sql)
if err.number = 0 then
response.write " <font color='red'>更新记录操作成功!</font><br><br> "
response.write " <font color='blue'>表 " + trim (TableName) + " 更新后的记录内容为:</font><br> "
tmpsql = " select * from " + TableName + " " + whereStr
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><br> "
response.write " <p align='center'><a href='index.asp'>[返回]</a></p> "
end if
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 数据删除 |*******************
' *******************----------------*********************
if Action = " delete " then
on error resume next
response.write " <form method='post' action='Query.asp' name='DetailForm'> " ' 写form
response.write " <input name='action' type='hidden' value='delete2'> "
response.write " <input name='QueryText' type='hidden' value= " + chr ( 34 ) + sql + chr ( 34 ) + " > "
' 各字句的划分
sql = trim (sql)
wherePos = instr ( ucase (sql), ucase ( " where " ))
fromPos = instr ( ucase (sql), ucase ( " from " ))
if wherePos = 0 then
TableName = trim ( mid (sql,fromPos + 5 , len (sql)))
tmpSql = " select * from " + TableName
tmpCountSql = " select Count(*) from " + TableName
else
TableName = trim ( mid (sql,fromPos + 5 ,wherePos - fromPos - 4 ))
whereStr = mid (sql,wherePos, len (sql))
tmpSql = " select * from " + TableName + " " + whereStr
tmpCountSql = " select Count(*) from " + TableName + " " + whereStr
end if
set rs = conn.execute(tmpCountSql)
deleteRecordCount = cstr (rs( 0 ))
rs.close
set rs = nothing
response.write " 查除SQL为: "
response.write " <font class='f2'> " + sql + " </font><br><br> "
response.write " <font style='color:red'>删除的数据内容如下:(共计: " + deleteRecordCount + " 条记录)</font> "
if wherePos = 0 then
response.write " <a href='javascript:history.back(-1)'>[**没有设置Where字句,返回设置**]</a> "
end if
response.write " <br> "
strTmp = WriteFieldRecord(tmpsql) ' 调用画表格函数
response.write strTmp
response.write " <br><p align='center'><a href='#' οnclick='delete2Submit()'>[确认删除]</a> <a href='#' οnclick='history.back(-1)'>[返回]</a></p> "
response.write " </form> "
if err.number <> 0 then
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 删除 第二步 |*********************
' *******************----------------*********************
if Action = " delete2 " then
on error resume next
response.write sql + " <br><br> "
conn.execute ( trim (sql))
if err.number = 0 then
response.write " <p align='center'> "
response.write " <a href='index.asp'>[数据删除完成,返回]</a> "
response.write " </p> "
end if
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href='index.asp' style='color:red'>SQL数据删除完成,返回</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| 表结构 |*********************
' *******************----------------*********************
function getType(num)
getType = num
select case num
case " 202 " :
getType = " 文本 "
case " 203 " :
getType = " 备注 "
case " 3 " :
getType = " 长整型 "
case " 2 " :
getType = " 整型 "
case " 17 " :
getType = " 字节 "
case " 3 " :
getType = " 长整型 "
case " 4 " :
getType = " 单精浮点 "
case " 5 " :
getType = " 双精浮点 "
case " 3 " :
getType = " 长整型 "
case " 72 " :
getType = " 同步复制ID "
case " 131 " :
getType = " 小数 "
case " 135 " :
getType = " 日期/时间 "
case " 6 " :
getType = " 货币 "
case " 11 " :
getType = " 是/否 "
case " 205 " :
getType = " OLE对象 "
end select
end function
if Action = " structure " then
on error resume next
response.write " 表: " + sql + " <br><br> "
set rs = conn.execute ( trim (sql))
response.write " <table style='border-collapse: collapse;' cellpadding='3'> "
response.write " <tr> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>字段名</font></td> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>类型</font></td> "
response.write " <td style='height: 23px; border: 1px solid #000000;background-color: #EEEEEE;' align='center' nowrap><font class='f3'>字段大小</font></td> "
response.write " </tr> "
for each field in rs.fields
response.write " <tr> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write field.name
response.write " </font> "
response.write " </td> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write getType(field.type )
response.write " </font> "
response.write " </td> "
response.write " <td style='height: 23px; border: 1px solid #000000;' align='center' nowrap> "
response.write " <font class='f1'> "
response.write field.DefinedSize
response.write " </font> "
response.write " </td> "
response.write " </tr> "
next
response.write " </table> "
rs.close
set rs = nothing
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()' style='color:red'>得到表结构失败,关闭</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
' *******************----------------*********************
' ******************| SQL强执行 |*********************
' *******************----------------*********************
if Action = " GouInSQL " then
on error resume next
response.write sql + " <br><br> "
conn.execute ( trim (sql))
if err.number = 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()'>[SQL强执行成功,关闭]</a> "
response.write " </p> "
end if
if err.number <> 0 then
response.write " <p align='center'> "
response.write " <a href=# οnclick='window.close()' style='color:red'>SQL强执行失败,关闭</a> "
response.write " </p> "
response.write " 错误信息:<font color=red> " + err.description + " </font> "
end if
end if
' ******************| THE END |********************
% >
< script type = " text/javascript " >
TableName = " <%=trim(replace(TableName,chr(10),""))%> " ;
</ script >
</ body >
</ html >
ViewDetail.asp代码:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title > 查看内容 </ title >
< style type ="text/css" >
.f1 {
font-size : 9pt ;
color : black ;
font-family : 宋体 ;
}
.f2 {
font-size : 9pt ;
color : #929292 ;
font-family : 宋体 ;
}
.f3 {
font-size : 9pt ;
color : #000000 ;
font-family : 宋体 ;
font-weight : bold ;
}
a {
font-size : 9pt ;
color : blue ;
font-family : 宋体 ;
text-decoration : none ;
}
</ style >
</ head >
< body >
< p style ="text-align:center" >< a href ="javascript:window.close()" > [关闭] </ a ></ p >
< table style ="width: 100%" cellspacing ="3" cellpadding ="4" >
< tr >
< td style ="width: 10%" > </ td >
< td >
< font class ="f1" >
<% = request( " AllText " ) %>
</ font >
</ td >
< td style ="width: 10%" > </ td >
</ tr >
</ table >
< p style ="text-align:center" >< a href ="javascript:window.close()" > [关闭] </ a ></ p >
</ body >
</ html >
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title > 查看内容 </ title >
< style type ="text/css" >
.f1 {
font-size : 9pt ;
color : black ;
font-family : 宋体 ;
}
.f2 {
font-size : 9pt ;
color : #929292 ;
font-family : 宋体 ;
}
.f3 {
font-size : 9pt ;
color : #000000 ;
font-family : 宋体 ;
font-weight : bold ;
}
a {
font-size : 9pt ;
color : blue ;
font-family : 宋体 ;
text-decoration : none ;
}
</ style >
</ head >
< body >
< p style ="text-align:center" >< a href ="javascript:window.close()" > [关闭] </ a ></ p >
< table style ="width: 100%" cellspacing ="3" cellpadding ="4" >
< tr >
< td style ="width: 10%" > </ td >
< td >
< font class ="f1" >
<% = request( " AllText " ) %>
</ font >
</ td >
< td style ="width: 10%" > </ td >
</ tr >
</ table >
< p style ="text-align:center" >< a href ="javascript:window.close()" > [关闭] </ a ></ p >
</ body >
</ html >