Skip to content

Instantly share code, notes, and snippets.

@greenkey
Created April 29, 2015 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenkey/41954d1f0b5fca39fc3b to your computer and use it in GitHub Desktop.
Save greenkey/41954d1f0b5fca39fc3b to your computer and use it in GitHub Desktop.
vbscript: Execute an SQL query until the result is as expected
' executes the query to the DB while the results is not as expected
' the query MUST return at least one record with a field named CHECK_VAL
' the loop will stop when CHECK_VAL = check_val (Function parameter)
' or when the timeout is reached (milliseconds)
' the return value will be True (check ok) or False (timeout reached)
' waitBetweenQueries is the milliseconds to wait between the query execution
Function waitUntilSQL(connection, sql, check_val, timeout, waitBetweenQueries)
Dim response, startTime
' default values
If IsEmpty(timeout) Then timeout = 60000
If IsEmpty(waitBetweenQueries) Then waitBetweenQueries = 1000
startTime = Timer()
waitUntilSQL = True
' first execution
Log.Message "Executing SQL on " & connection, sql
Set response = connection.Execute(sql)
Do Until CStr(response("CHECK_VAL").Value) = CStr(check_val)
aqUtils.Delay waitBetweenQueries
' check timeout
If FormatNumber(Timer() - startTime) * 1000 >= timeout Then
waitUntilSQL = False
Exit Do
End If
Set response = connection.Execute(sql)
Loop
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment