DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples > Classic ASP

Discuss "Basic SQL command inteface" in the Classic ASP forum.

Classic ASP - Post your Classic ASP code samples here.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old June 12th, 2008, 12:05 AM
dr_rock's Avatar
Drunk Developer

 
Join Date: Jun 2008
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
dr_rock is an unknown quantity at this point
Default Basic SQL command inteface

For the times you dont have access to the database, this will allow you to build sql queries on the fly to retrieve schema information and perform other database functions.

WARNING!!! DO NOT LEAVE THIS FILE UNSECURED ON YOUR LIVE SITE!!!!!!

Code:
<!--#INCLUDE file="include/connection.asp"-->
<%
'#Include File		 	- include/connection.asp
'# > Function OpenDB()  - creates open ado connection named adoConn
'# > Function CloseDB() - destroys adoConn

strAction = Request("action")
strCommand = Request("command")
intRows = Request("rows")
Select Case strAction
	Case "command"
	
			If (Session("active")) and (strCommand <> "") Then
			
				call OpenDB()
				strUrl = Replace(strCommand, vbcrlf, " ")
				Set rs = adoConn.Execute(strUrl) 
				call CloseDB()

				response.redirect("sqltool.asp?message=SQL Command Successful!")
			End If
		
	Case "query"
	
		If (Session("active")) and (strCommand <> "") and (IsNumeric(intRows)) Then
		
			call OpenDB()
			strUrl = Replace(strCommand, vbcrlf, " ")
			Set rs = adoConn.Execute(strUrl) 
			strResults = ""
			Do Until rs.EOF
				intMaxRows = CLng(intRows)
				for x = 0 to intMaxRows-1
					strResults = strResults & rs(x) & " | "
				next
				strResults = strResults & vbcrlf
				rs.movenext
			Loop
			rs.close()
			set rs = Nothing
			call CloseDB()
			
		End If
	Case "letmein"
		Session("active") = True
		response.redirect("sqltool.asp?message=Hello There!")
	Case "bye"
		Session("active") = False
		response.redirect("sqltool.asp?message=Goodbye Now!")
End Select
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SQL TOOL</title>
</head>
<body>
<%If NOT(Session("active")) Then%>
Access Denied! Bugger off!
<%Else%>
<form action="sqltool.asp" method="post" name="sqltool">
<table width="100%">
	<tr>
		<td valign="top">
			<textarea name="command" rows="4" cols="80"><%=strCommand%></textarea>
		</td>
	</tr>
</table>
<table width="100%">
	<tr>
		<td style="border : solid 2px #ACA899;">
		<input type="button" value="Select" style="width:100px;" onclick="document.sqltool.command.value='SELECT * FROM ___ WHERE ___ ORDER BY ___';document.sqltool.action[1].checked=true;" />
		<input type="button" value="Insert" style="width:100px;" onclick="document.sqltool.command.value='INSERT INTO () VALUES ()';document.sqltool.action[0].checked=true;" />
		<input type="button" value="Update" style="width:100px;" onclick="document.sqltool.command.value='UPDATE ___ SET ___ = ___ WHERE ___ = ___';document.sqltool.action[0].checked=true;" />
		<input type="button" value="Delete" style="width:100px;" onclick="document.sqltool.command.value='DELETE FROM ___ WHERE ___ = ___';document.sqltool.action[0].checked=true;" /><br />
		</td>
		<td style="border : solid 2px #ACA899;">
		<input type="button" value="Structure" style="width:100px;" onclick="document.sqltool.command.value='select table_name, column_name, ordinal_position, data_type from information_schema.columns order by 1,3';document.sqltool.action[1].checked=true;document.sqltool.rows.value=4;" />
		<input type="button" value="Add Table" style="width:100px;" onclick="document.sqltool.command.value='CREATE TABLE [dbo].[__] ([__] [bigint] IDENTITY (1, 1) NOT NULL ,	[__] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,	[__] [bit] NULL , [__] [varchar] (50) COLLATE Latin1_General_CI_AS NULL) ON [PRIMARY]';document.sqltool.action[0].checked=true;" />
		<input type="button" value="Hilight" style="width:100px;" onclick="document.sqltool.command.select();" />
		<input type="button" value="Clear" style="width:100px;" onclick="document.sqltool.command.value='';" />
		</td>
	<tr>
	</tr>
		<td colspan="2" style="border : solid 2px #ACA899;">
			<input type="radio" name="action" value="command" checked="checked" />Cmd&nbsp;
			<input type="radio" name="action" value="query" />
			Qry <input type="text" name="rows" value="<%=intRows%>" style="width:20px;" />cols&nbsp;
			<input type="submit" />
		</td>
	</tr>
</table>
<table width="100%">
	<tr>
		<td valign="top">
			<textarea name="response" rows="8" cols="80"><%If Request("message") <> "" Then Response.write(Request("message")&vbcrlf)%><%=strResults%></textarea>
		</td>
	</tr>
</table>
</form>
<%End If%>
</body>
</html>

Comments on this post
jmurrayhead agrees: pretty cool, mate
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old June 12th, 2008, 09:33 AM
BLaaaaaaaaaarche's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 43
Thanks: 10
Thanked 6 Times in 4 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

Default

Is this a question?
__________________
"You'll never be as perfect as BLaaaaaaaaarche."
Reply With Quote
  #3 (permalink)  
Old June 12th, 2008, 07:25 PM
dr_rock's Avatar
Drunk Developer

 
Join Date: Jun 2008
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
dr_rock is an unknown quantity at this point
Default

More a rehtorical statement
Reply With Quote
  #4 (permalink)  
Old June 16th, 2008, 08:54 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 534
Thanks: 14
Thanked 39 Times in 38 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft Windows Microsoft .Net Microsoft SQL Server Classic ASP 
Total Awards: 4

Default

So basically this allows you to query the database from a web interface when you can't physically access the database?
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
  #5 (permalink)  
Old June 17th, 2008, 01:02 AM
dr_rock's Avatar
Drunk Developer

 
Join Date: Jun 2008
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
dr_rock is an unknown quantity at this point
Default

Quote:
Originally Posted by jmurrayhead View Post
So basically this allows you to query the database from a web interface when you can't physically access the database?
Yes and I have a couple of auto insert commands to make life easier, note that you must have the command radio checked for commands and the query radio set + number of fields for queries, its great for pulling out schemas.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > Code Samples > Classic ASP

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Buttons Coloring alansidman Microsoft Access 5 May 15th, 2008 03:57 PM
Wizard1 error The command 'MoveComplete' is not valid peebman2000 .Net Development 10 April 28th, 2008 02:52 PM
Basic Login Script (using MS Acesss) BLaaaaaaaaaarche Classic ASP 0 March 24th, 2008 04:50 PM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 10:28 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46