Commit 4d3818d3 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-11037 Diagnostics_area refactoring for user defined exceptions

Part 2:

Moving the part of Sql_condition that contain condition items
(such as m_class_origin, m_cursor_name, etc) into a separate
class Sql_condition_items. This allows to remove duplicate code in
different Sql_condition constructors.

Also, introducing new Sql_condition constructors and removing the method
Sql_condition::set(). All code sequences that called an Sql_condition
constructor followed by Sql_condition::set() are now replaced to
the new constructor calls. This gives light performance improvement,
as the relevant members are now initialized only one time.
parent 6010662c
...@@ -242,10 +242,9 @@ bool sp_rcontext::handle_sql_condition(THD *thd, ...@@ -242,10 +242,9 @@ bool sp_rcontext::handle_sql_condition(THD *thd,
*/ */
if (!found_condition) if (!found_condition)
{ {
Sql_condition *condition= found_condition=
new (callers_arena->mem_root) Sql_condition(callers_arena->mem_root); new (callers_arena->mem_root) Sql_condition(callers_arena->mem_root,
condition->set(da, Sql_condition::WARN_LEVEL_ERROR, da->message()); da, da->message());
found_condition= condition;
} }
} }
else if (da->current_statement_warn_count()) else if (da->current_statement_warn_count())
......
...@@ -172,64 +172,6 @@ This file contains the implementation of error and warnings related ...@@ -172,64 +172,6 @@ This file contains the implementation of error and warnings related
See WL#2111 (Stored Procedures: Implement GET DIAGNOSTICS) See WL#2111 (Stored Procedures: Implement GET DIAGNOSTICS)
*/ */
Sql_condition::Sql_condition()
: Sql_alloc(),
m_class_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_subclass_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_catalog((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_schema((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_catalog_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_schema_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_table_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_column_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_message_text(),
m_mem_root(NULL)
{
}
void Sql_condition::init(MEM_ROOT *mem_root)
{
DBUG_ASSERT(mem_root != NULL);
DBUG_ASSERT(m_mem_root == NULL);
m_mem_root= mem_root;
}
void Sql_condition::clear()
{
m_class_origin.length(0);
m_subclass_origin.length(0);
m_constraint_catalog.length(0);
m_constraint_schema.length(0);
m_constraint_name.length(0);
m_catalog_name.length(0);
m_schema_name.length(0);
m_table_name.length(0);
m_column_name.length(0);
m_cursor_name.length(0);
m_message_text.length(0);
m_sql_errno= 0;
m_level= Sql_condition::WARN_LEVEL_ERROR;
}
Sql_condition::Sql_condition(MEM_ROOT *mem_root)
: Sql_alloc(),
m_class_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_subclass_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_catalog((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_schema((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_catalog_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_schema_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_table_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_column_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_message_text(),
m_mem_root(mem_root)
{
DBUG_ASSERT(mem_root != NULL);
}
static void copy_string(MEM_ROOT *mem_root, String* dst, const String* src) static void copy_string(MEM_ROOT *mem_root, String* dst, const String* src)
{ {
...@@ -715,12 +657,9 @@ Sql_condition *Warning_info::push_warning(THD *thd, ...@@ -715,12 +657,9 @@ Sql_condition *Warning_info::push_warning(THD *thd,
if (m_allow_unlimited_warnings || if (m_allow_unlimited_warnings ||
m_warn_list.elements() < thd->variables.max_error_count) m_warn_list.elements() < thd->variables.max_error_count)
{ {
cond= new (& m_warn_root) Sql_condition(& m_warn_root); cond= new (& m_warn_root) Sql_condition(& m_warn_root, value, msg);
if (cond) if (cond)
{
cond->set(value, msg);
m_warn_list.push_back(cond); m_warn_list.push_back(cond);
}
} }
m_warn_count[(uint) value->get_level()]++; m_warn_count[(uint) value->get_level()]++;
} }
......
...@@ -139,6 +139,10 @@ class Sql_state_errno: public Sql_state ...@@ -139,6 +139,10 @@ class Sql_state_errno: public Sql_state
{ {
*this= *other; *this= *other;
} }
void clear()
{
m_sql_errno= 0;
}
}; };
...@@ -177,6 +181,78 @@ class Sql_state_errno_level: public Sql_state_errno ...@@ -177,6 +181,78 @@ class Sql_state_errno_level: public Sql_state_errno
:Sql_state_errno(sqlerrno, sqlstate), :Sql_state_errno(sqlerrno, sqlstate),
m_level(level) m_level(level)
{ } { }
Sql_state_errno_level(const Sql_state_errno &state_errno,
enum_warning_level level)
:Sql_state_errno(state_errno),
m_level(level)
{ }
void clear()
{
m_level= WARN_LEVEL_ERROR;
Sql_state_errno::clear();
}
};
class Sql_condition_items
{
protected:
/** SQL CLASS_ORIGIN condition item. */
String m_class_origin;
/** SQL SUBCLASS_ORIGIN condition item. */
String m_subclass_origin;
/** SQL CONSTRAINT_CATALOG condition item. */
String m_constraint_catalog;
/** SQL CONSTRAINT_SCHEMA condition item. */
String m_constraint_schema;
/** SQL CONSTRAINT_NAME condition item. */
String m_constraint_name;
/** SQL CATALOG_NAME condition item. */
String m_catalog_name;
/** SQL SCHEMA_NAME condition item. */
String m_schema_name;
/** SQL TABLE_NAME condition item. */
String m_table_name;
/** SQL COLUMN_NAME condition item. */
String m_column_name;
/** SQL CURSOR_NAME condition item. */
String m_cursor_name;
Sql_condition_items()
:m_class_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_subclass_origin((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_catalog((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_schema((const char*) NULL, 0, & my_charset_utf8_bin),
m_constraint_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_catalog_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_schema_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_table_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_column_name((const char*) NULL, 0, & my_charset_utf8_bin),
m_cursor_name((const char*) NULL, 0, & my_charset_utf8_bin)
{ }
void clear()
{
m_class_origin.length(0);
m_subclass_origin.length(0);
m_constraint_catalog.length(0);
m_constraint_schema.length(0);
m_constraint_name.length(0);
m_catalog_name.length(0);
m_schema_name.length(0);
m_table_name.length(0);
m_column_name.length(0);
m_cursor_name.length(0);
}
}; };
...@@ -185,7 +261,9 @@ class Sql_state_errno_level: public Sql_state_errno ...@@ -185,7 +261,9 @@ class Sql_state_errno_level: public Sql_state_errno
A SQL condition can be a completion condition (note, warning), A SQL condition can be a completion condition (note, warning),
or an exception condition (error, not found). or an exception condition (error, not found).
*/ */
class Sql_condition : public Sql_alloc, public Sql_state_errno_level class Sql_condition : public Sql_alloc,
public Sql_state_errno_level,
public Sql_condition_items
{ {
public: public:
...@@ -237,55 +315,74 @@ class Sql_condition : public Sql_alloc, public Sql_state_errno_level ...@@ -237,55 +315,74 @@ class Sql_condition : public Sql_alloc, public Sql_state_errno_level
This constructor is usefull when allocating arrays. This constructor is usefull when allocating arrays.
Note that the init() method should be called to complete the Sql_condition. Note that the init() method should be called to complete the Sql_condition.
*/ */
Sql_condition(); Sql_condition()
:m_mem_root(NULL)
{ }
/** /**
Complete the Sql_condition initialisation. Complete the Sql_condition initialisation.
@param mem_root The memory root to use for the condition items @param mem_root The memory root to use for the condition items
of this condition of this condition
*/ */
void init(MEM_ROOT *mem_root); void init(MEM_ROOT *mem_root)
{
DBUG_ASSERT(mem_root != NULL);
DBUG_ASSERT(m_mem_root == NULL);
m_mem_root= mem_root;
}
/** /**
Constructor. Constructor.
@param mem_root The memory root to use for the condition items @param mem_root The memory root to use for the condition items
of this condition of this condition
*/ */
Sql_condition(MEM_ROOT *mem_root); Sql_condition(MEM_ROOT *mem_root)
:m_mem_root(mem_root)
/** Destructor. */ {
~Sql_condition() DBUG_ASSERT(mem_root != NULL);
{} }
/**
Copy optional condition items attributes.
@param cond the condition to copy.
*/
void copy_opt_attributes(const Sql_condition *cond);
/** /**
Set this condition area with a fixed message text. Constructor for a fixed message text.
@param value - the error number and the sql state for this condition. @param mem_root - memory root
@param level - the error level for this condition. @param value - the error number and the sql state for this condition
@param msg - the message text for this condition. @param level - the error level for this condition
@param msg - the message text for this condition
*/ */
void set(const Sql_state_errno *value, Sql_condition(MEM_ROOT *mem_root,
Sql_condition::enum_warning_level level, const Sql_state_errno_level *value,
const char* msg) const char *msg)
:Sql_state_errno_level(*value),
m_mem_root(mem_root)
{ {
DBUG_ASSERT(mem_root != NULL);
DBUG_ASSERT(value->get_sql_errno() != 0); DBUG_ASSERT(value->get_sql_errno() != 0);
DBUG_ASSERT(value->get_sqlstate() != NULL);
DBUG_ASSERT(msg != NULL); DBUG_ASSERT(msg != NULL);
set_condition_value(value);
set_builtin_message_text(msg); set_builtin_message_text(msg);
m_level= level;
} }
void set(const Sql_state_errno_level *cond, const char* msg) Sql_condition(MEM_ROOT *mem_root,
const Sql_state_errno *value,
const char *msg)
:Sql_state_errno_level(*value, Sql_condition::WARN_LEVEL_ERROR),
m_mem_root(mem_root)
{ {
set(cond, cond->get_level(), msg); DBUG_ASSERT(mem_root != NULL);
DBUG_ASSERT(value->get_sql_errno() != 0);
DBUG_ASSERT(msg != NULL);
set_builtin_message_text(msg);
} }
/** Destructor. */
~Sql_condition()
{}
/**
Copy optional condition items attributes.
@param cond the condition to copy.
*/
void copy_opt_attributes(const Sql_condition *cond);
/** /**
Set the condition message test. Set the condition message test.
@param str Message text, expressed in the character set derived from @param str Message text, expressed in the character set derived from
...@@ -310,39 +407,14 @@ class Sql_condition : public Sql_alloc, public Sql_state_errno_level ...@@ -310,39 +407,14 @@ class Sql_condition : public Sql_alloc, public Sql_state_errno_level
/** /**
Clear this SQL condition. Clear this SQL condition.
*/ */
void clear(); void clear()
{
Sql_state_errno_level::clear();
Sql_condition_items::clear();
m_message_text.length(0);
}
private: private:
/** SQL CLASS_ORIGIN condition item. */
String m_class_origin;
/** SQL SUBCLASS_ORIGIN condition item. */
String m_subclass_origin;
/** SQL CONSTRAINT_CATALOG condition item. */
String m_constraint_catalog;
/** SQL CONSTRAINT_SCHEMA condition item. */
String m_constraint_schema;
/** SQL CONSTRAINT_NAME condition item. */
String m_constraint_name;
/** SQL CATALOG_NAME condition item. */
String m_catalog_name;
/** SQL SCHEMA_NAME condition item. */
String m_schema_name;
/** SQL TABLE_NAME condition item. */
String m_table_name;
/** SQL COLUMN_NAME condition item. */
String m_column_name;
/** SQL CURSOR_NAME condition item. */
String m_cursor_name;
/** Message text, expressed in the character set implied by --language. */ /** Message text, expressed in the character set implied by --language. */
String m_message_text; String m_message_text;
......
...@@ -427,8 +427,7 @@ bool Sql_cmd_resignal::execute(THD *thd) ...@@ -427,8 +427,7 @@ bool Sql_cmd_resignal::execute(THD *thd)
DBUG_RETURN(result); DBUG_RETURN(result);
} }
Sql_condition signaled_err(thd->mem_root); Sql_condition signaled_err(thd->mem_root, signaled, signaled->message);
signaled_err.set(signaled, signaled->message);
if (m_cond) if (m_cond)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment