# ==== Purpose ====
#
# Check if a condition holds, fail with debug info ifnot.
#
# The condition is parsed before executed. The following constructs
# are supported:
#
# [SQL_STATEMENT, COLUMN, ROW]
# The square bracket is replaced by the result from SQL_STATEMENT,
# in the given COLUMN and ROW.
#
# Optionally, SQL_STATEMENT may have the form:
# connection:SQL_STATEMENT
# In this case, SQL_STATEMENT is executed on the named connection.
# All other queries executed by this script will be executed on
# the connection that was in use when this script was started.
# The current connection will also be restored at the endof this
# script.
#
# Nested sub-statements on this form are not allowed.
#
# <1>
# This is a shorthand for the result of the first executed square
# bracket. <2> is a shorthand for the second executed square
# bracket, and so on.
#
# ==== Usage ====
#
# --let $assert_text= Relay_Log_Pos must be between min_pos and max_pos
# --let $assert_cond= [SHOW SLAVE STATUS, Relay_Log_Pos, 1] >= $min_posAND <1> <= $max_pos
# [--let $assert_quiet= 1]
# [--let $rpl_debug= 1]
# --source include/assert.inc
#
# Parameters:
#
# $assert_text
# Text that describes what is being checked. This text is written to
# the query log so it should not contain non-deterministic elements.
#
# $assert_cond
# Condition to check. See above for details about the format. The
# condition will be executed as `SELECT $assert_cond`.
#
# Both $assert_condand the result from any substatement on the
# form [SQL_STATEMENT, COLUMN, ROW] will be used in SQL statements,
# inside single quotes (asin'$assert_text'). So any single quotes
# in these texts must be escaped or replaced by double quotes.
#
# $rpl_debug
# Print extra debug info.
# Evaluate square brackets in cond.
--let $_assert_substmt_number= 1
--let $_assert_cond_interp= '$assert_cond'
--let $_assert_lbracket= `SELECT LOCATE('[', $_assert_cond_interp)` while ($_assert_lbracket)
{
# Get position of right bracket
--let $_assert_rbracket= `SELECT LOCATE(']', $_assert_cond_interp)` if (!$_assert_rbracket)
{
--echo BUG IN TEST: Mismatching square brackets in assert_cond.
--echo Original assert_cond='$assert_cond'
--echo Interpolated assert_cond=$_assert_cond_interp
--die BUG IN TEST: Mismatching square brackets in$assert_cond
}
# Get sub-statement from statement. Preserve escapes for single quotes.
--let $_assert_full_substmt= `SELECT QUOTE(SUBSTRING($_assert_cond_interp, $_assert_lbracket + 1, $_assert_rbracket - $_assert_lbracket - 1))`
# Get connection from sub-statement
--let $_assert_colon= `SELECT IF($_assert_full_substmt REGEXP '^[a-zA-Z_][a-zA-Z_0-9]*:', LOCATE(':', $_assert_full_substmt), 0)`
--let $_assert_connection=
--let $_assert_substmt= $_assert_full_substmt if ($_assert_colon)
{
--let $_assert_connection= `SELECT SUBSTRING($_assert_substmt, 1, $_assert_colon - 1)`
# Preserve escapes for single quotes.
--let $_assert_substmt= `SELECT QUOTE(SUBSTRING($_assert_substmt, $_assert_colon + 1))`
}
# Interpolate escapes before using condition outside string context.
--let $_assert_substmt_interp= `SELECT $_assert_substmt`
# Execute and get result from sub-statement if ($_assert_connection)
{ if ($rpl_debug)
{
--echo # debug: connection='$_assert_connection' sub-statement=$_assert_substmt
}
--let $rpl_connection_name= $_assert_connection
--source include/rpl_connection.inc
--let $_assert_substmt_result= query_get_value($_assert_substmt_interp)
--let $rpl_connection_name= $_assert_old_connection
--source include/rpl_connection.inc
} if (!$_assert_connection)
{ if ($rpl_debug)
{
--echo # debug: old connection, sub-statement=$_assert_substmt
}
--let $_assert_substmt_result= query_get_value($_assert_substmt_interp)
} if ($rpl_debug)
{
--echo # debug: result of sub-statement='$_assert_substmt_result'
}
# Replace sub-statement by its result
--let $_assert_cond_interp= `SELECT QUOTE(REPLACE($_assert_cond_interp, CONCAT('[', $_assert_full_substmt, ']'), '$_assert_substmt_result'))`
# Replace result references by result
--let $_assert_cond_interp= `SELECT QUOTE(REPLACE($_assert_cond_interp, '<$_assert_substmt_number>', '$_assert_substmt_result'))`
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.