数据库管理工具 <% table_name=tables Function IIf(var, val1, val2) If var = True Then IIf = val1 Else IIf = val2 End If End Function '正则表达式函数,用于删除注释 '------------------------------------- Function RegExpReplace(strng, patrn, replStr) Dim regEx,match,matches ' 建立变量。 Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = patrn ' 设置模式。 regEx.IgnoreCase = True ' 设置是否区分大小写。 regEx.Global = True ' 设置全局可用性。 RegExpReplace = regEx.Replace(strng, replStr) ' 作替换。 End Function '==================================================================ADOVBS 常量声明 '---- DataTypeEnum Values ---- Const adEmpty = 0 Const adTinyInt = 16 Const adSmallInt = 2 Const adInteger = 3 Const adBigInt = 20 Const adUnsignedTinyInt = 17 Const adUnsignedSmallInt = 18 Const adUnsignedInt = 19 Const adUnsignedBigInt = 21 Const adSingle = 4 Const adDouble = 5 Const adCurrency = 6 Const adDecimal = 14 Const adNumeric = 131 Const adBoolean = 11 Const adError = 10 Const adUserDefined = 132 Const adVariant = 12 Const adIDispatch = 9 Const adIUnknown = 13 Const adGUID = 72 Const adDate = 7 Const adDBDate = 133 Const adDBTime = 134 Const adDBTimeStamp = 135 Const adBSTR = 8 Const adChar = 129 Const adVarChar = 200 Const adLongVarChar = 201 Const adWChar = 130 Const adVarWChar = 202 Const adLongVarWChar = 203 Const adBinary = 128 Const adVarBinary = 204 Const adLongVarBinary = 205 '---- FieldAttributeEnum Values ---- Const adFldMayDefer = &H00000002 Const adFldUpdatable = &H00000004 Const adFldUnknownUpdatable = &H00000008 Const adFldFixed = &H00000010 Const adFldIsNullable = &H00000020 Const adFldMayBeNull = &H00000040 Const adFldLong = &H00000080 Const adFldRowID = &H00000100 Const adFldRowVersion = &H00000200 Const adFldCacheDeferred = &H00001000 '---- SchemaEnum Values ---- '---- SchemaEnum Values ---- Const adSchemaProviderSpecific = -1 Const adSchemaAsserts = 0 Const adSchemaCatalogs = 1 Const adSchemaCharacterSets = 2 Const adSchemaCollations = 3 Const adSchemaColumns = 4 Const adSchemaCheckConstraints = 5 Const adSchemaConstraintColumnUsage = 6 Const adSchemaConstraintTableUsage = 7 Const adSchemaKeyColumnUsage = 8 Const adSchemaReferentialConstraints = 9 Const adSchemaTableConstraints = 10 Const adSchemaColumnsDomainUsage = 11 Const adSchemaIndexes = 12 Const adSchemaColumnPrivileges = 13 Const adSchemaTablePrivileges = 14 Const adSchemaUsagePrivileges = 15 Const adSchemaProcedures = 16 Const adSchemaSchemata = 17 Const adSchemaSQLLanguages = 18 Const adSchemaStatistics = 19 Const adSchemaTables = 20 Const adSchemaTranslations = 21 Const adSchemaProviderTypes = 22 Const adSchemaViews = 23 Const adSchemaViewColumnUsage = 24 Const adSchemaViewTableUsage = 25 Const adSchemaProcedureParameters = 26 Const adSchemaForeignKeys = 27 Const adSchemaPrimaryKeys = 28 Const adSchemaProcedureColumns = 29 Const adSchemaDBInfoKeywords = 30 Const adSchemaDBInfoLiterals = 31 Const adSchemaCubes = 32 Const adSchemaDimensions = 33 Const adSchemaHierarchies = 34 Const adSchemaLevels = 35 Const adSchemaMeasures = 36 Const adSchemaProperties = 37 Const adSchemaMembers = 38 Const adSchemaTrustees = 39 Const adSchemaFunctions = 40 Const adSchemaActions = 41 Const adSchemaCommands = 42 Const adSchemaSets = 43 '==================================================================返回字段类型函数 Function typ(field_type) 'field_type = 字段类型值 Select Case field_type case adEmpty:typ = "Empty" case adTinyInt:typ = "TinyInt" case adSmallInt:typ = "SmallInt" case adInteger:typ = "Integer" case adBigInt:typ = "BigInt" case adUnsignedTinyInt:typ = "TinyInt" 'UnsignedTinyInt case adUnsignedSmallInt:typ = "UnsignedSmallInt" case adUnsignedInt:typ = "UnsignedInt" case adUnsignedBigInt:typ = "UnsignedBigInt" case adSingle:typ = "Single" 'Single case adDouble:typ = "Double" 'Double case adCurrency:typ = "Money" 'Currency case adDecimal:typ = "Decimal" case adNumeric:typ = "Numeric" 'Numeric case adBoolean:typ = "Bit" 'Boolean case adError:typ = "Error" case adUserDefined:typ = "UserDefined" case adVariant:typ = "Variant" case adIDispatch:typ = "IDispatch" case adIUnknown:typ = "IUnknown" case adGUID:typ = "GUID" 'GUID case adDATE:typ = "DateTime" 'Date case adDBDate:typ = "DBDate" case adDBTime:typ = "DBTime" case adDBTimeStamp:typ = "DateTime" 'DBTimeStamp case adBSTR:typ = "BSTR" case adChar:typ = "Char" case adVarChar:typ = "VarChar" case adLongVarChar:typ = "LongVarChar" case adWChar:typ = "Text" 'WChar类型 SQL中为Text case adVarWChar:typ = "VarChar" 'VarWChar case adLongVarWChar:typ = "Text" 'LongVarWChar case adBinary:typ = "Binary" case adVarBinary:typ = "VarBinary" case adLongVarBinary:typ = "LongBinary"'LongVarBinary case adChapter:typ = "Chapter" case adPropVariant:typ = "PropVariant" case else:typ = "Unknown" end select End Function '==================================================================返回字段类型列表 Function fieldtypelist(n) dim strlist,str1,str2 strlist = "" response.write strlist End Function '==================================================================主界面 sub main(str) on error resume next %>
 
