diff options
author | unknown <monty@mashka.mysql.fi> | 2002-10-02 13:33:08 +0300 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2002-10-02 13:33:08 +0300 |
commit | 5a28c2caca888be932140d12f87c496398ad4220 (patch) | |
tree | 5a27bda6d3f628af7dcb922ad022e84cf8cb351c /sql/sql_error.cc | |
parent | 9421f1dae99e0f2d6100b31a3641b2cd0ad68e58 (diff) | |
download | mariadb-git-5a28c2caca888be932140d12f87c496398ad4220.tar.gz |
Fixes and code cleanups after merge with 4.0.3
Warning handling and initial prepared statement handling (last not complete yet)
Changed a lot of functions that returned 0/1 to my_bool type.
GRANT handling now uses read/write locks instead of mutex
Change basic net functions to use THD instead of NET
(needed for 4.1 protocol)
Use my_sprintf instead of sprintf() + strlen()
Added alloc_query() to be able to chare query initialization code with
prepared statements.
Cleanup handling of SHOW COUNT(*) WARNINGS and SELECT LAST_INSERT_ID()
Note that the following test fails (will be fixed ASAP):
sub_select, union, rpl_rotate_logs and rpl_mystery22
BitKeeper/deleted/.del-README~3449730baf983117:
Delete: mysql-test/t/README
BitKeeper/deleted/.del-sql_error.cc~2f1caca8d2485dbe:
Delete: libmysqld/sql_error.cc
BitKeeper/deleted/.del-sql_prepare.cc~f703729793935ed6:
Delete: libmysqld/sql_prepare.cc
Docs/manual.texi:
Updated variable list
client/mysql.cc:
Show warning count to user.
client/mysqltest.c:
Add warnings to test results
configure.in:
New shared library version number
include/errmsg.h:
Indentation cleanup
include/mysql.h:
Removed MYSQL_ERROR
Indentaion cleanups
include/mysql_com.h:
Changed functions to returns true/false to my_bool.
include/mysqld_error.h:
New error messages
isam/pack_isam.c:
Indentation change
libmysql/Makefile.am:
Fix of wrong merge
libmysql/Makefile.shared:
Indentation cleanup
libmysql/errmsg.c:
Removed not used errors
libmysql/libmysql.c:
Change functions to return 1 on error (not -1)
Change type of functions that returns 0/1 to my_bool
Lot of code optimizations.
Lot of changes for prepared statements. This now handles sending of binary data to server.
Receving of binary data is not yet done (will have to wait until server code for this is ready)
mysql_warning_count and mysql_warnings() implemented.
libmysql/libmysql.def:
Added mysql_warnings and mysql_warning_count
libmysql/manager.c:
Fixed wrong testing of result from my_connect()
libmysqld/lib_sql.cc:
Removed global variable THR_NET
Change basic net functions to use THD instead of NET
GRANT handling now uses read/write locks instead of mutex
libmysqld/libmysqld.c:
Changed functions to be my_bool
myisam/ft_boolean_search.c:
Trivial code cleanup
myisam/ft_stopwords.c:
Trivial code cleanup
myisam/mi_check.c:
Update to 4.1 structures
myisam/myisampack.c:
Trivial code cleanup
myisam/rt_key.c:
Code cleanup
myisam/rt_test.c:
Code cleanup
Removed compiler warnings
myisam/sp_key.c:
Indentation changes
myisam/sp_test.c:
Removed compiler warnings
mysql-test/README:
Updated to reflect the new --external flag.
mysql-test/mysql-test-run.sh:
--local (start new server) is now default.
Use --external to test against external server.
mysql-test/r/rollback.result:
Updated for 4.1 warnings
mysql-test/r/rpl_log.result:
Update for 4.1
mysql-test/t/rollback.test:
Updated for 4.1 warnings
mysql-test/t/rpl_log_pos.test:
Portability fix
mysys/hash.c:
Indentation change
mysys/my_error.c:
Indentation change
mysys/tree.c:
Updated file description
sql/field.cc:
Fixed bugs introduced by merge
Use my_sprintf instead of sprintf() + strlen()
sql/field.h:
Add CHARSET_INFO to field structure
sql/gstream.h:
Indentation changes.
Added GPL copyright header
sql/ha_innodb.cc:
Updated parameters for net functions.
sql/item.cc:
Updates of Item_param
Indentation changes
sql/item.h:
Removed size_of() function from item.
sql/item_func.cc:
Update function usage for 4.1
Added get_system_var()
sql/item_func.h:
Indentation change
sql/item_strfunc.cc:
Removed not needed inclusion of gstream.h
Update to use system variables (from 4.0)
sql/item_sum.h:
Removed size_of() functions from item.
sql/item_timefunc.cc:
Change sprintf() + strlen() -> my_sprintf()
Added length parameter to ->append()
sql/item_timefunc.h:
Removed size_of() functions from item.
sql/item_uniq.h:
Removed size_of() functions from item.
sql/lex.h:
Removed SQL_ERROR_COUNT variable
sql/log.cc:
Change sprintf() + strlen() -> my_sprintf()
sql/log_event.cc:
Change sprintf() + strlen() -> my_sprintf()
sql/mini_client.cc:
Added check that one always specifies a length to mc_mysql_query()
sql/mysql_priv.h:
New prototypes
Change of NET -> THD parameter for net functions.
sql/mysqld.cc:
New startup options: 'max_prepared_statements', 'max_error_count'
Updated usage of net functions.
sql/net_pkg.cc:
Change basic net functions to use THD instead of NET
(needed to be able to handle 4.0 and 4.1 protocols)
Lots of function comments
sql/net_serv.cc:
Change int return values -> my_bool
Updated net_write_command() to take an extra header block to be added to the packet.
(This made the prepared statement code much nicer and more efficient)
sql/repl_failsafe.cc:
Update net functions to use THD instead of NET
sql/set_var.cc:
Added @@error_count and @@warning_count variables.
Updated to 4.1 function usage
sql/set_var.h:
Added @@error_count and @@warning_count variables.
sql/share/czech/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/english/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/greek/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/hungarian/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/japanese/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/korean/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/norwegian-ny/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/norwegian/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/polish/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/romanian/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/slovak/errmsg.txt:
Removed Warning: from warning error messages.
sql/share/swedish/errmsg.txt:
Removed Warning: from warning error messages.
sql/slave.cc:
Change basic net functions to use THD instead of NET
skip_load_data_file recoded to fit new client/server protocol
sql/spatial.h:
Added copyright header
Indentation cleanups
sql/sql_acl.cc:
Change basic net functions to use THD instead of NET
GRANT handling now uses read/write locks instead of mutex
sql/sql_analyse.cc:
Change basic net functions to use THD instead of NET
sprintf() + strlen() -> my_sprintf()
sql/sql_base.cc:
More DBUG statements
sql/sql_class.cc:
Change basic net functions to use THD instead of NET
warning and prepared statement handling
sql/sql_class.h:
Change basic net functions to use THD instead of NET
warning and prepared statement handling
sql/sql_db.cc:
Code cleanup & optimization.
sql/sql_delete.cc:
Change basic net functions to use THD instead of NET
sql/sql_derived.cc:
Change basic net functions to use THD instead of NET
sql/sql_do.cc:
Change basic net functions to use THD instead of NET
sql/sql_error.cc:
Big rewrite of error handling.
sql/sql_handler.cc:
Change basic net functions to use THD instead of NET
sql/sql_insert.cc:
Change basic net functions to use THD instead of NET
sql/sql_lex.cc:
Change basic net functions to use THD instead of NET
sql/sql_lex.h:
Added param_count to st_select_lex_node
sql/sql_list.h:
Removed not needed error list.
sql/sql_load.cc:
Change basic net functions to use THD instead of NET
sql/sql_parse.cc:
Change basic net functions to use THD instead of NET
Added alloc_query() to be able to chare query initialization code with
prepared statements.
Update of warning handling.
Added create_select_for_variable() (for SHOW COUNT(*) WARNINGS)
sql/sql_prepare.cc:
Initial prepared statement handling
sql/sql_rename.cc:
Change basic net functions to use THD instead of NET
sql/sql_repl.cc:
Change basic net functions to use THD instead of NET
sql/sql_select.cc:
Small code cleanups
Added missing initialization of error that caused some queries that returned an empty result set to fail
sql/sql_select.h:
Ensure that JOIN.error is properly initialized
sql/sql_show.cc:
Change basic net functions to use THD instead of NET
A lot of optimization
sql/sql_table.cc:
Change basic net functions to use THD instead of NET
Indentaion cleanup
sql/sql_udf.cc:
Change basic net functions to use THD instead of NET
sql/sql_union.cc:
Change basic net functions to use THD instead of NET
sql/sql_update.cc:
Change basic net functions to use THD instead of NET
sql/sql_yacc.yy:
Change basic net functions to use THD instead of NET
Cleanup handling of SHOW COUNT(*) WARNINGS and SELECT LAST_INSERT_ID()
sql/structs.h:
Moved structures to files where they was used
sql/table.cc:
Don't accept empty database names
sql/uniques.cc:
Indentation cleanup
sql/unireg.cc:
Change basic net functions to use THD instead of NET
sql/unireg.h:
Added defaults for warnings and prepared statements
strings/ctype-simple.c:
optimization
tests/client_test.c:
Fixed wrong paramaters to printf()
Diffstat (limited to 'sql/sql_error.cc')
-rw-r--r-- | sql/sql_error.cc | 250 |
1 files changed, 92 insertions, 158 deletions
diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 13466f454c5..3d6a0fa24aa 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -18,202 +18,136 @@ /********************************************************************** This file contains the implementation of error and warnings related - - Whenever an error or warning occured, it pushes the same to - the respective list along with sending it to client. + - Whenever an error or warning occurred, it pushes it to a warning list + that the user can retrieve with SHOW WARNINGS or SHOW ERRORS. + + - For each statement, we return the number of warnings generated from this + command. Note that this can be different from @@warning_count as + we reset the warning list only for questions that uses a table. + This is done to allow on to do: + INSERT ...; + SELECT @@warning_count; + SHOW WARNINGS; + (If we would reset after each command, we could not retrieve the number + of warnings) - When client requests the information using SHOW command, then server processes from this list and returns back in the form of resultset. - syntax : SHOW [COUNT(*)] ERRORS [LIMIT [offset,] rows] - SHOW [COUNT(*)] WARNINGS [LIMIT [offset,] rows] + Supported syntaxes: + + SHOW [COUNT(*)] ERRORS [LIMIT [offset,] rows] + SHOW [COUNT(*)] WARNINGS [LIMIT [offset,] rows] + SELECT @@warning_count, @@error_count; ***********************************************************************/ -/* Handles errors and warnings .. */ #include "mysql_priv.h" -/* - Push the error to error list -*/ +/* + Reset all warnings for the thread -void push_error(uint code, const char *msg) -{ - THD *thd=current_thd; + SYNOPSIS + mysql_reset_errors() + thd Thread handle +*/ - mysql_st_error *err = new mysql_st_error(code,msg,(const char*)thd->query); - - if (thd->err_list.elements >= thd->max_error_count) - { - /* Remove the old elements and always maintain the max size - equal to sql_error_count. - - If one max_error_count using sets sql_error_count less than - the current list size, then make sure it always grows upto - sql_error_count size only - - ** BUG ** : Doesn't work in removing the old one - from the list, and thus SET SQL_ERROR_COUNT=x doesn't work - */ - for (uint count=thd->err_list.elements-1; - count <= thd->max_error_count-1; count++) - { - thd->err_list.remove_last(); - } - } - thd->err_list.push_front(err); +void mysql_reset_errors(THD *thd) +{ + free_root(&thd->warn_root,MYF(0)); + bzero((char*) thd->warn_count, sizeof(thd->warn_count)); + thd->warn_list.empty(); } + /* - Push the warning to warning list + Push the warning/error to error list if there is still room in the list + + SYNOPSIS + push_warning() + thd Thread handle + level Severity of warning (note, warning, error ...) + code Error number + msg Clear error message */ -void push_warning(uint code, const char *msg) -{ - THD *thd=current_thd; - - mysql_st_error *warn = new mysql_st_error(code,msg,(const char *)thd->query); - - if (thd->warn_list.elements >= thd->max_warning_count) +void push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code, + const char *msg) +{ + if (thd->warn_list.elements < thd->variables.max_error_count) { - /* Remove the old elements and always maintian the max size - equal to sql_error_count + /* + The following code is here to change the allocation to not + use the thd->mem_root, which is freed after each query */ - for (uint count=thd->warn_list.elements; - count <= thd->max_warning_count-1; count++) - { - thd->warn_list.remove_last(); - } - } - thd->warn_list.push_front(warn); -} - -/* - List all errors -*/ - -int mysqld_show_errors(THD *thd) -{ - List<Item> field_list; - DBUG_ENTER("mysqld_show_errors"); - - field_list.push_back(new Item_int("CODE",0,4)); - field_list.push_back(new Item_empty_string("MESSAGE",MYSQL_ERRMSG_SIZE)); - field_list.push_back(new Item_empty_string("QUERY",NAME_LEN)); - - if (send_fields(thd,field_list,1)) - DBUG_RETURN(1); - - mysql_st_error *err; - SELECT_LEX *sel=&thd->lex.select_lex; - ha_rows offset = sel->offset_limit,limit = sel->select_limit; - uint num_rows = 0; - - Error_iterator<mysql_st_error> it(thd->err_list); - - while(offset-- && (err = it++));/* Should be fixed with overloaded - operator '+' or with new funtion - goto() in list ? - */ - - while((num_rows++ < limit) && (err = it++)) - { - thd->packet.length(0); - net_store_data(&thd->packet,(uint32)err->code); - net_store_data(&thd->packet,err->msg); - net_store_data(&thd->packet,err->query); - - if (my_net_write(&thd->net,(char*)thd->packet.ptr(),thd->packet.length())) - DBUG_RETURN(-1); + MEM_ROOT *old_root=my_pthread_getspecific_ptr(MEM_ROOT*,THR_MALLOC); + my_pthread_setspecific_ptr(THR_MALLOC, &thd->warn_root); + MYSQL_ERROR *err= new MYSQL_ERROR(code, level, msg); + if (err) + thd->warn_list.push_back(err); + my_pthread_setspecific_ptr(THR_MALLOC, old_root); } - send_eof(&thd->net); - DBUG_RETURN(0); + thd->warn_count[(uint) level]++; + thd->total_warn_count++; } -/* - Return errors count -*/ -int mysqld_show_errors_count(THD *thd) -{ - List<Item> field_list; - DBUG_ENTER("mysqld_show_errors_count"); +/* + Send all notes, errors or warnings to the client in a result set - field_list.push_back(new Item_int("COUNT(*)",0,4)); + SYNOPSIS + mysqld_show_warnings() + thd Thread handler + levels_to_show Bitmap for which levels to show - if (send_fields(thd,field_list,1)) - DBUG_RETURN(1); + DESCRIPTION + Takes into account the current LIMIT - thd->packet.length(0); - net_store_data(&thd->packet,(uint32)thd->err_list.elements); + RETURN VALUES + 0 ok + 1 Error sending data to client +*/ - if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length())) - DBUG_RETURN(-1); +static const char *warning_level_names[]= {"Note", "Warning", "Error", "?"}; - send_eof(&thd->net); - DBUG_RETURN(0); -} -/* - List all warnings -*/ - -int mysqld_show_warnings(THD *thd) -{ +my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) +{ List<Item> field_list; - DBUG_ENTER("mysqld_show_warnings"); + DBUG_ENTER("mysqld_show_errors"); - field_list.push_back(new Item_int("CODE",0,21)); - field_list.push_back(new Item_empty_string("MESSAGE",MYSQL_ERRMSG_SIZE)); - field_list.push_back(new Item_empty_string("QUERY",NAME_LEN)); + field_list.push_back(new Item_empty_string("Level", 7)); + field_list.push_back(new Item_int("Code",0,4)); + field_list.push_back(new Item_empty_string("Message",MYSQL_ERRMSG_SIZE)); if (send_fields(thd,field_list,1)) DBUG_RETURN(1); - mysql_st_error *warn; - + MYSQL_ERROR *err; + SELECT_LEX *sel= &thd->lex.select_lex; + ha_rows offset= sel->offset_limit, limit= sel->select_limit; - SELECT_LEX *sel=&thd->lex.select_lex; - ha_rows offset = sel->offset_limit,limit = sel->select_limit; - uint num_rows = 0; - - Error_iterator<mysql_st_error> it(thd->warn_list); - while(offset-- && (warn = it++)); - while((num_rows++ < limit) && (warn = it++)) + List_iterator_fast<MYSQL_ERROR> it(thd->warn_list); + while ((err= it++)) { + /* Skip levels that the user is not interested in */ + if (!(levels_to_show & ((ulong) 1 << err->level))) + continue; + if (offset) + { + offset--; + continue; + } thd->packet.length(0); - net_store_data(&thd->packet,(uint32)warn->code); - net_store_data(&thd->packet,warn->msg); - net_store_data(&thd->packet,warn->query); - - if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length())) - DBUG_RETURN(-1); + net_store_data(&thd->packet,warning_level_names[err->level]); + net_store_data(&thd->packet,(uint32) err->code); + net_store_data(&thd->packet,err->msg); + if (my_net_write(&thd->net,(char*)thd->packet.ptr(),thd->packet.length())) + DBUG_RETURN(1); + if (!--limit) + break; } - send_eof(&thd->net); - DBUG_RETURN(0); -} - -/* - Return warnings count -*/ - -int mysqld_show_warnings_count(THD *thd) -{ - List<Item> field_list; - DBUG_ENTER("mysqld_show_warnings_count"); - - field_list.push_back(new Item_int("COUNT(*)",0,21)); - - if (send_fields(thd,field_list,1)) - DBUG_RETURN(1); - - thd->packet.length(0); - net_store_data(&thd->packet,(uint32)thd->warn_list.elements); - - if (my_net_write(&thd->net,(char*)thd->packet.ptr(),thd->packet.length())) - DBUG_RETURN(-1); - - send_eof(&thd->net); + send_eof(thd); DBUG_RETURN(0); } - |