|
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2008-06-26 21:44:37 +0000
+++ b/sql/sql_class.h 2008-06-30 22:11:40 +0000
@@ -1234,23 +1234,33 @@
class UTF8String64
{
public:
+ /** Constructor. */
UTF8String64();
+
+ /** Destructor. */
~UTF8String64()
{}
- /** Get the string value. */
+ /**
+ Get the string value.
+ @return the wrapped String object.
+ */
const String* get_string() const
{ return & m_value; }
/**
Set the string value.
- The string will be truncated if necessary.
+ The string will be truncated with a warning if necessary.
+ @param thd the current thread.
+ @param String the value to set.
*/
void set_string(THD *thd, String *value);
/**
Set the string value.
- The string will be truncated if necessary.
+ The string will be truncated with a warning if necessary.
+ @param thd the current thread.
+ @param value the value to set.
*/
void set_string(THD *thd, const char* value);
@@ -1262,29 +1272,58 @@
void deep_copy(MEM_ROOT *mem_root, const UTF8String64& str);
private:
+ /** The wrapped String value. */
String m_value;
};
/**
Representation of a SQL condition.
- A SQL condition can be a completion condition (warning),
- or an exception contition (error).
+ A SQL condition can be a completion condition (note, warning),
+ or an exception contition (error, not found).
*/
class SQL_condition : public Sql_alloc
{
public:
+ /** Constructor. */
SQL_condition();
+ /** Destructor. */
~SQL_condition()
{}
- /** Deep copy. */
+ /**
+ Deep copy (static method).
+ Builds a copy of a condition using a given memory root.
+ 'Deep copy' is useful to propagate SQL conditions raised from a short
+ lived runtime environment to a parent execution environment with a longer
+ life cycle.
+ For example, when proc_p1() calls proc_p2(), an exception raised in
+ proc_p2() should be copied when caught in proc_p1(),
+ before destroying the proc_p2() memory root.
+ @param thd the current thread.
+ @param mem_root the memory root to use for memory allocation.
+ @param cond the condition to copy.
+ @return the duplicated condition.
+ */
static SQL_condition* deep_copy(THD *thd, MEM_ROOT *mem_root,
const SQL_condition *cond);
+ /**
+ Deep copy (instance method).
+ @param mem_root the memory root to use for memory allocation.
+ @param cond the condition to copy.
+ */
void deep_copy(MEM_ROOT *mem_root, const SQL_condition *cond);
+ /**
+ Set this condition area.
+ @param thd the current thread.
+ @param code the error number for this condition.
+ @param str the message text for this condition.
+ @param level the error level for this condition.
+ @param MyFlags additional flags.
+ */
void set(THD *thd, uint code, const char *str,
MYSQL_ERROR::enum_warning_level level, myf MyFlags);
@@ -1300,11 +1339,15 @@
const char* get_message_text() const;
- /** The length in bytes of m_message_text. */
+ /**
+ The length in bytes of m_message_text.
+ @return the length in bytes of the message text.
+ */
int get_message_octet_length() const;
/** Set the SQLSTATE of this condition. */
void set_sqlstate(const char* sqlstate);
+
/** Get the SQLSTATE of this condition. */
const char* get_sqlstate() const
{ return m_returned_sqlstate; }
@@ -1366,12 +1409,12 @@
public:
/**
- Handle an error condition.
+ Handle a sql condition.
This method can be implemented by a subclass to achieve any of the
following:
- - mask an error internally, prevent exposing it to the user,
- - mask an error and throw another one instead.
- When this method returns true, the error condition is considered
+ - mask a warning/error internally, prevent exposing it to the user,
+ - mask a warning/error and throw another one instead.
+ When this method returns true, the sql condition is considered
'handled', and will not be propagated to upper layers.
It is the responsability of the code installing an internal handler
to then check for trapped conditions, and implement logic to recover
@@ -2642,7 +2685,8 @@
void push_internal_handler(Internal_error_handler *handler);
/**
- Handle an error condition.
+ Handle a sql condition.
+ @param cond the sql condition to handle.
@return true if the error is handled
*/
virtual bool handle_condition(const SQL_condition *cond);
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2008-06-20 23:00:44 +0000
+++ b/sql/sql_lex.h 2008-06-30 22:11:40 +0000
@@ -1517,23 +1517,52 @@
struct st_lex;
+/**
+ Abstract representation of a statement.
+ This class is an interface between the parser and the runtime.
+ The parser builds the appropriate sub classes of SQLCOM_statement
+ to represent a SQL statement in the parsed tree.
+ The execute() method in the sub classes contain the runtime implementation.
+ Note that this interface is used for SQL statement recently implemented,
+ the code for older statements tend to load the LEX structure with more
+ attributes instead.
+ The recommended way to implement new statements is to sub-class
+ SQLCOM_statement, as this improves code modularity (see the 'big switch' in
+ dispatch_command()), and decrease the total size of the LEX structure
+ (therefore saving memory in stored programs).
+*/
class SQLCOM_statement : public Sql_alloc
{
public:
+ /**
+ Execute this SQL statement.
+ @param thd the current thread.
+ @return 0 on success.
+ */
virtual int execute(THD *thd) = 0;
protected:
+ /**
+ Constructor.
+ @param lex the LEX structure that represents parts of this statement.
+ */
SQLCOM_statement(struct st_lex *lex)
: m_lex(lex)
{}
+ /** Destructor. */
virtual ~SQLCOM_statement()
{}
- int check_all_tables_access(THD *thd, ulong want_access);
- int open_and_lock_all_tables(THD *thd);
-
-private:
+protected:
+ /**
+ The legacy LEX structure for this statement.
+ The LEX structure contains the existing properties of the parsed tree.
+ TODO: with time, attributes from LEX should move to sub classes of
+ SQLCOM_statement, so that the parser only builds SQLCOM_statement objects
+ with the minimum set of attributes, instead of a LEX structure that
+ contains the collection of every possible attribute.
+ */
struct st_lex *m_lex;
};
=== modified file 'sql/sql_signal.cc'
--- a/sql/sql_signal.cc 2008-06-27 19:17:42 +0000
+++ b/sql/sql_signal.cc 2008-06-30 22:11:40 +0000
@@ -352,19 +352,6 @@
}
}
-// TODO: move to sql_class.cc ?
-
-int SQLCOM_statement::check_all_tables_access(THD *thd, ulong want_access)
-{
- return check_table_access(thd, want_access, m_lex->query_tables,
- FALSE, FALSE, UINT_MAX);
-}
-
-int SQLCOM_statement::open_and_lock_all_tables(THD *thd)
-{
- return open_and_lock_tables(thd, m_lex->query_tables);
-}
-
int Abstract_signal::eval_sqlcode_sqlstate(THD *thd, SQL_condition *cond)
{
DBUG_ASSERT(m_cond);
@@ -642,11 +629,7 @@
DBUG_ENTER("Abstract_signal::raise_condition");
- if (check_all_tables_access(thd, SELECT_ACL))
- DBUG_RETURN(result);
-
- if (open_and_lock_all_tables(thd))
- DBUG_RETURN(result);
+ DBUG_ASSERT(m_lex->query_tables == NULL);
if (m_cond != NULL)
{
=== modified file 'sql/sql_signal.h'
--- a/sql/sql_signal.h 2008-06-11 22:53:47 +0000
+++ b/sql/sql_signal.h 2008-06-30 22:11:40 +0000
@@ -16,9 +16,19 @@
#ifndef SQL_SIGNAL_H
#define SQL_SIGNAL_H
+/**
+ Abstract_signal represents the common properties of the SIGNAL and RESIGNAL
+ statements.
+*/
class Abstract_signal : public SQLCOM_statement
{
protected:
+ /**
+ Constructor.
+ @param lex the LEX structure for this statement.
+ @param cond the condition signaled if any, or NULL.
+ @param set collection of signal condition item assignments.
+ */
Abstract_signal(LEX *lex,
const sp_cond_type_t *cond,
const Set_signal_information& set)
@@ -30,19 +40,63 @@
virtual ~Abstract_signal()
{}
+ /**
+ Evaluate the condition sqlcode and sqlstate for this statement.
+ @param thd the current thread.
+ @param cond the condition to update.
+ @return 0 on success.
+ */
int eval_sqlcode_sqlstate(THD *thd, SQL_condition *cond);
+
+ /**
+ Evaluate default values for signal condition items for this statement.
+ @param thd the current thread.
+ @param cond the condition to update.
+ @return 0 on success.
+ */
int eval_defaults(THD *thd, SQL_condition *cond);
+
+ /**
+ Evaluate each signal condition items for this statement.
+ @param thd the current thread.
+ @param cond the condition to update.
+ @return 0 on success.
+ */
int eval_signal_informations(THD *thd, SQL_condition *cond);
+ /**
+ Raise a SQL condition.
+ @param thd the current thread.
+ @param cond the condition to raise.
+ @return 0 on success.
+ */
int raise_condition(THD *thd, SQL_condition *cond);
+ /**
+ The condition to signal or resignal.
+ This member is optional and can be NULL (RESIGNAL).
+ */
const sp_cond_type_t *m_cond;
+
+ /**
+ Collection of 'SET item = value' assignments in the
+ SIGNAL/RESIGNAL statement.
+ */
Set_signal_information m_set_signal_information;
};
+/**
+ SQLCOM_signal represents a SIGNAL statement.
+*/
class SQLCOM_signal : public Abstract_signal
{
public:
+ /**
+ Constructor, used to represent a SIGNAL statement.
+ @param lex the LEX structure for this statement.
+ @param cond the SQL condition to signal (required).
+ @param set the collection of signal informations to signal.
+ */
SQLCOM_signal(LEX *lex,
const sp_cond_type_t *cond,
const Set_signal_information& set)
@@ -52,12 +106,26 @@
virtual ~SQLCOM_signal()
{}
+ /**
+ Execute a SIGNAL statement at runtime.
+ @param thd the current thread.
+ @return 0 on success.
+ */
virtual int execute(THD *thd);
};
+/**
+ SQLCOM_resignal represents a RESIGNAL statement.
+*/
class SQLCOM_resignal : public Abstract_signal
{
public:
+ /**
+ Constructor, used to represent a RESIGNAL statement.
+ @param lex the LEX structure for this statement.
+ @param cond the SQL condition to resignal (optional, may be NULL).
+ @param set the collection of signal informations to resignal.
+ */
SQLCOM_resignal(LEX *lex,
const sp_cond_type_t *cond,
const Set_signal_information& set)
@@ -67,13 +135,31 @@
virtual ~SQLCOM_resignal()
{}
+ /**
+ Execute a RESIGNAL statement at runtime.
+ @param thd the current thread.
+ @return 0 on success.
+ */
virtual int execute(THD *thd);
};
-
+/**
+ SQLCOM_get_diag represents a GET DIAGNOSTICS statement.
+ There are two variants of GET DIAGNOSTICS statements:
+ - get diagnostics from the statement information area,
+ - get diagnostics from the condition information area.
+*/
class SQLCOM_get_diag : public SQLCOM_statement
{
public:
+ /**
+ Constructor, used to represent a get statement information diagnostics
+ statement.
+ @param lex the LEX structure for this statement.
+ @param area_type the diagnostics area to read from (CURRENT or STACKED).
+ @param statement_property_list the list of statement properties requested
+ in the statement.
+ */
SQLCOM_get_diag(LEX *lex,
diagnostic_area_type area_type,
List
*statement_property_list)
@@ -84,6 +170,16 @@
m_statement_property_list(statement_property_list)
{}
+ /**
+ Constructor, used to represent a get condition information diagnostics
+ statement.
+ @param lex the LEX structure for this statement.
+ @param area_type the diagnostics area to read from (CURRENT or STACKED).
+ @param condition_expr the expression that represents which condition
+ to read.
+ @param condition_property_list the list of condition properties requested
+ in the statement.
+ */
SQLCOM_get_diag(LEX *lex,
diagnostic_area_type area_type,
Item *condition_expr,
@@ -98,17 +194,66 @@
virtual ~SQLCOM_get_diag()
{}
+ /**
+ Execute a GET DIAGNOSTICS statement at runtime.
+ @param thd the current thread.
+ @return 0 on success.
+ */
virtual int execute(THD *thd);
private:
+ /**
+ Runtime implementation of the GET DIAGNOSTICS statement.
+ This method assumes that the diagnostics area has been marked read only,
+ so that executing GET DIAGNOSTICS does not change the content of the
+ diagnostics area.
+ @param thd the current thread.
+ @return 0 on success.
+ */
int execute_within_read_only_area(THD *thd);
+
+ /**
+ Execute a get statement diagnostics statement.
+ @param thd the current thread.
+ @param area the diagnostics area to read properties from
+ @return 0 on success.
+ */
int exec_stmt_diag(THD *thd, Diagnostics_stmt_area *area);
+
+ /**
+ Execute a get condition diagnostics statement.
+ @param thd the current thread.
+ @param area the diagnostics area to read properties from
+ @return 0 on success.
+ */
int exec_cond_diag(THD *thd, Diagnostics_stmt_area *area);
private:
+ /**
+ The diagnostics area (CURRENT or STACKED) specified in the statement.
+ */
diagnostic_area_type m_area_type;
+
+ /**
+ The expression representing which condition to read in the get
+ condition diagnostics statement.
+ This member is only used for get condition diagnostics, and is NULL
+ for get statement diagnostics.
+ */
Item *m_cond_expr;
+
+ /**
+ The list of properties to read in a get condition diagnostics statement.
+ This member is only used for get condition diagnostics, and is NULL
+ for get statement diagnostics.
+ */
List *m_condition_property_list;
+
+ /**
+ The list of properties to read in a get statement diagnostics statement.
+ This member is only used for get statement diagnostics, and is NULL
+ for get condition diagnostics.
+ */
List *m_statement_property_list;
};
|