<% end sub '==================================================================修改表名或字段名 2006-09-08 sub reobj() on error resume next Dim mydb,mytable,tablename tablename = request("tablename") Set mydb = Server.CreateObject("ADOX.Catalog") mydb.ActiveConnection = conn if request("obj") = "field" then '修改字段名 dim fieldsname,newfieldsname fieldsname = request("fieldsname") newfieldsname = request("newfieldsname") Set mytable = Server.CreateObject("ADOX.Table") Set mytable = mydb.Tables(tablename) mytable.Columns(fieldsname).Name = newfieldsname end if if request("obj") = "table" then '修改表名 dim newtablename newtablename = request("newtablename") mydb.Tables(tablename).Name = newtablename end if if err <> 0 then response.write err.description response.write "" exit sub end if if request("obj") = "field" then response.Redirect "?key=view&table_name=" & tablename else response.Redirect "?key=view&table_name=" & newtablename end if end sub '==================================================================查看表结构函数 sub view(table_name) 'table_name = 表名称 dim rs,sql,table,primary,primarykey,i,editstr,typs on error resume next table = table_name Set primary = Conn.OpenSchema(adSchemaPrimaryKeys,Array(empty, empty, table)) if primary("COLUMN_NAME") <> "" then primarykey = primary("COLUMN_NAME") end if primary.Close Set primary = Nothing %> 表:<%=tables%>    

