PreExecute

PreExecute event of ELS-QB component is fired when the user initiates  the execution of a query within ELS-QB Component and it is the first thing that occurs in the internal query processing chain of ELS-QB component. It occurs before the SQL text is validated against the back-end database and before the internal SQL parsing.

Such a behavior of PreExecute event will take user a chance to manipulate the SQL text in the PreExecute event, which in turn allows implementation of a custom mechanisms for running parameterized queries in the host application.

The following VB pseudo code illustrates the possible usage of this feature of ELS-QB component:

' the frmParam is a VB form in the host application

' via which the user will enter the query parameter value,

' in an ideal siruation, labels and text-boxes in such a form

' will be dynamically created depending on the number of

parameter variables for the parameterized que

 

Private Sub ELS_QBCtrl_PreExecute()

   Dim sSQL As String
   Dim nPos As Integer
   Dim sFldName As String

   ' get the current SQL text to check for ?-symbols
   sSQL = ctrlELSQB.GetSQLText
   nPos = InStr(1, sSQL, "?")
   If nPos > 0 Then

  ' calculate word length and using Mid VB-function
  ' set sFldName to the word following ?-symbol

  ' ... ' pass this parameter name to the frmParam to update label
  frmParam.lblFieldName = sFldName
  frmParam.Show vbModal, Me

  If frmParam.nIsOKed Then

'if the OK button is clicked

sSQL = Left(sSQL, nPos)
sSQL = sSQL + frmParam.txtValue

'use the form entry value
ctrlELSQB.SetQueryText sSQL

'since CancelExecute was not called, automatically

'proceed with the execution of the query

  Else

'the user clicked Cancel button, so cancel the query execution 

ctrlELSQB.CancelExecute

  End If

    End If

 End Sub