在线数据库管理工具 db007 下载:http://www.jb51.net/codes/6195.html
复制代码 代码如下:
<>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>在线数据库管理工具db0071.5</title>
<styletype="text/css">
<>
</style>
</head>
<body>
<%
ifrequest("key")="db"then
session("dbtype")=request("dbtype")
session("dbstr")=request("dbstr")
response.redirect"?"
endif
ifrequest("key")="createdatabase"then
callcreatedatabase()
endif
ifsession("dbtype")=""orsession("dbstr")=""then
%>
<formaction="?key=db"method="post"name="dbt">
<br>
连接类型:
<inputname="dbtype"type="radio"value="access"onClick="dbstr.value='Provider=Microsoft.Jet.OLEDB.4.0;PersistSecurityInfo=False;Password=;DataSource=<%=server.mappath("/")&""%>'"checked>
ACCESS
<inputdisabled="disabled"type="radio"name="dbtype"value="sql"onClick="dbstr.value='driver={SQLServer};database=;Server=;uid=;pwd='">
SQL<br><br>
连接字符:<inputname="dbstr"type="text"id="dbstr"size="120"value="Provider=Microsoft.Jet.OLEDB.4.0;PersistSecurityInfo=False;Password=;DataSource=<%=server.mappath("/")&""%>">
<inputtype="submit"name="Submit"value="连接"/><br><br>
注:access请使用绝对路径,本文件路径:<%=server.MapPath("db007.asp")%>
</form>
<formname="createdatabase"method="post"action="?key=createdatabase">
<fontcolor=red>创建数据库:</font>路径
<inputname="dataname"type="text"value="<%=server.MapPath("/")&"database.mdb"%>"size="100">
<inputtype="submit"name="Submit"value="创建">
</form>
<%
response.End()
endif
'==================================================================建库
subcreatedatabase()
dimDBName,dbstr,myCat
onerrorresumenext
DBName=request("dataname")
dbstr="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATASOURCE="&DBName
SetmyCat=Server.CreateObject("ADOX.Catalog")
myCat.Createdbstr
iferr<>0then
response.writeerr.description
session("dbtype")=""
session("dbstr")=""
response.write"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
response.end
endif
session("dbtype")="access"
session("dbstr")=dbstr
response.redirect"?"
endsub
'==================================================================调用链接函数
conn()
functionconn()
dimconn1,connstr
onerrorresumenext
selectcasesession("dbtype")
case"access"
'==================================================================连接ACCESS数据库
connstr=session("dbstr")
SetConn1=Server.CreateObject("ADODB.Connection")
conn1.Openconnstr
case"sql"
'==================================================================连接SQL数据库
setconn1=Server.CreateObject("ADODB.Connection")
conn1.opensession("dbstr")
endselect
iferr<>0then
response.writeerr.description
session("dbtype")=""
session("dbstr")=""
response.write"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
response.end
endif
setconn=conn1
endfunction
Subecho(str)
Response.Write(str)
EndSub
FunctionIIf(var,val1,val2)
Ifvar=TrueThen
IIf=val1
Else
IIf=val2
EndIf
EndFunction
'正则表达式函数,用于删除注释
'-------------------------------------
FunctionRegExpReplace(strng,patrn,replStr)
DimregEx,match,matches'建立变量。
SetregEx=NewRegExp'建立正则表达式。
regEx.Pattern=patrn'设置模式。
regEx.IgnoreCase=True'设置是否区分大小写。
regEx.Global=True'设置全局可用性。
RegExpReplace=regEx.Replace(strng,replStr)'作替换。
EndFunction
'==================================================================ADOVBS常量声明
'----DataTypeEnumValues----
ConstadEmpty=0
ConstadTinyInt=16
ConstadSmallInt=2
ConstadInteger=3
ConstadBigInt=20
ConstadUnsignedTinyInt=17
ConstadUnsignedSmallInt=18
ConstadUnsignedInt=19
ConstadUnsignedBigInt=21
ConstadSingle=4
ConstadDouble=5
ConstadCurrency=6
ConstadDecimal=14
ConstadNumeric=131
ConstadBoolean=11
ConstadError=10
ConstadUserDefined=132
ConstadVariant=12
ConstadIDispatch=9
ConstadIUnknown=13
ConstadGUID=72
ConstadDate=7
ConstadDBDate=133
ConstadDBTime=134
ConstadDBTimeStamp=135
ConstadBSTR=8
ConstadChar=129
ConstadVarChar=200
ConstadLongVarChar=201
ConstadWChar=130
ConstadVarWChar=202
ConstadLongVarWChar=203
ConstadBinary=128
ConstadVarBinary=204
ConstadLongVarBinary=205
'----FieldAttributeEnumValues----
ConstadFldMayDefer=&H00000002
ConstadFldUpdatable=&H00000004
ConstadFldUnknownUpdatable=&H00000008
ConstadFldFixed=&H00000010
ConstadFldIsNullable=&H00000020
ConstadFldMayBeNull=&H00000040
ConstadFldLong=&H00000080
ConstadFldRowID=&H00000100
ConstadFldRowVersion=&H00000200
ConstadFldCacheDeferred=&H00001000
'----SchemaEnumValues----
'----SchemaEnumValues----
ConstadSchemaProviderSpecific=-1
ConstadSchemaAsserts=0
ConstadSchemaCatalogs=1
ConstadSchemaCharacterSets=2
ConstadSchemaCollations=3
ConstadSchemaColumns=4
ConstadSchemaCheckConstraints=5
ConstadSchemaConstraintColumnUsage=6
ConstadSchemaConstraintTableUsage=7
ConstadSchemaKeyColumnUsage=8
ConstadSchemaReferentialConstraints=9
ConstadSchemaTableConstraints=10
ConstadSchemaColumnsDomainUsage=11
ConstadSchemaIndexes=12
ConstadSchemaColumnPrivileges=13
ConstadSchemaTablePrivileges=14
ConstadSchemaUsagePrivileges=15
ConstadSchemaProcedures=16
ConstadSchemaSchemata=17
ConstadSchemaSQLLanguages=18
ConstadSchemaStatistics=19
ConstadSchemaTables=20
ConstadSchemaTranslations=21
ConstadSchemaProviderTypes=22
ConstadSchemaViews=23
ConstadSchemaViewColumnUsage=24
ConstadSchemaViewTableUsage=25
ConstadSchemaProcedureParameters=26
ConstadSchemaForeignKeys=27
ConstadSchemaPrimaryKeys=28
ConstadSchemaProcedureColumns=29
ConstadSchemaDBInfoKeywords=30
ConstadSchemaDBInfoLiterals=31
ConstadSchemaCubes=32
ConstadSchemaDimensions=33
ConstadSchemaHierarchies=34
ConstadSchemaLevels=35
ConstadSchemaMeasures=36
ConstadSchemaProperties=37
ConstadSchemaMembers=38
ConstadSchemaTrustees=39
ConstadSchemaFunctions=40
ConstadSchemaActions=41
ConstadSchemaCommands=42
ConstadSchemaSets=43
'==================================================================返回字段类型函数
Functiontyp(field_type)
'field_type=字段类型值
SelectCasefield_type
caseadEmpty:typ="Empty"
caseadTinyInt:typ="TinyInt"
caseadSmallInt:typ="SmallInt"
caseadInteger:typ="Integer"
caseadBigInt:typ="BigInt"
caseadUnsignedTinyInt:typ="TinyInt"'UnsignedTinyInt
caseadUnsignedSmallInt:typ="UnsignedSmallInt"
caseadUnsignedInt:typ="UnsignedInt"
caseadUnsignedBigInt:typ="UnsignedBigInt"
caseadSingle:typ="Single"'Single
caseadDouble:typ="Double"'Double
caseadCurrency:typ="Money"'Currency
caseadDecimal:typ="Decimal"
caseadNumeric:typ="Numeric"'Numeric
caseadBoolean:typ="Bit"'Boolean
caseadError:typ="Error"
caseadUserDefined:typ="UserDefined"
caseadVariant:typ="Variant"
caseadIDispatch:typ="IDispatch"
caseadIUnknown:typ="IUnknown"
caseadGUID:typ="GUID"'GUID
caseadDATE:typ="DateTime"'Date
caseadDBDate:typ="DBDate"
caseadDBTime:typ="DBTime"
caseadDBTimeStamp:typ="DateTime"'DBTimeStamp
caseadBSTR:typ="BSTR"
caseadChar:typ="Char"
caseadVarChar:typ="VarChar"
caseadLongVarChar:typ="LongVarChar"
caseadWChar:typ="Text"'WChar类型SQL中为Text
caseadVarWChar:typ="VarChar"'VarWChar
caseadLongVarWChar:typ="Text"'LongVarWChar
caseadBinary:typ="Binary"
caseadVarBinary:typ="VarBinary"
caseadLongVarBinary:typ="LongBinary"'LongVarBinary
caseadChapter:typ="Chapter"
caseadPropVariant:typ="PropVariant"
caseelse:typ="Unknown"
endselect
EndFunction
'==================================================================返回字段类型列表
Functionfieldtypelist(n)
dimstrlist,str1,str2
strlist="<selectname=""field_type"">"
ifsession("dbtype")="access"then
strlist=strlist&"<optionvalue=""VarChar"">文本</option>"
strlist=strlist&"<optionvalue=""Text"">备注</option>"
strlist=strlist&"<optionvalue=""Bit"">(是/否)</option>"
strlist=strlist&"<optionvalue=""TinyInt"">数字(字节)</option>"
strlist=strlist&"<optionvalue=""SmallInt"">数字(整型)</option>"
strlist=strlist&"<optionvalue=""Integer"">数字(长整型)</option>"
strlist=strlist&"<optionvalue=""Single"">数字(单精度)</option>"
strlist=strlist&"<optionvalue=""Double"">数字(双精度)</option>"
strlist=strlist&"<optionvalue=""Numeric"">数字(小数)</option>"
strlist=strlist&"<optionvalue=""GUID"">数字(同步ID)</option>"
strlist=strlist&"<optionvalue=""DateTime"">时间/日期</option>"
strlist=strlist&"<optionvalue=""Money"">货币</option>"
strlist=strlist&"<optionvalue=""Binary"">二进制</option>"
strlist=strlist&"<optionvalue=""LongBinary"">长二进制</option>"
strlist=strlist&"<optionvalue=""LongBinary"">OLE对象</option>"
else
strlist=strlist&"<optionvalue="""">选择类型</option>"
strlist=strlist&"<optionvalue=""BigInt"">bigint</option>"
strlist=strlist&"<optionvalue=""Binary"">binary(二进制数据类型)</option>"
strlist=strlist&"<optionvalue=""Bit"">bit(整型)</option>"
strlist=strlist&"<optionvalue=""Char"">char(字符型)</option>"
strlist=strlist&"<optionvalue=""DateTime"">datetime(日期时间型)</option>"
strlist=strlist&"<optionvalue=""Decimal"">decimal(精确数值型)</option>"
strlist=strlist&"<optionvalue=""Float"">float(近似数值型)</option>"
strlist=strlist&"<optionvalue=""Image"">image(二进制数据类型)</option>"
strlist=strlist&"<optionvalue=""Int"">int(整型)</option>"
strlist=strlist&"<optionvalue=""Money"">money(货币型)</option>"
strlist=strlist&"<optionvalue=""nchar"">nchar(统一编码字符型)</option>"
strlist=strlist&"<optionvalue=""ntext"">ntext(统一编码字符型)</option>"
strlist=strlist&"<optionvalue=""numeric"">numeric(精确数值型)</option>"
strlist=strlist&"<optionvalue=""nvarchar"">nvarchar(统一编码字符型)</option>"
strlist=strlist&"<optionvalue=""real"">real(近似数值型)</option>"
strlist=strlist&"<optionvalue=""smalldatetime"">Smalldatetime(日期时间型)</option>"
strlist=strlist&"<optionvalue=""smallint"">smallint(整型)</option>"
strlist=strlist&"<optionvalue=""smallmoney"">smallmoney(货币型)</option>"
strlist=strlist&"<optionvalue=""sql_variant"">sql_variant()</option>"
strlist=strlist&"<optionvalue=""text"">text(字符型)</option>"
strlist=strlist&"<optionvalue=""timestamp"">timestamp(特殊数据型)</option>"
strlist=strlist&"<optionvalue=""tinyint"">tinyint(整型)</option>"
strlist=strlist&"<optionvalue=""uniqueidentifier"">Uniqueidentifier(特殊数据型)</option>"
strlist=strlist&"<optionvalue=""varbinary"">varbinary(二进制数据类型)</option>"
strlist=strlist&"<optionvalue=""varchar"">varchar(字符型)</option>"
endif
str1=""""&n&""""
str2=""""&n&""""&"selected"
strlist=replace(strlist,str1,str2)
strlist=strlist&"</select>"
echostrlist
EndFunction
'==================================================================主界面
submain(str)
onerrorresumenext
%>
<scriptlanguage=javascript>
ie=(document.all)?true:false
if(ie){
functionctlent(eventobject){if(event.ctrlKey&&
window.event.keyCode==13){this.document.exesql.submit();}}
}
</script>
<scriptlanguage="javascript">
functiontable_delete()
{
if(confirm("确认删除该记录吗?该操作将不可撤销!!!"))
returntrue;
else
returnfalse;
}
</script>
<formaction="?key=sql"method=postname="exesql">
<fontcolor=red>执行sql语句:</font><fontcolor=#999999>(每句语句以“;”结束,支持(--)SQL注释,Ctrl+Enter快速提交)</font><inputtype="button"value="刷新本页"onClick="javascript:location.reload()">
<spanonClick="document.exesql.sql.rows+=5;">+</span>
<spanonClick="if(document.exesql.sql.rows>9)document.exesql.sql.rows-=5">-</span>
<div>
<textareaid="sql"name="sql"rows="9"ondblClick="this.select();"onKeyDown="ctlent()"><%=request("sql")%></textarea><br/>
<inputtype="checkbox"name="SchemaTable"value="1">adSchemaTables
<inputtype="checkbox"name="SchemaColumn"value="2">adSchemaColumns
<inputtype="checkbox"name="SchemaProvider"value="3">adSchemaProviderTypes
分页大小:
<selectname="pageSize">
<%
ifrequest("pageSize")<>""andisNumeric(request("pageSize"))then
echo"<optionvalue='"&request("pageSize")&"'selected>"&request("pageSize")&"</option>"
else
echo"<optionvalue='50'>50</option>"
endif
%>
<optionvalue="10">10</option>
<optionvalue="20">20</option>
<optionvalue="30">30</option>
<optionvalue="40">40</option>
<optionvalue="50">50</option>
<optionvalue="60">60</option>
<optionvalue="70">70</option>
<optionvalue="80">80</option>
<optionvalue="90">90</option>
<optionvalue="100">100</option>
</select>
</div>
<div>
<inputtype="submit"name="Submit_confirm"value="提交"><br/><br/>
<inputtype="button"name="Submit3"value="清空"onClick="sql.value=''"><br/><br/>
<inputtype="button"name="ok"value="返回"onClick="javascript:history.go(-1)">
</div>
</form>
<div></div>
<%ifstr=""then%>
<formaction="?key=addtable"method="post">
<div><br/>
<fontcolor=red>创建新表:</font><br>
表名:<inputtype="text"name="table_name"size="20"><br>
字段数:<inputtype="text"name="field_num"size="20">
<inputtype="submit"name="Submit_create"value="提交">
<inputtype="reset"name="Submit32"value="重置">
</div>
</form>
<br><br>
<ahref="?key=tosql&strt=2">导出所有表结构到SQL</a>
<%
endif
endsub
'==================================================================创建表界面
subadd_table(table_name,field_num)
'table_name=表名称
'field_num=字段数
onerrorresumenext
ifnotIsNumeric(field_num)then
echo"字段数必须是整数。"
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
exitsub
endif
%>
<pclass="hei"><span>创建表:</span><%=table_name%></p>
<formaction="?key=createtable"method="post">
<tablewidth="600"border="0"cellpadding="2"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<tdwidth="75"height="20"align="center">字段名</td>
<tdwidth="99"height="20"align="center">类型</td>
<tdwidth="73"height="20"align="center">大小</td>
<tdwidth="96"height="20"align="center">空值</td>
<tdwidth="83"height="20"align="center">自动编号</td>
<tdwidth="143"height="20"align="center">主键</td>
</tr>
<%fori=0tofield_num-1%>
<tr>
<tdwidth="75"height="20"align="center">
<inputtype="text"name="field_name"size="10">
</td>
<tdwidth="99"height="20"align="center">
<%fieldtypelist(0)%>
</td>
<tdwidth="73"height="20"align="center">
<inputtype="text"name="field_size"size="10">
</td>
<tdwidth="96"height="20"align="center">
<selectname="null">
<optionvalue="NOT_NULL">NOT_NULL</option>
<optionvalue="NULL">NULL</option>
</select>
</td>
<tdwidth="83"height="20"align="center">
<selectsize="1"name="autoincrement">
<option></option>
<option>自动编号</option>
</select>
</td>
<tdwidth="143"height="20"align="left">
<selectname="primarykey">
<option></option>
<optionvalue="primarykey">primarykey</option>
</select>
</td>
</tr>
<%next%>
<tr>
<tdheight="35"align="center"colspan="5">
<inputtype="hidden"name="i"value=<%=field_num%>>
<inputtype="hidden"name="table_name"value="<%=table_name%>">
<inputtype="submit"name="Submit"value="提交">
<inputtype="reset"name="Submit2"value="重置">
<inputtype="button"name="ok"value="放弃"onClick="javascript:history.go(-1)">
</td>
<tdheight="20"></td>
</tr>
</table>
</form>
<%
endsub
'==================================================================构建创建表的SQL语句
subcreate_table()
dimsql,i,primarykey
onerrorresumenext
sql="CREATETABLE["&request("table_name")&"]("
fori=1torequest("i")
sql=sql&"["&request("field_name")(i)&"]"&request("field_type")(i)
ifrequest("field_size")(i)<>""then
sql=sql&"("&request("field_size")(i)&")"
endif
ifrequest("null")(i)="NOT_NULL"then
sql=sql&"notnull"
endif
ifrequest("autoincrement")(i)="自动编号"then
sql=sql&"identity"
endif
ifrequest("primarykey")(i)="primarykey"then
primarykey=request("field_name")(i)
endif
'ifprimarykey<>""then
sql=sql&","
'endif
next
ifprimarykey<>""then
sql=sql&"primarykey(["&primarykey&"])"
endif
sql=sql&")"
sql=replace(sql,"()","")'构建空表
response.redirect"?key=sql&sql="&sql
endsub
'==================================================================修改表名或字段名2006-09-08
subreobj()
onerrorresumenext
Dimmydb,mytable,tablename
tablename=request("tablename")
Setmydb=Server.CreateObject("ADOX.Catalog")
mydb.ActiveConnection=conn
ifrequest("obj")="field"then'修改字段名
dimfieldsname,newfieldsname
fieldsname=request("fieldsname")
newfieldsname=request("newfieldsname")
Setmytable=Server.CreateObject("ADOX.Table")
Setmytable=mydb.Tables(tablename)
mytable.Columns(fieldsname).Name=newfieldsname
endif
ifrequest("obj")="table"then'修改表名
dimnewtablename
newtablename=request("newtablename")
mydb.Tables(tablename).Name=newtablename
endif
iferr<>0then
echoerr.description
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
exitsub
endif
ifrequest("obj")="field"then
response.Redirect"?key=view&table_name="&tablename
else
response.Redirect"?key=view&table_name="&newtablename
endif
endsub
'==================================================================查看表结构函数
subview(table_name)
'table_name=表名称
dimrs,sql,table,primary,primarykey,i,editstr,typs
onerrorresumenext
table=table_name
Setprimary=Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty,empty,table))
ifprimary("COLUMN_NAME")<>""then
primarykey=primary("COLUMN_NAME")
endif
primary.Close
Setprimary=Nothing
%>
<scriptlanguage="javascript">
functiontable_delete()
{
if(confirm("确认删除该记录吗?该操作将不可撤销!!!"))
returntrue;
else
returnfalse;
}
</script>
<fontcolor=red>表:<%=table_name%></font><inputtype="button"value="刷新本页"onClick="javascript:location.reload()"><br><br>
<%ifrequest("key")="editfidlevi"thencalleditfidlevi()%>
<tablewidth="600"border="0"cellpadding="1"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<tdwidth="125"height="20"align="center">字段名</td>
<tdwidth="110"align="center">类型</td>
<tdwidth="83"align="center">设定大小</td>
<tdwidth="48"align="center">允许空</td>
<tdwidth="76"align="center">自动编号</td>
<tdwidth="54"align="center">主键</td>
<tdwidth="82"align="center">执行操作</td>
</tr>
<%
sql="SELECT*FROM["&table_name&"]"
Setrs=Conn.Execute(sql)
iferr=0then
Fori=0tors.fields.count-1
%>
<tr>
<tdheight="20"align="left"><%=rs(i).name%></td>
<tdalign="left"><%=typ(rs(i).type)%></td>
<tdalign="center"><%=rs(i).definedsize%></td>
<tdalign="center"><%=iif((rs(i).AttributesandadFldIsNullable)=0,"No","Yes")%></td>
<tdalign="center"><%=iif(rs(i).Properties("ISAUTOINCREMENT")=True,"是","否")%></td>
<tdalign="center"><%=iif(rs(i).name=primarykey,"是","否")%></td>
<tdalign="center">
<ahref="?key=editfidlevi&fidle=<%=rs(i).name%>&table_name=<%=table_name%>&fidletype=<%=typ(rs(i).type)%>">修改</a>
<ahref="?key=sql&sql=altertable[<%=table_name%>]drop[<%=rs(i).name%>];"onClick="returntable_delete();">删除</a>
</td>
</tr>
<%
editstr=editstr&"<optionvalue='"&rs(i).name&"'>"&rs(i).name&"</option>"
next
%>
</table>
<br>
<ahref="?key=tosql&strt=0&table_name=<%=table_name%>">导出表结构</a>
<ahref="?key=sql&sql=select*from<%=table_name%>&table_name=<%=table_name%>&primarykey=<%=primarykey%>">浏览表记录</a>
<ahref="?key=sql&sql=DROPTABLE<%=table_name%>"onClick="returntable_delete();">删除表</a>
<inputtype="text"name="newtablename"size="20"value="<%=table_name%>">
<inputtype="button"value="修改表名"onClick="location.href='?key=reobj&obj=table&tablename=<%=table_name%>&newtablename='+newtablename.value">
<br><br>
<%
'判断是否有主键
ifprimarykey=""then
echo"<fontcolor=red>该表没有主键,执行操作可能会导致数据损坏或丢失。</font><br>"
echo"你可以将:"
echo"<selectname='keyname'>"
Fori=0tors.fields.count-1
echo"<optionvalue="&rs(i).name&">"&rs(i).name&"</option>"
next
echo"</select>"
echo"<inputtype=buttonvalue=设为主键onclick=""location.href='?key=sql&sql=ALTERTABLE["&table_name&"]ADDPRIMARYKEY(['+keyname.value+'])';"">"
echo"<br><br>"
endif
'显示修改字段名
echo"<selectname='fieldsname'>"
echo"<optionvalue=''>选择字段</option>"
echoeditstr
echo"</select>改名为"&chr(10)
echo"<inputtype='text'name='newfieldsname'size='20'>"&chr(10)
echo"<inputtype=buttonvalue=修改字段名onclick=""location.href='?key=reobj&obj=field&tablename="&table_name&"&fieldsname='+fieldsname.value+'&newfieldsname='+newfieldsname.value"">"
echo"<br><br>"
endif
rs.close
setrs=nothing
%>
<fontcolor=red>增加字段:</font><br><br>
<formaction="?key=addfield"method="post">
<tablewidth="600"height="39"border="0"cellpadding="2"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<tdwidth="60"height="20"align="center">字段名</td>
<tdwidth="50"height="20"align="center">类型</td>
<tdwidth="58"height="20"align="center">设定大小</td>
<tdwidth="64"height="20"align="center">允许空值</td>
<tdwidth="66"height="20"align="center">自动编号</td>
<tdwidth="96"height="20"align="center"></td>
</tr>
<tr>
<tdwidth="60"height="20"align="center">
<inputtype="text"name="fldname"size="10">
</td>
<tdwidth="50"height="20"align="center">
<%fieldtypelist(0)%>
</td>
<tdwidth="58"height="20"align="center">
<inputtype="text"name="fldsize"size="10">
</td>
<tdwidth="64"height="20"align="center">
<inputname="null"type="checkbox"value="ON"checked>
</td>
<tdwidth="66"height="20"align="center">
<inputtype="checkbox"name="autoincrement"value="ON">
</td>
<tdwidth="96"height="20"align="center">
<inputtype="hidden"name="table_name"value="<%=table_name%>">
<inputtype="submit"value="提交">
</td>
</tr>
</table>
</form>
<%
endsub
'==================================================================修改字段属性的界面
subeditfidlevi()
dimsql,rs,i
onerrorresumenext
sql="Select*From["&request("table_name")&"]"
setrs=conn.execute(sql)
fori=0tors.fields.count-1
ifrs(i).name=request("fidle")then
%>
<scriptLANGUAGE="JavaScript">
functionvalidate(theForm){
if(theForm.type.value=="")
{
alert("请输入数据类型");
theForm.type.focus();
return(false);
}
return(true);
}
</script>
<fontcolor=red>修改字段属性:</font>
<formaction="?key=editfidle&fidle=<%=request("fidle")%>&table_name=<%=request("table_name")%>"method="post"name=frmonSubmit="returnvalidate(frm)">
<tablewidth="600"border="0"cellpadding="2"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<tdwidth="60"height="20"align="center">字段名</td>
<tdwidth="50"height="20"align="center">类型</td>
<tdwidth="58"height="20"align="center">设定大小</td>
<tdwidth="64"height="20"align="center">允许空值</td>
<tdwidth="66"height="20"align="center">自动编号</td>
<tdwidth="96"height="20"></td>
</tr>
<tr>
<tdwidth="60"height="20"align="center"><%=rs(i).name%></td>
<tdwidth="50"height="20"align="center">
<%fieldtypelist(request("fidletype"))%>
</td>
<tdwidth="58"height="20"><inputtype="text"name="size"size="10"></td>
<tdwidth="64"height="20"align="center">
<inputtype="checkbox"name="null"value="null"<%=iif((rs(i).AttributesandadFldIsNullable)=0,"","checked")%>>
</td>
<tdwidth="66"height="20"align="center">
<inputtype="checkbox"name="autoincrement"value="y"<%=iif(rs(i).Properties("ISAUTOINCREMENT")=True,"checked","")%>>
</td>
<tdwidth="96"height="20"align="center">
<inputtype="submit"name="Submit"value="提交">
</td>
</tr>
</table><br>
</form>
<%
endif
next
endsub
'==================================================================执行修改字段属性
subeditfidle()
onerrorresumenext
sql="ALTERTABLE["&request("table_name")&"]"
sql=sql&"ALTERCOLUMN["&request("fidle")&"]"
ifrequest("field_type")<>""then
sql=sql&request("field_type")
endif
ifrequest("size")<>""then
sql=sql&"("&request("size")&")"
endif
ifrequest("null")=""then
sql=sql&"notnull"
endif
ifrequest("autoincrement")="y"then
sql=sql&"identity"
endif
sql=trim(sql)
conn.execute(sql)
response.redirect"?key=view&table_name="&request("table_name")
endsub
'==================================================================添加字段函数
subaddfield()
onerrorresumenext
fldname=request("fldname")
fldtype=request("field_type")
fldsize=request("fldsize")
fldnull=request("null")
fldautoincrement=request("autoincrement")
table_name=request("table_name")
iffldname<>""andfldtype<>""then
sql="altertable["&table_name&"]add["&fldname&"]"&fldtype
iffldsize<>""then
sql=sql&"("&fldsize&")"
endif
iffldnull<>"ON"then
sql=sql&"notnull"
endif
iffldautoincrement="ON"then
sql=sql&"identity"
endif
conn.execute(sql)
response.redirect"?key=view&table_name="&table_name
else
echo"输入数据错误!<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
endif
iferr<>0then
echoerr.description
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
response.end
endif
endsub
'==================================================================编辑数据
subeditdata()
dimkeys,names,values,action,rs,sql,tab
onerrorresumenext
keys=request("primarykey")
names=request("table_name")
values=request("primarykeyvalue")
action=request("action")
Setrs=Server.CreateObject("Adodb.RecordSet")
ifaction=""oraction="save"oraction="new"then
sql="select*from"&names&"where"&keys&"="&values
endif
ifaction="pre"then
sql="selecttop1*from"&names&"where"&keys&"<"&values&"orderby"&keys&"desc"
endif
ifaction="next"then
sql="selecttop1*from"&names&"where"&keys&">"&values&"orderby"&keys&"asc"
endif
ifaction="add"then
sql="Select*From["&names&"]"
endif
rs.Opensql,conn,1,3
ifrs.eofandaction="new"then
sql="Select*From["&names&"]"
rs.Opensql,conn,1,3
endif
ifaction="save"oraction="new"then
Ifaction="new"Thenrs.AddNew
ForEachtabInrs.Fields
IfKeys<>tab.NameThen
rs(tab.Name)=Request.Form(tab.Name&"_Column")
iferr<>0then
echotab.name&err.description
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
response.end
endif
EndIf
Next
rs.update
endif
echo"字段数据编辑<br>"
echo"<tablewidth=600border=0cellpadding=5cellspacing=1bgcolor=#CCCCCC><tr><td>"
echo"<formaction='?key=edit&table_name="&names&"&primarykey="&keys&"&primarykeyvalue="&iif(action<>"add",rs(keys),"")&"'method='post'name='editor'>"
echo"<br>"
echo"<inputtype=hiddenname=actionvalue=save>"
echoiif(action="add","","<inputtype=submitvalue=保存onclick=this.form.action.value='save';>")
echo"<inputtype=buttonvalue=添加onclick=if(confirm('确实要添加当前为新记录吗?')){this.form.action.value='new';this.form.submit();};>"
echo"<inputtype=buttonvalue=上一条onclick=""this.form.action.value='pre';this.form.submit();"">"
echo"<inputtype=buttonvalue=下一条onclick=""this.form.action.value='next';this.form.submit();"">"
echo"<ahref='?key=view&table_name="&names&"'>表结构</a>"
echo"<ahref='?key=sql&sql=select*from"&names&"&table_name="&names&"&primarykey="&keys&"'>表浏览</a>"
echo"<ahref='?'>主界面</a><br>"
ifnotrs.eoforaction="add"then
ForEachtabInrs.Fields
echo""
echo"<BR><fontcolor=red>"&tab.Name&"</font><fontcolor=#999999>("&typ(tab.Type)&")</font><br>"
iftab.Type=201Ortab.Type=203then
echo"<textareaname="""&tab.Name&"_Column""rows=6"
echoIIf(tab.Name=keys,"disabledtitle='主键约束,将无法被修改.'>",">")
ifaction<>"add"thenechotrim(tab.value)
echo"</textarea>"
else
echo"<inputtype='text'name='"&tab.Name&"_Column'"
echoIIf(tab.Name=keys,"disabledtitle='主键约束,将无法被修改.'","")&"value='"
ifaction<>"add"thenechotrim(tab.value)
echo"'>"
endif
echo"<br>"
Next
else
echo"<script>alert('已经没有了!');history.back();</script>"
Response.End()
endif
echo"<br>"
echoiif(action="add","","<inputtype=submitvalue=保存onclick=this.form.action.value='save';>")
echo"<inputtype=buttonvalue=添加onclick=if(confirm('确实要添加当前为新记录吗?')){this.form.action.value='new';this.form.submit();};>"
echo"<inputtype=buttonvalue=上一条onclick=""this.form.action.value='pre';this.form.submit();"">"
echo"<inputtype=buttonvalue=下一条onclick=""this.form.action.value='next';this.form.submit();"">"
echo"<ahref='?key=view&table_name="&names&"'>表结构</a>"
echo"<ahref='?key=sql&sql=select*from"&names&"&table_name="&names&"&primarykey="&keys&"'>表浏览</a>"
echo"<ahref='?'>主界面</a>"
echo"</form></td></tr></table>"
endsub
'==================================================================显示存储过程
subshowproc()
dimsTableName,adox
onerrorresumenext
echo"存储过程:<fontcolor=red>"&Request("table_name")&"<font><br>"
sTableName=Request("table_name")
Setadox=Server.CreateObject("ADOX.Catalog")
adox.ActiveConnection=Conn
echo"<textareacols=70rows=8>"&adox.Procedures(sTableName).Command.CommandText&"</textarea><br>"
iferr<>0then
echoerr.description
exitsub
endif
endsub
'==================================================================分页导航
'分页导航
subshowNavBar(rs,page,pageUrl,pageSize)
page=cint(page)
%>
<tablewidth="100%"border="0"cellpadding="2"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<%ifrequest("primarykey")<>""andrequest("table_name")<>""then%>
<tdalign="left">当前表:<fontcolor=red><%=request("table_name")%></font>
<ahref="?key=edit&table_name=<%=request("table_name")%>&primarykey=<%=request("primarykey")%>&action=add">插入新记录</a>
</td>
<%endif%>
<tdalign="right">
<%
echo"共有"&rs.recordCount&"条纪录当前"&page&"/"&rs.PageCount&"页"
ifpage>1then
echo"<ahref='"&pageUrl&"&page=1&pageSize="&pageSize&"'>首页</a>"
echo"<ahref='"&pageUrl&"&page="&page-1&"&pageSize="&pageSize&"'>上页</a>"
endif
if(rs.PageCount>1andpage<rs.PageCount)then
echo"<ahref='"&pageUrl&"&page="&page+1&"&pageSize="&pageSize&"'>下页</a>"
echo"<ahref='"&pageUrl&"&page="&rs.pageCount&"&pageSize="&pageSize&"'>末页</a>"
endif
echo"转到:第"
echo"<selectname='select2'onChange='location.href=this.value;'>"
dimi
fori=1tors.PageCount
echo"<optionvalue='"&pageUrl&"&pageSize="&pageSize&"&page="&i&"'"
ifi=cint(page)thenecho"selected"
echo">"&i&"</option>"
next
echo"</select>页"
%>
</td>
</tr>
</table>
<%
endsub
'==================================================================显示查询
subshowselect(sql)
dimpage,pageUrl,strdel,geturl
pageSize=request("pageSize")'设置每页显示的记录数
ifpageSize=""ornotisNumeric(pageSize)thenpageSize=50
'判断是否删除
ifrequest("keylog")<>""then
strdel="deletefrom"&request("table_name")&"where"&request("primarykey")&"="&request("keylog")
response.Writestrdel
conn.execute(strdel)
geturl="?"&replace(request.QueryString,"&keylog="&request("keylog"),"")
response.Redirectgeturl
endif
page=request("page")'设置当前显示的页数
ifpage=""ornotisNumeric(page)thenpage=1
pageUrl="?key=sql&sql="&sql
ifrequest("primarykey")<>""andrequest("table_name")<>""then
pageUrl=pageUrl&"&table_name="&request("table_name")&"&primarykey="&request("primarykey")
endif
'--------------------------
dimrs
setrs=Server.CreateObject("ADODB.Recordset")
rs.Opensql,conn,3
ifnotrs.eofthen
rs.pageSize=pageSize
ifcint(page)<1thenpage=1
ifcint(page)>rs.PageCountthenpage=rs.PageCount
rs.absolutePage=page
endif
'显示分页导航
showNavBarrs,page,pageUrl,pageSize
'-------------------------------
echo"<div>"
echo"<tableborder=0border=0cellpadding=3cellspacing=1bgcolor=#CCCCCC><tr>"
primarykey=request("primarykey")
ifprimarykey<>""andrequest("table_name")<>""then
echo"<tdbgcolor=#ffffff>操作</td><tdbgcolor=#ffffff>删</td>"
endif
fori=0tors.fields.count-1'循环字段名
setfield=rs.fields.item(i)
echo"<tdbgcolor=#ffffff>"&field.name&"</td>"
next
echo"</tr>"
dimi,field,j
dowhilenotrs.eofandj<rs.pageSize'循环数据
echo"<tr>"
ifprimarykey<>""andrequest("table_name")<>""then
echo"<tdbgcolor=#ffffffnowrap><ahref='?key=edit&table_name="&request("table_name")&"&primarykey="&primarykey&"&primarykeyvalue="&rs(primarykey)&"'><fontcolor=#666666>编辑</font></a></td>"
echo"<td><ahref='?"&Request.QueryString&"&keylog="&rs(primarykey)&"'onClick='returntable_delete();'><fontcolor=#FF000>×</font></a></td>"
endif
fori=0tors.fields.count-1
setfield=rs.fields.item(i)
iflen(field.value)<12then
echo"<tdbgcolor=#ffffffnowrap>"&field.value&"</td>"
else
echo"<tdbgcolor='#ffffff'><spanclass='fixspan'>"&field.value&"</span></td>"
endif
next
echo"</tr>"
rs.MoveNext
j=j+1
loop
'response.ContentType="application/vnd.ms-excel"'生成EXCEL表格
echo"</table></div>"
endsub
subexesql(sql)
onerrorresumenext
'==================================================================执行sql函数
iftrim(request.form("SchemaTable"))<>""thenCallshowSchema(adSchemaTables)
iftrim(request.form("SchemaColumn"))<>""thenCallshowSchema(adSchemaColumns)
iftrim(request.form("SchemaProvider"))<>""thenCallshowSchema(adSchemaProviderTypes)
sql=trim(request("sql"))
ifsql=""thenexitsub
sql=RegExpReplace(sql,"(--)(.)*n","")'替换注释
sql=RegExpReplace(sql,"n[s|]*r","")'替换空行
sql=RegExpReplace(sql,"n","")'替换换行符
sql=RegExpReplace(sql,"r","")'替换回车符
if(LCase(left(sql,len("select")))="select")andinstr(sql,"into")=0then
CallshowSelect(sql)
iferr<>0thenecho"<br><fontcolor=red>"&err.description&"</font>"
response.end
else
'如果非select语句,允许执行多条以分号分隔的语句
dimaSql,iLoop
aSql=split(sql,";")
foriLoop=0toUBound(aSql)
iftrim(aSql(iLoop))<>""then
conn.execute(aSql(iLoop))
iferr<>0then
echo"<br><fontcolor=red>"&err.description&"<br><b>"
echoiLoop+1&"、</b></font><fontcolor=#CC6600>"&aSql(iLoop)&"</font><br>"
'err.clear()'忽略错误
exitsub'中止执行
else
echo"<div><b>"&iLoop+1&"、</b>"&aSql(iLoop)&"</div>"
endif
endif
next
echo"<fontcolor=red><h4>命令执行成功</h4></font>"
endif
endsub
'显示数据库信息
'QueryType有以下三个主要参数
'adSchemaTables
'adSchemaColumns
'adSchemaProviderTypes
'CallshowSchema(adSchemaTables)
subshowSchema(QueryType)
dimrs
'setrs=conn.OpenSchema()
setrs=conn.OpenSchema(QueryType)
'setrs=conn.OpenSchema(adSchemaProviderTypes)
echo"<div><tableborder=0border=0cellpadding=3cellspacing=1bgcolor=#CCCCCC><tr>"
fori=0tors.fields.count-1'循环字段名
setfield=rs.fields.item(i)
echo"<tdbgcolor='#FFFFFF'>"&field.name&"</td>"
next
echo"</tr>"
dimi,field
dowhilenotrs.eof'循环数据
echo"<tr>"
fori=0tors.fields.count-1
setfield=rs.fields.item(i)
echo"<tdbgcolor='#FFFFFF'>"&field.value&"</td>"
next
echo"</tr>"
rs.MoveNext
loop
echo"</table></div>"
endsub
%>
<%
'==================================================================导出SQL
subtosql(strt)
'strt=0导出结构
'strt=1导出内容
dimstrsql
ifstrt="0"then
table=request("table_name")
echo"以下是表<fontcolor=red>"&request("table_name")&"</font>的结构:"
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
strsql=getsql(table)
endif
ifstrt="2"then
echo"以下是<fontcolor=red>数据库</font>的结构:"
echo"<inputtype='button'name='ok'value='返回'onClick='javascript:history.go(-1)'>"
setobjSchema=Conn.OpenSchema(adSchemaTables)
DoWhileNotobjSchema.EOF
ifobjSchema("TABLE_TYPE")="TABLE"then
table=objSchema("TABLE_NAME")
strsql=strsql&getsql(table)'table&"|"'getsql(table)
endif
objSchema.MoveNext
Loop
objSchema.close
endif
echo"<textareacols=110rows=38>"&strsql&"</textarea>"
conn.close
endsub
'==================================================================输出表结构
functiongetsql(table)
onerrorresumenext
getsql="--表结构"&table&"的SQL语句。"&chr(10)
dimprimary,primarykey
Setprimary=Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty,empty,table))
ifprimary("COLUMN_NAME")<>""then
primarykey=primary("COLUMN_NAME")
endif
primary.Close
setprimary=nothing
tbl_struct="CREATETABLE["&table&"]("&chr(10)
sql="SELECT*FROM"&table
Setrs=Conn.Execute(sql)
iferr=0then
fori=0tors.fields.count-1
tbl_struct=tbl_struct&"["&rs(i).name&"]"
typs=typ(rs(i).type)
iftyps="VARCHAR"ortyps="BINARY"ortyps="CHAR"then
tbl_struct=tbl_struct&typs&"("&rs(i).definedsize&")"
else
tbl_struct=tbl_struct&typs&""
endif
attrib=rs(i).attributes
if(attribandadFldIsNullable)=0then
tbl_struct=tbl_struct&"NOTNULL"
endif
ifrs(i).Properties("ISAUTOINCREMENT")=Truethen
tbl_struct=tbl_struct&"IDENTITY"
endif
tbl_struct=tbl_struct&","&chr(10)
next
ifprimarykey<>""then
tbl_struct=tbl_struct&"PRIMARYKEY(["&primarykey&"]));"
else
len_of_sql=Len(tbl_struct)
tbl_struct=Mid(tbl_struct,1,len_of_sql-2)
tbl_struct=tbl_struct&");"
endif
else
tbl_struct="CREATETABLE["&table&"];"
endif
getsql=getsql&tbl_struct&chr(10)&chr(10)
endfunction
subhelp()
echo"SQL常用语句:<br><br>"
echo"创建表:<br>"
echo"CREATETABLE[表名](<br>"
echo"[test1]intnotnullidentity,<br>"
echo"[test2]binarynotnull,<br>"
echo"primarykey([test1]))<br><br>"
echo"设置主键:ALTERTABLE[tablename]ADDPRIMARYKEY([fieldname])<br><br>"
echo"查询:select*fromtablenamewherefieldname***orderbyiddesc<br><br>"
echo"更新:updatetanlenamesetfieldname=values,cn_name='values'whereID=1<br><br>"
echo"添加:insertintotanlename(fieldnam,fieldnam2)values(1,'values')<br><br>"
echo"删除:deletefromtanlenamewherefieldname=values<br><br>"
echo"删除表:DROPTABLE数据表名称<br><br>"
echo"添加字段:ALTERTABLE[表名]ADD[字段名]NVARCHAR(50)NULL<br><br>"
echo"删除字段:altertable[tablename]drop[fieldname]<br><br>"
echo"修改字段:ALTERTABLE[表名]ALTERCOLUMN[字段名]类型(大小)NULL<br><br>"
echo"新建约束:ALTERTABLE[表名]ADDCONSTRAINT约束名CHECK([约束字段]<='2000-1-1')<br><br>"
echo"删除约束:ALTERTABLE[表名]DROPCONSTRAINT约束名<br><br>"
echo"新建默认值:ALTERTABLE[表名]ADDCONSTRAINT默认值名DEFAULT'51WINDOWS.NET'FOR[字段名]<br><br>"
echo"删除默认值:ALTERTABLE[表名]DROPCONSTRAINT默认值名<br><br>"
endsub
%>
<>
<tablewidth="100%"height="100%"border="0"cellpadding="5"cellspacing="1"bgcolor="#CCCCCC">
<tr>
<tdwidth="18%"valign="top">
<divid="Layer1">
<div></div>
表:<ahref="?">主界面</a><ahref="?key=exit">退出</a><ahref="?key=help">Help</a><br>
<%
setobjSchema=Conn.OpenSchema(adSchemaTables)
DoWhileNotobjSchema.EOF
ifobjSchema("TABLE_TYPE")="TABLE"then
'输出表名
echo"<ahref='?key=view&table_name="&objSchema("TABLE_NAME")&"'>"&objSchema("TABLE_NAME")&"</a><br>"
endif
objSchema.MoveNext
Loop
echo"所有视图:<br>"
objSchema.MoveFirst
DoWhileNotobjSchema.EOF
ifobjSchema("TABLE_TYPE")="VIEW"then
'输出表名
echo"<ahref='?key=sql&sql=SELECT*FROM["&objSchema("TABLE_NAME")&"]'>"&objSchema("TABLE_NAME")&"</a><br>"
endif
objSchema.MoveNext
Loop
objSchema.Close
setobjSchema=nothing
'echo"存储过程:<br>"
'setobjSchema=Conn.OpenSchema(adSchemaProcedures)
'DoWhileNotobjSchema.EOF
'echo"<ahref='?key=proc&table_name="&objSchema("PROCEDURE_NAME")&"'>"&objSchema("PROCEDURE_NAME")&"</a><br>"
'objSchema.MoveNext
'Loop
'objSchema.Close
'setobjSchema=nothing
%>
</div>
</td>
<tdwidth="82%"valign="top">
<divid="Layer2">
<%
selectcaserequest("key")
case""'显示主界面
callmain("")
case"addtable"'显示创建表界面
calladd_table(request("table_name"),request("field_num"))
case"createtable"'执行创建表
callcreate_table()
case"view"
callview(request("table_name"))
case"sql"
callmain("1")
callexesql(trim(request("sql")))
case"addfield"
calladdfield()
case"editfidlevi"
callview(request("table_name"))
case"editfidle"
calleditfidle()
case"exit"
session("dbtype")=""
session("dbstr")=""
session("db007pass")=""
response.redirect"?"
case"tosql"
calltosql(request("strt"))
case"proc"
callmain("1")
callshowproc()
case"help"
callhelp()
case"edit"
callEditData()
case"reobj"
callreobj()
endselect
%>
</div>
</td>
</tr>
</table>
<>
</body>
</html>