mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-5816: Stored programs: validation of stored program statements
Added re-parsing of a failing cursor body. Re-parsing of a failing SP statement is implemented by the method validate_lex_and_exec_core(), therefore invocation of the method reset_lex_and_exec_core() inside sp_lex_keeper::cursor_reset_lex_and_exec_core was replaced by the method validate_lex_and_exec_core(). Re-parsing of a failed SP statement is relied upon interface provided by the class sp_lex_instr (the methods used for this goal are is_invalid(), parse_expr(), invalidate(), get_query(), get_expr_query()). To provide access to these methods on opening a cursor, the signature of the method sp_lex_keeper::cursor_reset_lex_and_exec_core was changed to accept a pointer to the class sp_lex_instr instead of the class sp_instr, and the new method get_push_instr() was added into the class sp_cursor. This method is to get access to an instance of the class sp_instr_cpush on opening a cursor (on handling the statement OPEN cursors_name). Default implementation of this method just returns NULL pointer of the type sp_instr_cpush. This method is overridden in the class sp_instr_cpush with trivial implementation { return this; } On handling the statement DECLARE CURSOR FOR the new instruction of the type sp_instr_cpush is added into sp_head. The class sp_instr_cpush holds a text of SELECT query referencing by a cursor declaration. When a cursor is being opened (on handling the statement 'OPEN cur_name') a pointer to sp_instr_cpush is returned by the method sp_cursor::get_push_instr() and this pointer is passed to the method sp_lex_keeper::cursor_reset_lex_and_exec_core in order to open a cursor and provide access to an interface required for SP statement re-parsing in case metadata changes took place. Since real access to a lex object is required on handling instruction sp_instr_cpush (an instance of this class is created during parsing of cursor declaration statement), calling of the method sp_cursor::open is moved from the method sp_instr_copen::exec_core into the method sp_instr_cpush::exec_core. Additionally, updated the methods get_query/get_expr_query in the classes sp_instr_cpush, sp_instr_cursor_copy_struct in order to return correct text of cursor's body taking into account that lexer treated the clause CURSOR FOR/ CURSOR IS as two different tokens following one after another. So, to return a correct text of SELECT statement specified in CURSOR declaration statement, the token FOR/IS should be skipped and text following it should be returned as a text of cursors's query.
This commit is contained in:
@ -5980,6 +5980,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class sp_instr_cpush;
|
||||
|
||||
/* A mediator between stored procedures and server side cursors */
|
||||
class sp_lex_keeper;
|
||||
class sp_cursor: public sp_cursor_statistics
|
||||
@ -6046,6 +6048,7 @@ public:
|
||||
server_side_cursor= NULL;
|
||||
}
|
||||
|
||||
virtual sp_instr_cpush *get_push_instr() { return nullptr; }
|
||||
private:
|
||||
Select_fetch_into_spvars result;
|
||||
Server_side_cursor *server_side_cursor;
|
||||
|
Reference in New Issue
Block a user