分享
 
 
 

数据库的Query Analyzer

王朝asp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

数据库的Query Analyzer

2001年7月6日 10:45:33·徐长友·http://yousoft.home.chinaren.com

很多人一定用过Query Analyzer,这个工具的功能如何如何,就不用我说了,这次给大家介绍下Web下的Query Analyzer,界面如图1,使用ASP写的。

(图1)

源程序如下:

<%

dim conn

dim connstr

on error resume next

if request("selectdb")="mdb" then

if request("dbname")<>"" then

connstr="DBQ="+server.mappath(request("dbname"))+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

set conn=server.createobject("ADODB.CONNECTION")

if err.number<>0 then

err.clear

set conn=nothing

response.write "错误:数据库连接出错!"

else

if request("dbpass")<>"" then

conn.open connstr

else

Conn.Open connstr,"admin",request("dbpass")

end if

if err then

set conn=nothing

response.write "错误:数据库连接出错!!!<br>" + err.description

err.clear

end if

end if

end if

elseif request("selectdb")="mssql" then

if request("dbname")<>"" then

connstr = "Provider=SQLOLEDB.1"

connstr = connstr & ";Data Source=" & request("sqlip") 'sql_server数据库

connstr = connstr & ";User ID=" & request("sqladmin") '数据库服务器用户

connstr = connstr & ";Password=" & request("sqlpass") '登录口令

connstr = connstr & ";Initial Catalog=" & request("sqldb") '数据库名

set conn=server.createobject("ADODB.CONNECTION")

if err.number<>0 then

err.clear

set conn=nothing

response.write "错误:数据库连接出错!"

else

conn.open connstr

if err then

set conn=nothing

response.write "错误:数据库连接出错!!!<br>" + err.description

err.clear

end if

end if

end if

end if

sub endConnection()

conn.close

set conn=nothing

end sub

%>

<HTML>

<HEAD>

<TITLE>Query Analyzer</TITLE>

<STYLE type=text/css>BODY {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}

P {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}

BR {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}

TD {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}

.p9 {FONT-SIZE: 9pt; LINE-HEIGHT: 14pt}

A:link {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}

A:visited {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}

