cleanup: get rid of (Item_splocal*)item downcast
MDEV-5317 out parameters in PREPARE "SELECT ... INTO"

originally based on the patch by Antony T Curtis
MDEV-5317 Compound statement / anonymous blocks

originally based on the patch by Antony T Curtis
cleanup: query rewrites for Item_param and Item_splocal

Fix query rewrites in PS code - it was memcpy-ing the same query tail
many times. Instead use the same logic as in SP code, copy query pieces
into the destination buffer.

Extract this logic into a separate class Rewritable_query_parameter
with Item_param and Item_splocal inheriting from it.

Create a helper class Copy_query_with_rewrite that incapsulates
the query rewriting logic, use it in SP and PS.
MDEV-6603 SBR failure upon executing a prepared statement with input placeholder under anonymous block

Normally, Prepared_statement object rewrites the query on execution
to replace ?-placeholders with values. The rewritten query may be written
to logs (including binlog) or stored in the query cache.

But for compound statements, the whole block is prepared and executed,
while contained statements are logged individually. So it doesn't make
sense to rewrite the original statement block. Instead, we need to rewrite
every contained statement. SP is already doing it to replace SP variables
with values. Let it rewrite PS parameters too in the same loop.
MDEV-6609 SQL inside an anonymous block is executed with wrong SQL_MODE
MDEV-6606 Server crashes in String::append on selecting sql_mode inside anonymous block