<% if request("key") = "editfidlevi" then call editfidlevi() %> <% sql = "SELECT * FROM [" & table_name & "] " Set rs = Conn.Execute(sql) if err = 0 then For i = 0 to rs.fields.count-1 %> <% editstr = editstr&"" next %>
字 段 名 类 型 设定大小 允许空 自动编号 主键 执行操作
<%=rs(i).name%> <%=typ(rs(i).type)%> <%=rs(i).definedsize%> <%=iif((rs(i).Attributes and adFldIsNullable)=0,"No","Yes")%> <%=iif(rs(i).Properties("ISAUTOINCREMENT") = True,"是","否")%> <%=iif(rs(i).name = primarykey,"是","否")%> 修改  删除
<% '显示修改字段名 response.write " 改名为 " & chr(10) response.write " " & chr(10) response.write " 修改字段属性:
&table_name=<%=request("table_name")%>" method="post" name=frm onSubmit="return validate(frm)">
字段名 类型 设定大小 允许空值 自动编号
<%=rs(i).name%> <% fieldtypelist(request("fidletype")) %> > >

<% end if next end sub '==================================================================执行修改字段属性 sub editfidle() on error resume next sql = "ALTER TABLE [" & request("table_name") & "] " sql = sql&"ALTER COLUMN [" & request("fidle") & "] " if request("field_type") <> "" then sql = sql & request("field_type") end if if request("size") <> "" then sql = sql & "(" & request("size") & ") " end if if request("null") = "" then sql = sql & " not null" end if if request("autoincrement") = "y" then sql = sql & " identity" end if sql = trim(sql) conn.execute(sql) response.redirect "?key=view&table_name="& request("table_name") end sub '==================================================================添加字段函数 sub addfield() on error resume next fldname = request("fldname") fldtype = request("field_type") if fldtype="VarChar" then fldsize="255" else fldsize = request("fldsize") end if fldnull = request("null") fldautoincrement = request("autoincrement") table_name = request("table_name") if fldname <> "" and fldtype <> "" then sql = "alter table [" & table_name & "] add ["&fldname&"] " & fldtype if fldsize <> "" then sql = sql & "(" & fldsize & ")" end if if fldnull <> "ON" then sql = sql & " not null" end if if fldautoincrement = "ON" then sql = sql & " identity" end if conn.execute(sql) response.redirect "?key=view&table_name=" & table_name else response.write "输入数据错误!" end if if err <> 0 then response.write err.description response.write "" response.end end if end sub sub exesql(sql) on error resume next '==================================================================执行sql函数 if trim(request.form("SchemaTable")) <> "" then Call showSchema (adSchemaTables) if trim (request.form("SchemaColumn")) <> "" then Call showSchema(adSchemaColumns) if trim (request.form("SchemaProvider")) <> "" then Call showSchema(adSchemaProviderTypes) sql = trim(request("sql")) if sql = "" then exit sub 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") and instr(sql,"into") = 0 then Call showSelect (sql) if err <> 0 then response.write "
" & err.description & "" response.end else '如果非select语句,允许执行多条以分号分隔的语句 dim aSql,iLoop aSql = split(sql,";") for iLoop = 0 to UBound(aSql) if trim(aSql(iLoop)) <> "" then conn.execute (aSql(iLoop)) if err <> 0 then response.write "
" & err.description & "
  " response.write iLoop + 1 & "、
" & aSql(iLoop) & "
" 'err.clear() '忽略错误 exit sub '中止执行 else response.write "
" & iLoop + 1 & "、" & aSql(iLoop) & "
" end if end if next response.write "

命令执行成功

" end if end sub %>
<% select case request("key") case "" '显示主界面 call main("") case "addtable" '显示创建表界面 call add_table(request("table_name"),request("field_num")) case "createtable" '执行创建表 call create_table() case "view" call view(request("table_name")) case "sql" call main("1") call exesql(trim(request("sql"))) case "addfield" call addfield() case "editfidlevi" call view(request("table_name")) case "editfidle" call editfidle() case "exit" session("dbtype") = "" session("dbstr") = "" session("db007pass") = "" response.redirect "?" case "tosql" call tosql(request("strt")) case "proc" call main("1") call showproc() case "help" call help() case "edit" call EditData() case "reobj" call reobj() end select %>
 

时间: 浏览次数: 
 
  信息查询
  请输入查询号:
 
  设为首页 | 收藏本站
CopyRight© 2006-2018All Right Reserved  客服热线:021-53851118 53850998 
  地址:上海市浦东新区祖冲之路2277弄4号楼    版权所有:上海德誉供应链管理股份有限公司