summaryrefslogtreecommitdiff
path: root/sql/sp_head.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sp_head.h')
-rw-r--r--sql/sp_head.h120
1 files changed, 86 insertions, 34 deletions
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 409db33ef02..604190079cb 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -30,8 +30,9 @@
#include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
#include "sql_class.h" // THD, set_var.h: THD
#include "set_var.h" // Item
-#include "sp.h"
+#include "sp_pcontext.h" // sp_pcontext
#include <stddef.h>
+#include "sp.h"
/**
@defgroup Stored_Routines Stored Routines
@@ -39,6 +40,11 @@
@{
*/
+// Values for the type enum. This reflects the order of the enum declaration
+// in the CREATE TABLE command.
+//#define TYPE_ENUM_FUNCTION 1 #define TYPE_ENUM_PROCEDURE 2 #define
+//TYPE_ENUM_TRIGGER 3 #define TYPE_ENUM_PROXY 4
+
Item_result
sp_map_result_type(enum enum_field_types type);
@@ -48,12 +54,9 @@ sp_map_item_type(enum enum_field_types type);
uint
sp_get_flags_for_command(LEX *lex);
-struct sp_label;
class sp_instr;
class sp_instr_opt_meta;
class sp_instr_jump_if_not;
-struct sp_cond_type;
-struct sp_variable;
/*************************************************************************/
@@ -119,6 +122,8 @@ public:
sp_name(LEX_STRING db, LEX_STRING name, bool use_explicit_name)
: m_db(db), m_name(name), m_explicit_name(use_explicit_name)
{
+ if (lower_case_table_names && m_db.str)
+ m_db.length= my_casedn_str(files_charset_info, m_db.str);
m_qname.str= 0;
m_qname.length= 0;
}
@@ -156,7 +161,21 @@ public:
LOG_SLOW_STATEMENTS= 256, // Used by events
LOG_GENERAL_LOG= 512, // Used by events
HAS_SQLCOM_RESET= 1024,
- HAS_SQLCOM_FLUSH= 2048
+ HAS_SQLCOM_FLUSH= 2048,
+
+ /**
+ Marks routines that directly (i.e. not by calling other routines)
+ change tables. Note that this flag is set automatically based on
+ type of statements used in the stored routine and is different
+ from routine characteristic provided by user in a form of CONTAINS
+ SQL, READS SQL DATA, MODIFIES SQL DATA clauses. The latter are
+ accepted by parser but pretty much ignored after that.
+ We don't rely on them:
+ a) for compatibility reasons.
+ b) because in CONTAINS SQL case they don't provide enough
+ information anyway.
+ */
+ MODIFIES_DATA= 4096
};
stored_procedure_type m_type;
@@ -274,6 +293,15 @@ public:
*/
Security_context m_security_ctx;
+ /**
+ List of all items (Item_trigger_field objects) representing fields in
+ old/new version of row in trigger. We use this list for checking whenever
+ all such fields are valid at trigger creation time and for binding these
+ fields to TABLE object at table open (although for latter pointer to table
+ being opened is probably enough).
+ */
+ SQL_I_List<Item_trigger_field> m_trg_table_fields;
+
static void *
operator new(size_t size) throw ();
@@ -312,17 +340,26 @@ public:
bool
execute_procedure(THD *thd, List<Item> *args);
+ static void
+ show_create_routine_get_fields(THD *thd, int type, List<Item> *fields);
+
bool
show_create_routine(THD *thd, int type);
int
add_instr(sp_instr *instr);
- inline uint
- instructions()
- {
- return m_instr.elements;
- }
+ /**
+ Returns true if any substatement in the routine directly
+ (not through another routine) modifies data/changes table.
+
+ @sa Comment for MODIFIES_DATA flag.
+ */
+ bool modifies_data() const
+ { return m_flags & MODIFIES_DATA; }
+
+ inline uint instructions()
+ { return m_instr.elements; }
inline sp_instr *
last_instruction()
@@ -352,12 +389,12 @@ public:
/// Put the instruction on the backpatch list, associated with the label.
int
- push_backpatch(sp_instr *, struct sp_label *);
+ push_backpatch(sp_instr *, sp_label *);
/// Update all instruction with this label in the backpatch list to
/// the current position.
void
- backpatch(struct sp_label *);
+ backpatch(sp_label *);
/// Start a new cont. backpatch level. If 'i' is NULL, the level is just incr.
int
@@ -450,9 +487,10 @@ public:
else if (m_flags & HAS_SQLCOM_FLUSH)
my_error(ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0), "FLUSH");
- return test(m_flags &
- (CONTAINS_DYNAMIC_SQL|MULTI_RESULTS|HAS_SET_AUTOCOMMIT_STMT|
- HAS_COMMIT_OR_ROLLBACK|HAS_SQLCOM_RESET|HAS_SQLCOM_FLUSH));
+ return MY_TEST(m_flags &
+ (CONTAINS_DYNAMIC_SQL | MULTI_RESULTS |
+ HAS_SET_AUTOCOMMIT_STMT | HAS_COMMIT_OR_ROLLBACK |
+ HAS_SQLCOM_RESET | HAS_SQLCOM_FLUSH));
}
#ifndef DBUG_OFF
@@ -493,7 +531,7 @@ private:
DYNAMIC_ARRAY m_instr; ///< The "instructions"
typedef struct
{
- struct sp_label *lab;
+ sp_label *lab;
sp_instr *instr;
} bp_t;
List<bp_t> m_backpatch; ///< Instructions needing backpatching
@@ -573,7 +611,7 @@ public:
instruction for CONTINUE error handlers.
@retval 0 on success,
- @retval other if some error occured
+ @retval other if some error occurred
*/
virtual int execute(THD *thd, uint *nextp) = 0;
@@ -593,7 +631,7 @@ public:
Get the continuation destination of this instruction.
@return the continuation destination
*/
- virtual uint get_cont_dest();
+ virtual uint get_cont_dest() const;
/*
Execute core function of instruction after all preparations (e.g.
@@ -865,7 +903,7 @@ public:
virtual void set_destination(uint old_dest, uint new_dest)
= 0;
- virtual uint get_cont_dest();
+ virtual uint get_cont_dest() const;
protected:
@@ -1016,15 +1054,21 @@ class sp_instr_hpush_jump : public sp_instr_jump
public:
- sp_instr_hpush_jump(uint ip, sp_pcontext *ctx, int htype, uint fp)
- : sp_instr_jump(ip, ctx), m_type(htype), m_frame(fp), m_opt_hpop(0)
+ sp_instr_hpush_jump(uint ip,
+ sp_pcontext *ctx,
+ sp_handler *handler)
+ :sp_instr_jump(ip, ctx),
+ m_handler(handler),
+ m_opt_hpop(0),
+ m_frame(ctx->current_var_count())
{
- m_cond.empty();
+ DBUG_ASSERT(m_handler->condition_values.elements == 0);
}
virtual ~sp_instr_hpush_jump()
{
- m_cond.empty();
+ m_handler->condition_values.empty();
+ m_handler= NULL;
}
virtual int execute(THD *thd, uint *nextp);
@@ -1048,17 +1092,24 @@ public:
m_opt_hpop= dest;
}
- inline void add_condition(struct sp_cond_type *cond)
- {
- m_cond.push_front(cond);
- }
+ void add_condition(sp_condition_value *condition_value)
+ { m_handler->condition_values.push_back(condition_value); }
+
+ sp_handler *get_handler()
+ { return m_handler; }
private:
- int m_type; ///< Handler type
+private:
+ /// Handler.
+ sp_handler *m_handler;
+
+ /// hpop marking end of handler scope.
+ uint m_opt_hpop;
+
+ // This attribute is needed for SHOW PROCEDURE CODE only (i.e. it's needed in
+ // debug version only). It's used in print().
uint m_frame;
- uint m_opt_hpop; // hpop marking end of handler scope.
- List<struct sp_cond_type> m_cond;
}; // class sp_instr_hpush_jump : public sp_instr_jump
@@ -1095,8 +1146,9 @@ class sp_instr_hreturn : public sp_instr_jump
public:
- sp_instr_hreturn(uint ip, sp_pcontext *ctx, uint fp)
- : sp_instr_jump(ip, ctx), m_frame(fp)
+ sp_instr_hreturn(uint ip, sp_pcontext *ctx)
+ :sp_instr_jump(ip, ctx),
+ m_frame(ctx->current_var_count())
{}
virtual ~sp_instr_hreturn()
@@ -1251,7 +1303,7 @@ public:
virtual void print(String *str);
- void add_to_varlist(struct sp_variable *var)
+ void add_to_varlist(sp_variable *var)
{
m_varlist.push_back(var);
}
@@ -1259,7 +1311,7 @@ public:
private:
uint m_cursor;
- List<struct sp_variable> m_varlist;
+ List<sp_variable> m_varlist;
}; // class sp_instr_cfetch : public sp_instr