VbScript (ASP) Access Database XML Accessor Class with Simple POST Interface

No warranty is provided, use at your own risk.


The basic functionality of this class is:
1. Receieve XML code in from a POST variable. This XML mimics SQL code in the way it is structured as shown below.
<?xml version="1.0" encoding="utf-8"?>
<query>
  <insert table="testtable">
    <textField type="text">test text</textField>
    <numberField type="number">275</numberField>
    <memoField type="memo">Memo test text</memoField>
    <booleanField type="yes/no">1</booleanField>
  </insert>
  <update table="testtable" where="[numberField]=275">
    <textField type="text">updated text</textField>
    <numberField type="number">200</numberField>
    <memoField type="memo">updated memo text</memoField>
    <booleanField type="yes/no">0</booleanField>
  </update>
  <select table="testtable" where="[numberField]=200" top="2">
    <textField />
    <numberField />
    <memoField />
    <booleanField />
  </select>
  <delete table="testtable" where="[numberField]=200" />
</query>
2. Take that XML code and convert it into MS Access style SQL statements and perform them on the specified database file.
3. Return XML code telling the caller what the results where and/or return result data structured in XML format.
4. Multiple statements can be sent at one time, which makes things more efficient.

Download the source file (remove .txt extension) here.

<% option explicit
' Copyright 2008 Scott J. Waldron
' www.thewayofcoding.com
'
' GNU LESSER GENERAL PUBLIC LICENSE
'                       Version 3, 29 June 2007
'
' Copyright (C) 2007 Free Software Foundation, Inc. &lt;http://fsf.org/&gt;
' Everyone is permitted to copy and distribute verbatim copies
' of this license document, but changing it is not allowed.
'
'
'  This version of the GNU Lesser General Public License incorporates
'the terms and conditions of version 3 of the GNU General Public
'License, supplemented by the additional permissions listed below.
'
'  0. Additional Definitions.
'
'  As used herein, "this License" refers to version 3 of the GNU Lesser
'General Public License, and the "GNU GPL" refers to version 3 of the GNU
'General Public License.
'
'  "The Library" refers to a covered work governed by this License,
'other than an Application or a Combined Work as defined below.
'
'  An "Application" is any work that makes use of an interface provided
'by the Library, but which is not otherwise based on the Library.
'Defining a subclass of a class defined by the Library is deemed a mode
'of using an interface provided by the Library.
'
'  A "Combined Work" is a work produced by combining or linking an
'Application with the Library.  The particular version of the Library
'with which the Combined Work was made is also called the "Linked
'Version".
'
'  The "Minimal Corresponding Source" for a Combined Work means the
'Corresponding Source for the Combined Work, excluding any source code
'for portions of the Combined Work that, considered in isolation, are
'based on the Application, and not on the Linked Version.
'
'  The "Corresponding Application Code" for a Combined Work means the
'object code and/or source code for the Application, including any data
'and utility programs needed for reproducing the Combined Work from the
'Application, but excluding the System Libraries of the Combined Work.
'
'  1. Exception to Section 3 of the GNU GPL.
'
'  You may convey a covered work under sections 3 and 4 of this License
'without being bound by section 3 of the GNU GPL.
'
'  2. Conveying Modified Versions.
'
'  If you modify a copy of the Library, and, in your modifications, a
'facility refers to a function or data to be supplied by an Application
'that uses the facility (other than as an argument passed when the
'facility is invoked), then you may convey a copy of the modified
'version:
'
'   a) under this License, provided that you make a good faith effort to
'   ensure that, in the event an Application does not supply the
'   function or data, the facility still operates, and performs
'   whatever part of its purpose remains meaningful, or
'
'   b) under the GNU GPL, with none of the additional permissions of
'   this License applicable to that copy.
'
'  3. Object Code Incorporating Material from Library Header Files.
'
'  The object code form of an Application may incorporate material from
'a header file that is part of the Library.  You may convey such object
'code under terms of your choice, provided that, if the incorporated
'material is not limited to numerical parameters, data structure
'layouts and accessors, or small macros, inline functions and templates
'(ten or fewer lines in length), you do both of the following:
'
'   a) Give prominent notice with each copy of the object code that the
'   Library is used in it and that the Library and its use are
'   covered by this License.
'
'   b) Accompany the object code with a copy of the GNU GPL and this license
'   document.
'
'  4. Combined Works.
'
'  You may convey a Combined Work under terms of your choice that,
'taken together, effectively do not restrict modification of the
'portions of the Library contained in the Combined Work and reverse
'engineering for debugging such modifications, if you also do each of
'the following:
'
'   a) Give prominent notice with each copy of the Combined Work that
'   the Library is used in it and that the Library and its use are
'   covered by this License.
'
'   b) Accompany the Combined Work with a copy of the GNU GPL and this license
'   document.
'
'   c) For a Combined Work that displays copyright notices during
'   execution, include the copyright notice for the Library among
'   these notices, as well as a reference directing the user to the
'   copies of the GNU GPL and this license document.
'
'   d) Do one of the following:
'
'       0) Convey the Minimal Corresponding Source under the terms of this
'       License, and the Corresponding Application Code in a form
'       suitable for, and under terms that permit, the user to
'       recombine or relink the Application with a modified version of
'       the Linked Version to produce a modified Combined Work, in the
'       manner specified by section 6 of the GNU GPL for conveying
'       Corresponding Source.
'
'       1) Use a suitable shared library mechanism for linking with the
'       Library.  A suitable mechanism is one that (a) uses at run time
'       a copy of the Library already present on the user's computer
'       system, and (b) will operate properly with a modified version
'       of the Library that is interface-compatible with the Linked
'       Version.
'
'   e) Provide Installation Information, but only if you would otherwise
'   be required to provide such information under section 6 of the
'   GNU GPL, and only to the extent that such information is
'   necessary to install and execute a modified version of the
'   Combined Work produced by recombining or relinking the
'   Application with a modified version of the Linked Version. (If
'   you use option 4d0, the Installation Information must accompany
'   the Minimal Corresponding Source and Corresponding Application
'   Code. If you use option 4d1, you must provide the Installation
'   Information in the manner specified by section 6 of the GNU GPL
'   for conveying Corresponding Source.)
'
'  5. Combined Libraries.
'
'  You may place library facilities that are a work based on the
'Library side by side in a single library together with other library
'facilities that are not Applications and are not covered by this
'License, and convey such a combined library under terms of your
'choice, if you do both of the following:
'
'   a) Accompany the combined library with a copy of the same work based
'   on the Library, uncombined with any other library facilities,
'   conveyed under the terms of this License.
'
'   b) Give prominent notice with the combined library that part of it
'   is a work based on the Library, and explaining where to find the
'   accompanying uncombined form of the same work.
'
'  6. Revised Versions of the GNU Lesser General Public License.
'
'  The Free Software Foundation may publish revised and/or new versions
'of the GNU Lesser General Public License from time to time. Such new
'versions will be similar in spirit to the present version, but may
'differ in detail to address new problems or concerns.
'
'  Each version is given a distinguishing version number. If the
'Library as you received it specifies that a certain numbered version
'of the GNU Lesser General Public License "or any later version"
'applies to it, you have the option of following the terms and
'conditions either of that published version or of any later version
'published by the Free Software Foundation. If the Library as you
'received it does not specify a version number of the GNU Lesser
'General Public License, you may choose any version of the GNU Lesser
'General Public License ever published by the Free Software Foundation.
'
'  If the Library as you received it specifies that a proxy can decide
'whether future versions of the GNU Lesser General Public License shall
'apply, that proxy's public statement of acceptance of any version is
'permanent authorization for you to choose that version for the
'Library.
'
'--------------- EXAMPLE ON HOW TO USE THIS CLASS ---------------
' dim passedFormDatabaseName, passedFormPassword, passedXmlFormData, constructedXmlDocument 
'
' 'start constructing the return document
' constructedXmlDocument = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf & "<returndata>" & vbCrLf
'
' passedFormDatabaseName = request.form("databasefilename")
' passedFormPassword = request.form("databasepassword")
' passedPostBackData = request.form("postbackdata")
'
' 'create an instance of the access database connector class
' set adbInstance = new AccessDatabase
'	
' 'define the database filename, note that it should be in the same directory as this script
' adbInstance.setDatabaseFilename = passedFormDatabaseName
'	
' 'include a password if available
' if passedFormPassword <> "" then
'  adbInstance.setDatabasePassword = passedFormPassword
' end if
'	
' 'initialize the instance
' call adbInstance.initialize()
'
' 'write whatever xml was generated by the class instance
' constructedXmlDocument = constructedXmlDocument & adbInstance.xmlToDatabase(passedXmlFormData)
'
' set adbInstance = nothing
'
' 'finish off the return document
' constructedXmlDocument = constructedXmlDocument & vbCrLf & "</returndata>"
'
' 'tell the caller what type of data is being returned
' response.contentType = "text/xml"
' 'send the xml document to the user
' response.write(constructedXmlDocument)
'
'-----------------------------------------------------------------
'
' You would then post data to this code in the two (or 3 with password) elements.
' Here is an example of a insert statement:
' <?xml version="1.0" encoding="utf-8"?>
' <query>
'  <insert table="comment">
'   <entryid>1</entryid>
'   <bodytext>
'    <![CDATA[text here...]]>
'   </bodytext>
'   <username>person</username>
'   <timestamp>3:45pm</timestamp>
'  </insert>
' </query>
'
' We are inserting a comment into a comment table, entry id would be the foreign key.
' Each tag inside the insert tag, corresponds to a field in the database.
' All of this XML-AS-SQL, gets converted to MS-Access SQL code and then written to whatever database file is specified.
'
' All XML sent to the class should be encased in the <query> tags
' Inside that, there can be as many sql commands as you want (currently INSERT, UPDATE, DELETE, SELECT statements).
'
'
'
'''
''' AccessDatabase Class with Post Data Processor
''' A generic class that will allow access to an MS Access database in the same directory as the script file.
''' 
class AccessDatabase
	dim dbConnection 'the database connection object used throughout the script
	dim errorHandlerState 'defines whether the error handler is on or not
	dim fullSitePath
	dim databaseFilename
	dim databasePassword
	dim errorList 'will store a list of errors that happen in execution
		
	'''
	''' Property to set the database filename (necessary before calling initialize())
	public property let setDatabaseFilename(filename)
		databaseFilename = filename
	end property
	
	'''
	''' property to set the database password (not necessary unless the db has a password)
	public property let setDatabasePassword(password)
		databasePassword = password
	end property
	
	'''
	''' property to get a list of errors that happened
	public property get getErrors()
		getErrors = errorList
	end property
		
	'''
	''' Class destructor that closes and destroys the database object when the class is no longer in use.
	private sub Class_Terminate()
		'make sure the database object is closed
		call closeDatabaseConnection()
	end sub
		
	'''
	''' Creates the database connection based on data that the user passed to the object.
	public function initialize()
		dim functionSuccess
		functionSuccess = true
		errorList = "" 'get the error variable ready in case it is needed
		
		'determine whether the errors should be captured or not.
		errorHandlerState = false
		
		'get the full directory path to this script file
		fullSitePath = getFullPath()
		
		'before trying to load the database
		if databaseFilename <> "" then
			call initializeDatabaseConnection()
		end if
		
		initialize = functionSuccess
	end function
		
	'''
	''' This function processes whatever errors happened
	private function processError()
		'save the current error before calling any other functions
		dim errorNumber, errorDescription, errorSource, errorTimestamp
		errorNumber = err.number
		errorDescription = err.description
		errorSource = err.source
		errorTimestamp = date() & " " & time()
		errorList = errorList & vbCrLf & "<error>" & cleanInput(errorDescription) & "</error>" & vbCrLf
		err.clear
	end function
	
	'''
	''' Connect to the database so we can perform queries.
	private function initializeDatabaseConnection()
		if errorHandlerState = true then on error resume next end if
		'open the database
		dim fullDbFilePath, databaseConnectionString
		
		'create the full path to the database file including the actual filename
		fullDbFilePath = fullSitePath & databaseFilename
		
		'append the database
		databaseConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fullDbFilePath & ";"
		
		'add a password to the connection string if it is available
		if databasePassword <> "" then
			databaseConnectionString = databaseConnectionString & "Jet OLEDB:Database Password=" & databasePassword & ";"
		end if
		
		'create the database object
		set dbConnection = Server.CreateObject("ADODB.Connection")
		
		''open a connection to the database
		call dbConnection.open(databaseConnectionString)
		
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
	
	'''
	''' Close the global database connection
	private function closeDatabaseConnection()
		if errorHandlerState = true then on error resume next end if
		'close the database
		call dbConnection.close()
		set dbConnection = nothing
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
	
	'''
	'''This function returns the full path to this script file eg: c:\\folder\folder\folder\
	private function getFullPath()
		if errorHandlerState = true then on error resume next end if
		dim absRoot, lsPath, arPath
		absRoot = request.ServerVariables("APPL_PHYSICAL_PATH")
		lsPath = Request.ServerVariables("SCRIPT_NAME")
		arPath = split(lsPath, "/")
		arPath(uBound(arPath, 1)) = ""
		absRoot = left(absRoot, LEN(absRoot) - 1) & join(arPath, "\")
		getFullPath = absRoot
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
	
	'''
	''' Take xml data (most likely from a form submission and insert it into a database
	''' the xml data should be like this:
	''' <query>
	'''   <insert table="tablename">
	'''     <fieldname>value</fieldname>
	'''   </insert>
	'''   <update table="tablename" where="statement">
    	'''     <fieldname>value</fieldname>
	'''   </update>
	'''   <delete table="tablename" where="statement" />
	''' </query>
	public function xmlToDatabase(xmlData)
		if errorHandlerState = true then on error resume next end if
		dim objXmlData, queryXmlReturnData, resultingSql(), resultCounter, resultXmlText
		
		'initialize the xml object
		set objXmlData = Server.CreateObject("Msxml2.DOMDocument.6.0")
		
		'make the object a standard synchronous type
		objXmlData.aSync = false
		
		'process the textual xml data into the object
		call objXmlData.loadXml(xmlData)
		
		'recursively go through the xml file and perform the functions on the database
		call xmlToQueryStringArray(objXmlData.documentElement, resultingSql, 0)
		
		'loop through the resulting sql statements and execute them on the database
		if isArray(resultingSql) then
			queryXmlReturnData = processQueryStringArray(resultingSql)
			resultXmlText = queryXmlReturnData
		else
			resultXmlText = ""
		end if
		
		'destroy the object as it is done being used
		set objXmlData = nothing
		
		'return to the caller whatever xml result data was generated
		xmlToDatabase = resultXmlText
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
	
	'''
	''' This takes an array of sql statements and executes them on the database.
	''' it will return data as an xml document
	''' <result success="true" />
	''' <result success="true">
	''' <row>
	''' <field>value</field>
	''' <field2>value</field2>
	''' </row>
	''' <row>
	''' <field>value</field>
	''' <field2>value</field2>
	''' </row>
	private function processQueryStringArray(byRef queryStringArray())
		if errorHandlerState = true then on error resume next end if
		dim resultingXml, resultCounter, dbCommand
		resultingXml = ""
		
		'create a command object so sql can be executed
		set dbCommand = server.createObject("ADODB.Command")
		
		'give the command object a reference to the connection object
		dbCommand.activeConnection = dbConnection
		
		'loop through the sql commands and execute them on the database
		'create xml code that will be of use to the caller 
		for resultCounter = 0 to uBound(queryStringArray) - 1
			dim rowsAffectedCount, dbRecordPointer
			
			'set the command to be executed
			dbCommand.commandText = queryStringArray(resultCounter)
			
			'execute the command on the database
			set dbRecordPointer = dbCommand.execute(rowsAffectedCount) 'adCmdText = 1
			
			'if there were rows affected in this query, make note of that fact
			if rowsAffectedCount > 0 then
				'there must have been rows modified, so note that
				resultingXml = resultingXml & "<result success=""true"" />" & vbCrLf
			else 'no rows were affected, so this could be a select statement
				'see if there is actual data being returned (aka from a select statement) before trying to process anything
				if not dbRecordPointer is nothing then
					if dbRecordPointer.state = 1 then '1 = adStateOpen
						if dbRecordPointer.BOF = false then
							'go through the returned records and generate an xml document out of them
							resultingXml = resultingXml & "<result success=""true"">" & vbCrLf
							while dbRecordPointer.EOF = false
								dim fieldCounter
								
								'start the row tag
								resultingXml = resultingXml & "<row>" & vbCrLf
								
								'loop through each field in the record
								'generate xml code that will hold the record data
								for fieldCounter = 0 to dbRecordPointer.fields.count - 1
									resultingXml = resultingXml & "<" & dbRecordPointer.fields(fieldCounter).name & "><![CDATA[" & vbCrLf & _
									dbRecordPointer.fields(fieldCounter).value & vbCrLf & "]]></" & dbRecordPointer.fields(fieldCounter).name & ">" & vbCrLf
								next
								'end the row tag
								resultingXml = resultingXml & "</row>" & vbCrLf
								
								'move to the next record
								dbRecordPointer.MoveNext()
							wEnd
							'end the result and query tags
							resultingXml = resultingXml & "</result>" & vbCrLf & vbCrLf
							
							'destroy the record set object
							set dbRecordPointer = nothing
						else 'for some reason the results don't exist, return with a false result
							resultingXml = resultingXml & "<result success=""false"" />" & vbCrLf
						end if
					else 'no results were returned, so return with a false result
						resultingXml = resultingXml & "<result success=""false"" />" & vbCrLf
					end if
				else 'the object was null, so return with a false result
					resultingXml = resultingXml & "<result success=""false"" />" & vbCrLf
				end if
			end if
		next
		'make sure to close the recordset object
		if not dbRecordPointer is nothing then
			if dbRecordPointer.state <> 0 then '0 = adStateClosed
				dbRecordPointer.close()
			end if
		end if
		
		'destroy the command object as it is not needed anymore
		set dbCommand = nothing
		
		'return the resulting xml, that defines what happened with the sql
		processQueryStringArray = resultingXml
		
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
	
	'''
	''' Takes an xml document object and converts it into a string of SQL statements
	''' This xml code:
	''' <query>
	'''   <insert table="tablename">
	'''     <fieldname type="text">value</fieldname>
	'''   </insert>
	''' </query>
	''' Would be converted to:
	''' INSERT INTO [tablename] (fieldname) VALUES ('value');
	''' if you don't specify a type, it will be added as a string, if the field is numeric, an error will be thrown
	private sub xmlToQueryStringArray(xmlNode, byRef resultingSql(), totalResultCount)
		if errorHandlerState = true then on error resume next end if
		dim partialSqlCode
		partialSqlCode = ""
		
		'make sure there is an xml node to process (not empty, null, or error)
		if not xmlNode is nothing then
			'test the current node to see if it is a special keyword (insert, update, delete)
			select case xmlNode.nodeName 'figure out what to do with this current xml tag
				case "query": 'loop through all of the queries that were asked to be executed
					'this should be the first element of the xml file, we should process each child item as an sql statement
					dim queryChildCounter
					'loop through all of the children nodes of this query block
					for queryChildCounter = 0 to xmlNode.childNodes.length - 1
						dim queryXmlChildNode
						set queryXmlChildNode = xmlNode.childNodes(queryChildCounter)
						
						'expand the array so we can insert another statement into it
						reDim preserve resultingSql(totalResultCount + 1)
						
						'process each statement in this query
						call xmlToQueryStringArray(xmlNode.childNodes(queryChildCounter), resultingSql, totalResultCount)
						
						'get ready for any additional query strings that need to be made
						totalResultCount = totalResultCount + 1
					next
					
				case "insert":
					'get the table name for this insert
					dim insertTableAttribute
					insertTableAttribute = xmlNode.getAttribute("table")
					
					'make sure a table attribute was specified
					if insertTableAttribute <> "" then
						partialSqlCode = partialSqlCode & "INSERT INTO [" & insertTableAttribute & "] ("
						
						dim insertChildCount
						dim insertChildrenCounter
						dim insertSqlFieldList, insertSqlValueList
						insertSqlFieldList = ""
						insertSqlValueList = ""
						insertChildCount = xmlNode.childNodes.length - 1
						
						'loop through all of the children nodes
						for insertChildrenCounter = 0 to insertChildCount
							dim xmlChildNode
							set xmlChildNode = xmlNode.childNodes(insertChildrenCounter)
							dim insertChildTypeAttribute
							
							'get they data type for this field so we can know how to write the sql statement
							insertChildTypeAttribute = lCase(xmlChildNode.getAttribute("type"))
							
							'set a default if the type could not be returned
							'this still may cause issues if the type was an integer, but the caller didn't specify...
							if isNull(insertChildTypeAttribute) then
								insertChildTypeAttribute = "text"
							end if
							
							dim tempFieldName, tempFieldValue
							tempFieldName = xmlChildNode.nodeName
							tempFieldValue = xmlChildNode.text
							
							'piece together the statement
							if insertChildrenCounter <> insertChildCount then
								if insertChildTypeAttribute <> "number" then
									insertSqlFieldList = insertSqlFieldList & "[" &  cleanInput(tempFieldName) & "], "
									insertSqlValueList = insertSqlValueList & "'" &  cleanInput(tempFieldValue) & "', "
								else
									insertSqlFieldList = insertSqlFieldList & "[" &  cleanInput(tempFieldName) & "], "
									insertSqlValueList = insertSqlValueList &  cleanInput(tempFieldValue) & ", "
								end if
							else
								if insertChildTypeAttribute <> "number" then
									insertSqlFieldList = insertSqlFieldList & "[" &  cleanInput(tempFieldName) & "])"
									insertSqlValueList = insertSqlValueList & "'" &  cleanInput(tempFieldValue) & "')"
								else
									insertSqlFieldList = insertSqlFieldList & "[" &  cleanInput(tempFieldName) & "])"
									insertSqlValueList = insertSqlValueList &  cleanInput(tempFieldValue) & ")"
								end if
							end if
						next
						
						'piece together the sql statement
						partialSqlCode = partialSqlCode & insertSqlFieldList & " VALUES (" & insertSqlValueList
					end if
					
					'assign all data that was constructed in this pass to the proper array index
					resultingSql(totalResultCount) = partialSqlCode
					
				case "update":
					'get the table name for this update as well as the where statement
					dim updateTableAttribute, updateWhereAttribute
					updateTableAttribute = xmlNode.getAttribute("table")
					updateWhereAttribute = xmlNode.getAttribute("where")
					
					'make sure a table and where statement were specified
					if updateTableAttribute <> "" and updateWhereAttribute <> "" then
						partialSqlCode = partialSqlCode & "UPDATE [" & updateTableAttribute & "] SET "
						
						dim updateChildCount, updateChildrenCounter
						
						'save the programming type count (eg. count that starts at 0)
						updateChildCount = xmlNode.childNodes.length - 1
						
						'loop through all of the children nodes
						for updateChildrenCounter = 0 to updateChildCount
							dim updateXmlChildNode, updateChildTypeAttribute
							set updateXmlChildNode = xmlNode.childNodes(updateChildrenCounter)
							
							'get they data type for this field so we can know how to write the sql statement
							updateChildTypeAttribute = lCase(updateXmlChildNode.getAttribute("type"))
							
							'set a default if the type could not be returned
							'this still may cause issues if the type was an integer, but the caller didn't specify...
							if isNull(updateChildTypeAttribute) then
								updateChildTypeAttribute = "text"
							end if
							
							'add to the string differently depending on if this is the last one or not
							if updateChildrenCounter <> updateChildCount then
								if updateChildTypeAttribute <> "number" then
									partialSqlCode = partialSqlCode & "[" & cleanInput(updateXmlChildNode.nodeName) & "]='" & cleanInput(updateXmlChildNode.text) & "', "
								else
									partialSqlCode = partialSqlCode & "[" & cleanInput(updateXmlChildNode.nodeName) & "]=" & cleanInput(updateXmlChildNode.text) & ", "
								end if
							else
								if updateChildTypeAttribute <> "number" then
									partialSqlCode = partialSqlCode & "[" & cleanInput(updateXmlChildNode.nodeName) & "]='" & cleanInput(updateXmlChildNode.text) & "' "
								else
									partialSqlCode = partialSqlCode & "[" & cleanInput(updateXmlChildNode.nodeName) & "]=" & cleanInput(updateXmlChildNode.text) & " "
								end if
							end if
						next
						
						partialSqlCode = partialSqlCode & "WHERE " & updateWhereAttribute
					end if
					
					'assign all data that was constructed in this pass to the proper array index
					resultingSql(totalResultCount) = partialSqlCode
					
				case "delete":
					'get the table name for this delete as well as the where statement
					dim deleteTableAttribute, deleteWhereAttribute
					deleteTableAttribute = xmlNode.getAttribute("table")
					deleteWhereAttribute = xmlNode.getAttribute("where")
					
					if deleteTableAttribute <> "" and deleteWhereAttribute <> "" then
						partialSqlCode = partialSqlCode & "DELETE FROM [" & deleteTableAttribute & "] WHERE " & deleteWhereAttribute
					end if
					
					'assign all data that was constructed in this pass to the proper array index
					resultingSql(totalResultCount) = partialSqlCode
					
				case "select":
					'get the table name, where statement, and optional top statement (aka. record return limit)
					dim selectTableAttribute, selectWhereAttribute, selectTopAttribute, selectOrderByAttribute, selectCount, selectReturnList
					selectTableAttribute = xmlNode.getAttribute("table")
					selectWhereAttribute = xmlNode.getAttribute("where")
					selectTopAttribute = xmlNode.getAttribute("top")
					selectOrderByAttribute = xmlNode.getAttribute("order")
					selectCount = xmlNode.getAttribute("count")
					
					partialSqlCode = partialSqlCode & "SELECT "
					
					if selectTableAttribute <> "" then
						'see if the caller only wants a count if rows
						if selectCount <> "" then
							selectReturnList = "COUNT(" & selectCount & ") "
						else 'not trying to get a count, so process the selection list
							'if the caller wants only a certain number of results, set that in the sql statement
							if selectTopAttribute <> "" then
								partialSqlCode = partialSqlCode & "TOP " & selectTopAttribute & " "
							end if
							
							dim selectChildCount, selectChildrenCounter
							selectChildCount = xmlNode.childNodes.length - 1
							selectReturnList = ""
							
							'loop through all of the children nodes
							for selectChildrenCounter = 0 to selectChildCount
								dim selectXmlChildNode
								set selectXmlChildNode = xmlNode.childNodes(selectChildrenCounter)
								
								if selectChildrenCounter <> selectChildCount then
									selectReturnList = selectReturnList & "[" & cleanInput(selectXmlChildNode.nodeName) & "], "
								else
									selectReturnList = selectReturnList & "[" &  cleanInput(selectXmlChildNode.nodeName) & "]"
								end if
							next
						end if
						
						'if the caller didn't specify fields to return, return all of them with *
						if selectReturnList <> "" then
							partialSqlCode = partialSqlCode & selectReturnList & " FROM [" & selectTableAttribute & "]"
						else
							partialSqlCode = partialSqlCode & "* FROM [" & selectTableAttribute & "]"
						end if
						
						'add a where statement if available
						if selectWhereAttribute <> "" then
							partialSqlCode = partialSqlCode & " WHERE " & selectWhereAttribute
						end if
						
						'add an order by statement if the caller specified one
						if selectOrderByAttribute <> "" then
							partialSqlCode = partialSqlCode & " ORDER BY " & selectOrderByAttribute
						end if
					end if

					'assign all data that was constructed in this pass to the proper array index
					resultingSql(totalResultCount) = partialSqlCode
			end select
		end if
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end sub
		
	'''
	''' Takes an input and replaces all characters that could cause problems with their html escaped equivalents.
	private function cleanInput(inputStringData)
		if errorHandlerState = true then on error resume next end if
		dim fixedString
		fixedString = inputStringData 'save a copy so we can to multiple replacements on the string
		
		if inputStringData <> "" then
			dim replacementList(5, 2)
			replacementList(0,0) = """" 'an " character
			replacementList(0,1) = "&#34;" 'an " character
			replacementList(1,0) = "'"
			replacementList(1,1) = "&#39;" 'an ' character
			replacementList(2,0) = "<"
			replacementList(2,1) = "&#60;" 'an < character
			replacementList(3,0) = ">"
			replacementList(3,1) = "&#62;" 'an > character
			replacementList(4,0) = "\"
			replacementList(4,1) = "&#92;" 'an \ character
			
			'replace any matching characters it finds with their html encoded values
			dim i 'counter variable
			for i = 0 to 4
				'take each related pair and do the replacement
				fixedString = replace(fixedString, replacementList(i, 0), replacementList(i, 1))
			next
			
			fixedString = trim(fixedString)
		end if
		
		cleanInput = fixedString
		if errorHandlerState = true and err.number <> 0 then processError() end if
	end function
end class

%>