ViewRecords: Where the Data Retrieval Process Begins

The viewData.asp file passes four parameters to ViewRecords: oRequest (a Request object), oResponse (a Response object), oServer (a Server object), and optionally ConnectionString (a string).

Code examines the QueryString collection of the Request object to determine whether a query statement must be assembled or whether the query must be run by a stored procedure. The following code fragment shows how the name of the table is assigned to the tableName variable, or alternatively, how the stored procedure name is assigned to the procname variable:

tableName = oRequest.QueryString("tableName")
   If tableName = "" Or IsEmpty(tableName) Then
   
      procName = oRequest.QueryString("procName")

If the query uses a stored procedure, AppendParams is called to retrieve parameter information for the stored procedure (see Calling AppendParams To Retrieve Parameter Information). The stored procedure then runs. If the query does not use a stored procedure, an SQL statement is assembled from information in the QueryString collection. The contents of the fieldList variable in the QueryString collection is appended to the query. If fieldList does not contain a value, the default value "*" is used. The following code shows the query at this stage of assembly:

qryString = qryString & "SELECT " & fieldList & " FROM [" & tableName & "] AS t" 

Additional phrases are added to the query based on the content of the QueryString collection. A WHERE or WHERE CONTAINS clause for a full-text search can be included. The ViewRecords method creates an instance of the ADO Recordset object and opens a recordset on the query.

ViewRecords calls the EmitDTD method (see Creating a DTD on the Fly), passing the recordset and the Response object as parameters. EmitDTD dynamically creates a DTD based on the recordset definition and uses the Write method of the Response object to return the string containing the DTD to the calling ASP page.

The following code writes the first tag for the XML data stream:

 oResponse.Write "<xmldata>" & vbCrLf

ViewRecords then calls the Convert method (see Converting a Recordset To XML), passing the recordset, Response object, and Server object, as the following code illustrates:

Do Until oRs Is Nothing
   If Not oRs.EOF Then Call Convert(oRs, oResponse, oServer)
   Set oRs = oRs.NextRecordset
Loop

The following code writes the end tag for the XML data stream:

 oResponse.Write "</xmldata>"