A:hover {COLOR: #ff0000; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: underline}

.p105 {FONT-SIZE: 10.5pt}

INPUT.yellowbtn {BACKGROUND-COLOR: #88a3f2; COLOR: #000000; FONT-SIZE: 9pt}

</STYLE>

</HEAD>

<BODY BGCOLOR="#FFFFFF" topmargin="0">

<script language=JavaScript>

function setWB(x) {

document.main.whichbutton.value = x;

document.main.submit();

}

function showSQL(x) {

sqlvalue = document.main.sql.value;

if (x == 0) {

smsg = "\n怎样使用sql语句帮助:\n\n";

smsg = smsg + "1. 在选择框里选一个命令\n";

smsg = smsg + "2. 点击[显示]按钮\n";

smsg = smsg + "3. sql语句会显示在左边的文本框里面\n\n";

smsg = smsg + "4. 修改此语句来适合你数据库结构\n\n";

smsg = smsg + "5. 根据语句查询结果或执行命令\n\n";

alert(smsg); }

else if (x == 1) {

smsg = "SELECT columnName1, columnName2\n";

smsg = smsg + " FROM tableName\n";

smsg = smsg + " WHERE columnName = 'value'\n\n";

document.main.sql.value = smsg;

}

else if (x == 2) {

smsg = "INSERT INTO tableName\n";

smsg = smsg + " (columnName, IntegerColumnName)\n";

smsg = smsg + " VALUES ('value', numericValue)\n\n";

document.main.sql.value = smsg;

}

else if (x == 3) {

smsg = "UPDATE tableName\n";

smsg = smsg + " SET columnName = 'value'\n";

smsg = smsg + " WHERE columnName = 'value'\n\n";

document.main.sql.value = smsg;

}

else if (x == 4) {

smsg = "DELETE columnName\n";

smsg = smsg + " FROM tableName\n";

smsg = smsg + " WHERE columnName = 'value'\n\n";

document.main.sql.value = smsg;

}

else if (x == 5) {

smsg = "CREATE TABLE tableName\n";

smsg = smsg + " (columnName1 varchar(20),\n";

smsg = smsg + " columnName2 char(20),\n";

smsg = smsg + " columnName3 integer)\n\n";

document.main.sql.value = smsg;

}

else if (x == 6) {

smsg = "DROP TABLE tableName\n\n";

document.main.sql.value = smsg;

}

else if (x == 7) {

smsg = "SELECT a.columnName, b.columnName\n";

smsg = smsg + " FROM tableName a, tableName b\n";

smsg = smsg + " WHERE a.columnName = b.columnName\n\n";

document.main.sql.value = smsg;

}

}

function helpme(){

helpmsg="在上面的那个文本框输入一句sql语句,例如:\n\n";

helpmsg+="select * from tablename\n\n";

helpmsg+="如果需要查询结果,则按[查询结果],如果只\n";

helpmsg+="需执行一句sql语句,则按[执行sql语句],一\n";

helpmsg+="般select是用于查询的,update、delete、\n";

helpmsg+="create table等是用于执行的。\n\n";

helpmsg+="在sql语句帮助表里可以获得一些基本sql语句\n";

helpmsg+="的语法。";

alert(helpmsg);}

</script>

<form action="<%=request.servervariables("script_name")%>" method=post name=main>

<br>

<table border=0 cellpadding=2 cellspacing=2 width=100% align="center">

<tr bgcolor="#00CCFF">

<td width="157">

<input type="radio" name="selectdb" value="mdb" <%if request("selectdb")="mdb" then response.write "checked" %>>

MDB数据库</td>

<td width="588"> 数据库:

<input type="text" name="dbname" value="<%=request("dbname")%>">

(例如:db.mdb,或dir/db.mdb)<br>

密&nbsp;&nbsp;码:

<input type="password" name="dbpass" value="<%=request("dbpass")%>">

</td>

</tr>

<tr bgcolor="#00FFCC">

<td height="40" width="157">

<input type="radio" name="selectdb" value="mssql" <%if request("selectdb")="mssql" then response.write "checked" %>>

MS_SQLServer</td>

<td height="40" width="588"> 服务器:

<input type="text" name="sqlip" value="<%=request("sqlip")%>">

(SQLSERVER 的IP地址)<br>

数据库:

<input type="text" name="sqldb" value="<%=request("sqldb")%>">

<br>

登录名:

<input type="text" name="sqladmin" value="<%=request("sqladmin")%>">

<br>

密&nbsp;&nbsp;码:

<input type="password" name="sqlpass" value="<%=request("sqlpass")%>">

</td>

</tr>

<tr bgcolor="#33CCFF">

<td width="157" rowspan="2">

<table border=0 cellpadding=2 cellspacing=2

width="83%" align="center">

<tr>

<td align=center bgcolor=#00CCCC

valign=center>SQL向导</td>

</tr>

<tbody>

<tr>

<td align=left bgcolor=#00CCCC

valign=center>

<div align="center">

<select

name=sqlsyntax size=5>

<option selected>Choose SQL</option>

<option>Select</option>

<option>Insert</option>

<option>Update</option>

<option>Delete</option>

<option>Create Table</option>

<option>Drop Table</option>

<option>Simple Join</option>

</select>

</div>

</td>

</tr>

<tr>

<td align=left bgcolor=#00CCCC

valign=center>

<div align="center">

<input name=sqlasst1 onClick=showSQL(document.main.sqlsyntax.selectedIndex); type=button value="显示">

<input name=sqlasst2 onClick="document.main.sql.value='';" type=button value="清除">

</div>

</td>

</tr>

</table>

</td>

<td width="588"> SQL Query : </td>

</tr>

<tr>

<td width="588" align="center" bgcolor="#33CCFF">

<textarea cols=50 name=sql rows=12 wrap=VIRTUAL></textarea>

</td>

</tr>

<tr>

<td colspan="2">

<input name=whichbutton type=hidden value="NORS">

<input name=action2 type=hidden value=exec>

<input name=selindex type=hidden>

<b>

<input name=b1 class=yellowbtn onClick="setWB('GetRS');" type=button value="查询结果">

<input name=b2 class=yellowbtn onClick="setWB('NORS');" type=button value="执行SQL语句">

<input name=b3 class=yellowbtn onClick="helpme();" type="button" value="帮助">

</b> <b>

<script language=JavaScript>

document.main.sql.focus();

if (document.main.selindex.value != "") { document.main.db.options[document.main.selindex.value].selected = true; }

</script>

</b></td>

</tr>

</table>

<br>

</form>

<p>

<%

dim sql,rs

ifrs=request("whichbutton")

sql=request("sql")

if sql<>"" then

select case ifrs

case "NORS"

conn.execute sql

if err then

response.write "这句sql语句有错误,没有完全执行。<br>"&err.description&"<br>"&sql

else

response.write "执行成功!"

end if

case "GetRS"

set rs=server.createobject("adodb.recordset")

rs.open sql,conn,1,1

if err then

response.write "这句查询sql语句有错误,没有完全执行。<br>"&err.description&"<br>"&sql

else

response.write "找到了<b>"&cstr(rs.recordcount)&"</b>个结果"

%>

<table border="1" align="center">

<tr>

<%

colnum=rs.fields.count

for i=0 to rs.fields.count-1 %>

<td bgcolor="#33CCFF"><font color='red'><%=rs(i).name%></font></td>

<%next%>

</tr>

<%do while not rs.eof

k=0 %>

<tr>

<%for k=0 to colnum-1%>

<td><%=rs(rs(k).name)%></td>

<%next %>

</tr>

<% rs.movenext

loop

%>

</table>

<%

rs.close

set rs=Nothing

end if

end select

end if

endconnection

%>

</BODY>

</HTML>

Query Analyzer就这么简单,当然还需要改进,这就看你的了,呵呵...:)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有