/usr/share/cagefs-skeleton/usr/include/mysql/server/private
/* -*- C++ -*- */ /* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ #ifndef _SP_RCONTEXT_H_ #define _SP_RCONTEXT_H_ #ifdef USE_PRAGMA_INTERFACE #pragma interface /* gcc class implementation */ #endif #include "sql_class.h" // select_result_interceptor #include "sp_pcontext.h" // sp_condition_value /////////////////////////////////////////////////////////////////////////// // sp_rcontext declaration. /////////////////////////////////////////////////////////////////////////// class sp_cursor; class sp_lex_keeper; class sp_instr_cpush; class sp_instr_hpush_jump; class Query_arena; class sp_head; class Item_cache; class Virtual_tmp_table; /* This class is a runtime context of a Stored Routine. It is used in an execution and is intended to contain all dynamic objects (i.e. objects, which can be changed during execution), such as: - stored routine variables; - cursors; - handlers; Runtime context is used with sp_head class. sp_head class is intended to contain all static things, related to the stored routines (code, for example). sp_head instance creates runtime context for the execution of a stored routine. There is a parsing context (an instance of sp_pcontext class), which is used on parsing stage. However, now it contains some necessary for an execution things, such as definition of used stored routine variables. That's why runtime context needs a reference to the parsing context. */ class sp_rcontext : public Sql_alloc { public: /// Construct and properly initialize a new sp_rcontext instance. The static /// create-function is needed because we need a way to return an error from /// the constructor. /// /// @param thd Thread handle. /// @param root_parsing_ctx Top-level parsing context for this stored program. /// @param return_value_fld Field object to store the return value /// (for stored functions only). /// /// @return valid sp_rcontext object or NULL in case of OOM-error. static sp_rcontext *create(THD *thd, const sp_head *owner, const sp_pcontext *root_parsing_ctx, Field *return_value_fld, Row_definition_list &defs); ~sp_rcontext(); private: sp_rcontext(const sp_head *owner, const sp_pcontext *root_parsing_ctx, Field *return_value_fld, bool in_sub_stmt); // Prevent use of copying constructor and operator. sp_rcontext(const sp_rcontext &); void operator=(sp_rcontext &); public: /// This class stores basic information about SQL-condition, such as: /// - SQL error code; /// - error level; /// - SQLSTATE; /// - text message. /// /// It's used to organize runtime SQL-handler call stack. /// /// Standard Sql_condition class can not be used, because we don't always have /// an Sql_condition object for an SQL-condition in Diagnostics_area. /// /// Eventually, this class should be moved to sql_error.h, and be a part of /// standard SQL-condition processing (Diagnostics_area should contain an /// object for active SQL-condition, not just information stored in DA's /// fields). class Sql_condition_info : public Sql_alloc, public Sql_condition_identity { public: /// Text message. char *message; /** Row number where the condition has happened */ ulong m_row_number; /// The constructor. /// /// @param _sql_condition The SQL condition. /// @param arena Query arena for SP Sql_condition_info(const Sql_condition *_sql_condition, Query_arena *arena) :Sql_condition_identity(*_sql_condition) { message= strdup_root(arena->mem_root, _sql_condition->get_message_text()); m_row_number= _sql_condition->m_row_number; } }; private: /// This class represents a call frame of SQL-handler (one invocation of a /// handler). Basically, it's needed to store continue instruction pointer for /// CONTINUE SQL-handlers. class Handler_call_frame : public Sql_alloc { public: /// SQL-condition, triggered handler activation. const Sql_condition_info *sql_condition; /// Continue-instruction-pointer for CONTINUE-handlers. /// The attribute contains 0 for EXIT-handlers. uint continue_ip; /// The constructor. /// /// @param _sql_condition SQL-condition, triggered handler activation. /// @param _continue_ip Continue instruction pointer. Handler_call_frame(const Sql_condition_info *_sql_condition, uint _continue_ip) :sql_condition(_sql_condition), continue_ip(_continue_ip) { } }; public: /// Arena used to (re) allocate items on. E.g. reallocate INOUT/OUT /// SP-variables when they don't fit into prealloced items. This is common /// situation with String items. It is used mainly in sp_eval_func_item(). Query_arena *callers_arena; /// Flag to end an open result set before start executing an SQL-handler /// (if one is found). Otherwise the client will hang due to a violation /// of the client/server protocol. bool end_partial_result_set; bool pause_state; bool quit_func; uint instr_ptr; /// The stored program for which this runtime context is created. Used for /// checking if correct runtime context is used for variable handling, /// and to access the package run-time context. /// Also used by slow log. const sp_head *m_sp; ///////////////////////////////////////////////////////////////////////// // SP-variables. ///////////////////////////////////////////////////////////////////////// uint argument_count() const { return m_root_parsing_ctx->context_var_count(); } int set_variable(THD *thd, uint var_idx, Item **value); int set_variable_row_field(THD *thd, uint var_idx, uint field_idx, Item **value); int set_variable_row_field_by_name(THD *thd, uint var_idx, const LEX_CSTRING &field_name, Item **value); int set_variable_row(THD *thd, uint var_idx, List<Item> &items); int set_parameter(THD *thd, uint var_idx, Item **value) { DBUG_ASSERT(var_idx < argument_count()); return set_variable(thd, var_idx, value); } Item_field *get_variable(uint var_idx) const { return m_var_items[var_idx]; } Item **get_variable_addr(uint var_idx) const { return ((Item **) m_var_items.array()) + var_idx; } Item_field *get_parameter(uint var_idx) const { DBUG_ASSERT(var_idx < argument_count()); return get_variable(var_idx); } bool find_row_field_by_name_or_error(uint *field_idx, uint var_idx, const LEX_CSTRING &field_name); bool set_return_value(THD *thd, Item **return_value_item); bool is_return_value_set() const { return m_return_value_set; } ///////////////////////////////////////////////////////////////////////// // SQL-handlers. ///////////////////////////////////////////////////////////////////////// /// Push an sp_instr_hpush_jump instance to the handler call stack. /// /// @param entry The condition handler entry /// /// @return error flag. /// @retval false on success. /// @retval true on error. bool push_handler(sp_instr_hpush_jump *entry); /// Pop and delete given number of instances from the handler /// call stack. /// /// @param count Number of handler entries to pop & delete. void pop_handlers(size_t count); const Sql_condition_info *raised_condition() const { return m_handler_call_stack.elements() ? (*m_handler_call_stack.back())->sql_condition : NULL; } /// Handle current SQL condition (if any). /// /// This is the public-interface function to handle SQL conditions in /// stored routines. /// /// @param thd Thread handle. /// @param ip[out] Instruction pointer to the first handler /// instruction. /// @param cur_spi Current SP instruction. /// /// @retval true if an SQL-handler has been activated. That means, all of /// the following conditions are satisfied: /// - the SP-instruction raised SQL-condition(s), /// - and there is an SQL-handler to process at least one of those /// SQL-conditions, /// - and that SQL-handler has been activated. /// Note, that the return value has nothing to do with "error flag" /// semantics. /// /// @retval false otherwise. bool handle_sql_condition(THD *thd, uint *ip, const sp_instr *cur_spi); /// Remove latest call frame from the handler call stack. /// /// @param da Diagnostics area containing handled conditions. /// /// @return continue instruction pointer of the removed handler. uint exit_handler(Diagnostics_area *da); ///////////////////////////////////////////////////////////////////////// // Cursors. ///////////////////////////////////////////////////////////////////////// /// Push a cursor to the cursor stack. /// /// @param cursor The cursor /// void push_cursor(sp_cursor *cur); void pop_cursor(THD *thd); /// Pop and delete given number of sp_cursor instance from the cursor stack. /// /// @param count Number of cursors to pop & delete. void pop_cursors(THD *thd, size_t count); void pop_all_cursors(THD *thd) { pop_cursors(thd, m_ccount); } sp_cursor *get_cursor(uint i) const { return m_cstack[i]; } ///////////////////////////////////////////////////////////////////////// // CASE expressions. ///////////////////////////////////////////////////////////////////////// /// Set CASE expression to the specified value. /// /// @param thd Thread handler. /// @param case_expr_id The CASE expression identifier. /// @param case_expr_item The CASE expression value /// /// @return error flag. /// @retval false on success. /// @retval true on error. /// /// @note The idea is to reuse Item_cache for the expression of the one /// CASE statement. This optimization takes place when there is CASE /// statement inside of a loop. So, in other words, we will use the same /// object on each iteration instead of creating a new one for each /// iteration. /// /// TODO /// Hypothetically, a type of CASE expression can be different for each /// iteration. For instance, this can happen if the expression contains /// a session variable (something like @@VAR) and its type is changed /// from one iteration to another. /// /// In order to cope with this problem, we check type each time, when we /// use already created object. If the type does not match, we re-create /// Item. This also can (should?) be optimized. bool set_case_expr(THD *thd, int case_expr_id, Item **case_expr_item_ptr); Item *get_case_expr(int case_expr_id) const { return m_case_expr_holders[case_expr_id]; } Item ** get_case_expr_addr(int case_expr_id) const { return (Item**) m_case_expr_holders.array() + case_expr_id; } private: /// Internal function to allocate memory for arrays. /// /// @param thd Thread handle. /// /// @return error flag: false on success, true in case of failure. bool alloc_arrays(THD *thd); /// Create and initialize a table to store SP-variables. /// /// param thd Thread handle. /// /// @return error flag. /// @retval false on success. /// @retval true on error. bool init_var_table(THD *thd, List<Spvar_definition> &defs); /// Create and initialize an Item-adapter (Item_field) for each SP-var field. /// /// param thd Thread handle. /// /// @return error flag. /// @retval false on success. /// @retval true on error. bool init_var_items(THD *thd, List<Spvar_definition> &defs); /// Create an instance of appropriate Item_cache class depending on the /// specified type in the callers arena. /// /// @note We should create cache items in the callers arena, as they are /// used between in several instructions. /// /// @param thd Thread handler. /// @param item Item to get the expression type. /// /// @return Pointer to valid object on success, or NULL in case of error. Item_cache *create_case_expr_holder(THD *thd, const Item *item) const; Virtual_tmp_table *virtual_tmp_table_for_row(uint idx); private: /// Top-level (root) parsing context for this runtime context. const sp_pcontext *m_root_parsing_ctx; /// Virtual table for storing SP-variables. Virtual_tmp_table *m_var_table; /// Collection of Item_field proxies, each of them points to the /// corresponding field in m_var_table. Bounds_checked_array<Item_field *> m_var_items; /// This is a pointer to a field, which should contain return value for /// stored functions (only). For stored procedures, this pointer is NULL. Field *m_return_value_fld; /// Indicates whether the return value (in m_return_value_fld) has been /// set during execution. bool m_return_value_set; /// Flag to tell if the runtime context is created for a sub-statement. bool m_in_sub_stmt; /// Stack of visible handlers. Dynamic_array<sp_instr_hpush_jump *> m_handlers; /// Stack of caught SQL conditions. Dynamic_array<Handler_call_frame *> m_handler_call_stack; /// Stack of cursors. Bounds_checked_array<sp_cursor *> m_cstack; /// Current number of cursors in m_cstack. uint m_ccount; /// Array of CASE expression holders. Bounds_checked_array<Item_cache *> m_case_expr_holders; }; // class sp_rcontext : public Sql_alloc #endif /* _SP_RCONTEXT_H_ */
.
Edit
..
Edit
aligned.h
Edit
aria_backup.h
Edit
assume_aligned.h
Edit
atomic
Edit
authors.h
Edit
backup.h
Edit
bounded_queue.h
Edit
client_settings.h
Edit
compat56.h
Edit
config.h
Edit
contributors.h
Edit
create_options.h
Edit
create_tmp_table.h
Edit
cset_narrowing.h
Edit
custom_conf.h
Edit
data
Edit
datadict.h
Edit
ddl_log.h
Edit
debug.h
Edit
debug_sync.h
Edit
derived_handler.h
Edit
derror.h
Edit
des_key_file.h
Edit
discover.h
Edit
dur_prop.h
Edit
embedded_priv.h
Edit
event_data_objects.h
Edit
event_db_repository.h
Edit
event_parse_data.h
Edit
event_queue.h
Edit
event_scheduler.h
Edit
events.h
Edit
field.h
Edit
field_comp.h
Edit
filesort.h
Edit
filesort_utils.h
Edit
ft_global.h
Edit
gcalc_slicescan.h
Edit
gcalc_tools.h
Edit
grant.h
Edit
group_by_handler.h
Edit
gstream.h
Edit
ha_handler_stats.h
Edit
ha_partition.h
Edit
ha_sequence.h
Edit
handle_connections_win.h
Edit
handler.h
Edit
hash.h
Edit
hash_filo.h
Edit
heap.h
Edit
hostname.h
Edit
ilist.h
Edit
init.h
Edit
innodb_priv.h
Edit
item.h
Edit
item_cmpfunc.h
Edit
item_create.h
Edit
item_func.h
Edit
item_geofunc.h
Edit
item_jsonfunc.h
Edit
item_row.h
Edit
item_strfunc.h
Edit
item_subselect.h
Edit
item_sum.h
Edit
item_timefunc.h
Edit
item_vers.h
Edit
item_windowfunc.h
Edit
item_xmlfunc.h
Edit
json_table.h
Edit
key.h
Edit
keycaches.h
Edit
lex.h
Edit
lex_charset.h
Edit
lex_hash.h
Edit
lex_ident.h
Edit
lex_string.h
Edit
lex_symbol.h
Edit
lex_token.h
Edit
lf.h
Edit
lock.h
Edit
log.h
Edit
log_event.h
Edit
log_event_data_type.h
Edit
log_event_old.h
Edit
log_slow.h
Edit
maria.h
Edit
mariadb.h
Edit
mdl.h
Edit
mem_root_array.h
Edit
message.h
Edit
multi_range_read.h
Edit
my_alarm.h
Edit
my_apc.h
Edit
my_atomic.h
Edit
my_atomic_wrapper.h
Edit
my_base.h
Edit
my_bit.h
Edit
my_bitmap.h
Edit
my_check_opt.h
Edit
my_compare.h
Edit
my_counter.h
Edit
my_cpu.h
Edit
my_crypt.h
Edit
my_decimal.h
Edit
my_default.h
Edit
my_handler_errors.h
Edit
my_json_writer.h
Edit
my_libwrap.h
Edit
my_md5.h
Edit
my_minidump.h
Edit
my_nosys.h
Edit
my_rdtsc.h
Edit
my_rnd.h
Edit
my_service_manager.h
Edit
my_stack_alloc.h
Edit
my_stacktrace.h
Edit
my_time.h
Edit
my_tree.h
Edit
my_uctype.h
Edit
my_user.h
Edit
my_virtual_mem.h
Edit
myisam.h
Edit
myisamchk.h
Edit
myisammrg.h
Edit
myisampack.h
Edit
mysqld.h
Edit
mysqld_default_groups.h
Edit
mysqld_suffix.h
Edit
mysys_err.h
Edit
opt_histogram_json.h
Edit
opt_range.h
Edit
opt_subselect.h
Edit
opt_trace.h
Edit
opt_trace_context.h
Edit
parse_file.h
Edit
partition_element.h
Edit
partition_info.h
Edit
password.h
Edit
pfs_file_provider.h
Edit
pfs_idle_provider.h
Edit
pfs_memory_provider.h
Edit
pfs_metadata_provider.h
Edit
pfs_socket_provider.h
Edit
pfs_stage_provider.h
Edit
pfs_statement_provider.h
Edit
pfs_table_provider.h
Edit
pfs_thread_provider.h
Edit
pfs_transaction_provider.h
Edit
privilege.h
Edit
probes_mysql.h
Edit
probes_mysql_dtrace.h
Edit
probes_mysql_nodtrace.h
Edit
procedure.h
Edit
protocol.h
Edit
providers
Edit
proxy_protocol.h
Edit
queues.h
Edit
records.h
Edit
repl_failsafe.h
Edit
replication.h
Edit
rijndael.h
Edit
rowid_filter.h
Edit
rpl_constants.h
Edit
rpl_filter.h
Edit
rpl_gtid.h
Edit
rpl_injector.h
Edit
rpl_mi.h
Edit
rpl_parallel.h
Edit
rpl_record.h
Edit
rpl_record_old.h
Edit
rpl_reporting.h
Edit
rpl_rli.h
Edit
rpl_tblmap.h
Edit
rpl_utility.h
Edit
scheduler.h
Edit
scope.h
Edit
select_handler.h
Edit
semisync.h
Edit
semisync_master.h
Edit
semisync_master_ack_receiver.h
Edit
semisync_slave.h
Edit
service_versions.h
Edit
session_tracker.h
Edit
set_var.h
Edit
slave.h
Edit
socketpair.h
Edit
source_revision.h
Edit
sp.h
Edit
sp_cache.h
Edit
sp_head.h
Edit
sp_pcontext.h
Edit
sp_rcontext.h
Edit
span.h
Edit
spatial.h
Edit
sql_acl.h
Edit
sql_admin.h
Edit
sql_alloc.h
Edit
sql_alter.h
Edit
sql_analyse.h
Edit
sql_analyze_stmt.h
Edit
sql_array.h
Edit
sql_audit.h
Edit
sql_base.h
Edit
sql_basic_types.h
Edit
sql_binlog.h
Edit
sql_bitmap.h
Edit
sql_bootstrap.h
Edit
sql_cache.h
Edit
sql_callback.h
Edit
sql_class.h
Edit
sql_cmd.h
Edit
sql_connect.h
Edit
sql_const.h
Edit
sql_crypt.h
Edit
sql_cte.h
Edit
sql_cursor.h
Edit
sql_db.h
Edit
sql_debug.h
Edit
sql_delete.h
Edit
sql_derived.h
Edit
sql_digest.h
Edit
sql_digest_stream.h
Edit
sql_do.h
Edit
sql_error.h
Edit
sql_explain.h
Edit
sql_expression_cache.h
Edit
sql_get_diagnostics.h
Edit
sql_handler.h
Edit
sql_help.h
Edit
sql_hset.h
Edit
sql_i_s.h
Edit
sql_insert.h
Edit
sql_join_cache.h
Edit
sql_lex.h
Edit
sql_lifo_buffer.h
Edit
sql_limit.h
Edit
sql_list.h
Edit
sql_load.h
Edit
sql_locale.h
Edit
sql_manager.h
Edit
sql_mode.h
Edit
sql_parse.h
Edit
sql_partition.h
Edit
sql_partition_admin.h
Edit
sql_plist.h
Edit
sql_plugin.h
Edit
sql_plugin_compat.h
Edit
sql_prepare.h
Edit
sql_priv.h
Edit
sql_profile.h
Edit
sql_reload.h
Edit
sql_rename.h
Edit
sql_repl.h
Edit
sql_schema.h
Edit
sql_select.h
Edit
sql_sequence.h
Edit
sql_servers.h
Edit
sql_show.h
Edit
sql_signal.h
Edit
sql_sort.h
Edit
sql_statistics.h
Edit
sql_string.h
Edit
sql_table.h
Edit
sql_test.h
Edit
sql_time.h
Edit
sql_trigger.h
Edit
sql_truncate.h
Edit
sql_tvc.h
Edit
sql_type.h
Edit
sql_type_fixedbin.h
Edit
sql_type_fixedbin_storage.h
Edit
sql_type_geom.h
Edit
sql_type_int.h
Edit
sql_type_json.h
Edit
sql_type_real.h
Edit
sql_type_string.h
Edit
sql_udf.h
Edit
sql_union.h
Edit
sql_update.h
Edit
sql_view.h
Edit
sql_window.h
Edit
ssl_compat.h
Edit
strfunc.h
Edit
structs.h
Edit
sys_vars_shared.h
Edit
t_ctype.h
Edit
table.h
Edit
table_cache.h
Edit
thr_alarm.h
Edit
thr_lock.h
Edit
thr_malloc.h
Edit
thr_timer.h
Edit
thread_cache.h
Edit
threadpool.h
Edit
threadpool_generic.h
Edit
threadpool_winsockets.h
Edit
transaction.h
Edit
tzfile.h
Edit
tztime.h
Edit
uniques.h
Edit
unireg.h
Edit
vers_string.h
Edit
violite.h
Edit
waiting_threads.h
Edit
welcome_copyright_notice.h
Edit
win_tzname_data.h
Edit
winservice.h
Edit
wqueue.h
Edit
wsrep.h
Edit
wsrep_allowlist_service.h
Edit
wsrep_applier.h
Edit
wsrep_binlog.h
Edit
wsrep_client_service.h
Edit
wsrep_client_state.h
Edit
wsrep_condition_variable.h
Edit
wsrep_high_priority_service.h
Edit
wsrep_mutex.h
Edit
wsrep_mysqld.h
Edit
wsrep_mysqld_c.h
Edit
wsrep_on.h
Edit
wsrep_priv.h
Edit
wsrep_schema.h
Edit
wsrep_server_service.h
Edit
wsrep_server_state.h
Edit
wsrep_sst.h
Edit
wsrep_status.h
Edit
wsrep_storage_service.h
Edit
wsrep_thd.h
Edit
wsrep_trans_observer.h
Edit
wsrep_types.h
Edit
wsrep_utils.h
Edit
wsrep_var.h
Edit
wsrep_xid.h
Edit
xa.h
Edit