Created
April 29, 2015 16:10
-
-
Save greenkey/41954d1f0b5fca39fc3b to your computer and use it in GitHub Desktop.
vbscript: Execute an SQL query until the result is as expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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