programming-examples/asp/Miscellaneous/DB Viewer.asp
2019-11-18 14:25:58 +01:00

171 lines
6.8 KiB
Plaintext

<%@ Language=VBScript %>
<HTML>
<HEAD>
<STYLE TYPE="text/css">
Body {font-size:10;font-family:Verdana, Arial;color:Black;text-decoration:none;}
TD,SELECT,OPTION,TextArea ,Input, {font-size:9;font-family:Verdana, Arial;color:Black;text-decoration:none;}
TH {font-size:8pt;font-family:Verdana, Arial;color:Black;}
</STYLE>
</HEAD>
<BODY>
<%
if Request("Action") = "ShowdB" then
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=SQLOLEDB; Data Source=martini; Initial Catalog=" & Request("dB") & "; User ID=UserID; Password=Password"
strSQL = "SELECT name,length,xtype,isnullable FROM syscolumns WHERE id=" & Request("id") & " ORDER BY colorder ASC"
Response.Write "<form action='db.asp' method='post'>" & vbCrLf
Set objRS = objConn.Execute(strSQL)
Response.Write "<TABLE BORDER=1 CELLSPACING=1><TR>" & vbCrLf
For Each fld in objRS.Fields
Response.Write "<TH>" & fld.Name & "</TH>" & vbCrLf
Next
Response.Write "</TR><TR>" & vbCrLf
if objRS.EOF then
Response.Write "test"
else
i=0
Do While not objRS.EOF
Response.Write "<TR>" & vbCrLf
For Each fld in objRS.Fields
if fld.Name = "xtype" then
xSQL = "SELECT name FROM systypes WHERE xtype = '" & fld.value & "'"
Set xRS = Server.CreateObject("ADODB.Recordset")
xRS.Open xSQL, objConn
Response.Write "<TD>" & xRS("name") & "</TD>" & vbCrLf
xRS.Close
Set xRS = Nothing
elseif fld.Name = "name" then
Response.Write "<TD><input type='checkbox' name='field" & i & "' value='" & fld.value & "'>" & fld.Value & "</TD>" & vbCrLf
else
Response.Write "<TD>" & fld.Value & "</TD>" & vbCrLf
end if
Next
Response.Write "</TR>" & vbCrLf
i=i+1
objRS.MoveNext
Loop
end if
Response.Write "</TABLE><table border=1>"
Response.Write "<tr><td><input type='radio' name='Type' value='Insert' checked>Insert Statement</td></tr>" & vbCrLf
Response.Write "<tr><td><input type='radio' name='Type' value='Select'>Select Statement</td></tr>" & vbCrLf
Response.Write "<tr><td><input type='submit' value='Make Statement'></td></tr>" & vbCrLf
Response.Write "</table>"
Response.Write "<input type='hidden' name='Action' value='Statement'>" & vbCrLf
Response.Write "<input type='hidden' name='Table' value='" & Request("Table") & "'>" & vbCrLf
Response.Write "</form>"
sSQL = "SELECT * FROM " & Trim(Request("Table"))
'Response.Write sSQL & "<P>"
Set sConn = Server.CreateObject("ADODB.Connection")
sConn.Open "Provider=SQLOLEDB; Data Source=martini; Initial Catalog=" & Request("dB") & "; User ID=UserName; Password=Password"
Set sRS = Server.CreateObject("ADODB.Recordset")
sRS.Open sSQL, sConn
Response.Write "<P><b>Copy & Paste:</b></P>"
sFldString = "<textarea cols=50 rows=15 wrap=hard id=textarea1 name=textarea1>"
intCount = sRS.Fields.Count - 1
for i=0 to intCount
sFldString = sFldString & sRS(i).Name & ","
next
sFldString = Left(sFldString,Len(sFldString)-1) & "</textarea>"
Set RS = Nothing
Set Conn = Nothing
Response.Write "<P>" & sFldString
objConn.Close
Set objConn = Nothing
elseif Request("Action") = "Statement" then
if Request("Type") = "Select" then
sSQL = "SELECT "
for each item in Request.Form
if instr(1,Left(item,5),"field") then
if i=0 then
sFields = Request.Form(item)
i=1
else
sFields = sFields & "," & Request.Form(item)
end if
end if
next
sSQL = sSQL & sFields & " FROM " & Request("Table")
Response.Write "<textarea cols=60 rows=10>" & sSQL & "</textarea>"
else
sSQL = "INSERT INTO " & Request("Table") & "("
for each item in Request.Form
if instr(1,Left(item,5),"field") then
if i=0 then
sFields = Request.Form(item)
sValues = "'"" & Request(""" & Request.Form(item) & """) & ""'"
i=1
else
sFields = sFields & "," & Request.Form(item)
sValues = sValues & ",'"" & Request(""" & Request.Form(item) & """) & ""'"
end if
end if
next
sSQL = sSQL & sFields & ") VALUES (" & sValues & ")"""
Response.Write "<textarea cols=60 rows=10>" & sSQL & "</textarea>"
end if
elseif Request("Action") = "ShowT" then
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=SQLOLEDB; Data Source=martini; Initial Catalog=" & Request("dB") & "; User ID=UserName; Password=Password"
Dim strSQL
strSQL = "SELECT id,name,crdate AS Create_Date FROM sysobjects WHERE xtype='U' ORDER BY name ASC"
'Response.Write strSQL
Dim objRS
Set objRS = objConn.Execute(strSQL)
Response.Write "<TABLE BORDER=1 CELLSPACING=1><TR>" & vbCrLf
Dim fld
For Each fld in objRS.Fields
if fld.Name = "id" then
'do nothing
else
Response.Write "<TH>" & fld.Name & "</TH>" & vbCrLf
end if
Next
Response.Write "</TR><TR>" & vbCrLf
Do While not objRS.EOF
Response.Write "<TR>" & vbCrLf
For Each fld in objRS.Fields
if fld.Name = "name" then
Response.Write "<TD><a href='db.asp?Action=ShowdB&id=" & objRS("id") & "&dB=" & Request("dB") & "&Table=" & fld.Value & "'>" & fld.Value & "</a></TD>" & vbCrLf
elseif fld.Name = "id" then
'do nothing
else
Response.Write "<TD>" & fld.Value & "</TD>" & vbCrLf
end if
Next
Response.Write "</TR>" & vbCrLf
objRS.MoveNext
Loop
Response.Write "</TABLE>"
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
else
SQL = "SELECT name FROM sysdatabases ORDER BY name ASC"
Set dConn = Server.CreateObject("ADODB.Connection")
dConn.Open "Provider=SQLOLEDB; Data Source=martini; Initial Catalog=Master; User ID=UserName; Password=Password"
Set dRS = Server.CreateObject("ADODB.Recordset")
dRS.Open SQL , dConn
Response.Write "<table border=0>" & vbCrLf
While Not dRS.EOF
Response.Write "<Tr><td><a href='db.asp?Action=ShowT&dB=" & dRS("name") & "'>" & dRS("name") & "</a></td></tr>" & vbCrLf
dRS.MoveNext
Wend
Response.Write "</table>" & vbCrLf
dRS.Close
Set dRS = Nothing
end if
%>
</BODY>
</HTML>