Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > Code Samples

Sponsored Links

Discuss "Basic SQL command inteface" in the Code Samples forum.

Code Samples - Search through our code samples to give your application that something extra or provide a code sample of your own.


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old June 12th, 2008, 12:05 AM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Posts: 36
Thanks: 5
Thanked 3 Times in 1 Post
Rep Power: 1
dr_rock is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

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  
Old June 12th, 2008, 09:33 AM
BLaaaaaaaaaarche's Avatar
Moderator
 
Join Date: Mar 2008
Posts: 55
Thanks: 10
Thanked 7 Times in 5 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
HTML & CSS Classic ASP 
Total Awards: 2

Default

Is this a question?
__________________
"You'll never be as perfect as BLaaaaaaaaarche."
Reply With Quote
  #3  
Old June 12th, 2008, 07:25 PM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Posts: 36
Thanks: 5
Thanked 3 Times in 1 Post
Rep Power: 1
dr_rock is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

Default

More a rehtorical statement
Reply With Quote
  #4  
Old June 16th, 2008, 08:54 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 863
Thanks: 20
Thanked 78 Times in 75 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net 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
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
  #5  
Old June 17th, 2008, 01:02 AM
dr_rock's Avatar
Drunk Barn Owl
 
Join Date: Jun 2008
Posts: 36
Thanks: 5
Thanked 3 Times in 1 Post
Rep Power: 1
dr_rock is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

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

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
Basic Questions nboscaino Microsoft Access 16 August 20th, 2008 03:18 PM
[Basic Tools] An intro to making complex databases using simple methods. sbenj69 Microsoft Access 3 June 27th, 2008 12:09 AM
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
[ASP/VBScript] Basic Login Script (using MS Acesss) BLaaaaaaaaaarche Code Samples 0 March 24th, 2008 04:50 PM


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



Content Relevant URLs by vBSEO 3.2.0