#At file:///home/alik/MySQL/bzr/00/bug55843/mysql-trunk-bug55843-02/ based on revid:alexander.nozdrin@stripped
3191 Alexander Nozdrin 2011-06-10
Draft patch.
Make Warning_info interface more const-oriented.
Provide constant iterator for elements of Warning-info-area.
modified:
sql/event_scheduler.cc
sql/log_event.cc
sql/rpl_slave.cc
sql/sp_head.cc
sql/sql_admin.cc
sql/sql_class.h
sql/sql_error.cc
sql/sql_error.h
sql/sql_list.h
sql/sql_prepare.h
sql/sql_show.cc
sql/sql_table.cc
=== modified file 'sql/event_scheduler.cc'
--- a/sql/event_scheduler.cc 2011-06-10 15:57:57 +0000
+++ b/sql/event_scheduler.cc 2011-06-10 16:51:09 +0000
@@ -75,7 +75,6 @@ struct scheduler_param {
void
Event_worker_thread::print_warnings(THD *thd, Event_job_data *et)
{
- MYSQL_ERROR *err;
DBUG_ENTER("evex_print_warnings");
if (thd->get_stmt_wi()->is_empty())
DBUG_VOID_RETURN;
@@ -93,7 +92,8 @@ Event_worker_thread::print_warnings(THD
prefix.append(et->name.str, et->name.length, system_charset_info);
prefix.append("] ", 2);
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
String err_msg(msg_buf, sizeof(msg_buf), system_charset_info);
=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc 2011-06-10 15:57:57 +0000
+++ b/sql/log_event.cc 2011-06-10 16:51:09 +0000
@@ -208,8 +208,8 @@ static void inline slave_rows_error_repo
char buff[MAX_SLAVE_ERRMSG], *slider;
const char *buff_end= buff + sizeof(buff);
uint len;
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
buff[0]= 0;
for (err= it++, slider= buff; err && slider < buff_end - 1;
=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc 2011-06-10 15:57:57 +0000
+++ b/sql/rpl_slave.cc 2011-06-10 16:51:09 +0000
@@ -3747,8 +3747,8 @@ log '%s' at position %s, relay log '%s'
}
/* Print any warnings issued */
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
/*
Added controlled slave thread cancel for replication
of user-defined variables.
=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc 2011-06-10 15:57:57 +0000
+++ b/sql/sp_head.cc 2011-06-10 16:51:09 +0000
@@ -1148,8 +1148,8 @@ find_handler_after_execution(THD *thd, s
}
else if (thd->get_stmt_wi()->statement_warn_count())
{
- List_iterator<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
if (err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN &&
=== modified file 'sql/sql_admin.cc'
--- a/sql/sql_admin.cc 2011-06-10 15:57:57 +0000
+++ b/sql/sql_admin.cc 2011-06-10 16:51:09 +0000
@@ -639,8 +639,8 @@ send_result:
lex->cleanup_after_one_table_open();
thd->clear_error(); // these errors shouldn't get client
{
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
protocol->prepare_for_resend();
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2011-06-10 15:57:57 +0000
+++ b/sql/sql_class.h 2011-06-10 16:51:09 +0000
@@ -2836,6 +2836,10 @@ public:
Warning_info *get_stmt_wi()
{ return get_stmt_da()->get_warning_info(); }
+ /// Returns Warning-information-area for the current diagnostics area.
+ const Warning_info *get_stmt_wi() const
+ { return get_stmt_da()->get_warning_info(); }
+
/// Returns Diagnostics-area for the current statement.
Diagnostics_area *get_stmt_da()
{ return m_stmt_da; }
=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc 2011-06-10 15:57:57 +0000
+++ b/sql/sql_error.cc 2011-06-10 16:51:09 +0000
@@ -510,7 +510,7 @@ void Warning_info::clear_warning_info(ul
Append warnings only if the original contents of the routine
warning info was replaced.
*/
-void Warning_info::merge_with_routine_info(THD *thd, Warning_info *source)
+void Warning_info::merge_with_routine_info(THD *thd, const Warning_info *source)
{
/*
If a routine body is empty or if a routine did not
@@ -692,7 +692,6 @@ bool mysqld_show_warnings(THD *thd, ulon
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
- MYSQL_ERROR *err;
SELECT_LEX *sel= &thd->lex->select_lex;
SELECT_LEX_UNIT *unit= &thd->lex->unit;
ulonglong idx= 0;
@@ -700,7 +699,8 @@ bool mysqld_show_warnings(THD *thd, ulon
unit->set_limit(sel);
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
/* Skip levels that the user is not interested in */
=== modified file 'sql/sql_error.h'
--- a/sql/sql_error.h 2011-06-10 07:49:17 +0000
+++ b/sql/sql_error.h 2011-06-10 16:51:09 +0000
@@ -244,8 +244,8 @@ class Warning_info
private:
Warning_info(const Warning_info &rhs); /* Not implemented */
Warning_info& operator=(const Warning_info &rhs); /* Not implemented */
-public:
+public:
Warning_info(ulonglong warn_id_arg, bool allow_unlimited_warnings);
~Warning_info();
@@ -255,6 +255,7 @@ public:
to point to the first row.
*/
void clear_warning_info(ulonglong warn_id_arg);
+
/**
Only clear warning info if haven't yet done that already
for the current query. Allows to be issued at any time
@@ -271,19 +272,17 @@ public:
clear_warning_info(query_id);
}
- void append_warning_info(THD *thd, Warning_info *source)
- {
- append_warnings(thd, & source->warn_list());
- }
+ void append_warning_info(THD *thd, const Warning_info *source)
+ { append_warnings(thd, & source->warn_list()); }
/**
Concatenate the list of warnings.
It's considered tolerable to lose a warning.
*/
- void append_warnings(THD *thd, List<MYSQL_ERROR> *src)
+ void append_warnings(THD *thd, const List<MYSQL_ERROR> *src)
{
- MYSQL_ERROR *err;
- List_iterator_fast<MYSQL_ERROR> it(*src);
+ const MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(*src);
/*
Don't use ::push_warning() to avoid invocation of condition
handlers or escalation of warnings to errors.
@@ -295,14 +294,15 @@ public:
/**
Conditional merge of related warning information areas.
*/
- void merge_with_routine_info(THD *thd, Warning_info *source);
+ void merge_with_routine_info(THD *thd, const Warning_info *source);
/**
Reset between two COM_ commands. Warnings are preserved
between commands, but statement_warn_count indicates
the number of warnings of this particular statement only.
*/
- void reset_for_next_command() { m_statement_warn_count= 0; }
+ void reset_for_next_command()
+ { m_statement_warn_count= 0; }
/**
Used for @@warning_count system variable, which prints
@@ -320,34 +320,40 @@ public:
}
/**
- This is for iteration purposes. We return a non-constant reference
- since List doesn't have constant iterators.
+ Iterator over warning objects.
*/
- List<MYSQL_ERROR> &warn_list() { return m_warn_list; }
+ const List<MYSQL_ERROR> &warn_list() const
+ { return m_warn_list; }
/**
The number of errors, or number of rows returned by SHOW ERRORS,
also the value of session variable @@error_count.
*/
ulong error_count() const
- {
- return m_warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
- }
+ { return m_warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR]; }
/** Id of the warning information area. */
- ulonglong warn_id() const { return m_warn_id; }
+ ulonglong warn_id() const
+ { return m_warn_id; }
/** Do we have any errors and warnings that we can *show*? */
- bool is_empty() const { return m_warn_list.elements == 0; }
+ bool is_empty() const
+ { return m_warn_list.elements == 0; }
/** Increment the current row counter to point at the next row. */
- void inc_current_row_for_warning() { m_current_row_for_warning++; }
+ void inc_current_row_for_warning()
+ { m_current_row_for_warning++; }
+
/** Reset the current row counter. Start counting from the first row. */
- void reset_current_row_for_warning() { m_current_row_for_warning= 1; }
+ void reset_current_row_for_warning()
+ { m_current_row_for_warning= 1; }
+
/** Return the current counter value. */
- ulong current_row_for_warning() const { return m_current_row_for_warning; }
+ ulong current_row_for_warning() const
+ { return m_current_row_for_warning; }
- ulong statement_warn_count() const { return m_statement_warn_count; }
+ ulong statement_warn_count() const
+ { return m_statement_warn_count; }
/** Add a new condition to the current list. */
MYSQL_ERROR *push_warning(THD *thd,
=== modified file 'sql/sql_list.h'
--- a/sql/sql_list.h 2011-05-26 15:20:09 +0000
+++ b/sql/sql_list.h 2011-06-10 16:51:09 +0000
@@ -295,7 +295,9 @@ public:
inline void **head_ref() { return first != &end_of_list ? &first->info : 0; }
inline bool is_empty() { return first == &end_of_list ; }
inline list_node *last_ref() { return &end_of_list; }
+ inline const list_node *last_ref() const { return &end_of_list; }
friend class base_list_iterator;
+ friend class base_list_const_iterator;
friend class error_list;
friend class error_list_iterator;
@@ -448,6 +450,53 @@ public:
friend class error_list_iterator;
};
+class base_list_const_iterator
+{
+protected:
+ const base_list *list;
+ list_node * const * el;
+ const list_node *current;
+
+public:
+ base_list_const_iterator()
+ :list(), el(0), current(0)
+ { }
+
+ base_list_const_iterator(const base_list &list_par)
+ { init(list_par); }
+
+ void init(const base_list &list_par)
+ {
+ list= &list_par;
+ el= &list_par.first;
+ current= 0;
+ }
+
+ const void *next(void)
+ {
+ current= *el;
+ el= ¤t->next;
+ return current->info;
+ }
+
+ const void *next_fast(void)
+ {
+ list_node *tmp;
+ tmp= *el;
+ el= &tmp->next;
+ return tmp->info;
+ }
+
+ void rewind(void)
+ { el= &list->first; }
+
+ void * const * ref(void) // Get reference pointer
+ { return ¤t->info; }
+
+ bool is_last(void) const
+ { return el == &list->last_ref()->next; }
+};
+
template <class T> class List :public base_list
{
public:
@@ -516,6 +565,24 @@ public:
};
+template <class T>
+class List_const_iterator_fast :public base_list_const_iterator
+{
+public:
+ List_const_iterator_fast(const List<T> &a) : base_list_const_iterator(a) {}
+ List_const_iterator_fast() : base_list_const_iterator() {}
+
+ void init(const List<T> &a)
+ { base_list_const_iterator::init(a); }
+
+ const T* operator++ (int)
+ { return (const T*) base_list_const_iterator::next_fast(); }
+
+ void rewind(void)
+ { base_list_const_iterator::rewind(); }
+};
+
+
/*
A simple intrusive list which automaticly removes element from list
on delete (for THD element)
=== modified file 'sql/sql_prepare.h'
--- a/sql/sql_prepare.h 2011-06-10 07:49:17 +0000
+++ b/sql/sql_prepare.h 2011-06-10 16:51:09 +0000
@@ -261,7 +261,7 @@ public:
The second is a numeric code.
The third is warning text.
*/
- List<MYSQL_ERROR> *get_warn_list()
+ const List<MYSQL_ERROR> *get_warn_list() const
{ return &m_diagnostics_area.get_warning_info()->warn_list(); }
/**
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2011-06-10 08:33:15 +0000
+++ b/sql/sql_show.cc 2011-06-10 16:51:09 +0000
@@ -6831,8 +6831,8 @@ static bool do_fill_table(THD *thd,
// correspond to the errors which were filtered out in fill_table().
- List_iterator_fast<MYSQL_ERROR> it(wi_tmp.warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(wi_tmp.warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2011-06-10 15:57:57 +0000
+++ b/sql/sql_table.cc 2011-06-10 16:51:09 +0000
@@ -2940,10 +2940,11 @@ const CHARSET_INFO* get_sql_field_charse
}
+// TODO: move this function to the Warning_info class.
bool check_duplicate_warning(THD *thd, char *msg, ulong length)
{
- List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
- MYSQL_ERROR *err;
+ List_const_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+ const MYSQL_ERROR *err;
while ((err= it++))
{
if (strncmp(msg, err->get_message_text(), length) == 0)
Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110610165109-itpq7qc5npy0qvcl.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (alexander.nozdrin:3191) | Alexander Nozdrin | 11 Jun |