Siebel VB Language Reference > Siebel VB Language Reference >

SQLRequest Function


This custom VB function establishes a connection to a data source, executes a SQL statement contained in query$, returns the results of the request in the ref() array, and closes the connection.

NOTE:  Siebel VB SQLxxxx functions are supported for non-Unicode databases only.

Syntax

SQLRequest(connectString, query, outputString[, prompt][, columnNames], ref())

Argument
Description
connectString
A string or string variable specifying the data source to connect to. For details on the connect string, read SQLOpen Function.
query
A SQL query
outputString
A string variable to hold the completed connection string if the connection is successful
prompt
An integer that specifies when driver dialog boxes are displayed. For a table of values for prompt, read SQLOpen Function.
columnNames
An integer with a value of 0 or nonzero. When columnNames is nonzero, column names are returned as the first row of the ref() array. If columnNames is omitted, the default is 0.
ref()
An array of type variant for the results appropriate to the action requested; it must be an array even if only one dimension with one element

Returns

A variant containing a negative-numbered error code if the connection cannot be made, the query is invalid, or another error condition occurs. If the request is successful, returns a positive number representing the number of results returned or rows affected. Other SQL statements return 0.

Usage

The SQLRequest function establishes a connection to the data source specified in connectString, executes the SQL statement contained in query, returns the results of the request in the ref() array, and closes the connection.

CAUTION:  This function, as well as the other SQL functions available in Siebel VB, should not be used to query the underlying database. Use the Siebel Object Interfaces to query Siebel data. Use the SQL functions only to query non-Siebel data.

Example

Function WebApplet_PreInvokeMethod (MethodName As String) As Integer
   If MethodName = "queryExtSys" Then

      ' The following opens the datasource SVBTESTW and
      ' executes the query specified by query and returns the
      ' results in destination.

      Dim errors(1 To 10, 1 To 3) As Variant
      Dim destination(1 To 50, 1 To 125) As Variant
      Dim prompt As Integer
      Dim outputStr As String
      Dim retCode As Integer

      ' In the event of a connection error, do not display a
      ' dialog box, return an error
      prompt = 4

      ' SQL Statement to submit. In this example we'll perform a
      ' simple select
      query = "SELECT * FROM authors"

      ' Invoke the SQLRequest function to submit the SQL, execute the
      ' query and return a result set.
      retCode = SQLRequest("DSN=SVBTESTW;UID=sa;PWD=sa", _
               query, outputStr, prompt, 0, destination())

      ' If retCode < 0, an error has occurred. Retrieve the first
      ' error returned in the array and display to the user.
      If retCode < 0 Then
         SQLError destination := errors
         errCounter = 1

         While errors(errCounter,1) <> 0
            TheApplication.RaiseErrorText "Error " & _
            " ODBC error: " & destination(errCounter,1) & _
            " Numeric code = " & destination(errCounter,2) & _
            " Error Text = " & destination(errCounter,3)

            errCounter = errCounter + 1
         Wend
      Else
         ' do some processing of the results
      End If

      WebApplet_PreInvokeMethod = CancelOperation
   Else
      WebApplet_PreInvokeMethod = ContinueOperation
   End If

End Function

See Also

SQLClose Function
SQLError Function
SQLExecQuery Function
SQLGetSchema Function
SQLOpen Function
SQLRetrieve Function
SQLRetrieveToFile Function


 Siebel VB Language Reference
 Published: 18 June 2003