1 # include/wait_show_condition.inc
5 # Waits until the show statement ($show_statement) has one or all of the
6 # rows of the result set for the field ($field) a value which fulfils
7 # a condition ($condition), or the operation times out.
12 # All rows of the result must fulfil the condition if $all_rows_fulfil is 1
13 # else at least one of the result must fulfil the condition.
14 # let $wait_for_all= 1;
15 # let $show_statement= SHOW PROCESSLIST;
17 # let $condition= = 'Updating';
18 # --source include/wait_show_condition.inc
22 # let $wait_timeout= 60; # Override default of 30 seconds with 60.
23 # let $show_statement= SHOW PROCESSLIST;
25 # let $condition= = 'Updating';
26 # --source include/wait_show_condition.inc
28 # Please do not use this use routine if you can replace the SHOW statement
29 # with a select. In such a case include/wait_condition.inc is recommended.
31 # Created: 2009-02-18 mleich
36 --die ERROR IN TEST: the
"condition" variable must be
set
41 --die ERROR IN TEST: the
"field" variable must be
set
46 --die ERROR IN TEST: the
"show_statement" variable must be
set
49 let $max_run_time= 30;
52 let $max_run_time= $wait_timeout;
54 # Reset $wait_timeout so that its value won't be used on subsequent
55 # calls, and default will be used instead.
58 # The smallest timespan till UNIX_TIMESTAMP() gets incremented is ~0 seconds.
59 # We add one second to avoid the case that somebody measures timespans on a
60 # real clock with fractions of seconds, detects that n seconds are sufficient,
61 # assigns n to this routine and suffers because he sometimes gets n - 1
66 let $max_end_time= `SELECT UNIX_TIMESTAMP() + $max_run_time`;
68 if ($wait_for_all != 1)
70 while (`SELECT UNIX_TIMESTAMP() <= $max_end_time AND $found = 0`)
72 # Sleep a bit to avoid too heavy load.
75 let $process_result= 1;
79 let $field_value= query_get_value($show_statement, $field, $rowno);
80 if (`SELECT
'$field_value' $condition`)
85 if ($field_value == No such row)
87 # We are behind the last row of the result set.
88 let $process_result= 0;
96 if ($wait_for_all == 1)
98 while (`SELECT UNIX_TIMESTAMP() <= $max_end_time AND $found = 0`)
100 # Sleep a bit to avoid too heavy load.
103 let $process_result= 1;
107 let $field_value= query_get_value($show_statement, $field, $rowno);
108 if ($field_value == No such row)
113 if (`SELECT $found = 0 AND NOT
'$field_value' $condition`)
115 let process_result= 0;
125 echo # Timeout in include/wait_show_condition.inc
for $condition;
126 echo # show_statement : $show_statement;
127 echo # field : $field;
128 echo # condition : $condition;
129 echo # max_run_time : $max_run_time;