<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = true%>
<OBJECT RUNAT=server PROGID=FMStocks_DB.Version id=db> </OBJECT>
<OBJECT RUNAT=server PROGID=ADODB.Connection id=conn> </OBJECT>

<html>
<head>
	<!--#include file="t_head.asp"-->
	<title>Run SQL Command</title>

</head>

<body>
<!--#include file="t_begin.asp"-->
<form method="post" action="_RunSQL.asp">

<textarea rows="15" cols="40" id="SQLStatement" name="SQLStatement">
<%
if request("SQLStatement") <> "" then
	response.write request("SQLStatement")
else
	response.write "select * from stocks where company like '%.com%'"
end if
%>
</textarea>

<input type="submit" value="GO">
<%
if Request("SQLStatement") <>"" then
	dim  dsn, rs, f
	dsn = db.ConnectionString()
	
	Response.Write ("<p>(Using DSN: " & dsn & ")</p>")
	
	conn.Open dsn
	set rs = conn.Execute(Request("SQLStatement"))

	if rs is nothing then	
		Response.Write "<b>rs is nothing</b><br>"
	elseif rs.State = 0 then
		Response.Write "<b>No results returned</b><br>"
	else

		do until rs Is Nothing
			if rs.state <> 0 then
			
				Response.Write "<table border=1>"
			
				'header
				Response.Write "<tr>" & vbNewLine
				for each f in rs.fields
					Response.Write vbTab & "<td><strong>" & f.name & "</strong></td>"
				next
				Response.Write "</tr>" & vbNewLine
				'data
				do until rs.EOF
					Response.Write "<tr>" & vbNewLine
					for each f in rs.fields
						Response.Write vbTab & "<td>" & f.value & "</td>"
					next
					Response.Write "</tr>" & vbNewLine 
					rs.moveNext
				loop	
				Response.Write "</table><br>"
			end if

		    Set rs = rs.NextRecordset
		loop
	end if
end if
%>
</form>

<!--#include file="t_end.asp"-->
</body>
</html>
