From 41b808d224c6ad4c7ef6f785fa8b40dd1b2c42bf Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Tue, 19 Oct 2004 22:27:19 +0200 Subject: [PATCH 01/94] Optimization: in the replication slave, we can avoid doing one strlen() per event's execution, as we already have db_len in Log_event. Only if rewrite_db() changed the db we need a strlen (so we now do the strlen() in rewrite_db). Plus a test (we had none for --replicate-rewrite-db :( ). --- mysql-test/r/rpl_rewrite_db.result | 22 ++++++++++++++++++++++ mysql-test/t/rpl_rewrite_db-slave.opt | 1 + mysql-test/t/rpl_rewrite_db.test | 19 +++++++++++++++++++ sql/log_event.cc | 23 ++++++++++------------- sql/slave.cc | 7 +++++-- sql/slave.h | 4 ++-- 6 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 mysql-test/r/rpl_rewrite_db.result create mode 100644 mysql-test/t/rpl_rewrite_db-slave.opt create mode 100644 mysql-test/t/rpl_rewrite_db.test diff --git a/mysql-test/r/rpl_rewrite_db.result b/mysql-test/r/rpl_rewrite_db.result new file mode 100644 index 00000000000..2804b98dea1 --- /dev/null +++ b/mysql-test/r/rpl_rewrite_db.result @@ -0,0 +1,22 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +drop database if exists mysqltest1; +create database mysqltest1; +use mysqltest1; +create table t1 (a int); +insert into t1 values(9); +select * from mysqltest1.t1; +a +9 +show databases like 'mysqltest1'; +Database (mysqltest1) +mysqltest1 +select * from test.t1; +a +9 +drop table t1; +drop database mysqltest1; diff --git a/mysql-test/t/rpl_rewrite_db-slave.opt b/mysql-test/t/rpl_rewrite_db-slave.opt new file mode 100644 index 00000000000..b9cd29e9205 --- /dev/null +++ b/mysql-test/t/rpl_rewrite_db-slave.opt @@ -0,0 +1 @@ +"--replicate-rewrite-db=mysqltest1->test" diff --git a/mysql-test/t/rpl_rewrite_db.test b/mysql-test/t/rpl_rewrite_db.test new file mode 100644 index 00000000000..4cc8ae4b676 --- /dev/null +++ b/mysql-test/t/rpl_rewrite_db.test @@ -0,0 +1,19 @@ +source include/master-slave.inc; +--disable_warnings +drop database if exists mysqltest1; +--enable_warnings +create database mysqltest1; + +use mysqltest1; +create table t1 (a int); +insert into t1 values(9); +select * from mysqltest1.t1; +sync_slave_with_master; +show databases like 'mysqltest1'; # should be empty +select * from test.t1; +# cleanup +connection master; +drop table t1; +drop database mysqltest1; +sync_slave_with_master; + diff --git a/sql/log_event.cc b/sql/log_event.cc index 326f2fc5c59..977c3c0fe24 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -977,7 +977,8 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) int Query_log_event::exec_event(struct st_relay_log_info* rli) { int expected_error,actual_error= 0; - thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed + thd->db_length= db_len; + thd->db= (char*) rewrite_db(db, &thd->db_length); /* InnoDB internally stores the master log position it has processed so far; @@ -995,11 +996,6 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) if (db_ok(thd->db, replicate_do_db, replicate_ignore_db)) { thd->set_time((time_t)when); - /* - We cannot use db_len from event to fill thd->db_length, because - rewrite_db() may have changed db. - */ - thd->db_length= thd->db ? strlen(thd->db) : 0; thd->query_length= q_len; thd->query = (char*)query; VOID(pthread_mutex_lock(&LOCK_thread_count)); @@ -1057,7 +1053,7 @@ Default database: '%s'. Query: '%s'", expected_error, actual_error ? thd->net.last_error: "no error", actual_error, - print_slave_db_safe(db), query); + print_slave_db_safe(thd->db), query); thd->query_error= 1; } /* @@ -1078,7 +1074,7 @@ Default database: '%s'. Query: '%s'", "Error '%s' on query. Default database: '%s'. Query: '%s'", (actual_error ? thd->net.last_error : "unexpected success or fatal error"), - print_slave_db_safe(db), query); + print_slave_db_safe(thd->db), query); thd->query_error= 1; } } /* End of if (db_ok(... */ @@ -1706,7 +1702,8 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, bool use_rli_only_for_errors) { char *load_data_query= 0; - thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed + thd->db_length= db_len; + thd->db= (char*) rewrite_db(db, &thd->db_length); DBUG_ASSERT(thd->query == 0); thd->query_length= 0; // Should not be needed thd->query_error= 0; @@ -1741,7 +1738,6 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, if (db_ok(thd->db, replicate_do_db, replicate_ignore_db)) { thd->set_time((time_t)when); - thd->db_length= thd->db ? strlen(thd->db) : 0; VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_id = query_id++; VOID(pthread_mutex_unlock(&LOCK_thread_count)); @@ -1847,7 +1843,7 @@ Slave: load data infile on table '%s' at log position %s in log \ (char*) table_name, llstr(log_pos,llbuff), RPL_LOG_NAME, (ulong) thd->cuted_fields, - print_slave_db_safe(db)); + print_slave_db_safe(thd->db)); } if (net) net->pkt_nr= thd->net.pkt_nr; @@ -1865,6 +1861,7 @@ Slave: load data infile on table '%s' at log position %s in log \ } thd->net.vio = 0; + char *save_db= thd->db; VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->db= 0; thd->query= 0; @@ -1887,7 +1884,7 @@ Slave: load data infile on table '%s' at log position %s in log \ } slave_print_error(rli,sql_errno,"\ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", - err, (char*)table_name, print_slave_db_safe(db)); + err, (char*)table_name, print_slave_db_safe(save_db)); free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC)); return 1; } @@ -1897,7 +1894,7 @@ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", { slave_print_error(rli,ER_UNKNOWN_ERROR, "\ Fatal error running LOAD DATA INFILE on table '%s'. Default database: '%s'", - (char*)table_name, print_slave_db_safe(db)); + (char*)table_name, print_slave_db_safe(save_db)); return 1; } diff --git a/sql/slave.cc b/sql/slave.cc index 4ef8715f1e6..d5278e06d8a 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1032,7 +1032,7 @@ bool net_request_file(NET* net, const char* fname) } -const char *rewrite_db(const char* db) +const char *rewrite_db(const char* db, uint *new_len) { if (replicate_rewrite_db.is_empty() || !db) return db; @@ -1042,7 +1042,10 @@ const char *rewrite_db(const char* db) while ((tmp=it++)) { if (!strcmp(tmp->key, db)) + { + *new_len= strlen(tmp->val); return tmp->val; + } } return db; } @@ -1056,7 +1059,7 @@ const char *rewrite_db(const char* db) const char *print_slave_db_safe(const char* db) { - return (db ? rewrite_db(db) : ""); + return (db ? db : ""); } /* diff --git a/sql/slave.h b/sql/slave.h index 20167094453..97f197fb50a 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -510,8 +510,8 @@ int add_table_rule(HASH* h, const char* table_spec); int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec); void init_table_rule_hash(HASH* h, bool* h_inited); void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited); -const char *rewrite_db(const char* db); -const char *print_slave_db_safe(const char* db); +const char *rewrite_db(const char* db, uint *new_db_len); +const char *print_slave_db_safe(const char *db); int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code); void skip_load_data_infile(NET* net); void slave_print_error(RELAY_LOG_INFO* rli, int err_code, const char* msg, ...); From 4714a6e7448672b93313deddfa67ad83f2084d01 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Wed, 20 Oct 2004 04:04:37 +0300 Subject: [PATCH 02/94] errors without code removed net_printf/send_error calls replaced by my_error family functions -1/1 (sent/unsent) error reporting removed (WL#2133) --- include/mysqld_error.h | 23 +- mysql-test/r/rpl_charset.result | 6 +- mysql-test/r/rpl_timezone.result | 2 +- mysql-test/r/sp-security.result | 4 +- mysql-test/r/sp.result | 12 +- mysql-test/t/connect.test | 2 +- mysql-test/t/rpl_charset.test | 6 +- mysql-test/t/rpl_timezone.test | 2 +- mysql-test/t/sp-security.test | 4 +- mysql-test/t/sp.test | 17 +- sql/ha_innodb.cc | 12 +- sql/ha_innodb.h | 2 +- sql/item.cc | 66 ++-- sql/item_cmpfunc.cc | 32 +- sql/item_func.cc | 44 +-- sql/item_row.cc | 4 +- sql/item_subselect.cc | 35 +- sql/item_subselect.h | 8 +- sql/item_sum.cc | 26 +- sql/item_timefunc.cc | 4 +- sql/item_uniq.h | 2 +- sql/mysql_priv.h | 236 ++++++------- sql/mysqld.cc | 20 +- sql/protocol.cc | 5 +- sql/protocol_cursor.cc | 2 +- sql/repl_failsafe.cc | 49 ++- sql/repl_failsafe.h | 6 +- sql/set_var.cc | 22 +- sql/share/czech/errmsg.txt | 19 + sql/share/danish/errmsg.txt | 19 + sql/share/dutch/errmsg.txt | 19 + sql/share/english/errmsg.txt | 19 + sql/share/estonian/errmsg.txt | 19 + sql/share/french/errmsg.txt | 19 + sql/share/german/errmsg.txt | 19 + sql/share/greek/errmsg.txt | 19 + sql/share/hungarian/errmsg.txt | 19 + sql/share/italian/errmsg.txt | 19 + sql/share/japanese/errmsg.txt | 19 + sql/share/korean/errmsg.txt | 19 + sql/share/norwegian-ny/errmsg.txt | 19 + sql/share/norwegian/errmsg.txt | 19 + sql/share/polish/errmsg.txt | 19 + sql/share/portuguese/errmsg.txt | 19 + sql/share/romanian/errmsg.txt | 19 + sql/share/russian/errmsg.txt | 19 + sql/share/serbian/errmsg.txt | 19 + sql/share/slovak/errmsg.txt | 19 + sql/share/spanish/errmsg.txt | 19 + sql/share/swedish/errmsg.txt | 19 + sql/share/ukrainian/errmsg.txt | 19 + sql/slave.cc | 25 +- sql/slave.h | 4 +- sql/sp.cc | 2 +- sql/sp_head.cc | 21 +- sql/sp_rcontext.cc | 12 +- sql/sql_acl.cc | 90 +++-- sql/sql_acl.h | 16 +- sql/sql_base.cc | 20 +- sql/sql_class.cc | 4 +- sql/sql_class.h | 1 + sql/sql_db.cc | 32 +- sql/sql_delete.cc | 81 ++--- sql/sql_do.cc | 6 +- sql/sql_error.cc | 14 +- sql/sql_handler.cc | 43 ++- sql/sql_help.cc | 68 ++-- sql/sql_insert.cc | 68 ++-- sql/sql_lex.h | 10 +- sql/sql_load.cc | 26 +- sql/sql_map.cc | 8 +- sql/sql_parse.cc | 552 +++++++++++++----------------- sql/sql_prepare.cc | 209 +++++------ sql/sql_repl.cc | 91 +++-- sql/sql_repl.h | 10 +- sql/sql_select.cc | 56 ++- sql/sql_select.h | 2 +- sql/sql_show.cc | 200 +++++------ sql/sql_table.cc | 180 +++++----- sql/sql_trigger.cc | 25 +- sql/sql_udf.cc | 21 +- sql/sql_union.cc | 70 ++-- sql/sql_update.cc | 101 +++--- sql/sql_view.cc | 52 ++- sql/sql_view.h | 6 +- sql/sql_yacc.yy | 236 +++++++------ 86 files changed, 1886 insertions(+), 1566 deletions(-) diff --git a/include/mysqld_error.h b/include/mysqld_error.h index 6faf876f2f1..93438f98255 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 59 Temple Placeo Suite 330, Boston, MA 02111-1307 USA */ /* Definefile for error messagenumbers */ @@ -386,4 +386,23 @@ #define ER_ILLEGAL_VALUE_FOR_TYPE 1367 #define ER_VIEW_NONUPD_CHECK 1368 #define ER_VIEW_CHECK_FAILED 1369 -#define ER_ERROR_MESSAGES 370 +#define ER_RELAY_LOG_FAIL 1370 +#define ER_PASSWD_LENGTH 1371 +#define ER_UNKNOWN_TARGET_BINLOG 1372 +#define ER_IO_ERR_LOG_INDEX_READ 1373 +#define ER_BINLOG_PURGE_PROHIBITED 1374 +#define ER_FSEEK_FAIL 1375 +#define ER_BINLOG_PURGE_FATAL_ERR 1376 +#define ER_LOG_IN_USE 1377 +#define ER_LOG_PURGE_UNKNOWN_ERR 1378 +#define ER_RELAY_LOG_INIT 1379 +#define ER_NO_BINARY_LOGGING 1380 +#define ER_RESERVED_SYNTAX 1381 +#define ER_WSAS_FAILED 1382 +#define ER_DIFF_GROUPS_PROC 1383 +#define ER_NO_GROUP_FOR_PROC 1384 +#define ER_ORDER_WITH_PROC 1385 +#define ER_LOGING_PROHIBIT_CHANGING_OF 1386 +#define ER_NO_FILE_MAPPING 1387 +#define ER_WRONG_MAGIC 1388 +#define ER_ERROR_MESSAGES 389 diff --git a/mysql-test/r/rpl_charset.result b/mysql-test/r/rpl_charset.result index a427e77a18d..2007d35516f 100644 --- a/mysql-test/r/rpl_charset.result +++ b/mysql-test/r/rpl_charset.result @@ -162,9 +162,9 @@ master-bin.000001 # Query 1 # use `mysqltest2`; drop database mysqltest2 master-bin.000001 # Query 1 # SET ONE_SHOT CHARACTER_SET_CLIENT=8,COLLATION_CONNECTION=31,COLLATION_DATABASE=9,COLLATION_SERVER=64 master-bin.000001 # Query 1 # drop database mysqltest3 set global character_set_server=latin2; -ERROR HY000: Binary logging and replication forbid changing the global server character set or collation +ERROR HY000: Binary logging and replication forbid changing the global server character set, collation set global character_set_server=latin2; -ERROR HY000: Binary logging and replication forbid changing the global server character set or collation +ERROR HY000: Binary logging and replication forbid changing the global server character set, collation set one_shot @@character_set_server=latin5; set @@max_join_size=1000; select @@character_set_server; @@ -181,7 +181,7 @@ select @@character_set_server; @@character_set_server latin5 set one_shot max_join_size=10; -ERROR HY000: The SET ONE_SHOT syntax is reserved for purposes internal to the MySQL server +ERROR HY000: The 'SET ONE_SHOT' syntax is reserved for purposes internal to the MySQL server set character_set_client=9999999; ERROR 42000: Unknown character set: '9999999' set collation_server=9999998; diff --git a/mysql-test/r/rpl_timezone.result b/mysql-test/r/rpl_timezone.result index 6dc8f87393c..495fccd35a3 100644 --- a/mysql-test/r/rpl_timezone.result +++ b/mysql-test/r/rpl_timezone.result @@ -73,5 +73,5 @@ t 2001-09-09 03:46:40 1000000000 set global time_zone='MET'; -ERROR HY000: Binary logging and replication forbid changing of the global server time zone +ERROR HY000: Binary logging and replication forbid changing the global server time zone drop table t1, t2; diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result index cdcc4595a73..f5e74733bc5 100644 --- a/mysql-test/r/sp-security.result +++ b/mysql-test/r/sp-security.result @@ -30,7 +30,7 @@ db1_secret select * from db1_secret.t1; ERROR 42000: Access denied for user 'user1'@'localhost' to database 'db1_secret' create procedure db1_secret.dummy() begin end; -ERROR 42000: Unknown database 'db1_secret' +ERROR 42000: Access denied for user 'user1'@'localhost' to database 'db1_secret' drop procedure db1_secret.dummy; ERROR 42000: PROCEDURE db1_secret.dummy does not exist call db1_secret.stamp(3); @@ -40,7 +40,7 @@ db1_secret select * from db1_secret.t1; ERROR 42000: Access denied for user ''@'localhost' to database 'db1_secret' create procedure db1_secret.dummy() begin end; -ERROR 42000: Unknown database 'db1_secret' +ERROR 42000: Access denied for user ''@'localhost' to database 'db1_secret' drop procedure db1_secret.dummy; ERROR 42000: PROCEDURE db1_secret.dummy does not exist select * from t1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 7544fbe5d60..e265ac9de3a 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -1728,10 +1728,20 @@ drop table if exists t3| create procedure bug4904() begin declare continue handler for sqlstate 'HY000' begin end; -create table t2 as select * from t; +create table t2 as select * from t3; +end| +call bug4904()| +ERROR 42S02: Table 'test.t3' doesn't exist +drop procedure bug4904| +create table t3 (s1 char character set latin1, s2 char character set latin2)| +create procedure bug4904 () +begin +declare continue handler for sqlstate 'HY000' begin end; +select s1 from t3 union select s2 from t3; end| call bug4904()| drop procedure bug4904| +drop table t3| create procedure bug336(out y int) begin declare x int; diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 4598ca5ea15..3ec2648fa7e 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -49,7 +49,7 @@ flush privileges; #show tables; connect (con1,localhost,test,gambling2,mysql); set password=""; ---error 1105 +--error 1371 set password='gambling3'; set password=old_password('gambling3'); show tables; diff --git a/mysql-test/t/rpl_charset.test b/mysql-test/t/rpl_charset.test index 74112ac44fe..e49ab7468a3 100644 --- a/mysql-test/t/rpl_charset.test +++ b/mysql-test/t/rpl_charset.test @@ -112,10 +112,10 @@ sync_slave_with_master; # Check that we can't change global.collation_server -error 1105; +error 1386; set global character_set_server=latin2; connection master; -error 1105; +error 1386; set global character_set_server=latin2; # Check that SET ONE_SHOT is really one shot @@ -129,7 +129,7 @@ select @@character_set_server; select @@character_set_server; # ONE_SHOT on not charset/collation stuff is not allowed -error 1105; +error 1381; set one_shot max_join_size=10; # Test of wrong character set numbers; diff --git a/mysql-test/t/rpl_timezone.test b/mysql-test/t/rpl_timezone.test index 8dff90a84cf..03e910cd7ca 100644 --- a/mysql-test/t/rpl_timezone.test +++ b/mysql-test/t/rpl_timezone.test @@ -76,7 +76,7 @@ select * from t2; # replication # connection master; ---error 1105 +--error 1386 set global time_zone='MET'; # Clean up diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test index 4804d44e63a..2089d311fd3 100644 --- a/mysql-test/t/sp-security.test +++ b/mysql-test/t/sp-security.test @@ -58,7 +58,7 @@ select db1_secret.db(); select * from db1_secret.t1; # ...and not this ---error 1049 +--error 1044 create procedure db1_secret.dummy() begin end; --error 1305 drop procedure db1_secret.dummy; @@ -78,7 +78,7 @@ select db1_secret.db(); select * from db1_secret.t1; # ...and not this ---error 1049 +--error 1044 create procedure db1_secret.dummy() begin end; --error 1305 drop procedure db1_secret.dummy; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index a3101ff9488..d76e8daa58a 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1865,12 +1865,27 @@ create procedure bug4904() begin declare continue handler for sqlstate 'HY000' begin end; - create table t2 as select * from t; + create table t2 as select * from t3; +end| + +-- error 1146 +call bug4904()| + +drop procedure bug4904| + +create table t3 (s1 char character set latin1, s2 char character set latin2)| + +create procedure bug4904 () +begin + declare continue handler for sqlstate 'HY000' begin end; + + select s1 from t3 union select s2 from t3; end| call bug4904()| drop procedure bug4904| +drop table t3| # # BUG#336 diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 4d068cfc0ce..7c911ca60bd 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -4821,7 +4821,7 @@ ha_innobase::external_lock( Implements the SHOW INNODB STATUS command. Sends the output of the InnoDB Monitor to the client. */ -int +bool innodb_show_status( /*===============*/ THD* thd) /* in: the MySQL query thread of the caller */ @@ -4835,7 +4835,7 @@ innodb_show_status( my_message(ER_NOT_SUPPORTED_YET, "Cannot call SHOW INNODB STATUS because skip-innodb is defined", MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } trx = check_trx_exists(thd); @@ -4864,7 +4864,7 @@ innodb_show_status( if (!(str = my_malloc(flen + 1, MYF(0)))) { mutex_exit_noninline(&srv_monitor_file_mutex); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } rewind(srv_monitor_file); @@ -4881,7 +4881,7 @@ innodb_show_status( my_free(str, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } protocol->prepare_for_resend(); @@ -4889,10 +4889,10 @@ innodb_show_status( my_free(str, MYF(0)); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } /**************************************************************************** diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index fa3e9f012e8..a2017d59cc3 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -222,7 +222,7 @@ int innobase_savepoint( my_off_t binlog_cache_pos); int innobase_close_connection(THD *thd); int innobase_drop_database(char *path); -int innodb_show_status(THD* thd); +bool innodb_show_status(THD* thd); my_bool innobase_query_caching_of_table_permitted(THD* thd, char* full_name, uint full_name_len); diff --git a/sql/item.cc b/sql/item.cc index 267560b0709..813eaf41b45 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1279,7 +1279,7 @@ bool Item::fix_fields(THD *thd, // We do not check fields which are fixed during construction DBUG_ASSERT(fixed == 0 || basic_const_item()); fixed= 1; - return 0; + return FALSE; } double Item_ref_null_helper::val() @@ -1447,9 +1447,9 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } } if (!tmp) - return -1; + return TRUE; if (!refer) - return 1; + return TRUE; if (tmp == not_found_field && refer == (Item **)not_found_item) { if (upward_lookup) @@ -1463,7 +1463,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) // Call to report error find_field_in_tables(thd, this, tables, ref, 1, 1); } - return -1; + return TRUE; } else if (refer != (Item **)not_found_item) { @@ -1471,7 +1471,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); - return -1; + return TRUE; } Item_ref *rf; @@ -1481,16 +1481,16 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) (char *)field_name); register_item_tree_changing(ref); if (!rf) - return 1; + return TRUE; /* rf is Item_ref => never substitute other items (in this case) during fix_fields() => we can use rf after fix_fields() */ if (rf->fix_fields(thd, tables, ref) || rf->check_cols(1)) - return 1; + return TRUE; mark_as_dependent(thd, last, cursel, rf); - return 0; + return FALSE; } else { @@ -1503,7 +1503,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) (char *)cached_table->alias, (char *)field_name); if (!rf) - return 1; + return TRUE; /* rf is Item_ref => never substitute other items (in this case) during fix_fields() => we can use rf after fix_fields() @@ -1513,7 +1513,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } } else if (!tmp) - return -1; + return TRUE; /* if it is not expression from merged VIEW we will set this field. @@ -1564,12 +1564,12 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) thd->host_or_ip, field_name, tab); - return 1; + return TRUE; } } #endif fixed= 1; - return 0; + return FALSE; } void Item_field::cleanup() @@ -2209,9 +2209,9 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) } if (!ref) - return 1; + return TRUE; else if (!tmp) - return -1; + return TRUE; else if (ref == (Item **)not_found_item && tmp == not_found_field) { if (upward_lookup) @@ -2229,7 +2229,7 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) REPORT_ALL_ERRORS); } ref= 0; - return 1; + return TRUE; } else if (tmp != not_found_field) { @@ -2238,10 +2238,10 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) { Item_field* fld; if (!((*reference)= fld= new Item_field(tmp))) - return 1; + return TRUE; mark_as_dependent(thd, last, thd->lex->current_select, fld); register_item_tree_changing(reference); - return 0; + return FALSE; } /* We can leave expression substituted from view for next PS/SP @@ -2261,7 +2261,7 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); - return -1; + return TRUE; } mark_as_dependent(thd, last, thd->lex->current_select, this); @@ -2269,14 +2269,14 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) } } else if (!ref) - return 1; + return TRUE; else { if (!(*ref)->fixed) { my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, "forward reference in item list"); - return -1; + return TRUE; } ref= thd->lex->current_select->ref_pointer_array + counter; } @@ -2299,7 +2299,7 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) ((*ref)->with_sum_func? "reference on group function": "forward reference in item list")); - return 1; + return TRUE; } max_length= (*ref)->max_length; maybe_null= (*ref)->maybe_null; @@ -2309,8 +2309,8 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) fixed= 1; if (ref && (*ref)->check_cols(1)) - return 1; - return 0; + return TRUE; + return FALSE; } @@ -2416,17 +2416,17 @@ bool Item_default_value::fix_fields(THD *thd, if (!arg) { fixed= 1; - return 0; + return FALSE; } if (arg->fix_fields(thd, table_list, &arg)) - return 1; + return TRUE; if (arg->type() == REF_ITEM) { Item_ref *ref= (Item_ref *)arg; if (ref->ref[0]->type() != FIELD_ITEM) { - return 1; + return TRUE; } arg= ref->ref[0]; } @@ -2435,16 +2435,16 @@ bool Item_default_value::fix_fields(THD *thd, { my_printf_error(ER_NO_DEFAULT_FOR_FIELD, ER(ER_NO_DEFAULT_FOR_FIELD), MYF(0), field_arg->field->field_name); - return 1; + return TRUE; } if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of()))) - return 1; + return TRUE; memcpy(def_field, field_arg->field, field_arg->field->size_of()); def_field->move_field(def_field->table->default_values - def_field->table->record[0]); set_field(def_field); fixed= 1; - return 0; + return FALSE; } void Item_default_value::print(String *str) @@ -2472,14 +2472,14 @@ bool Item_insert_value::fix_fields(THD *thd, { DBUG_ASSERT(fixed == 0); if (arg->fix_fields(thd, table_list, &arg)) - return 1; + return TRUE; if (arg->type() == REF_ITEM) { Item_ref *ref= (Item_ref *)arg; if (ref->ref[0]->type() != FIELD_ITEM) { - return 1; + return TRUE; } arg= ref->ref[0]; } @@ -2488,7 +2488,7 @@ bool Item_insert_value::fix_fields(THD *thd, { Field *def_field= (Field*) sql_alloc(field_arg->field->size_of()); if (!def_field) - return 1; + return TRUE; memcpy(def_field, field_arg->field, field_arg->field->size_of()); def_field->move_field(def_field->table->insert_values - def_field->table->record[0]); @@ -2502,7 +2502,7 @@ bool Item_insert_value::fix_fields(THD *thd, tmp_field->table, &my_charset_bin)); } fixed= 1; - return 0; + return FALSE; } void Item_insert_value::print(String *str) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 582277cd142..252c6d29f5e 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -631,17 +631,17 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, { DBUG_ASSERT(fixed == 0); if (fix_left(thd, tables, ref)) - return 1; + return TRUE; if (args[0]->maybe_null) maybe_null=1; if (!args[1]->fixed && args[1]->fix_fields(thd, tables, args+1)) - return 1; + return TRUE; Item_in_subselect * sub= (Item_in_subselect *)args[1]; if (args[0]->cols() != sub->engine->cols()) { my_error(ER_OPERAND_COLUMNS, MYF(0), args[0]->cols()); - return 1; + return TRUE; } if (args[1]->maybe_null) maybe_null=1; @@ -650,7 +650,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, not_null_tables_cache|= args[1]->not_null_tables(); const_item_cache&= args[1]->const_item(); fixed= 1; - return 0; + return FALSE; } @@ -1964,7 +1964,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) and_tables_cache= ~(table_map) 0; if (check_stack_overrun(thd, buff)) - return 1; // Fatal error flag is set! + return TRUE; // Fatal error flag is set! while ((item=li++)) { table_map tmp_table_map; @@ -1982,7 +1982,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if ((!item->fixed && item->fix_fields(thd, tables, li.ref())) || (item= *li.ref())->check_cols(1)) - return 1; /* purecov: inspected */ + return TRUE; /* purecov: inspected */ used_tables_cache|= item->used_tables(); tmp_table_map= item->not_null_tables(); not_null_tables_cache|= tmp_table_map; @@ -1995,7 +1995,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) thd->lex->current_select->cond_count+= list.elements; fix_length_and_dec(); fixed= 1; - return 0; + return FALSE; } bool Item_cond::walk(Item_processor processor, byte *arg) @@ -2306,12 +2306,12 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref) DBUG_ASSERT(fixed == 0); if (Item_bool_func2::fix_fields(thd, tlist, ref) || escape_item->fix_fields(thd, tlist, &escape_item)) - return 1; + return TRUE; if (!escape_item->const_during_execution()) { my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE"); - return 1; + return TRUE; } if (escape_item->const_item()) @@ -2329,7 +2329,7 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref) { String* res2 = args[1]->val_str(&tmp_value2); if (!res2) - return 0; // Null argument + return FALSE; // Null argument const size_t len = res2->length(); const char* first = res2->ptr(); @@ -2362,7 +2362,7 @@ bool Item_func_like::fix_fields(THD *thd, TABLE_LIST *tlist, Item ** ref) } } } - return 0; + return FALSE; } #ifdef USE_REGEX @@ -2373,13 +2373,13 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) DBUG_ASSERT(fixed == 0); if (args[0]->fix_fields(thd, tables, args) || args[0]->check_cols(1) || args[1]->fix_fields(thd,tables, args + 1) || args[1]->check_cols(1)) - return 1; /* purecov: inspected */ + return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; max_length= 1; decimals= 0; if (agg_arg_collations(cmp_collation, args, 2)) - return 1; + return TRUE; used_tables_cache=args[0]->used_tables() | args[1]->used_tables(); not_null_tables_cache= (args[0]->not_null_tables() | @@ -2393,7 +2393,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (args[1]->null_value) { // Will always return NULL maybe_null=1; - return 0; + return FALSE; } int error; if ((error=regcomp(&preg,res->c_ptr(), @@ -2404,7 +2404,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { (void) regerror(error,&preg,buff,sizeof(buff)); my_printf_error(ER_REGEXP_ERROR,ER(ER_REGEXP_ERROR),MYF(0),buff); - return 1; + return TRUE; } regex_compiled=regex_is_const=1; maybe_null=args[0]->maybe_null; @@ -2412,7 +2412,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) else maybe_null=1; fixed= 1; - return 0; + return FALSE; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 4aec7fea2d4..38f0d514314 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -199,8 +199,8 @@ Item_func::Item_func(THD *thd, Item_func *item) item. RETURN VALUES - 0 ok - 1 Got error. Stored with my_error(). + FALSE ok + TRUE Got error. Stored with my_error(). */ bool @@ -216,7 +216,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) const_item_cache=1; if (check_stack_overrun(thd, buff)) - return 1; // Fatal error if flag is set! + return TRUE; // Fatal error if flag is set! if (arg_count) { // Print purify happy for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) @@ -228,7 +228,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) */ if ((!(*arg)->fixed && (*arg)->fix_fields(thd, tables, arg)) || (*arg)->check_cols(allowed_arg_cols)) - return 1; /* purecov: inspected */ + return TRUE; /* purecov: inspected */ item= *arg; if (item->maybe_null) maybe_null=1; @@ -240,10 +240,10 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) } } fix_length_and_dec(); - if (thd->net.last_errno) // An error inside fix_length_and_dec occured - return 1; + if (thd->net.report_error) // An error inside fix_length_and_dec occured + return TRUE; fixed= 1; - return 0; + return FALSE; } bool Item_func::walk (Item_processor processor, byte *argument) @@ -1568,7 +1568,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, DBUG_ENTER("Item_udf_func::fix_fields"); if (check_stack_overrun(thd, buff)) - DBUG_RETURN(1); // Fatal error flag is set! + DBUG_RETURN(TRUE); // Fatal error flag is set! udf_func *tmp_udf=find_udf(u_d->name.str,(uint) u_d->name.length,1); @@ -1576,7 +1576,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, { my_printf_error(ER_CANT_FIND_UDF,ER(ER_CANT_FIND_UDF),MYF(0),u_d->name.str, errno); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } u_d=tmp_udf; args=arguments; @@ -1593,7 +1593,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, { free_udf(u_d); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } uint i; Item **arg,**arg_end; @@ -1606,7 +1606,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, // we can't assign 'item' before, because fix_fields() can change arg Item *item= *arg; if (item->check_cols(1)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); /* TODO: We should think about this. It is not always right way just to set an UDF result to return my_charset_bin @@ -1639,7 +1639,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, sizeof(long)))) { free_udf(u_d); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } func->fix_length_and_dec(); @@ -1698,7 +1698,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0), u_d->name.str, thd->net.last_error); free_udf(u_d); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } func->max_length=min(initid.max_length,MAX_BLOB_WIDTH); func->maybe_null=initid.maybe_null; @@ -1710,9 +1710,9 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, { my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0), u_d->name.str, ER(ER_UNKNOWN_ERROR)); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -2322,7 +2322,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables, /* fix_fields will call Item_func_set_user_var::fix_length_and_dec */ if (Item_func::fix_fields(thd, tables, ref) || !(entry= get_variable(&thd->user_vars, name, 1))) - return 1; + return TRUE; /* Remember the last query which updated it, this way a query can later know if this variable is a constant item in the query (it is if update_query_id @@ -2331,7 +2331,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd, TABLE_LIST *tables, entry->update_query_id= thd->query_id; entry->collation.set(args[0]->collation); cached_result_type= args[0]->result_type(); - return 0; + return FALSE; } @@ -2490,7 +2490,7 @@ String *user_var_entry::val_str(my_bool *null_value, String *str, will be catched by thd->net.report_error check in sql_set_variables(). RETURN - 0 - OK. + FALSE OK. */ bool @@ -2520,7 +2520,7 @@ Item_func_set_user_var::check() DBUG_ASSERT(0); break; } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -2968,7 +2968,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) !args[0]->const_during_execution()) { my_error(ER_WRONG_ARGUMENTS,MYF(0),"AGAINST"); - return 1; + return TRUE; } const_item_cache=0; @@ -2991,7 +2991,7 @@ bool Item_func_match::fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref) if (key == NO_SUCH_KEY && !(flags & FT_BOOL)) { my_error(ER_WRONG_ARGUMENTS,MYF(0),"MATCH"); - return 1; + return TRUE; } table=((Item_field *)item)->field->table; table->fulltext_searched=1; @@ -3202,7 +3202,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, { if (!var->is_struct()) { - net_printf(thd, ER_VARIABLE_IS_NOT_STRUCT, base_name->str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str); return 0; } } diff --git a/sql/item_row.cc b/sql/item_row.cc index f6623e80734..0cfe8287dcb 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -62,7 +62,7 @@ bool Item_row::fix_fields(THD *thd, TABLE_LIST *tabl, Item **ref) for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++) { if ((*arg)->fix_fields(thd, tabl, arg)) - return 1; + return TRUE; // we can't assign 'item' before, because fix_fields() can change arg Item *item= *arg; used_tables_cache |= item->used_tables(); @@ -81,7 +81,7 @@ bool Item_row::fix_fields(THD *thd, TABLE_LIST *tabl, Item **ref) with_sum_func= with_sum_func || item->with_sum_func; } fixed= 1; - return 0; + return FALSE; } void Item_row::split_sum_func(Item **ref_pointer_array, List &fields) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 25bb2701101..8fe6e5c81dd 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -66,7 +66,7 @@ void Item_subselect::init(st_select_lex *select_lex, parsing_place= unit->item->parsing_place; unit->item->engine= 0; unit->item= this; - engine->change_item(this, result); + engine->change_result(this, result); } else { @@ -133,13 +133,13 @@ Item_subselect::select_transformer(JOIN *join) bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) { char const *save_where= thd_param->where; - int res; + bool res; DBUG_ASSERT(fixed == 0); engine->set_thd((thd= thd_param)); if (check_stack_overrun(thd, (gptr)&res)) - return 1; + return TRUE; res= engine->prepare(); @@ -168,7 +168,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) if (substype() == SINGLEROW_SUBS && (*ref)->with_sum_func) { my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0)); - return 1; + return TRUE; } return ret; } @@ -176,7 +176,7 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) if (engine->cols() > max_columns) { my_error(ER_OPERAND_COLUMNS, MYF(0), 1); - return 1; + return TRUE; } fix_length_and_dec(); } @@ -1493,12 +1493,12 @@ void subselect_indexsubquery_engine::print(String *str) res new select_result object RETURN - 0 OK - -1 error + FALSE OK + TRUE error */ -int subselect_single_select_engine::change_item(Item_subselect *si, - select_subselect *res) +bool subselect_single_select_engine::change_result(Item_subselect *si, + select_subselect *res) { item= si; result= res; @@ -1515,12 +1515,12 @@ int subselect_single_select_engine::change_item(Item_subselect *si, res new select_result object RETURN - 0 OK - -1 error + FALSE OK + TRUE error */ -int subselect_union_engine::change_item(Item_subselect *si, - select_subselect *res) +bool subselect_union_engine::change_result(Item_subselect *si, + select_subselect *res) { item= si; int rc= unit->change_result(res, result); @@ -1538,12 +1538,13 @@ int subselect_union_engine::change_item(Item_subselect *si, res new select_result object RETURN - -1 error + FALSE OK + TRUE error */ -int subselect_uniquesubquery_engine::change_item(Item_subselect *si, - select_subselect *res) +bool subselect_uniquesubquery_engine::change_result(Item_subselect *si, + select_subselect *res) { DBUG_ASSERT(0); - return -1; + return TRUE; } diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 4a325c4b224..e45cd6911e9 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -290,7 +290,7 @@ public: virtual table_map upper_select_const_tables()= 0; static table_map calc_const_tables(TABLE_LIST *); virtual void print(String *str)= 0; - virtual int change_item(Item_subselect *si, select_subselect *result)= 0; + virtual bool change_result(Item_subselect *si, select_subselect *result)= 0; }; @@ -314,7 +314,7 @@ public: void exclude(); table_map upper_select_const_tables(); void print (String *str); - int change_item(Item_subselect *si, select_subselect *result); + bool change_result(Item_subselect *si, select_subselect *result); }; @@ -334,7 +334,7 @@ public: void exclude(); table_map upper_select_const_tables(); void print (String *str); - int change_item(Item_subselect *si, select_subselect *result); + bool change_result(Item_subselect *si, select_subselect *result); }; @@ -363,7 +363,7 @@ public: void exclude(); table_map upper_select_const_tables() { return 0; } void print (String *str); - int change_item(Item_subselect *si, select_subselect *result); + bool change_result(Item_subselect *si, select_subselect *result); }; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index d400c198828..bf3601931ca 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -215,12 +215,12 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) DBUG_ASSERT(fixed == 0); if (save_args_for_prepared_statement(thd)) - return 1; + return TRUE; if (!thd->allow_sum_func) { my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); - return 1; + return TRUE; } thd->allow_sum_func=0; // No included group funcs decimals=0; @@ -228,7 +228,7 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) for (uint i=0 ; i < arg_count ; i++) { if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1)) - return 1; + return TRUE; if (decimals < args[i]->decimals) decimals=args[i]->decimals; maybe_null |= args[i]->maybe_null; @@ -239,7 +239,7 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) fix_length_and_dec(); thd->allow_sum_func=1; // Allow group functions fixed= 1; - return 0; + return FALSE; } @@ -249,13 +249,13 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) DBUG_ASSERT(fixed == 0); if (save_args_for_prepared_statement(thd)) - return 1; + return TRUE; Item *item= args[0]; if (!thd->allow_sum_func) { my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); - return 1; + return TRUE; } thd->allow_sum_func=0; // No included group funcs @@ -263,7 +263,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!item->fixed && item->fix_fields(thd, tables, args) || (item= args[0])->check_cols(1)) - return 1; + return TRUE; hybrid_type= item->result_type(); if (hybrid_type == INT_RESULT) @@ -294,7 +294,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) else hybrid_field_type= Item::field_type(); fixed= 1; - return 0; + return FALSE; } @@ -2060,12 +2060,12 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) DBUG_ASSERT(fixed == 0); if (save_args_for_prepared_statement(thd)) - return 1; + return TRUE; if (!thd->allow_sum_func) { my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); - return 1; + return TRUE; } thd->allow_sum_func= 0; @@ -2079,7 +2079,7 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) for (i=0 ; i < arg_count ; i++) { if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1)) - return 1; + return TRUE; if (i < arg_count_field) maybe_null|= args[i]->maybe_null; } @@ -2089,10 +2089,10 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) max_length= group_concat_max_len; thd->allow_sum_func= 1; if (!(tmp_table_param= new TMP_TABLE_PARAM)) - return 1; + return TRUE; tables_list= tables; fixed= 1; - return 0; + return FALSE; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 988529c845c..76aa06bf7cc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1671,7 +1671,7 @@ Item_func_convert_tz::fix_fields(THD *thd_arg, TABLE_LIST *tables_arg, Item **re { String str; if (Item_date_func::fix_fields(thd_arg, tables_arg, ref)) - return 1; + return TRUE; tz_tables= thd_arg->lex->time_zone_tables_used; @@ -1681,7 +1681,7 @@ Item_func_convert_tz::fix_fields(THD *thd_arg, TABLE_LIST *tables_arg, Item **re if (args[2]->const_item()) to_tz= my_tz_find(args[2]->val_str(&str), tz_tables); - return 0; + return FALSE; } diff --git a/sql/item_uniq.h b/sql/item_uniq.h index 5582537bdbb..c69bd02ae5b 100644 --- a/sql/item_uniq.h +++ b/sql/item_uniq.h @@ -50,7 +50,7 @@ public: { DBUG_ASSERT(fixed == 0); fixed= 1; - return 0; + return FALSE; } Item *copy_or_same(THD* thd) { diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b4fba907fbf..99fc54fd73b 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -418,17 +418,17 @@ bool check_one_table_access(THD *thd, ulong privilege, bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list); -int multi_update_precheck(THD *thd, TABLE_LIST *tables); -int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count); -int mysql_multi_update_prepare(THD *thd); -int mysql_multi_delete_prepare(THD *thd); -int mysql_insert_select_prepare(THD *thd); -int insert_select_precheck(THD *thd, TABLE_LIST *tables); -int update_precheck(THD *thd, TABLE_LIST *tables); -int delete_precheck(THD *thd, TABLE_LIST *tables); -int insert_precheck(THD *thd, TABLE_LIST *tables, bool update); -int create_table_precheck(THD *thd, TABLE_LIST *tables, - TABLE_LIST *create_table); +bool multi_update_precheck(THD *thd, TABLE_LIST *tables); +bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count); +bool mysql_multi_update_prepare(THD *thd); +bool mysql_multi_delete_prepare(THD *thd); +bool mysql_insert_select_prepare(THD *thd); +bool insert_select_precheck(THD *thd, TABLE_LIST *tables); +bool update_precheck(THD *thd, TABLE_LIST *tables); +bool delete_precheck(THD *thd, TABLE_LIST *tables); +bool insert_precheck(THD *thd, TABLE_LIST *tables, bool update); +bool create_table_precheck(THD *thd, TABLE_LIST *tables, + TABLE_LIST *create_table); Item *negate_expression(THD *thd, Item *expr); #include "sql_class.h" #include "opt_range.h" @@ -475,12 +475,12 @@ struct Query_cache_query_flags #define prepare_execute(A) ((A)->command == COM_EXECUTE) -int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); -int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); -int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); +bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); +bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); +bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); -int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, - my_bool drop_temporary); +bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, + my_bool drop_temporary); int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary, bool drop_view, bool log_query); int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables, @@ -507,7 +507,7 @@ extern "C" pthread_handler_decl(handle_one_connection,arg); extern "C" pthread_handler_decl(handle_bootstrap,arg); void end_thread(THD *thd,bool put_in_cache); void flush_thread_cache(); -int mysql_execute_command(THD *thd); +bool mysql_execute_command(THD *thd); bool do_command(THD *thd); bool dispatch_command(enum enum_server_command command, THD *thd, char* packet, uint packet_length); @@ -526,22 +526,22 @@ bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables, bool no_errors); bool check_global_access(THD *thd, ulong want_access); -int mysql_backup_table(THD* thd, TABLE_LIST* table_list); -int mysql_restore_table(THD* thd, TABLE_LIST* table_list); +bool mysql_backup_table(THD* thd, TABLE_LIST* table_list); +bool mysql_restore_table(THD* thd, TABLE_LIST* table_list); -int mysql_checksum_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -int mysql_check_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -int mysql_repair_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -int mysql_analyze_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -int mysql_optimize_table(THD* thd, TABLE_LIST* table_list, - HA_CHECK_OPT* check_opt); -int mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, - LEX_STRING *key_cache_name); -int mysql_preload_keys(THD* thd, TABLE_LIST* table_list); +bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_check_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_repair_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list, + HA_CHECK_OPT* check_opt); +bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list, + LEX_STRING *key_cache_name); +bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list); int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache, KEY_CACHE *dst_cache); @@ -554,20 +554,20 @@ int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, List &fields, List &all_fields, ORDER *order, bool *hidden_group_fields); -int handle_select(THD *thd, LEX *lex, select_result *result); -int mysql_select(THD *thd, Item ***rref_pointer_array, - TABLE_LIST *tables, uint wild_num, List &list, - COND *conds, uint og_num, ORDER *order, ORDER *group, - Item *having, ORDER *proc_param, ulong select_type, - select_result *result, SELECT_LEX_UNIT *unit, - SELECT_LEX *select_lex); +bool handle_select(THD *thd, LEX *lex, select_result *result); +bool mysql_select(THD *thd, Item ***rref_pointer_array, + TABLE_LIST *tables, uint wild_num, List &list, + COND *conds, uint og_num, ORDER *order, ORDER *group, + Item *having, ORDER *proc_param, ulong select_type, + select_result *result, SELECT_LEX_UNIT *unit, + SELECT_LEX *select_lex); void free_underlaid_joins(THD *thd, SELECT_LEX *select); -int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, - select_result *result); +bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, + select_result *result); int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type, select_result *result); -int mysql_union(THD *thd, LEX *lex, select_result *result, - SELECT_LEX_UNIT *unit); +bool mysql_union(THD *thd, LEX *lex, select_result *result, + SELECT_LEX_UNIT *unit); int mysql_handle_derived(LEX *lex); Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, Item ***copy_func, Field **from_field, @@ -577,61 +577,61 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, List &keys, uint &db_options, handler *file, KEY *&key_info_buffer, uint &key_count, int select_field_count); -int mysql_create_table(THD *thd,const char *db, const char *table_name, - HA_CREATE_INFO *create_info, - List &fields, List &keys, - bool tmp_table, uint select_field_count); +bool mysql_create_table(THD *thd,const char *db, const char *table_name, + HA_CREATE_INFO *create_info, + List &fields, List &keys, + bool tmp_table, uint select_field_count); TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, TABLE_LIST *create_table, List *extra_fields, List *keys, List *items, - MYSQL_LOCK **lock); -int mysql_alter_table(THD *thd, char *new_db, char *new_name, - HA_CREATE_INFO *create_info, - TABLE_LIST *table_list, - List &fields, - List &keys, - uint order_num, ORDER *order, - enum enum_duplicates handle_duplicates, - ALTER_INFO *alter_info, bool do_send_ok=1); -int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok); -int mysql_create_like_table(THD *thd, TABLE_LIST *table, - HA_CREATE_INFO *create_info, - Table_ident *src_table); + MYSQL_LOCK **lock); +bool mysql_alter_table(THD *thd, char *new_db, char *new_name, + HA_CREATE_INFO *create_info, + TABLE_LIST *table_list, + List &fields, + List &keys, + uint order_num, ORDER *order, + enum enum_duplicates handle_duplicates, + ALTER_INFO *alter_info, bool do_send_ok=1); +bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool do_send_ok); +bool mysql_create_like_table(THD *thd, TABLE_LIST *table, + HA_CREATE_INFO *create_info, + Table_ident *src_table); bool mysql_rename_table(enum db_type base, const char *old_db, const char * old_name, const char *new_db, const char * new_name); -int mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys); -int mysql_drop_index(THD *thd, TABLE_LIST *table_list, - ALTER_INFO *alter_info); +bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys); +bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, + ALTER_INFO *alter_info); int mysql_prepare_update(THD *thd, TABLE_LIST *table_list, Item **conds, uint order_num, ORDER *order); -int mysql_update(THD *thd,TABLE_LIST *tables,List &fields, - List &values,COND *conds, - uint order_num, ORDER *order, ha_rows limit, - enum enum_duplicates handle_duplicates); -int mysql_multi_update(THD *thd, TABLE_LIST *table_list, - List *fields, List *values, - COND *conds, ulong options, - enum enum_duplicates handle_duplicates, - SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex); -int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, - List &fields, List_item *values, - List &update_fields, - List &update_values, enum_duplicates duplic); -int mysql_insert(THD *thd,TABLE_LIST *table,List &fields, - List &values, List &update_fields, - List &update_values, enum_duplicates flag); +bool mysql_update(THD *thd,TABLE_LIST *tables,List &fields, + List &values,COND *conds, + uint order_num, ORDER *order, ha_rows limit, + enum enum_duplicates handle_duplicates); +bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, + List *fields, List *values, + COND *conds, ulong options, + enum enum_duplicates handle_duplicates, + SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex); +bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, + List &fields, List_item *values, + List &update_fields, + List &update_values, enum_duplicates duplic); +bool mysql_insert(THD *thd,TABLE_LIST *table,List &fields, + List &values, List &update_fields, + List &update_values, enum_duplicates flag); int check_that_all_fields_are_given_values(THD *thd, TABLE *entry); -int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); -int mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order, - ha_rows rows, ulong options); -int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok); -int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create); +bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds); +bool mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, SQL_LIST *order, + ha_rows rows, ulong options); +bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok); +bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create); TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update); TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem, bool *refresh); @@ -683,45 +683,45 @@ void free_des_key_file(); #endif /* HAVE_OPENSSL */ /* sql_do.cc */ -int mysql_do(THD *thd, List &values); +bool mysql_do(THD *thd, List &values); /* sql_show.cc */ -int mysqld_show_dbs(THD *thd,const char *wild); -int mysqld_show_open_tables(THD *thd,const char *wild); -int mysqld_show_tables(THD *thd, const char *db, const char *wild, - bool verbose); -int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild); -int mysqld_show_fields(THD *thd,TABLE_LIST *table, const char *wild, - bool verbose); -int mysqld_show_keys(THD *thd, TABLE_LIST *table); -int mysqld_show_logs(THD *thd); +bool mysqld_show_dbs(THD *thd,const char *wild); +bool mysqld_show_open_tables(THD *thd,const char *wild); +bool mysqld_show_tables(THD *thd, const char *db, const char *wild, + bool verbose); +bool mysqld_extend_show_tables(THD *thd,const char *db,const char *wild); +bool mysqld_show_fields(THD *thd,TABLE_LIST *table, const char *wild, + bool verbose); +bool mysqld_show_keys(THD *thd, TABLE_LIST *table); +bool mysqld_show_logs(THD *thd); void append_identifier(THD *thd, String *packet, const char *name, uint length); void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); int mysqld_dump_create_info(THD *thd, TABLE *table, int fd = -1); -int mysqld_show_create(THD *thd, TABLE_LIST *table_list); -int mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create); +bool mysqld_show_create(THD *thd, TABLE_LIST *table_list); +bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create); void mysqld_list_processes(THD *thd,const char *user,bool verbose); int mysqld_show_status(THD *thd); int mysqld_show_variables(THD *thd,const char *wild); -int mysqld_show(THD *thd, const char *wild, show_var_st *variables, +bool mysqld_show(THD *thd, const char *wild, show_var_st *variables, enum enum_var_type value_type, pthread_mutex_t *mutex, struct system_status_var *status_var); int mysql_find_files(THD *thd,List *files, const char *db, const char *path, const char *wild, bool dir); -int mysqld_show_charsets(THD *thd,const char *wild); -int mysqld_show_collations(THD *thd,const char *wild); -int mysqld_show_storage_engines(THD *thd); -int mysqld_show_privileges(THD *thd); -int mysqld_show_column_types(THD *thd); -int mysqld_help (THD *thd, const char *text); +bool mysqld_show_charsets(THD *thd,const char *wild); +bool mysqld_show_collations(THD *thd,const char *wild); +bool mysqld_show_storage_engines(THD *thd); +bool mysqld_show_privileges(THD *thd); +bool mysqld_show_column_types(THD *thd); +bool mysqld_help (THD *thd, const char *text); void calc_sum_of_all_status(STATUS_VAR *to); /* sql_prepare.cc */ -int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, - LEX_STRING *name=NULL); +bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, + LEX_STRING *name=NULL); void mysql_stmt_execute(THD *thd, char *packet, uint packet_length); void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name); void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length); @@ -736,15 +736,15 @@ MYSQL_ERROR *push_warning(THD *thd, MYSQL_ERROR::enum_warning_level level, uint void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, uint code, const char *format, ...); void mysql_reset_errors(THD *thd); -my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show); +bool mysqld_show_warnings(THD *thd, ulong levels_to_show); /* sql_handler.cc */ -int mysql_ha_open(THD *thd, TABLE_LIST *tables); -int mysql_ha_close(THD *thd, TABLE_LIST *tables, - bool dont_send_ok=0, bool dont_lock=0, bool no_alias=0); +bool mysql_ha_open(THD *thd, TABLE_LIST *tables); +bool mysql_ha_close(THD *thd, TABLE_LIST *tables, + bool dont_send_ok=0, bool dont_lock=0, bool no_alias=0); int mysql_ha_close_list(THD *thd, TABLE_LIST *tables, bool flushed=0); -int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, - List *,enum ha_rkey_function,Item *,ha_rows,ha_rows); +bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, + List *,enum ha_rkey_function,Item *,ha_rows,ha_rows); /* sql_base.cc */ void set_item_name(Item *item,char *pos,uint length); @@ -778,16 +778,16 @@ bool insert_fields(THD *thd,TABLE_LIST *tables, bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds); int setup_wild(THD *thd, TABLE_LIST *tables, List &fields, List *sum_func_list, uint wild_num); -int setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, - List &item, bool set_query_id, - List *sum_func_list, bool allow_sum_func); +bool setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, + List &item, bool set_query_id, + List *sum_func_list, bool allow_sum_func); int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds); int setup_ftfuncs(SELECT_LEX* select); int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order); void wait_for_refresh(THD *thd); int open_tables(THD *thd, TABLE_LIST *tables, uint *counter); int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables); -int open_and_lock_tables(THD *thd,TABLE_LIST *tables); +bool open_and_lock_tables(THD *thd,TABLE_LIST *tables); int lock_tables(THD *thd, TABLE_LIST *tables, uint counter); TABLE *open_temporary_table(THD *thd, const char *path, const char *db, const char *table_name, bool link_in_list); @@ -837,9 +837,9 @@ inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, bool eval_const_cond(COND *cond); /* sql_load.cc */ -int mysql_load(THD *thd,sql_exchange *ex, TABLE_LIST *table_list, - List &fields, enum enum_duplicates handle_duplicates, - bool local_file,thr_lock_type lock_type); +bool mysql_load(THD *thd,sql_exchange *ex, TABLE_LIST *table_list, + List &fields, enum enum_duplicates handle_duplicates, + bool local_file,thr_lock_type lock_type); int write_record(THD *thd, TABLE *table, COPY_INFO *info); /* sql_manager.cc */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index db81b14c9c9..c408478cb15 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1145,7 +1145,7 @@ static void server_init(void) WSADATA WsaData; if (SOCKET_ERROR == WSAStartup (0x0101, &WsaData)) { - my_message(0,"WSAStartup Failed\n",MYF(0)); + my_error(ER_WSAS_FAILED, MYF(0)); unireg_abort(1); } } @@ -1298,8 +1298,9 @@ void yyerror(const char *s) /* "parse error" changed into "syntax error" between bison 1.75 and 1.875 */ if (strcmp(s,"parse error") == 0 || strcmp(s,"syntax error") == 0) s=ER(ER_SYNTAX_ERROR); - net_printf(thd,ER_PARSE_ERROR, s, yytext ? (char*) yytext : "", - thd->lex->yylineno); + my_printf_error(ER_PARSE_ERROR, ER(ER_PARSE_ERROR), MYF(0), s, + (yytext ? (char*) yytext : ""), + thd->lex->yylineno); } @@ -2091,6 +2092,11 @@ extern "C" int my_message_sql(uint error, const char *str, THD *thd; DBUG_ENTER("my_message_sql"); DBUG_PRINT("error", ("error: %u message: '%s'", error, str)); + /* + Put here following assertion when situation with EE_* error codes + will be fixed + DBUG_ASSERT(error != 0); + */ if ((thd= current_thd)) { if (thd->spcont && @@ -2098,6 +2104,9 @@ extern "C" int my_message_sql(uint error, const char *str, { DBUG_RETURN(0); } + + thd->query_error= 1; // needed to catch query errors during replication + /* thd->lex->current_select == 0 if lex structure is not inited (not query command (COM_QUERY)) @@ -2112,6 +2121,9 @@ extern "C" int my_message_sql(uint error, const char *str, { NET *net= &thd->net; net->report_error= 1; +#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/ + query_cache_abort(net); +#endif if (!net->last_error[0]) // Return only first message { strmake(net->last_error, str, sizeof(net->last_error)-1); @@ -3381,7 +3393,7 @@ static void create_new_thread(THD *thd) ("Can't create thread to handle request (error %d)", error)); thread_count--; - thd->killed= THD::KILL_CONNECTION; // Safety + thd->killed= THD::KILL_CONNECTION; // Safety (void) pthread_mutex_unlock(&LOCK_thread_count); statistic_increment(aborted_connects,&LOCK_status); net_printf(thd,ER_CANT_CREATE_THREAD,error); diff --git a/sql/protocol.cc b/sql/protocol.cc index 187989158df..c92d25f3f4d 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -70,9 +70,6 @@ void send_error(THD *thd, uint sql_errno, const char *err) { DBUG_VOID_RETURN; } -#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/ - query_cache_abort(net); -#endif thd->query_error= 1; // needed to catch query errors during replication if (!err) { @@ -614,7 +611,7 @@ bool Protocol::send_fields(List *list, int flags) DBUG_RETURN(prepare_for_send(list)); err: - send_error(thd,ER_OUT_OF_RESOURCES); /* purecov: inspected */ + my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } diff --git a/sql/protocol_cursor.cc b/sql/protocol_cursor.cc index 8904aba7b88..0954bb5466f 100644 --- a/sql/protocol_cursor.cc +++ b/sql/protocol_cursor.cc @@ -85,7 +85,7 @@ bool Protocol_cursor::send_fields(List *list, int flags) DBUG_RETURN(FALSE); err: - send_error(thd, ER_OUT_OF_RESOURCES); /* purecov: inspected */ + my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */ } diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 10ff5fa3596..6ba1ce6267f 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -196,7 +196,6 @@ err: my_message(ER_UNKNOWN_ERROR, "Wrong parameters to function register_slave", MYF(0)); err2: - send_error(thd); return 1; } @@ -440,7 +439,7 @@ static Slave_log_event* find_slave_event(IO_CACHE* log, This function is broken now. See comment for translate_master(). */ -int show_new_master(THD* thd) +bool show_new_master(THD* thd) { Protocol *protocol= thd->protocol; DBUG_ENTER("show_new_master"); @@ -454,7 +453,7 @@ int show_new_master(THD* thd) if (errmsg[0]) my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), "SHOW NEW MASTER", errmsg); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } else { @@ -463,14 +462,14 @@ int show_new_master(THD* thd) MYSQL_TYPE_LONGLONG)); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); protocol->prepare_for_resend(); protocol->store(lex_mi->log_file_name, &my_charset_bin); protocol->store((ulonglong) lex_mi->pos); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } } @@ -633,7 +632,7 @@ err: } -int show_slave_hosts(THD* thd) +bool show_slave_hosts(THD* thd) { List field_list; Protocol *protocol= thd->protocol; @@ -655,7 +654,7 @@ int show_slave_hosts(THD* thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); pthread_mutex_lock(&LOCK_slave_list); @@ -676,12 +675,12 @@ int show_slave_hosts(THD* thd) if (protocol->write()) { pthread_mutex_unlock(&LOCK_slave_list); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } pthread_mutex_unlock(&LOCK_slave_list); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -762,7 +761,7 @@ static int fetch_db_tables(THD *thd, MYSQL *mysql, const char *db, - No active transaction (flush_relay_log_info would not work in this case) */ -int load_master_data(THD* thd) +bool load_master_data(THD* thd) { MYSQL mysql; MYSQL_RES* master_status_res = 0; @@ -784,16 +783,15 @@ int load_master_data(THD* thd) (error=terminate_slave_threads(active_mi,restart_thread_mask, 1 /*skip lock*/))) { - send_error(thd,error); + my_error(error, MYF(0)); unlock_slave_threads(active_mi); pthread_mutex_unlock(&LOCK_active_mi); - return 1; + return TRUE; } if (connect_to_master(thd, &mysql, active_mi)) { - net_printf(thd, error= ER_CONNECT_TO_MASTER, - mysql_error(&mysql)); + my_error(error= ER_CONNECT_TO_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -805,8 +803,7 @@ int load_master_data(THD* thd) if (mysql_real_query(&mysql, "SHOW DATABASES", 14) || !(db_res = mysql_store_result(&mysql))) { - net_printf(thd, error = ER_QUERY_ON_MASTER, - mysql_error(&mysql)); + my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -819,7 +816,7 @@ int load_master_data(THD* thd) if (!(table_res = (MYSQL_RES**)thd->alloc(num_dbs * sizeof(MYSQL_RES*)))) { - net_printf(thd, error = ER_OUTOFMEMORY); + my_error(error = ER_OUTOFMEMORY, MYF(0)); goto err; } @@ -833,8 +830,7 @@ int load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW MASTER STATUS",18) || !(master_status_res = mysql_store_result(&mysql))) { - net_printf(thd, error = ER_QUERY_ON_MASTER, - mysql_error(&mysql)); + my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -879,7 +875,6 @@ int load_master_data(THD* thd) if (mysql_create_db(thd, db, &create_info, 1)) { - send_error(thd, 0, 0); cleanup_mysql_results(db_res, cur_table_res - 1, table_res); goto err; } @@ -888,8 +883,7 @@ int load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW TABLES", 11) || !(*cur_table_res = mysql_store_result(&mysql))) { - net_printf(thd, error = ER_QUERY_ON_MASTER, - mysql_error(&mysql)); + my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); cleanup_mysql_results(db_res, cur_table_res - 1, table_res); goto err; } @@ -927,7 +921,7 @@ int load_master_data(THD* thd) if (init_master_info(active_mi, master_info_file, relay_log_info_file, 0)) - send_error(thd, ER_MASTER_INFO); + my_error(ER_MASTER_INFO, MYF(0)); strmake(active_mi->master_log_name, row[0], sizeof(active_mi->master_log_name)); active_mi->master_log_pos= my_strtoll10(row[1], (char**) 0, &error); @@ -946,8 +940,7 @@ int load_master_data(THD* thd) if (mysql_real_query(&mysql, "UNLOCK TABLES", 13)) { - net_printf(thd, error = ER_QUERY_ON_MASTER, - mysql_error(&mysql)); + my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } } @@ -956,10 +949,10 @@ int load_master_data(THD* thd) 0 /* not only reset, but also reinit */, &errmsg)) { - send_error(thd, 0, "Failed purging old relay logs"); + my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); unlock_slave_threads(active_mi); pthread_mutex_unlock(&LOCK_active_mi); - return 1; + return TRUE; } pthread_mutex_lock(&active_mi->rli.data_lock); active_mi->rli.group_master_log_pos = active_mi->master_log_pos; diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h index a9c504330ab..1ced69fdc3c 100644 --- a/sql/repl_failsafe.h +++ b/sql/repl_failsafe.h @@ -24,11 +24,11 @@ int update_slave_list(MYSQL* mysql, MASTER_INFO* mi); extern HASH slave_list; -int load_master_data(THD* thd); +bool load_master_data(THD* thd); int connect_to_master(THD *thd, MYSQL* mysql, MASTER_INFO* mi); -int show_new_master(THD* thd); -int show_slave_hosts(THD* thd); +bool show_new_master(THD* thd); +bool show_slave_hosts(THD* thd); int translate_master(THD* thd, LEX_MASTER_INFO* mi, char* errmsg); void init_slave_list(); void end_slave_list(); diff --git a/sql/set_var.cc b/sql/set_var.cc index 33c6a380223..e08a65c793a 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1520,8 +1520,8 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) { if (var_type != OPT_DEFAULT) { - net_printf(thd, ER_INCORRECT_GLOBAL_LOCAL_VAR, - name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); + my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), + name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); return 0; } /* As there was no local variable, return the global value */ @@ -1564,7 +1564,7 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) return tmp; } default: - net_printf(thd, ER_VAR_CANT_BE_READ, name); + my_error(ER_VAR_CANT_BE_READ, MYF(0), name); } return 0; } @@ -1950,8 +1950,8 @@ bool sys_var_character_set_server::check(THD *thd, set_var *var) (mysql_bin_log.is_open() || active_mi->slave_running || active_mi->rli.slave_running)) { - my_printf_error(0, "Binary logging and replication forbid changing \ -the global server character set or collation", MYF(0)); + my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0), + "character set, collation"); return 1; } return sys_var_character_set::check(thd,var); @@ -2057,8 +2057,8 @@ bool sys_var_collation_server::check(THD *thd, set_var *var) (mysql_bin_log.is_open() || active_mi->slave_running || active_mi->rli.slave_running)) { - my_printf_error(0, "Binary logging and replication forbid changing \ -the global server character set or collation", MYF(0)); + my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0), + "character set, collation"); return 1; } return sys_var_collation::check(thd,var); @@ -2407,8 +2407,7 @@ bool sys_var_thd_time_zone::check(THD *thd, set_var *var) (mysql_bin_log.is_open() || active_mi->slave_running || active_mi->rli.slave_running)) { - my_printf_error(0, "Binary logging and replication forbid changing " - "of the global server time zone", MYF(0)); + my_error(ER_LOGING_PROHIBIT_CHANGING_OF, MYF(0), "time zone"); return 1; } #endif @@ -2686,9 +2685,6 @@ void set_var_free() length Length of variable. zero means that we should use strlen() on the variable - NOTE - We have to use net_printf() as this is called during the parsing stage - RETURN VALUES pointer pointer to variable definitions 0 Unknown variable (error message is given) @@ -2701,7 +2697,7 @@ sys_var *find_sys_var(const char *str, uint length) length ? length : strlen(str)); if (!var) - net_printf(current_thd, ER_UNKNOWN_SYSTEM_VARIABLE, (char*) str); + my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); return var; } diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index 301ac6133ca..3f5814df575 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -398,3 +398,22 @@ character-set=latin2 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index 128859a5505..fa5d8f8a8c7 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -389,3 +389,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 3ad8d91bba7..7dbd32c9db4 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -398,3 +398,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 1878d6e2da2..8fe08ddc7a7 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -386,3 +386,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index af14aeac85c..b52aa6154ec 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -391,3 +391,22 @@ character-set=latin7 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index b731f398a2f..43a77fdec42 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -386,3 +386,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index ff797119971..1b3a916c777 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -399,3 +399,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index f5db8296d14..baf88d7fead 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -386,3 +386,22 @@ character-set=greek "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index 0b410dc1ac7..2c1efa97e30 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -391,3 +391,22 @@ character-set=latin2 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index 0c0ccdc0a74..5859e5380ef 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -386,3 +386,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index bd9dd98d525..c58acde49cd 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -390,3 +390,22 @@ character-set=ujis "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 9ab305bc2d8..74e42b09fc7 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -386,3 +386,22 @@ character-set=euckr "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index c8166a777bf..1bce2767784 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -388,3 +388,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index 07f7381091d..c09aa257ead 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -388,3 +388,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index 43cf08666ac..96985de759d 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -391,3 +391,22 @@ character-set=latin2 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 827c49d3f1f..c9dac302f5e 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -388,3 +388,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index a3c16ea5023..25c06397d7c 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -391,3 +391,22 @@ character-set=latin2 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index c5988fca6d5..71b21268dba 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -391,3 +391,22 @@ character-set=koi8r "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION ÄÌÑ ÎÅÏÂÎÏ×ÌÑÅÍÏÇÏ VIEW '%-.64s.%-.64s'" "ÐÒÏ×ÅÒËÁ CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÐÒÏ×ÁÌÉÌÁÓØ" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index 5a08ae4ba54..4228f3a3a4e 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -379,3 +379,22 @@ character-set=cp1250 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index a6bab89d689..9b9508eeca9 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -394,3 +394,22 @@ character-set=latin2 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 11bc53cde16..5af6d647fd3 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -390,3 +390,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index 6d9a6b98204..85866007367 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -386,3 +386,22 @@ character-set=latin1 "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION on non-updatable view '%-.64s.%-.64s'" "CHECK OPTION failed '%-.64s.%-.64s'" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index 03f3172c2fb..4bb3a6a1aab 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -392,3 +392,22 @@ character-set=koi8u "Illegal %s '%-.64s' value found during parsing", "CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÝÏ ÎÅ ÍÏÖÅ ÂÕÔÉ ÏÎÏ×ÌÅÎÎÉÍ" "ÐÅÒÅצÒËÁ CHECK OPTION ÄÌÑ VIEW '%-.64s.%-.64s' ÎÅ ÐÒÏÊÛÌÁ" +"Failed purging old relay logs: %s" +"Password hash should be a %d-digit hexadecimal number" +"Target log not found in binlog index" +"I/O error reading log index file" +"Server configuration does not permit binlog purge" +"Failed on fseek()" +"Fatal error during log purge" +"A purgeable log is in use, will not purge" +"Unknown error during log purge" +"Failed initializing relay log position: %s" +"You are not using binary logging" +"The '%-.64s' syntax is reserved for purposes internal to the MySQL server" +"WSAStartup Failed" +"Can't handle procedures with differents groups yet" +"Select must have a group with this procedure" +"Can't use ORDER clause with this procedure" +"Binary logging and replication forbid changing the global server %s" +"Can't map file: %-.64s, errno: %d" +"Wrong magic in %-.64s" diff --git a/sql/slave.cc b/sql/slave.cc index 2c6fb06b7cb..2ed554e65c8 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1489,7 +1489,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, packet_len= my_net_read(net); // read create table statement if (packet_len == packet_error) { - send_error(thd, ER_MASTER_NET_READ); + my_error(ER_MASTER_NET_READ, MYF(0)); DBUG_RETURN(1); } if (net->read_pos[0] == 255) // error from master @@ -1498,7 +1498,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, err_msg= (char*) net->read_pos + ((mysql->server_capabilities & CLIENT_PROTOCOL_41) ? 3+SQLSTATE_LENGTH+1 : 3); - net_printf(thd, ER_MASTER, err_msg); + my_error(ER_MASTER, MYF(0), err_msg); DBUG_RETURN(1); } thd->command = COM_TABLE_DUMP; @@ -1507,7 +1507,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, if (!(query = thd->strmake((char*) net->read_pos, packet_len))) { sql_print_error("create_table_from_dump: out of memory"); - net_printf(thd, ER_GET_ERRNO, "Out of memory"); + my_error(ER_GET_ERRNO, MYF(0), "Out of memory"); DBUG_RETURN(1); } thd->query= query; @@ -1521,7 +1521,6 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, /* Drop the table if 'overwrite' is true */ if (overwrite && mysql_rm_table(thd,&tables,1,0)) /* drop if exists */ { - send_error(thd); sql_print_error("create_table_from_dump: failed to drop the table"); goto err; } @@ -1544,7 +1543,6 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, tables.lock_type = TL_WRITE; if (!open_ltable(thd, &tables, TL_WRITE)) { - send_error(thd,0,0); // Send error from open_ltable sql_print_error("create_table_from_dump: could not open created table"); goto err; } @@ -1554,7 +1552,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, /* Copy the data file */ if (file->net_read_dump(net)) { - net_printf(thd, ER_MASTER_NET_READ); + my_error(ER_MASTER_NET_READ, MYF(0)); sql_print_error("create_table_from_dump: failed in\ handler::net_read_dump()"); goto err; @@ -1574,7 +1572,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, error=file->repair(thd,&check_opt) != 0; thd->net.vio = save_vio; if (error) - net_printf(thd, ER_INDEX_REBUILD,tables.table->real_name); + my_error(ER_INDEX_REBUILD, MYF(0), tables.table->real_name); err: close_thread_tables(thd); @@ -1597,12 +1595,11 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, { if (!(mysql = mysql_init(NULL))) { - send_error(thd); // EOM DBUG_RETURN(1); } if (connect_to_master(thd, mysql, mi)) { - net_printf(thd, ER_CONNECT_TO_MASTER, mysql_error(mysql)); + my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql)); mysql_close(mysql); DBUG_RETURN(1); } @@ -1626,7 +1623,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, if (!called_connected) mysql_close(mysql); if (errmsg && thd->vio_ok()) - send_error(thd, error, errmsg); + my_message(error, errmsg, MYF(0)); DBUG_RETURN(test(error)); // Return 1 on error } @@ -2263,7 +2260,7 @@ void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a) } } -int show_master_info(THD* thd, MASTER_INFO* mi) +bool show_master_info(THD* thd, MASTER_INFO* mi) { // TODO: fix this for multi-master List field_list; @@ -2327,7 +2324,7 @@ int show_master_info(THD* thd, MASTER_INFO* mi) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if (mi->host[0]) { @@ -2426,10 +2423,10 @@ int show_master_info(THD* thd, MASTER_INFO* mi) pthread_mutex_unlock(&mi->data_lock); if (my_net_write(&thd->net, (char*)thd->packet.ptr(), packet->length())) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } diff --git a/sql/slave.h b/sql/slave.h index 46fe58e1976..e0383b6ebe8 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -474,8 +474,8 @@ int fetch_master_table(THD* thd, const char* db_name, const char* table_name, void table_rule_ent_hash_to_str(String* s, HASH* h); void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a); -int show_master_info(THD* thd, MASTER_INFO* mi); -int show_binlog_info(THD* thd); +bool show_master_info(THD* thd, MASTER_INFO* mi); +bool show_binlog_info(THD* thd); /* See if the query uses any tables that should not be replicated */ int tables_ok(THD* thd, TABLE_LIST* tables); diff --git a/sql/sp.cc b/sql/sp.cc index 6475b64eb18..2fae2addf2a 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -983,7 +983,7 @@ sp_cache_functions(THD *thd, LEX *lex) { delete newlex; thd->lex= oldlex; - net_printf(thd, ER_SP_DOES_NOT_EXIST, "FUNCTION", ls->str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", ls->str); ret= 1; break; } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 6a17bc189c3..1f1cf8ac4cd 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -494,16 +494,17 @@ sp_head::execute(THD *thd) case SP_HANDLER_CONTINUE: ctx->save_variables(hf); ctx->push_hstack(ip); - // Fall through + // Fall through default: ip= hip; ret= 0; ctx->clear_handler(); ctx->in_handler= TRUE; + thd->clear_error(); continue; } } - } while (ret == 0 && !thd->killed && !thd->query_error); + } while (ret == 0 && !thd->killed); cleanup_items(thd->current_arena->free_list); thd->current_arena= old_arena; @@ -512,7 +513,7 @@ sp_head::execute(THD *thd) DBUG_PRINT("info", ("ret=%d killed=%d query_error=%d", ret, thd->killed, thd->query_error)); - if (thd->killed || thd->query_error) + if (thd->killed) ret= -1; /* If the DB has changed, the pointer has changed too, but the original thd->db will then have been freed */ @@ -622,8 +623,8 @@ sp_head::execute_procedure(THD *thd, List *args) if (args->elements != params) { - net_printf(thd, ER_SP_WRONG_NO_OF_ARGS, "PROCEDURE", m_name.str, - params, args->elements); + my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), + "PROCEDURE", m_name.str, params, args->elements); DBUG_RETURN(-1); } @@ -694,13 +695,7 @@ sp_head::execute_procedure(THD *thd, List *args) if (! ret) ret= execute(thd); - // Don't copy back OUT values if we got an error - if (ret) - { - if (thd->net.report_error) - send_error(thd, 0, NullS); - } - else if (csize > 0) + if (!ret && csize > 0) { List_iterator_fast li(*args); Item *it; @@ -898,7 +893,7 @@ sp_head::check_backpatch(THD *thd) { if (bp->lab->type == SP_LAB_REF) { - net_printf(thd, ER_SP_LILABEL_MISMATCH, "GOTO", bp->lab->name); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "GOTO", bp->lab->name); return -1; } } diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 169c9809383..3f9ab39e358 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -148,7 +148,7 @@ sp_cursor::pre_open(THD *thd) { if (m_isopen) { - send_error(thd, ER_SP_CURSOR_ALREADY_OPEN); + my_error(ER_SP_CURSOR_ALREADY_OPEN, MYF(0)); return NULL; } @@ -182,7 +182,7 @@ sp_cursor::close(THD *thd) { if (! m_isopen) { - send_error(thd, ER_SP_CURSOR_NOT_OPEN); + my_error(ER_SP_CURSOR_NOT_OPEN, MYF(0)); return -1; } destroy(); @@ -212,12 +212,12 @@ sp_cursor::fetch(THD *thd, List *vars) if (! m_isopen) { - send_error(thd, ER_SP_CURSOR_NOT_OPEN); + my_error(ER_SP_CURSOR_NOT_OPEN, MYF(0)); return -1; } if (m_current_row == NULL) { - send_error(thd, ER_SP_FETCH_NO_DATA); + my_error(ER_SP_FETCH_NO_DATA, MYF(0)); return -1; } @@ -229,7 +229,7 @@ sp_cursor::fetch(THD *thd, List *vars) if (fldcount >= m_prot->get_field_count()) { - send_error(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS); + my_error(ER_SP_WRONG_NO_OF_FETCH_ARGS, MYF(0)); return -1; } s= row[fldcount]; @@ -255,7 +255,7 @@ sp_cursor::fetch(THD *thd, List *vars) } if (fldcount < m_prot->get_field_count()) { - send_error(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS); + my_error(ER_SP_WRONG_NO_OF_FETCH_ARGS, MYF(0)); return -1; } m_current_row= m_current_row->next; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 51768922f6d..bb5f1d0949d 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1225,8 +1225,7 @@ bool check_change_password(THD *thd, const char *host, const char *user, { if (!initialized) { - net_printf(thd,ER_OPTION_PREVENTS_STATEMENT, - "--skip-grant-tables"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); return(1); } if (!thd->slave_thread && @@ -1238,16 +1237,14 @@ bool check_change_password(THD *thd, const char *host, const char *user, } if (!thd->slave_thread && !thd->user[0]) { - send_error(thd, ER_PASSWORD_ANONYMOUS_USER); + my_error(ER_PASSWORD_ANONYMOUS_USER, MYF(0)); return(1); } uint len=strlen(new_password); if (len && len != SCRAMBLED_PASSWORD_CHAR_LENGTH && len != SCRAMBLED_PASSWORD_CHAR_LENGTH_323) { - net_printf(thd, 0, - "Password hash should be a %d-digit hexadecimal number", - SCRAMBLED_PASSWORD_CHAR_LENGTH); + my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH); return -1; } return(0); @@ -1285,7 +1282,7 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(acl_user= find_acl_user(host, user))) { VOID(pthread_mutex_unlock(&acl_cache->lock)); - send_error(thd, ER_PASSWORD_NO_MATCH); + my_error(ER_PASSWORD_NO_MATCH, MYF(0)); DBUG_RETURN(1); } /* update loaded acl entry: */ @@ -1298,7 +1295,6 @@ bool change_password(THD *thd, const char *host, const char *user, new_password, new_password_len)) { VOID(pthread_mutex_unlock(&acl_cache->lock)); /* purecov: deadcode */ - send_error(thd,0); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } @@ -2290,11 +2286,11 @@ table_error: revoke_grant Set to 1 if this is a REVOKE command RETURN - 0 ok - 1 error + FALSE ok + TRUE error */ -int mysql_table_grant(THD *thd, TABLE_LIST *table_list, +bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, List &user_list, List &columns, ulong rights, bool revoke_grant) @@ -2311,12 +2307,12 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); /* purecov: inspected */ - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } if (rights & ~TABLE_ACLS) { my_error(ER_ILLEGAL_GRANT_FOR_TABLE,MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (columns.elements && !revoke_grant) @@ -2325,8 +2321,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, List_iterator column_iter(columns); int res; - if ((res= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(res); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); while ((column = column_iter++)) { @@ -2338,7 +2334,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { my_error(ER_BAD_FIELD_ERROR, MYF(0), column->column.c_ptr(), table_list->alias); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } column_priv|= column->rights; } @@ -2353,7 +2349,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (access(buf,F_OK)) { my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } @@ -2386,19 +2382,19 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, */ tables[0].updating= tables[1].updating= tables[2].updating= 1; if (!tables_ok(0, tables)) - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } #endif if (simple_open_n_lock_tables(thd,tables)) { // Should never happen close_thread_tables(thd); /* purecov: deadcode */ - DBUG_RETURN(-1); /* purecov: deadcode */ + DBUG_RETURN(TRUE); /* purecov: deadcode */ } if (!revoke_grant) create_new_users= test_if_create_new_users(thd); - int result=0; + bool result= FALSE; rw_wrlock(&LOCK_grant); MEM_ROOT *old_root=my_pthread_getspecific_ptr(MEM_ROOT*,THR_MALLOC); my_pthread_setspecific_ptr(THR_MALLOC,&memex); @@ -2411,7 +2407,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, Str->user.length > USERNAME_LENGTH) { my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); - result= -1; + result= TRUE; continue; } /* Create user if needed */ @@ -2421,7 +2417,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, pthread_mutex_unlock(&acl_cache->lock); if (error) { - result= -1; // Remember error + result= TRUE; // Remember error continue; // Add next user } @@ -2441,7 +2437,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), Str->user.str, Str->host.str, table_list->real_name); - result= -1; + result= TRUE; continue; } grant_table = new GRANT_TABLE (Str->host.str, db_name, @@ -2450,7 +2446,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, column_priv); if (!grant_table) // end of memory { - result= -1; /* purecov: deadcode */ + result= TRUE; /* purecov: deadcode */ continue; /* purecov: deadcode */ } my_hash_insert(&column_priv_hash,(byte*) grant_table); @@ -2494,7 +2490,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, db_name, real_name, rights, column_priv, revoke_grant)) { // Crashend table ?? - result= -1; /* purecov: deadcode */ + result= TRUE; /* purecov: deadcode */ } else if (tables[2].table) { @@ -2503,7 +2499,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, db_name, real_name, rights, revoke_grant))) { - result= -1; + result= TRUE; } } } @@ -2517,8 +2513,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, } -int mysql_grant(THD *thd, const char *db, List &list, - ulong rights, bool revoke_grant) +bool mysql_grant(THD *thd, const char *db, List &list, + ulong rights, bool revoke_grant) { List_iterator str_list (list); LEX_USER *Str; @@ -2530,7 +2526,7 @@ int mysql_grant(THD *thd, const char *db, List &list, { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); /* purecov: tested */ - DBUG_RETURN(-1); /* purecov: tested */ + DBUG_RETURN(TRUE); /* purecov: tested */ } if (lower_case_table_names && db) @@ -2561,14 +2557,14 @@ int mysql_grant(THD *thd, const char *db, List &list, */ tables[0].updating= tables[1].updating= 1; if (!tables_ok(0, tables)) - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } #endif if (simple_open_n_lock_tables(thd,tables)) { // This should never happen close_thread_tables(thd); /* purecov: deadcode */ - DBUG_RETURN(-1); /* purecov: deadcode */ + DBUG_RETURN(TRUE); /* purecov: deadcode */ } if (!revoke_grant) @@ -2880,11 +2876,11 @@ err: command= "create view"; else if (want_access & SHOW_VIEW_ACL) command= "show create view"; - net_printf(thd,ER_TABLEACCESS_DENIED_ERROR, - command, - thd->priv_user, - thd->host_or_ip, - table ? table->real_name : "unknown"); + my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + table ? table->real_name : "unknown"); } DBUG_RETURN(1); } @@ -3146,7 +3142,7 @@ static uint command_lengths[]= Send to client grant-like strings depicting user@host privileges */ -int mysql_show_grants(THD *thd,LEX_USER *lex_user) +bool mysql_show_grants(THD *thd,LEX_USER *lex_user) { ulong want_access; uint counter,index; @@ -3161,7 +3157,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (!initialized) { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!lex_user->host.str) @@ -3173,7 +3169,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) lex_user->user.length > USERNAME_LENGTH) { my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } for (counter=0 ; counter < acl_users.elements ; counter++) @@ -3192,7 +3188,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) { my_error(ER_NONEXISTING_GRANT, MYF(0), lex_user->user.str, lex_user->host.str); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } Item_string *field=new Item_string("",0,&my_charset_latin1); @@ -3204,7 +3200,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) field_list.push_back(field); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -3526,7 +3522,7 @@ int open_grant_tables(THD *thd, TABLE_LIST *tables) if (!initialized) { - net_printf(thd,ER_OPTION_PREVENTS_STATEMENT, "--skip-grant-tables"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); DBUG_RETURN(-1); } @@ -3595,7 +3591,7 @@ ACL_USER *check_acl_user(LEX_USER *user_name, } -int mysql_drop_user(THD *thd, List &list) +bool mysql_drop_user(THD *thd, List &list) { uint counter, acl_userd; int result; @@ -3606,7 +3602,7 @@ int mysql_drop_user(THD *thd, List &list) DBUG_ENTER("mysql_drop_user"); if ((result= open_grant_tables(thd, tables))) - DBUG_RETURN(result == 1 ? 0 : 1); + DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -3694,7 +3690,7 @@ int mysql_drop_user(THD *thd, List &list) record[0]))) { tables[0].table->file->print_error(error, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } delete_dynamic_element(&acl_users, acl_userd); } @@ -3708,7 +3704,7 @@ int mysql_drop_user(THD *thd, List &list) DBUG_RETURN(result); } -int mysql_revoke_all(THD *thd, List &list) +bool mysql_revoke_all(THD *thd, List &list) { uint counter; int result; @@ -3717,7 +3713,7 @@ int mysql_revoke_all(THD *thd, List &list) DBUG_ENTER("mysql_revoke_all"); if ((result= open_grant_tables(thd, tables))) - DBUG_RETURN(result == 1 ? 0 : 1); + DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 390106c1546..f6074da5279 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -158,11 +158,11 @@ bool check_change_password(THD *thd, const char *host, const char *user, char *password); bool change_password(THD *thd, const char *host, const char *user, char *password); -int mysql_grant(THD *thd, const char *db, List &user_list, - ulong rights, bool revoke); -int mysql_table_grant(THD *thd, TABLE_LIST *table, List &user_list, - List &column_list, ulong rights, - bool revoke); +bool mysql_grant(THD *thd, const char *db, List &user_list, + ulong rights, bool revoke); +bool mysql_table_grant(THD *thd, TABLE_LIST *table, List &user_list, + List &column_list, ulong rights, + bool revoke); my_bool grant_init(THD *thd); void grant_free(void); void grant_reload(THD *thd); @@ -179,11 +179,11 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table); ulong get_column_grant(THD *thd, GRANT_INFO *grant, const char *db_name, const char *table_name, const char *field_name); -int mysql_show_grants(THD *thd, LEX_USER *user); +bool mysql_show_grants(THD *thd, LEX_USER *user); void get_privilege_desc(char *to, uint max_length, ulong access); void get_mqh(const char *user, const char *host, USER_CONN *uc); -int mysql_drop_user(THD *thd, List &list); -int mysql_revoke_all(THD *thd, List &list); +bool mysql_drop_user(THD *thd, List &list); +bool mysql_revoke_all(THD *thd, List &list); void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, const char *db, const char *table); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8199c6fcdce..9a45660c45b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1815,21 +1815,20 @@ int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables) tables - list of tables for open&locking RETURN - 0 - ok - -1 - error - 1 - error reported to user + FALSE - ok + TRUE - error NOTE The lock will automaticly be freed by close_thread_tables() */ -int open_and_lock_tables(THD *thd, TABLE_LIST *tables) +bool open_and_lock_tables(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("open_and_lock_tables"); uint counter; if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter) || mysql_handle_derived(thd->lex)) - DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ /* Let us propagate pointers to open tables from global table list to table lists in particular selects if needed. @@ -1850,7 +1849,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables) } } } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -2609,9 +2608,9 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List &fields, ** Check that all given fields exists and fill struct with current data ****************************************************************************/ -int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, - List &fields, bool set_query_id, - List *sum_func_list, bool allow_sum_func) +bool setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, + List &fields, bool set_query_id, + List *sum_func_list, bool allow_sum_func) { reg2 Item *item; List_iterator it(fields); @@ -2629,7 +2628,7 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, (item= *(it.ref()))->check_cols(1)) { select_lex->no_wrap_view_item= 0; - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } if (ref) *(ref++)= item; @@ -2958,7 +2957,6 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name); err: - send_error(thd); DBUG_RETURN(1); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 392534492df..a543222a4a1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -762,7 +762,7 @@ select_result::select_result() void select_result::send_error(uint errcode,const char *err) { - ::send_error(thd, errcode, err); + my_message(errcode, err, MYF(0)); } @@ -865,7 +865,7 @@ bool select_send::send_eof() void select_to_file::send_error(uint errcode,const char *err) { - ::send_error(thd,errcode,err); + my_message(errcode, err, MYF(0)); if (file > 0) { (void) end_io_cache(&cache); diff --git a/sql/sql_class.h b/sql/sql_class.h index 32f156fbee8..f014a597169 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1112,6 +1112,7 @@ public: net.last_error[0]= 0; net.last_errno= 0; net.report_error= 0; + query_error= 0; } inline bool vio_ok() const { return net.vio != 0; } #else diff --git a/sql/sql_db.cc b/sql/sql_db.cc index f41e03b0602..df3c27b9b72 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -379,13 +379,13 @@ bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create) In this case the entry should not be logged. RETURN VALUES - 0 ok - -1 Error + FALSE ok + TRUE Error */ -int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, - bool silent) +bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, + bool silent) { char path[FN_REFLEN+16]; long result= 1; @@ -489,7 +489,7 @@ exit2: /* db-name is already validated when we come here */ -int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) +bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) { char path[FN_REFLEN+16]; long result=1; @@ -532,7 +532,7 @@ exit: start_waiting_global_read_lock(thd); exit2: VOID(pthread_mutex_unlock(&LOCK_mysql_create_db)); - DBUG_RETURN(error ? -1 : 0); /* -1 to delegate send_error() */ + DBUG_RETURN(error); } @@ -548,11 +548,11 @@ exit2: silent Don't generate errors RETURN - 0 ok (Database dropped) - -1 Error generated + FALSE ok (Database dropped) + ERROR Error */ -int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) +bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) { long deleted=0; int error= 0; @@ -985,12 +985,12 @@ bool mysql_change_db(THD *thd, const char *name) if (!dbname || !(db_length= strlen(dbname))) { x_free(dbname); /* purecov: inspected */ - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } if (check_db_name(dbname)) { - net_printf(thd, ER_WRONG_DB_NAME, dbname); + my_error(ER_WRONG_DB_NAME, MYF(0), dbname); x_free(dbname); DBUG_RETURN(1); } @@ -1003,10 +1003,10 @@ bool mysql_change_db(THD *thd, const char *name) thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - net_printf(thd,ER_DBACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - dbname); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->priv_host, @@ -1021,7 +1021,7 @@ bool mysql_change_db(THD *thd, const char *name) path[length-1]=0; // remove ending '\' if (access(path,F_OK)) { - net_printf(thd,ER_BAD_DB_ERROR,dbname); + my_error(ER_BAD_DB_ERROR, MYF(0), dbname); my_free(dbname,MYF(0)); DBUG_RETURN(1); } diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index f9dba49d2e3..54c6cd1ebc5 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -29,8 +29,8 @@ #include "sp_head.h" #include "sql_trigger.h" -int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, - ha_rows limit, ulong options) +bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, + SQL_LIST *order, ha_rows limit, ulong options) { int error; TABLE *table; @@ -41,22 +41,22 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, ha_rows deleted; DBUG_ENTER("mysql_delete"); - if ((error= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(error); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); table= table_list->table; table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); thd->proc_info="init"; table->map=1; - if ((error= mysql_prepare_delete(thd, table_list, &conds))) - DBUG_RETURN(error); + if (mysql_prepare_delete(thd, table_list, &conds)) + DBUG_RETURN(TRUE); const_cond= (!conds || conds->const_item()); safe_update=test(thd->options & OPTION_SAFE_UPDATES); if (safe_update && const_cond) { - send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE); - DBUG_RETURN(1); + my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); + DBUG_RETURN(TRUE); } if (thd->lex->duplicates == DUP_IGNORE) @@ -85,7 +85,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, table->quick_keys.clear_all(); // Can't use 'only index' select=make_select(table,0,0,conds,&error); if (error) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if ((select && select->check_quick(thd, safe_update, limit)) || !limit) { delete select; @@ -103,8 +103,8 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, { delete select; free_underlaid_joins(thd, &thd->lex->select_lex); - send_error(thd,ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE); - DBUG_RETURN(1); + my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); + DBUG_RETURN(TRUE); } } if (options & OPTION_QUICK) @@ -135,7 +135,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, { delete select; free_underlaid_joins(thd, &thd->lex->select_lex); - DBUG_RETURN(-1); // This will force out message + DBUG_RETURN(TRUE); } /* Filesort has already found and selected the rows we want to delete, @@ -150,7 +150,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, { delete select; free_underlaid_joins(thd, &thd->lex->select_lex); - DBUG_RETURN(-1); // This will force out message + DBUG_RETURN(TRUE); } init_read_record(&info,thd,table,select,1,1); deleted=0L; @@ -253,15 +253,13 @@ cleanup: thd->lock=0; } free_underlaid_joins(thd, &thd->lex->select_lex); - if (error >= 0 || thd->net.report_error) - send_error(thd,thd->killed_errno()); - else + if (error < 0) { thd->row_count_func= deleted; send_ok(thd,deleted); DBUG_PRINT("info",("%d records deleted",deleted)); } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -275,11 +273,10 @@ cleanup: conds - conditions RETURN VALUE - 0 - OK - 1 - error (message is sent to user) - -1 - error (message is not sent to user) + FALSE OK + TRUE error */ -int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) +bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) { SELECT_LEX *select_lex= &thd->lex->select_lex; DBUG_ENTER("mysql_prepare_delete"); @@ -287,19 +284,19 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) if (setup_tables(thd, table_list, conds) || setup_conds(thd, table_list, conds) || setup_ftfuncs(select_lex)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if (!table_list->updatable || check_key_in_view(thd, table_list)) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (unique_table(table_list, table_list->next_independent())) { my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, conds); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -323,16 +320,15 @@ extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b) thd thread handler RETURN - 0 OK - -1 Error + FALSE OK + TRUE Error */ -int mysql_multi_delete_prepare(THD *thd) +bool mysql_multi_delete_prepare(THD *thd) { LEX *lex= thd->lex; TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxilliary_table_list.first; TABLE_LIST *target_tbl; - int res= 0; DBUG_ENTER("mysql_multi_delete_prepare"); /* @@ -342,7 +338,7 @@ int mysql_multi_delete_prepare(THD *thd) lex->query_tables also point on local list of DELETE SELECT_LEX */ if (setup_tables(thd, lex->query_tables, &lex->select_lex.where)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); /* Fix tables-to-be-deleted-from list to point at opened tables */ for (target_tbl= (TABLE_LIST*) aux_tables; @@ -355,7 +351,7 @@ int mysql_multi_delete_prepare(THD *thd) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), target_tbl->real_name, "DELETE"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* Check are deleted table used somewhere inside subqueries. @@ -373,12 +369,11 @@ int mysql_multi_delete_prepare(THD *thd) { my_error(ER_UPDATE_TABLE_USED, MYF(0), target_tbl->correspondent_table->real_name); - res= -1; - break; + DBUG_RETURN(TRUE); } } } - DBUG_RETURN(res); + DBUG_RETURN(FALSE); } @@ -522,7 +517,7 @@ void multi_delete::send_error(uint errcode,const char *err) DBUG_ENTER("multi_delete::send_error"); /* First send error what ever it is ... */ - ::send_error(thd,errcode,err); + my_message(errcode, err, MYF(0)); /* If nothing deleted return */ if (!deleted) @@ -668,9 +663,7 @@ bool multi_delete::send_eof() if (ha_autocommit_or_rollback(thd,local_error > 0)) local_error=1; - if (local_error) - ::send_error(thd); - else + if (!local_error) { thd->row_count_func= deleted; ::send_ok(thd, deleted); @@ -695,12 +688,12 @@ bool multi_delete::send_eof() - If we want to have a name lock on the table on exit without errors. */ -int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) +bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) { HA_CREATE_INFO create_info; char path[FN_REFLEN]; TABLE **table_ptr; - int error; + bool error; DBUG_ENTER("mysql_truncate"); bzero((char*) &create_info,sizeof(create_info)); @@ -738,7 +731,7 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) { my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!ha_supports_generate(table_type)) { @@ -748,11 +741,11 @@ int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) HA_POS_ERROR, 0)); } if (lock_and_wait_for_table_name(thd, table_list)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } *fn_ext(path)=0; // Remove the .frm extension - error= ha_create_table(path,&create_info,1) ? -1 : 0; + error= ha_create_table(path,&create_info,1); query_cache_invalidate3(thd, table_list, 0); end: @@ -779,5 +772,5 @@ end: unlock_table_name(thd, table_list); VOID(pthread_mutex_unlock(&LOCK_open)); } - DBUG_RETURN(error ? -1 : 0); + DBUG_RETURN(error); } diff --git a/sql/sql_do.cc b/sql/sql_do.cc index 25a8359f3d2..3ca3bea743a 100644 --- a/sql/sql_do.cc +++ b/sql/sql_do.cc @@ -20,16 +20,16 @@ #include "mysql_priv.h" #include "sql_acl.h" -int mysql_do(THD *thd, List &values) +bool mysql_do(THD *thd, List &values) { List_iterator li(values); Item *value; DBUG_ENTER("mysql_do"); if (setup_fields(thd, 0, 0, values, 0, 0, 0)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); while ((value = li++)) value->val_int(); thd->clear_error(); // DO always is OK send_ok(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } diff --git a/sql/sql_error.cc b/sql/sql_error.cc index c0f76ab0388..e4b9e615db6 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -184,14 +184,14 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, Takes into account the current LIMIT RETURN VALUES - 0 ok - 1 Error sending data to client + FALSE ok + TRUE Error sending data to client */ static const char *warning_level_names[]= {"Note", "Warning", "Error", "?"}; static int warning_level_length[]= { 4, 7, 5, 1 }; -my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) +bool mysqld_show_warnings(THD *thd, ulong levels_to_show) { List field_list; DBUG_ENTER("mysqld_show_warnings"); @@ -202,7 +202,7 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) if (thd->protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); MYSQL_ERROR *err; SELECT_LEX *sel= &thd->lex->select_lex; @@ -226,10 +226,10 @@ my_bool mysqld_show_warnings(THD *thd, ulong levels_to_show) protocol->store((uint32) err->code); protocol->store(err->msg, strlen(err->msg), system_charset_info); if (protocol->write()) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); if (!--limit) break; } - send_eof(thd); - DBUG_RETURN(0); + send_eof(thd); + DBUG_RETURN(FALSE); } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 1443f9f9d5f..bb872b2c39b 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -47,7 +47,7 @@ static TABLE **find_table_ptr_by_name(THD *thd,const char *db, bool is_alias, bool dont_lock, bool *was_flushed); -int mysql_ha_open(THD *thd, TABLE_LIST *tables) +bool mysql_ha_open(THD *thd, TABLE_LIST *tables) { HANDLER_TABLES_HACK(thd); uint counter; @@ -58,18 +58,18 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables) HANDLER_TABLES_HACK(thd); if (err) - return -1; + return TRUE; // there can be only one table in *tables if (!(tables->table->file->table_flags() & HA_CAN_SQL_HANDLER)) { my_printf_error(ER_ILLEGAL_HA,ER(ER_ILLEGAL_HA),MYF(0), tables->alias); mysql_ha_close(thd, tables,1); - return -1; + return TRUE; } send_ok(thd); - return 0; + return FALSE; } @@ -98,11 +98,11 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables) is suppressed. RETURN - 0 ok - -1 error + FALSE OK + TRUE Error */ -int mysql_ha_close(THD *thd, TABLE_LIST *tables, +bool mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok, bool dont_lock, bool no_alias) { TABLE **table_ptr; @@ -127,11 +127,11 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables, { my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), tables->alias, "HANDLER"); - return -1; + return TRUE; } if (!dont_send_ok) send_ok(thd); - return 0; + return FALSE; } @@ -201,11 +201,11 @@ static enum enum_ha_read_modes rkey_to_rnext[]= { RNEXT_SAME, RNEXT, RPREV, RNEXT, RPREV, RNEXT, RPREV, RPREV }; -int mysql_ha_read(THD *thd, TABLE_LIST *tables, - enum enum_ha_read_modes mode, char *keyname, - List *key_expr, - enum ha_rkey_function ha_rkey_mode, Item *cond, - ha_rows select_limit,ha_rows offset_limit) +bool mysql_ha_read(THD *thd, TABLE_LIST *tables, + enum enum_ha_read_modes mode, char *keyname, + List *key_expr, + enum ha_rkey_function ha_rkey_mode, Item *cond, + ha_rows select_limit,ha_rows offset_limit) { int err, keyno=-1; bool was_flushed; @@ -216,12 +216,12 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, { my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0), tables->alias,"HANDLER"); - return -1; + return TRUE; } tables->table=table; if (cond && (cond->fix_fields(thd, tables, &cond) || cond->check_cols(1))) - return -1; + return TRUE; /* InnoDB needs to know that this table handle is used in the HANDLER */ @@ -233,7 +233,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, { my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), keyname,tables->alias); - return -1; + return TRUE; } table->file->ha_index_or_rnd_end(); table->file->ha_index_init(keyno); @@ -333,10 +333,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, key_len+=key_part->store_length; } if (!(key= (byte*) thd->calloc(ALIGN_SIZE(key_len)))) - { - send_error(thd,ER_OUTOFMEMORY); goto err; - } key_copy(key, table, keyno, key_len); err=table->file->index_read(table->record[0], key,key_len,ha_rkey_mode); @@ -344,7 +341,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, break; } default: - send_error(thd,ER_ILLEGAL_HA); + my_error(ER_ILLEGAL_HA, MYF(0)); goto err; } @@ -384,11 +381,11 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ok: mysql_unlock_tables(thd,lock); send_eof(thd); - return 0; + return FALSE; err: mysql_unlock_tables(thd,lock); err0: - return -1; + return TRUE; } diff --git a/sql/sql_help.cc b/sql/sql_help.cc index cba74c93a6a..d108f6f69b4 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -276,7 +276,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, (iindex_relations= find_type((char*) primary_key_name, &relations->keynames, 1+2)-1)<0) { - send_error(thd,ER_CORRUPT_HELP_DB); + my_error(ER_CORRUPT_HELP_DB, 0); DBUG_RETURN(-1); } rtopic_id= find_fields[help_relation_help_topic_id].field; @@ -607,12 +607,11 @@ SQL_SELECT *prepare_select_for_name(THD *thd, const char *mask, uint mlen, thd Thread handler RETURN VALUES - 0 Success - 1 Error and send_error already commited - -1 error && send_error should be issued (normal case) + FALSE Success + TRUE Error and send_error already commited */ -int mysqld_help(THD *thd, const char *mask) +bool mysqld_help(THD *thd, const char *mask) { Protocol *protocol= thd->protocol; SQL_SELECT *select; @@ -640,8 +639,8 @@ int mysqld_help(THD *thd, const char *mask) uint mlen= strlen(mask); MEM_ROOT *mem_root= &thd->mem_root; - if ((res= open_and_lock_tables(thd, tables))) - goto end; + if (open_and_lock_tables(thd, tables)) + goto error; /* Init tables and fields to be usable from items @@ -650,10 +649,7 @@ int mysqld_help(THD *thd, const char *mask) setup_tables(thd, tables, 0); memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields)); if (init_fields(thd, tables, used_fields, array_elements(used_fields))) - { - res= -1; - goto end; - } + goto error; size_t i; for (i=0; ifile->init_table_handle_for_HANDLER(); @@ -661,12 +657,8 @@ int mysqld_help(THD *thd, const char *mask) if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[0].table, used_fields[help_topic_name].field,&error))) - { - res= -1; - goto end; - } + goto error; - res= 1; count_topics= search_topics(thd,tables[0].table,used_fields, select,&topics_list, &name, &description, &example); @@ -678,10 +670,8 @@ int mysqld_help(THD *thd, const char *mask) if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[3].table, used_fields[help_keyword_name].field,&error))) - { - res= -1; - goto end; - } + goto error; + count_topics=search_keyword(thd,tables[3].table,used_fields,select,&key_id); delete select; count_topics= (count_topics != 1) ? 0 : @@ -697,10 +687,7 @@ int mysqld_help(THD *thd, const char *mask) if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, used_fields[help_category_name].field,&error))) - { - res= -1; - goto end; - } + goto error; count_categories= search_categories(thd, tables[1].table, used_fields, select, @@ -709,13 +696,13 @@ int mysqld_help(THD *thd, const char *mask) if (!count_categories) { if (send_header_2(protocol,FALSE)) - goto end; + goto error; } else if (count_categories > 1) { if (send_header_2(protocol,FALSE) || send_variant_2_list(mem_root,protocol,&categories_list,"Y",0)) - goto end; + goto error; } else { @@ -728,20 +715,14 @@ int mysqld_help(THD *thd, const char *mask) new Item_int((int32)category_id)); if (!(select= prepare_simple_select(thd,cond_topic_by_cat, tables,tables[0].table,&error))) - { - res= -1; - goto end; - } + goto error; get_all_items_for_category(thd,tables[0].table, used_fields[help_topic_name].field, select,&topics_list); delete select; if (!(select= prepare_simple_select(thd,cond_cat_by_cat,tables, tables[1].table,&error))) - { - res= -1; - goto end; - } + goto error; get_all_items_for_category(thd,tables[1].table, used_fields[help_category_name].field, select,&subcategories_list); @@ -750,39 +731,36 @@ int mysqld_help(THD *thd, const char *mask) if (send_header_2(protocol, true) || send_variant_2_list(mem_root,protocol,&topics_list, "N",cat) || send_variant_2_list(mem_root,protocol,&subcategories_list,"Y",cat)) - goto end; + goto error; } } else if (count_topics == 1) { if (send_answer_1(protocol,&name,&description,&example)) - goto end; + goto error; } else { /* First send header and functions */ if (send_header_2(protocol, FALSE) || send_variant_2_list(mem_root,protocol, &topics_list, "N", 0)) - goto end; + goto error; if (!(select= prepare_select_for_name(thd,mask,mlen,tables,tables[1].table, used_fields[help_category_name].field,&error))) - { - res= -1; - goto end; - } + goto error; search_categories(thd, tables[1].table, used_fields, select,&categories_list, 0); delete select; /* Then send categories */ if (send_variant_2_list(mem_root,protocol, &categories_list, "Y", 0)) - goto end; + goto error; } - res= 0; - send_eof(thd); end: - DBUG_RETURN(res); + DBUG_RETURN(FALSE); +error: + DBUG_RETURN(TRUE); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 787774e3236..04d7bf5d5ab 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -115,12 +115,12 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, } -int mysql_insert(THD *thd,TABLE_LIST *table_list, - List &fields, - List &values_list, - List &update_fields, - List &update_values, - enum_duplicates duplic) +bool mysql_insert(THD *thd,TABLE_LIST *table_list, + List &fields, + List &values_list, + List &update_fields, + List &update_values, + enum_duplicates duplic) { int error, res; /* @@ -174,7 +174,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, my_printf_error(ER_DELAYED_INSERT_TABLE_LOCKED, ER(ER_DELAYED_INSERT_TABLE_LOCKED), MYF(0), table_list->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } if ((table= delayed_get_table(thd,table_list)) && !thd->is_fatal_error) @@ -200,7 +200,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, #endif /* EMBEDDED_LIBRARY */ res= open_and_lock_tables(thd, table_list); if (res || thd->is_fatal_error) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); table= table_list->table; thd->proc_info="init"; @@ -298,6 +298,15 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, info.records++; continue; } + /* + Field::store methods can't send errors + + TODO: set thd->abort_on_warning if values_list.elements == 1 + and check that all items return warning in case of problem with + storing field. + */ + if (!thd->net.report_error) + my_error(ER_UNKNOWN_ERROR, MYF(0)); error=1; break; } @@ -315,6 +324,9 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, info.records++; continue; } + /* Field::store methods can't send errors */ + if (!thd->net.report_error) + my_error(ER_UNKNOWN_ERROR, MYF(0)); error=1; break; } @@ -465,7 +477,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, free_underlaid_joins(thd, &thd->lex->select_lex); table->insert_values=0; thd->abort_on_warning= 0; - DBUG_RETURN(0); + DBUG_RETURN(FALSE); abort: #ifndef EMBEDDED_LIBRARY @@ -475,7 +487,7 @@ abort: free_underlaid_joins(thd, &thd->lex->select_lex); table->insert_values=0; thd->abort_on_warning= 0; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } @@ -609,11 +621,11 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, table_list Global/local table list RETURN VALUE - 0 OK - -1 error (message is not sent to user) + FALSE OK + TRUE error */ -int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, +bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, List &fields, List_item *values, List &update_fields, List &update_values, enum_duplicates duplic) @@ -621,7 +633,7 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, bool insert_into_view= (table_list->view != 0); /* TODO: use this condition for 'WITH CHECK OPTION' */ Item *unused_conds= 0; - int res; + bool res; DBUG_ENTER("mysql_prepare_insert"); if (mysql_prepare_insert_check_table(thd, table_list, fields, &unused_conds)) @@ -636,15 +648,15 @@ int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, thd->lex->select_lex.no_wrap_view_item= 0, res) || setup_fields(thd, 0, table_list, update_values, 0, 0, 0)))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if (unique_table(table_list, table_list->next_independent())) { my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } thd->lex->select_lex.first_execution= 0; - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -737,7 +749,12 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) store_record(table,insert_values); restore_record(table,record[1]); if (fill_record(*info->update_fields, *info->update_values, 0)) + { + /* Field::store methods can't send errors */ + if (!thd->net.report_error) + my_error(ER_UNKNOWN_ERROR, MYF(0)); goto err; + } /* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */ if (info->view && @@ -1018,7 +1035,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) delete tmp; thd->fatal_error(); pthread_mutex_unlock(&LOCK_delayed_create); - net_printf(thd,ER_CANT_CREATE_THREAD,error); + my_error(ER_CANT_CREATE_THREAD, MYF(0), error); DBUG_RETURN(0); } @@ -1648,11 +1665,11 @@ bool delayed_insert::handle_inserts(void) thd thread handler RETURN - 0 OK - -1 Error + FALSE OK + TRUE Error */ -int mysql_insert_select_prepare(THD *thd) +bool mysql_insert_select_prepare(THD *thd) { LEX *lex= thd->lex; DBUG_ENTER("mysql_insert_select_prepare"); @@ -1664,8 +1681,8 @@ int mysql_insert_select_prepare(THD *thd) if (mysql_prepare_insert_check_table(thd, lex->query_tables, lex->field_list, &lex->select_lex.where)) - DBUG_RETURN(-1); - DBUG_RETURN(0); + DBUG_RETURN(TRUE); + DBUG_RETURN(FALSE); } @@ -1768,8 +1785,7 @@ void select_insert::send_error(uint errcode,const char *err) { DBUG_ENTER("select_insert::send_error"); - /* TODO error should be sent at the query processing end */ - ::send_error(thd,errcode,err); + my_message(errcode, err, MYF(0)); if (!table) { @@ -1845,8 +1861,6 @@ bool select_insert::send_eof() if (error) { table->file->print_error(error,MYF(0)); - //TODO error should be sent at the query processing end - ::send_error(thd); DBUG_RETURN(1); } char buff[160]; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 72d28aa4526..8536bcb5c3e 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -328,8 +328,8 @@ protected: TABLE *table; /* temporary table using for appending UNION results */ select_result *result; - int res; ulong found_rows_for_union; + bool res; bool prepared, // prepare phase already performed for UNION (unit) optimized, // optimize phase already performed for UNION (unit) executed, // already executed @@ -388,9 +388,9 @@ public: void exclude_tree(); /* UNION methods */ - int prepare(THD *thd, select_result *result, ulong additional_options); - int exec(); - int cleanup(); + bool prepare(THD *thd, select_result *result, ulong additional_options); + bool exec(); + bool cleanup(); inline void unclean() { cleaned= 0; } void reinit_exec_mechanism(); @@ -398,7 +398,7 @@ public: void print(String *str); ulong init_prepare_fake_select_lex(THD *thd); - int change_result(select_subselect *result, select_subselect *old_result); + bool change_result(select_subselect *result, select_subselect *old_result); void set_limit(st_select_lex *values, st_select_lex *sl); friend void mysql_init_query(THD *thd, uchar *buf, uint length, bool lexonly); diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 28de2b9d116..353a3b2c83c 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -78,7 +78,7 @@ static int read_sep_field(THD *thd,COPY_INFO &info,TABLE *table, List &fields, READ_INFO &read_info, String &enclosed, ulong skip_lines); -int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, +bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, List &fields, enum enum_duplicates handle_duplicates, bool read_file_from_client,thr_lock_type lock_type) { @@ -112,16 +112,16 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS), MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } table_list->lock_type= lock_type; - if ((res= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(res); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); /* TODO: add key check when we will support VIEWs in LOAD */ if (!table_list->updatable) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } table= table_list->table; transactional_table= table->file->has_transactions(); @@ -140,14 +140,14 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, Item *unused_conds= 0; if (setup_tables(thd, table_list, &unused_conds) || setup_fields(thd, 0, table_list, fields, 1, 0, 0)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if (thd->dupp_field) { my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (check_that_all_fields_are_given_values(thd, table)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } uint tot_length=0; @@ -173,7 +173,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { my_message(ER_BLOBS_AND_NO_TERMINATED,ER(ER_BLOBS_AND_NO_TERMINATED), MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* We can't give an error in the middle when using LOCAL files */ @@ -206,7 +206,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, #if !defined(__WIN__) && !defined(OS2) && ! defined(__NETWARE__) MY_STAT stat_info; if (!my_stat(name,&stat_info,MYF(MY_WME))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); // if we are not in slave thread, the file must be: if (!thd->slave_thread && @@ -218,14 +218,14 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, (stat_info.st_mode & S_IFIFO) == S_IFIFO))) { my_error(ER_TEXTFILE_NOT_READABLE,MYF(0),name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if ((stat_info.st_mode & S_IFIFO) == S_IFIFO) is_fifo = 1; #endif } if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } COPY_INFO info; @@ -240,7 +240,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { if (file >= 0) my_close(file,MYF(0)); // no files in net reading - DBUG_RETURN(-1); // Can't allocate buffers + DBUG_RETURN(TRUE); // Can't allocate buffers } #ifndef EMBEDDED_LIBRARY diff --git a/sql/sql_map.cc b/sql/sql_map.cc index e7e24f957c6..c6637474908 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -47,13 +47,12 @@ mapped_files::mapped_files(const my_string filename,byte *magic,uint magic_lengt 0L))) { error=errno; - my_printf_error(0,"Can't map file: %s, errno: %d",MYF(0), - (my_string) name,error); + my_error(ER_NO_FILE_MAPPING,MYF(0), (my_string) name, error); } } if (map && memcmp(map,magic,magic_length)) { - my_printf_error(0,"Wrong magic in %s",MYF(0),name); + my_error(ER_WRONG_MAGIC, MYF(0), name); VOID(munmap(map,size)); map=0; } @@ -112,8 +111,7 @@ mapped_files *map_file(const my_string name,byte *magic,uint magic_length) { map->use_count++; if (!map->map) - my_printf_error(0,"Can't map file: %s, error: %d",MYF(0),path, - map->error); + my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error); } VOID(pthread_mutex_unlock(&LOCK_mapped_file)); return map; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f93aaf09933..8817a29a705 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1191,7 +1191,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd) if (!db || check_db_name(db)) { - net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); goto err; } if (lower_case_table_names) @@ -1370,8 +1370,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, db= thd->alloc(db_len + tbl_len + 2); tbl_name= strmake(db, packet + 1, db_len)+1; strmake(tbl_name, packet + db_len + 2, tbl_len); - if (mysql_table_dump(thd, db, tbl_name, -1)) - send_error(thd); // dump to NET + mysql_table_dump(thd, db, tbl_name, -1); break; } case COM_CHANGE_USER: @@ -1396,7 +1395,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* Small check for incoming packet */ if ((uint) ((uchar*) db - net->read_pos) > packet_length) { - send_error(thd, ER_UNKNOWN_COM_ERROR); + my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); break; } #endif @@ -1418,7 +1417,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (!(thd->user= my_strdup(user, MYF(0)))) { thd->user= save_user; - send_error(thd, ER_OUT_OF_RESOURCES); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); break; } @@ -1430,7 +1429,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { /* authentication failure, we shall restore old user */ if (res > 0) - send_error(thd, ER_UNKNOWN_COM_ERROR); + my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); x_free(thd->user); thd->user= save_user; thd->priv_user= save_priv_user; @@ -1538,7 +1537,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_FIELD_LIST: // This isn't actually needed #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ break; #else { @@ -1551,7 +1550,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, bzero((char*) &table_list,sizeof(table_list)); if (!(table_list.db=thd->db)) { - send_error(thd,ER_NO_DB_ERROR); + my_error(ER_NO_DB_ERROR, MYF(0)); break; } pend= strend(packet); @@ -1604,7 +1603,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, // null test to handle EOM if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); break; } if (check_access(thd,CREATE_ACL,db,0,1,0)) @@ -1621,14 +1620,14 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* null test to handle EOM */ if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); break; } if (check_access(thd,DROP_ACL,db,0,1,0)) break; if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); break; } mysql_log.write(thd,command,db); @@ -1670,9 +1669,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (check_global_access(thd,RELOAD_ACL)) break; mysql_log.write(thd,command,NullS); - if (reload_acl_and_cache(thd, options, (TABLE_LIST*) 0, NULL)) - send_error(thd, 0); - else + if (!reload_acl_and_cache(thd, options, (TABLE_LIST*) 0, NULL)) send_ok(thd); break; } @@ -1696,7 +1693,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, else if (level != SHUTDOWN_WAIT_ALL_BUFFERS) { my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level"); - send_error(thd); break; } DBUG_PRINT("quit",("Got shutdown command for level %u", level)); @@ -1780,7 +1776,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, send_eof(thd); break; default: - send_error(thd, ER_UNKNOWN_COM_ERROR); + my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); break; } break; @@ -1799,7 +1795,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_DELAYED_INSERT: case COM_END: default: - send_error(thd, ER_UNKNOWN_COM_ERROR); + my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); break; } if (thd->lock || thd->open_tables || thd->derived_tables) @@ -1808,8 +1804,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd, close_thread_tables(thd); /* Free tables */ } - if (thd->is_fatal_error) - send_error(thd,0); // End of memory ? + /* report error issued during command execution */ + if (thd->killed_errno() && !thd->net.report_error) + thd->send_kill_message(); + if (thd->is_fatal_error || thd->net.report_error) + send_error(thd); time_t start_of_query=thd->start_time; thd->end_time(); // Set start time @@ -1854,8 +1853,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, query_length RETURN VALUES - 0 ok - 1 error; In this case thd->fatal_error is set + FALSE ok + TRUE error; In this case thd->fatal_error is set */ bool alloc_query(THD *thd, char *packet, ulong packet_length) @@ -1880,7 +1879,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) packet_length, thd->db_length+ 1 + QUERY_CACHE_FLAGS_SIZE))) - return 1; + return TRUE; thd->query[packet_length]=0; thd->query_length= packet_length; @@ -1890,7 +1889,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) if (!(specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),QUERY_PRIOR); - return 0; + return FALSE; } /**************************************************************************** @@ -1898,10 +1897,10 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) ** Execute command saved in thd and current_lex->sql_command ****************************************************************************/ -int +bool mysql_execute_command(THD *thd) { - int res= 0; + bool res= FALSE; LEX *lex= thd->lex; /* first table of first SELECT_LEX */ TABLE_LIST *first_table= (TABLE_LIST*) lex->select_lex.table_list.first; @@ -1982,7 +1981,6 @@ mysql_execute_command(THD *thd) if ((tmp= my_tz_get_table_list(thd, &lex->query_tables_last)) == &fake_time_zone_tables_list) { - send_error(thd, 0); DBUG_RETURN(-1); } lex->time_zone_tables_used= tmp; @@ -1998,7 +1996,7 @@ mysql_execute_command(THD *thd) !(thd->slave_thread || (thd->master_access & SUPER_ACL)) && (uc_update_queries[lex->sql_command] > 0)) { - net_printf(thd, ER_OPTION_PREVENTS_STATEMENT, "--read-only"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); DBUG_RETURN(-1); } @@ -2027,20 +2025,14 @@ mysql_execute_command(THD *thd) lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL, any_db, 0, 0, 0); if (res) - { - res=0; - break; // Error message is given - } + goto error; if (!(res= open_and_lock_tables(thd, all_tables))) { if (lex->describe) { if (!(result= new select_send())) - { - send_error(thd, ER_OUT_OF_RESOURCES); goto error; - } else thd->send_explain_fields(result); res= mysql_explain_union(thd, &thd->lex->unit, result); @@ -2060,10 +2052,7 @@ mysql_execute_command(THD *thd) else { if (!result && !(result= new select_send())) - { - res= -1; - break; - } + goto error; query_cache_store_query(thd, all_tables); res= handle_select(thd, lex, result); if (result != lex->result) @@ -2083,6 +2072,7 @@ mysql_execute_command(THD *thd) CHARSET_INFO *to_cs= thd->variables.collation_connection; bool need_conversion; user_var_entry *entry; + String *pstr= &str; uint32 unused; /* Convert @var contents to string in connection character set. Although @@ -2098,26 +2088,37 @@ mysql_execute_command(THD *thd) String *pstr; my_bool is_var_null; pstr= entry->val_str(&is_var_null, &str, NOT_FIXED_DEC); + /* + NULL value of variable checked early as entry->value so here + we can't get NULL in normal conditions + */ DBUG_ASSERT(!is_var_null); if (!pstr) - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_ASSERT(pstr == &str); + goto error; } else + { + /* + variable absent or equal to NULL, so we need to set variable to + something reasonable to get readable error message during parsing + */ str.set("NULL", 4, &my_charset_latin1); - need_conversion= - String::needs_conversion(str.length(), str.charset(), to_cs, &unused); + } - query_len= need_conversion? (str.length() * to_cs->mbmaxlen) : - str.length(); + need_conversion= + String::needs_conversion(pstr->length(), pstr->charset(), + to_cs, &unused); + + query_len= need_conversion? (pstr->length() * to_cs->mbmaxlen) : + pstr->length(); if (!(query_str= alloc_root(&thd->mem_root, query_len+1))) - send_error(thd, ER_OUT_OF_RESOURCES); + goto error; if (need_conversion) - query_len= copy_and_convert(query_str, query_len, to_cs, str.ptr(), - str.length(), str.charset()); + query_len= copy_and_convert(query_str, query_len, to_cs, pstr->ptr(), + pstr->length(), pstr->charset()); else - memcpy(query_str, str.ptr(), str.length()); + memcpy(query_str, pstr->ptr(), pstr->length()); query_str[query_len]= 0; } else @@ -2130,8 +2131,8 @@ mysql_execute_command(THD *thd) query_len, query_str)); } thd->command= COM_PREPARE; - if (!mysql_stmt_prepare(thd, query_str, query_len + 1, - &lex->prepared_stmt_name)) + if (!(res= mysql_stmt_prepare(thd, query_str, query_len + 1, + &lex->prepared_stmt_name))) send_ok(thd, 0L, 0L, "Statement prepared"); break; } @@ -2157,22 +2158,20 @@ mysql_execute_command(THD *thd) } else { - res= -1; my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), lex->prepared_stmt_name.length, lex->prepared_stmt_name.str, "DEALLOCATE PREPARE"); + goto error; } break; } case SQLCOM_DO: if (all_tables && - ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || - (res= open_and_lock_tables(thd, all_tables)))) - break; + (check_table_access(thd, SELECT_ACL, all_tables, 0) || + open_and_lock_tables(thd, all_tables))) + goto error; res= mysql_do(thd, *lex->insert_list); - if (thd->net.report_error) - res= -1; break; case SQLCOM_EMPTY_QUERY: @@ -2222,12 +2221,12 @@ mysql_execute_command(THD *thd) goto error; /* This query don't work now. See comment in repl_failsafe.cc */ #ifndef WORKING_NEW_MASTER - net_printf(thd, ER_NOT_SUPPORTED_YET, "SHOW NEW MASTER"); - res= 1; + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "SHOW NEW MASTER"); + goto error; #else res = show_new_master(thd); -#endif break; +#endif } #ifdef HAVE_REPLICATION @@ -2323,7 +2322,7 @@ mysql_execute_command(THD *thd) if (check_global_access(thd, SUPER_ACL)) goto error; if (end_active_trans(thd)) - res= -1; + goto error; else res = load_master_data(thd); break; @@ -2354,7 +2353,7 @@ mysql_execute_command(THD *thd) } if (strlen(first_table->real_name) > NAME_LEN) { - net_printf(thd, ER_WRONG_TABLE_NAME, first_table->real_name); + my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->real_name); break; } pthread_mutex_lock(&LOCK_active_mi); @@ -2381,7 +2380,7 @@ mysql_execute_command(THD *thd) TABLE_LIST *select_tables= lex->query_tables; if ((res= create_table_precheck(thd, select_tables, create_table))) - goto unsent_create_error; + goto create_error; #ifndef HAVE_READLINK lex->create_info.data_file_name=lex->create_info.index_file_name=0; @@ -2391,10 +2390,7 @@ mysql_execute_command(THD *thd) create_table->real_name) || append_file_to_dir(thd, &lex->create_info.index_file_name, create_table->real_name)) - { - res=-1; - goto unsent_create_error; - } + goto create_error; #endif /* If we are using SET CHARSET without DEFAULT, add an implicit @@ -2428,7 +2424,7 @@ mysql_execute_command(THD *thd) if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && unique_table(create_table, select_tables)) { - net_printf(thd, ER_UPDATE_TABLE_USED, create_table->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->real_name); goto create_error; } /* If we create merge table, we have to test tables in merge, too */ @@ -2441,7 +2437,7 @@ mysql_execute_command(THD *thd) { if (unique_table(tab, select_tables)) { - net_printf(thd, ER_UPDATE_TABLE_USED, tab->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->real_name); goto create_error; } } @@ -2488,11 +2484,9 @@ mysql_execute_command(THD *thd) break; create_error: - res= 1; //error reported -unsent_create_error: /* put tables back for PS rexecuting */ lex->link_first_table_back(create_table, link_to_local); - break; + goto error; } case SQLCOM_CREATE_INDEX: DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -2500,7 +2494,7 @@ unsent_create_error: goto error; /* purecov: inspected */ thd->slow_command=TRUE; if (end_active_trans(thd)) - res= -1; + goto error; else res = mysql_create_index(thd, first_table, lex->key_list); break; @@ -2529,7 +2523,7 @@ unsent_create_error: */ if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); goto error; } { @@ -2543,16 +2537,15 @@ unsent_create_error: case SQLCOM_ALTER_TABLE: DBUG_ASSERT(first_table == all_tables && first_table != 0); #if defined(DONT_ALLOW_SHOW_COMMANDS) - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { ulong priv=0; if (lex->name && (!lex->name[0] || strlen(lex->name) > NAME_LEN)) { - net_printf(thd, ER_WRONG_TABLE_NAME, lex->name); - res=0; - break; + my_error(ER_WRONG_TABLE_NAME, MYF(0), lex->name); + goto error; } if (!select_lex->db) select_lex->db= first_table->db; @@ -2583,7 +2576,7 @@ unsent_create_error: lex->create_info.data_file_name=lex->create_info.index_file_name=0; /* ALTER TABLE ends previous transaction */ if (end_active_trans(thd)) - res= -1; + goto error; else { thd->slow_command=TRUE; @@ -2628,16 +2621,14 @@ unsent_create_error: } } query_cache_invalidate3(thd, first_table, 0); - if (end_active_trans(thd)) - res= -1; - else if (mysql_rename_tables(thd, first_table)) - res= -1; + if (end_active_trans(thd) || mysql_rename_tables(thd, first_table)) + goto error; break; } #ifndef EMBEDDED_LIBRARY case SQLCOM_SHOW_BINLOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { @@ -2651,7 +2642,7 @@ unsent_create_error: case SQLCOM_SHOW_CREATE: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { @@ -2754,8 +2745,6 @@ unsent_create_error: (ORDER *) select_lex->order_list.first, select_lex->select_limit, lex->duplicates); - if (thd->net.report_error) - res= -1; break; case SQLCOM_UPDATE_MULTI: { @@ -2780,8 +2769,6 @@ unsent_create_error: res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values, select_lex->item_list, lex->value_list, (update ? DUP_UPDATE : lex->duplicates)); - if (thd->net.report_error) - res= -1; if (first_table->view && !first_table->contain_auto_increment) thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it break; @@ -2834,11 +2821,9 @@ unsent_create_error: lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE; delete result; } - if (thd->net.report_error) - res= -1; } else - res= -1; + res= TRUE; if (first_table->view && !first_table->contain_auto_increment) thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it @@ -2855,7 +2840,7 @@ unsent_create_error: */ if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION,NullS); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); goto error; } @@ -2869,8 +2854,6 @@ unsent_create_error: res = mysql_delete(thd, all_tables, select_lex->where, &select_lex->order_list, select_lex->select_limit, select_lex->options); - if (thd->net.report_error) - res= -1; break; } case SQLCOM_DELETE_MULTI: @@ -2888,14 +2871,11 @@ unsent_create_error: if (select_lex->item_list.elements != 0) select_lex->item_list.empty(); if (add_item_to_list(thd, new Item_null())) - { - res= -1; - break; - } + goto error; thd->proc_info="init"; - if ((res= open_and_lock_tables(thd, all_tables))) - break; + if (open_and_lock_tables(thd, all_tables)) + goto error; if ((res= mysql_multi_delete_prepare(thd))) break; @@ -2913,12 +2893,10 @@ unsent_create_error: select_lex->options | thd->options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK, result, unit, select_lex); - if (thd->net.report_error) - res= -1; delete result; } else - res= -1; // Error is not sent + res= TRUE; close_thread_tables(thd); break; } @@ -2930,10 +2908,7 @@ unsent_create_error: if (check_table_access(thd, DROP_ACL, all_tables, 0)) goto error; /* purecov: inspected */ if (end_active_trans(thd)) - { - res= -1; - break; - } + goto error; } else { @@ -2957,13 +2932,13 @@ unsent_create_error: if (check_one_table_access(thd, INDEX_ACL, all_tables)) goto error; /* purecov: inspected */ if (end_active_trans(thd)) - res= -1; + goto error; else res = mysql_drop_index(thd, first_table, &lex->alter_info); break; case SQLCOM_SHOW_DATABASES: #if defined(DONT_ALLOW_SHOW_COMMANDS) - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else if ((specialflag & SPECIAL_SKIP_SHOW_DB) && @@ -3009,7 +2984,7 @@ unsent_create_error: break; case SQLCOM_SHOW_LOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { @@ -3022,30 +2997,30 @@ unsent_create_error: case SQLCOM_SHOW_TABLES: /* FALL THROUGH */ #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { char *db=select_lex->db ? select_lex->db : thd->db; if (!db) { - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: inspected */ goto error; /* purecov: inspected */ } remove_escape(db); // Fix escaped '_' if (check_db_name(db)) { - net_printf(thd,ER_WRONG_DB_NAME, db); + my_error(ER_WRONG_DB_NAME, MYF(0), db); goto error; } if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) goto error; /* purecov: inspected */ if (!thd->col_access && check_grant_db(thd,db)) { - net_printf(thd, ER_DBACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - db); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + db); goto error; } /* grant is checked in mysqld_show_tables */ @@ -3071,7 +3046,7 @@ unsent_create_error: case SQLCOM_SHOW_FIELDS: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { @@ -3092,7 +3067,7 @@ unsent_create_error: case SQLCOM_SHOW_KEYS: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ goto error; #else { @@ -3128,7 +3103,7 @@ unsent_create_error: if (!(thd->client_capabilities & CLIENT_LOCAL_FILES) || ! opt_local_infile) { - send_error(thd,ER_NOT_ALLOWED_COMMAND); + my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); goto error; } if (check_one_table_access(thd, privilege, all_tables)) @@ -3143,15 +3118,13 @@ unsent_create_error: { List *lex_var_list= &lex->var_list; if (all_tables && - ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || - (res= open_and_lock_tables(thd, all_tables)))) - break; + (check_table_access(thd, SELECT_ACL, all_tables, 0) || + open_and_lock_tables(thd, all_tables))) + goto error; if (lex->one_shot_set && not_all_support_one_shot(lex_var_list)) { - my_printf_error(0, "The SET ONE_SHOT syntax is reserved for \ -purposes internal to the MySQL server", MYF(0)); - res= -1; - break; + my_error(ER_RESERVED_SYNTAX, MYF(0), "SET ONE_SHOT"); + goto error; } if (!(res= sql_set_variables(thd, lex_var_list))) { @@ -3162,8 +3135,6 @@ purposes internal to the MySQL server", MYF(0)); thd->one_shot_set|= lex->one_shot_set; send_ok(thd); } - if (thd->net.report_error) - res= -1; break; } @@ -3206,7 +3177,7 @@ purposes internal to the MySQL server", MYF(0)); char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - net_printf(thd,ER_WRONG_DB_NAME, lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3236,7 +3207,7 @@ purposes internal to the MySQL server", MYF(0)); char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - net_printf(thd, ER_WRONG_DB_NAME, lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3259,7 +3230,7 @@ purposes internal to the MySQL server", MYF(0)); break; if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); goto error; } res=mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : lex->name), @@ -3270,7 +3241,7 @@ purposes internal to the MySQL server", MYF(0)); { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - net_printf(thd, ER_WRONG_DB_NAME, lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3293,7 +3264,7 @@ purposes internal to the MySQL server", MYF(0)); break; if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); goto error; } res=mysql_alter_db(thd,lex->name,&lex->create_info); @@ -3303,14 +3274,14 @@ purposes internal to the MySQL server", MYF(0)); { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - net_printf(thd,ER_WRONG_DB_NAME, lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } if (check_access(thd,SELECT_ACL,lex->name,0,1,0)) break; if (thd->locked_tables || thd->active_transaction()) { - send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); goto error; } res=mysqld_show_create_db(thd,lex->name,&lex->create_info); @@ -3324,13 +3295,13 @@ purposes internal to the MySQL server", MYF(0)); #ifdef HAVE_DLOPEN if ((sph= sp_find_function(thd, lex->spname))) { - net_printf(thd, ER_UDF_EXISTS, lex->spname->m_name.str); + my_error(ER_UDF_EXISTS, MYF(0), lex->spname->m_name.str); goto error; } if (!(res = mysql_create_function(thd,&lex->udf))) send_ok(thd); #else - res= -1; + res= TRUE; #endif break; } @@ -3432,8 +3403,8 @@ purposes internal to the MySQL server", MYF(0)); { if (lex->columns.elements) { - send_error(thd,ER_ILLEGAL_GRANT_FOR_TABLE); - res=1; + my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); + goto error; } else res = mysql_grant(thd, select_lex->db, lex->users_list, lex->grant, @@ -3473,9 +3444,7 @@ purposes internal to the MySQL server", MYF(0)); binlog or not. */ bool write_to_binlog; - if (reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog)) - send_error(thd, 0); - else + if (!reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog)) { /* We WANT to write and we CAN write. @@ -3498,7 +3467,6 @@ purposes internal to the MySQL server", MYF(0)); break; #ifndef NO_EMBEDDED_ACCESS_CHECKS case SQLCOM_SHOW_GRANTS: - res=0; if ((thd->priv_user && !strcmp(thd->priv_user,lex->grant_user->user.str)) || !check_access(thd, SELECT_ACL, "mysql",0,1,0)) @@ -3542,9 +3510,7 @@ purposes internal to the MySQL server", MYF(0)); close_thread_tables(thd); // Free tables } if (end_active_trans(thd)) - { - res= -1; - } + goto error; else { thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | @@ -3567,7 +3533,7 @@ purposes internal to the MySQL server", MYF(0)); send_ok(thd); } else - res= -1; + goto error; break; } case SQLCOM_ROLLBACK: @@ -3589,7 +3555,7 @@ purposes internal to the MySQL server", MYF(0)); send_ok(thd); } else - res= -1; + res= TRUE; thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); break; case SQLCOM_ROLLBACK_TO_SAVEPOINT: @@ -3601,29 +3567,26 @@ purposes internal to the MySQL server", MYF(0)); send_ok(thd); } else - res= -1; + goto error; break; case SQLCOM_SAVEPOINT: if (!ha_savepoint(thd, lex->savepoint_name)) send_ok(thd); else - res= -1; + goto error; break; case SQLCOM_CREATE_PROCEDURE: case SQLCOM_CREATE_SPFUNCTION: { uint namelen; char *name; + int result; - if (!lex->sphead) - { - res= -1; // Shouldn't happen - break; - } + DBUG_ASSERT(lex->sphead); if (! lex->sphead->m_db.str) { - send_error(thd,ER_NO_DB_ERROR); + my_error(ER_NO_DB_ERROR, MYF(0)); delete lex->sphead; lex->sphead= 0; goto error; @@ -3637,7 +3600,7 @@ purposes internal to the MySQL server", MYF(0)); if (udf) { - net_printf(thd, ER_UDF_EXISTS, name); + my_error(ER_UDF_EXISTS, MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; @@ -3647,14 +3610,14 @@ purposes internal to the MySQL server", MYF(0)); if (lex->sphead->m_type == TYPE_ENUM_FUNCTION && !lex->sphead->m_has_return) { - net_printf(thd, ER_SP_NORETURN, name); + my_error(ER_SP_NORETURN, MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; } - res= lex->sphead->create(thd); - switch (res) { + res= (result= lex->sphead->create(thd)); + switch (result) { case SP_OK: send_ok(thd); lex->unit.cleanup(); @@ -3662,19 +3625,19 @@ purposes internal to the MySQL server", MYF(0)); lex->sphead= 0; break; case SP_WRITE_ROW_FAILED: - net_printf(thd, ER_SP_ALREADY_EXISTS, SP_TYPE_STRING(lex), name); + my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; case SP_NO_DB_ERROR: - net_printf(thd, ER_BAD_DB_ERROR, lex->sphead->m_db.str); + my_error(ER_BAD_DB_ERROR, MYF(0), lex->sphead->m_db.str); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; default: - net_printf(thd, ER_SP_STORE_FAILED, SP_TYPE_STRING(lex), name); + my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; @@ -3688,8 +3651,8 @@ purposes internal to the MySQL server", MYF(0)); if (!(sp= sp_find_procedure(thd, lex->spname))) { - net_printf(thd, ER_SP_DOES_NOT_EXIST, "PROCEDURE", - lex->spname->m_qname.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PROCEDURE", + lex->spname->m_qname.str); goto error; } else @@ -3703,11 +3666,9 @@ purposes internal to the MySQL server", MYF(0)); /* In case the arguments are subselects... */ if (all_tables && - ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || - (res= open_and_lock_tables(thd, all_tables)))) - { - break; - } + (check_table_access(thd, SELECT_ACL, all_tables, 0) || + open_and_lock_tables(thd, all_tables))) + goto error; #ifndef EMBEDDED_LIBRARY /* @@ -3721,7 +3682,7 @@ purposes internal to the MySQL server", MYF(0)); { if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) { - send_error(thd, ER_SP_BADSELECT); + my_error(ER_SP_BADSELECT, MYF(0)); #ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; #endif @@ -3754,7 +3715,7 @@ purposes internal to the MySQL server", MYF(0)); thd->server_status &= ~SERVER_MORE_RESULTS_EXISTS; } - if (res == 0) + if (!res) send_ok(thd, (ulong) (thd->row_count_func < 0 ? 0 : thd->row_count_func)); else goto error; // Substatement should already have sent error @@ -3764,32 +3725,33 @@ purposes internal to the MySQL server", MYF(0)); case SQLCOM_ALTER_PROCEDURE: case SQLCOM_ALTER_FUNCTION: { - res= -1; + int result; uint newname_len= 0; if (lex->name) newname_len= strlen(lex->name); if (newname_len > NAME_LEN) { - net_printf(thd, ER_TOO_LONG_IDENT, lex->name); - goto error; + my_error(ER_TOO_LONG_IDENT, MYF(0), lex->name); + goto error; } if (lex->sql_command == SQLCOM_ALTER_PROCEDURE) - res= sp_update_procedure(thd, lex->spname, - lex->name, newname_len, &lex->sp_chistics); + result= sp_update_procedure(thd, lex->spname, + lex->name, newname_len, &lex->sp_chistics); else - res= sp_update_function(thd, lex->spname, - lex->name, newname_len, &lex->sp_chistics); - switch (res) + result= sp_update_function(thd, lex->spname, + lex->name, newname_len, &lex->sp_chistics); + res= result; + switch (result) { case SP_OK: send_ok(thd); break; case SP_KEY_NOT_FOUND: - net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex), + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; default: - net_printf(thd, ER_SP_CANT_ALTER, SP_COM_STRING(lex), + my_error(ER_SP_CANT_ALTER, MYF(0), SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; } @@ -3798,13 +3760,14 @@ purposes internal to the MySQL server", MYF(0)); case SQLCOM_DROP_PROCEDURE: case SQLCOM_DROP_FUNCTION: { + int result; if (lex->sql_command == SQLCOM_DROP_PROCEDURE) - res= sp_drop_procedure(thd, lex->spname); + result= sp_drop_procedure(thd, lex->spname); else { - res= sp_drop_function(thd, lex->spname); + result= sp_drop_function(thd, lex->spname); #ifdef HAVE_DLOPEN - if (res == SP_KEY_NOT_FOUND) + if (result == SP_KEY_NOT_FOUND) { udf_func *udf = find_udf(lex->spname->m_name.str, lex->spname->m_name.length); @@ -3812,7 +3775,7 @@ purposes internal to the MySQL server", MYF(0)); { if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 0)) goto error; - if (!(res = mysql_drop_function(thd,&lex->spname->m_name))) + if (!(result = mysql_drop_function(thd,&lex->spname->m_name))) { send_ok(thd); break; @@ -3821,7 +3784,8 @@ purposes internal to the MySQL server", MYF(0)); } #endif } - switch (res) + res= result; + switch (result) { case SP_OK: send_ok(thd); @@ -3832,34 +3796,31 @@ purposes internal to the MySQL server", MYF(0)); push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), SP_COM_STRING(lex), lex->spname->m_name.str); - res= 0; + res= FALSE; send_ok(thd); break; } - net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), SP_COM_STRING(lex), + lex->spname->m_qname.str); goto error; default: - net_printf(thd, ER_SP_DROP_FAILED, SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_error(ER_SP_DROP_FAILED, MYF(0), SP_COM_STRING(lex), + lex->spname->m_qname.str); goto error; } break; } case SQLCOM_SHOW_CREATE_PROC: { - res= -1; if (lex->spname->m_name.length > NAME_LEN) { - net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str); + my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); goto error; } - res= sp_show_create_procedure(thd, lex->spname); - if (res != SP_OK) + if (sp_show_create_procedure(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - net_printf(thd, ER_SP_DOES_NOT_EXIST, - SP_COM_STRING(lex), lex->spname->m_name.str); - res= 0; + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } break; @@ -3868,18 +3829,15 @@ purposes internal to the MySQL server", MYF(0)); { if (lex->spname->m_name.length > NAME_LEN) { - net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str); + my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); goto error; } - res= sp_show_create_function(thd, lex->spname); - if (res != SP_OK) + if (sp_show_create_function(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - net_printf(thd, ER_SP_DOES_NOT_EXIST, - SP_COM_STRING(lex), lex->spname->m_name.str); - res= 0; + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } - res= 0; break; } case SQLCOM_SHOW_STATUS_PROC: @@ -3901,13 +3859,9 @@ purposes internal to the MySQL server", MYF(0)); } case SQLCOM_DROP_VIEW: { - if (check_table_access(thd, DROP_ACL, all_tables, 0)) - goto error; - if (end_active_trans(thd)) - { - res= -1; - break; - } + if (check_table_access(thd, DROP_ACL, all_tables, 0) || + end_active_trans(thd)) + goto error; res= mysql_drop_view(thd, first_table, thd->lex->drop_mode); break; } @@ -3975,17 +3929,11 @@ purposes internal to the MySQL server", MYF(0)); thd->row_count_func= -1; } - /* - We end up here if res == 0 and send_ok() has been done, - or res != 0 and no send_error() has yet been done. - */ - if (res < 0) - send_error(thd,thd->killed_errno()); - DBUG_RETURN(res); + DBUG_RETURN(res || thd->net.report_error); error: /* We end up here if send_error() has already been done. */ - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } @@ -4064,7 +4012,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { DBUG_PRINT("error",("No database")); if (!no_errors) - send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */ + my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -4091,10 +4039,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { // We can never grant this DBUG_PRINT("error",("No possible access")); if (!no_errors) - net_printf(thd,ER_ACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - thd->password ? ER(ER_YES) : ER(ER_NO));/* purecov: tested */ + my_error(ER_ACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + thd->password ? ER(ER_YES) : ER(ER_NO));/* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -4120,10 +4068,10 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_PRINT("error",("Access denied")); if (!no_errors) - net_printf(thd,ER_DBACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - db ? db : thd->db ? thd->db : "unknown"); /* purecov: tested */ + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + db ? db : thd->db ? thd->db : "unknown"); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4157,8 +4105,7 @@ bool check_global_access(THD *thd, ulong want_access) if ((thd->master_access & want_access)) return 0; get_privilege_desc(command, sizeof(command), want_access); - net_printf(thd,ER_SPECIFIC_ACCESS_DENIED_ERROR, - command); + my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); return 1; #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4270,7 +4217,7 @@ static bool check_db_used(THD *thd,TABLE_LIST *tables) { if (!(tables->db=thd->db)) { - send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */ + my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: tested */ return TRUE; /* purecov: tested */ } } @@ -4449,7 +4396,7 @@ mysql_new_select(LEX *lex, bool move_down) { if (lex->current_select->order_list.first && !lex->current_select->braces) { - net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "ORDER BY"); + my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY"); return 1; } select_lex->include_neighbour(lex->current_select); @@ -4549,7 +4496,6 @@ void mysql_parse(THD *thd, char *inBuf, uint length) { if (thd->net.report_error) { - send_error(thd, 0, NullS); if (thd->lex->sphead) { if (lex != thd->lex) @@ -4638,7 +4584,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if (strlen(field_name) > NAME_LEN) { - net_printf(thd, ER_TOO_LONG_IDENT, field_name); /* purecov: inspected */ + my_error(ER_TOO_LONG_IDENT, MYF(0), field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } if (type_modifier & PRI_KEY_FLAG) @@ -4669,7 +4615,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC && type == FIELD_TYPE_TIMESTAMP)) { - net_printf(thd, ER_INVALID_DEFAULT, field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } else if (default_value->type() == Item::NULL_ITEM) @@ -4678,20 +4624,20 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG) { - net_printf(thd,ER_INVALID_DEFAULT,field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } else if (type_modifier & AUTO_INCREMENT_FLAG) { - net_printf(thd, ER_INVALID_DEFAULT, field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } if (on_update_value && type != FIELD_TYPE_TIMESTAMP) { - net_printf(thd, ER_INVALID_ON_UPDATE, field_name); + my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name); DBUG_RETURN(1); } @@ -4817,7 +4763,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res=default_value->val_str(&str); if (res->length()) { - net_printf(thd,ER_BLOB_CANT_HAVE_DEFAULT,field_name); /* purecov: inspected */ + my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), + field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->def=0; @@ -4837,7 +4784,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, uint tmp_length=new_field->length; if (tmp_length > PRECISION_FOR_DOUBLE) { - net_printf(thd,ER_WRONG_FIELD_SPEC,field_name); + my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); DBUG_RETURN(1); } else if (tmp_length > PRECISION_FOR_FLOAT) @@ -4923,7 +4870,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, { if (interval->count > sizeof(longlong)*8) { - net_printf(thd,ER_TOO_BIG_SET,field_name); /* purecov: inspected */ + my_error(ER_TOO_BIG_SET, MYF(0), field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->pack_length=(interval->count+7)/8; @@ -4953,7 +4900,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, ¬_used2, ¬_used3); if (thd->cuted_fields) { - net_printf(thd,ER_INVALID_DEFAULT,field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } @@ -4979,7 +4926,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res->strip_sp(); if (!find_type(interval, res->ptr(), res->length(), 0)) { - net_printf(thd,ER_INVALID_DEFAULT,field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } @@ -4993,14 +4940,14 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY)) { - net_printf(thd,ER_TOO_BIG_FIELDLENGTH,field_name, - MAX_FIELD_CHARLENGTH); /* purecov: inspected */ + my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), field_name, + MAX_FIELD_CHARLENGTH); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } type_modifier&= AUTO_INCREMENT_FLAG; if ((~allowed_type_modifier) & type_modifier) { - net_printf(thd,ER_WRONG_FIELD_SPEC,field_name); + my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); DBUG_RETURN(1); } if (!new_field->pack_length) @@ -5130,7 +5077,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (check_table_name(table->table.str,table->table.length) || table->db.str && check_db_name(table->db.str)) { - net_printf(thd, ER_WRONG_TABLE_NAME, table->table.str); + my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); DBUG_RETURN(0); } @@ -5138,7 +5085,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { if (table->sel) { - net_printf(thd,ER_DERIVED_MUST_HAVE_ALIAS); + my_error(ER_DERIVED_MUST_HAVE_ALIAS, MYF(0)); DBUG_RETURN(0); } if (!(alias_str=thd->memdup(alias_str,table->table.length+1))) @@ -5192,7 +5139,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && !strcmp(ptr->db, tables->db)) { - net_printf(thd,ER_NONUNIQ_TABLE,alias_str); /* purecov: tested */ + my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */ DBUG_RETURN(0); /* purecov: tested */ } } @@ -5688,7 +5635,7 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query) if (!error) send_ok(thd); else - net_printf(thd,error,id); + my_error(error, MYF(0), id); } /* Clear most status variables */ @@ -5769,7 +5716,7 @@ bool check_simple_select() char command[80]; strmake(command, thd->lex->yylval->symbol.str, min(thd->lex->yylval->symbol.length, sizeof(command)-1)); - net_printf(thd, ER_CANT_USE_OPTION_HERE, command); + my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command); return 1; } return 0; @@ -5857,7 +5804,7 @@ Item * all_any_subquery_creator(Item *left_expr, One should normally create all indexes with CREATE TABLE or ALTER TABLE. */ -int mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys) +bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys) { List fields; ALTER_INFO alter_info; @@ -5875,7 +5822,7 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys) } -int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) +bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) { List fields; List keys; @@ -5903,12 +5850,11 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) tables Global/local table list (have to be the same) RETURN VALUE - 0 OK - 1 Error (message is sent to user) - -1 Error (message is not sent to user) + FALSE OK + TRUE Error */ -int multi_update_precheck(THD *thd, TABLE_LIST *tables) +bool multi_update_precheck(THD *thd, TABLE_LIST *tables) { const char *msg= 0; TABLE_LIST *table; @@ -5919,7 +5865,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) if (select_lex->item_list.elements != lex->value_list.elements) { my_error(ER_WRONG_VALUE_COUNT, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* Ensure that we have UPDATE or SELECT privilege for each table @@ -5933,7 +5879,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) (check_access(thd, SELECT_ACL, table->db, &table->grant.privilege, 0, 0) || grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0))) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); table->table_in_first_from_clause= 1; } @@ -5949,7 +5895,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) if (check_access(thd, SELECT_ACL, table->db, &table->grant.privilege, 0, 0) || grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } } @@ -5962,9 +5908,9 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) if (msg) { my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } /* @@ -5977,11 +5923,11 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) table_count Pointer to table counter RETURN VALUE - 0 OK - 1 error (message is sent to user) - -1 error (message is not sent to user) + FALSE OK + TRUE error */ -int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) + +bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) { SELECT_LEX *select_lex= &thd->lex->select_lex; TABLE_LIST *aux_tables= @@ -5996,11 +5942,11 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) if (check_db_used(thd, tables) || check_db_used(thd,aux_tables) || check_table_access(thd,SELECT_ACL, tables,0) || check_table_access(thd,DELETE_ACL, aux_tables,0)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); if ((thd->options & OPTION_SAFE_UPDATES) && !select_lex->where) { my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } for (target_tbl= aux_tables; target_tbl; target_tbl= target_tbl->next_local) { @@ -6018,12 +5964,12 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) { my_error(ER_UNKNOWN_TABLE, MYF(0), target_tbl->real_name, "MULTI DELETE"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } walk->lock_type= target_tbl->lock_type; target_tbl->correspondent_table= walk; // Remember corresponding table } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -6036,12 +5982,11 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) tables Global table list RETURN VALUE - 0 OK - 1 Error (message is sent to user) - -1 Error (message is not sent to user) + FALSE OK + TRUE Error */ -int insert_select_precheck(THD *thd, TABLE_LIST *tables) +bool insert_select_precheck(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("insert_select_precheck"); /* @@ -6050,7 +5995,7 @@ int insert_select_precheck(THD *thd, TABLE_LIST *tables) */ ulong privilege= (thd->lex->duplicates == DUP_REPLACE ? INSERT_ACL | DELETE_ACL : INSERT_ACL); - DBUG_RETURN(check_one_table_access(thd, privilege, tables) ? 1 : 0); + DBUG_RETURN(check_one_table_access(thd, privilege, tables)); } @@ -6063,21 +6008,20 @@ int insert_select_precheck(THD *thd, TABLE_LIST *tables) tables Global table list RETURN VALUE - 0 OK - 1 Error (message is sent to user) - -1 Error (message is not sent to user) + FALSE OK + TRUE Error */ -int update_precheck(THD *thd, TABLE_LIST *tables) +bool update_precheck(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("update_precheck"); if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements) { my_error(ER_WRONG_VALUE_COUNT, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } - DBUG_RETURN((check_db_used(thd, tables) || - check_one_table_access(thd, UPDATE_ACL, tables)) ? 1 : 0); + DBUG_RETURN(check_db_used(thd, tables) || + check_one_table_access(thd, UPDATE_ACL, tables)); } @@ -6090,19 +6034,18 @@ int update_precheck(THD *thd, TABLE_LIST *tables) tables Global table list RETURN VALUE - 0 OK - 1 error (message is sent to user) - -1 error (message is not sent to user) + FALSE OK + TRUE error */ -int delete_precheck(THD *thd, TABLE_LIST *tables) +bool delete_precheck(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("delete_precheck"); if (check_one_table_access(thd, DELETE_ACL, tables)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); /* Set privilege for the WHERE clause */ tables->grant.want_privilege=(SELECT_ACL & ~tables->grant.privilege); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -6115,12 +6058,11 @@ int delete_precheck(THD *thd, TABLE_LIST *tables) tables Global table list RETURN VALUE - 0 OK - 1 error (message is sent to user) - -1 error (message is not sent to user) + FALSE OK + TRUE error */ -int insert_precheck(THD *thd, TABLE_LIST *tables, bool update) +bool insert_precheck(THD *thd, TABLE_LIST *tables, bool update) { LEX *lex= thd->lex; DBUG_ENTER("insert_precheck"); @@ -6129,14 +6071,14 @@ int insert_precheck(THD *thd, TABLE_LIST *tables, bool update) INSERT_ACL | DELETE_ACL : INSERT_ACL | update); if (check_one_table_access(thd, privilege, tables)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); if (lex->select_lex.item_list.elements != lex->value_list.elements) { my_error(ER_WRONG_VALUE_COUNT, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -6150,13 +6092,12 @@ int insert_precheck(THD *thd, TABLE_LIST *tables, bool update) create_table Table which will be created RETURN VALUE - 0 OK - 1 Error (message is sent to user) - -1 Error (message is not sent to user) + FALSE OK + TRUE Error */ -int create_table_precheck(THD *thd, TABLE_LIST *tables, - TABLE_LIST *create_table) +bool create_table_precheck(THD *thd, TABLE_LIST *tables, + TABLE_LIST *create_table) { LEX *lex= thd->lex; DBUG_ENTER("create_table_precheck"); @@ -6168,10 +6109,9 @@ int create_table_precheck(THD *thd, TABLE_LIST *tables, check_merge_table_access(thd, create_table->db, (TABLE_LIST *) lex->create_info.merge_list.first)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); DBUG_RETURN((grant_option && want_priv != CREATE_TMP_ACL && - check_grant(thd, want_priv, create_table, 0, UINT_MAX, 0)) ? - 1 : 0); + check_grant(thd, want_priv, create_table, 0, UINT_MAX, 0))); } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 982e00391ef..aa5da98f56f 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -122,16 +122,13 @@ inline bool is_param_null(const uchar *pos, ulong param_no) enum { STMT_QUERY_LOG_LENGTH= 8192 }; -enum enum_send_error { DONT_SEND_ERROR= 0, SEND_ERROR }; - /* Seek prepared statement in statement map by id: returns zero if statement was not found, pointer otherwise. */ static Prepared_statement * -find_prepared_statement(THD *thd, ulong id, const char *where, - enum enum_send_error se) +find_prepared_statement(THD *thd, ulong id, const char *where) { Statement *stmt= thd->stmt_map.find(id); @@ -139,8 +136,6 @@ find_prepared_statement(THD *thd, ulong id, const char *where, { char llbuf[22]; my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), 22, llstr(id, llbuf), where); - if (se == SEND_ERROR) - send_error(thd); return 0; } return (Prepared_statement *) stmt; @@ -180,7 +175,7 @@ static bool send_prep_stmt(Prepared_statement *stmt, thd->client_stmt_id= stmt->id; thd->client_param_count= stmt->param_count; - thd->net.last_errno= 0; + thd->clear_error(); return 0; } @@ -881,24 +876,23 @@ static bool insert_params_from_vars_with_log(Prepared_statement *stmt, tables global/local table list RETURN VALUE - 0 ok - 1 error, sent to the client - -1 error, not sent to client + FALSE OK + TRUE error */ -static int mysql_test_insert(Prepared_statement *stmt, - TABLE_LIST *table_list, - List &fields, - List &values_list, - List &update_fields, - List &update_values, - enum_duplicates duplic) +static bool mysql_test_insert(Prepared_statement *stmt, + TABLE_LIST *table_list, + List &fields, + List &values_list, + List &update_fields, + List &update_values, + enum_duplicates duplic) { THD *thd= stmt->thd; LEX *lex= stmt->lex; List_iterator_fast its(values_list); List_item *values; - int res; + bool res; my_bool update= (lex->value_list.elements ? UPDATE_ACL : 0); DBUG_ENTER("mysql_test_insert"); @@ -909,9 +903,9 @@ static int mysql_test_insert(Prepared_statement *stmt, open temporary memory pool for temporary data allocated by derived tables & preparation procedure */ - if ((res= open_and_lock_tables(thd, table_list))) + if (open_and_lock_tables(thd, table_list)) { - DBUG_RETURN(res); + DBUG_RETURN(TRUE); } if ((values= its++)) @@ -958,14 +952,13 @@ error: tables list of tables queries RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error */ -static int mysql_test_update(Prepared_statement *stmt, - TABLE_LIST *table_list) +static bool mysql_test_update(Prepared_statement *stmt, + TABLE_LIST *table_list) { - int res; + bool res; THD *thd= stmt->thd; SELECT_LEX *select= &stmt->lex->select_lex; DBUG_ENTER("mysql_test_update"); @@ -1010,28 +1003,27 @@ static int mysql_test_update(Prepared_statement *stmt, tables list of tables queries RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error */ static int mysql_test_delete(Prepared_statement *stmt, TABLE_LIST *table_list) { - int res; THD *thd= stmt->thd; LEX *lex= stmt->lex; DBUG_ENTER("mysql_test_delete"); - if ((res= delete_precheck(thd, table_list))) - DBUG_RETURN(res); + if (delete_precheck(thd, table_list)) + DBUG_RETURN(TRUE); - if (!(res=open_and_lock_tables(thd, table_list))) + if (!open_and_lock_tables(thd, table_list)) { - res= mysql_prepare_delete(thd, table_list, &lex->select_lex.where); + mysql_prepare_delete(thd, table_list, &lex->select_lex.where); lex->unit.cleanup(); + DBUG_RETURN(FALSE) } /* TODO: here we should send types of placeholders to the client. */ - DBUG_RETURN(res); + DBUG_RETURN(TRUE); } @@ -1046,9 +1038,8 @@ static int mysql_test_delete(Prepared_statement *stmt, tables list of tables queries RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error, sent to client */ static int mysql_test_select(Prepared_statement *stmt, @@ -1057,7 +1048,7 @@ static int mysql_test_select(Prepared_statement *stmt, THD *thd= stmt->thd; LEX *lex= stmt->lex; SELECT_LEX_UNIT *unit= &lex->unit; - int result; + bool result; DBUG_ENTER("mysql_test_select"); #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -1065,26 +1056,21 @@ static int mysql_test_select(Prepared_statement *stmt, if (tables) { if (check_table_access(thd, privilege, tables,0)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } else if (check_access(thd, privilege, any_db,0,0,0)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); #endif if ((result= open_and_lock_tables(thd, tables))) - { - result= 1; // Error sent - send_error(thd); goto err; - } - result= 1; + result= TRUE; thd->used_tables= 0; // Updated by setup_fields // JOIN::prepare calls if (unit->prepare(thd, 0, 0)) { - send_error(thd); goto err_prep; } if (!text_protocol) @@ -1106,7 +1092,7 @@ static int mysql_test_select(Prepared_statement *stmt, goto err_prep; } } - result= 0; // ok + result= FALSE; // ok err_prep: unit->cleanup(); @@ -1125,30 +1111,27 @@ err: values list of expressions RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error, sent to client */ -static int mysql_test_do_fields(Prepared_statement *stmt, +static bool mysql_test_do_fields(Prepared_statement *stmt, TABLE_LIST *tables, List *values) { DBUG_ENTER("mysql_test_do_fields"); THD *thd= stmt->thd; - int res= 0; - if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0))) - DBUG_RETURN(res); + bool res; + if (tables && check_table_access(thd, SELECT_ACL, tables, 0)) + DBUG_RETURN(TRUE); - if (tables && (res= open_and_lock_tables(thd, tables))) + if (tables && open_and_lock_tables(thd, tables)) { - DBUG_RETURN(res); + DBUG_RETURN(TRUE); } res= setup_fields(thd, 0, 0, *values, 0, 0, 0); stmt->lex->unit.cleanup(); - if (res) - DBUG_RETURN(-1); - DBUG_RETURN(0); + DBUG_RETURN(res); } @@ -1162,22 +1145,21 @@ static int mysql_test_do_fields(Prepared_statement *stmt, values list of expressions RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error */ -static int mysql_test_set_fields(Prepared_statement *stmt, - TABLE_LIST *tables, - List *var_list) +static bool mysql_test_set_fields(Prepared_statement *stmt, + TABLE_LIST *tables, + List *var_list) { DBUG_ENTER("mysql_test_set_fields"); List_iterator_fast it(*var_list); THD *thd= stmt->thd; set_var_base *var; - int res= 0; + bool res= 0; - if (tables && (res= check_table_access(thd, SELECT_ACL, tables, 0))) - DBUG_RETURN(res); + if (tables && check_table_access(thd, SELECT_ACL, tables, 0)) + DBUG_RETURN(TRUE); if (tables && (res= open_and_lock_tables(thd, tables))) goto error; @@ -1186,7 +1168,7 @@ static int mysql_test_set_fields(Prepared_statement *stmt, if (var->light_check(thd)) { stmt->lex->unit.cleanup(); - res= -1; + res= TRUE; goto error; } } @@ -1206,18 +1188,17 @@ error: specific_prepare - function of command specific prepare RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error */ -static int select_like_statement_test(Prepared_statement *stmt, - TABLE_LIST *tables, - int (*specific_prepare)(THD *thd)) +static bool select_like_statement_test(Prepared_statement *stmt, + TABLE_LIST *tables, + bool (*specific_prepare)(THD *thd)) { DBUG_ENTER("select_like_statement_test"); THD *thd= stmt->thd; LEX *lex= stmt->lex; - int res= 0; + bool res= 0; if (tables && (res= open_and_lock_tables(thd, tables))) goto end; @@ -1230,7 +1211,7 @@ static int select_like_statement_test(Prepared_statement *stmt, // JOIN::prepare calls if (lex->unit.prepare(thd, 0, 0)) { - res= thd->net.report_error ? -1 : 1; + res= TRUE; } end: lex->unit.cleanup(); @@ -1287,16 +1268,15 @@ static int mysql_test_create_table(Prepared_statement *stmt) tables list of tables queries RETURN VALUE - 0 success - 1 error, sent to client - -1 error, not sent to client + FALSE success + TRUE error */ -static int mysql_test_multiupdate(Prepared_statement *stmt, + +static bool mysql_test_multiupdate(Prepared_statement *stmt, TABLE_LIST *tables) { - int res; - if ((res= multi_update_precheck(stmt->thd, tables))) - return res; + if (multi_update_precheck(stmt->thd, tables)) + return TRUE; return select_like_statement_test(stmt, tables, &mysql_multi_update_prepare); } @@ -1477,8 +1457,6 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol) if (res == 0) DBUG_RETURN(text_protocol? 0 : send_prep_stmt(stmt, 0)); error: - if (res < 0) - send_error(thd,thd->killed_errno()); DBUG_RETURN(1); } @@ -1500,10 +1478,7 @@ static bool init_param_array(Prepared_statement *stmt) alloc_root(&stmt->thd->mem_root, sizeof(Item_param*) * stmt->param_count); if (!stmt->param_array) - { - send_error(stmt->thd, ER_OUT_OF_RESOURCES); return 1; - } for (to= stmt->param_array; to < stmt->param_array + stmt->param_count; ++to) @@ -1527,10 +1502,10 @@ static bool init_param_array(Prepared_statement *stmt) name NULL or statement name. For unnamed statements binary PS protocol is used, for named statements text protocol is used. - RETURN - 0 OK, statement prepared successfully - other Error - + RETURN + FALSE OK, statement prepared successfully + TRUE Error + NOTES This function parses the query and sends the total number of parameters and resultset metadata information back to client (if any), without @@ -1544,21 +1519,18 @@ static bool init_param_array(Prepared_statement *stmt) */ -int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, - LEX_STRING *name) +bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, + LEX_STRING *name) { LEX *lex; Prepared_statement *stmt= new Prepared_statement(thd); - int error; + bool error; DBUG_ENTER("mysql_stmt_prepare"); DBUG_PRINT("prep_query", ("%s", packet)); if (stmt == 0) - { - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_RETURN(1); - } + DBUG_RETURN(TRUE); if (name) { @@ -1567,16 +1539,14 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, name->length))) { delete stmt; - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } if (thd->stmt_map.insert(stmt)) { delete stmt; - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } thd->set_n_backup_statement(stmt, &thd->stmt_backup); @@ -1588,8 +1558,7 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, thd->restore_backup_item_arena(stmt, &thd->stmt_backup); /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } mysql_log.write(thd, COM_PREPARE, "%s", packet); @@ -1768,8 +1737,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) packet+= 9; /* stmt_id + 5 bytes of flags */ - if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute", - SEND_ERROR))) + if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_execute"))) DBUG_VOID_RETURN; DBUG_PRINT("exec_query:", ("%s", stmt->query)); @@ -1777,7 +1745,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) /* Check if we got an error when sending long data */ if (stmt->state == Item_arena::ERROR) { - send_error(thd, stmt->last_errno, stmt->last_error); + my_message(stmt->last_errno, stmt->last_error, MYF(0)); DBUG_VOID_RETURN; } @@ -1795,10 +1763,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) { if (!stmt->cursor && !(stmt->cursor= new (&stmt->mem_root) Cursor())) - { - send_error(thd, ER_OUT_OF_RESOURCES); DBUG_VOID_RETURN; - } /* If lex->result is set, mysql_execute_command will use it */ stmt->lex->result= &stmt->cursor->result; } @@ -1866,7 +1831,6 @@ set_params_data_err: reset_stmt_params(stmt); my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute"); err: - send_error(thd); DBUG_VOID_RETURN; } @@ -1892,14 +1856,12 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name) { my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_name->length, stmt_name->str, "EXECUTE"); - send_error(thd); DBUG_VOID_RETURN; } if (stmt->param_count != thd->lex->prepared_stmt_params.elements) { my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); - send_error(thd); DBUG_VOID_RETURN; } @@ -1910,7 +1872,6 @@ void mysql_sql_stmt_execute(THD *thd, LEX_STRING *stmt_name) &expanded_query)) { my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE"); - send_error(thd); } execute_stmt(thd, stmt, &expanded_query); DBUG_VOID_RETURN; @@ -1994,7 +1955,6 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) !stmt->cursor->is_open()) { my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), stmt_id, "fetch"); - send_error(thd); DBUG_VOID_RETURN; } @@ -2018,9 +1978,6 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length) thd->set_statement(&thd->stmt_backup); thd->set_item_arena(&thd->stmt_backup); - if (error && error != -4) - send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_VOID_RETURN; } @@ -2050,8 +2007,7 @@ void mysql_stmt_reset(THD *thd, char *packet) DBUG_ENTER("mysql_stmt_reset"); - if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset", - SEND_ERROR))) + if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset"))) DBUG_VOID_RETURN; stmt->state= Item_arena::PREPARED; @@ -2081,8 +2037,7 @@ void mysql_stmt_free(THD *thd, char *packet) DBUG_ENTER("mysql_stmt_free"); - if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close", - DONT_SEND_ERROR))) + if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close"))) DBUG_VOID_RETURN; /* Statement map deletes statement on erase */ @@ -2132,8 +2087,8 @@ void mysql_stmt_get_longdata(THD *thd, char *packet, ulong packet_length) stmt_id= uint4korr(packet); packet+= 4; - if (!(stmt=find_prepared_statement(thd, stmt_id, "mysql_stmt_send_long_data", - DONT_SEND_ERROR))) + if (!(stmt=find_prepared_statement(thd, stmt_id, + "mysql_stmt_send_long_data"))) DBUG_VOID_RETURN; param_number= uint2korr(packet); diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 9e38a65d412..fe7e8432ec6 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -278,41 +278,39 @@ bool log_in_use(const char* log_name) return result; } -int purge_error_message(THD* thd, int res) +bool purge_error_message(THD* thd, int res) { - const char *errmsg= 0; + uint errmsg= 0; switch (res) { case 0: break; - case LOG_INFO_EOF: errmsg= "Target log not found in binlog index"; break; - case LOG_INFO_IO: errmsg= "I/O error reading log index file"; break; - case LOG_INFO_INVALID: - errmsg= "Server configuration does not permit binlog purge"; break; - case LOG_INFO_SEEK: errmsg= "Failed on fseek()"; break; - case LOG_INFO_MEM: errmsg= "Out of memory"; break; - case LOG_INFO_FATAL: errmsg= "Fatal error during purge"; break; - case LOG_INFO_IN_USE: errmsg= "A purgeable log is in use, will not purge"; - break; - default: errmsg= "Unknown error during purge"; break; + case LOG_INFO_EOF: errmsg= ER_UNKNOWN_TARGET_BINLOG; break; + case LOG_INFO_IO: errmsg= ER_IO_ERR_LOG_INDEX_READ; break; + case LOG_INFO_INVALID:errmsg= ER_BINLOG_PURGE_PROHIBITED; break; + case LOG_INFO_SEEK: errmsg= ER_FSEEK_FAIL; break; + case LOG_INFO_MEM: errmsg= ER_OUT_OF_RESOURCES; break; + case LOG_INFO_FATAL: errmsg= ER_BINLOG_PURGE_FATAL_ERR; break; + case LOG_INFO_IN_USE: errmsg= ER_LOG_IN_USE; break; + default: errmsg= ER_LOG_PURGE_UNKNOWN_ERR; break; } if (errmsg) { - send_error(thd, 0, errmsg); - return 1; + my_error(errmsg, MYF(0)); + return TRUE; } send_ok(thd); - return 0; + return FALSE; } -int purge_master_logs(THD* thd, const char* to_log) +bool purge_master_logs(THD* thd, const char* to_log) { char search_file_name[FN_REFLEN]; if (!mysql_bin_log.is_open()) { send_ok(current_thd); - return 0; + return FALSE; } mysql_bin_log.make_log_name(search_file_name, to_log); @@ -322,10 +320,10 @@ int purge_master_logs(THD* thd, const char* to_log) } -int purge_master_logs_before_date(THD* thd, time_t purge_time) +bool purge_master_logs_before_date(THD* thd, time_t purge_time) { - int res = mysql_bin_log.purge_logs_before_date(purge_time); - return purge_error_message(thd ,res); + return purge_error_message(thd, + mysql_bin_log.purge_logs_before_date(purge_time)); } int test_for_non_eof_log_read_errors(int error, const char **errmsg) @@ -753,7 +751,7 @@ err: pthread_mutex_unlock(&LOCK_thread_count); if (file >= 0) (void) my_close(file, MYF(MY_WME)); - send_error(thd, my_errno, errmsg); + my_message(my_errno, errmsg, MYF(0)); DBUG_VOID_RETURN; } @@ -1054,7 +1052,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) } -int change_master(THD* thd, MASTER_INFO* mi) +bool change_master(THD* thd, MASTER_INFO* mi) { int thread_mask; const char* errmsg= 0; @@ -1065,9 +1063,9 @@ int change_master(THD* thd, MASTER_INFO* mi) init_thread_mask(&thread_mask,mi,0 /*not inverse*/); if (thread_mask) // We refuse if any slave thread is running { - net_printf(thd,ER_SLAVE_MUST_STOP); + my_error(ER_SLAVE_MUST_STOP, MYF(0)); unlock_slave_threads(mi); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } thd->proc_info = "Changing master"; @@ -1075,9 +1073,9 @@ int change_master(THD* thd, MASTER_INFO* mi) // TODO: see if needs re-write if (init_master_info(mi, master_info_file, relay_log_info_file, 0)) { - send_error(thd, ER_MASTER_INFO); + my_error(ER_MASTER_INFO, MYF(0)); unlock_slave_threads(mi); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } /* @@ -1194,9 +1192,9 @@ int change_master(THD* thd, MASTER_INFO* mi) 0 /* not only reset, but also reinit */, &errmsg)) { - net_printf(thd, 0, "Failed purging old relay logs: %s",errmsg); + my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); unlock_slave_threads(mi); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } else @@ -1210,9 +1208,9 @@ int change_master(THD* thd, MASTER_INFO* mi) 0 /*no data lock*/, &msg, 0)) { - net_printf(thd,0,"Failed initializing relay log position: %s",msg); + my_error(ER_RELAY_LOG_INIT, MYF(0), msg); unlock_slave_threads(mi); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } mi->rli.group_master_log_pos = mi->master_log_pos; @@ -1254,7 +1252,7 @@ int change_master(THD* thd, MASTER_INFO* mi) unlock_slave_threads(mi); thd->proc_info = 0; send_ok(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } int reset_master(THD* thd) @@ -1285,7 +1283,7 @@ int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1, } -int show_binlog_events(THD* thd) +bool show_binlog_events(THD* thd) { Protocol *protocol= thd->protocol; DBUG_ENTER("show_binlog_events"); @@ -1299,7 +1297,7 @@ int show_binlog_events(THD* thd) Log_event::init_show_field_list(&field_list); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); if (mysql_bin_log.is_open()) { @@ -1405,18 +1403,18 @@ err: { my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), "SHOW BINLOG EVENTS", errmsg); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); pthread_mutex_lock(&LOCK_thread_count); thd->current_linfo = 0; pthread_mutex_unlock(&LOCK_thread_count); - DBUG_RETURN(0); + DBUG_RETURN(TRUE); } -int show_binlog_info(THD* thd) +bool show_binlog_info(THD* thd) { Protocol *protocol= thd->protocol; DBUG_ENTER("show_binlog_info"); @@ -1429,7 +1427,7 @@ int show_binlog_info(THD* thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); protocol->prepare_for_resend(); if (mysql_bin_log.is_open()) @@ -1442,10 +1440,10 @@ int show_binlog_info(THD* thd) protocol->store(&binlog_do_db); protocol->store(&binlog_ignore_db); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -1457,11 +1455,11 @@ int show_binlog_info(THD* thd) thd Thread specific variable RETURN VALUES - 0 ok - 1 error (Error message sent to client) + FALSE OK + TRUE error */ -int show_binlogs(THD* thd) +bool show_binlogs(THD* thd) { IO_CACHE *index_file; char fname[FN_REFLEN]; @@ -1472,15 +1470,14 @@ int show_binlogs(THD* thd) if (!mysql_bin_log.is_open()) { - //TODO: Replace with ER() error message - send_error(thd, 0, "You are not using binary logging"); + my_error(ER_NO_BINARY_LOGGING, MYF(0)); return 1; } field_list.push_back(new Item_empty_string("Log_name", 255)); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); mysql_bin_log.lock_index(); index_file=mysql_bin_log.get_index_file(); @@ -1498,11 +1495,11 @@ int show_binlogs(THD* thd) } mysql_bin_log.unlock_index(); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: mysql_bin_log.unlock_index(); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } diff --git a/sql/sql_repl.h b/sql/sql_repl.h index c39ef90114d..3f457a060cb 100644 --- a/sql/sql_repl.h +++ b/sql/sql_repl.h @@ -27,17 +27,17 @@ File open_binlog(IO_CACHE *log, const char *log_file_name, int start_slave(THD* thd, MASTER_INFO* mi, bool net_report); int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report); -int change_master(THD* thd, MASTER_INFO* mi); -int show_binlog_events(THD* thd); +bool change_master(THD* thd, MASTER_INFO* mi); +bool show_binlog_events(THD* thd); int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1, const char* log_file_name2, ulonglong log_pos2); int reset_slave(THD *thd, MASTER_INFO* mi); int reset_master(THD* thd); -int purge_master_logs(THD* thd, const char* to_log); -int purge_master_logs_before_date(THD* thd, time_t purge_time); +bool purge_master_logs(THD* thd, const char* to_log); +bool purge_master_logs_before_date(THD* thd, time_t purge_time); bool log_in_use(const char* log_name); void adjust_linfo_offsets(my_off_t purge_offset); -int show_binlogs(THD* thd); +bool show_binlogs(THD* thd); extern int init_master_info(MASTER_INFO* mi); void kill_zombie_dump_threads(uint32 slave_server_id); int check_binlog_magic(IO_CACHE* log, const char** errmsg); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e104ac1ca38..8cbc7589d26 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -194,9 +194,9 @@ static Item *remove_additional_cond(Item* conds); This handles SELECT with and without UNION */ -int handle_select(THD *thd, LEX *lex, select_result *result) +bool handle_select(THD *thd, LEX *lex, select_result *result) { - int res; + bool res; register SELECT_LEX *select_lex = &lex->select_lex; DBUG_ENTER("handle_select"); @@ -223,14 +223,14 @@ int handle_select(THD *thd, LEX *lex, select_result *result) /* Don't set res if it's -1 as we may want this later */ DBUG_PRINT("info",("res: %d report_error: %d", res, thd->net.report_error)); - if (thd->net.report_error) - res= 1; + res|= thd->net.report_error; if (unlikely(res)) { - if (res > 0) - result->send_error(0, NullS); + /* + If we have real error reported erly then this will be ignored + */ + result->send_error(ER_UNKNOWN_ERROR, NullS); result->abort(); - res= 1; // Error sent to client } DBUG_RETURN(res); } @@ -395,21 +395,20 @@ JOIN::prepare(Item ***rref_pointer_array, { if (!test_if_subpart(procedure->group,group_list)) { /* purecov: inspected */ - my_message(0,"Can't handle procedures with differents groups yet", - MYF(0)); /* purecov: inspected */ + my_error(ER_DIFF_GROUPS_PROC, MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } } #ifdef NOT_NEEDED else if (!group_list && procedure->flags & PROC_GROUP) { - my_message(0,"Select must have a group with this procedure",MYF(0)); + my_message(ER_NO_GROUP_FOR_PROC, MYF(0)); goto err; } #endif if (order && (procedure->flags & PROC_NO_SORT)) { /* purecov: inspected */ - my_message(0,"Can't use order with this procedure",MYF(0)); /* purecov: inspected */ + my_error(ER_ORDER_WITH_PROC, MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } } @@ -1890,7 +1889,7 @@ Cursor::~Cursor() /*********************************************************************/ -int +bool mysql_select(THD *thd, Item ***rref_pointer_array, TABLE_LIST *tables, uint wild_num, List &fields, COND *conds, uint og_num, ORDER *order, ORDER *group, @@ -1898,7 +1897,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array, select_result *result, SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex) { - int err; + bool err; bool free_join= 1; DBUG_ENTER("mysql_select"); @@ -1906,7 +1905,10 @@ mysql_select(THD *thd, Item ***rref_pointer_array, if (select_lex->join != 0) { join= select_lex->join; - // is it single SELECT in derived table, called in derived table creation + /* + is it single SELECT in derived table, called in derived table + creation + */ if (select_lex->linkage != DERIVED_TABLE_TYPE || (select_options & SELECT_DESCRIBE)) { @@ -1915,7 +1917,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array, //here is EXPLAIN of subselect or derived table if (join->change_result(result)) { - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } else @@ -1934,7 +1936,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array, else { if (!(join= new JOIN(thd, fields, select_options, result))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); thd->proc_info="init"; thd->used_tables=0; // Updated by setup_fields if (join->prepare(rref_pointer_array, tables, wild_num, @@ -1982,10 +1984,8 @@ err: { thd->proc_info="end"; err= join->cleanup(); - if (thd->net.report_error) - err= -1; delete join; - DBUG_RETURN(err); + DBUG_RETURN(err || thd->net.report_error); } DBUG_RETURN(join->error); } @@ -11557,10 +11557,10 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, } -int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) +bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) { DBUG_ENTER("mysql_explain_union"); - int res= 0; + bool res= 0; SELECT_LEX *first= unit->first_select(); for (SELECT_LEX *sl= first; @@ -11611,9 +11611,7 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) first->options | thd->options | SELECT_DESCRIBE, result, unit, first); } - if (res > 0 || thd->net.report_error) - res= -1; // mysql_explain_select do not report error - DBUG_RETURN(res); + DBUG_RETURN(res || thd->net.report_error); } @@ -11824,17 +11822,17 @@ void st_select_lex::print(THD *thd, String *str) res new select_result object RETURN - 0 - OK - -1 - error + FALSE - OK + TRUE - error */ -int JOIN::change_result(select_result *res) +bool JOIN::change_result(select_result *res) { DBUG_ENTER("JOIN::change_result"); result= res; if (!procedure && result->prepare(fields_list, select_lex->master_unit())) { - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } diff --git a/sql/sql_select.h b/sql/sql_select.h index eb80f3ee608..e1f98059618 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -330,7 +330,7 @@ class JOIN :public Sql_alloc return (do_send_rows && tmp_table_param.sum_func_count != 0 && !group_list); } - int change_result(select_result *result); + bool change_result(select_result *result); }; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 14bef9d2236..b9c2a5d8e18 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -48,7 +48,7 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *packet); A database is a directory in the mysql_data_home directory */ -int +bool mysqld_show_dbs(THD *thd,const char *wild) { Item_string *field=new Item_string("",0,thd->charset()); @@ -68,9 +68,9 @@ mysqld_show_dbs(THD *thd,const char *wild) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); if (mysql_find_files(thd,&files,NullS,mysql_data_home,wild,1)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); List_iterator_fast it(files); while ((file_name=it++)) @@ -84,11 +84,11 @@ mysqld_show_dbs(THD *thd,const char *wild) protocol->prepare_for_resend(); protocol->store(file_name, system_charset_info); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -96,7 +96,7 @@ mysqld_show_dbs(THD *thd,const char *wild) List all open tables in a database ***************************************************************************/ -int mysqld_show_open_tables(THD *thd,const char *wild) +bool mysqld_show_open_tables(THD *thd,const char *wild) { List field_list; OPEN_TABLE_LIST *open_list; @@ -110,10 +110,10 @@ int mysqld_show_open_tables(THD *thd,const char *wild) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); if (!(open_list=list_open_tables(thd,wild)) && thd->is_fatal_error) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); for (; open_list ; open_list=open_list->next) { @@ -124,11 +124,11 @@ int mysqld_show_open_tables(THD *thd,const char *wild) protocol->store_tiny((longlong) open_list->locked); if (protocol->write()) { - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -137,7 +137,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild) ** A table is a .frm file in the current databasedir ***************************************************************************/ -int mysqld_show_tables(THD *thd, const char *db, const char *wild, +bool mysqld_show_tables(THD *thd, const char *db, const char *wild, bool show_type) { Item_string *field=new Item_string("",0,thd->charset()); @@ -162,10 +162,9 @@ int mysqld_show_tables(THD *thd, const char *db, const char *wild, if (show_type) field_list.push_back(new Item_empty_string("table_type", 10)); if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - if (mysql_find_files(thd,&files,db,path,wild,0)) - DBUG_RETURN(-1); + Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF) || + mysql_find_files(thd,&files,db,path,wild,0)) + DBUG_RETURN(TRUE); List_iterator_fast it(files); while ((file_name=it++)) { @@ -190,17 +189,17 @@ int mysqld_show_tables(THD *thd, const char *db, const char *wild, } } if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } /*************************************************************************** ** List all table types supported ***************************************************************************/ -int mysqld_show_storage_engines(THD *thd) +bool mysqld_show_storage_engines(THD *thd) { List field_list; Protocol *protocol= thd->protocol; @@ -212,7 +211,7 @@ int mysqld_show_storage_engines(THD *thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); const char *default_type_name= ha_get_storage_engine((enum db_type)thd->variables.table_type); @@ -230,10 +229,10 @@ int mysqld_show_storage_engines(THD *thd) protocol->store(option_name, system_charset_info); protocol->store(types->comment, system_charset_info); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -275,7 +274,7 @@ static struct show_privileges_st sys_privileges[]= {NullS, NullS, NullS} }; -int mysqld_show_privileges(THD *thd) +bool mysqld_show_privileges(THD *thd) { List field_list; Protocol *protocol= thd->protocol; @@ -287,7 +286,7 @@ int mysqld_show_privileges(THD *thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); show_privileges_st *privilege= sys_privileges; for (privilege= sys_privileges; privilege->privilege ; privilege++) @@ -297,10 +296,10 @@ int mysqld_show_privileges(THD *thd) protocol->store(privilege->context, system_charset_info); protocol->store(privilege->comment, system_charset_info); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -340,7 +339,7 @@ static struct show_column_type_st sys_column_types[]= "A very small integer"}, }; -int mysqld_show_column_types(THD *thd) +bool mysqld_show_column_types(THD *thd) { List field_list; Protocol *protocol= thd->protocol; @@ -363,7 +362,7 @@ int mysqld_show_column_types(THD *thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); /* TODO: Change the loop to not use 'i' */ for (uint i=0; i < sizeof(sys_column_types)/sizeof(sys_column_types[0]); i++) @@ -384,10 +383,10 @@ int mysqld_show_column_types(THD *thd) protocol->store(sys_column_types[i].default_value, system_charset_info); protocol->store(sys_column_types[i].comment, system_charset_info); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -486,7 +485,7 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, Extended version of mysqld_show_tables ***************************************************************************/ -int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) +bool mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) { Item *item; List files; @@ -496,7 +495,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) TABLE *table; Protocol *protocol= thd->protocol; TIME time; - int res; + bool res; DBUG_ENTER("mysqld_extend_show_tables"); (void) sprintf(path,"%s/%s",mysql_data_home,db); @@ -537,11 +536,9 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) field_list.push_back(item=new Item_empty_string("Comment",80)); item->maybe_null=1; if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - - if (mysql_find_files(thd,&files,db,path,wild,0)) - DBUG_RETURN(-1); + Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF) || + mysql_find_files(thd,&files,db,path,wild,0)) + DBUG_RETURN(TRUE); List_iterator_fast it(files); while ((file_name=it++)) { @@ -558,14 +555,12 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) { for (uint i=2 ; i < field_list.elements ; i++) protocol->store_null(); - // Send error to Comment field if possible - if (res < 0) + // Send error to Comment field + if (res) { protocol->store(thd->net.last_error, system_charset_info); thd->clear_error(); } - else - DBUG_RETURN(1); } else if (table_list.view) { @@ -680,10 +675,10 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) } close_thread_tables(thd, 0); if (protocol->write()) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -691,7 +686,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) ** List all columns in a table_list->real_name ***************************************************************************/ -int +bool mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, bool verbose) { @@ -707,11 +702,9 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, table_list->real_name)); table_list->lock_type= TL_UNLOCK; - if ((res= open_and_lock_tables(thd, table_list))) + if (open_and_lock_tables(thd, table_list)) { - if (res < 0) - send_error(thd); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } table= table_list->table; file=table->file; @@ -737,7 +730,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, // Send first number of fields and records if (protocol->send_records_num(&field_list, (ulonglong)file->records) || protocol->send_fields(&field_list, Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); restore_record(table,default_values); // Get empty record Field **ptr,*field; @@ -844,16 +837,16 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, system_charset_info); } if (protocol->write()) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } -int +bool mysqld_show_create(THD *thd, TABLE_LIST *table_list) { TABLE *table; @@ -866,18 +859,16 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) table_list->real_name)); /* Only one table for now, but VIEW can involve several tables */ - if ((res= open_and_lock_tables(thd, table_list))) + if (open_and_lock_tables(thd, table_list)) { - if (res < 0) - send_error(thd); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } /* TODO: add environment variables show when it become possible */ if (thd->lex->only_view && !table_list->view) { my_error(ER_WRONG_OBJECT, MYF(0), table_list->db, table_list->real_name, "VIEW"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } table= table_list->table; @@ -885,7 +876,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) if ((table_list->view ? view_store_create_info(thd, table_list, &buffer) : store_create_info(thd, table, &buffer))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); List field_list; if (table_list->view) @@ -904,31 +895,31 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); protocol->prepare_for_resend(); buffer.length(0); if (table_list->view) { protocol->store(table_list->view_name.str, system_charset_info); if (view_store_create_info(thd, table_list, &buffer)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } else { protocol->store(table->table_name, system_charset_info); if (store_create_info(thd, table, &buffer)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } protocol->store(buffer.ptr(), buffer.length(), buffer.charset()); if (protocol->write()) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } -int mysqld_show_create_db(THD *thd, char *dbname, - HA_CREATE_INFO *create_info) +bool mysqld_show_create_db(THD *thd, char *dbname, + HA_CREATE_INFO *create_info) { int length; char path[FN_REFLEN]; @@ -945,8 +936,8 @@ int mysqld_show_create_db(THD *thd, char *dbname, if (check_db_name(dbname)) { - net_printf(thd,ER_WRONG_DB_NAME, dbname); - DBUG_RETURN(1); + my_error(ER_WRONG_DB_NAME, MYF(0), dbname); + DBUG_RETURN(TRUE); } #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -957,11 +948,11 @@ int mysqld_show_create_db(THD *thd, char *dbname, thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - net_printf(thd,ER_DBACCESS_DENIED_ERROR, - thd->priv_user, thd->host_or_ip, dbname); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, thd->host_or_ip, dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->host_or_ip, dbname); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } #endif @@ -975,8 +966,8 @@ int mysqld_show_create_db(THD *thd, char *dbname, } if (access(path,F_OK)) { - net_printf(thd,ER_BAD_DB_ERROR,dbname); - DBUG_RETURN(1); + my_error(ER_BAD_DB_ERROR, MYF(0), dbname); + DBUG_RETURN(TRUE); } if (found_libchar) path[length-1]= FN_LIBCHAR; @@ -989,7 +980,7 @@ int mysqld_show_create_db(THD *thd, char *dbname, if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); protocol->prepare_for_resend(); protocol->store(dbname, strlen(dbname), system_charset_info); @@ -1014,12 +1005,12 @@ int mysqld_show_create_db(THD *thd, char *dbname, protocol->store(buffer.ptr(), buffer.length(), buffer.charset()); if (protocol->write()) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } -int +bool mysqld_show_logs(THD *thd) { List field_list; @@ -1032,19 +1023,19 @@ mysqld_show_logs(THD *thd) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); #ifdef HAVE_BERKELEY_DB if ((have_berkeley_db == SHOW_OPTION_YES) && berkeley_show_logs(protocol)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); #endif send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } -int +bool mysqld_show_keys(THD *thd, TABLE_LIST *table_list) { TABLE *table; @@ -1055,8 +1046,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) if (!(table = open_ltable(thd, table_list, TL_UNLOCK))) { - send_error(thd); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } List field_list; @@ -1082,7 +1072,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); KEY *key_info=table->key_info; table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME); @@ -1133,11 +1123,11 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) else protocol->store("", 0, system_charset_info); if (protocol->write()) - DBUG_RETURN(1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -1155,12 +1145,8 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) DBUG_PRINT("enter",("table: %s",table_list->real_name)); table_list->lock_type= TL_UNLOCK; - if ((res= open_and_lock_tables(thd, table_list))) - { - if (res < 0) - send_error(thd); + if (open_and_lock_tables(thd, table_list)) DBUG_VOID_RETURN; - } table= table_list->table; List field_list; @@ -1805,7 +1791,7 @@ static bool write_collation(Protocol *protocol, CHARSET_INFO *cs) return protocol->write(); } -int mysqld_show_collations(THD *thd, const char *wild) +bool mysqld_show_collations(THD *thd, const char *wild) { char buff[8192]; String packet2(buff,sizeof(buff),thd->charset()); @@ -1813,7 +1799,7 @@ int mysqld_show_collations(THD *thd, const char *wild) CHARSET_INFO **cs; Protocol *protocol= thd->protocol; - DBUG_ENTER("mysqld_show_charsets"); + DBUG_ENTER(" mysqld_show_collations"); field_list.push_back(new Item_empty_string("Collation",30)); field_list.push_back(new Item_empty_string("Charset",30)); @@ -1824,7 +1810,7 @@ int mysqld_show_collations(THD *thd, const char *wild) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) { @@ -1845,10 +1831,10 @@ int mysqld_show_collations(THD *thd, const char *wild) } } } - send_eof(thd); - DBUG_RETURN(0); + send_eof(thd); + DBUG_RETURN(FALSE); err: - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } static bool write_charset(Protocol *protocol, CHARSET_INFO *cs) @@ -1861,7 +1847,7 @@ static bool write_charset(Protocol *protocol, CHARSET_INFO *cs) return protocol->write(); } -int mysqld_show_charsets(THD *thd, const char *wild) +bool mysqld_show_charsets(THD *thd, const char *wild) { char buff[8192]; String packet2(buff,sizeof(buff),thd->charset()); @@ -1878,7 +1864,7 @@ int mysqld_show_charsets(THD *thd, const char *wild) if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) { @@ -1891,18 +1877,18 @@ int mysqld_show_charsets(THD *thd, const char *wild) goto err; } } - send_eof(thd); - DBUG_RETURN(0); + send_eof(thd); + DBUG_RETURN(FALSE); err: - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } -int mysqld_show(THD *thd, const char *wild, show_var_st *variables, - enum enum_var_type value_type, - pthread_mutex_t *mutex, - struct system_status_var *status_var) +bool mysqld_show(THD *thd, const char *wild, show_var_st *variables, + enum enum_var_type value_type, + pthread_mutex_t *mutex, + struct system_status_var *status_var) { char buff[1024]; List field_list; @@ -1914,7 +1900,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, field_list.push_back(new Item_empty_string("Value",256)); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ null_lex_str.str= 0; // For sys_var->value_ptr() null_lex_str.length= 0; @@ -2206,11 +2192,11 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, } pthread_mutex_unlock(mutex); send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: pthread_mutex_unlock(mutex); - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 399fed00040..d84611ae496 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -57,15 +57,15 @@ static int copy_data_between_tables(TABLE *from,TABLE *to, Wait if global_read_lock (FLUSH TABLES WITH READ LOCK) is set. RETURN - 0 ok. In this case ok packet is sent to user - -1 Error (Error message given but not sent to user) + FALSE OK. In this case ok packet is sent to user + TRUE Error */ -int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, - my_bool drop_temporary) +bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, + my_bool drop_temporary) { - int error= 0; + bool error= FALSE; DBUG_ENTER("mysql_rm_table"); /* mark for close and remove all cached entries */ @@ -80,7 +80,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, { my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,MYF(0), tables->real_name); - error= 1; + error= TRUE; goto err; } while (global_read_lock && ! thd->killed) @@ -100,9 +100,9 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, pthread_mutex_unlock(&thd->mysys_var->mutex); if (error) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); send_ok(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -1101,22 +1101,22 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, and must be zero for standard create of table. RETURN VALUES - 0 ok - -1 error + FALSE OK + TRUE error */ -int mysql_create_table(THD *thd,const char *db, const char *table_name, - HA_CREATE_INFO *create_info, - List &fields, - List &keys,bool tmp_table, - uint select_field_count) +bool mysql_create_table(THD *thd,const char *db, const char *table_name, + HA_CREATE_INFO *create_info, + List &fields, + List &keys,bool tmp_table, + uint select_field_count) { char path[FN_REFLEN]; const char *alias; - int error= -1; uint db_options, key_count; KEY *key_info_buffer; handler *file; + bool error= TRUE; enum db_type new_db_type; DBUG_ENTER("mysql_create_table"); @@ -1124,7 +1124,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (!fields.elements) { my_error(ER_TABLE_MUST_HAVE_COLUMNS,MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if ((new_db_type= ha_checktype(create_info->db_type)) != create_info->db_type) @@ -1154,7 +1154,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, (file->table_flags() & HA_NO_TEMP_TABLES)) { my_error(ER_ILLEGAL_HA,MYF(0),table_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } #endif @@ -1179,7 +1179,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, keys, tmp_table, db_options, file, key_info_buffer, &key_count, select_field_count)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); /* Check if table exists */ if (create_info->options & HA_LEX_CREATE_TMP_TABLE) @@ -1202,10 +1202,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) { create_info->table_existed= 1; // Mark that table existed - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (wait_if_global_read_lock(thd, 0, 1)) DBUG_RETURN(error); @@ -1217,7 +1217,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) { create_info->table_existed= 1; // Mark that table existed - error= 0; + error= FALSE; } else my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); @@ -1246,7 +1246,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, if (create_if_not_exists) { create_info->table_existed= 1; // Mark that table existed - error= 0; + error= FALSE; } else my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); @@ -1285,7 +1285,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, HA_LEX_CREATE_TMP_TABLE)); mysql_bin_log.write(&qinfo); } - error=0; + error= FALSE; end: VOID(pthread_mutex_unlock(&LOCK_open)); start_waiting_global_read_lock(thd); @@ -1547,7 +1547,7 @@ static int send_check_errmsg(THD *thd, TABLE_LIST* table, protocol->store((char*) operator_name, system_charset_info); protocol->store("error", 5, system_charset_info); protocol->store(errmsg, system_charset_info); - thd->net.last_error[0]=0; + thd->clear_error(); if (protocol->write()) return -1; return 1; @@ -1722,16 +1722,16 @@ end: } -static int mysql_admin_table(THD* thd, TABLE_LIST* tables, - HA_CHECK_OPT* check_opt, - const char *operator_name, - thr_lock_type lock_type, - bool open_for_modify, - uint extra_open_options, - int (*prepare_func)(THD *, TABLE_LIST *, - HA_CHECK_OPT *), - int (handler::*operator_func) - (THD *, HA_CHECK_OPT *)) +static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, + HA_CHECK_OPT* check_opt, + const char *operator_name, + thr_lock_type lock_type, + bool open_for_modify, + uint extra_open_options, + int (*prepare_func)(THD *, TABLE_LIST *, + HA_CHECK_OPT *), + int (handler::*operator_func) + (THD *, HA_CHECK_OPT *)) { TABLE_LIST *table; List field_list; @@ -1749,7 +1749,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, item->maybe_null = 1; if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); mysql_ha_close(thd, tables, /*dont_send_ok*/ 1, /*dont_lock*/ 1); for (table= tables; table; table= table->next_local) @@ -1761,9 +1761,6 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, thd->open_options|= extra_open_options; table->table = open_ltable(thd, table, lock_type); -#ifdef EMBEDDED_LIBRARY - thd->net.last_errno= 0; // these errors shouldn't get client -#endif thd->open_options&= ~extra_open_options; if (prepare_func) @@ -1785,7 +1782,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, if (!(err_msg=thd->net.last_error)) err_msg=ER(ER_CHECK_NO_SUCH_TABLE); protocol->store(err_msg, system_charset_info); - thd->net.last_error[0]=0; + thd->clear_error(); if (protocol->write()) goto err; continue; @@ -1829,9 +1826,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, } int result_code = (table->table->file->*operator_func)(thd, check_opt); -#ifdef EMBEDDED_LIBRARY - thd->net.last_errno= 0; // these errors shouldn't get client -#endif + thd->clear_error(); // these errors shouldn't get client protocol->prepare_for_resend(); protocol->store(table_name, system_charset_info); protocol->store(operator_name, system_charset_info); @@ -1932,16 +1927,16 @@ send_result_message: } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: close_thread_tables(thd); // Shouldn't be needed if (table) table->table=0; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } -int mysql_backup_table(THD* thd, TABLE_LIST* table_list) +bool mysql_backup_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("mysql_backup_table"); DBUG_RETURN(mysql_admin_table(thd, table_list, 0, @@ -1950,7 +1945,7 @@ int mysql_backup_table(THD* thd, TABLE_LIST* table_list) } -int mysql_restore_table(THD* thd, TABLE_LIST* table_list) +bool mysql_restore_table(THD* thd, TABLE_LIST* table_list) { DBUG_ENTER("mysql_restore_table"); DBUG_RETURN(mysql_admin_table(thd, table_list, 0, @@ -1960,7 +1955,7 @@ int mysql_restore_table(THD* thd, TABLE_LIST* table_list) } -int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) +bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) { DBUG_ENTER("mysql_repair_table"); DBUG_RETURN(mysql_admin_table(thd, tables, check_opt, @@ -1970,7 +1965,7 @@ int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) } -int mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) +bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) { DBUG_ENTER("mysql_optimize_table"); DBUG_RETURN(mysql_admin_table(thd, tables, check_opt, @@ -1988,11 +1983,11 @@ int mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) tables Table list (one table only) RETURN VALUES - 0 ok - -1 error + FALSE ok + TRUE error */ -int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, +bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, LEX_STRING *key_cache_name) { HA_CHECK_OPT check_opt; @@ -2005,7 +2000,7 @@ int mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, { pthread_mutex_unlock(&LOCK_global_system_variables); my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } pthread_mutex_unlock(&LOCK_global_system_variables); check_opt.key_cache= key_cache; @@ -2063,11 +2058,11 @@ int reassign_keycache_tables(THD *thd, KEY_CACHE *src_cache, tables Table list (one table only) RETURN VALUES - 0 ok - -1 error + FALSE ok + TRUE error */ -int mysql_preload_keys(THD* thd, TABLE_LIST* tables) +bool mysql_preload_keys(THD* thd, TABLE_LIST* tables) { DBUG_ENTER("mysql_preload_keys"); DBUG_RETURN(mysql_admin_table(thd, tables, 0, @@ -2087,13 +2082,13 @@ int mysql_preload_keys(THD* thd, TABLE_LIST* tables) table_ident Src table_ident RETURN VALUES - 0 ok - -1 error + FALSE OK + TRUE error */ -int mysql_create_like_table(THD* thd, TABLE_LIST* table, - HA_CREATE_INFO *create_info, - Table_ident *table_ident) +bool mysql_create_like_table(THD* thd, TABLE_LIST* table, + HA_CREATE_INFO *create_info, + Table_ident *table_ident) { TABLE **tmp_table; char src_path[FN_REFLEN], dst_path[FN_REFLEN]; @@ -2101,7 +2096,8 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table, char *table_name= table->real_name; char *src_db= thd->db; char *src_table= table_ident->table.str; - int err, res= -1; + int err; + bool res= TRUE; TABLE_LIST src_tables_list; DBUG_ENTER("mysql_create_like_table"); @@ -2114,7 +2110,7 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table, table_ident->db.str && check_db_name((src_db= table_ident->db.str))) { my_error(ER_WRONG_TABLE_NAME, MYF(0), src_table); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } bzero((gptr)&src_tables_list, sizeof(src_tables_list)); @@ -2201,7 +2197,7 @@ int mysql_create_like_table(THD* thd, TABLE_LIST* table, HA_LEX_CREATE_TMP_TABLE)); mysql_bin_log.write(&qinfo); } - res= 0; + res= FALSE; goto err; table_exists: @@ -2212,7 +2208,7 @@ table_exists: ER(ER_TABLE_EXISTS_ERROR), table_name); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_TABLE_EXISTS_ERROR,warn_buff); - res= 0; + res= FALSE; } else my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); @@ -2225,7 +2221,7 @@ err: } -int mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) +bool mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) { #ifdef OS2 thr_lock_type lock_type = TL_WRITE; @@ -2240,7 +2236,7 @@ int mysql_analyze_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) } -int mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt) +bool mysql_check_table(THD* thd, TABLE_LIST* tables,HA_CHECK_OPT* check_opt) { #ifdef OS2 thr_lock_type lock_type = TL_WRITE; @@ -2528,13 +2524,13 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list, Alter table */ -int mysql_alter_table(THD *thd,char *new_db, char *new_name, - HA_CREATE_INFO *create_info, - TABLE_LIST *table_list, - List &fields, List &keys, - uint order_num, ORDER *order, - enum enum_duplicates handle_duplicates, - ALTER_INFO *alter_info, bool do_send_ok) +bool mysql_alter_table(THD *thd,char *new_db, char *new_name, + HA_CREATE_INFO *create_info, + TABLE_LIST *table_list, + List &fields, List &keys, + uint order_num, ORDER *order, + enum enum_duplicates handle_duplicates, + ALTER_INFO *alter_info, bool do_send_ok) { TABLE *table,*new_table; int error; @@ -2563,7 +2559,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list, alter_info->tablespace_op)); if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); /* Check that we are not trying to rename to an existing table */ if (new_name) @@ -2595,7 +2591,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (find_temporary_table(thd,new_db,new_name_buff)) { my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name_buff); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } else @@ -2605,7 +2601,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, { /* Table will be closed in do_command() */ my_error(ER_TABLE_EXISTS_ERROR,MYF(0), new_alias); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } @@ -2788,7 +2784,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (def->sql_type == FIELD_TYPE_BLOB) { my_error(ER_BLOB_CANT_HAVE_DEFAULT,MYF(0),def->change); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } def->def=alter->def; // Use new default alter_it.remove(); @@ -2802,7 +2798,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (def->change && ! def->field) { my_error(ER_BAD_FIELD_ERROR,MYF(0),def->change,table_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!def->after) create_list.push_back(def); @@ -2820,7 +2816,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (!find) { my_error(ER_BAD_FIELD_ERROR,MYF(0),def->after,table_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } find_it.after(def); // Put element after this } @@ -2829,12 +2825,12 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, { my_error(ER_BAD_FIELD_ERROR,MYF(0),alter_info->alter_list.head()->name, table_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!create_list.elements) { my_error(ER_CANT_REMOVE_ALL_FIELDS,MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* @@ -2923,7 +2919,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, !my_strcasecmp(system_charset_info,key->name,primary_key_name)) { my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } @@ -3261,10 +3257,10 @@ end_temporary: if (do_send_ok) send_ok(thd,copied+deleted,0L,tmp_name); thd->some_tables_deleted=0; - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } @@ -3433,8 +3429,8 @@ copy_data_between_tables(TABLE *from,TABLE *to, RETURN Like mysql_alter_table(). */ -int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, - bool do_send_ok) +bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, + bool do_send_ok) { DBUG_ENTER("mysql_recreate_table"); LEX *lex= thd->lex; @@ -3455,7 +3451,7 @@ int mysql_recreate_table(THD *thd, TABLE_LIST *table_list, } -int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) +bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) { TABLE_LIST *table; List field_list; @@ -3469,7 +3465,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) item->maybe_null= 1; if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); for (table= tables; table; table= table->next_local) { @@ -3488,7 +3484,7 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) { /* Table didn't exist */ protocol->store_null(); - thd->net.last_error[0]=0; + thd->clear_error(); } else { @@ -3550,11 +3546,11 @@ int mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt) } send_eof(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: close_thread_tables(thd); // Shouldn't be needed if (table) table->table=0; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index add4078ce8e..b71bb4ba42a 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -38,12 +38,13 @@ static File_option triggers_file_parameters[]= methods. RETURN VALUE - 0 - Success, non-0 in case of error. + FALSE Success + TRUE error */ -int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) +bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) { TABLE *table; - int result= 0; + bool result= 0; DBUG_ENTER("mysql_create_or_drop_trigger"); @@ -53,7 +54,7 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) */ if (open_and_lock_tables(thd, tables)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); /* TODO: We should check if user has TRIGGER privilege for table here. @@ -61,7 +62,7 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) we don't have proper privilege checking for triggers in place yet. */ if (check_global_access(thd, SUPER_ACL)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); table= tables->table; @@ -74,7 +75,7 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) if (tables->view || table->tmp_table != NO_TMP_TABLE) { my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!table->triggers) @@ -82,11 +83,11 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) if (!create) { my_error(ER_TRG_DOES_NOT_EXIST, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!(table->triggers= new (&table->mem_root) Table_triggers_list())) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* @@ -96,12 +97,12 @@ int mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) global read lock is held without helding LOCK_open). */ if (wait_if_global_read_lock(thd, 0, 0)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); VOID(pthread_mutex_lock(&LOCK_open)); - if ((create ? table->triggers->create_trigger(thd, tables): - table->triggers->drop_trigger(thd, tables))) - result= -1; + result= (create ? + table->triggers->create_trigger(thd, tables): + table->triggers->drop_trigger(thd, tables)); /* It is sensible to invalidate table in any case */ close_cached_table(thd, table); diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 561f79f9de1..d27b72c02a7 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -369,7 +369,7 @@ int mysql_create_function(THD *thd,udf_func *udf) if (!initialized) { - send_error(thd, ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES)); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); DBUG_RETURN(1); } @@ -380,19 +380,19 @@ int mysql_create_function(THD *thd,udf_func *udf) */ if (strchr(udf->dl, '/')) { - send_error(thd, ER_UDF_NO_PATHS,ER(ER_UDF_NO_PATHS)); + my_error(ER_UDF_NO_PATHS, MYF(0)); DBUG_RETURN(1); } if (udf->name.length > NAME_LEN) { - net_printf(thd, ER_TOO_LONG_IDENT,udf->name); + my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name); DBUG_RETURN(1); } rw_wrlock(&THR_LOCK_udf); if ((hash_search(&udf_hash,(byte*) udf->name.str, udf->name.length))) { - net_printf(thd, ER_UDF_EXISTS, udf->name); + my_error(ER_UDF_EXISTS, MYF(0), udf->name); goto err; } if (!(dl = find_udf_dl(udf->dl))) @@ -401,7 +401,7 @@ int mysql_create_function(THD *thd,udf_func *udf) { DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)", udf->dl,errno,dlerror())); - net_printf(thd, ER_CANT_OPEN_LIBRARY, udf->dl, errno, dlerror()); + my_error(ER_CANT_OPEN_LIBRARY, MYF(0), udf->dl, errno, dlerror()); goto err; } new_dl=1; @@ -411,16 +411,13 @@ int mysql_create_function(THD *thd,udf_func *udf) if (udf->func == NULL) { - net_printf(thd, ER_CANT_FIND_DL_ENTRY, udf->name); + my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), udf->name); goto err; } udf->name.str=strdup_root(&mem,udf->name.str); udf->dl=strdup_root(&mem,udf->dl); if (!(u_d=add_udf(&udf->name,udf->returns,udf->dl,udf->type))) - { - send_error(thd,0); // End of memory goto err; - } u_d->dlhandle = dl; u_d->func=udf->func; u_d->func_init=udf->func_init; @@ -448,7 +445,7 @@ int mysql_create_function(THD *thd,udf_func *udf) close_thread_tables(thd); if (error) { - net_printf(thd, ER_ERROR_ON_WRITE, "func@mysql",error); + my_error(ER_ERROR_ON_WRITE, MYF(0), "func@mysql", error); del_udf(u_d); goto err; } @@ -471,14 +468,14 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) DBUG_ENTER("mysql_drop_function"); if (!initialized) { - send_error(thd, ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES)); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); DBUG_RETURN(1); } rw_wrlock(&THR_LOCK_udf); if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name->str, (uint) udf_name->length))) { - net_printf(thd, ER_FUNCTION_NOT_DEFINED, udf_name->str); + my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str); goto err; } del_udf(udf); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index cf4203bf5b8..6a2d11ba7f5 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -24,21 +24,20 @@ #include "mysql_priv.h" #include "sql_select.h" -int mysql_union(THD *thd, LEX *lex, select_result *result, - SELECT_LEX_UNIT *unit) +bool mysql_union(THD *thd, LEX *lex, select_result *result, + SELECT_LEX_UNIT *unit) { DBUG_ENTER("mysql_union"); - int res, res_cln; + bool res; if (!(res= unit->prepare(thd, result, SELECT_NO_UNLOCK))) res= unit->exec(); - if (res == 0 && thd->cursor && thd->cursor->is_open()) + if (!res && thd->cursor && thd->cursor->is_open()) { thd->cursor->set_unit(unit); - res_cln= 0; } else - res_cln= unit->cleanup(); - DBUG_RETURN(res?res:res_cln); + res|= unit->cleanup(); + DBUG_RETURN(res); } @@ -104,8 +103,7 @@ bool select_union::flush() int error; if ((error=table->file->extra(HA_EXTRA_NO_CACHE))) { - table->file->print_error(error,MYF(0)); - ::send_error(thd); + table->file->print_error(error, MYF(0)); return 1; } return 0; @@ -147,8 +145,8 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd) } -int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, - ulong additional_options) +bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, + ulong additional_options) { SELECT_LEX *lex_select_save= thd_arg->lex->current_select; SELECT_LEX *sl, *first_select; @@ -176,16 +174,16 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, if (!sl->join->procedure && result->prepare(sl->join->fields_list, this)) { - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } sl->join->select_options|= SELECT_DESCRIBE; sl->join->reinit(); } } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } prepared= 1; - res= 0; + res= FALSE; thd_arg->lex->current_select= sl= first_select= first_select_in_union(); found_rows_for_union= first_select->options & OPTION_FOUND_ROWS; @@ -232,7 +230,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, sl->having, (ORDER*) NULL, sl, this); - if (res || thd_arg->is_fatal_error) + if ((res= (res || thd_arg->is_fatal_error))) goto err; if (sl == first_select) { @@ -262,7 +260,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, while ((type= tp++, item_tmp= it++)) { if (((Item_type_holder*)type)->join_types(thd_arg, item_tmp)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } @@ -305,7 +303,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, { if (arena) thd->restore_backup_item_arena(arena, &backup); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } if (arena) @@ -323,7 +321,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, result))) { fake_select_lex->table_list.empty(); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } fake_select_lex->item_list= item_list; @@ -345,15 +343,15 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, thd_arg->lex->current_select= lex_select_save; - DBUG_RETURN(res || thd_arg->is_fatal_error ? 1 : 0); + DBUG_RETURN(res || thd_arg->is_fatal_error); err: thd_arg->lex->current_select= lex_select_save; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } -int st_select_lex_unit::exec() +bool st_select_lex_unit::exec() { SELECT_LEX *lex_select_save= thd->lex->current_select; SELECT_LEX *select_cursor=first_select_in_union(); @@ -361,7 +359,7 @@ int st_select_lex_unit::exec() DBUG_ENTER("st_select_lex_unit::exec"); if (executed && !uncacheable && !describe) - DBUG_RETURN(0); + DBUG_RETURN(FALSE); executed= 1; if (uncacheable || !item || !item->assigned() || describe) @@ -376,7 +374,7 @@ int st_select_lex_unit::exec() } /* re-enabling indexes for next subselect iteration */ if (union_distinct && table->file->enable_indexes(HA_KEY_SWITCH_ALL)) - DBUG_ASSERT(1); + DBUG_ASSERT(TRUE); } for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select()) { @@ -431,7 +429,7 @@ int st_select_lex_unit::exec() if (sl == union_distinct) { if (table->file->disable_indexes(HA_KEY_SWITCH_ALL)) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); table->no_keyread=1; } res= sl->join->error; @@ -439,7 +437,7 @@ int st_select_lex_unit::exec() if (!res && union_result->flush()) { thd->lex->current_select= lex_select_save; - DBUG_RETURN(1); + DBUG_RETURN(TRUE); } } if (res) @@ -465,7 +463,7 @@ int st_select_lex_unit::exec() optimized= 1; /* Send result to 'result' */ - res= -1; + res= TRUE; { List empty_list; empty_list.empty(); @@ -484,7 +482,7 @@ int st_select_lex_unit::exec() fake_select_lex->options, result))) { fake_select_lex->table_list.empty(); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* @@ -528,7 +526,7 @@ int st_select_lex_unit::exec() } -int st_select_lex_unit::cleanup() +bool st_select_lex_unit::cleanup() { int error= 0; JOIN *join; @@ -536,7 +534,7 @@ int st_select_lex_unit::cleanup() if (cleaned) { - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } cleaned= 1; @@ -610,19 +608,19 @@ void st_select_lex_unit::reinit_exec_mechanism() old_result old select_result object RETURN - 0 - OK - -1 - error + FALSE - OK + TRUE - error */ -int st_select_lex_unit::change_result(select_subselect *result, - select_subselect *old_result) +bool st_select_lex_unit::change_result(select_subselect *result, + select_subselect *old_result) { - int res= 0; + bool res= FALSE; for (SELECT_LEX *sl= first_select_in_union(); sl; sl= sl->next_select()) { if (sl->join && sl->join->result == old_result) - if ((res= sl->join->change_result(result))) - return (res); + if (sl->join->change_result(result)) + return TRUE; } if (fake_select_lex && fake_select_lex->join) res= fake_select_lex->join->change_result(result); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 00e70ccb484..8d64d30a9e0 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -87,21 +87,21 @@ static bool check_fields(THD *thd, List &items) } -int mysql_update(THD *thd, - TABLE_LIST *table_list, - List &fields, - List &values, - COND *conds, - uint order_num, ORDER *order, - ha_rows limit, - enum enum_duplicates handle_duplicates) +bool mysql_update(THD *thd, + TABLE_LIST *table_list, + List &fields, + List &values, + COND *conds, + uint order_num, ORDER *order, + ha_rows limit, + enum enum_duplicates handle_duplicates) { bool using_limit= limit != HA_POS_ERROR; bool safe_update= thd->options & OPTION_SAFE_UPDATES; bool used_key_is_modified, transactional_table, log_delayed; bool ignore_err= (thd->lex->duplicates == DUP_IGNORE); + bool res; int error=0; - int res; uint used_index; #ifndef NO_EMBEDDED_ACCESS_CHECKS uint want_privilege; @@ -117,8 +117,8 @@ int mysql_update(THD *thd, LINT_INIT(used_index); LINT_INIT(timestamp_query_id); - if ((error= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(error); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); thd->proc_info="init"; table= table_list->table; table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); @@ -156,16 +156,16 @@ int mysql_update(THD *thd, res= setup_fields(thd, 0, table_list, fields, 1, 0, 0); thd->lex->select_lex.no_wrap_view_item= 0; if (res) - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } if (table_list->view && check_fields(thd, fields)) { - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!table_list->updatable || check_key_in_view(thd, table_list)) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (table->timestamp_field) { @@ -184,7 +184,7 @@ int mysql_update(THD *thd, if (setup_fields(thd, 0, table_list, values, 0, 0, 0)) { free_underlaid_joins(thd, &thd->lex->select_lex); - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } // Don't count on usage of 'only index' when calculating which key to use @@ -197,10 +197,10 @@ int mysql_update(THD *thd, free_underlaid_joins(thd, &thd->lex->select_lex); if (error) { - DBUG_RETURN(-1); // Error in where + DBUG_RETURN(TRUE); // Error in where } send_ok(thd); // No matching records - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } /* If running in safe sql mode, don't allow updates without keys */ if (table->quick_keys.is_clear_all()) @@ -363,7 +363,15 @@ int mysql_update(THD *thd, { store_record(table,record[1]); if (fill_record(fields,values, 0) || thd->net.report_error) + { + /* Field::store methods can't send errors */ + if (!thd->net.report_error) + { + /* TODO: convert last warning to error */ + my_error(ER_UNKNOWN_ERROR, MYF(0)); + } break; /* purecov: inspected */ + } found++; if (table->triggers) @@ -456,9 +464,7 @@ int mysql_update(THD *thd, } free_underlaid_joins(thd, &thd->lex->select_lex); - if (error >= 0) - send_error(thd,thd->killed_errno()); /* purecov: inspected */ - else + if (error < 0) { char buff[80]; sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated, @@ -472,7 +478,7 @@ int mysql_update(THD *thd, thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */ thd->abort_on_warning= 0; free_io_cache(table); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: delete select; @@ -483,7 +489,7 @@ err: table->file->extra(HA_EXTRA_NO_KEYREAD); } thd->abort_on_warning= 0; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* @@ -555,11 +561,11 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list, thd thread handler RETURN - 0 OK - -1 Error + FALSE OK + TRUE Error */ -int mysql_multi_update_prepare(THD *thd) +bool mysql_multi_update_prepare(THD *thd) { LEX *lex= thd->lex; TABLE_LIST *table_list= lex->query_tables; @@ -597,7 +603,7 @@ int mysql_multi_update_prepare(THD *thd) res= setup_fields(thd, 0, table_list, *fields, 1, 0, 0), thd->lex->select_lex.no_wrap_view_item= 0, res)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); for (tl= table_list; tl ; tl= tl->next_local) { @@ -610,7 +616,7 @@ int mysql_multi_update_prepare(THD *thd) if (update_view && check_fields(thd, *fields)) { - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } { @@ -650,36 +656,36 @@ int mysql_multi_update_prepare(THD *thd) (tables_for_update & tl->table->map)) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), tl->alias, "UPDATE"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } - DBUG_RETURN (0); + DBUG_RETURN(FALSE); } -int mysql_multi_update(THD *thd, - TABLE_LIST *table_list, - List *fields, - List *values, - COND *conds, - ulong options, - enum enum_duplicates handle_duplicates, - SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex) +bool mysql_multi_update(THD *thd, + TABLE_LIST *table_list, + List *fields, + List *values, + COND *conds, + ulong options, + enum enum_duplicates handle_duplicates, + SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex) { - int res; + bool res; multi_update *result; DBUG_ENTER("mysql_multi_update"); - if ((res= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(res); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); if ((res= mysql_multi_update_prepare(thd))) DBUG_RETURN(res); if (!(result= new multi_update(thd, table_list, fields, values, handle_duplicates))) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); thd->no_trans_update= 0; thd->abort_on_warning= test(thd->variables.sql_mode & @@ -696,7 +702,7 @@ int mysql_multi_update(THD *thd, result, unit, select_lex); delete result; thd->abort_on_warning= 0; - DBUG_RETURN(res); + DBUG_RETURN(TRUE); } @@ -1023,7 +1029,15 @@ bool multi_update::send_data(List ¬_used_values) table->status|= STATUS_UPDATED; store_record(table,record[1]); if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0)) + { + /* Field::store methods can't send errors */ + if (!thd->net.report_error) + { + /* TODO: convert last warning to error */ + my_error(ER_UNKNOWN_ERROR, MYF(0)); + } DBUG_RETURN(1); + } found++; if (compare_record(table, thd->query_id)) { @@ -1087,7 +1101,7 @@ bool multi_update::send_data(List ¬_used_values) void multi_update::send_error(uint errcode,const char *err) { /* First send error what ever it is ... */ - ::send_error(thd,errcode,err); + my_error(errcode, MYF(0), err); /* If nothing updated return */ if (!updated) @@ -1278,7 +1292,6 @@ bool multi_update::send_eof() /* Safety: If we haven't got an error before (should not happen) */ my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update", MYF(0)); - ::send_error(thd); return 1; } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 4cdbfe9728b..7894287aee4 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -41,13 +41,12 @@ TYPELIB updatable_views_with_limit_typelib= mode - VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE RETURN VALUE - 0 OK - -1 Error - 1 Error and error message given + FALSE OK + TRUE Error */ -int mysql_create_view(THD *thd, - enum_view_create_mode mode) +bool mysql_create_view(THD *thd, + enum_view_create_mode mode) { LEX *lex= thd->lex; bool link_to_local; @@ -57,7 +56,7 @@ int mysql_create_view(THD *thd, TABLE_LIST *tbl; SELECT_LEX *select_lex= &lex->select_lex, *sl; SELECT_LEX_UNIT *unit= &lex->unit; - int res= 0; + bool res= FALSE; DBUG_ENTER("mysql_create_view"); if (lex->proc_list.first || @@ -66,7 +65,7 @@ int mysql_create_view(THD *thd, my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), (lex->result ? "INTO" : "PROCEDURE")); - res= -1; + res= TRUE; goto err; } if (lex->derived_tables || @@ -75,7 +74,7 @@ int mysql_create_view(THD *thd, my_error((lex->derived_tables ? ER_VIEW_SELECT_DERIVED : ER_VIEW_SELECT_VARIABLE), MYF(0)); - res= -1; + res= TRUE; goto err; } @@ -101,7 +100,7 @@ int mysql_create_view(THD *thd, (check_access(thd, DELETE_ACL, view->db, &view->grant.privilege, 0, 0) || grant_option && check_grant(thd, DELETE_ACL, view, 0, 1, 0)))) - DBUG_RETURN(1); + DBUG_RETURN(TRUE); for (sl= select_lex; sl; sl= sl->next_select()) { for (tbl= sl->get_table_list(); tbl; tbl= tbl->next_local) @@ -119,7 +118,7 @@ int mysql_create_view(THD *thd, thd->priv_user, thd->host_or_ip, tbl->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } /* Mark this table as a table which will be checked after the prepare @@ -155,7 +154,7 @@ int mysql_create_view(THD *thd, &tbl->grant.privilege, 0, 0) || grant_option && check_grant(thd, SELECT_ACL, tbl, 0, 1, 0)) { - res= 1; + res= TRUE; goto err; } } @@ -177,8 +176,8 @@ int mysql_create_view(THD *thd, } #endif - if ((res= open_and_lock_tables(thd, tables))) - DBUG_RETURN(res); + if (open_and_lock_tables(thd, tables)) + DBUG_RETURN(TRUE); /* check that tables are not temporary and this VIEW do not used in query @@ -190,7 +189,7 @@ int mysql_create_view(THD *thd, if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view) { my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); - res= -1; + res= TRUE; goto err; } @@ -200,7 +199,7 @@ int mysql_create_view(THD *thd, strcmp(tbl->view_name.str, view->real_name) == 0) { my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str); - res= -1; + res= TRUE; goto err; } @@ -220,7 +219,7 @@ int mysql_create_view(THD *thd, some errors from prepare are reported to user, if is not then it will be checked after err: label */ - res= 1; + res= TRUE; goto err; } @@ -255,7 +254,7 @@ int mysql_create_view(THD *thd, if (strcmp(item->name, check->name) == 0) { my_error(ER_DUP_FIELDNAME, MYF(0), item->name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } @@ -294,7 +293,7 @@ int mysql_create_view(THD *thd, thd->host_or_ip, item->name, view->real_name); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } } } @@ -303,7 +302,7 @@ int mysql_create_view(THD *thd, if (wait_if_global_read_lock(thd, 0, 0)) { - res= -1; + res= TRUE; goto err; } VOID(pthread_mutex_lock(&LOCK_open)); @@ -321,9 +320,7 @@ err: thd->proc_info= "end"; lex->link_first_table_back(view, link_to_local); unit->cleanup(); - if (thd->net.report_error) - res= -1; - DBUG_RETURN(res); + DBUG_RETURN(res || thd->net.report_error); } @@ -824,12 +821,11 @@ err: drop_mode - cascade/check RETURN VALUE - 0 OK - -1 Error - 1 Error and error message given + FALSE OK + TRUE Error */ -int mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) +bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { DBUG_ENTER("mysql_drop_view"); char path[FN_REFLEN]; @@ -865,11 +861,11 @@ int mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) VOID(pthread_mutex_unlock(&LOCK_open)); } send_ok(thd); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); err: VOID(pthread_mutex_unlock(&LOCK_open)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } diff --git a/sql/sql_view.h b/sql/sql_view.h index 538f548d97b..4cb2514f5b9 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -16,12 +16,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -int mysql_create_view(THD *thd, - enum_view_create_mode mode); +bool mysql_create_view(THD *thd, + enum_view_create_mode mode); my_bool mysql_make_view(File_parser *parser, TABLE_LIST *table); -int mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode); +bool mysql_drop_view(THD *thd, TABLE_LIST *view, enum_drop_mode drop_mode); bool check_key_in_view(THD *thd, TABLE_LIST * view); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 31016b59c6f..fe25d689b4b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -810,7 +810,7 @@ query: if (!thd->bootstrap && (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT))) { - send_error(thd,ER_EMPTY_QUERY); + my_error(ER_EMPTY_QUERY, MYF(0)); YYABORT; } else @@ -1146,7 +1146,7 @@ create: if (lex->sphead) { - net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE"); + my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "PROCEDURE"); YYABORT; } /* Order is important here: new - reset - init */ @@ -1219,7 +1219,7 @@ create: if (lex->sphead) { - net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "TRIGGER"); + my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "TRIGGER"); YYABORT; } @@ -1300,7 +1300,7 @@ create_function_tail: if (lex->sphead) { - net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION"); + my_error(ER_SP_NO_RECURSIVE_CREATE, MYF(0), "FUNCTION"); YYABORT; } /* Order is important here: new - reset - init */ @@ -1455,7 +1455,7 @@ sp_fdparam: if (spc->find_pvar(&$1, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_PARAM, $1.str); + my_error(ER_SP_DUP_PARAM, MYF(0), $1.str); YYABORT; } spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in); @@ -1481,7 +1481,7 @@ sp_pdparam: if (spc->find_pvar(&$2, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_PARAM, $2.str); + my_error(ER_SP_DUP_PARAM, MYF(0), $2.str); YYABORT; } spc->push_pvar(&$2, (enum enum_field_types)$3, @@ -1515,12 +1515,12 @@ sp_decls: better error handling this way.) */ if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs)) { /* Variable or condition following cursor or handler */ - send_error(YYTHD, ER_SP_VARCOND_AFTER_CURSHNDLR); + my_error(ER_SP_VARCOND_AFTER_CURSHNDLR, MYF(0)); YYABORT; } if ($2.curs && $1.hndlrs) { /* Cursor following handler */ - send_error(YYTHD, ER_SP_CURSOR_AFTER_HANDLER); + my_error(ER_SP_CURSOR_AFTER_HANDLER, MYF(0)); YYABORT; } $$.vars= $1.vars + $2.vars; @@ -1568,7 +1568,7 @@ sp_decl: if (spc->find_cond(&$2, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_COND, $2.str); + my_error(ER_SP_DUP_COND, MYF(0), $2.str); YYABORT; } YYTHD->lex->spcont->push_cond(&$2, $5); @@ -1625,7 +1625,7 @@ sp_decl: if (ctx->find_cursor(&$2, &offp, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_CURS, $2.str); + my_error(ER_SP_DUP_CURS, MYF(0), $2.str); delete $5; YYABORT; } @@ -1652,12 +1652,12 @@ sp_cursor_stmt: if (lex->sql_command != SQLCOM_SELECT) { - send_error(YYTHD, ER_SP_BAD_CURSOR_QUERY); + my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0)); YYABORT; } if (lex->result) { - send_error(YYTHD, ER_SP_BAD_CURSOR_SELECT); + my_error(ER_SP_BAD_CURSOR_SELECT, MYF(0)); YYABORT; } lex->sp_lex_in_use= TRUE; @@ -1727,7 +1727,7 @@ sp_hcond: $$= Lex->spcont->find_cond(&$1); if ($$ == NULL) { - net_printf(YYTHD, ER_SP_COND_MISMATCH, $1.str); + my_error(ER_SP_COND_MISMATCH, MYF(0), $1.str); YYABORT; } } @@ -1756,7 +1756,7 @@ sp_decl_idents: if (spc->find_pvar(&$1, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_VAR, $1.str); + my_error(ER_SP_DUP_VAR, MYF(0), $1.str); YYABORT; } spc->push_pvar(&$1, (enum_field_types)0, sp_param_in); @@ -1769,7 +1769,7 @@ sp_decl_idents: if (spc->find_pvar(&$3, TRUE)) { - net_printf(YYTHD, ER_SP_DUP_VAR, $3.str); + my_error(ER_SP_DUP_VAR, MYF(0), $3.str); YYABORT; } spc->push_pvar(&$3, (enum_field_types)0, sp_param_in); @@ -1802,7 +1802,7 @@ sp_proc_stmt: } if (lex->sql_command == SQLCOM_CHANGE_DB) { /* "USE db" doesn't work in a procedure */ - send_error(YYTHD, ER_SP_NO_USE); + my_error(ER_SP_NO_USE, MYF(0)); YYABORT; } /* Don't add an instruction for empty SET statements. @@ -1821,7 +1821,7 @@ sp_proc_stmt: */ if (sp->m_type != TYPE_ENUM_PROCEDURE) { - send_error(YYTHD, ER_SP_BADSTATEMENT); + my_error(ER_SP_BADSTATEMENT, MYF(0)); YYABORT; } else @@ -1851,7 +1851,7 @@ sp_proc_stmt: if (lex->sphead->m_type == TYPE_ENUM_PROCEDURE) { - send_error(YYTHD, ER_SP_BADRETURN); + my_error(ER_SP_BADRETURN, MYF(0)); YYABORT; } else @@ -1860,7 +1860,7 @@ sp_proc_stmt: if ($2->type() == Item::SUBSELECT_ITEM) { /* QQ For now, just disallow subselects as values */ - send_error(lex->thd, ER_SP_BADSTATEMENT); + my_error(ER_SP_BADSTATEMENT, MYF(0)); YYABORT; } i= new sp_instr_freturn(lex->sphead->instructions(), @@ -1923,7 +1923,7 @@ sp_proc_stmt: if (! lab) { - net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE", $2.str); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "LEAVE", $2.str); YYABORT; } else @@ -1953,7 +1953,7 @@ sp_proc_stmt: if (! lab || lab->type != SP_LAB_ITER) { - net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE", $2.str); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "ITERATE", $2.str); YYABORT; } else @@ -1981,7 +1981,7 @@ sp_proc_stmt: if (lab) { - net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $2.str); + my_error(ER_SP_LABEL_REDEFINE, MYF(0), $2.str); YYABORT; } else @@ -2005,7 +2005,7 @@ sp_proc_stmt: if (sp->m_in_handler) { - send_error(lex->thd, ER_SP_GOTO_IN_HNDLR); + my_error(ER_SP_GOTO_IN_HNDLR, MYF(0)); YYABORT; } lab= ctx->find_label($2.str); @@ -2056,7 +2056,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); YYABORT; } i= new sp_instr_copen(sp->instructions(), lex->spcont, offset); @@ -2071,7 +2071,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); YYABORT; } i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset); @@ -2088,7 +2088,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); YYABORT; } i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset); @@ -2106,7 +2106,7 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$1))) { - net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); YYABORT; } else @@ -2128,7 +2128,7 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$3))) { - net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $3.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str); YYABORT; } else @@ -2252,7 +2252,7 @@ sp_labeled_control: if (lab) { - net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $1.str); + my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str); YYABORT; } else @@ -2273,7 +2273,7 @@ sp_labeled_control: if (!lab || my_strcasecmp(system_charset_info, $5.str, lab->name) != 0) { - net_printf(YYTHD, ER_SP_LABEL_MISMATCH, $5.str); + my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str); YYABORT; } } @@ -2531,9 +2531,9 @@ default_charset: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - net_printf(YYTHD, ER_CONFLICTING_DECLARATIONS, - "CHARACTER SET ", cinfo->default_table_charset->csname, - "CHARACTER SET ", $4->csname); + my_error(ER_CONFLICTING_DECLARATIONS, MYF(0), + "CHARACTER SET ", cinfo->default_table_charset->csname, + "CHARACTER SET ", $4->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2548,8 +2548,8 @@ default_collation: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH, - $4->name, cinfo->default_table_charset->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $4->name, cinfo->default_table_charset->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2561,7 +2561,7 @@ storage_engines: { $$ = ha_resolve_by_name($1.str,$1.length); if ($$ == DB_TYPE_UNKNOWN) { - net_printf(YYTHD, ER_UNKNOWN_STORAGE_ENGINE, $1.str); + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str); YYABORT; } }; @@ -2740,18 +2740,19 @@ type: $$=FIELD_TYPE_TINY_BLOB; } | BLOB_SYM opt_len { Lex->charset=&my_charset_bin; $$=FIELD_TYPE_BLOB; } - | spatial_type { + | spatial_type + { #ifdef HAVE_SPATIAL - Lex->charset=&my_charset_bin; - Lex->uint_geom_type= (uint)$1; - $$=FIELD_TYPE_GEOMETRY; + Lex->charset=&my_charset_bin; + Lex->uint_geom_type= (uint)$1; + $$=FIELD_TYPE_GEOMETRY; #else - net_printf(Lex->thd, ER_FEATURE_DISABLED, - sym_group_geom.name, - sym_group_geom.needed_define); - YYABORT; + my_error(ER_FEATURE_DISABLED, MYF(0) + sym_group_geom.name, + sym_group_geom.needed_define); + YYABORT; #endif - } + } | MEDIUMBLOB { Lex->charset=&my_charset_bin; $$=FIELD_TYPE_MEDIUM_BLOB; } | LONGBLOB { Lex->charset=&my_charset_bin; @@ -2915,8 +2916,8 @@ attribute: { if (Lex->charset && !my_charset_same(Lex->charset,$2)) { - net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH, - $2->name,Lex->charset->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $2->name,Lex->charset->csname); YYABORT; } else @@ -2941,7 +2942,7 @@ charset_name: { if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0)))) { - net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); YYABORT; } } @@ -2959,7 +2960,7 @@ old_or_new_charset_name: if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) && !($$=get_old_charset_by_name($1.str))) { - net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,$1.str); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); YYABORT; } } @@ -2975,7 +2976,7 @@ collation_name: { if (!($$=get_charset_by_name($1.str,MYF(0)))) { - net_printf(YYTHD,ER_UNKNOWN_COLLATION,$1.str); + my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str); YYABORT; } }; @@ -2999,9 +3000,10 @@ opt_binary: | BYTE_SYM { Lex->charset=&my_charset_bin; } | UNICODE_SYM { - if (!(Lex->charset=get_charset_by_csname("ucs2",MY_CS_PRIMARY,MYF(0)))) + if (!(Lex->charset=get_charset_by_csname("ucs2", + MY_CS_PRIMARY,MYF(0)))) { - net_printf(YYTHD,ER_UNKNOWN_CHARACTER_SET,"ucs2"); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), "ucs2"); YYABORT; } } @@ -3063,8 +3065,8 @@ key_type: #ifdef HAVE_SPATIAL $$= Key::SPATIAL; #else - net_printf(Lex->thd, ER_FEATURE_DISABLED, - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif }; @@ -3096,8 +3098,8 @@ opt_unique_or_fulltext: #ifdef HAVE_SPATIAL $$= Key::SPATIAL; #else - net_printf(Lex->thd, ER_FEATURE_DISABLED, - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif } @@ -3324,7 +3326,7 @@ alter_list_item: if (check_table_name($3->table.str,$3->table.length) || $3->db.str && check_db_name($3->db.str)) { - net_printf(lex->thd,ER_WRONG_TABLE_NAME,$3->table.str); + my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str); YYABORT; } lex->alter_info.flags|= ALTER_RENAME; @@ -3339,8 +3341,8 @@ alter_list_item: $5= $5 ? $5 : $4; if (!my_charset_same($4,$5)) { - net_printf(YYTHD,ER_COLLATION_CHARSET_MISMATCH, - $5->name,$4->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $5->name, $4->csname); YYABORT; } LEX *lex= Lex; @@ -3462,7 +3464,7 @@ slave_until: !((lex->mi.log_file_name && lex->mi.pos) || (lex->mi.relay_log_name && lex->mi.relay_log_pos))) { - send_error(lex->thd, ER_BAD_SLAVE_UNTIL_COND); + my_error(ER_BAD_SLAVE_UNTIL_COND, MYF(0)); YYABORT; } @@ -4175,9 +4177,9 @@ simple_expr: { if (!$1.symbol->create_func) { - net_printf(Lex->thd, ER_FEATURE_DISABLED, - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(void))($1.symbol->create_func))(); @@ -4186,9 +4188,9 @@ simple_expr: { if (!$1.symbol->create_func) { - net_printf(Lex->thd, ER_FEATURE_DISABLED, - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*))($1.symbol->create_func))($3); @@ -4197,9 +4199,9 @@ simple_expr: { if (!$1.symbol->create_func) { - net_printf(Lex->thd, ER_FEATURE_DISABLED, - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5); @@ -4208,9 +4210,9 @@ simple_expr: { if (!$1.symbol->create_func) { - net_printf(Lex->thd, ER_FEATURE_DISABLED, - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7); @@ -4311,8 +4313,8 @@ simple_expr: #ifdef HAVE_SPATIAL $$= $1; #else - net_printf(Lex->thd, ER_FEATURE_DISABLED, - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif } @@ -5168,12 +5170,12 @@ olap_opt: LEX *lex=Lex; if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE) { - net_printf(lex->thd, ER_WRONG_USAGE, "WITH CUBE", + my_error(ER_WRONG_USAGE, MYF(0), "WITH CUBE", "global union parameters"); YYABORT; } lex->current_select->olap= CUBE_TYPE; - net_printf(lex->thd, ER_NOT_SUPPORTED_YET, "CUBE"); + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "CUBE"); YYABORT; /* To be deleted in 5.1 */ } | WITH ROLLUP_SYM @@ -5181,7 +5183,7 @@ olap_opt: LEX *lex= Lex; if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE) { - net_printf(lex->thd, ER_WRONG_USAGE, "WITH ROLLUP", + my_error(ER_WRONG_USAGE, MYF(0), "WITH ROLLUP", "global union parameters"); YYABORT; } @@ -5205,9 +5207,8 @@ order_clause: lex->current_select->olap != UNSPECIFIED_OLAP_TYPE) { - net_printf(lex->thd, ER_WRONG_USAGE, - "CUBE/ROLLUP", - "ORDER BY"); + my_error(ER_WRONG_USAGE, MYF(0), + "CUBE/ROLLUP", "ORDER BY"); YYABORT; } } order_list; @@ -5305,9 +5306,7 @@ procedure_clause: LEX *lex=Lex; if (&lex->select_lex != lex->current_select) { - net_printf(lex->thd, ER_WRONG_USAGE, - "PROCEDURE", - "subquery"); + my_error(ER_WRONG_USAGE, MYF(0), "PROCEDURE", "subquery"); YYABORT; } lex->proc_list.elements=0; @@ -5371,7 +5370,7 @@ select_var_ident: if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1))) { - net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); YYABORT; } if (! lex->result) @@ -5466,7 +5465,7 @@ drop: LEX *lex=Lex; if (lex->sphead) { - net_printf(YYTHD, ER_SP_NO_DROP_SP, "FUNCTION"); + my_error(ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"); YYABORT; } lex->sql_command = SQLCOM_DROP_FUNCTION; @@ -5478,7 +5477,7 @@ drop: LEX *lex=Lex; if (lex->sphead) { - net_printf(YYTHD, ER_SP_NO_DROP_SP, "PROCEDURE"); + my_error(ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE"); YYABORT; } lex->sql_command = SQLCOM_DROP_PROCEDURE; @@ -5726,8 +5725,8 @@ update: else if (lex->select_lex.get_table_list()->derived) { /* it is single table update and it is update of derived table */ - net_printf(lex->thd, ER_NON_UPDATABLE_TABLE, - lex->select_lex.get_table_list()->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), + lex->select_lex.get_table_list()->alias, "UPDATE"); YYABORT; } } @@ -6049,7 +6048,7 @@ show_engine_param: Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; break; default: - net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "STATUS"); + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "STATUS"); YYABORT; } } @@ -6060,7 +6059,7 @@ show_engine_param: Lex->sql_command = SQLCOM_SHOW_LOGS; break; default: - net_printf(YYTHD, ER_NOT_SUPPORTED_YET, "LOGS"); + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "LOGS"); YYABORT; } }; @@ -6212,7 +6211,7 @@ purge_option: { if ($2->check_cols(1) || $2->fix_fields(Lex->thd, 0, &$2)) { - net_printf(Lex->thd, ER_WRONG_ARGUMENTS, "PURGE LOGS BEFORE"); + my_error(ER_WRONG_ARGUMENTS, MYF(0), "PURGE LOGS BEFORE"); YYABORT; } Item *tmp= new Item_func_unix_timestamp($2); @@ -6234,7 +6233,7 @@ kill: LEX *lex=Lex; if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1)) { - send_error(lex->thd, ER_SET_CONSTANTS_ONLY); + my_error(ER_SET_CONSTANTS_ONLY, MYF(0)); YYABORT; } lex->sql_command=SQLCOM_KILL; @@ -6381,7 +6380,7 @@ param_marker: (uchar *) thd->query)); if (!($$= item) || lex->param_list.push_back(item)) { - send_error(thd, ER_OUT_OF_RESOURCES); + my_error(ER_OUT_OF_RESOURCES, MYF(0)); YYABORT; } } @@ -6437,7 +6436,6 @@ NUM_literal: $$= new Item_real($1.str, $1.length); if (YYTHD->net.report_error) { - send_error(YYTHD, 0, NullS); YYABORT; } } @@ -6446,7 +6444,6 @@ NUM_literal: $$ = new Item_float($1.str, $1.length); if (YYTHD->net.report_error) { - send_error(YYTHD, 0, NullS); YYABORT; } } @@ -6541,16 +6538,14 @@ simple_ident_q: if (lex->trg_chistics.event == TRG_EVENT_INSERT && !new_row) { - net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "OLD", - "on INSERT"); + my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "OLD", "on INSERT"); YYABORT; } if (lex->trg_chistics.event == TRG_EVENT_DELETE && new_row) { - net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW", - "on DELETE"); + my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), "NEW", "on DELETE"); YYABORT; } @@ -6567,8 +6562,8 @@ simple_ident_q: FIXME. Far from perfect solution. See comment for "SET NEW.field_name:=..." for more info. */ - net_printf(YYTHD, ER_BAD_FIELD_ERROR, $3.str, - new_row ? "NEW": "OLD"); + my_error(ER_BAD_FIELD_ERROR, MYF(0), $3.str, + new_row ? "NEW": "OLD"); YYABORT; } @@ -6655,8 +6650,8 @@ IDENT_sys: $1.length); if (wlen < $1.length) { - net_printf(YYTHD, ER_INVALID_CHARACTER_STRING, cs->csname, - $1.str + wlen); + my_error(ER_INVALID_CHARACTER_STRING, MYF(0), cs->csname, + $1.str + wlen); YYABORT; } $$= $1; @@ -7034,7 +7029,7 @@ option_value: */ if (lex->query_tables) { - send_error(YYTHD, ER_SP_SUBSELECT_NYI); + my_error(ER_SP_SUBSELECT_NYI, MYF(0)); YYABORT; } sp_instr_set_user_var *i= @@ -7057,7 +7052,7 @@ option_value: sp_instr_set_trigger_field *i; if (lex->query_tables) { - send_error(YYTHD, ER_SP_SUBSELECT_NYI); + my_error(ER_SP_SUBSELECT_NYI, MYF(0)); YYABORT; } if ($3) @@ -7086,7 +7081,7 @@ option_value: Error message also should be improved. */ - net_printf(YYTHD, ER_BAD_FIELD_ERROR, $1.base_name, "NEW"); + my_error(ER_BAD_FIELD_ERROR, MYF(0), $1.base_name, "NEW"); YYABORT; } lex->sphead->add_instr(i); @@ -7152,7 +7147,8 @@ option_value: $3= $3 ? $3 : $2; if (!my_charset_same($2,$3)) { - net_printf(thd,ER_COLLATION_CHARSET_MISMATCH,$3->name,$2->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $3->name, $2->csname); YYABORT; } lex->var_list.push_back(new set_var_collation_client($3,$3,$3)); @@ -7218,18 +7214,18 @@ internal_variable_name: { if ($1.str[0]=='O' || $1.str[0]=='o') { - net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "OLD", ""); + my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "OLD", ""); YYABORT; } if (lex->trg_chistics.event == TRG_EVENT_DELETE) { - net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW", - "on DELETE"); + my_error(ER_TRG_NO_SUCH_ROW_IN_TRG, MYF(0), + "NEW", "on DELETE"); YYABORT; } if (lex->trg_chistics.action_time == TRG_ACTION_AFTER) { - net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "NEW", "after "); + my_error(ER_TRG_CANT_CHANGE_ROW, MYF(0), "NEW", "after "); YYABORT; } /* This special combination will denote field of NEW row */ @@ -7242,7 +7238,7 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); $$.var= tmp; $$.base_name= $1; } @@ -7253,7 +7249,7 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); $$.var= tmp; $$.base_name.str= (char*) "default"; $$.base_name.length= 7; @@ -7498,7 +7494,7 @@ require_list_element: LEX *lex=Lex; if (lex->x509_subject) { - net_printf(lex->thd,ER_DUP_ARGUMENT, "SUBJECT"); + my_error(ER_DUP_ARGUMENT, MYF(0), "SUBJECT"); YYABORT; } lex->x509_subject=$2.str; @@ -7508,7 +7504,7 @@ require_list_element: LEX *lex=Lex; if (lex->x509_issuer) { - net_printf(lex->thd,ER_DUP_ARGUMENT, "ISSUER"); + my_error(ER_DUP_ARGUMENT, MYF(0), "ISSUER"); YYABORT; } lex->x509_issuer=$2.str; @@ -7518,7 +7514,7 @@ require_list_element: LEX *lex=Lex; if (lex->ssl_cipher) { - net_printf(lex->thd,ER_DUP_ARGUMENT, "CIPHER"); + my_error(ER_DUP_ARGUMENT, MYF(0), "CIPHER"); YYABORT; } lex->ssl_cipher=$2.str; @@ -7534,7 +7530,7 @@ opt_table: lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE); + my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); YYABORT; } } @@ -7546,7 +7542,7 @@ opt_table: lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE); + my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); YYABORT; } } @@ -7558,7 +7554,7 @@ opt_table: lex->grant= GLOBAL_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - send_error(lex->thd,ER_ILLEGAL_GRANT_FOR_TABLE); + my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); YYABORT; } } @@ -7743,7 +7739,7 @@ union_list: if (lex->exchange) { /* Only the last SELECT can have INTO...... */ - net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "INTO"); + my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO"); YYABORT; } if (lex->current_select->linkage == GLOBAL_OPTIONS_TYPE) From d409547de420ae0f928dfb5f37f8a794efc05b7d Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Wed, 20 Oct 2004 16:06:54 +0300 Subject: [PATCH 03/94] changed function name to prevent injection wrong code from 4.1 (WL#2133) --- mysql-test/r/rpl_rotate_logs.result | 2 +- mysql-test/t/rpl_rotate_logs.test | 2 +- sql/log_event.cc | 2 +- sql/mysqld.cc | 4 +-- sql/protocol.cc | 12 +++---- sql/protocol.h | 3 +- sql/sql_class.h | 2 -- sql/sql_parse.cc | 53 +++++++++++++---------------- sql/sql_repl.cc | 4 +-- 9 files changed, 39 insertions(+), 45 deletions(-) diff --git a/mysql-test/r/rpl_rotate_logs.result b/mysql-test/r/rpl_rotate_logs.result index 85071e13555..29dd1ead381 100644 --- a/mysql-test/r/rpl_rotate_logs.result +++ b/mysql-test/r/rpl_rotate_logs.result @@ -1,7 +1,7 @@ drop table if exists t1, t2, t3, t4; drop table if exists t1, t2, t3, t4; start slave; -ERROR HY000: Could not initialize master info structure; more error messages can be found in the MySQL error log +ERROR HY000: File '/home/bell/mysql/bk/work-error-5.0/mysql-test/var/slave-data/master.info' not found (Errcode: 13) start slave; ERROR HY000: Could not initialize master info structure; more error messages can be found in the MySQL error log change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root'; diff --git a/mysql-test/t/rpl_rotate_logs.test b/mysql-test/t/rpl_rotate_logs.test index c3c0ff5be10..4bb1acbf748 100644 --- a/mysql-test/t/rpl_rotate_logs.test +++ b/mysql-test/t/rpl_rotate_logs.test @@ -23,7 +23,7 @@ drop table if exists t1, t2, t3, t4; # START SLAVE will fail because it can't read the file (mode 000) # (system error 13) ---error 1201 +--error 1105 start slave; system chmod 600 var/slave-data/master.info; # It will fail again because the file is empty so the slave cannot get valuable diff --git a/sql/log_event.cc b/sql/log_event.cc index 01dcb2af21c..9c9e600edf0 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2587,7 +2587,7 @@ Slave: load data infile on table '%s' at log position %s in log \ my_afree(load_data_query); if (thd->query_error) { - /* this err/sql_errno code is copy-paste from send_error() */ + /* this err/sql_errno code is copy-paste from net_send_error() */ const char *err; int sql_errno; if ((err=thd->net.last_error)[0]) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index c408478cb15..f2c235cac99 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1331,7 +1331,7 @@ void close_connection(THD *thd, uint errcode, bool lock) if ((vio=thd->net.vio) != 0) { if (errcode) - send_error(thd, errcode, ER(errcode)); /* purecov: inspected */ + net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */ vio_close(vio); /* vio is freed in delete thd */ } if (lock) @@ -3396,7 +3396,7 @@ static void create_new_thread(THD *thd) thd->killed= THD::KILL_CONNECTION; // Safety (void) pthread_mutex_unlock(&LOCK_thread_count); statistic_increment(aborted_connects,&LOCK_status); - net_printf(thd,ER_CANT_CREATE_THREAD,error); + net_printf_error(thd, ER_CANT_CREATE_THREAD, error); (void) pthread_mutex_lock(&LOCK_thread_count); close_connection(thd,0,0); delete thd; diff --git a/sql/protocol.cc b/sql/protocol.cc index c92d25f3f4d..b8414e45c97 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -53,14 +53,14 @@ bool Protocol_prep::net_store_data(const char *from, uint length) /* Send a error string to client */ -void send_error(THD *thd, uint sql_errno, const char *err) +void net_send_error(THD *thd, uint sql_errno, const char *err) { #ifndef EMBEDDED_LIBRARY uint length; char buff[MYSQL_ERRMSG_SIZE+2], *pos; #endif NET *net= &thd->net; - DBUG_ENTER("send_error"); + DBUG_ENTER("net_send_error"); DBUG_PRINT("enter",("sql_errno: %d err: %s", sql_errno, err ? err : net->last_error[0] ? net->last_error : "NULL")); @@ -169,7 +169,7 @@ void send_warning(THD *thd, uint sql_errno, const char *err) */ void -net_printf(THD *thd, uint errcode, ...) +net_printf_error(THD *thd, uint errcode, ...) { va_list args; uint length,offset; @@ -182,7 +182,7 @@ net_printf(THD *thd, uint errcode, ...) #endif NET *net= &thd->net; - DBUG_ENTER("net_printf"); + DBUG_ENTER("net_printf_error"); DBUG_PRINT("enter",("message: %u",errcode)); if (thd->spcont && thd->spcont->find_handler(errcode, @@ -196,8 +196,8 @@ net_printf(THD *thd, uint errcode, ...) #endif va_start(args,errcode); /* - The following is needed to make net_printf() work with 0 argument for - errorcode and use the argument after that as the format string. This + The following is needed to make net_printf_error() work with 0 argument + for errorcode and use the argument after that as the format string. This is useful for rare errors that are not worth the hassle to put in errmsg.sys, but at the same time, the message is not fixed text */ diff --git a/sql/protocol.h b/sql/protocol.h index 1a5896a3ae5..b65a666a5b1 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -172,7 +172,8 @@ public: }; void send_warning(THD *thd, uint sql_errno, const char *err=0); -void net_printf(THD *thd,uint sql_errno, ...); +void net_printf_error(THD *thd, uint sql_errno, ...); +void net_send_error(THD *thd, uint sql_errno=0, const char *err=0); void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L, const char *info=0); void send_eof(THD *thd, bool no_flush=0); diff --git a/sql/sql_class.h b/sql/sql_class.h index f014a597169..46cf8ca4899 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1196,8 +1196,6 @@ public: class JOIN; -void send_error(THD *thd, uint sql_errno=0, const char *err=0); - class select_result :public Sql_alloc { protected: THD *thd; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 8817a29a705..ed174162db8 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -165,7 +165,7 @@ static int get_or_create_user_conn(THD *thd, const char *user, my_malloc(sizeof(struct user_conn) + temp_len+1, MYF(MY_WME))))) { - send_error(thd, 0, NullS); // Out of memory + net_send_error(thd, 0, NullS); // Out of memory return_val=1; goto end; } @@ -183,7 +183,7 @@ static int get_or_create_user_conn(THD *thd, const char *user, if (my_hash_insert(&hash_user_connections, (byte*) uc)) { my_free((char*) uc,0); - send_error(thd, 0, NullS); // Out of memory + net_send_error(thd, 0, NullS); // Out of memory return_val=1; goto end; } @@ -258,7 +258,7 @@ int check_user(THD *thd, enum enum_server_command command, */ if (opt_secure_auth_local && passwd_len == SCRAMBLE_LENGTH_323) { - net_printf(thd, ER_NOT_SUPPORTED_AUTH_MODE); + net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE); mysql_log.write(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN(-1); } @@ -290,8 +290,8 @@ int check_user(THD *thd, enum enum_server_command command, NET *net= &thd->net; if (opt_secure_auth_local) { - net_printf(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE, - thd->user, thd->host_or_ip); + net_printf_error(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE, + thd->user, thd->host_or_ip); mysql_log.write(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE), thd->user, thd->host_or_ip); DBUG_RETURN(-1); @@ -330,7 +330,7 @@ int check_user(THD *thd, enum enum_server_command command, VOID(pthread_mutex_unlock(&LOCK_thread_count)); if (!count_ok) { // too many connections - send_error(thd, ER_CON_COUNT_ERROR); + net_send_error(thd, ER_CON_COUNT_ERROR); DBUG_RETURN(-1); } } @@ -380,14 +380,14 @@ int check_user(THD *thd, enum enum_server_command command, } else if (res == 2) // client gave short hash, server has long hash { - net_printf(thd, ER_NOT_SUPPORTED_AUTH_MODE); + net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE); mysql_log.write(thd,COM_CONNECT,ER(ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN(-1); } - net_printf(thd, ER_ACCESS_DENIED_ERROR, - thd->user, - thd->host_or_ip, - passwd_len ? ER(ER_YES) : ER(ER_NO)); + net_printf_error(thd, ER_ACCESS_DENIED_ERROR, + thd->user, + thd->host_or_ip, + passwd_len ? ER(ER_YES) : ER(ER_NO)); mysql_log.write(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR), thd->user, thd->host_or_ip, @@ -450,16 +450,16 @@ static int check_for_max_user_connections(THD *thd, USER_CONN *uc) if (max_user_connections && max_user_connections < (uint) uc->connections) { - net_printf(thd,ER_TOO_MANY_USER_CONNECTIONS, uc->user); + net_printf_error(thd, ER_TOO_MANY_USER_CONNECTIONS, uc->user); error=1; goto end; } if (uc->user_resources.connections && uc->user_resources.connections <= uc->conn_per_hour) { - net_printf(thd, ER_USER_LIMIT_REACHED, uc->user, - "max_connections", - (long) uc->user_resources.connections); + net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, + "max_connections", + (long) uc->user_resources.connections); error=1; goto end; } @@ -585,8 +585,8 @@ static bool check_mqh(THD *thd, uint check_command) if (uc->user_resources.questions && uc->questions++ >= uc->user_resources.questions) { - net_printf(thd, ER_USER_LIMIT_REACHED, uc->user, "max_questions", - (long) uc->user_resources.questions); + net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, "max_questions", + (long) uc->user_resources.questions); error=1; goto end; } @@ -596,8 +596,8 @@ static bool check_mqh(THD *thd, uint check_command) if (uc->user_resources.updates && uc_update_queries[check_command] && uc->updates++ >= uc->user_resources.updates) { - net_printf(thd, ER_USER_LIMIT_REACHED, uc->user, "max_updates", - (long) uc->user_resources.updates); + net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, "max_updates", + (long) uc->user_resources.updates); error=1; goto end; } @@ -1001,7 +1001,7 @@ pthread_handler_decl(handle_one_connection,arg) if ((error=check_connection(thd))) { // Wrong permissions if (error > 0) - net_printf(thd,error,thd->host_or_ip); + net_printf_error(thd, error, thd->host_or_ip); #ifdef __NT__ if (vio_type(net->vio) == VIO_TYPE_NAMEDPIPE) my_sleep(1000); /* must wait after eof() */ @@ -1044,7 +1044,7 @@ pthread_handler_decl(handle_one_connection,arg) thd->host_or_ip, (net->last_errno ? ER(net->last_errno) : ER(ER_UNKNOWN_ERROR))); - send_error(thd,net->last_errno,NullS); + net_send_error(thd, net->last_errno, NullS); statistic_increment(aborted_threads,&LOCK_status); } else if (thd->killed) @@ -1113,7 +1113,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) uint length=(uint) strlen(buff); if (buff[length-1]!='\n' && !feof(file)) { - send_error(thd,ER_NET_PACKET_TOO_LARGE, NullS); + net_send_error(thd, ER_NET_PACKET_TOO_LARGE, NullS); thd->is_fatal_error= 1; break; } @@ -1267,7 +1267,7 @@ bool do_command(THD *thd) statistic_increment(aborted_threads,&LOCK_status); DBUG_RETURN(TRUE); // We have to close it. } - send_error(thd,net->last_errno,NullS); + net_send_error(thd, net->last_errno, NullS); net->error= 0; DBUG_RETURN(FALSE); } @@ -1808,7 +1808,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (thd->killed_errno() && !thd->net.report_error) thd->send_kill_message(); if (thd->is_fatal_error || thd->net.report_error) - send_error(thd); + net_send_error(thd); time_t start_of_query=thd->start_time; thd->end_time(); // Set start time @@ -3671,10 +3671,6 @@ create_error: goto error; #ifndef EMBEDDED_LIBRARY - /* - When executing substatements, they're assumed to send_error when - it happens, but not to send_ok. - */ my_bool nsok= thd->net.no_send_ok; thd->net.no_send_ok= TRUE; #endif @@ -3932,7 +3928,6 @@ create_error: DBUG_RETURN(res || thd->net.report_error); error: - /* We end up here if send_error() has already been done. */ DBUG_RETURN(TRUE); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index fe7e8432ec6..16daba09954 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -867,7 +867,7 @@ int start_slave(THD* thd , MASTER_INFO* mi, bool net_report) if (slave_errno) { if (net_report) - send_error(thd, slave_errno); + my_error(slave_errno, MYF(0)); DBUG_RETURN(1); } else if (net_report) @@ -917,7 +917,7 @@ int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report ) if (slave_errno) { if (net_report) - send_error(thd, slave_errno); + my_error(slave_errno, MYF(0)); return 1; } else if (net_report) From 5bf7a8c30b7fb3c21a8cd57b4dad9b05b2a3b521 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 28 Oct 2004 14:02:09 +0300 Subject: [PATCH 04/94] post-merge fix --- libmysqld/lib_sql.cc | 2 +- mysql-test/t/connect.test | 2 +- mysql-test/t/rpl_charset.test | 6 +++--- mysql-test/t/rpl_timezone.test | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index fdc1acea09b..85e4ccd48bf 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -664,7 +664,7 @@ bool Protocol::send_fields(List *list, int flags) DBUG_RETURN(prepare_for_send(list)); err: - send_error(thd, ER_OUT_OF_RESOURCES); /* purecov: inspected */ + my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 3ec2648fa7e..8e1a92a586e 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -49,7 +49,7 @@ flush privileges; #show tables; connect (con1,localhost,test,gambling2,mysql); set password=""; ---error 1371 +--error 1372 set password='gambling3'; set password=old_password('gambling3'); show tables; diff --git a/mysql-test/t/rpl_charset.test b/mysql-test/t/rpl_charset.test index e49ab7468a3..b270a704eaa 100644 --- a/mysql-test/t/rpl_charset.test +++ b/mysql-test/t/rpl_charset.test @@ -112,10 +112,10 @@ sync_slave_with_master; # Check that we can't change global.collation_server -error 1386; +error 1387; set global character_set_server=latin2; connection master; -error 1386; +error 1387; set global character_set_server=latin2; # Check that SET ONE_SHOT is really one shot @@ -129,7 +129,7 @@ select @@character_set_server; select @@character_set_server; # ONE_SHOT on not charset/collation stuff is not allowed -error 1381; +error 1382; set one_shot max_join_size=10; # Test of wrong character set numbers; diff --git a/mysql-test/t/rpl_timezone.test b/mysql-test/t/rpl_timezone.test index 03e910cd7ca..ebb58a9c880 100644 --- a/mysql-test/t/rpl_timezone.test +++ b/mysql-test/t/rpl_timezone.test @@ -76,7 +76,7 @@ select * from t2; # replication # connection master; ---error 1386 +--error 1387 set global time_zone='MET'; # Clean up From a3294186ec089d4b6abf318894e36cbf042f72c6 Mon Sep 17 00:00:00 2001 From: "marko@hundin.mysql.fi" <> Date: Mon, 1 Nov 2004 12:08:44 +0200 Subject: [PATCH 05/94] mysqld.cc: Describe innodb_max_purge_lag Improve description of innodb_table_locks --- sql/mysqld.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d36b441ac9a..768acd77c27 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3702,12 +3702,12 @@ struct my_option my_long_options[] = "Percentage of dirty pages allowed in bufferpool", (gptr*) &srv_max_buf_pool_modified_pct, (gptr*) &srv_max_buf_pool_modified_pct, 0, GET_ULONG, REQUIRED_ARG, 90, 0, 100, 0, 0, 0}, {"innodb_max_purge_lag", OPT_INNODB_MAX_PURGE_LAG, - "", + "Desired maximum length of the purge queue (0 = no limit)", (gptr*) &srv_max_purge_lag, (gptr*) &srv_max_purge_lag, 0, GET_LONG, REQUIRED_ARG, 0, 0, ~0L, 0, 1L, 0}, {"innodb_table_locks", OPT_INNODB_TABLE_LOCKS, - "If Innodb should enforce LOCK TABLE", + "Enable InnoDB locking in LOCK TABLES", (gptr*) &global_system_variables.innodb_table_locks, (gptr*) &global_system_variables.innodb_table_locks, 0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0}, From 10291f36647dfdf072db440c14a4faa5d072a371 Mon Sep 17 00:00:00 2001 From: "joerg@mysql.com" <> Date: Mon, 1 Nov 2004 18:15:45 +0100 Subject: [PATCH 06/94] Ensure that a source distribution contains 'libmysql/libmysql.def' which is needed for Netware ports. --- libmysql/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index fefed7f079c..3c4e98e5053 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -31,7 +31,7 @@ include $(srcdir)/Makefile.shared libmysqlclient_la_SOURCES = $(target_sources) libmysqlclient_la_LIBADD = $(target_libadd) libmysqlclient_la_LDFLAGS = $(target_ldflags) -EXTRA_DIST = Makefile.shared +EXTRA_DIST = Makefile.shared libmysql.def # This is called from the toplevel makefile link_sources: From 22269d451af650f887a7679ba6fffe7577d1c007 Mon Sep 17 00:00:00 2001 From: "heikki@hundin.mysql.fi" <> Date: Tue, 2 Nov 2004 13:21:11 +0200 Subject: [PATCH 07/94] ha_innodb.cc: Backport Jan's fix of the LOAD DATA INFILE REPLACE duplicate key error bug (Bug #5835) to 4.0 --- sql/ha_innodb.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index e747ff3210c..d57a9f73c91 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -2285,7 +2285,9 @@ ha_innobase::write_row( if (error == DB_DUPLICATE_KEY && (user_thd->lex.sql_command == SQLCOM_REPLACE || user_thd->lex.sql_command - == SQLCOM_REPLACE_SELECT)) { + == SQLCOM_REPLACE_SELECT + || (user_thd->lex.sql_command == SQLCOM_LOAD + && user_thd->lex.duplicates == DUP_REPLACE))) { skip_auto_inc_decr= TRUE; } From b0510c7fd46f462f9456d16cb8cba58d1dbe12c1 Mon Sep 17 00:00:00 2001 From: "tim@siva.hindu.god" <> Date: Tue, 2 Nov 2004 17:53:25 -0700 Subject: [PATCH 08/94] Portability fixes to mysqld_safe for non-Linux systems. Fix FIND_PROC for Solaris test, and fix if @IS_LINUX@ test in mysqld_safe itself. --- BitKeeper/etc/logging_ok | 1 + configure.in | 2 +- scripts/mysqld_safe.sh | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 060586b6874..a716afb2392 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -139,6 +139,7 @@ tim@bitch.mysql.fi tim@black.box tim@hundin.mysql.fi tim@sand.box +tim@siva.hindu.god tim@threads.polyesthetic.msg tim@white.box tim@work.mysql.com diff --git a/configure.in b/configure.in index d4ede468435..97a59258ba8 100644 --- a/configure.in +++ b/configure.in @@ -444,7 +444,7 @@ if $PS p $$ 2> /dev/null | grep $0 > /dev/null then FIND_PROC="$PS p \$\$PID | grep mysqld > /dev/null" # Solaris -elif $PS -p $$ 2> /dev/null | grep $0 > /dev/null +elif $PS -fp $$ 2> /dev/null | grep $0 > /dev/null then FIND_PROC="$PS -p \$\$PID | grep mysqld > /dev/null" # BSD style diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index b9e7ce21f79..da7e06f6c05 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -315,7 +315,7 @@ do break fi - if test @IS_LINUX@ -a $KILL_MYSQLD -eq 1 + if @IS_LINUX@ && test $KILL_MYSQLD -eq 1 then # Test if one process was hanging. # This is only a fix for Linux (running as base 3 mysqld processes) From b58cb6b50f5f311afc07ea035993e49c342a9422 Mon Sep 17 00:00:00 2001 From: "marko@hundin.mysql.fi" <> Date: Wed, 3 Nov 2004 14:56:48 +0200 Subject: [PATCH 09/94] InnoDB: fix bugs in the FOREIGN KEY parser (Bug #6340) --- innobase/dict/dict0dict.c | 55 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index 5ca31ecd422..aa5bab210ef 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -604,7 +604,7 @@ dict_table_get_on_id( } /************************************************************************ -Looks for column n postion in the clustered index. */ +Looks for column n position in the clustered index. */ ulint dict_table_get_nth_col_pos( @@ -2140,8 +2140,8 @@ dict_foreign_add_to_cache( /************************************************************************* Scans from pointer onwards. Stops if is at the start of a copy of -'string' where characters are compared without case sensitivity. Stops -also at '\0'. */ +'string' where characters are compared without case sensitivity, and +only outside `` or "" quotes. Stops also at '\0'. */ static const char* dict_scan_to( @@ -2150,31 +2150,34 @@ dict_scan_to( const char* ptr, /* in: scan from */ const char* string) /* in: look for this */ { - ibool success; - ulint i; -loop: - if (*ptr == '\0') { - return(ptr); - } - - success = TRUE; - - for (i = 0; i < ut_strlen(string); i++) { - if (toupper((ulint)(ptr[i])) != toupper((ulint)(string[i]))) { - success = FALSE; + char quote = '\0'; + for (; *ptr; ptr++) { + if (*ptr == quote) { + /* Closing quote character: do not look for + starting quote or the keyword. */ + quote = '\0'; + } else if (quote) { + /* Within quotes: do nothing. */ + } else if (*ptr == '`' || *ptr == '"') { + /* Starting quote: remember the quote character. */ + quote = *ptr; + } else { + /* Outside quotes: look for the keyword. */ + ulint i; + for (i = 0; string[i]; i++) { + if (toupper((ulint)(ptr[i])) + != toupper((ulint)(string[i]))) { + goto nomatch; + } + } break; + nomatch: + ; } } - if (success) { - - return(ptr); - } - - ptr++; - - goto loop; + return(ptr); } /************************************************************************* @@ -2762,13 +2765,13 @@ loop: ut_a(success); - if (!isspace(*ptr)) { + if (!isspace(*ptr) && *ptr != '"' && *ptr != '`') { goto loop; } - do { + while (isspace(*ptr)) { ptr++; - } while (isspace(*ptr)); + } /* read constraint name unless got "CONSTRAINT FOREIGN" */ if (ptr != ptr2) { From fa21feda932a9ccc68142dd04b18fe37daf15655 Mon Sep 17 00:00:00 2001 From: "dlenev@mysql.com" <> Date: Wed, 3 Nov 2004 17:59:03 +0000 Subject: [PATCH 10/94] Fix for bug #6387 "Queried timestamp values do not match the inserted value if server runs in time zone with leap seconds". Now in my_gmt_sec() function we take into account difference between our target and estimation in seconds part. --- mysql-test/Makefile.am | 2 + .../r/have_moscow_leap_timezone.require | 2 + mysql-test/r/timezone3.result | 41 ++++++++++++ mysql-test/std_data/Moscow_leap | Bin 0 -> 991 bytes mysql-test/t/timezone3-master.opt | 1 + mysql-test/t/timezone3.test | 59 ++++++++++++++++++ sql/time.cc | 23 +++++-- 7 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 mysql-test/r/have_moscow_leap_timezone.require create mode 100644 mysql-test/r/timezone3.result create mode 100644 mysql-test/std_data/Moscow_leap create mode 100644 mysql-test/t/timezone3-master.opt create mode 100644 mysql-test/t/timezone3.test diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index ba96c5947ba..8b0c096120a 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -32,6 +32,7 @@ dist-hook: $(INSTALL_DATA) $(srcdir)/r/*.result $(srcdir)/r/*.require $(distdir)/r $(INSTALL_DATA) $(srcdir)/std_data/*.dat $(srcdir)/std_data/*.001 $(distdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(distdir)/std_data + $(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(distdir)/std_data install-data-local: $(mkinstalldirs) \ @@ -50,6 +51,7 @@ install-data-local: $(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data $(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data + $(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data SUFFIXES = .sh diff --git a/mysql-test/r/have_moscow_leap_timezone.require b/mysql-test/r/have_moscow_leap_timezone.require new file mode 100644 index 00000000000..f27452d7770 --- /dev/null +++ b/mysql-test/r/have_moscow_leap_timezone.require @@ -0,0 +1,2 @@ +from_unixtime(1072904422) +2004-01-01 00:00:00 diff --git a/mysql-test/r/timezone3.result b/mysql-test/r/timezone3.result new file mode 100644 index 00000000000..2135dd33511 --- /dev/null +++ b/mysql-test/r/timezone3.result @@ -0,0 +1,41 @@ +drop table if exists t1; +create table t1 (i int, c varchar(20)); +insert into t1 values +(unix_timestamp("2004-01-01 00:00:00"), "2004-01-01 00:00:00"); +insert into t1 values +(unix_timestamp("2004-03-28 01:59:59"), "2004-03-28 01:59:59"), +(unix_timestamp("2004-03-28 02:30:00"), "2004-03-28 02:30:00"), +(unix_timestamp("2004-03-28 03:00:00"), "2004-03-28 03:00:00"); +insert into t1 values +(unix_timestamp('2004-05-01 00:00:00'),'2004-05-01 00:00:00'); +insert into t1 values +(unix_timestamp('2004-10-31 01:00:00'),'2004-10-31 01:00:00'), +(unix_timestamp('2004-10-31 02:00:00'),'2004-10-31 02:00:00'), +(unix_timestamp('2004-10-31 02:59:59'),'2004-10-31 02:59:59'), +(unix_timestamp('2004-10-31 04:00:00'),'2004-10-31 04:00:00'), +(unix_timestamp('2004-10-31 02:59:59'),'2004-10-31 02:59:59'); +insert into t1 values +(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'), +(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00'); +select i, from_unixtime(i), c from t1; +i from_unixtime(i) c +1072904422 2004-01-01 00:00:00 2004-01-01 00:00:00 +1080428421 2004-03-28 01:59:59 2004-03-28 01:59:59 +1080428422 2004-03-28 03:00:00 2004-03-28 02:30:00 +1080428422 2004-03-28 03:00:00 2004-03-28 03:00:00 +1083355222 2004-05-01 00:00:00 2004-05-01 00:00:00 +1099170022 2004-10-31 01:00:00 2004-10-31 01:00:00 +1099177222 2004-10-31 02:00:00 2004-10-31 02:00:00 +1099180821 2004-10-31 02:59:59 2004-10-31 02:59:59 +1099184422 2004-10-31 04:00:00 2004-10-31 04:00:00 +1099180821 2004-10-31 02:59:59 2004-10-31 02:59:59 +362793608 1981-07-01 03:59:59 1981-07-01 03:59:59 +362793610 1981-07-01 04:00:00 1981-07-01 04:00:00 +drop table t1; +create table t1 (ts timestamp); +insert into t1 values (19730101235900), (20040101235900); +select * from t1; +ts +19730101235900 +20040101235900 +drop table t1; diff --git a/mysql-test/std_data/Moscow_leap b/mysql-test/std_data/Moscow_leap new file mode 100644 index 0000000000000000000000000000000000000000..4994c005595dc06bc6d288e9ecea38307ce11c82 GIT binary patch literal 991 zcmWHE%1mRx1Ux_?5EcXCMkrfucD&q;xptps%+q==G4H!&$NZKEi3K-uITkXAX)Lr^ z=CDK{_rMZcqYX<%Gd3)>Wj?T6&NX1`63GNn_2oCkB<^^LbKH&+|HXe=;uYU*$=l98 zQfDULk>0c5kIb5he`M!0{gvw}{wrUT@>d}z^si!!+g~Lg^MA@V8vj&uB>$<(aQ#!` z{{3H_RlQ#Qt3-pwQ}GF!75gV>UbzsUb!4-n_Le)1I!n$r=}y_#q}Q^(S-)gKvq8$l zX2aOMEJj5$Sd4AwvzP=`v6{*@vYHviu$ui%X0wp4XtTKM%4YdHs?BPzI-B)vn>L$e z&TY24<=X7pRNL%lGqgFRv9~$4$g(-PzHD<&{?F#3db-Wk`5~Jd>)JMV<-=_5?@qCK zGB0KGJhz6;>v21q_qskdpEHZweESO6{MNL#`R4_(1@xr11%~If1?70Q1)B%7h4^T< zg^C-sh3W9Ng?$%kixAafi@5f!E%GZ5Thz82ZP8cWvBk{)$`-rj0$W`Db+-5^o7fWK zcd{kco@-08pUsvWyP+*bzLqW3c2Zj!$IP~L*^;*O7u9VUf5X}`PsFxm-L+`TUSZ#s zb1alCw?nZlZ<#q;eg<<}L7OC7VW0wAQR;8DVnZgj64$$Ir260> zt>VH8w#s*V+p0Enu~na&-&QkoSzGP8#&46d#rKnxUM*#tJ2k#)%%MxX^u>}~Q*K$@8| zJ(w9tvv7N~wE$^WUTyAHAkD_lW6uVp*#+JfwF7Amp>xZCE@I#moqwtmNOOrd{Nn=B z+>%L#-9Va0R`nGqd+{pXdJ1$i1E1==xqU#IU%mb!KadvC3ivt!NDJy1X#)MhAfzW8 nGYLow8$4GL2GSzNJ3OWUX;HHt0iX}T*%U}IFfalEm;ogKHtY+x literal 0 HcmV?d00001 diff --git a/mysql-test/t/timezone3-master.opt b/mysql-test/t/timezone3-master.opt new file mode 100644 index 00000000000..6910e6e6e8d --- /dev/null +++ b/mysql-test/t/timezone3-master.opt @@ -0,0 +1 @@ +--timezone=:$MYSQL_TEST_DIR/std_data/Moscow_leap diff --git a/mysql-test/t/timezone3.test b/mysql-test/t/timezone3.test new file mode 100644 index 00000000000..8910783cd85 --- /dev/null +++ b/mysql-test/t/timezone3.test @@ -0,0 +1,59 @@ +# +# Test of handling time zone with leap seconds. +# +# This test should be run with TZ=:$MYSQL_TEST_DIR/std_data/Moscow_leap +# This implies that this test should be run only on systems that interpret +# characters after colon in TZ variable as path to zoneinfo file. +# +# Check that we have successfully set time zone with leap seconds. +--require r/have_moscow_leap_timezone.require +disable_query_log; +select from_unixtime(1072904422); +enable_query_log; + +# Initial clean-up +--disable_warnings +drop table if exists t1; +--enable_warnings + +# +# Let us check behavior of conversion from broken-down representation +# to time_t representation, for normal, non-existent and ambigious dates +# (This check is similar to the one in timezone2.test in 4.1) +# +create table t1 (i int, c varchar(20)); +# Normal value without DST +insert into t1 values + (unix_timestamp("2004-01-01 00:00:00"), "2004-01-01 00:00:00"); +# Values around and in spring time-gap +insert into t1 values + (unix_timestamp("2004-03-28 01:59:59"), "2004-03-28 01:59:59"), + (unix_timestamp("2004-03-28 02:30:00"), "2004-03-28 02:30:00"), + (unix_timestamp("2004-03-28 03:00:00"), "2004-03-28 03:00:00"); +# Normal value with DST +insert into t1 values + (unix_timestamp('2004-05-01 00:00:00'),'2004-05-01 00:00:00'); +# Ambiguos values (also check for determenism) +insert into t1 values + (unix_timestamp('2004-10-31 01:00:00'),'2004-10-31 01:00:00'), + (unix_timestamp('2004-10-31 02:00:00'),'2004-10-31 02:00:00'), + (unix_timestamp('2004-10-31 02:59:59'),'2004-10-31 02:59:59'), + (unix_timestamp('2004-10-31 04:00:00'),'2004-10-31 04:00:00'), + (unix_timestamp('2004-10-31 02:59:59'),'2004-10-31 02:59:59'); +# Test of leap +insert into t1 values + (unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'), + (unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00'); + +select i, from_unixtime(i), c from t1; +drop table t1; + +# +# Test for bug #6387 "Queried timestamp values do not match the +# inserted". my_gmt_sec() function was not working properly if we +# had time zone with leap seconds +# +create table t1 (ts timestamp); +insert into t1 values (19730101235900), (20040101235900); +select * from t1; +drop table t1; diff --git a/sql/time.cc b/sql/time.cc index 0363d764100..38670db054f 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -81,6 +81,10 @@ long my_gmt_sec(TIME *t, long *my_timezone) I couldn't come up with a better way to get a repeatable result :( We can't use mktime() as it's buggy on many platforms and not thread safe. + + Note: this code assumes that our time_t estimation is not too far away + from real value (we assume that localtime_r(tmp) will return something + within 24 hrs from t) which is probably true for all current time zones. */ tmp=(time_t) (((calc_daynr((uint) t->year,(uint) t->month,(uint) t->day) - (long) days_at_timestart)*86400L + (long) t->hour*3600L + @@ -93,7 +97,8 @@ long my_gmt_sec(TIME *t, long *my_timezone) for (loop=0; loop < 2 && (t->hour != (uint) l_time->tm_hour || - t->minute != (uint) l_time->tm_min); + t->minute != (uint) l_time->tm_min || + t->second != (uint) l_time->tm_sec); loop++) { /* One check should be enough ? */ /* Get difference in days */ @@ -103,15 +108,22 @@ long my_gmt_sec(TIME *t, long *my_timezone) else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) + - (long) (60*((int) t->minute - (int) l_time->tm_min))); + (long) (60*((int) t->minute - (int) l_time->tm_min)) + + (long) ((int) t->second - (int) l_time->tm_sec)); current_timezone+= diff+3600; // Compensate for -3600 above tmp+= (time_t) diff; localtime_r(&tmp,&tm_tmp); l_time=&tm_tmp; } /* - Fix that if we are in the not existing daylight saving time hour - we move the start of the next real hour + Fix that if we are in the non existing daylight saving time hour + we move the start of the next real hour. + + This code doesn't handle such exotical thing as time-gaps whose length + is more than one hour or non-integer (latter can theoretically happen + if one of seconds will be removed due leap correction, or because of + general time correction like it happened for Africa/Monrovia time zone + in year 1972). */ if (loop == 2 && t->hour != (uint) l_time->tm_hour) { @@ -121,7 +133,8 @@ long my_gmt_sec(TIME *t, long *my_timezone) else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+ - (long) (60*((int) t->minute - (int) l_time->tm_min))); + (long) (60*((int) t->minute - (int) l_time->tm_min)) + + (long) ((int) t->second - (int) l_time->tm_sec)); if (diff == 3600) tmp+=3600 - t->minute*60 - t->second; // Move to next hour else if (diff == -3600) From cb0bd6f57d87ad2bc3691a9dce013ce7e9419cd7 Mon Sep 17 00:00:00 2001 From: "joerg@mysql.com" <> Date: Thu, 4 Nov 2004 11:18:12 +0100 Subject: [PATCH 11/94] The files stored in "Docs/Images" within the "mysqldocs" BK tree must be included in the source tar-ball for distribution. This is done by using the "DISTFILES" macro in a new "Docs/Images/Makefile". As the source BK tree does not contain these files, they are copied from the "mysqldocs" tree at release build time. This changeset relies on "bk commit - mysqldoc tree (joerg:1.2276)" of today. --- Build-tools/Bootstrap | 4 ++++ Docs/Images/Makefile.am | 35 +++++++++++++++++++++++++++++++++++ Docs/Makefile.am | 2 ++ configure.in | 2 +- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Docs/Images/Makefile.am diff --git a/Build-tools/Bootstrap b/Build-tools/Bootstrap index 8cad093bc5f..e21179fe78c 100755 --- a/Build-tools/Bootstrap +++ b/Build-tools/Bootstrap @@ -288,6 +288,10 @@ unless ($opt_skip_manual) system ("bk cat $opt_docdir/Docs/$file.texi > $target_dir/Docs/$file.texi") == 0 or &abort("Could not update $file.texi in $target_dir/Docs/!"); } + system ("rm $target_dir/Docs/Images/Makefile*") == 0 + or &abort("Could not remove Makefiles in $target_dir/Docs/Images/!"); + system ("cp $opt_docdir/Docs/Images/*.* $target_dir/Docs/Images") == 0 + or &abort("Could not copy image files in $target_dir/Docs/Images/!"); } # diff --git a/Docs/Images/Makefile.am b/Docs/Images/Makefile.am new file mode 100644 index 00000000000..b57d701d8a0 --- /dev/null +++ b/Docs/Images/Makefile.am @@ -0,0 +1,35 @@ +# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +# MA 02111-1307, USA + +## Process this file with automake to create Makefile.in + +# This is a dummy file to satisfy the hierarchy of Makefiles. +# When a release is built, the true Makefile will be copied +# together with the "real" files in this directory. + +EXTRA_DIST = + +# Nothing to create in this dummy directory. +all: + : + +# Nothing to cleanup in this dummy directory. +clean: + : + +# Don't update the files from bitkeeper +%::SCCS/s.% diff --git a/Docs/Makefile.am b/Docs/Makefile.am index a4e8e14a38d..e53ea195d94 100644 --- a/Docs/Makefile.am +++ b/Docs/Makefile.am @@ -24,6 +24,8 @@ BUILT_SOURCES = $(targets) manual_toc.html include.texi EXTRA_DIST = $(noinst_SCRIPTS) $(BUILT_SOURCES) mysqld_error.txt \ INSTALL-BINARY reservedwords.texi +SUBDIRS = Images + all: $(targets) txt_files txt_files: ../INSTALL-SOURCE ../COPYING ../EXCEPTIONS-CLIENT \ diff --git a/configure.in b/configure.in index d4ede468435..0c520ca8980 100644 --- a/configure.in +++ b/configure.in @@ -2711,7 +2711,7 @@ AC_OUTPUT(Makefile extra/Makefile mysys/Makefile isam/Makefile dnl pstack/Makefile pstack/aout/Makefile sql/Makefile sql/share/Makefile dnl merge/Makefile dbug/Makefile scripts/Makefile dnl include/Makefile sql-bench/Makefile tools/Makefile dnl - tests/Makefile Docs/Makefile support-files/Makefile dnl + tests/Makefile Docs/Makefile Docs/Images/Makefile support-files/Makefile dnl support-files/MacOSX/Makefile mysql-test/Makefile dnl netware/Makefile dnl include/mysql_version.h dnl From 0d5290fc5c5ceea10e513991195263587e7e1d93 Mon Sep 17 00:00:00 2001 From: "lars@mysql.com" <> Date: Thu, 4 Nov 2004 15:59:19 +0100 Subject: [PATCH 12/94] BUG#6239 V2: Since uint can be shorter than ulong on 64 bit platforms, the comparision of "packet_len" (uint) and "len" (uint) with "packet_error" (ulong) was always false. --- client/mysqlbinlog.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 5f9a499bd31..8015871428e 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -204,7 +204,7 @@ int Load_log_processor::load_old_format_file(NET* net, const char*server_fname, for (;;) { - uint packet_len = my_net_read(net); + ulong packet_len = my_net_read(net); if (packet_len == 0) { if (my_net_write(net, "", 0) || net_flush(net)) @@ -226,7 +226,13 @@ int Load_log_processor::load_old_format_file(NET* net, const char*server_fname, return -1; } - if (my_write(file, (byte*) net->read_pos, packet_len,MYF(MY_WME|MY_NABP))) + if (packet_len > UINT_MAX) + { + sql_print_error("Illegal length of packet read from net"); + return -1; + } + if (my_write(file, (byte*) net->read_pos, + (uint) packet_len, MYF(MY_WME|MY_NABP))) return -1; } @@ -747,7 +753,8 @@ static int dump_remote_log_entries(const char* logname) { char buf[128]; char last_db[FN_REFLEN+1] = ""; - uint len, logname_len; + ulong len; + uint logname_len; NET* net; int old_format; int error= 0; @@ -770,7 +777,15 @@ static int dump_remote_log_entries(const char* logname) */ int4store(buf, (uint32)start_position); int2store(buf + BIN_LOG_HEADER_SIZE, binlog_flags); - logname_len = (uint) strlen(logname); + + size_s tlen = strlen(logname); + if (tlen > UINT_MAX) + { + fprintf(stderr,"Log name too long\n"); + error= 1; + goto err; + } + logname_len = (uint) tlen; int4store(buf + 6, 0); memcpy(buf + 10, logname, logname_len); if (simple_command(mysql, COM_BINLOG_DUMP, buf, logname_len + 10, 1)) From 1869cd9f837e58adc709514d0133fd5c6323aa9b Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Thu, 4 Nov 2004 19:19:23 +0100 Subject: [PATCH 13/94] Fix for BUG##5714 "Insert into MyISAM table and select ... for update]": the fact that the transaction log is empty does not mean we're not in a transaction (it could be BEGIN; SELECT * FOR UPDATE FROM ibtable: then we don't want to commit now, even if the statement is a MyISAM update). With a testcase. --- mysql-test/r/mix_innodb_myisam_binlog.result | 21 ++++++++++++ .../t/mix_innodb_myisam_binlog-master.opt | 1 + mysql-test/t/mix_innodb_myisam_binlog.test | 32 +++++++++++++++++++ sql/log.cc | 3 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 mysql-test/t/mix_innodb_myisam_binlog-master.opt diff --git a/mysql-test/r/mix_innodb_myisam_binlog.result b/mysql-test/r/mix_innodb_myisam_binlog.result index 7b266544c92..93a647f673c 100644 --- a/mysql-test/r/mix_innodb_myisam_binlog.result +++ b/mysql-test/r/mix_innodb_myisam_binlog.result @@ -177,4 +177,25 @@ master-bin.001 79 Query 1 79 use `test`; BEGIN master-bin.001 119 Query 1 79 use `test`; insert into t1 values(16) master-bin.001 179 Query 1 79 use `test`; insert into t1 values(18) master-bin.001 239 Query 1 239 use `test`; COMMIT +delete from t1; +delete from t2; +alter table t2 type=MyISAM; +insert into t1 values (1); +begin; +select * from t1 for update; +a +1 +select (@before:=unix_timestamp())*0; +(@before:=unix_timestamp())*0 +0 +begin; + select * from t1 for update; +insert into t2 values (20); +Lock wait timeout exceeded; Try restarting transaction +select (@after:=unix_timestamp())*0; +(@after:=unix_timestamp())*0 +0 +select (@after-@before) >= 2; +(@after-@before) >= 2 +1 drop table t1,t2; diff --git a/mysql-test/t/mix_innodb_myisam_binlog-master.opt b/mysql-test/t/mix_innodb_myisam_binlog-master.opt new file mode 100644 index 00000000000..cb48f1aaf60 --- /dev/null +++ b/mysql-test/t/mix_innodb_myisam_binlog-master.opt @@ -0,0 +1 @@ +--loose-innodb_lock_wait_timeout=2 diff --git a/mysql-test/t/mix_innodb_myisam_binlog.test b/mysql-test/t/mix_innodb_myisam_binlog.test index be45c2c3133..5f3b778c61a 100644 --- a/mysql-test/t/mix_innodb_myisam_binlog.test +++ b/mysql-test/t/mix_innodb_myisam_binlog.test @@ -175,4 +175,36 @@ select a from t1 order by a; # check that savepoints work :) show binlog events from 79; +# Test for BUG#5714, where a MyISAM update in the transaction used to +# release row-level locks in InnoDB + +connect (con3,localhost,root,,); + +connection con3; +delete from t1; +delete from t2; +--disable_warnings +alter table t2 type=MyISAM; +--enable_warnings +insert into t1 values (1); +begin; +select * from t1 for update; + +connection con2; +select (@before:=unix_timestamp())*0; # always give repeatable output +begin; +send select * from t1 for update; + +connection con3; +insert into t2 values (20); + +connection con2; +--error 1205 +reap; +select (@after:=unix_timestamp())*0; # always give repeatable output +# verify that innodb_lock_wait_timeout was exceeded. When there was +# the bug, the reap would return immediately after the insert into t2. +select (@after-@before) >= 2; + +# cleanup drop table t1,t2; diff --git a/sql/log.cc b/sql/log.cc index fee77b38f21..aa5d9d8753b 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1254,7 +1254,8 @@ bool MYSQL_LOG::write(Log_event* event_info) if (flush_io_cache(file)) goto err; - if (opt_using_transactions && !my_b_tell(&thd->transaction.trans_log)) + if (opt_using_transactions && + !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) { /* LOAD DATA INFILE in AUTOCOMMIT=1 mode writes to the binlog From e9c50b8773f81515a1d538bf30c86895ba1c9ed8 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Fri, 5 Nov 2004 09:00:04 +0400 Subject: [PATCH 14/94] libmysql.def, libmysql.c: Clean-ups --- libmysql/libmysql.c | 2 +- libmysql/libmysql.def | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 9257bf0efd0..2257ae739eb 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3170,7 +3170,7 @@ void my_net_local_init(NET *net) encoded string, not including the terminating null character. */ -unsigned long +ulong STDCALL mysql_hex_string(char *to, const char *from, unsigned long length) { char *to0= to; diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def index b0433a34cb3..51a4edda5aa 100644 --- a/libmysql/libmysql.def +++ b/libmysql/libmysql.def @@ -11,6 +11,7 @@ EXPORTS mysql_errno mysql_error mysql_escape_string + mysql_hex_string mysql_fetch_field mysql_fetch_field_direct mysql_fetch_fields From 0a375d4b72a9af2b93da5eaa65423b4b365dce49 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Fri, 5 Nov 2004 09:07:07 +0400 Subject: [PATCH 15/94] libmysql.c: After-merge clean-up --- libmysql/libmysql.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 2250111f5a0..47f28e296b2 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3173,7 +3173,8 @@ void my_net_local_init(NET *net) trailing '. The caller must supply whichever of those is desired. */ -ulong mysql_hex_string(char *to, const char *from, ulong length) +ulong STDCALL +mysql_hex_string(char *to, const char *from, ulong length) { char *to0= to; const char *end; From 630ea6e63c02c4ba2dbf8a811a7c35fdda370174 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Fri, 5 Nov 2004 09:23:53 +0400 Subject: [PATCH 16/94] client_priv.h: Backport --hex-blob to 4.0 --- client/client_priv.h | 3 ++- client/mysqldump.c | 56 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index 5029f219494..016c9e5ee80 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -38,4 +38,5 @@ enum options_client { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH, OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT, OPT_LOCAL_INFILE, OPT_DELETE_MASTER_LOGS, - OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION, OPT_FRM }; + OPT_PROMPT, OPT_IGN_LINES,OPT_TRANSACTION, OPT_FRM, + OPT_HEXBLOB }; diff --git a/client/mysqldump.c b/client/mysqldump.c index 49822f0bee0..a78eee3794a 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -78,7 +78,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0, opt_alldbs=0,opt_create_db=0,opt_first_slave=0, opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0, opt_delete_master_logs=0, tty_password=0, - opt_single_transaction=0, opt_comments= 0; + opt_single_transaction=0, opt_comments= 0, + opt_hex_blob; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*sock=0; static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, @@ -248,6 +249,8 @@ static struct my_option my_long_options[] = {"comments", 'i', "Write additional information.", (gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"hex-blob", OPT_HEXBLOB, "Dump BLOBs in HEX.", + (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -1104,6 +1107,7 @@ static void dumpTable(uint numFields, char *table) for (i = 0; i < mysql_num_fields(res); i++) { + int is_blob; if (!(field = mysql_fetch_field(res))) { sprintf(query,"%s: Not enough fields from table %s! Aborting.\n", @@ -1112,6 +1116,13 @@ static void dumpTable(uint numFields, char *table) error= EX_CONSCHECK; goto err; } + + is_blob= (opt_hex_blob && (field->flags & BINARY_FLAG) && + (field->type == FIELD_TYPE_STRING || + field->type == FIELD_TYPE_BLOB || + field->type == FIELD_TYPE_LONG_BLOB || + field->type == FIELD_TYPE_MEDIUM_BLOB || + field->type == FIELD_TYPE_TINY_BLOB)) ? 1 : 0; if (extended_insert) { ulong length = lengths[i]; @@ -1126,18 +1137,37 @@ static void dumpTable(uint numFields, char *table) { if (!IS_NUM_FIELD(field)) { + /* + "length * 2 + 2" is OK for both HEX and non-HEX modes: + - In HEX mode we need exactly 2 bytes per character + plus 2 bytes for '0x' prefix. + - In non-HEX mode we need up to 2 bytes per character, + plus 2 bytes for leading and trailing '\'' characters. + */ if (dynstr_realloc(&extended_row,length * 2+2)) { fputs("Aborting dump (out of memory)",stderr); error= EX_EOM; goto err; } - dynstr_append(&extended_row,"\'"); - extended_row.length += + if (opt_hex_blob && is_blob) + { + dynstr_append(&extended_row, "0x"); + extended_row.length+= mysql_hex_string(extended_row.str + + extended_row.length, + row[i], length); + extended_row.str[extended_row.length]= '\0'; + } + else + { + dynstr_append(&extended_row,"\'"); + extended_row.length += mysql_real_escape_string(&mysql_connection, - &extended_row.str[extended_row.length],row[i],length); - extended_row.str[extended_row.length]='\0'; - dynstr_append(&extended_row,"\'"); + &extended_row.str[extended_row.length], + row[i],length); + extended_row.str[extended_row.length]='\0'; + dynstr_append(&extended_row,"\'"); + } } else { @@ -1180,7 +1210,19 @@ static void dumpTable(uint numFields, char *table) if (opt_xml) print_quoted_xml(md_result_file, field->name, row[i], lengths[i]); - else + else if (opt_hex_blob && is_blob) + { /* sakaik got this idea. */ + ulong counter; + char xx[4]; + unsigned char *ptr= row[i]; + fputs("0x", md_result_file); + for (counter = 0; counter < lengths[i]; counter++) + { + sprintf(xx, "%02X", ptr[counter]); + fputs(xx, md_result_file); + } + } + else unescape(md_result_file, row[i], lengths[i]); } else From 5e2b6e3035e6943f0fa8de61d1b8bdcf198617a6 Mon Sep 17 00:00:00 2001 From: "joerg@mysql.com" <> Date: Fri, 5 Nov 2004 15:22:03 +0100 Subject: [PATCH 17/94] Change "Bootstrap" so that it will not fail on BK source trees of other versions; this is important because this 4.0 "Bootstrap" is the one generally used on host "build". --- Build-tools/Bootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build-tools/Bootstrap b/Build-tools/Bootstrap index e21179fe78c..a7d347ba32f 100755 --- a/Build-tools/Bootstrap +++ b/Build-tools/Bootstrap @@ -288,7 +288,7 @@ unless ($opt_skip_manual) system ("bk cat $opt_docdir/Docs/$file.texi > $target_dir/Docs/$file.texi") == 0 or &abort("Could not update $file.texi in $target_dir/Docs/!"); } - system ("rm $target_dir/Docs/Images/Makefile*") == 0 + system ("rm -f $target_dir/Docs/Images/Makefile*") == 0 or &abort("Could not remove Makefiles in $target_dir/Docs/Images/!"); system ("cp $opt_docdir/Docs/Images/*.* $target_dir/Docs/Images") == 0 or &abort("Could not copy image files in $target_dir/Docs/Images/!"); From b911810af7930beaaea78c1a407b08b1bd29c1ab Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Fri, 5 Nov 2004 20:33:56 +0400 Subject: [PATCH 18/94] mysqldump.c: Dump VARCHAR(n) BINARY in HEX if --hex-blob too. --- client/mysqldump.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/mysqldump.c b/client/mysqldump.c index a78eee3794a..0e840512ba0 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1119,6 +1119,7 @@ static void dumpTable(uint numFields, char *table) is_blob= (opt_hex_blob && (field->flags & BINARY_FLAG) && (field->type == FIELD_TYPE_STRING || + field->type == FIELD_TYPE_VAR_STRING || field->type == FIELD_TYPE_BLOB || field->type == FIELD_TYPE_LONG_BLOB || field->type == FIELD_TYPE_MEDIUM_BLOB || From 083a2f5613362353a935434130febef98009b0b5 Mon Sep 17 00:00:00 2001 From: "jani@a193-229-222-105.elisa-laajakaista.fi" <> Date: Fri, 5 Nov 2004 18:59:19 +0200 Subject: [PATCH 19/94] Changed default.c so that it now checks for my.ini and then my.cnf from the default directories. --- BitKeeper/etc/logging_ok | 1 + mysys/default.c | 89 ++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index a716afb2392..01b9190b044 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -47,6 +47,7 @@ hf@genie.(none) igor@hundin.mysql.fi igor@rurik.mysql.com ingo@mysql.com +jani@a193-229-222-105.elisa-laajakaista.fi jani@a80-186-24-72.elisa-laajakaista.fi jani@a80-186-41-201.elisa-laajakaista.fi jani@dsl-jkl1657.dial.inet.fi diff --git a/mysys/default.c b/mysys/default.c index 81290322223..ed7f4b47097 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -60,11 +60,7 @@ DATADIR, NullS, }; -#define default_ext ".cnf" /* extension for config file */ -#ifdef __WIN__ -#include -#define windows_ext ".ini" -#endif +static const char *f_extensions[]= { ".ini", ".cnf", 0 }; static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, const char *dir, const char *config_file, @@ -115,7 +111,8 @@ int load_defaults(const char *conf_file, const char **groups, uint args_used=0; int error= 0; MEM_ROOT alloc; - char *ptr,**res; + char *ptr, **res, **ext; + DBUG_ENTER("load_defaults"); init_alloc_root(&alloc,512,0); @@ -169,38 +166,43 @@ int load_defaults(const char *conf_file, const char **groups, } else if (dirname_length(conf_file)) { - if ((error= search_default_file(&args, &alloc, NullS, conf_file, - default_ext, &group)) < 0) - goto err; + for (ext= (char**) f_extensions; *ext; *ext++) + if ((error= search_default_file(&args, &alloc, NullS, conf_file, + *ext, &group)) < 0) + goto err; } else { #ifdef __WIN__ char system_dir[FN_REFLEN]; GetWindowsDirectory(system_dir,sizeof(system_dir)); - if ((search_default_file(&args, &alloc, system_dir, conf_file, - windows_ext, &group))) - goto err; + for (ext= (char**) f_extensions; *ext; *ext++) + if ((search_default_file(&args, &alloc, system_dir, conf_file, + *ext, &group))) + goto err; #endif #if defined(__EMX__) || defined(OS2) - if (getenv("ETC") && - (search_default_file(&args, &alloc, getenv("ETC"), conf_file, - default_ext, &group)) < 0) - goto err; + for (ext= (char**) f_extensions; *ext; *ext++) + if (getenv("ETC") && + (search_default_file(&args, &alloc, getenv("ETC"), conf_file, + *ext, &group)) < 0) + goto err; #endif for (dirs=default_directories ; *dirs; dirs++) { if (**dirs) { - if (search_default_file(&args, &alloc, *dirs, conf_file, - default_ext, &group) < 0) - goto err; + for (ext= (char**) f_extensions; *ext; *ext++) + if (search_default_file(&args, &alloc, *dirs, conf_file, + *ext, &group) < 0) + goto err; } else if (defaults_extra_file) { - if (search_default_file(&args, &alloc, NullS, defaults_extra_file, - default_ext, &group) < 0) - goto err; /* Fatal error */ + for (ext= (char**) f_extensions; ext; ext++) + if (search_default_file(&args, &alloc, NullS, defaults_extra_file, + *ext, &group) < 0) + goto err; /* Fatal error */ } } } @@ -478,8 +480,9 @@ void print_defaults(const char *conf_file, const char **groups) #ifdef __WIN__ bool have_ext=fn_ext(conf_file)[0] != 0; #endif - char name[FN_REFLEN]; + char name[FN_REFLEN], **ext; const char **dirs; + puts("\nDefault options are read from the following files in the given order:"); if (dirname_length(conf_file)) @@ -488,27 +491,35 @@ void print_defaults(const char *conf_file, const char **groups) { #ifdef __WIN__ GetWindowsDirectory(name,sizeof(name)); - printf("%s\\%s%s ",name,conf_file,have_ext ? "" : windows_ext); + if (have_ext) + for (ext= (char**) f_extensions; *ext; *ext++) + printf("%s\\%s%s ", name, conf_file, *ext); + else + printf("%s\\%s ", name, conf_file); #endif #if defined(__EMX__) || defined(OS2) - if (getenv("ETC")) - printf("%s\\%s%s ", getenv("ETC"), conf_file, default_ext); + for (ext= (char**) f_extensions; *ext; *ext++) + if (getenv("ETC")) + printf("%s\\%s%s ", getenv("ETC"), conf_file, *ext); #endif for (dirs=default_directories ; *dirs; dirs++) { - const char *pos; - char *end; - if (**dirs) - pos= *dirs; - else if (defaults_extra_file) - pos= defaults_extra_file; - else - continue; - end=convert_dirname(name, pos, NullS); - if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ - *end++='.'; - strxmov(end,conf_file,default_ext," ",NullS); - fputs(name,stdout); + for (ext= (char**) f_extensions; *ext; *ext++) + { + const char *pos; + char *end; + if (**dirs) + pos= *dirs; + else if (defaults_extra_file) + pos= defaults_extra_file; + else + continue; + end= convert_dirname(name, pos, NullS); + if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ + *end++='.'; + strxmov(end, conf_file, *ext, " ", NullS); + fputs(name,stdout); + } } puts(""); } From bfdf57ef31174814cdec5e275d710b4a48dc55c7 Mon Sep 17 00:00:00 2001 From: "jani@a193-229-222-105.elisa-laajakaista.fi" <> Date: Fri, 5 Nov 2004 23:58:30 +0200 Subject: [PATCH 20/94] Fixed a typo that caused segmentation fault when using --defaults-extra-file option. --- mysys/default.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/default.c b/mysys/default.c index ed7f4b47097..416de09b661 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -199,7 +199,7 @@ int load_defaults(const char *conf_file, const char **groups, } else if (defaults_extra_file) { - for (ext= (char**) f_extensions; ext; ext++) + for (ext= (char**) f_extensions; *ext; *ext++) if (search_default_file(&args, &alloc, NullS, defaults_extra_file, *ext, &group) < 0) goto err; /* Fatal error */ From b7776f83e7a3c35bf3de1c62dc75b8c218120ce7 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Mon, 8 Nov 2004 13:15:01 +0400 Subject: [PATCH 21/94] ctype_ujis.result, ctype_ujis.test, field.cc: Bug#6345 Unexpected behaviour with partial indices --- mysql-test/r/ctype_ujis.result | 40 ++++++++++++++++++++++++++++++++++ mysql-test/t/ctype_ujis.test | 36 ++++++++++++++++++++++++++++++ sql/field.cc | 8 +++++-- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ctype_ujis.result b/mysql-test/r/ctype_ujis.result index 7c3ae52cbc9..d02ac0062f8 100644 --- a/mysql-test/r/ctype_ujis.result +++ b/mysql-test/r/ctype_ujis.result @@ -126,3 +126,43 @@ Field Type Null Key Default Extra a char(1) b enum('¤¢','¤¤') YES NULL DROP TABLE t1; +CREATE TABLE t1 +( +a INTEGER NOT NULL, +b VARCHAR(50) NOT NULL DEFAULT '', +PRIMARY KEY (a), +KEY b (b(10)) +) TYPE=InnoDB CHARACTER SET 'ujis' COLLATE 'ujis_japanese_ci'; +INSERT INTO t1 (a, b) VALUES (0, 'aaabbbcccddd'); +INSERT INTO t1 (a, b) VALUES (1, 'eeefffggghhh'); +INSERT INTO t1 (a, b) VALUES (2, 'iiijjjkkkl'); +SELECT t1.* FROM t1 WHERE b='aaabbbcccddd' ORDER BY a; +a b +0 aaabbbcccddd +SELECT t1.* FROM t1 WHERE b='eeefffggghhh' ORDER BY a; +a b +1 eeefffggghhh +SELECT t1.* FROM t1 WHERE b='iiijjjkkkl' ORDER BY a; +a b +2 iiijjjkkkl +DROP TABLE t1; +CREATE TABLE t1 +( +a INTEGER NOT NULL, +b VARCHAR(50) NOT NULL DEFAULT '', +PRIMARY KEY (a), +KEY b (b(10)) +) TYPE=MyISAM CHARACTER SET 'ujis' COLLATE 'ujis_japanese_ci'; +INSERT INTO t1 (a, b) VALUES (0, 'aaabbbcccddd'); +INSERT INTO t1 (a, b) VALUES (1, 'eeefffggghhh'); +INSERT INTO t1 (a, b) VALUES (2, 'iiijjjkkkl'); +SELECT t1.* FROM t1 WHERE b='aaabbbcccddd' ORDER BY a; +a b +0 aaabbbcccddd +SELECT t1.* FROM t1 WHERE b='eeefffggghhh' ORDER BY a; +a b +1 eeefffggghhh +SELECT t1.* FROM t1 WHERE b='iiijjjkkkl' ORDER BY a; +a b +2 iiijjjkkkl +DROP TABLE t1; diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test index e5405d9f1bd..9cfb6b14d7e 100644 --- a/mysql-test/t/ctype_ujis.test +++ b/mysql-test/t/ctype_ujis.test @@ -83,3 +83,39 @@ CREATE TABLE t1 ( SHOW CREATE TABLE t1; SHOW COLUMNS FROM t1; DROP TABLE t1; + +# +# Bug #6345 Unexpected behaviour with partial indices +# +--disable_warnings +CREATE TABLE t1 +( + a INTEGER NOT NULL, + b VARCHAR(50) NOT NULL DEFAULT '', + PRIMARY KEY (a), + KEY b (b(10)) +) TYPE=InnoDB CHARACTER SET 'ujis' COLLATE 'ujis_japanese_ci'; +--enable_warnings +INSERT INTO t1 (a, b) VALUES (0, 'aaabbbcccddd'); +INSERT INTO t1 (a, b) VALUES (1, 'eeefffggghhh'); +INSERT INTO t1 (a, b) VALUES (2, 'iiijjjkkkl'); +SELECT t1.* FROM t1 WHERE b='aaabbbcccddd' ORDER BY a; +SELECT t1.* FROM t1 WHERE b='eeefffggghhh' ORDER BY a; +SELECT t1.* FROM t1 WHERE b='iiijjjkkkl' ORDER BY a; +DROP TABLE t1; +--disable_warnings +CREATE TABLE t1 +( + a INTEGER NOT NULL, + b VARCHAR(50) NOT NULL DEFAULT '', + PRIMARY KEY (a), + KEY b (b(10)) +) TYPE=MyISAM CHARACTER SET 'ujis' COLLATE 'ujis_japanese_ci'; +--enable_warnings +INSERT INTO t1 (a, b) VALUES (0, 'aaabbbcccddd'); +INSERT INTO t1 (a, b) VALUES (1, 'eeefffggghhh'); +INSERT INTO t1 (a, b) VALUES (2, 'iiijjjkkkl'); +SELECT t1.* FROM t1 WHERE b='aaabbbcccddd' ORDER BY a; +SELECT t1.* FROM t1 WHERE b='eeefffggghhh' ORDER BY a; +SELECT t1.* FROM t1 WHERE b='iiijjjkkkl' ORDER BY a; +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index 24bd0c48c92..1111e47bc38 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4401,10 +4401,14 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr) (const uchar*) b_ptr, field_length); } - return my_strnncoll(field_charset,(const uchar*) a_ptr, field_length, - (const uchar*) b_ptr, field_length); + uint char_len= field_length/field_charset->mbmaxlen; + uint a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len); + uint b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len); + return my_strnncoll(field_charset,(const uchar*) a_ptr, a_len, + (const uchar*) b_ptr, b_len); } + void Field_string::sort_string(char *to,uint length) { uint tmp=my_strnxfrm(field_charset, From 9f999953a2bc2dec5da6fe9a5ee8ad56eb54c94f Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Mon, 8 Nov 2004 10:21:39 +0000 Subject: [PATCH 22/94] removed editline and replaced with mysql readline created new facade object for CommandInterpreter removed CPC #if 0 code removed editline from mgmtsrver, no replace with readline since interface is obsolete anyways --- configure.in | 1 - ndb/src/common/Makefile.am | 2 +- ndb/src/common/Makefile_old | 15 - ndb/src/common/editline/MANIFEST | 15 - ndb/src/common/editline/Makefile.am | 10 - ndb/src/common/editline/Makefile_old | 18 - ndb/src/common/editline/README | 53 - ndb/src/common/editline/complete.c | 195 --- ndb/src/common/editline/editline.3 | 178 -- ndb/src/common/editline/editline.c | 1498 ----------------- ndb/src/common/editline/editline_internal.h | 30 - ndb/src/common/editline/sysunix.c | 132 -- ndb/src/common/editline/test/Makefile | 10 - ndb/src/common/editline/test/testit.c | 55 - ndb/src/common/editline/unix.h | 9 - ndb/src/mgmclient/CommandInterpreter.cpp | 402 +++-- ndb/src/mgmclient/CommandInterpreter.hpp | 197 --- ndb/src/mgmclient/Makefile.am | 13 +- ndb/src/mgmclient/Makefile_old | 25 - ndb/src/mgmclient/main.cpp | 8 +- .../ndb_mgmclient.hpp} | 27 +- ndb/src/mgmsrv/CommandInterpreter.hpp | 28 +- ndb/src/mgmsrv/Makefile.am | 1 - .../mgmclient => test/include}/CpcClient.hpp | 0 ndb/test/run-test/Makefile.am | 5 +- ndb/{src/mgmclient => test/src}/CpcClient.cpp | 0 ndb/test/src/Makefile.am | 3 +- ndb/test/tools/Makefile.am | 4 +- 28 files changed, 272 insertions(+), 2662 deletions(-) delete mode 100644 ndb/src/common/Makefile_old delete mode 100644 ndb/src/common/editline/MANIFEST delete mode 100644 ndb/src/common/editline/Makefile.am delete mode 100644 ndb/src/common/editline/Makefile_old delete mode 100644 ndb/src/common/editline/README delete mode 100644 ndb/src/common/editline/complete.c delete mode 100644 ndb/src/common/editline/editline.3 delete mode 100644 ndb/src/common/editline/editline.c delete mode 100644 ndb/src/common/editline/editline_internal.h delete mode 100644 ndb/src/common/editline/sysunix.c delete mode 100644 ndb/src/common/editline/test/Makefile delete mode 100644 ndb/src/common/editline/test/testit.c delete mode 100644 ndb/src/common/editline/unix.h delete mode 100644 ndb/src/mgmclient/CommandInterpreter.hpp delete mode 100644 ndb/src/mgmclient/Makefile_old rename ndb/src/{common/editline/editline_win32.c => mgmclient/ndb_mgmclient.hpp} (68%) rename ndb/{src/mgmclient => test/include}/CpcClient.hpp (100%) rename ndb/{src/mgmclient => test/src}/CpcClient.cpp (100%) diff --git a/configure.in b/configure.in index 71adaa747f5..cd2daf10690 100644 --- a/configure.in +++ b/configure.in @@ -3093,7 +3093,6 @@ AC_CONFIG_FILES(ndb/Makefile ndb/include/Makefile dnl ndb/src/common/logger/Makefile dnl ndb/src/common/transporter/Makefile dnl ndb/src/common/mgmcommon/Makefile dnl - ndb/src/common/editline/Makefile dnl ndb/src/kernel/Makefile dnl ndb/src/kernel/error/Makefile dnl ndb/src/kernel/blocks/Makefile dnl diff --git a/ndb/src/common/Makefile.am b/ndb/src/common/Makefile.am index 7fcf2cab636..8733205eca2 100644 --- a/ndb/src/common/Makefile.am +++ b/ndb/src/common/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = portlib debugger util logger transporter mgmcommon editline +SUBDIRS = portlib debugger util logger transporter mgmcommon noinst_LTLIBRARIES = libcommon.la diff --git a/ndb/src/common/Makefile_old b/ndb/src/common/Makefile_old deleted file mode 100644 index ebde75bf3ec..00000000000 --- a/ndb/src/common/Makefile_old +++ /dev/null @@ -1,15 +0,0 @@ -include .defs.mk - -LIB_DIRS := \ - portlib \ - debugger \ - util \ - logger - -ifneq ($(USE_EDITLINE), N) -LIB_DIRS += editline -endif - -DIRS := transporter mgmcommon - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/common/editline/MANIFEST b/ndb/src/common/editline/MANIFEST deleted file mode 100644 index dc8b4b36f88..00000000000 --- a/ndb/src/common/editline/MANIFEST +++ /dev/null @@ -1,15 +0,0 @@ -File Name Description --------------------------------------------------------- -README Release notes and copyright -MANIFEST This shipping list -Make.os9 OS-9 makefile -Makefile Unix makefile -complete.c Filename completion routines -editline.3 Manual page for editline library -editline.c Line-editing routines -editline_internal.h Internal library header file -os9.h OS-9-specific declarations -sysos9.c OS-9-specific routines -sysunix.c Unix-specific routines -testit.c Test driver -unix.h Unix-specific declarations diff --git a/ndb/src/common/editline/Makefile.am b/ndb/src/common/editline/Makefile.am deleted file mode 100644 index 4f53bdc6326..00000000000 --- a/ndb/src/common/editline/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ - -noinst_LIBRARIES = libeditline.a - -libeditline_a_SOURCES = complete.c editline.c sysunix.c - -INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/ndb/include -DEFS = -DANSI_ARROWS -DHAVE_TCGETATTR -DSYS_UNIX - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/ndb/src/common/editline/Makefile_old b/ndb/src/common/editline/Makefile_old deleted file mode 100644 index 800df8f0f31..00000000000 --- a/ndb/src/common/editline/Makefile_old +++ /dev/null @@ -1,18 +0,0 @@ -include .defs.mk - -TYPE := - -ARCHIVE_TARGET := editline - -CFLAGS += -DANSI_ARROWS -DHAVE_TCGETATTR -DSYS_UNIX - -ifeq ($(NDB_OS), WIN32) -SOURCES = editline_win32.c -else -SOURCES = complete.c editline.c sysunix.c -endif - -DIRS := test - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/common/editline/README b/ndb/src/common/editline/README deleted file mode 100644 index 537c7bd8611..00000000000 --- a/ndb/src/common/editline/README +++ /dev/null @@ -1,53 +0,0 @@ --- -NOTE: This version has been modified by Ericsson/Alzato. Please -see the cvs changelog for more details. --- - -$Revision: 1.2 $ - -This is a line-editing library. It can be linked into almost any -program to provide command-line editing and recall. - -It is call-compatible with the FSF readline library, but it is a -fraction of the size (and offers fewer features). It does not use -standard I/O. It is distributed under a "C News-like" copyright. - -Configuration is done in the Makefile. Type "make testit" to get -a small slow shell for testing. - -This contains some changes since the posting to comp.sources.misc: - - Bugfix for completion on absolute pathnames. - - Better handling of M-n versus showing raw 8bit chars. - - Better signal handling. - - Now supports termios/termio/sgttyb ioctl's. - - Add M-m command to toggle how 8bit data is displayed. -The following changes, made since the last public release, come from -J.G. Vons : - - History-searching no longer redraws the line wrong - - Added ESC-ESC as synonym for ESC-? - - SIGQUIT (normally ^\) now sends a signal, not indicating EOF. - - Fixed some typo's and unclear wording in the manpage. - - Fixed completion when all entries shared a common prefix. - - Fixed some meta-char line-redrawing bugs. - -Enjoy, - Rich $alz - - - Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved. - - This software is not subject to any license of the American Telephone - and Telegraph Company or of the Regents of the University of California. - - Permission is granted to anyone to use this software for any purpose on - any computer system, and to alter it and redistribute it freely, subject - to the following restrictions: - 1. The authors are not responsible for the consequences of use of this - software, no matter how awful, even if they arise from flaws in it. - 2. The origin of this software must not be misrepresented, either by - explicit claim or by omission. Since few users ever read sources, - credits must appear in the documentation. - 3. Altered versions must be plainly marked as such, and must not be - misrepresented as being the original software. Since few users - ever read sources, credits must appear in the documentation. - 4. This notice may not be removed or altered. diff --git a/ndb/src/common/editline/complete.c b/ndb/src/common/editline/complete.c deleted file mode 100644 index c524a88c678..00000000000 --- a/ndb/src/common/editline/complete.c +++ /dev/null @@ -1,195 +0,0 @@ -/* -*- c-basic-offset: 4; -*- -** $Revision: 1.8 $ -** -** History and file completion functions for editline library. -*/ -#include "editline_internal.h" - - -/* -** strcmp-like sorting predicate for qsort. -*/ -static int -compare(const void *p1, const void *p2) -{ - const char **v1; - const char **v2; - - v1 = (const char **)p1; - v2 = (const char **)p2; - return strcmp(*v1, *v2); -} - -/* -** Fill in *avp with an array of names that match file, up to its length. -** Ignore . and .. . -*/ -static int -FindMatches(char *dir, char *file, char ***avp) -{ - char **av; - char **new; - char *p; - DIR *dp; - struct dirent *ep; - size_t ac; - size_t len; - - if ((dp = opendir(dir)) == NULL) - return 0; - - av = NULL; - ac = 0; - len = strlen(file); - while ((ep = readdir(dp)) != NULL) { - p = ep->d_name; - if (p[0] == '.' && (p[1] == '\0' || (p[1] == '.' && p[2] == '\0'))) - continue; - if (len && strncmp(p, file, len) != 0) - continue; - - if ((ac % MEM_INC) == 0) { - if ((new = malloc(sizeof(char*) * (ac + MEM_INC))) == NULL) - break; - if (ac) { - memcpy(new, av, ac * sizeof (char **)); - free(av); - } - *avp = av = new; - } - - if ((av[ac] = strdup(p)) == NULL) { - if (ac == 0) - free(av); - break; - } - ac++; - } - - /* Clean up and return. */ - (void)closedir(dp); - if (ac) - qsort(av, ac, sizeof (char **), compare); - return ac; -} - -/* -** Split a pathname into allocated directory and trailing filename parts. -*/ -static int -SplitPath(char *path, char **dirpart, char ** filepart) -{ - static char DOT[] = "."; - char *dpart; - char *fpart; - - if ((fpart = strrchr(path, '/')) == NULL) { - if ((dpart = strdup(DOT)) == NULL) - return -1; - if ((fpart = strdup(path)) == NULL) { - free(dpart); - return -1; - } - } - else { - if ((dpart = strdup(path)) == NULL) - return -1; - dpart[fpart - path + 1] = '\0'; - if ((fpart = strdup(++fpart)) == NULL) { - free(dpart); - return -1; - } - } - *dirpart = dpart; - *filepart = fpart; - return 0; -} - -/* -** Attempt to complete the pathname, returning an allocated copy. -** Fill in *unique if we completed it, or set it to 0 if ambiguous. -*/ -char * -rl_complete(char *pathname,int *unique) -{ - char **av; - char *dir; - char *file; - char *new; - char *p; - size_t ac; - size_t end; - size_t i; - size_t j; - size_t len; - size_t new_len; - size_t p_len; - - if (SplitPath(pathname, &dir, &file) < 0) - return NULL; - if ((ac = FindMatches(dir, file, &av)) == 0) { - free(dir); - free(file); - return NULL; - } - - p = NULL; - len = strlen(file); - if (ac == 1) { - /* Exactly one match -- finish it off. */ - *unique = 1; - j = strlen(av[0]) - len + 2; - p_len = sizeof(char) * (j + 1); - if ((p = malloc(p_len)) != NULL) { - memcpy(p, av[0] + len, j); - new_len = sizeof(char) * (strlen(dir) + strlen(av[0]) + 2); - new = malloc(new_len); - if(new != NULL) { - snprintf(new, new_len, "%s/%s", dir, av[0]); - rl_add_slash(new, p, p_len); - free(new); - } - } - } - else { - /* Find largest matching substring. */ - for (*unique = 0, i = len, end = strlen(av[0]); i < end; i++) - for (j = 1; j < ac; j++) - if (av[0][i] != av[j][i]) - goto breakout; -breakout: - if (i > len) { - j = i - len + 1; - if ((p = malloc(sizeof(char) * j)) != NULL) { - memcpy(p, av[0] + len, j); - p[j - 1] = '\0'; - } - } - } - - /* Clean up and return. */ - free(dir); - free(file); - for (i = 0; i < ac; i++) - free(av[i]); - free(av); - return p; -} - -/* -** Return all possible completions. -*/ -int -rl_list_possib(char *pathname, char ***avp) -{ - char *dir; - char *file; - int ac; - - if (SplitPath(pathname, &dir, &file) < 0) - return 0; - ac = FindMatches(dir, file, avp); - free(dir); - free(file); - return ac; -} diff --git a/ndb/src/common/editline/editline.3 b/ndb/src/common/editline/editline.3 deleted file mode 100644 index 159cc7f87bb..00000000000 --- a/ndb/src/common/editline/editline.3 +++ /dev/null @@ -1,178 +0,0 @@ -.\" $Revision: 1.1 $ -.TH EDITLINE 3 -.SH NAME -editline \- command-line editing library with history -.SH SYNOPSIS -.nf -.B "char *" -.B "readline(prompt)" -.B " char *prompt;" - -.B "void" -.B "add_history(line)" -.B " char *line;" -.fi -.SH DESCRIPTION -.I Editline -is a library that provides an line-editing interface with text recall. -It is intended to be compatible with the -.I readline -library provided by the Free Software Foundation, but much smaller. -The bulk of this manual page describes the user interface. -.PP -The -.I readline -routine returns a line of text with the trailing newline removed. -The data is returned in a buffer allocated with -.IR malloc (3), -so the space should be released with -.IR free (3) -when the calling program is done with it. -Before accepting input from the user, the specified -.I prompt -is displayed on the terminal. -.PP -The -.I add_history -routine makes a copy of the specified -.I line -and adds it to the internal history list. -.SS "User Interface" -A program that uses this library provides a simple emacs-like editing -interface to its users. -A line may be edited before it is sent to the calling program by typing either -control characters or escape sequences. -A control character, shown as a caret followed by a letter, is typed by -holding down the ``control'' key while the letter is typed. -For example, ``^A'' is a control-A. -An escape sequence is entered by typing the ``escape'' key followed by one or -more characters. -The escape key is abbreviated as ``ESC''. -Note that unlike control keys, case matters in escape sequences; ``ESC\ F'' -is not the same as ``ESC\ f''. -.PP -An editing command may be typed anywhere on the line, not just at the -beginning. -In addition, a return may also be typed anywhere on the line, not just at -the end. -.PP -Most editing commands may be given a repeat count, -.IR n , -where -.I n -is a number. -To enter a repeat count, type the escape key, the number, and then -the command to execute. -For example, ``ESC\ 4\ ^f'' moves forward four characters. -If a command may be given a repeat count then the text ``[n]'' is given at the -end of its description. -.PP -The following control characters are accepted: -.RS -.nf -.ta \w'ESC DEL 'u -^A Move to the beginning of the line -^B Move left (backwards) [n] -^D Delete character [n] -^E Move to end of line -^F Move right (forwards) [n] -^G Ring the bell -^H Delete character before cursor (backspace key) [n] -^I Complete filename (tab key); see below -^J Done with line (return key) -^K Kill to end of line (or column [n]) -^L Redisplay line -^M Done with line (alternate return key) -^N Get next line from history [n] -^P Get previous line from history [n] -^R Search backward (forward if [n]) through history for text; -\& prefixing the string with a caret (^) forces it to -\& match only at the beginning of a history line -^T Transpose characters -^V Insert next character, even if it is an edit command -^W Wipe to the mark -^X^X Exchange current location and mark -^Y Yank back last killed text -^[ Start an escape sequence (escape key) -^]c Move forward to next character ``c'' -^? Delete character before cursor (delete key) [n] -.fi -.RE -.PP -The following escape sequences are provided. -.RS -.nf -.ta \w'ESC DEL 'u -ESC\ ^H Delete previous word (backspace key) [n] -ESC\ DEL Delete previous word (delete key) [n] -ESC\ ESC Show possible completions; see below -ESC\ SP Set the mark (space key); see ^X^X and ^Y above -ESC\ . Get the last (or [n]'th) word from previous line -ESC\ ? Show possible completions; see below -ESC\ < Move to start of history -ESC\ > Move to end of history -ESC\ b Move backward a word [n] -ESC\ d Delete word under cursor [n] -ESC\ f Move forward a word [n] -ESC\ l Make word lowercase [n] -ESC\ m Toggle if 8bit chars display as themselves or with -\& an ``M\-'' prefix -ESC\ u Make word uppercase [n] -ESC\ y Yank back last killed text -ESC\ w Make area up to mark yankable -ESC\ nn Set repeat count to the number nn -ESC\ C Read from environment variable ``_C_'', where C is -\& an uppercase letter -.fi -.RE -.PP -The -.I editline -library has a small macro facility. -If you type the escape key followed by an uppercase letter, -.IR C , -then the contents of the environment variable -.I _C_ -are read in as if you had typed them at the keyboard. -For example, if the variable -.I _L_ -contains the following: -.RS -^A^Kecho '^V^[[H^V^[[2J'^M -.RE -Then typing ``ESC L'' will move to the beginning of the line, kill the -entire line, enter the echo command needed to clear the terminal (if your -terminal is like a VT-100), and send the line back to the shell. -.PP -The -.I editline -library also does filename completion. -Suppose the root directory has the following files in it: -.RS -.nf -.ta \w'core 'u -bin vmunix -core vmunix.old -.fi -.RE -If you type ``rm\ /v'' and then the tab key. -.I Editline -will then finish off as much of the name as possible by adding ``munix''. -Because the name is not unique, it will then beep. -If you type the escape key followed by either a question mark or another -escape, it will display the two choices. -If you then type a period and a tab, the library will finish off the filename -for you: -.RS -.nf -.RI "rm /v[TAB]" munix ".[TAB]" old -.fi -.RE -The tab key is shown by ``[TAB]'' and the automatically-entered text -is shown in italics. -.SH "BUGS AND LIMITATIONS" -Cannot handle lines more than 80 columns. -.SH AUTHORS -Simmule R. Turner -and Rich $alz . -Original manual page by DaviD W. Sanderson . diff --git a/ndb/src/common/editline/editline.c b/ndb/src/common/editline/editline.c deleted file mode 100644 index 886dac2793b..00000000000 --- a/ndb/src/common/editline/editline.c +++ /dev/null @@ -1,1498 +0,0 @@ -/* -*- c-basic-offset: 4; -*- -** $Revision: 1.6 $ -** -** Main editing routines for editline library. -*/ -#include - -#include "editline_internal.h" -#include - -/* -** Manifest constants. -*/ -#define SCREEN_WIDTH 80 -#define SCREEN_ROWS 24 -#define NO_ARG (-1) -#define DEL 127 -#define TAB '\t' -#define CTL(x) ((x) & 0x1F) -#define ISCTL(x) ((x) && (x) < ' ') -#define UNCTL(x) ((x) + 64) -#define META(x) ((x) | 0x80) -#define ISMETA(x) ((x) & 0x80) -#define UNMETA(x) ((x) & 0x7F) -#define MAPSIZE 32 -#define METAMAPSIZE 16 -#if !defined(HIST_SIZE) -#define HIST_SIZE 20 -#endif /* !defined(HIST_SIZE) */ - -/* -** Command status codes. -*/ -typedef enum _STATUS { - CSdone, CSeof, CSmove, CSdispatch, CSstay, CSsignal -} STATUS; - -/* -** The type of case-changing to perform. -*/ -typedef enum _CASE { - TOupper, TOlower -} CASE; - -/* -** Key to command mapping. -*/ -typedef struct _KEYMAP { - char Key; - char Active; - STATUS (*Function)(); -} KEYMAP; - -/* -** Command history structure. -*/ -typedef struct _HISTORY { - int Size; - int Pos; - char *Lines[HIST_SIZE]; -} HISTORY; - -/* -** Globals. -*/ -int rl_eof; -int rl_erase; -int rl_intr; -int rl_kill; -int rl_quit; -#if defined(DO_SIGTSTP) -int rl_susp; -#endif /* defined(DO_SIGTSTP) */ - -static char NIL[] = ""; -static const char *Input = NIL; -static char *Line; -static const char *Prompt; -static char *Yanked; -static char *Screen; -static char NEWLINE[]= CRLF; -static HISTORY H; -static int Repeat; -static int End; -static int Mark; -static int OldPoint; -static int Point; -static int PushBack; -static int Pushed; -static int Signal; -static KEYMAP Map[MAPSIZE]; -static KEYMAP MetaMap[METAMAPSIZE]; -static size_t Length; -static size_t ScreenCount; -static size_t ScreenSize; -static char *backspace; -static int TTYwidth; -static int TTYrows; - -/* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */ -int rl_meta_chars = 1; - -/* -** Declarations. -*/ -static char *editinput(); - -#if defined(USE_TERMCAP) -extern char *getenv(); -extern char *tgetstr(); -extern int tgetent(); -extern int tgetnum(); -#endif /* defined(USE_TERMCAP) */ - -/* -** TTY input/output functions. -*/ - -static void -TTYflush() -{ - if (ScreenCount) { - (void)write(1, Screen, ScreenCount); - ScreenCount = 0; - } -} - -static void -TTYput(const char c) -{ - Screen[ScreenCount] = c; - if (++ScreenCount >= ScreenSize - 1) { - ScreenSize += SCREEN_INC; - Screen = realloc(Screen, sizeof(char) * ScreenSize); - /* XXX what to do if realloc failes? */ - } -} - -static void -TTYputs(const char *p) -{ - while (*p) - TTYput(*p++); -} - -static void -TTYshow(char c) -{ - if (c == DEL) { - TTYput('^'); - TTYput('?'); - } - else if (c == TAB) { - /* XXX */ - } - else if (ISCTL(c)) { - TTYput('^'); - TTYput(UNCTL(c)); - } - else if (rl_meta_chars && ISMETA(c)) { - TTYput('M'); - TTYput('-'); - TTYput(UNMETA(c)); - } - else - TTYput(c); -} - -static void -TTYstring(char *p) -{ - while (*p) - TTYshow(*p++); -} - -static int -TTYget() -{ - char c; - - TTYflush(); - if (Pushed) { - Pushed = 0; - return PushBack; - } - if (*Input) - return *Input++; - return read(0, &c, (size_t)1) == 1 ? c : EOF; -} - -#define TTYback() (backspace ? TTYputs((const char *)backspace) : TTYput('\b')) - -static void -TTYbackn(int n) -{ - while (--n >= 0) - TTYback(); -} - -static void -TTYinfo() -{ - static int init; -#if defined(USE_TERMCAP) - char *term; - char buff[2048]; - char *bp; - char *p; -#endif /* defined(USE_TERMCAP) */ -#if defined(TIOCGWINSZ) - struct winsize W; -#endif /* defined(TIOCGWINSZ) */ - - if (init) { -#if defined(TIOCGWINSZ) - /* Perhaps we got resized. */ - if (ioctl(0, TIOCGWINSZ, &W) >= 0 - && W.ws_col > 0 && W.ws_row > 0) { - TTYwidth = (int)W.ws_col; - TTYrows = (int)W.ws_row; - } -#endif /* defined(TIOCGWINSZ) */ - return; - } - init++; - - TTYwidth = TTYrows = 0; -#if defined(USE_TERMCAP) - bp = &buff[0]; - if ((term = getenv("TERM")) == NULL) - term = "dumb"; - if (tgetent(buff, term) < 0) { - TTYwidth = SCREEN_WIDTH; - TTYrows = SCREEN_ROWS; - return; - } - p = tgetstr("le", &bp); - backspace = p ? strdup(p) : NULL; - TTYwidth = tgetnum("co"); - TTYrows = tgetnum("li"); -#endif /* defined(USE_TERMCAP) */ - -#if defined(TIOCGWINSZ) - if (ioctl(0, TIOCGWINSZ, &W) >= 0) { - TTYwidth = (int)W.ws_col; - TTYrows = (int)W.ws_row; - } -#endif /* defined(TIOCGWINSZ) */ - - if (TTYwidth <= 0 || TTYrows <= 0) { - TTYwidth = SCREEN_WIDTH; - TTYrows = SCREEN_ROWS; - } -} - - -/* -** Print an array of words in columns. -*/ -static void -columns(int ac, char **av) -{ - char *p; - int i; - int j; - int k; - int len; - int skip; - int longest; - int cols; - - /* Find longest name, determine column count from that. */ - for (longest = 0, i = 0; i < ac; i++) - if ((j = strlen((char *)av[i])) > longest) - longest = j; - cols = TTYwidth / (longest + 3); - - TTYputs((const char *)NEWLINE); - for (skip = ac / cols + 1, i = 0; i < skip; i++) { - for (j = i; j < ac; j += skip) { - for (p = av[j], len = strlen((char *)p), k = len; --k >= 0; p++) - TTYput(*p); - if (j + skip < ac) - while (++len < longest + 3) - TTYput(' '); - } - TTYputs((const char *)NEWLINE); - } -} - -static void -reposition() -{ - int i; - char *p; - - TTYput('\r'); - TTYputs((const char *)Prompt); - for (i = Point, p = Line; --i >= 0; p++) - TTYshow(*p); -} - -static void -left(STATUS Change) -{ - char c; - - TTYback(); - if (Point) { - c = Line[Point - 1]; - if (c == TAB) { - /* XXX */ - } - else if (ISCTL(c)) - TTYback(); - else if (rl_meta_chars && ISMETA(c)) { - TTYback(); - TTYback(); - } - } - if (Change == CSmove) - Point--; -} - -static void -right(STATUS Change) -{ - TTYshow(Line[Point]); - if (Change == CSmove) - Point++; -} - -static STATUS -ring_bell() -{ - TTYput('\07'); - TTYflush(); - return CSstay; -} - -static STATUS -do_macro(int c) -{ - char name[4]; - - name[0] = '_'; - name[1] = c; - name[2] = '_'; - name[3] = '\0'; - - if ((Input = (char *)getenv((char *)name)) == NULL) { - Input = NIL; - return ring_bell(); - } - return CSstay; -} - -static STATUS -do_forward(STATUS move) -{ - int i; - char *p; - - i = 0; - do { - p = &Line[Point]; - for ( ; Point < End && (*p == ' ' || !isalnum((int)*p)); Point++, p++) - if (move == CSmove) - right(CSstay); - - for (; Point < End && isalnum((int)*p); Point++, p++) - if (move == CSmove) - right(CSstay); - - if (Point == End) - break; - } while (++i < Repeat); - - return CSstay; -} - -static STATUS -do_case(CASE type) -{ - int i; - int end; - int count; - char *p; - - (void)do_forward(CSstay); - if (OldPoint != Point) { - if ((count = Point - OldPoint) < 0) - count = -count; - Point = OldPoint; - if ((end = Point + count) > End) - end = End; - for (i = Point, p = &Line[i]; i < end; i++, p++) { - if (type == TOupper) { - if (islower((int)*p)) - *p = toupper((int)*p); - } - else if (isupper((int)*p)) - *p = tolower((int)*p); - right(CSmove); - } - } - return CSstay; -} - -static STATUS -case_down_word() -{ - return do_case(TOlower); -} - -static STATUS -case_up_word() -{ - return do_case(TOupper); -} - -static void -ceol() -{ - int extras; - int i; - char *p; - - for (extras = 0, i = Point, p = &Line[i]; i <= End; i++, p++) { - TTYput(' '); - if (*p == TAB) { - /* XXX */ - } - else if (ISCTL(*p)) { - TTYput(' '); - extras++; - } - else if (rl_meta_chars && ISMETA(*p)) { - TTYput(' '); - TTYput(' '); - extras += 2; - } - } - - for (i += extras; i > Point; i--) - TTYback(); -} - -static void -clear_line() -{ - Point = -strlen(Prompt); - TTYput('\r'); - ceol(); - Point = 0; - End = 0; - Line[0] = '\0'; -} - -static STATUS -insert_string(char *p) -{ - size_t len; - int i; - char *new; - char *q; - - len = strlen((char *)p); - if (End + len >= Length) { - if ((new = malloc(sizeof(char) * (Length + len + MEM_INC))) == NULL) - return CSstay; - if (Length) { - memcpy(new, Line, Length); - free(Line); - } - Line = new; - Length += len + MEM_INC; - } - - for (q = &Line[Point], i = End - Point; --i >= 0; ) - q[len + i] = q[i]; - memcpy(&Line[Point], p, len); - End += len; - Line[End] = '\0'; - TTYstring(&Line[Point]); - Point += len; - - return Point == End ? CSstay : CSmove; -} - -static STATUS -redisplay() -{ - TTYputs((const char *)NEWLINE); - TTYputs((const char *)Prompt); - TTYstring(Line); - return CSmove; -} - -static STATUS -redisplay_no_nl() -{ - TTYput('\r'); - TTYputs((const char *)Prompt); - TTYstring(Line); - return CSmove; -} - -static STATUS -toggle_meta_mode() -{ - rl_meta_chars = !rl_meta_chars; - return redisplay(); -} - - -static char * -next_hist() -{ - return H.Pos >= H.Size - 1 ? NULL : H.Lines[++H.Pos]; -} - -static char * -prev_hist() -{ - return H.Pos == 0 ? NULL : H.Lines[--H.Pos]; -} - -static STATUS -do_insert_hist(char *p) -{ - if (p == NULL) - return ring_bell(); - Point = 0; - reposition(); - ceol(); - End = 0; - return insert_string(p); -} - -static STATUS -do_hist(char *(*move)()) -{ - char *p; - int i; - - i = 0; - do { - if ((p = (*move)()) == NULL) - return ring_bell(); - } while (++i < Repeat); - return do_insert_hist(p); -} - -static STATUS -h_next() -{ - return do_hist(next_hist); -} - -static STATUS -h_prev() -{ - return do_hist(prev_hist); -} - -static STATUS -h_first() -{ - return do_insert_hist(H.Lines[H.Pos = 0]); -} - -static STATUS -h_last() -{ - return do_insert_hist(H.Lines[H.Pos = H.Size - 1]); -} - -/* -** Return zero if pat appears as a substring in text. -*/ -static int -substrcmp(char *text, char *pat,int len) -{ - char c; - - if ((c = *pat) == '\0') - return *text == '\0'; - for ( ; *text; text++) - if (*text == c && strncmp(text, pat, len) == 0) - return 0; - return 1; -} - -static char * -search_hist(char *search,char *(*move)()) -{ - static char *old_search; - int len; - int pos; - int (*match)(); - char *pat; - - /* Save or get remembered search pattern. */ - if (search && *search) { - if (old_search) - free(old_search); - old_search = strdup(search); - } - else { - if (old_search == NULL || *old_search == '\0') - return NULL; - search = old_search; - } - - /* Set up pattern-finder. */ - if (*search == '^') { - match = strncmp; - pat = (char *)(search + 1); - } - else { - match = substrcmp; - pat = (char *)search; - } - len = strlen(pat); - - for (pos = H.Pos; (*move)() != NULL; ) - if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0) - return H.Lines[H.Pos]; - H.Pos = pos; - return NULL; -} - -static STATUS -h_search() -{ - static int Searching; - const char *old_prompt; - char *(*move)(); - char *p; - - if (Searching) - return ring_bell(); - Searching = 1; - - clear_line(); - old_prompt = Prompt; - Prompt = "Search: "; - TTYputs((const char *)Prompt); - move = Repeat == NO_ARG ? prev_hist : next_hist; - p = editinput(); - Searching = 0; - if (p == NULL && Signal > 0) { - Signal = 0; - clear_line(); - Prompt = old_prompt; - return redisplay_no_nl(); - } - p = search_hist(p, move); - clear_line(); - Prompt = old_prompt; - if (p == NULL) { - (void)ring_bell(); - return redisplay_no_nl(); - } - return do_insert_hist(p); -} - -static STATUS -fd_char() -{ - int i; - - i = 0; - do { - if (Point >= End) - break; - right(CSmove); - } while (++i < Repeat); - return CSstay; -} - -static void -save_yank(int begin, int i) -{ - if (Yanked) { - free(Yanked); - Yanked = NULL; - } - - if (i < 1) - return; - - if ((Yanked = malloc(sizeof(char) * (i + 1))) != NULL) { - memcpy(Yanked, &Line[begin], i); - Yanked[i] = '\0'; - } -} - -static STATUS -delete_string(int count) -{ - int i; - char *p; - - if (count <= 0 || End == Point) - return ring_bell(); - - if (count == 1 && Point == End - 1) { - /* Optimize common case of delete at end of line. */ - End--; - p = &Line[Point]; - i = 1; - TTYput(' '); - if (*p == TAB) { - /* XXX */ - } - else if (ISCTL(*p)) { - i = 2; - TTYput(' '); - } - else if (rl_meta_chars && ISMETA(*p)) { - i = 3; - TTYput(' '); - TTYput(' '); - } - TTYbackn(i); - *p = '\0'; - return CSmove; - } - if (Point + count > End && (count = End - Point) <= 0) - return CSstay; - - if (count > 1) - save_yank(Point, count); - - ceol(); - for (p = &Line[Point], i = End - (Point + count) + 1; --i >= 0; p++) - p[0] = p[count]; - End -= count; - TTYstring(&Line[Point]); - return CSmove; -} - -static STATUS -bk_char() -{ - int i; - - i = 0; - do { - if (Point == 0) - break; - left(CSmove); - } while (++i < Repeat); - - return CSstay; -} - -static STATUS -bk_del_char() -{ - int i; - - i = 0; - do { - if (Point == 0) - break; - left(CSmove); - } while (++i < Repeat); - - return delete_string(i); -} - -static STATUS -kill_line() -{ - int i; - - if (Repeat != NO_ARG) { - if (Repeat < Point) { - i = Point; - Point = Repeat; - reposition(); - (void)delete_string(i - Point); - } - else if (Repeat > Point) { - right(CSmove); - (void)delete_string(Repeat - Point - 1); - } - return CSmove; - } - - save_yank(Point, End - Point); - ceol(); - Line[Point] = '\0'; - End = Point; - return CSstay; -} - -static STATUS -insert_char(int c) -{ - STATUS s; - char buff[2]; - char *p; - char *q; - int i; - - if (Repeat == NO_ARG || Repeat < 2) { - buff[0] = c; - buff[1] = '\0'; - return insert_string(buff); - } - - if ((p = malloc(sizeof(char) * (Repeat + 1))) == NULL) - return CSstay; - for (i = Repeat, q = p; --i >= 0; ) - *q++ = c; - *q = '\0'; - Repeat = 0; - s = insert_string(p); - free(p); - return s; -} - -static STATUS -meta() -{ - int c; - KEYMAP *kp; - - if ((c = TTYget()) == EOF) - return CSeof; -#if defined(ANSI_ARROWS) - /* Also include VT-100 arrows. */ - if (c == '[' || c == 'O') - switch ((int)(c = TTYget())) { - default: return ring_bell(); - case EOF: return CSeof; - case 'A': return h_prev(); - case 'B': return h_next(); - case 'C': return fd_char(); - case 'D': return bk_char(); - } -#endif /* defined(ANSI_ARROWS) */ - - if (isdigit(c)) { - for (Repeat = c - '0'; (c = TTYget()) != EOF && isdigit(c); ) - Repeat = Repeat * 10 + c - '0'; - Pushed = 1; - PushBack = c; - return CSstay; - } - - if (isupper(c)) - return do_macro(c); - for (OldPoint = Point, kp = MetaMap; kp < &MetaMap[METAMAPSIZE]; kp++) - if (kp->Key == c && kp->Active) - return (*kp->Function)(); - - return ring_bell(); -} - -static STATUS -emacs(int c) -{ - STATUS s; - KEYMAP *kp; - -#if 0 - /* This test makes it impossible to enter eight-bit characters when - * meta-char mode is enabled. */ - if (rl_meta_chars && ISMETA(c)) { - Pushed = 1; - PushBack = UNMETA(c); - return meta(); - } -#endif /* 0 */ - for (kp = Map; kp < &Map[MAPSIZE]; kp++) - if (kp->Key == c && kp->Active) - break; - s = kp < &Map[MAPSIZE] ? (*kp->Function)() : insert_char((int)c); - if (!Pushed) - /* No pushback means no repeat count; hacky, but true. */ - Repeat = NO_ARG; - return s; -} - -static STATUS -TTYspecial(int c) -{ - if (rl_meta_chars && ISMETA(c)) - return CSdispatch; - - if (c == rl_erase || c == DEL) - return bk_del_char(); - if (c == rl_kill) { - if (Point != 0) { - Point = 0; - reposition(); - } - Repeat = NO_ARG; - return kill_line(); - } - if (c == rl_eof && Point == 0 && End == 0) - return CSeof; - if (c == rl_intr) { - Signal = SIGINT; - return CSsignal; - } - if (c == rl_quit) { - Signal = SIGQUIT; - return CSsignal; - } -#if defined(DO_SIGTSTP) - if (c == rl_susp) { - Signal = SIGTSTP; - return CSsignal; - } -#endif /* defined(DO_SIGTSTP) */ - - return CSdispatch; -} - -static char * -editinput() -{ - int c; - - Repeat = NO_ARG; - OldPoint = Point = Mark = End = 0; - Line[0] = '\0'; - - Signal = -1; - while ((c = TTYget()) != EOF) - switch (TTYspecial(c)) { - case CSdone: - return Line; - case CSeof: - return NULL; - case CSsignal: - return (char *)""; - case CSmove: - reposition(); - break; - case CSdispatch: - switch (emacs(c)) { - case CSdone: - return Line; - case CSeof: - return NULL; - case CSsignal: - return (char *)""; - case CSmove: - reposition(); - break; - case CSdispatch: - case CSstay: - break; - } - break; - case CSstay: - break; - } - return NULL; -} - -static void -hist_add(char *p) -{ - int i; - - if ((p = strdup(p)) == NULL) - return; - if (H.Size < HIST_SIZE) - H.Lines[H.Size++] = p; - else { - free(H.Lines[0]); - for (i = 0; i < HIST_SIZE - 1; i++) - H.Lines[i] = H.Lines[i + 1]; - H.Lines[i] = p; - } - H.Pos = H.Size - 1; -} - -static char * -read_redirected() -{ - int size; - char *p; - char *line; - char *end; - - for (size = MEM_INC, p = line = malloc(sizeof(char) * size), end = p + size; ; p++) { - if (p == end) { - size += MEM_INC; - p = line = realloc(line, size); - end = p + size; - } - if (read(0, p, 1) <= 0) { - /* Ignore "incomplete" lines at EOF, just like we do for a tty. */ - free(line); - return NULL; - } - if (*p == '\n') - break; - } - *p = '\0'; - return line; -} - -/* -** For compatibility with FSF readline. -*/ -/* ARGSUSED0 */ -void -rl_reset_terminal(char *p) -{ - (void)p; /* Suppress warning */ -} - -void -rl_initialize() -{ -} - -int -rl_insert(int count, int c) -{ - if (count > 0) { - Repeat = count; - (void)insert_char(c); - (void)redisplay_no_nl(); - } - return 0; -} - -int (*rl_event_hook)(); - -int -rl_key_action(int c, char flag) -{ - KEYMAP *kp; - int size; - - (void)flag; /* Suppress warning */ - - if (ISMETA(c)) { - kp = MetaMap; - size = METAMAPSIZE; - } - else { - kp = Map; - size = MAPSIZE; - } - for ( ; --size >= 0; kp++) - if (kp->Key == c) { - kp->Active = c ? 1 : 0; - return 1; - } - return -1; -} - -char * -readline(const char *prompt) -{ - char *line; - int s; - - if (!isatty(0)) { - TTYflush(); - return read_redirected(); - } - - if (Line == NULL) { - Length = MEM_INC; - if ((Line = malloc(sizeof(char) * Length)) == NULL) - return NULL; - } - - TTYinfo(); - rl_ttyset(0); - hist_add(NIL); - ScreenSize = SCREEN_INC; - Screen = malloc(sizeof(char) * ScreenSize); - Prompt = prompt ? prompt : (char *)NIL; - TTYputs((const char *)Prompt); - if ((line = editinput()) != NULL) { - line = strdup(line); - TTYputs((const char *)NEWLINE); - TTYflush(); - } - rl_ttyset(1); - free(Screen); - free(H.Lines[--H.Size]); - if (Signal > 0) { - s = Signal; - Signal = 0; - (void)kill(getpid(), s); - } - return (char *)line; -} - -void -add_history(char *p) -{ - if (p == NULL || *p == '\0') - return; - -#if defined(UNIQUE_HISTORY) - if (H.Size && strcmp(p, H.Lines[H.Size - 1]) == 0) - return; -#endif /* defined(UNIQUE_HISTORY) */ - hist_add((char *)p); -} - - -static STATUS -beg_line() -{ - if (Point) { - Point = 0; - return CSmove; - } - return CSstay; -} - -static STATUS -del_char() -{ - return delete_string(Repeat == NO_ARG ? 1 : Repeat); -} - -static STATUS -end_line() -{ - if (Point != End) { - Point = End; - return CSmove; - } - return CSstay; -} - -/* -** Return allocated copy of word under cursor, moving cursor after the -** word. -*/ -static char * -find_word() -{ - static char SEPS[] = "\"#;&|^$=`'{}()<>\n\t "; - char *p; - char *new; - size_t len; - - /* Move forward to end of word. */ - p = &Line[Point]; - for ( ; Point < End && strchr(SEPS, (char)*p) == NULL; Point++, p++) - right(CSstay); - - /* Back up to beginning of word. */ - for (p = &Line[Point]; p > Line && strchr(SEPS, (char)p[-1]) == NULL; p--) - continue; - len = Point - (p - Line) + 1; - if ((new = malloc(sizeof(char) * len)) == NULL) - return NULL; - memcpy(new, p, len); - new[len - 1] = '\0'; - return new; -} - -static STATUS -c_complete() -{ - char *p; - char *word; - int unique; - - word = find_word(); - p = (char *)rl_complete((char *)word, &unique); - if (word) - free(word); - if (p && *p) { - (void)insert_string(p); - if (!unique) - (void)ring_bell(); - free(p); - return redisplay_no_nl(); - } - return ring_bell(); -} - -static STATUS -c_possible() -{ - char **av; - char *word; - int ac; - - word = find_word(); - ac = rl_list_possib((char *)word, (char ***)&av); - if (word) - free(word); - if (ac) { - columns(ac, av); - while (--ac >= 0) - free(av[ac]); - free(av); - return redisplay_no_nl(); - } - return ring_bell(); -} - -static STATUS -accept_line() -{ - Line[End] = '\0'; - return CSdone; -} - -static STATUS -transpose() -{ - char c; - - if (Point) { - if (Point == End) - left(CSmove); - c = Line[Point - 1]; - left(CSstay); - Line[Point - 1] = Line[Point]; - TTYshow(Line[Point - 1]); - Line[Point++] = c; - TTYshow(c); - } - return CSstay; -} - -static STATUS -quote() -{ - int c; - - return (c = TTYget()) == EOF ? CSeof : insert_char((int)c); -} - -static STATUS -wipe() -{ - int i; - - if (Mark > End) - return ring_bell(); - - if (Point > Mark) { - i = Point; - Point = Mark; - Mark = i; - reposition(); - } - - return delete_string(Mark - Point); -} - -static STATUS -mk_set() -{ - Mark = Point; - return CSstay; -} - -static STATUS -exchange() -{ - int c; - - if ((c = TTYget()) != CTL('X')) - return c == EOF ? CSeof : ring_bell(); - - if ((c = Mark) <= End) { - Mark = Point; - Point = c; - return CSmove; - } - return CSstay; -} - -static STATUS -yank() -{ - if (Yanked && *Yanked) - return insert_string(Yanked); - return CSstay; -} - -static STATUS -copy_region() -{ - if (Mark > End) - return ring_bell(); - - if (Point > Mark) - save_yank(Mark, Point - Mark); - else - save_yank(Point, Mark - Point); - - return CSstay; -} - -static STATUS -move_to_char() -{ - int c; - int i; - char *p; - - if ((c = TTYget()) == EOF) - return CSeof; - for (i = Point + 1, p = &Line[i]; i < End; i++, p++) - if (*p == c) { - Point = i; - return CSmove; - } - return CSstay; -} - -static STATUS -fd_word() -{ - return do_forward(CSmove); -} - -static STATUS -fd_kill_word() -{ - int i; - - (void)do_forward(CSstay); - if (OldPoint != Point) { - i = Point - OldPoint; - Point = OldPoint; - return delete_string(i); - } - return CSstay; -} - -static STATUS -bk_word() -{ - int i; - char *p; - - i = 0; - do { - for (p = &Line[Point]; p > Line && !isalnum((int)p[-1]); p--) - left(CSmove); - - for (; p > Line && p[-1] != ' ' && isalnum((int)p[-1]); p--) - left(CSmove); - - if (Point == 0) - break; - } while (++i < Repeat); - - return CSstay; -} - -static STATUS -bk_kill_word() -{ - (void)bk_word(); - if (OldPoint != Point) - return delete_string(OldPoint - Point); - return CSstay; -} - -static int -argify(char *line, char ***avp) -{ - char *c; - char **p; - char **new; - int ac; - int i; - - i = MEM_INC; - if ((*avp = p = malloc(sizeof(char*) * i))== NULL) - return 0; - - for (c = line; isspace((int)*c); c++) - continue; - if (*c == '\n' || *c == '\0') - return 0; - - for (ac = 0, p[ac++] = c; *c && *c != '\n'; ) { - if (isspace((int)*c)) { - *c++ = '\0'; - if (*c && *c != '\n') { - if (ac + 1 == i) { - new = malloc(sizeof(char*) * (i + MEM_INC)); - if (new == NULL) { - p[ac] = NULL; - return ac; - } - memcpy(new, p, i * sizeof (char **)); - i += MEM_INC; - free(p); - *avp = p = new; - } - p[ac++] = c; - } - } - else - c++; - } - *c = '\0'; - p[ac] = NULL; - return ac; -} - -static STATUS -last_argument() -{ - char **av; - char *p; - STATUS s; - int ac; - - if (H.Size == 1 || (p = H.Lines[H.Size - 2]) == NULL) - return ring_bell(); - - if ((p = strdup(p)) == NULL) - return CSstay; - ac = argify(p, &av); - - if (Repeat != NO_ARG) - s = Repeat < ac ? insert_string(av[Repeat]) : ring_bell(); - else - s = ac ? insert_string(av[ac - 1]) : CSstay; - - if (ac) - free(av); - free(p); - return s; -} - -static KEYMAP Map[MAPSIZE] = { - { CTL('@'), 1, ring_bell }, - { CTL('A'), 1, beg_line }, - { CTL('B'), 1, bk_char }, - { CTL('D'), 1, del_char }, - { CTL('E'), 1, end_line }, - { CTL('F'), 1, fd_char }, - { CTL('G'), 1, ring_bell }, - { CTL('H'), 1, bk_del_char }, - { CTL('I'), 1, c_complete }, - { CTL('J'), 1, accept_line }, - { CTL('K'), 1, kill_line }, - { CTL('L'), 1, redisplay }, - { CTL('M'), 1, accept_line }, - { CTL('N'), 1, h_next }, - { CTL('O'), 1, ring_bell }, - { CTL('P'), 1, h_prev }, - { CTL('Q'), 1, ring_bell }, - { CTL('R'), 1, h_search }, - { CTL('S'), 1, ring_bell }, - { CTL('T'), 1, transpose }, - { CTL('U'), 1, ring_bell }, - { CTL('V'), 1, quote }, - { CTL('W'), 1, wipe }, - { CTL('X'), 1, exchange }, - { CTL('Y'), 1, yank }, - { CTL('Z'), 1, ring_bell }, - { CTL('['), 1, meta }, - { CTL(']'), 1, move_to_char }, - { CTL('^'), 1, ring_bell }, - { CTL('_'), 1, ring_bell }, -}; - -static KEYMAP MetaMap[16]= { - { CTL('H'), 1, bk_kill_word }, - { CTL('['), 1, c_possible }, - { DEL, 1, bk_kill_word }, - { ' ', 1, mk_set }, - { '.', 1, last_argument }, - { '<', 1, h_first }, - { '>', 1, h_last }, - { '?', 1, c_possible }, - { 'b', 1, bk_word }, - { 'd', 1, fd_kill_word }, - { 'f', 1, fd_word }, - { 'l', 1, case_down_word }, - { 'm', 1, toggle_meta_mode}, - { 'u', 1, case_up_word }, - { 'y', 1, yank }, - { 'w', 1, copy_region }, -}; diff --git a/ndb/src/common/editline/editline_internal.h b/ndb/src/common/editline/editline_internal.h deleted file mode 100644 index d82fa91c44b..00000000000 --- a/ndb/src/common/editline/editline_internal.h +++ /dev/null @@ -1,30 +0,0 @@ -/* $Revision: 1.2 $ -** -** Internal header file for editline library. -*/ - -#include - -#if defined(SYS_UNIX) -#include "unix.h" -#endif /* defined(SYS_UNIX) */ - -#define MEM_INC 64 -#define SCREEN_INC 256 - -/* -** Variables and routines internal to this package. -*/ -extern int rl_eof; -extern int rl_erase; -extern int rl_intr; -extern int rl_kill; -extern int rl_quit; -#if defined(DO_SIGTSTP) -extern int rl_susp; -#endif /* defined(DO_SIGTSTP) */ -extern char *rl_complete(); -extern int rl_list_possib(); -extern void rl_ttyset(); -extern void rl_add_slash(); - diff --git a/ndb/src/common/editline/sysunix.c b/ndb/src/common/editline/sysunix.c deleted file mode 100644 index b0242fb99ce..00000000000 --- a/ndb/src/common/editline/sysunix.c +++ /dev/null @@ -1,132 +0,0 @@ -/* $Revision: 1.4 $ -** -** Unix system-dependant routines for editline library. -*/ -#include "editline_internal.h" - -#if defined(HAVE_TCGETATTR) -#include - -void -rl_ttyset(int Reset) -{ - static struct termios old; - struct termios new; - - if (Reset == 0) { - if (tcgetattr(0, &old) < 0) perror("tcgetattr"); - rl_erase = old.c_cc[VERASE]; - rl_kill = old.c_cc[VKILL]; - rl_eof = old.c_cc[VEOF]; - rl_intr = old.c_cc[VINTR]; - rl_quit = old.c_cc[VQUIT]; -#if defined(DO_SIGTSTP) - rl_susp = old.c_cc[VSUSP]; -#endif /* defined(DO_SIGTSTP) */ - - new = old; - new.c_lflag &= ~(ECHO | ICANON | ISIG); - new.c_iflag &= ~(ISTRIP | INPCK); - new.c_cc[VMIN] = 1; - new.c_cc[VTIME] = 0; - if (tcsetattr(0, TCSADRAIN, &new) < 0) perror("tcsetattr"); - } - else - (void)tcsetattr(0, TCSADRAIN, &old); -} - -#else -#if defined(HAVE_TERMIO) -#include - -void -rl_ttyset(int Reset) -{ - static struct termio old; - struct termio new; - - if (Reset == 0) { - (void)ioctl(0, TCGETA, &old); - rl_erase = old.c_cc[VERASE]; - rl_kill = old.c_cc[VKILL]; - rl_eof = old.c_cc[VEOF]; - rl_intr = old.c_cc[VINTR]; - rl_quit = old.c_cc[VQUIT]; -#if defined(DO_SIGTSTP) - rl_susp = old.c_cc[VSUSP]; -#endif /* defined(DO_SIGTSTP) */ - - new = old; - new.c_lflag &= ~(ECHO | ICANON | ISIG); - new.c_iflag &= ~(ISTRIP | INPCK); - new.c_cc[VMIN] = 1; - new.c_cc[VTIME] = 0; - (void)ioctl(0, TCSETAW, &new); - } - else - (void)ioctl(0, TCSETAW, &old); -} - -#else -#include - -void -rl_ttyset(int Reset) -{ - static struct sgttyb old_sgttyb; - static struct tchars old_tchars; - struct sgttyb new_sgttyb; - struct tchars new_tchars; -#if defined(DO_SIGTSTP) - struct ltchars old_ltchars; -#endif /* defined(DO_SIGTSTP) */ - - if (Reset == 0) { - (void)ioctl(0, TIOCGETP, &old_sgttyb); - rl_erase = old_sgttyb.sg_erase; - rl_kill = old_sgttyb.sg_kill; - - (void)ioctl(0, TIOCGETC, &old_tchars); - rl_eof = old_tchars.t_eofc; - rl_intr = old_tchars.t_intrc; - rl_quit = old_tchars.t_quitc; - -#if defined(DO_SIGTSTP) - (void)ioctl(0, TIOCGLTC, &old_ltchars); - rl_susp = old_ltchars.t_suspc; -#endif /* defined(DO_SIGTSTP) */ - - new_sgttyb = old_sgttyb; - new_sgttyb.sg_flags &= ~ECHO; - new_sgttyb.sg_flags |= RAW; -#if defined(PASS8) - new_sgttyb.sg_flags |= PASS8; -#endif /* defined(PASS8) */ - (void)ioctl(0, TIOCSETP, &new_sgttyb); - - new_tchars = old_tchars; - new_tchars.t_intrc = -1; - new_tchars.t_quitc = -1; - (void)ioctl(0, TIOCSETC, &new_tchars); - } - else { - (void)ioctl(0, TIOCSETP, &old_sgttyb); - (void)ioctl(0, TIOCSETC, &old_tchars); - } -} -#endif /* defined(HAVE_TERMIO) */ -#endif /* defined(HAVE_TCGETATTR) */ - -void -rl_add_slash(char *path, char *p, size_t p_len) -{ - struct stat Sb; - - if (stat(path, &Sb) >= 0) { - size_t len= strlen(p); - if (len+1 < p_len) { - p[len]= S_ISDIR(Sb.st_mode) ? '/' : ' '; - p[len+1]= 0; - } - } -} diff --git a/ndb/src/common/editline/test/Makefile b/ndb/src/common/editline/test/Makefile deleted file mode 100644 index 20229d0aa62..00000000000 --- a/ndb/src/common/editline/test/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include .defs.mk - -TYPE := util - -BIN_TARGET := editline_test -BIN_TARGET_ARCHIVES := editline - -SOURCES = testit.c - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/common/editline/test/testit.c b/ndb/src/common/editline/test/testit.c deleted file mode 100644 index 4058f8ae660..00000000000 --- a/ndb/src/common/editline/test/testit.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 2003 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -/* -*- c-basic-offset: 4; -*- -** $Revision: 1.5 $ -** -** A "micro-shell" to test editline library. -** If given any arguments, commands aren't executed. -*/ -#include -#include - -int -main(int argc, char **argv) -{ - char *prompt; - char *p; - int doit; - - (void)argv; /* Suppress warning */ - - doit = argc == 1; - if ((prompt = getenv("TESTPROMPT")) == NULL) - prompt = "testit> "; - - while ((p = readline(prompt)) != NULL) { - (void)printf("\t\t\t|%s|\n", p); - if (doit) { - if (strncmp(p, "cd ", 3) == 0) { - if (chdir(&p[3]) < 0) - perror(&p[3]); - } else { - if (system(p) != 0) - perror(p); - } - } - add_history(p); - free(p); - } - - return 0; -} diff --git a/ndb/src/common/editline/unix.h b/ndb/src/common/editline/unix.h deleted file mode 100644 index c2fde7547b3..00000000000 --- a/ndb/src/common/editline/unix.h +++ /dev/null @@ -1,9 +0,0 @@ -/* $Revision: 1.3 $ -** -** Editline system header file for Unix. -*/ - -#define CRLF "\r\n" - -#include -#include diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index e0935c2104e..e802ffff5ce 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -17,7 +17,195 @@ #include #include -#include "CommandInterpreter.hpp" +// copied from mysql.cc to get readline +extern "C" { +#if defined( __WIN__) || defined(OS2) +#include +#elif !defined(__NETWARE__) +#include +extern "C" int add_history(const char *command); /* From readline directory */ +#define HAVE_READLINE +#endif +} + +//#define HAVE_GLOBAL_REPLICATION + +#include +#ifdef HAVE_GLOBAL_REPLICATION +#include "../rep/repapi/repapi.h" +#endif + +#include + +class MgmtSrvr; + +/** + * @class CommandInterpreter + * @brief Reads command line in management client + * + * This class has one public method which reads a command line + * from a stream. It then interpret that commmand line and calls a suitable + * method in the MgmtSrvr class which executes the command. + * + * For command syntax, see the HELP command. + */ +class CommandInterpreter { +public: + /** + * Constructor + * @param mgmtSrvr: Management server to use when executing commands + */ + CommandInterpreter(const char *); + ~CommandInterpreter(); + + /** + * Reads one line from the stream, parse the line to find + * a command and then calls a suitable method which executes + * the command. + * + * @return true until quit/bye/exit has been typed + */ + int readAndExecute(int _try_reconnect=-1); + int execute(const char *_line, int _try_reconnect=-1); + +private: + void printError(); + + /** + * Analyse the command line, after the first token. + * + * @param processId: DB process id to send command to or -1 if + * command will be sent to all DB processes. + * @param allAfterFirstToken: What the client gave after the + * first token on the command line + */ + void analyseAfterFirstToken(int processId, char* allAfterFirstTokenCstr); + + /** + * Parse the block specification part of the LOG* commands, + * things after LOG*: [BLOCK = {ALL|+}] + * + * @param allAfterLog: What the client gave after the second token + * (LOG*) on the command line + * @param blocks, OUT: ALL or name of all the blocks + * @return: true if correct syntax, otherwise false + */ + bool parseBlockSpecification(const char* allAfterLog, + Vector& blocks); + + /** + * A bunch of execute functions: Executes one of the commands + * + * @param processId: DB process id to send command to + * @param parameters: What the client gave after the command name + * on the command line. + * For example if complete input from user is: "1 LOGLEVEL 22" then the + * parameters argument is the string with everything after LOGLEVEL, in + * this case "22". Each function is responsible to check the parameters + * argument. + */ + void executeHelp(char* parameters); + void executeShow(char* parameters); + void executeShutdown(char* parameters); + void executeRun(char* parameters); + void executeInfo(char* parameters); + void executeClusterLog(char* parameters); + +public: + void executeStop(int processId, const char* parameters, bool all); + void executeEnterSingleUser(char* parameters); + void executeExitSingleUser(char* parameters); + void executeStart(int processId, const char* parameters, bool all); + void executeRestart(int processId, const char* parameters, bool all); + void executeLogLevel(int processId, const char* parameters, bool all); + void executeError(int processId, const char* parameters, bool all); + void executeTrace(int processId, const char* parameters, bool all); + void executeLog(int processId, const char* parameters, bool all); + void executeLogIn(int processId, const char* parameters, bool all); + void executeLogOut(int processId, const char* parameters, bool all); + void executeLogOff(int processId, const char* parameters, bool all); + void executeTestOn(int processId, const char* parameters, bool all); + void executeTestOff(int processId, const char* parameters, bool all); + void executeSet(int processId, const char* parameters, bool all); + void executeGetStat(int processId, const char* parameters, bool all); + void executeStatus(int processId, const char* parameters, bool all); + void executeEventReporting(int processId, const char* parameters, bool all); + void executeDumpState(int processId, const char* parameters, bool all); + void executeStartBackup(char * parameters); + void executeAbortBackup(char * parameters); + + void executeRep(char* parameters); + + void executeCpc(char * parameters); + +public: + bool connect(); + bool disconnect(); + + /** + * A execute function definition + */ +public: + typedef void (CommandInterpreter::* ExecuteFunction)(int processId, + const char * param, + bool all); + + struct CommandFunctionPair { + const char * command; + ExecuteFunction executeFunction; + }; +private: + /** + * + */ + void executeForAll(const char * cmd, + ExecuteFunction fun, + const char * param); + + NdbMgmHandle m_mgmsrv; + bool connected; + const char *host; + int try_reconnect; +#ifdef HAVE_GLOBAL_REPLICATION + NdbRepHandle m_repserver; + const char *rep_host; + bool rep_connected; +#endif +}; + + +/* + * Facade object for CommandInterpreter + */ + +#include "ndb_mgmclient.hpp" + +Ndb_mgmclient::Ndb_mgmclient(const char *host) +{ + m_cmd= new CommandInterpreter(host); +} +Ndb_mgmclient::~Ndb_mgmclient() +{ + delete m_cmd; +} +int Ndb_mgmclient::read_and_execute(int _try_reconnect) +{ + return m_cmd->readAndExecute(_try_reconnect); +} +int Ndb_mgmclient::execute(const char *_line, int _try_reconnect) +{ + return m_cmd->execute(_line,_try_reconnect); +} +int +Ndb_mgmclient::disconnect() +{ + return m_cmd->disconnect(); +} + + +/* + * The CommandInterpreter + */ #include #include @@ -33,7 +221,10 @@ #endif // HAVE_GLOBAL_REPLICATION #include "MgmtErrorReporter.hpp" -#include "CpcClient.hpp" +#include +#include +#include +#include /***************************************************************************** @@ -201,7 +392,7 @@ CommandInterpreter::~CommandInterpreter() host = NULL; } -bool +static bool emptyString(const char* s) { if (s == NULL) { @@ -265,17 +456,47 @@ CommandInterpreter::disconnect() int CommandInterpreter::readAndExecute(int _try_reconnect) +{ + static char *line_read = (char *)NULL; + + /* If the buffer has already been allocated, return the memory + to the free pool. */ + if (line_read) + { + free (line_read); + line_read = (char *)NULL; + } +#ifdef HAVE_READLINE + /* Get a line from the user. */ + line_read = readline ("ndb_mgm> "); + /* If the line has any text in it, save it on the history. */ + if (line_read && *line_read) + add_history (line_read); +#else + static char linebuffer[254]; + fputs("ndb_mgm> ", stdout); + linebuffer[sizeof(linebuffer)-1]=0; + line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); + if (line_read == linebuffer) { + char *q=linebuffer; + while (*q > 31) q++; + *q=0; + line_read= strdup(linebuffer); + } +#endif + return execute(line_read,_try_reconnect); +} + +int +CommandInterpreter::execute(const char *_line, int _try_reconnect) { if (_try_reconnect >= 0) try_reconnect=_try_reconnect; - - char* _line = readline_gets(); char * line; if(_line == NULL) { // ndbout << endl; return false; } - line = my_strdup(_line,MYF(MY_WME)); My_auto_ptr ptr(line); @@ -349,10 +570,6 @@ CommandInterpreter::readAndExecute(int _try_reconnect) strcmp(firstToken, "BYE") == 0) && allAfterFirstToken == NULL){ return false; -#if 0 - } else if(strcmp(firstToken, "CPC") == 0) { - executeCpc(allAfterFirstToken); -#endif } else { /** * First token should be a digit, node ID @@ -1903,169 +2120,4 @@ CommandInterpreter::executeRep(char* parameters) } #endif // HAVE_GLOBAL_REPLICATION - -/***************************************************************************** - * CPC - *****************************************************************************/ - -#if 0 - -#if 0 -//#ifdef NDB_SOLARIS // XXX fix me -static char* strsep(char** x, const char* y) { return 0; } -#endif - -// Note this code has not been verified -#if 0 -static char * my_strsep(char **stringp, const char *delim) -{ - char *tmp= *stringp; - if (tmp == 0) - return 0; - *stringp = strtok(tmp, delim); - return tmp; -} -#endif - -void -CommandInterpreter::executeCpc(char *parameters) -{ - char *host_str = NULL, *port_str = NULL, *end; - long port = 1234; /* XXX */ - - while((host_str = my_strsep(¶meters, " \t:")) != NULL && - host_str[0] == '\0'); - - if(parameters && parameters[0] != '\0') { - while((port_str = my_strsep(¶meters, " \t:")) != NULL && - port_str[0] == '\0'); - - errno = 0; - port = strtol(port_str, &end, 0); - if(end[0] != '\0') - goto error; - if((port == LONG_MAX || port == LONG_MIN) && - errno == ERANGE) - goto error; - } - - { - SimpleCpcClient cpc(host_str, port); - bool done = false; - - if(cpc.connect() < 0) { - ndbout_c("Cannot connect to %s:%d.", cpc.getHost(), cpc.getPort()); - switch(errno) { - case ENOENT: - ndbout << ": " << "No such host" << endl; - break; - default: - ndbout << ": " << strerror(errno) << endl; - break; - } - return; - } - - while(!done) { - char *line = readline("CPC> "); - if(line != NULL) { - add_history(line); - - char *cmd = strtok(line, " "); - char *arg = strtok(NULL, ""); - - if(arg != NULL) { - while(arg[0] == ' ') - arg++; - if(strlen(arg) == 0) - arg = NULL; - } - - if(cmd != NULL) { - if(strcmp(cmd, "exit") == 0) - done = true; - else if(strcmp(cmd, "list") == 0) - cpc.cmd_list(arg); - else if(strcmp(cmd, "start") == 0) - cpc.cmd_start(arg); - else if(strcmp(cmd, "stop") == 0) - cpc.cmd_stop(arg); - else if(strcmp(cmd, "help") == 0) - cpc.cmd_help(arg); - } - } else { - done = true; - ndbout << endl; - } - } - } - return; - - error: - ndbout << "Error: expected a tcp port number, got '" << port_str << "'." - << endl; - return; -} -#endif - -#if 0 -static -void -CmdBackupCallback(const MgmtSrvr::BackupEvent & event){ - char str[255]; - - ndbout << endl; - - bool ok = false; - switch(event.Event){ - case MgmtSrvr::BackupEvent::BackupStarted: - ok = true; - BaseString::snprintf(str, sizeof(str), - "Backup %d started", event.Started.BackupId); - break; - case MgmtSrvr::BackupEvent::BackupFailedToStart: - ok = true; - BaseString::snprintf(str, sizeof(str), - "Backup failed to start (Error %d)", - event.FailedToStart.ErrorCode); - break; - case MgmtSrvr::BackupEvent::BackupCompleted: - ok = true; - BaseString::snprintf(str, sizeof(str), - "Backup %d completed", - event.Completed.BackupId); - ndbout << str << endl; - - BaseString::snprintf(str, sizeof(str), - " StartGCP: %d StopGCP: %d", - event.Completed.startGCP, event.Completed.stopGCP); - ndbout << str << endl; - - BaseString::snprintf(str, sizeof(str), - " #Records: %d #LogRecords: %d", - event.Completed.NoOfRecords, event.Completed.NoOfLogRecords); - ndbout << str << endl; - - BaseString::snprintf(str, sizeof(str), - " Data: %d bytes Log: %d bytes", - event.Completed.NoOfBytes, event.Completed.NoOfLogBytes); - break; - case MgmtSrvr::BackupEvent::BackupAborted: - ok = true; - BaseString::snprintf(str, sizeof(str), - "Backup %d has been aborted reason %d", - event.Aborted.BackupId, - event.Aborted.Reason); - break; - } - if(!ok){ - BaseString::snprintf(str, sizeof(str), - "Unknown backup event: %d", - event.Event); - - } - ndbout << str << endl; -} -#endif - template class Vector; diff --git a/ndb/src/mgmclient/CommandInterpreter.hpp b/ndb/src/mgmclient/CommandInterpreter.hpp deleted file mode 100644 index eecc48a739e..00000000000 --- a/ndb/src/mgmclient/CommandInterpreter.hpp +++ /dev/null @@ -1,197 +0,0 @@ -/* Copyright (C) 2003 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#ifndef CommandInterpreter_H -#define CommandInterpreter_H - -//#define HAVE_GLOBAL_REPLICATION -//***************************************************************************** -// Author: Peter Lind -//***************************************************************************** - -#include -#include -#include - -#ifdef HAVE_GLOBAL_REPLICATION -#include "../rep/repapi/repapi.h" -#endif - -#include - -class MgmtSrvr; - -/** - * @class CommandInterpreter - * @brief Reads command line in management client - * - * This class has one public method which reads a command line - * from a stream. It then interpret that commmand line and calls a suitable - * method in the MgmtSrvr class which executes the command. - * - * For command syntax, see the HELP command. - */ -class CommandInterpreter { -public: - /** - * Constructor - * @param mgmtSrvr: Management server to use when executing commands - */ - CommandInterpreter(const char *); - ~CommandInterpreter(); - - /** - * Reads one line from the stream, parse the line to find - * a command and then calls a suitable method which executes - * the command. - * - * @return true until quit/bye/exit has been typed - */ - int readAndExecute(int _try_reconnect=-1); - -private: - /** - * Read a string, and return a pointer to it. - * - * @return NULL on EOF. - */ - char *readline_gets () - { - static char *line_read = (char *)NULL; - - /* If the buffer has already been allocated, return the memory - to the free pool. */ - if (line_read) - { - free (line_read); - line_read = (char *)NULL; - } - - /* Get a line from the user. */ - line_read = readline ("NDB> "); - - /* If the line has any text in it, save it on the history. */ - if (line_read && *line_read) - add_history (line_read); - - return (line_read); - } - - void printError(); - - /** - * Analyse the command line, after the first token. - * - * @param processId: DB process id to send command to or -1 if - * command will be sent to all DB processes. - * @param allAfterFirstToken: What the client gave after the - * first token on the command line - */ - void analyseAfterFirstToken(int processId, char* allAfterFirstTokenCstr); - - /** - * Parse the block specification part of the LOG* commands, - * things after LOG*: [BLOCK = {ALL|+}] - * - * @param allAfterLog: What the client gave after the second token - * (LOG*) on the command line - * @param blocks, OUT: ALL or name of all the blocks - * @return: true if correct syntax, otherwise false - */ - bool parseBlockSpecification(const char* allAfterLog, - Vector& blocks); - - /** - * A bunch of execute functions: Executes one of the commands - * - * @param processId: DB process id to send command to - * @param parameters: What the client gave after the command name - * on the command line. - * For example if complete input from user is: "1 LOGLEVEL 22" then the - * parameters argument is the string with everything after LOGLEVEL, in - * this case "22". Each function is responsible to check the parameters - * argument. - */ - void executeHelp(char* parameters); - void executeShow(char* parameters); - void executeShutdown(char* parameters); - void executeRun(char* parameters); - void executeInfo(char* parameters); - void executeClusterLog(char* parameters); - -public: - void executeStop(int processId, const char* parameters, bool all); - void executeEnterSingleUser(char* parameters); - void executeExitSingleUser(char* parameters); - void executeStart(int processId, const char* parameters, bool all); - void executeRestart(int processId, const char* parameters, bool all); - void executeLogLevel(int processId, const char* parameters, bool all); - void executeError(int processId, const char* parameters, bool all); - void executeTrace(int processId, const char* parameters, bool all); - void executeLog(int processId, const char* parameters, bool all); - void executeLogIn(int processId, const char* parameters, bool all); - void executeLogOut(int processId, const char* parameters, bool all); - void executeLogOff(int processId, const char* parameters, bool all); - void executeTestOn(int processId, const char* parameters, bool all); - void executeTestOff(int processId, const char* parameters, bool all); - void executeSet(int processId, const char* parameters, bool all); - void executeGetStat(int processId, const char* parameters, bool all); - void executeStatus(int processId, const char* parameters, bool all); - void executeEventReporting(int processId, const char* parameters, bool all); - void executeDumpState(int processId, const char* parameters, bool all); - void executeStartBackup(char * parameters); - void executeAbortBackup(char * parameters); - - void executeRep(char* parameters); - - void executeCpc(char * parameters); - -public: - bool connect(); - bool disconnect(); - - /** - * A execute function definition - */ -public: - typedef void (CommandInterpreter::* ExecuteFunction)(int processId, - const char * param, - bool all); - - struct CommandFunctionPair { - const char * command; - ExecuteFunction executeFunction; - }; -private: - /** - * - */ - void executeForAll(const char * cmd, - ExecuteFunction fun, - const char * param); - - NdbMgmHandle m_mgmsrv; - bool connected; - const char *host; - int try_reconnect; -#ifdef HAVE_GLOBAL_REPLICATION - NdbRepHandle m_repserver; - const char *rep_host; - bool rep_connected; -#endif -}; - -#endif // CommandInterpreter_H diff --git a/ndb/src/mgmclient/Makefile.am b/ndb/src/mgmclient/Makefile.am index e271c7bed53..e3f0b23a79a 100644 --- a/ndb/src/mgmclient/Makefile.am +++ b/ndb/src/mgmclient/Makefile.am @@ -1,18 +1,19 @@ ndbtools_PROGRAMS = ndb_mgm +noinst_LTLIBRARIES = libndbmgmclient.la -ndb_mgm_SOURCES = \ - main.cpp \ - CommandInterpreter.cpp \ - CpcClient.cpp +libndbmgmclient_la_SOURCES = CommandInterpreter.cpp + +ndb_mgm_SOURCES = main.cpp include $(top_srcdir)/ndb/config/common.mk.am include $(top_srcdir)/ndb/config/type_ndbapi.mk.am INCLUDES += -I$(top_srcdir)/ndb/include/mgmapi -I$(top_srcdir)/ndb/src/common/mgmcommon -LDADD_LOC = $(top_builddir)/ndb/src/libndbclient.la \ - $(top_builddir)/ndb/src/common/editline/libeditline.a \ +LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/libndbmgmclient.la \ + @readline_link@ \ + $(top_builddir)/ndb/src/libndbclient.la \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/strings/libmystrings.a \ diff --git a/ndb/src/mgmclient/Makefile_old b/ndb/src/mgmclient/Makefile_old deleted file mode 100644 index d1b2d60a52a..00000000000 --- a/ndb/src/mgmclient/Makefile_old +++ /dev/null @@ -1,25 +0,0 @@ -include .defs.mk - -TYPE := ndbapi - -BIN_TARGET := mgmtclient -BIN_TARGET_LIBS := -BIN_TARGET_ARCHIVES := trace logger mgmapi general mgmsrvcommon portlib repapi - -BIN_TARGET_ARCHIVES += editline - -DIRS = test_cpcd - -# Source files of non-templated classes (.cpp files) -SOURCES = \ - main.cpp \ - CommandInterpreter.cpp \ - CpcClient.cpp - -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/include/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/src/common/mgmcommon) - -include $(NDB_TOP)/Epilogue.mk - -_bins_mkconfig : $(NDB_TOP)/bin/$(BIN_TARGET) - diff --git a/ndb/src/mgmclient/main.cpp b/ndb/src/mgmclient/main.cpp index a37214d366b..3415ede1985 100644 --- a/ndb/src/mgmclient/main.cpp +++ b/ndb/src/mgmclient/main.cpp @@ -23,12 +23,12 @@ #include #include -#include "CommandInterpreter.hpp" +#include "ndb_mgmclient.hpp" const char *progname = "ndb_mgm"; -static CommandInterpreter* com; +static Ndb_mgmclient* com; extern "C" void @@ -127,8 +127,8 @@ int main(int argc, char** argv){ signal(SIGPIPE, handler); - com = new CommandInterpreter(buf); - while(com->readAndExecute(_try_reconnect)); + com = new Ndb_mgmclient(buf); + while(com->read_and_execute(_try_reconnect)); delete com; return 0; diff --git a/ndb/src/common/editline/editline_win32.c b/ndb/src/mgmclient/ndb_mgmclient.hpp similarity index 68% rename from ndb/src/common/editline/editline_win32.c rename to ndb/src/mgmclient/ndb_mgmclient.hpp index 5083edb7fae..2f021a0f2b6 100644 --- a/ndb/src/common/editline/editline_win32.c +++ b/ndb/src/mgmclient/ndb_mgmclient.hpp @@ -14,19 +14,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef Ndb_mgmclient_h +#define Ndb_mgmclient_h -#include - - -char* readline(const char* prompt) +class CommandInterpreter; +class Ndb_mgmclient { - char* szBuf; - printf(prompt); - szBuf = (char*)malloc(256); - return gets(szBuf); -} - -void add_history(char* pch) -{ -} +public: + Ndb_mgmclient(const char*); + ~Ndb_mgmclient(); + int read_and_execute(int _try_reconnect=-1); + int execute(const char *_line, int _try_reconnect=-1); + int disconnect(); +private: + CommandInterpreter *m_cmd; +}; +#endif // Ndb_mgmclient_h diff --git a/ndb/src/mgmsrv/CommandInterpreter.hpp b/ndb/src/mgmsrv/CommandInterpreter.hpp index 3466ee76226..db23f76a5bd 100644 --- a/ndb/src/mgmsrv/CommandInterpreter.hpp +++ b/ndb/src/mgmsrv/CommandInterpreter.hpp @@ -23,7 +23,6 @@ #include #include -#include #include class MgmtSrvr; @@ -63,26 +62,27 @@ private: */ char *readline_gets () { + static char linebuffer[254]; static char *line_read = (char *)NULL; - // Disable the default file-name completion action of TAB - // rl_bind_key ('\t', rl_insert); - /* If the buffer has already been allocated, return the memory to the free pool. */ if (line_read) - { - free (line_read); - line_read = (char *)NULL; - } + { + free (line_read); + line_read = (char *)NULL; + } /* Get a line from the user. */ - line_read = readline ("NDB> "); - - /* If the line has any text in it, save it on the history. */ - if (line_read && *line_read) - add_history (line_read); - + fputs("ndb_mgmd> ", stdout); + linebuffer[sizeof(linebuffer)-1]=0; + line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); + if (line_read == linebuffer) { + char *q=linebuffer; + while (*q > 31) q++; + *q=0; + line_read= strdup(linebuffer); + } return (line_read); } diff --git a/ndb/src/mgmsrv/Makefile.am b/ndb/src/mgmsrv/Makefile.am index 3b57b027827..4cb164d48fe 100644 --- a/ndb/src/mgmsrv/Makefile.am +++ b/ndb/src/mgmsrv/Makefile.am @@ -24,7 +24,6 @@ INCLUDES_LOC = -I$(top_srcdir)/ndb/src/ndbapi \ -I$(top_srcdir)/ndb/src/common/mgmcommon LDADD_LOC = $(top_builddir)/ndb/src/libndbclient.la \ - $(top_builddir)/ndb/src/common/editline/libeditline.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/strings/libmystrings.a @NDB_SCI_LIBS@ diff --git a/ndb/src/mgmclient/CpcClient.hpp b/ndb/test/include/CpcClient.hpp similarity index 100% rename from ndb/src/mgmclient/CpcClient.hpp rename to ndb/test/include/CpcClient.hpp diff --git a/ndb/test/run-test/Makefile.am b/ndb/test/run-test/Makefile.am index 1eac96e7ac7..c890536dcc6 100644 --- a/ndb/test/run-test/Makefile.am +++ b/ndb/test/run-test/Makefile.am @@ -11,9 +11,8 @@ test_SCRIPTS=atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \ atrt-clear-result.sh make-config.sh make-index.sh make-html-reports.sh atrt_SOURCES = main.cpp -INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include -I$(top_srcdir)/ndb/src/mgmclient -LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/CpcClient.o \ - $(top_builddir)/ndb/test/src/libNDBT.a \ +INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include +LDADD_LOC = $(top_builddir)/ndb/test/src/libNDBT.a \ $(top_builddir)/ndb/src/libndbclient.la \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/mysys/libmysys.a \ diff --git a/ndb/src/mgmclient/CpcClient.cpp b/ndb/test/src/CpcClient.cpp similarity index 100% rename from ndb/src/mgmclient/CpcClient.cpp rename to ndb/test/src/CpcClient.cpp diff --git a/ndb/test/src/Makefile.am b/ndb/test/src/Makefile.am index a8f34a0ea22..56f3d6a1ec6 100644 --- a/ndb/test/src/Makefile.am +++ b/ndb/test/src/Makefile.am @@ -9,7 +9,8 @@ libNDBT_a_SOURCES = \ HugoAsynchTransactions.cpp UtilTransactions.cpp \ NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \ NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \ - NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c + NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c \ + CpcClient.cpp INCLUDES_LOC = -I$(top_srcdir)/ndb/src/common/mgmcommon -I$(top_srcdir)/ndb/include/mgmcommon -I$(top_srcdir)/ndb/include/kernel -I$(top_srcdir)/ndb/src/mgmapi diff --git a/ndb/test/tools/Makefile.am b/ndb/test/tools/Makefile.am index 8d94c21b721..3255267b636 100644 --- a/ndb/test/tools/Makefile.am +++ b/ndb/test/tools/Makefile.am @@ -20,12 +20,10 @@ copy_tab_SOURCES = copy_tab.cpp create_index_SOURCES = create_index.cpp ndb_cpcc_SOURCES = cpcc.cpp -INCLUDES_LOC = -I$(top_srcdir)/ndb/src/mgmclient - include $(top_srcdir)/ndb/config/common.mk.am include $(top_srcdir)/ndb/config/type_ndbapitest.mk.am -ndb_cpcc_LDADD = $(LDADD) $(top_builddir)/ndb/src/mgmclient/CpcClient.o +ndb_cpcc_LDADD = $(LDADD) # Don't update the files from bitkeeper %::SCCS/s.% From ed807c29c9a64d139066d85db4de4f20f1831cee Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Mon, 8 Nov 2004 14:23:14 +0400 Subject: [PATCH 23/94] alter_table.result, alter_table.test, field_conv.cc: Bug #6479 ALTER TABLE ... changing charset fails for TEXT columns Fix: use do_conv_blob rather than do_copy_blob if the column's character sets are different. --- mysql-test/r/alter_table.result | 10 ++++++++++ mysql-test/t/alter_table.test | 12 ++++++++++++ sql/field_conv.cc | 2 ++ 3 files changed, 24 insertions(+) diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 89b8bd66848..9e14ca85a29 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -483,3 +483,13 @@ ERROR 42000: Incorrect table name 't1\\' rename table t1 to `t1\\`; ERROR 42000: Incorrect table name 't1\\' drop table t1; +create table t1 (a text) character set koi8r; +insert into t1 values (_koi8r'ÔÅÓÔ'); +select hex(a) from t1; +hex(a) +D4C5D3D4 +alter table t1 convert to character set cp1251; +select hex(a) from t1; +hex(a) +F2E5F1F2 +drop table t1; diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index e46027ae8d9..66a4adc90fe 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -324,3 +324,15 @@ alter table t1 rename to `t1\\`; rename table t1 to `t1\\`; drop table t1; +# +# Bug #6479 ALTER TABLE ... changing charset fails for TEXT columns +# +# The column's character set was changed but the actual data was not +# modified. In other words, the values were reinterpreted +# as UTF8 instead of being converted. +create table t1 (a text) character set koi8r; +insert into t1 values (_koi8r'ÔÅÓÔ'); +select hex(a) from t1; +alter table t1 convert to character set cp1251; +select hex(a) from t1; +drop table t1; diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 890687fc925..8a36fcd153c 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -475,6 +475,8 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) { if (!(from->flags & BLOB_FLAG)) return do_conv_blob; + if (from->charset() != to->charset()) + return do_conv_blob; if (from_length != to_length || to->table->db_low_byte_first != from->table->db_low_byte_first) { From f5b373d67854efd094444a99df24a5500001cc5f Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Mon, 8 Nov 2004 10:35:23 +0000 Subject: [PATCH 24/94] Makefile.am: changed make order .del-Makefile_old~dde91b00b37d2a06: Delete: ndb/tools/Makefile_old .del-Makefile_old~70d769657921a760: Delete: ndb/test/tools/Makefile_old .del-Makefile_old~58f0559822147dd9: Delete: ndb/test/tools/old_dirs/waiter/Makefile_old .del-Makefile_old~4fdb3c92ebd2eb29: Delete: ndb/test/run-test/Makefile_old .del-Makefile_old~1497f81a0c2125e: Delete: ndb/test/src/Makefile_old .del-Makefile_old~fbd3934fabdfe550: Delete: ndb/test/ndbapi/Makefile_old .del-Makefile_old~ec8e48326d4aa09: Delete: ndb/test/ndbapi/old_dirs/flexBench/Makefile_old .del-Makefile_old~1046c9ce93ef1fb8: Delete: ndb/test/ndbapi/bank/Makefile_old .del-Makefile_old~7c98d8f1d275983f: Delete: ndb/src/ndbapi/Makefile_old .del-Makefile_old~4463cf06fc2fceb9: Delete: ndb/src/mgmapi/Makefile_old .del-Makefile_old~274925c960801993: Delete: ndb/src/mgmsrv/Makefile_old .del-Makefile_old~b3d33fdde8bc12c0: Delete: ndb/src/kernel/Makefile_old .del-Makefile_old~6dbe2defc7237d4d: Delete: ndb/src/kernel/vm/Makefile_old .del-Makefile_old~cf05571c99011360: Delete: ndb/src/kernel/error/Makefile_old .del-Makefile_old~29a955a7e17d650e: Delete: ndb/src/kernel/blocks/Makefile_old .del-Makefile_old~f8b2a47eb434d43: Delete: ndb/src/kernel/blocks/suma/Makefile_old .del-Makefile_old~f0c05bb23d5c23ca: Delete: ndb/src/kernel/blocks/grep/Makefile_old .del-Makefile_old~a6fd2e579249f6e0: Delete: ndb/src/kernel/blocks/ndbcntr/Makefile_old .del-Makefile_old~7e8d8b4e2b1fa8f7: Delete: ndb/src/kernel/blocks/ndbfs/Makefile_old .del-Makefile_old~73c174fc712803c5: Delete: ndb/src/kernel/blocks/qmgr/Makefile_old .del-Makefile_old~16de31311951fc04: Delete: ndb/src/kernel/blocks/trix/Makefile_old .del-Makefile_old~788c80e5e758ac7: Delete: ndb/src/kernel/blocks/dbutil/Makefile_old .del-Makefile_old~5ebf2b4f85ab09cf: Delete: ndb/src/kernel/blocks/dbtux/Makefile_old .del-Makefile_old~530f9e0bc038a62: Delete: ndb/src/kernel/blocks/dbtup/Makefile_old .del-Makefile_old~315b927180484020: Delete: ndb/src/kernel/blocks/dbtc/Makefile_old .del-Makefile_old~d013a228cad86ba0: Delete: ndb/src/kernel/blocks/dbacc/Makefile_old .del-Makefile_old~c2e33f043b8aa45e: Delete: ndb/src/kernel/blocks/cmvmi/Makefile_old .del-Makefile_old~bdf406f5fb4696cb: Delete: ndb/src/kernel/blocks/dblqh/Makefile_old .del-Makefile_old~38a24016d2ad8aa7: Delete: ndb/src/kernel/blocks/dbdict/Makefile_old .del-Makefile_old~2804044250a6fd91: Delete: ndb/src/kernel/blocks/dbdih/Makefile_old .del-Makefile_old~e58eec87cd8dc79e: Delete: ndb/src/cw/Makefile_old .del-Makefile_old~b50c85b8eb69aacb: Delete: ndb/src/kernel/blocks/backup/Makefile_old .del-Makefile_old~16e186623106985e: Delete: ndb/src/cw/cpcd/Makefile_old .del-Makefile_old~f03f74238d640d5: Delete: ndb/src/common/mgmcommon/Makefile_old .del-Makefile_old~a8e9765b520b7c68: Delete: ndb/src/common/util/Makefile_old .del-Makefile_old~9f275aed83c8652b: Delete: ndb/src/common/transporter/Makefile_old .del-Makefile_old~8d901a664eca1ec: Delete: ndb/src/common/portlib/Makefile_old .del-Makefile_old~19643559613c75c7: Delete: ndb/src/common/portlib/old_dirs/unix/Makefile_old .del-Makefile_old~a3f6fc0e1411bb28: Delete: ndb/src/common/logger/Makefile_old .del-Makefile_old~754f27fab7d4da3b: Delete: ndb/src/common/debugger/signaldata/Makefile_old .del-Makefile_old~54ca8df95719e59f: Delete: ndb/src/common/debugger/Makefile_old --- ndb/src/common/debugger/Makefile_old | 11 ---- .../common/debugger/signaldata/Makefile_old | 33 ---------- ndb/src/common/logger/Makefile_old | 27 --------- ndb/src/common/mgmcommon/Makefile_old | 29 --------- ndb/src/common/portlib/Makefile_old | 21 ------- .../common/portlib/old_dirs/unix/Makefile_old | 27 --------- ndb/src/common/transporter/Makefile_old | 43 ------------- ndb/src/common/util/Makefile_old | 28 --------- ndb/src/cw/Makefile_old | 6 -- ndb/src/cw/cpcd/Makefile_old | 11 ---- ndb/src/kernel/Makefile_old | 5 -- ndb/src/kernel/blocks/Makefile_old | 28 --------- ndb/src/kernel/blocks/backup/Makefile_old | 18 ------ ndb/src/kernel/blocks/cmvmi/Makefile_old | 9 --- ndb/src/kernel/blocks/dbacc/Makefile_old | 11 ---- ndb/src/kernel/blocks/dbdict/Makefile_old | 12 ---- ndb/src/kernel/blocks/dbdih/Makefile_old | 13 ---- ndb/src/kernel/blocks/dblqh/Makefile_old | 12 ---- ndb/src/kernel/blocks/dbtc/Makefile_old | 11 ---- ndb/src/kernel/blocks/dbtup/Makefile_old | 26 -------- ndb/src/kernel/blocks/dbtux/Makefile_old | 17 ------ ndb/src/kernel/blocks/dbutil/Makefile_old | 8 --- ndb/src/kernel/blocks/grep/Makefile_old | 9 --- ndb/src/kernel/blocks/ndbcntr/Makefile_old | 12 ---- ndb/src/kernel/blocks/ndbfs/Makefile_old | 14 ----- ndb/src/kernel/blocks/qmgr/Makefile_old | 11 ---- ndb/src/kernel/blocks/suma/Makefile_old | 10 ---- ndb/src/kernel/blocks/trix/Makefile_old | 8 --- ndb/src/kernel/error/Makefile_old | 12 ---- ndb/src/kernel/vm/Makefile_old | 30 ---------- ndb/src/mgmapi/Makefile_old | 27 --------- ndb/src/mgmclient/Makefile.am | 2 +- ndb/src/mgmsrv/Makefile_old | 41 ------------- ndb/src/ndbapi/Makefile_old | 60 ------------------- ndb/test/ndbapi/Makefile_old | 49 --------------- ndb/test/ndbapi/bank/Makefile_old | 12 ---- .../ndbapi/old_dirs/flexBench/Makefile_old | 11 ---- ndb/test/run-test/Makefile_old | 22 ------- ndb/test/src/Makefile_old | 33 ---------- ndb/test/tools/Makefile_old | 9 --- ndb/test/tools/old_dirs/waiter/Makefile_old | 11 ---- ndb/tools/Makefile_old | 12 ---- 42 files changed, 1 insertion(+), 800 deletions(-) delete mode 100644 ndb/src/common/debugger/Makefile_old delete mode 100644 ndb/src/common/debugger/signaldata/Makefile_old delete mode 100644 ndb/src/common/logger/Makefile_old delete mode 100644 ndb/src/common/mgmcommon/Makefile_old delete mode 100644 ndb/src/common/portlib/Makefile_old delete mode 100644 ndb/src/common/portlib/old_dirs/unix/Makefile_old delete mode 100644 ndb/src/common/transporter/Makefile_old delete mode 100644 ndb/src/common/util/Makefile_old delete mode 100644 ndb/src/cw/Makefile_old delete mode 100644 ndb/src/cw/cpcd/Makefile_old delete mode 100644 ndb/src/kernel/Makefile_old delete mode 100644 ndb/src/kernel/blocks/Makefile_old delete mode 100644 ndb/src/kernel/blocks/backup/Makefile_old delete mode 100644 ndb/src/kernel/blocks/cmvmi/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbacc/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbdict/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbdih/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dblqh/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbtc/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbtup/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbtux/Makefile_old delete mode 100644 ndb/src/kernel/blocks/dbutil/Makefile_old delete mode 100644 ndb/src/kernel/blocks/grep/Makefile_old delete mode 100644 ndb/src/kernel/blocks/ndbcntr/Makefile_old delete mode 100644 ndb/src/kernel/blocks/ndbfs/Makefile_old delete mode 100644 ndb/src/kernel/blocks/qmgr/Makefile_old delete mode 100644 ndb/src/kernel/blocks/suma/Makefile_old delete mode 100644 ndb/src/kernel/blocks/trix/Makefile_old delete mode 100644 ndb/src/kernel/error/Makefile_old delete mode 100644 ndb/src/kernel/vm/Makefile_old delete mode 100644 ndb/src/mgmapi/Makefile_old delete mode 100644 ndb/src/mgmsrv/Makefile_old delete mode 100644 ndb/src/ndbapi/Makefile_old delete mode 100644 ndb/test/ndbapi/Makefile_old delete mode 100644 ndb/test/ndbapi/bank/Makefile_old delete mode 100644 ndb/test/ndbapi/old_dirs/flexBench/Makefile_old delete mode 100644 ndb/test/run-test/Makefile_old delete mode 100644 ndb/test/src/Makefile_old delete mode 100644 ndb/test/tools/Makefile_old delete mode 100644 ndb/test/tools/old_dirs/waiter/Makefile_old delete mode 100644 ndb/tools/Makefile_old diff --git a/ndb/src/common/debugger/Makefile_old b/ndb/src/common/debugger/Makefile_old deleted file mode 100644 index ac3a4475a54..00000000000 --- a/ndb/src/common/debugger/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := kernel -DIRS := signaldata - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := trace - -SOURCES = SignalLoggerManager.cpp DebuggerNames.cpp BlockNames.cpp LogLevel.cpp EventLogger.cpp GrepError.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/common/debugger/signaldata/Makefile_old b/ndb/src/common/debugger/signaldata/Makefile_old deleted file mode 100644 index bd00667b482..00000000000 --- a/ndb/src/common/debugger/signaldata/Makefile_old +++ /dev/null @@ -1,33 +0,0 @@ -include .defs.mk - -TYPE := ndbapi - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := signaldataprint - -SOURCES = TcKeyReq.cpp TcKeyConf.cpp TcKeyRef.cpp \ - TcRollbackRep.cpp \ - TupKey.cpp TupCommit.cpp LqhKey.cpp \ - FsOpenReq.cpp FsCloseReq.cpp FsRef.cpp FsConf.cpp FsReadWriteReq.cpp\ - SignalDataPrint.cpp SignalNames.cpp \ - ContinueB.cpp DihContinueB.cpp NdbfsContinueB.cpp \ - CloseComReqConf.cpp PackedSignal.cpp PrepFailReqRef.cpp \ - GCPSave.cpp DictTabInfo.cpp \ - AlterTable.cpp AlterTab.cpp \ - CreateTrig.cpp AlterTrig.cpp DropTrig.cpp \ - FireTrigOrd.cpp TrigAttrInfo.cpp \ - CreateIndx.cpp AlterIndx.cpp DropIndx.cpp TcIndx.cpp \ - IndxKeyInfo.cpp IndxAttrInfo.cpp \ - FsAppendReq.cpp ScanTab.cpp \ - BackupImpl.cpp BackupSignalData.cpp \ - UtilSequence.cpp UtilPrepare.cpp UtilDelete.cpp UtilExecute.cpp \ - LqhFrag.cpp DropTab.cpp PrepDropTab.cpp LCP.cpp MasterLCP.cpp \ - CopyGCI.cpp SystemError.cpp StartRec.cpp NFCompleteRep.cpp \ - FailRep.cpp DisconnectRep.cpp SignalDroppedRep.cpp \ - SumaImpl.cpp NdbSttor.cpp CreateFragmentation.cpp \ - CntrStart.cpp ReadNodesConf.cpp \ - UtilLock.cpp TuxMaint.cpp TupAccess.cpp AccLock.cpp \ - LqhTrans.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/common/logger/Makefile_old b/ndb/src/common/logger/Makefile_old deleted file mode 100644 index 994eb86ba35..00000000000 --- a/ndb/src/common/logger/Makefile_old +++ /dev/null @@ -1,27 +0,0 @@ -include .defs.mk - -TYPE := ndbapi - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := logger - -DIRS := loggertest - -SOURCES := Logger.cpp LogHandlerList.cpp LogHandler.cpp \ - ConsoleLogHandler.cpp FileLogHandler.cpp - -ifeq ($(NDB_OS), OSE) -NO_SYSLOG := Y -endif - -ifeq ($(NDB_OS), WIN32) -NO_SYSLOG := Y -endif - -ifneq ($(NO_SYSLOG), Y) -SOURCES += SysLogHandler.cpp -endif - -include $(NDB_TOP)/Epilogue.mk - - diff --git a/ndb/src/common/mgmcommon/Makefile_old b/ndb/src/common/mgmcommon/Makefile_old deleted file mode 100644 index c7bfda7e3bf..00000000000 --- a/ndb/src/common/mgmcommon/Makefile_old +++ /dev/null @@ -1,29 +0,0 @@ -include .defs.mk - -TYPE := ndbapi mgmapiclient - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := mgmsrvcommon - -# Removed temporary -DIRS := printConfig - -SOURCES = \ - LocalConfig.cpp \ - Config.cpp \ - ConfigInfo.cpp \ - ConfigRetriever.cpp \ - InitConfigFileParser.cpp \ - IPCConfig.cpp - -SOURCES.c = NdbConfig.c - -CFLAGS_IPCConfig.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmapi) - -include $(NDB_TOP)/Epilogue.mk - - - - - - diff --git a/ndb/src/common/portlib/Makefile_old b/ndb/src/common/portlib/Makefile_old deleted file mode 100644 index 48f4929a839..00000000000 --- a/ndb/src/common/portlib/Makefile_old +++ /dev/null @@ -1,21 +0,0 @@ -include .defs.mk - -DIRS := - -ifeq ($(NDB_OS), SOFTOSE) -DIRS += ose -else -ifeq ($(NDB_OS), OSE) -DIRS += ose -else -ifeq ($(NDB_OS), WIN32) -DIRS += win32 -else -DIRS += unix -endif -endif -endif - - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/common/portlib/old_dirs/unix/Makefile_old b/ndb/src/common/portlib/old_dirs/unix/Makefile_old deleted file mode 100644 index 452196d9f08..00000000000 --- a/ndb/src/common/portlib/old_dirs/unix/Makefile_old +++ /dev/null @@ -1,27 +0,0 @@ -include .defs.mk - -TYPE := util - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := portlib - -SOURCES.c = NdbCondition.c \ - NdbMutex.c \ - NdbSleep.c \ - NdbTick.c \ - NdbEnv.c \ - NdbThread.c \ - NdbHost.c \ - NdbTCP.c \ - NdbDaemon.c - -ifeq ($(NDB_OS), SOFTOSE) - SOURCES += NdbMem_SoftOse.cpp -else - SOURCES.c += NdbMem.c -endif - -include $(NDB_TOP)/Epilogue.mk - -testNdbDaemon: NdbDaemon.c - $(CC) -o $@ NdbDaemon.c $(CCFLAGS) -DNDB_DAEMON_TEST -L$(NDB_TOP)/lib diff --git a/ndb/src/common/transporter/Makefile_old b/ndb/src/common/transporter/Makefile_old deleted file mode 100644 index 372bf640566..00000000000 --- a/ndb/src/common/transporter/Makefile_old +++ /dev/null @@ -1,43 +0,0 @@ -include .defs.mk - -TYPE := util - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := transporter -DIRS := basictest perftest - -# Source files of non-templated classes (.cpp files) -SOURCES = \ - Transporter.cpp \ - SendBuffer.cpp \ - TCP_Transporter.cpp \ - TransporterRegistry.cpp \ - Packer.cpp - -DIRS := basictest perftest - -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/include/kernel) \ - -I$(call fixpath,$(NDB_TOP)/include/transporter) - - -ifeq ($(NDB_SHM), Y) -SOURCES += SHM_Transporter.cpp -ifeq ($(NDB_OS), WIN32) -SOURCES += SHM_Transporter.win32.cpp -else -SOURCES += SHM_Transporter.unix.cpp -endif -endif - -ifeq ($(NDB_SCI), Y) -SOURCES += SCI_Transporter.cpp -endif - -ifneq ($(findstring OSE, $(NDB_OS)),) - SOURCES += OSE_Transporter.cpp - SOURCES += OSE_Receiver.cpp -endif - - - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/common/util/Makefile_old b/ndb/src/common/util/Makefile_old deleted file mode 100644 index 65093396246..00000000000 --- a/ndb/src/common/util/Makefile_old +++ /dev/null @@ -1,28 +0,0 @@ -include .defs.mk - -TYPE := util - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := general - -SOURCES = File.cpp md5_hash.cpp Properties.cpp socket_io.cpp \ - SimpleProperties.cpp Parser.cpp InputStream.cpp SocketServer.cpp \ - OutputStream.cpp NdbOut.cpp BaseString.cpp Base64.cpp \ - NdbSqlUtil.cpp ConfigValues.cpp new.cpp - -SOURCES.c = uucode.c random.c getarg.c version.c - -ifeq ($(NDB_OS), OSE) - SOURCES += NdbErrHnd.cpp -endif -ifeq ($(NDB_OS), OSE) - SOURCES += NdbErrHnd.cpp -endif - SOURCES.c += strdup.c strlcat.c strlcpy.c - -DIRS := testSimpleProperties testProperties testConfigValues - -include $(NDB_TOP)/Epilogue.mk - -testNdbSqlUtil: NdbSqlUtil.cpp - $(CC) -o $@ NdbSqlUtil.cpp $(CCFLAGS) -DNDB_SQL_UTIL_TEST -L$(NDB_TOP)/lib -lportlib -lgeneral diff --git a/ndb/src/cw/Makefile_old b/ndb/src/cw/Makefile_old deleted file mode 100644 index e710c1e244d..00000000000 --- a/ndb/src/cw/Makefile_old +++ /dev/null @@ -1,6 +0,0 @@ -include .defs.mk - -DIRS := cpcd - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/cw/cpcd/Makefile_old b/ndb/src/cw/cpcd/Makefile_old deleted file mode 100644 index f214fb087d2..00000000000 --- a/ndb/src/cw/cpcd/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := util -BIN_TARGET := ndb_cpcd - -# Source files of non-templated classes (.cpp files) -SOURCES = main.cpp CPCD.cpp Process.cpp APIService.cpp Monitor.cpp common.cpp - -BIN_TARGET_LIBS += logger - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/Makefile_old b/ndb/src/kernel/Makefile_old deleted file mode 100644 index d1f1741aca4..00000000000 --- a/ndb/src/kernel/Makefile_old +++ /dev/null @@ -1,5 +0,0 @@ -include .defs.mk - -DIRS := error vm ndb-main blocks - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/Makefile_old b/ndb/src/kernel/blocks/Makefile_old deleted file mode 100644 index ce554dfc3b8..00000000000 --- a/ndb/src/kernel/blocks/Makefile_old +++ /dev/null @@ -1,28 +0,0 @@ -#-------------------------------------------------------------------------- -# -# Name Makefile -# -# -# -# List subdirectories to be travered -include .defs.mk - -DIRS := \ - cmvmi \ - dbacc \ - dbdict \ - dbdih \ - dblqh \ - dbtc \ - dbtup \ - ndbfs \ - ndbcntr \ - qmgr \ - trix \ - backup \ - dbutil \ - suma \ - grep \ - dbtux - -include ${NDB_TOP}/Epilogue.mk diff --git a/ndb/src/kernel/blocks/backup/Makefile_old b/ndb/src/kernel/blocks/backup/Makefile_old deleted file mode 100644 index 989199cbe02..00000000000 --- a/ndb/src/kernel/blocks/backup/Makefile_old +++ /dev/null @@ -1,18 +0,0 @@ -include .defs.mk - -TYPE := kernel - -#ifneq ($(MYSQLCLUSTER_TOP),) -DIRS := restore -#endif - -ARCHIVE_TARGET := backup - -SOURCES = Backup.cpp BackupInit.cpp - -include $(NDB_TOP)/Epilogue.mk - -$(NDB_TOP)/bin/readBackupFile: read.o - $(C++) -o $@ read.o \ - $(NDB_TOP)/lib/libportlib.a $(NDB_TOP)/lib/libgeneral.a - diff --git a/ndb/src/kernel/blocks/cmvmi/Makefile_old b/ndb/src/kernel/blocks/cmvmi/Makefile_old deleted file mode 100644 index d75e5dbf08b..00000000000 --- a/ndb/src/kernel/blocks/cmvmi/Makefile_old +++ /dev/null @@ -1,9 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := cmvmi - -SOURCES = Cmvmi.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbacc/Makefile_old b/ndb/src/kernel/blocks/dbacc/Makefile_old deleted file mode 100644 index 93a830cec95..00000000000 --- a/ndb/src/kernel/blocks/dbacc/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbacc - -SOURCES = \ - DbaccInit.cpp \ - DbaccMain.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbdict/Makefile_old b/ndb/src/kernel/blocks/dbdict/Makefile_old deleted file mode 100644 index 46d938114fb..00000000000 --- a/ndb/src/kernel/blocks/dbdict/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbdict - -SOURCES = \ - Dbdict.cpp - -DIRS := printSchemafile - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbdih/Makefile_old b/ndb/src/kernel/blocks/dbdih/Makefile_old deleted file mode 100644 index 83c1b95b5c4..00000000000 --- a/ndb/src/kernel/blocks/dbdih/Makefile_old +++ /dev/null @@ -1,13 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbdih - -DIRS := printSysfile - -SOURCES = \ - DbdihInit.cpp \ - DbdihMain.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dblqh/Makefile_old b/ndb/src/kernel/blocks/dblqh/Makefile_old deleted file mode 100644 index 520486d8058..00000000000 --- a/ndb/src/kernel/blocks/dblqh/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dblqh -DIRS := redoLogReader - -SOURCES = \ - DblqhInit.cpp \ - DblqhMain.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbtc/Makefile_old b/ndb/src/kernel/blocks/dbtc/Makefile_old deleted file mode 100644 index ae876ab1f84..00000000000 --- a/ndb/src/kernel/blocks/dbtc/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbtc -SOURCES = \ - DbtcInit.cpp \ - DbtcMain.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/kernel/blocks/dbtup/Makefile_old b/ndb/src/kernel/blocks/dbtup/Makefile_old deleted file mode 100644 index 87146f4b441..00000000000 --- a/ndb/src/kernel/blocks/dbtup/Makefile_old +++ /dev/null @@ -1,26 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbtup -SOURCES = \ - DbtupExecQuery.cpp \ - DbtupBuffer.cpp \ - DbtupRoutines.cpp \ - DbtupCommit.cpp \ - DbtupFixAlloc.cpp \ - DbtupTrigger.cpp \ - DbtupAbort.cpp \ - DbtupLCP.cpp \ - DbtupUndoLog.cpp \ - DbtupPageMap.cpp \ - DbtupPagMan.cpp \ - DbtupStoredProcDef.cpp \ - DbtupMeta.cpp \ - DbtupTabDesMan.cpp \ - DbtupGen.cpp \ - DbtupSystemRestart.cpp \ - DbtupIndex.cpp \ - DbtupDebug.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbtux/Makefile_old b/ndb/src/kernel/blocks/dbtux/Makefile_old deleted file mode 100644 index 30927c31848..00000000000 --- a/ndb/src/kernel/blocks/dbtux/Makefile_old +++ /dev/null @@ -1,17 +0,0 @@ -include .defs.mk - -TYPE = kernel - -ARCHIVE_TARGET = dbtux - -SOURCES = \ - DbtuxGen.cpp \ - DbtuxMeta.cpp \ - DbtuxMaint.cpp \ - DbtuxNode.cpp \ - DbtuxTree.cpp \ - DbtuxScan.cpp \ - DbtuxCmp.cpp \ - DbtuxDebug.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/dbutil/Makefile_old b/ndb/src/kernel/blocks/dbutil/Makefile_old deleted file mode 100644 index 54b7326e4e5..00000000000 --- a/ndb/src/kernel/blocks/dbutil/Makefile_old +++ /dev/null @@ -1,8 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := dbutil -SOURCES = DbUtil.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/grep/Makefile_old b/ndb/src/kernel/blocks/grep/Makefile_old deleted file mode 100644 index 5ad5a0bce3b..00000000000 --- a/ndb/src/kernel/blocks/grep/Makefile_old +++ /dev/null @@ -1,9 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := grep - -SOURCES = Grep.cpp GrepInit.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/ndbcntr/Makefile_old b/ndb/src/kernel/blocks/ndbcntr/Makefile_old deleted file mode 100644 index 8e9c4f01027..00000000000 --- a/ndb/src/kernel/blocks/ndbcntr/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := ndbcntr - -SOURCES = \ - NdbcntrInit.cpp \ - NdbcntrSysTable.cpp \ - NdbcntrMain.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/ndbfs/Makefile_old b/ndb/src/kernel/blocks/ndbfs/Makefile_old deleted file mode 100644 index 58e1458bf16..00000000000 --- a/ndb/src/kernel/blocks/ndbfs/Makefile_old +++ /dev/null @@ -1,14 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := ndbfs - -SOURCES = \ - AsyncFile.cpp \ - Ndbfs.cpp VoidFs.cpp \ - Filename.cpp \ - CircularIndex.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/kernel/blocks/qmgr/Makefile_old b/ndb/src/kernel/blocks/qmgr/Makefile_old deleted file mode 100644 index cd15643ea60..00000000000 --- a/ndb/src/kernel/blocks/qmgr/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := qmgr - -SOURCES = \ - QmgrInit.cpp \ - QmgrMain.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/blocks/suma/Makefile_old b/ndb/src/kernel/blocks/suma/Makefile_old deleted file mode 100644 index 20014c94670..00000000000 --- a/ndb/src/kernel/blocks/suma/Makefile_old +++ /dev/null @@ -1,10 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := suma - -SOURCES = Suma.cpp SumaInit.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/src/kernel/blocks/trix/Makefile_old b/ndb/src/kernel/blocks/trix/Makefile_old deleted file mode 100644 index 5ac0da11f33..00000000000 --- a/ndb/src/kernel/blocks/trix/Makefile_old +++ /dev/null @@ -1,8 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := trix -SOURCES = Trix.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/error/Makefile_old b/ndb/src/kernel/error/Makefile_old deleted file mode 100644 index 0fe81f083ce..00000000000 --- a/ndb/src/kernel/error/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := error - -SOURCES = \ - TimeModule.cpp \ - ErrorReporter.cpp \ - ErrorMessages.cpp - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/kernel/vm/Makefile_old b/ndb/src/kernel/vm/Makefile_old deleted file mode 100644 index a162f3672ce..00000000000 --- a/ndb/src/kernel/vm/Makefile_old +++ /dev/null @@ -1,30 +0,0 @@ -include .defs.mk - -TYPE := kernel - -ARCHIVE_TARGET := kernel - -SOURCES = \ - SimulatedBlock.cpp \ - FastScheduler.cpp \ - TimeQueue.cpp \ - VMSignal.cpp \ - ThreadConfig.cpp \ - TransporterCallback.cpp \ - Emulator.cpp \ - Configuration.cpp \ - WatchDog.cpp \ - SimplePropertiesSection.cpp \ - SectionReader.cpp \ - MetaData.cpp \ - Mutex.cpp SafeCounter.cpp - -CFLAGS_Configuration.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmapi) - -DIRS := testCopy testDataBuffer testSimplePropertiesSection - -ifneq ($(USE_EDITLINE), N) -DIRS += testLongSig -endif - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/mgmapi/Makefile_old b/ndb/src/mgmapi/Makefile_old deleted file mode 100644 index fa734f998e6..00000000000 --- a/ndb/src/mgmapi/Makefile_old +++ /dev/null @@ -1,27 +0,0 @@ -include .defs.mk - -TYPE := util - -PIC_ARCHIVE := Y -ARCHIVE_TARGET := mgmapi - -A_LIB := Y -SO_LIB := Y -PIC_LIB := Y - -#DIRS := test - -LIB_TARGET := MGM_API -LIB_TARGET_ARCHIVES := $(ARCHIVE_TARGET) general portlib - -# Source files of non-templated classes (.C files) -SOURCES = mgmapi.cpp mgmapi_configuration.cpp - -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/include/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/src/common/mgmcommon) - -CCFLAGS += -DNO_DEBUG_MESSAGES - -# -I$(NDB_TOP)/src/common/mgmcommon - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/src/mgmclient/Makefile.am b/ndb/src/mgmclient/Makefile.am index e3f0b23a79a..41a7f00ba15 100644 --- a/ndb/src/mgmclient/Makefile.am +++ b/ndb/src/mgmclient/Makefile.am @@ -1,6 +1,6 @@ -ndbtools_PROGRAMS = ndb_mgm noinst_LTLIBRARIES = libndbmgmclient.la +ndbtools_PROGRAMS = ndb_mgm libndbmgmclient_la_SOURCES = CommandInterpreter.cpp diff --git a/ndb/src/mgmsrv/Makefile_old b/ndb/src/mgmsrv/Makefile_old deleted file mode 100644 index c99875ae8b6..00000000000 --- a/ndb/src/mgmsrv/Makefile_old +++ /dev/null @@ -1,41 +0,0 @@ -include .defs.mk - -TYPE := ndbapi mgmapiclient - -BIN_TARGET := mgmtsrvr -BIN_TARGET_LIBS := -BIN_TARGET_ARCHIVES := NDB_API mgmsrvcommon mgmapi general - -ifneq ($(USE_EDITLINE), N) -BIN_TARGET_ARCHIVES += editline -DIRS := mkconfig -endif -BIN_TARGET_ARCHIVES += general - -BIN_FLAGS += $(TERMCAP_LIB) - -# Source files of non-templated classes (.cpp files) -SOURCES = \ - MgmtSrvr.cpp \ - MgmtSrvrGeneralSignalHandling.cpp \ - main.cpp \ - Services.cpp \ - convertStrToInt.cpp \ - NodeLogLevel.cpp \ - NodeLogLevelList.cpp \ - SignalQueue.cpp \ - MgmtSrvrConfig.cpp - -ifeq ($(findstring OSE, $(NDB_OS)),) -SOURCES += CommandInterpreter.cpp -endif - -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/src/ndbapi) \ - -I$(call fixpath,$(NDB_TOP)/src/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/include/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/src/common/mgmcommon) - -include $(NDB_TOP)/Epilogue.mk - -_bins_mkconfig : $(NDB_TOP)/bin/$(BIN_TARGET) - diff --git a/ndb/src/ndbapi/Makefile_old b/ndb/src/ndbapi/Makefile_old deleted file mode 100644 index 54de9ba96f4..00000000000 --- a/ndb/src/ndbapi/Makefile_old +++ /dev/null @@ -1,60 +0,0 @@ -include .defs.mk - -TYPE := ndbapi - -PIC_ARCHIVE := Y -NONPIC_ARCHIVE := Y -ARCHIVE_TARGET := ndbapi - -A_LIB := Y -SO_LIB := Y -PIC_LIB := Y -LIB_TARGET := NDB_API - -LIB_TARGET_ARCHIVES := $(ARCHIVE_TARGET) \ - transporter \ - general \ - signaldataprint \ - mgmapi mgmsrvcommon \ - portlib \ - logger \ - trace - -DIRS := signal-sender - -CFLAGS_TransporterFacade.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmapi) -CFLAGS_ClusterMgr.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmapi) - -# Source files of non-templated classes (.cpp files) -SOURCES = \ - TransporterFacade.cpp \ - ClusterMgr.cpp \ - Ndb.cpp \ - NdbPoolImpl.cpp NdbPool.cpp \ - Ndblist.cpp \ - Ndbif.cpp \ - Ndbinit.cpp \ - ndberror.c Ndberr.cpp NdbErrorOut.cpp \ - NdbConnection.cpp \ - NdbConnectionScan.cpp \ - NdbOperation.cpp \ - NdbOperationSearch.cpp \ - NdbOperationInt.cpp \ - NdbOperationDefine.cpp \ - NdbOperationExec.cpp \ - NdbResultSet.cpp \ - NdbScanOperation.cpp NdbScanFilter.cpp \ - NdbIndexOperation.cpp \ - NdbEventOperation.cpp \ - NdbEventOperationImpl.cpp \ - NdbApiSignal.cpp \ - NdbRecAttr.cpp \ - NdbUtil.cpp \ - NdbReceiver.cpp \ - NdbDictionary.cpp NdbDictionaryImpl.cpp DictCache.cpp - NdbBlob.cpp - -include $(NDB_TOP)/Epilogue.mk - -### -# Backward compatible diff --git a/ndb/test/ndbapi/Makefile_old b/ndb/test/ndbapi/Makefile_old deleted file mode 100644 index c3198096ec0..00000000000 --- a/ndb/test/ndbapi/Makefile_old +++ /dev/null @@ -1,49 +0,0 @@ -include .defs.mk - - -ifeq ($(NDB_OS), OSE) -DIRS = basic flexBench flexAsynch -else -DIRS = lmc-bench ronja -BIN_DIRS = \ - flexAsynch \ - flexBench \ - flexHammer \ - flexTT \ - create_tab \ - create_all_tabs \ - drop_all_tabs \ - bulk_copy \ - restarter2 restarter \ - restarts testScan testNdbApi \ - testScanInterpreter testIndex \ - testInterpreter \ - testOIBasic \ - testBackup \ - testBasic \ - basicAsynch \ - testNodeRestart \ - testOperations testTransactions \ - testSystemRestart \ - testTimeout \ - testMgm \ - testRestartGci \ - testDataBuffers \ - testDict \ - acid \ - telco \ - indexTest \ - test_event \ - indexTest2 \ - testGrep \ - testBlobs - -ifeq ($(NDB_OS), SOLARIS) -ifeq ($(NDB_COMPILER), FORTE6) - DIRS += flexTimedAsynch -endif -endif -endif - -include ${NDB_TOP}/Epilogue.mk - diff --git a/ndb/test/ndbapi/bank/Makefile_old b/ndb/test/ndbapi/bank/Makefile_old deleted file mode 100644 index f710f9e6612..00000000000 --- a/ndb/test/ndbapi/bank/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -DIRS = src bankCreator \ - bankSumAccounts \ - bankTransactionMaker \ - bankValidateAllGLs \ - bankMakeGL \ - bankTimer \ - testBank - - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old b/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old deleted file mode 100644 index bfff5cd161a..00000000000 --- a/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -BIN_TARGET := flexBench - -# Source files of non-templated classes (.C files) -SOURCES = flexBench.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/test/run-test/Makefile_old b/ndb/test/run-test/Makefile_old deleted file mode 100644 index 6b4689b2dbb..00000000000 --- a/ndb/test/run-test/Makefile_old +++ /dev/null @@ -1,22 +0,0 @@ -include .defs.mk - -TYPE := util - -BIN_TARGET := atrt -BIN_TARGET_LIBS := mgmapi - -SOURCES = main.cpp -SCRIPTS = atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \ - atrt-clear-result.sh make-config.sh - -OBJECTS_LOC = $(call fixpath,$(NDB_TOP)/src/mgmclient/CpcClient.o) - -CFLAGS_main.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmclient) -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/include/mgmapi) - -include $(NDB_TOP)/Epilogue.mk - -_bins:: - -rm -f $(SCRIPTS:%=$(NDB_TOP)/bin/%) - cp $(SCRIPTS) $(NDB_TOP)/bin - diff --git a/ndb/test/src/Makefile_old b/ndb/test/src/Makefile_old deleted file mode 100644 index 2738ce1aba2..00000000000 --- a/ndb/test/src/Makefile_old +++ /dev/null @@ -1,33 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -ARCHIVE_TARGET := NDBT - -SOURCES = NDBT_ReturnCodes.cpp \ - NDBT_Error.cpp NDBT_Tables.cpp NDBT_ResultRow.cpp \ - NDBT_Test.cpp HugoCalculator.cpp \ - HugoOperations.cpp HugoTransactions.cpp \ - HugoAsynchTransactions.cpp UtilTransactions.cpp \ - NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \ - NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp - -SOURCES.c = - -CFLAGS_NdbRestarter.cpp := -I$(call fixpath,$(NDB_TOP)/src/common/mgmcommon) -CFLAGS_NdbConfig.cpp := -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) \ - -I$(call fixpath,$(NDB_TOP)/src/mgmapi) -CFLAGS_NdbRestarts.cpp := -I$(call fixpath,$(NDB_TOP)/include/kernel) -CFLAGS_NdbBackup.cpp := -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) \ - -I$(call fixpath,$(NDB_TOP)/src/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/include/kernel) -CFLAGS_NdbGrep.cpp += -I$(call fixpath,$(NDB_TOP)/include/kernel) -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) - -include $(NDB_TOP)/Epilogue.mk - - - - - - - diff --git a/ndb/test/tools/Makefile_old b/ndb/test/tools/Makefile_old deleted file mode 100644 index b8e90ae207f..00000000000 --- a/ndb/test/tools/Makefile_old +++ /dev/null @@ -1,9 +0,0 @@ -include .defs.mk - -DIRS := hugoCalculator hugoFill hugoLoad hugoLockRecords \ - hugoPkDelete hugoPkRead hugoPkReadRecord hugoPkUpdate \ - hugoScanRead hugoScanUpdate restart waiter - -include $(NDB_TOP)/Epilogue.mk - -_bins_ndbapi : _libs_src diff --git a/ndb/test/tools/old_dirs/waiter/Makefile_old b/ndb/test/tools/old_dirs/waiter/Makefile_old deleted file mode 100644 index da2c9daff00..00000000000 --- a/ndb/test/tools/old_dirs/waiter/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -BIN_TARGET := waiter - -# Source files of non-templated classes (.C files) -SOURCES = waiter.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/tools/Makefile_old b/ndb/tools/Makefile_old deleted file mode 100644 index b9dc6883e18..00000000000 --- a/ndb/tools/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -BIN_DIRS = select_all select_count desc list_tables \ - drop_tab delete_all copy_tab \ - create_index drop_index verify_index cpcc - -ifneq ($(NDB_ODBC),N) -BIN_DIRS += ndbsql -endif - -include $(NDB_TOP)/Epilogue.mk - From f3cd21dbb37931cf47f5ef02081d4ab824f894e8 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Mon, 8 Nov 2004 10:41:59 +0000 Subject: [PATCH 25/94] Makefile.am: remove mysql_test_run_new for now, it breaks the make --- mysql-test/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index ad02d304d1b..8ae0c256148 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -37,9 +37,10 @@ test_DATA = std_data/client-key.pem std_data/client-cert.pem std_data/cacert.pem CLEANFILES = $(test_SCRIPTS) $(test_DATA) INCLUDES = -I$(srcdir)/../include -I../include -I.. -bin_PROGRAMS = mysql_test_run_new +# remove mysql_test_run_new for now, it breaks the make +#bin_PROGRAMS = mysql_test_run_new noinst_HEADERS = my_manage.h -mysql_test_run_new_SOURCES= mysql_test_run_new.c my_manage.c +#mysql_test_run_new_SOURCES= mysql_test_run_new.c my_manage.c dist-hook: From 3f38389905140f8ffe15222760535ac398c3924a Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Mon, 8 Nov 2004 10:53:48 +0000 Subject: [PATCH 26/94] Makefile.am: added so that it is possible to make mysql_test_run_new but not done for target all do: make mysql_test_run_new --- mysql-test/Makefile.am | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index 8ae0c256148..fcf352f46e6 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -37,10 +37,9 @@ test_DATA = std_data/client-key.pem std_data/client-cert.pem std_data/cacert.pem CLEANFILES = $(test_SCRIPTS) $(test_DATA) INCLUDES = -I$(srcdir)/../include -I../include -I.. -# remove mysql_test_run_new for now, it breaks the make -#bin_PROGRAMS = mysql_test_run_new +EXTRA_PROGRAMS = mysql_test_run_new noinst_HEADERS = my_manage.h -#mysql_test_run_new_SOURCES= mysql_test_run_new.c my_manage.c +mysql_test_run_new_SOURCES= mysql_test_run_new.c my_manage.c dist-hook: From eea1b83b20901388c616bac9f9a7bd242229f04c Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Mon, 8 Nov 2004 11:28:57 +0000 Subject: [PATCH 27/94] Makefile.am: fix to make make -jN work --- ndb/src/mgmclient/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/src/mgmclient/Makefile.am b/ndb/src/mgmclient/Makefile.am index 41a7f00ba15..cd6ddb0ad57 100644 --- a/ndb/src/mgmclient/Makefile.am +++ b/ndb/src/mgmclient/Makefile.am @@ -11,7 +11,7 @@ include $(top_srcdir)/ndb/config/type_ndbapi.mk.am INCLUDES += -I$(top_srcdir)/ndb/include/mgmapi -I$(top_srcdir)/ndb/src/common/mgmcommon -LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/libndbmgmclient.la \ +LDADD_LOC = $(noinst_LTLIBRARIES) \ @readline_link@ \ $(top_builddir)/ndb/src/libndbclient.la \ $(top_builddir)/dbug/libdbug.a \ From ffaa063659b6a34dc4e3068cd10915887286c4ab Mon Sep 17 00:00:00 2001 From: "joreland@mysql.com" <> Date: Mon, 8 Nov 2004 13:59:04 +0100 Subject: [PATCH 28/94] compile fix for ndbapi test program on irix (variable scope) --- ndb/test/include/NDBT_Test.hpp | 4 +-- ndb/test/ndbapi/ScanFunctions.hpp | 20 +++++------ ndb/test/ndbapi/testDataBuffers.cpp | 50 +++++++++++++++------------ ndb/test/ndbapi/testDeadlock.cpp | 7 ++-- ndb/test/ndbapi/testDict.cpp | 5 +-- ndb/test/ndbapi/testIndex.cpp | 24 +++++++------ ndb/test/ndbapi/testLcp.cpp | 7 ++-- ndb/test/ndbapi/testNdbApi.cpp | 16 ++++----- ndb/test/ndbapi/testOIBasic.cpp | 19 +++++----- ndb/test/ndbapi/testReadPerf.cpp | 5 +-- ndb/test/ndbapi/testRestartGci.cpp | 5 +-- ndb/test/ndbapi/testScanPerf.cpp | 5 +-- ndb/test/ndbapi/testSystemRestart.cpp | 12 +++---- 13 files changed, 97 insertions(+), 82 deletions(-) diff --git a/ndb/test/include/NDBT_Test.hpp b/ndb/test/include/NDBT_Test.hpp index b0b5fe15960..8b69faebde8 100644 --- a/ndb/test/include/NDBT_Test.hpp +++ b/ndb/test/include/NDBT_Test.hpp @@ -392,10 +392,10 @@ C##suitname():NDBT_TestSuite(#suitname){ \ // Add a number of equal steps to the testcase #define STEPS(stepfunc, num) \ - for (int i = 0; i < num; i++){ \ + { int i; for (i = 0; i < num; i++){ \ pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \ pt->addStep(pts);\ - } + } } #define VERIFIER(stepfunc) \ ptv = new NDBT_Verifier(pt, #stepfunc, stepfunc); \ diff --git a/ndb/test/ndbapi/ScanFunctions.hpp b/ndb/test/ndbapi/ScanFunctions.hpp index 2ff4b751c33..6964f8c73a8 100644 --- a/ndb/test/ndbapi/ScanFunctions.hpp +++ b/ndb/test/ndbapi/ScanFunctions.hpp @@ -286,36 +286,36 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attr = new Attrib; attr->numAttribs = 0; attriblist.push_back(attr); - - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + int i; + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; aattribs[a] = a; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns()-1; i > 0; i--){ + for(i = pTab->getNoOfColumns()-1; i > 0; i--){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; aattribs[a] = a; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns(); i > 0; i--){ + for(i = pTab->getNoOfColumns(); i > 0; i--){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; agetNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; agetNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = 2; for(int a = 0; a<2; a++){ @@ -345,11 +345,11 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attriblist.push_back(attr); #if 1 - for(size_t i = 0; i < attriblist.size(); i++){ + for(size_t j = 0; j < attriblist.size(); j++){ - g_info << attriblist[i]->numAttribs << ": " ; - for(int a = 0; a < attriblist[i]->numAttribs; a++) - g_info << attriblist[i]->attribs[a] << ", "; + g_info << attriblist[j]->numAttribs << ": " ; + for(int a = 0; a < attriblist[j]->numAttribs; a++) + g_info << attriblist[j]->attribs[a] << ", "; g_info << endl; } #endif diff --git a/ndb/test/ndbapi/testDataBuffers.cpp b/ndb/test/ndbapi/testDataBuffers.cpp index 04602f51d5f..03d52252334 100644 --- a/ndb/test/ndbapi/testDataBuffers.cpp +++ b/ndb/test/ndbapi/testDataBuffers.cpp @@ -123,15 +123,15 @@ chkerror(char const* fmt, ...) // alignment of addresses and data sizes -static bool isAligned(unsigned x) +static bool isAligned(UintPtr x) { return ((x & 3) == 0); } static bool isAligned(char* p) { - return isAligned(unsigned(p)); + return isAligned(UintPtr(p)); } -static unsigned toAligned(unsigned x) +static unsigned toAligned(UintPtr x) { while (! isAligned(x)) x++; @@ -223,10 +223,10 @@ testcase(int flag) noRandom = ! (flag & 8); ndbout << (noRandom ? "simple sizes" : "randomize sizes") << endl; - int smax = 0, stot = 0; + int smax = 0, stot = 0, i; if (xverbose) ndbout << "- define table " << tab << endl; - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; memset(&c, 0, sizeof(c)); sprintf(c.aAttrName, "C%d", i); @@ -266,7 +266,7 @@ testcase(int flag) return ndberror("getNdbSchemaOp"); if (top->createTable(tab) < 0) return ndberror("createTable"); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (top->createAttribute( c.aAttrName, @@ -299,7 +299,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->deleteTuple() < 0) return ndberror("deleteTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -329,7 +329,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->insertTuple() < 0) return ndberror("insertTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -362,7 +362,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->readTuple() < 0) return ndberror("readTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -371,7 +371,7 @@ testcase(int flag) if (xverbose) { char tmp[20]; if (useBuf) - sprintf(tmp, "0x%x", int(c.buf + off)); + sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; @@ -388,23 +388,24 @@ testcase(int flag) } if (con->execute(Commit) != 0) return ndberror("execute key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { } else if (useBuf) { - for (int j = 0; j < off; j++) { + int j; + for (j = 0; j < off; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); } } - for (int j = 0; j < c.aArraySize; j++) { + for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } - for (int j = c.aArraySize + off; j < c.bufsiz; j++) { + for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); @@ -431,7 +432,8 @@ testcase(int flag) if (xverbose) ndbout << "- scan" << endl; char found[MaxOper]; - for (int k = 0; k < opercnt; k++) + int k; + for (k = 0; k < opercnt; k++) found[k] = 0; for (key = 0; key < opercnt; key++) { int off = makeOff(key); @@ -459,7 +461,7 @@ testcase(int flag) if (op->interpret_exit_ok() < 0) return ndberror("interpret_exit_ok"); } - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->getValue(c.aAttrName, (char*)&newkey) < 0) @@ -468,7 +470,7 @@ testcase(int flag) if (xverbose) { char tmp[20]; if (useBuf) - sprintf(tmp, "0x%x", int(c.buf + off)); + sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; @@ -489,22 +491,23 @@ testcase(int flag) while ((ret = rs->nextResult()) == 0) { if (key != newkey) return ndberror("unexpected key=%d newkey=%d", key, newkey); - for (int i = 1; i < attrcnt; i++) { + for (i = 1; i < attrcnt; i++) { col& c = ccol[i]; if (useBuf) { - for (int j = 0; j < off; j++) { + int j; + for (j = 0; j < off; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); } } - for (int j = 0; j < c.aArraySize; j++) { + for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } - for (int j = c.aArraySize + off; j < c.bufsiz; j++) { + for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); @@ -533,7 +536,7 @@ testcase(int flag) } con = 0; op = 0; - for (int k = 0; k < opercnt; k++) + for (k = 0; k < opercnt; k++) if (! found[k]) return ndberror("key %d not found", k); ndbout << "scanned " << key << endl; @@ -545,6 +548,7 @@ testcase(int flag) NDB_COMMAND(testDataBuffers, "testDataBuffers", "testDataBuffers", "testDataBuffers", 65535) { + int i; ndb_init(); while (++argv, --argc > 0) { char const* p = argv[0]; @@ -602,7 +606,7 @@ NDB_COMMAND(testDataBuffers, "testDataBuffers", "testDataBuffers", "testDataBuff } } unsigned ok = true; - for (int i = 1; 0 == loopcnt || i <= loopcnt; i++) { + for (i = 1; 0 == loopcnt || i <= loopcnt; i++) { ndbout << "=== loop " << i << " ===" << endl; for (int flag = 0; flag < (1< cols; Vector tabs; + int i; Ndb* pNdb = GETNDB(step); const Uint32 count = NDBT_Tables::getNumTables(); - for (int i=0; i < count; i++){ + for (i=0; i < count; i++){ const NdbDictionary::Table * tab = NDBT_Tables::getTable(i); pNdb->getDictionary()->createTable(* tab); @@ -1458,7 +1459,7 @@ runTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){ Uint32 size = cols.size() / 2; char ** columns = &cols[0]; Uint64 start = NdbTick_CurrentMillisecond(); - for(int i = 0; igetNoOfColumns(); i++){ + int i; + + for(i = 1; i <= pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; agetNoOfColumns()-1; i > 0; i--){ + for(i = pTab->getNoOfColumns()-1; i > 0; i--){ attr = new Attrib; attr->numAttribs = i; b++; @@ -74,21 +76,21 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attr->attribs[a] = a+b; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns(); i > 0; i--){ + for(i = pTab->getNoOfColumns(); i > 0; i--){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; agetNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; agetNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = 2; for(int a = 0; a<2; a++){ @@ -226,8 +228,8 @@ int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){ while (l < loops && result == NDBT_OK){ - - for (unsigned int i = 0; i < attrList.attriblist.size(); i++){ + unsigned int i; + for (i = 0; i < attrList.attriblist.size(); i++){ // Try to create index if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED) @@ -235,7 +237,7 @@ int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){ } // Now drop all indexes that where created - for (unsigned int i = 0; i < attrList.attriblist.size(); i++){ + for (i = 0; i < attrList.attriblist.size(); i++){ // Try to drop index if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK) @@ -1083,8 +1085,8 @@ runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){ else pIdx.setType(NdbDictionary::Index::UniqueHashIndex); pIdx.setStoredIndex(logged); - - for (int c = 0; c< pTab->getNoOfColumns(); c++){ + int c; + for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getPrimaryKey()){ pIdx.addIndexColumn(col->getName()); @@ -1093,7 +1095,7 @@ runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){ } int colId = -1; - for (int c = 0; c< pTab->getNoOfColumns(); c++){ + for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getNullable()){ pIdx.addIndexColumn(col->getName()); diff --git a/ndb/test/ndbapi/testLcp.cpp b/ndb/test/ndbapi/testLcp.cpp index c92be091a97..d11692db761 100644 --- a/ndb/test/ndbapi/testLcp.cpp +++ b/ndb/test/ndbapi/testLcp.cpp @@ -85,7 +85,8 @@ main(int argc, char ** argv){ g_info << " where ZLCP_OP_WRITE_RT_BREAK is finished before SAVE_PAGES" << endl; require(!pause_lcp()); - for(size_t j = 0; jcloseTransaction(conVector[i]); + for(size_t j = 0; j < conVector.size(); j++){ + pNdb->closeTransaction(conVector[j]); } conVector.clear(); l++; @@ -537,8 +537,8 @@ int runTestDeleteNdb(NDBT_Context* ctx, NDBT_Step* step){ } // Delete the ndb objects - for(size_t i = 0; i < ndbVector.size(); i++) - delete ndbVector[i]; + for(size_t j = 0; j < ndbVector.size(); j++) + delete ndbVector[j]; ndbVector.clear(); l++; } diff --git a/ndb/test/ndbapi/testOIBasic.cpp b/ndb/test/ndbapi/testOIBasic.cpp index 21862e02328..41f0686e63b 100644 --- a/ndb/test/ndbapi/testOIBasic.cpp +++ b/ndb/test/ndbapi/testOIBasic.cpp @@ -407,10 +407,11 @@ Col::verify(const void* addr) const const unsigned char* p = (const unsigned char*)addr; unsigned n = (p[0] << 8) | p[1]; assert(n <= m_length); - for (unsigned i = 0; i < n; i++) { + unsigned i; + for (i = 0; i < n; i++) { assert(p[2 + i] != 0); } - for (unsigned i = n; i < m_length; i++) { + for (i = n; i < m_length; i++) { assert(p[2 + i] == 0); } } @@ -3021,7 +3022,8 @@ runstep(Par par, const char* fname, TFunc func, unsigned mode) { LL2(fname); const int threads = (mode & ST ? 1 : par.m_threads); - for (int n = 0; n < threads; n++) { + int n; + for (n = 0; n < threads; n++) { LL4("start " << n); Thr& thr = *g_thrlist[n]; thr.m_par.m_tab = par.m_tab; @@ -3033,7 +3035,7 @@ runstep(Par par, const char* fname, TFunc func, unsigned mode) thr.start(); } unsigned errs = 0; - for (int n = threads - 1; n >= 0; n--) { + for (n = threads - 1; n >= 0; n--) { LL4("stop " << n); Thr& thr = *g_thrlist[n]; thr.stopped(); @@ -3301,10 +3303,11 @@ runtest(Par par) CHK(con.connect() == 0); par.m_con = &con; g_thrlist = new Thr* [par.m_threads]; - for (unsigned n = 0; n < par.m_threads; n++) { + unsigned n; + for (n = 0; n < par.m_threads; n++) { g_thrlist[n] = 0; } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { g_thrlist[n] = new Thr(par, n); Thr& thr = *g_thrlist[n]; assert(thr.m_thread != 0); @@ -3330,11 +3333,11 @@ runtest(Par par) } } } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { Thr& thr = *g_thrlist[n]; thr.exit(); } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { Thr& thr = *g_thrlist[n]; thr.join(); delete &thr; diff --git a/ndb/test/ndbapi/testReadPerf.cpp b/ndb/test/ndbapi/testReadPerf.cpp index 8d0d78cbe8c..380a809ad00 100644 --- a/ndb/test/ndbapi/testReadPerf.cpp +++ b/ndb/test/ndbapi/testReadPerf.cpp @@ -99,7 +99,8 @@ main(int argc, const char** argv){ { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" } }; const int num_args = 1 + P_MAX; - for(int i = 0; i nodeIds; - for(Uint32 i = 0; i nodeIds; - for(Uint32 i = 0; i nodeIds; - for(Uint32 i = 0; i nodeIds; - for(Uint32 i = 0; i nodeIds; - for(Uint32 i = 0; i nodeIds; - for(Uint32 i = 0; i Date: Mon, 8 Nov 2004 13:33:10 +0000 Subject: [PATCH 29/94] added ndb test platform test --- mysql-test/ndb/ndbcluster.sh | 7 +++ ndb/tools/Makefile.am | 3 ++ ndb/tools/ndb_test_platform.cpp | 93 +++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 ndb/tools/ndb_test_platform.cpp diff --git a/mysql-test/ndb/ndbcluster.sh b/mysql-test/ndb/ndbcluster.sh index 9c6b6093b93..f5757a11056 100644 --- a/mysql-test/ndb/ndbcluster.sh +++ b/mysql-test/ndb/ndbcluster.sh @@ -22,6 +22,7 @@ if [ -d ../sql ] ; then exec_ndb=$ndbtop/src/kernel/ndbd exec_mgmtsrvr=$ndbtop/src/mgmsrv/ndb_mgmd exec_waiter=$ndbtop/tools/ndb_waiter + exec_test=$ndbtop/tools/ndb_test_platform exec_mgmtclient=$ndbtop/src/mgmclient/ndb_mgm else BINARY_DIST=1 @@ -34,9 +35,15 @@ else exec_mgmtsrvr=$BASEDIR/bin/ndb_mgmd fi exec_waiter=$BASEDIR/bin/ndb_waiter + exec_waiter=$BASEDIR/bin/ndb_test_platform exec_mgmtclient=$BASEDIR/bin/ndb_mgm fi +if $exec_test ; then :; else + echo "ndb not correctly compiled to support this platform" + exit 1 +fi + pidfile=ndbcluster.pid cfgfile=Ndb.cfg stop_ndb= diff --git a/ndb/tools/Makefile.am b/ndb/tools/Makefile.am index 64625f69ea2..fad9bf9ff84 100644 --- a/ndb/tools/Makefile.am +++ b/ndb/tools/Makefile.am @@ -1,5 +1,6 @@ ndbtools_PROGRAMS = \ + ndb_test_platform \ ndb_waiter \ ndb_drop_table \ ndb_delete_all \ @@ -11,6 +12,7 @@ ndbtools_PROGRAMS = \ tools_common_sources = ../test/src/NDBT_ReturnCodes.cpp ../test/src/NDBT_Table.cpp ../test/src/NDBT_Output.cpp +ndb_test_platform_SOURCES = ndb_test_platform.cpp ndb_waiter_SOURCES = waiter.cpp $(tools_common_sources) ndb_delete_all_SOURCES = delete_all.cpp $(tools_common_sources) ndb_desc_SOURCES = desc.cpp $(tools_common_sources) @@ -23,6 +25,7 @@ ndb_select_count_SOURCES = select_count.cpp $(tools_common_sources) include $(top_srcdir)/ndb/config/common.mk.am include $(top_srcdir)/ndb/config/type_ndbapitools.mk.am +ndb_test_platform_LDFLAGS = @ndb_bin_am_ldflags@ ndb_waiter_LDFLAGS = @ndb_bin_am_ldflags@ ndb_drop_table_LDFLAGS = @ndb_bin_am_ldflags@ ndb_delete_all_LDFLAGS = @ndb_bin_am_ldflags@ diff --git a/ndb/tools/ndb_test_platform.cpp b/ndb/tools/ndb_test_platform.cpp new file mode 100644 index 00000000000..2b8bbd0274b --- /dev/null +++ b/ndb/tools/ndb_test_platform.cpp @@ -0,0 +1,93 @@ +/* Copyright (C) 2003 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#include +#include +#include + +/* + * Test BaseString::snprintf + */ + +static +int test_snprintf(const char * fmt, int buf_sz, int result) +{ + int ret; + char buf[100]; + ret = BaseString::snprintf(buf, buf_sz, fmt); + + if(ret < 0) + { + printf("BaseString::snprint returns %d\n", ret); + return -1; + } + + if(ret+1 == buf_sz) + { + printf("BaseString::snprint truncates\n"); + return -1; + } + + if(ret != result) + { + printf("BaseString::snprint returns incorrect value: %d != %d\n", + ret, result); + return -1; + } + + for(ret = 0; ret+1 < buf_sz && ret < result; ret++) + { + if(buf[ret] != fmt[ret]) + { + printf("BaseString::snprint Incorrect value in output buffer: " + "%d %d %d %d %d\n", + buf_sz, result, ret, buf[ret], fmt[ret]); + return -1; + } + } + return 0; +} + +int +main(void) +{ + /* + * Test BaseString::snprintf + */ + + if(test_snprintf("test", 1, 4)) + return -1; + + if(test_snprintf("test", 0, 4)) + return -1; + + if(test_snprintf("test", 100, 4)) + return -1; + + /* + * Test UintPtr + */ + + if (sizeof(UintPtr) != sizeof(Uint32*)) + { + printf("sizeof(UintPtr)=%d != sizeof(Uint32*)=%d\n", + sizeof(UintPtr), sizeof(Uint32*)); + return -1; + } + + return 0; +} From a83f8e60abfacc06d440996e3b3206e834bdb85c Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Tue, 9 Nov 2004 00:19:39 +0400 Subject: [PATCH 30/94] mysql.h: Adding a prototype for the new function. --- include/mysql.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/mysql.h b/include/mysql.h index 8abeb86e32a..08ea2da2e58 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -392,6 +392,8 @@ unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long from_length); +unsigned long STDCALL mysql_hex_string(char *to,const char *from, + unsigned long from_length); unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length); From 0517e7b22d545ece452022b372d1bd3426e720d4 Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Mon, 8 Nov 2004 21:45:23 +0100 Subject: [PATCH 31/94] As rollback can be 30 times slower than insert in InnoDB, and user may not know there's rollback (if it's because of a dupl row), better warn that it's happening. It can also be of use for a DBA killing a connection and wondering what this connection is still doing now. Example: | 5 | root | localhost | test | Killed | 10 | Rolling back | insert into i select * from j | --- sql/handler.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql/handler.cc b/sql/handler.cc index f7a1a6ef0bf..cb88ab463d8 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -581,6 +581,12 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) if (opt_using_transactions) { bool operation_done=0; + /* + As rollback can be 30 times slower than insert in InnoDB, and user may + not know there's rollback (if it's because of a dupl row), better warn. + */ + const char *save_proc_info= thd->proc_info; + thd->proc_info= "Rolling back"; #ifdef HAVE_NDBCLUSTER_DB if (trans->ndb_tid) { @@ -652,6 +658,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) thd->variables.tx_isolation=thd->session_tx_isolation; if (operation_done) statistic_increment(ha_rollback_count,&LOCK_status); + thd->proc_info= save_proc_info; } #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); From 6c44563fc5c248fdab9d5818fd19138bb104fcb4 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Tue, 9 Nov 2004 03:20:58 +0200 Subject: [PATCH 32/94] Simple optimization --- sql/field.cc | 13 ++++++++++--- sql/field_conv.cc | 4 +--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index 1111e47bc38..deb38048d42 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4390,6 +4390,8 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)), int Field_string::cmp(const char *a_ptr, const char *b_ptr) { + uint a_len, b_len; + if (field_charset->strxfrm_multiply > 1) { /* @@ -4401,9 +4403,14 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr) (const uchar*) b_ptr, field_length); } - uint char_len= field_length/field_charset->mbmaxlen; - uint a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len); - uint b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len); + if (field_charset->mbmaxlen != 1) + { + uint char_len= field_length/field_charset->mbmaxlen; + a_len= my_charpos(field_charset, a_ptr, a_ptr + field_length, char_len); + b_len= my_charpos(field_charset, b_ptr, b_ptr + field_length, char_len); + } + else + a_len= b_len= field_length; return my_strnncoll(field_charset,(const uchar*) a_ptr, a_len, (const uchar*) b_ptr, b_len); } diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 8a36fcd153c..61a5a28f47b 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -473,9 +473,7 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) { if (to->flags & BLOB_FLAG) { - if (!(from->flags & BLOB_FLAG)) - return do_conv_blob; - if (from->charset() != to->charset()) + if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset()) return do_conv_blob; if (from_length != to_length || to->table->db_low_byte_first != from->table->db_low_byte_first) From d6860f8502c264b08313271710ad46c9a48e7eb2 Mon Sep 17 00:00:00 2001 From: "joreland@mysql.com" <> Date: Tue, 9 Nov 2004 11:59:28 +0100 Subject: [PATCH 33/94] ndb: compile fix for hpita2-64 bit - remove a bunch of includes --- .../debugger/signaldata/SignalDataPrint.cpp | 64 ++----------------- 1 file changed, 5 insertions(+), 59 deletions(-) diff --git a/ndb/src/common/debugger/signaldata/SignalDataPrint.cpp b/ndb/src/common/debugger/signaldata/SignalDataPrint.cpp index 188468e1c31..a4cee38e06f 100644 --- a/ndb/src/common/debugger/signaldata/SignalDataPrint.cpp +++ b/ndb/src/common/debugger/signaldata/SignalDataPrint.cpp @@ -16,65 +16,9 @@ -#include "GlobalSignalNumbers.h" -#include "signaldata/SignalDataPrint.hpp" -#include "signaldata/TcKeyReq.hpp" -#include "signaldata/TcKeyConf.hpp" -#include "signaldata/TcKeyRef.hpp" -#include "signaldata/LqhKey.hpp" -#include "signaldata/TupKey.hpp" -#include "signaldata/TupCommit.hpp" -#include "signaldata/FsOpenReq.hpp" -#include "signaldata/FsCloseReq.hpp" -#include "signaldata/FsReadWriteReq.hpp" -#include "signaldata/FsRef.hpp" -#include "signaldata/FsConf.hpp" -#include "signaldata/CloseComReqConf.hpp" -#include "signaldata/PackedSignal.hpp" -#include "signaldata/PrepFailReqRef.hpp" -#include "signaldata/DictTabInfo.hpp" -#include "signaldata/AlterTable.hpp" -#include "signaldata/AlterTab.hpp" -#include "signaldata/CreateTrig.hpp" -#include "signaldata/AlterTrig.hpp" -#include "signaldata/DropTrig.hpp" -#include "signaldata/FireTrigOrd.hpp" -#include "signaldata/TrigAttrInfo.hpp" -#include "signaldata/CreateIndx.hpp" -#include "signaldata/AlterIndx.hpp" -#include "signaldata/DropIndx.hpp" -#include "signaldata/TcIndx.hpp" -#include "signaldata/IndxKeyInfo.hpp" -#include "signaldata/IndxAttrInfo.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include /** * This is the register @@ -254,6 +198,8 @@ SignalDataPrintFunctions[] = { ,{ 0, 0 } }; +#include + template struct BitmaskPOD<1>; template struct BitmaskPOD<2>; template struct BitmaskPOD<4>; From d45bbae2de60d92a98e1696f8dc54b5c74915e3b Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Tue, 9 Nov 2004 14:46:26 +0200 Subject: [PATCH 34/94] Fix for valgrind/purify for variables that the compiler touches but that doesn't affect the outcome of the tests --- include/my_global.h | 6 ++++++ sql/item_timefunc.cc | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index f6200830ee3..07d4d8dc1cc 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -370,6 +370,12 @@ int __void__; #define LINT_INIT(var) #endif +#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_purify) +#define PURIFY_OR_LINT_INIT(var) var=0 +#else +#define PURIFY_OR_LINT_INIT(var) +#endif + /* Define some useful general macros */ #if defined(__cplusplus) && defined(__GNUC__) #define max(a, b) ((a) >? (b)) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 41418c0094d..d8142352e70 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -161,21 +161,24 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, { int weekday= 0, yearday= 0, daypart= 0; int week_number= -1; - CHARSET_INFO *cs= &my_charset_bin; int error= 0; - bool usa_time= 0; - bool sunday_first_n_first_week_non_iso= -2; - bool strict_week_number; int strict_week_number_year= -1; - bool strict_week_number_year_type= -1; int frac_part; + bool usa_time= 0; + bool sunday_first_n_first_week_non_iso; + bool strict_week_number; + bool strict_week_number_year_type; const char *val_begin= val; const char *val_end= val + length; const char *ptr= format->format.str; const char *end= ptr + format->format.length; + CHARSET_INFO *cs= &my_charset_bin; DBUG_ENTER("extract_date_time"); LINT_INIT(strict_week_number); + /* Remove valgrind varnings when using gcc 3.3 and -O1 */ + PURIFY_OR_LINT_INIT(strict_week_number_year_type); + PURIFY_OR_LINT_INIT(sunday_first_n_first_week_non_iso); if (!sub_pattern_end) bzero((char*) l_time, sizeof(*l_time)); From d7eecc803d483617139b6f76dac5349dd5ccf78a Mon Sep 17 00:00:00 2001 From: "heikki@hundin.mysql.fi" <> Date: Tue, 9 Nov 2004 15:59:45 +0200 Subject: [PATCH 35/94] dict0dict.ic: Fix a bug in InnoDB code that fortunately was never used: row id is stored in a record always as a 6-byte unsigned integer, in a 'non-compressed' form --- innobase/include/dict0dict.ic | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/innobase/include/dict0dict.ic b/innobase/include/dict0dict.ic index 0f7cc8973db..85e4aaf1a05 100644 --- a/innobase/include/dict0dict.ic +++ b/innobase/include/dict0dict.ic @@ -342,13 +342,16 @@ dict_index_rec_get_sys_col( ut_ad(len == 7); return(trx_read_roll_ptr(field)); - } else if ((type == DATA_ROW_ID) || (type == DATA_MIX_ID)) { + } else if (type == DATA_TRX_ID) { + + return(trx_read_trx_id(field)); + } else if (type == DATA_MIX_ID) { return(mach_dulint_read_compressed(field)); } else { - ut_ad(type == DATA_TRX_ID); + ut_a(type == DATA_ROW_ID); - return(trx_read_trx_id(field)); + return(mach_read_from_6(field)); } } From 0d0ed072da20c4af7a2433e21206aec773482b49 Mon Sep 17 00:00:00 2001 From: "paul@kite-hub.kitebird.com" <> Date: Tue, 9 Nov 2004 11:03:02 -0600 Subject: [PATCH 36/94] Alphabetize some out-of-order options in option structure. Revise the --hex-blob help message string. (This will need revising after merge to 4.1, too, but the CHAR BINARY and VARCHAR BINARY data types will be BINARY and VARBINRY.) --- client/mysqldump.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 0e840512ba0..58d601654a4 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -114,6 +114,9 @@ static struct my_option my_long_options[] = {"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"comments", 'i', "Write additional information.", + (gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG, + 1, 0, 0, 0, 0, 0}, {"complete-insert", 'c', "Use complete insert statements.", (gptr*) &cFlag, (gptr*) &cFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"compress", 'C', "Use compression in server/client protocol.", @@ -166,6 +169,9 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0, 0}, {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"hex-blob", OPT_HEXBLOB, "Dump binary strings (CHAR BINARY, " + "VARCHAR BINARY, BLOB) in hexadecimal format.", + (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"host", 'h', "Connect to host.", (gptr*) ¤t_host, (gptr*) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", @@ -180,10 +186,6 @@ static struct my_option my_long_options[] = "Wrap tables with autocommit/commit statements.", (gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"single-transaction", OPT_TRANSACTION, - "Dump all tables in single transaction to get consistent snapshot. Mutually exclusive with --lock-tables.", - (gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG, - 0, 0, 0, 0, 0, 0}, {"no-create-db", 'n', "'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}", (gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0, @@ -192,9 +194,6 @@ static struct my_option my_long_options[] = (gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"set-variable", 'O', - "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"opt", OPT_OPTIMIZE, "Same as --add-drop-table --add-locks --all --quick --extended-insert --lock-tables --disable-keys", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -216,6 +215,13 @@ static struct my_option my_long_options[] = {"result-file", 'r', "Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\r\\n' (carriage return + line feed).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"set-variable", 'O', + "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"single-transaction", OPT_TRANSACTION, + "Dump all tables in single transaction to get consistent snapshot. Mutually exclusive with --lock-tables.", + (gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, {"socket", 'S', "Socket file to use for connection.", (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -246,11 +252,6 @@ static struct my_option my_long_options[] = (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, MALLOC_OVERHEAD-1024, 1024, 0}, - {"comments", 'i', "Write additional information.", - (gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG, - 1, 0, 0, 0, 0, 0}, - {"hex-blob", OPT_HEXBLOB, "Dump BLOBs in HEX.", - (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; From fd3ec9ca01ac0865a2187c48f309f9ef718470bc Mon Sep 17 00:00:00 2001 From: "kent@mysql.com" <> Date: Tue, 9 Nov 2004 20:21:37 +0100 Subject: [PATCH 37/94] mysql_test_run_new.c, my_manage.h, my_manage.c: Added Solaris compatibility --- mysql-test/my_manage.c | 92 +++++--- mysql-test/my_manage.h | 2 - mysql-test/mysql_test_run_new.c | 398 ++++++++++++++++---------------- 3 files changed, 257 insertions(+), 235 deletions(-) diff --git a/mysql-test/my_manage.c b/mysql-test/my_manage.c index ba5c674d105..cc27558f131 100644 --- a/mysql-test/my_manage.c +++ b/mysql-test/my_manage.c @@ -30,7 +30,8 @@ #ifndef __WIN__ #include #include -#include +#include +#include /* FIXME HAVE_FNMATCH_H or something */ #else #include #include @@ -100,7 +101,7 @@ void init_args(arg_list_t *al) void add_arg(arg_list_t *al, const char *format, ...) { va_list ap; - char temp[PATH_MAX]; + char temp[FN_REFLEN]; ASSERT(al != NULL); @@ -230,10 +231,10 @@ int wait_for_server_start(char *bin_dir __attribute__((unused)), { arg_list_t al; int err= 0, i; - char trash[PATH_MAX]; + char trash[FN_REFLEN]; /* mysqladmin file */ - snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir); + snprintf(trash, FN_REFLEN, "%s/trash.out",tmp_dir); /* args */ init_args(&al); @@ -490,9 +491,9 @@ int stop_server(char *bin_dir __attribute__((unused)), char *mysqladmin_file, { arg_list_t al; int err= 0; - char trash[PATH_MAX]; + char trash[FN_REFLEN]; - snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir); + snprintf(trash, FN_REFLEN, "%s/trash.out",tmp_dir); /* args */ init_args(&al); @@ -548,7 +549,7 @@ int stop_server(char *bin_dir __attribute__((unused)), char *mysqladmin_file, #ifndef __WIN__ pid_t get_server_pid(char *pid_file) { - char buf[PATH_MAX]; + char buf[FN_REFLEN]; int fd, err; char *p; pid_t id= 0; @@ -556,7 +557,7 @@ pid_t get_server_pid(char *pid_file) /* discover id */ fd= open(pid_file, O_RDONLY); - err= read(fd, buf, PATH_MAX); + err= read(fd, buf, FN_REFLEN); close(fd); @@ -619,7 +620,7 @@ void del_tree(char *dir) #ifndef __WIN__ DIR *parent= opendir(dir); struct dirent *entry; - char temp[PATH_MAX]; + char temp[FN_REFLEN]; if (parent == NULL) { @@ -629,22 +630,36 @@ void del_tree(char *dir) while ((entry= readdir(parent)) != NULL) { /* create long name */ - snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name); + snprintf(temp, FN_REFLEN, "%s/%s", dir, entry->d_name); if (entry->d_name[0] == '.') { /* Skip */ } else - if (S_ISDIR(entry->d_type)) { - /* delete subdirectory */ - del_tree(temp); - } - else - { - /* remove file */ - remove(temp); +/* FIXME missing test in acinclude.m4 */ +#ifndef STRUCT_DIRENT_HAS_D_TYPE + struct stat st; + + if (lstat(entry->d_name, &st) == -1) + { + /* FIXME error */ + return; + } + if (S_ISDIR(st.st_mode)) +#else + if (S_ISDIR(entry->d_type)) +#endif + { + /* delete subdirectory */ + del_tree(temp); + } + else + { + /* remove file */ + remove(temp); + } } } /* remove directory */ @@ -652,10 +667,10 @@ void del_tree(char *dir) #else struct _finddata_t parent; intptr_t handle; - char temp[PATH_MAX]; - char mask[PATH_MAX]; + char temp[FN_REFLEN]; + char mask[FN_REFLEN]; - snprintf(mask,MAX_PATH,"%s/*.*",dir); + snprintf(mask,FN_REFLEN,"%s/*.*",dir); if ((handle=_findfirst(mask,&parent)) == -1L) { @@ -665,7 +680,7 @@ void del_tree(char *dir) do { /* create long name */ - snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name); + snprintf(temp, FN_REFLEN, "%s/%s", dir, parent.name); if (parent.name[0] == '.') { /* Skip */ @@ -700,11 +715,11 @@ int removef(const char *format, ...) { #ifdef __NETWARE__ va_list ap; - char path[PATH_MAX]; + char path[FN_REFLEN]; va_start(ap, format); - vsnprintf(path, PATH_MAX, format, ap); + vsnprintf(path, FN_REFLEN, format, ap); va_end(ap); return remove(path); @@ -712,15 +727,15 @@ int removef(const char *format, ...) #eldef __WIN__ { va_list ap; - char path[PATH_MAX]; + char path[FN_REFLEN]; struct _finddata_t parent; intptr_t handle; - char temp[PATH_MAX]; + char temp[FN_REFLEN]; char *p; va_start(ap, format); - vsnprintf(path, PATH_MAX, format, ap); + vsnprintf(path, FN_REFLEN, format, ap); va_end(ap); @@ -739,7 +754,7 @@ int removef(const char *format, ...) { if (! (parent.attrib & _A_SUBDIR)) { - snprintf(temp, PATH_MAX, "%s/%s", path, parent.name); + snprintf(temp, FN_REFLEN, "%s/%s", path, parent.name); remove(temp); } }while (_findnext(handle,&parent) == 0); @@ -749,14 +764,14 @@ int removef(const char *format, ...) #else DIR *parent; struct dirent *entry; - char temp[PATH_MAX]; + char temp[FN_REFLEN]; va_list ap; - char path[PATH_MAX]; + char path[FN_REFLEN]; char *p; /* Get path with mask */ va_start(ap, format); - vsnprintf(path, PATH_MAX, format, ap); + vsnprintf(path, FN_REFLEN, format, ap); va_end(ap); @@ -775,10 +790,21 @@ int removef(const char *format, ...) while ((entry= readdir(parent)) != NULL) { /* entry is not directory and entry matches with mask */ +#ifndef STRUCT_DIRENT_HAS_D_TYPE + struct stat st; + + if (lstat(entry->d_name, &st) == -1) + { + return 1; + } + + if (!S_ISDIR(st.st_mode) && !fnmatch(p, entry->d_name,0)) +#else if (!S_ISDIR(entry->d_type) && !fnmatch(p, entry->d_name,0)) +#endif { /* create long name */ - snprintf(temp, PATH_MAX, "%s/%s", path, entry->d_name); + snprintf(temp, FN_REFLEN, "%s/%s", path, entry->d_name); /* Delete only files */ remove(temp); } @@ -795,7 +821,7 @@ int removef(const char *format, ...) void get_basedir(char *argv0, char *basedir) { - char temp[PATH_MAX]; + char temp[FN_REFLEN]; char *p; int position; diff --git a/mysql-test/my_manage.h b/mysql-test/my_manage.h index a61c693c22c..7e371d36ab1 100644 --- a/mysql-test/my_manage.h +++ b/mysql-test/my_manage.h @@ -52,8 +52,6 @@ int my_vsnprintf_(char *to, size_t n, const char* value, ...); #define TRY_MAX 5 #ifdef __WIN__ -#define PATH_MAX _MAX_PATH -#define NAME_MAX _MAX_FNAME #define kill(A,B) TerminateProcess((HANDLE)A,0) #define NOT_NEED_PID 0 #define MASTER_PID 1 diff --git a/mysql-test/mysql_test_run_new.c b/mysql-test/mysql_test_run_new.c index 1e8a1dded51..d8bf731b398 100644 --- a/mysql-test/mysql_test_run_new.c +++ b/mysql-test/mysql_test_run_new.c @@ -73,25 +73,25 @@ const char *TEST_IGNORE= "[ignore]"; ******************************************************************************/ #ifdef __NETWARE__ -static char base_dir[PATH_MAX]= "sys:/mysql"; +static char base_dir[FN_REFLEN]= "sys:/mysql"; #else -static char base_dir[PATH_MAX]= ".."; +static char base_dir[FN_REFLEN]= ".."; #endif -static char db[PATH_MAX]= "test"; -static char user[PATH_MAX]= "root"; -static char password[PATH_MAX]= ""; +static char db[FN_LEN]= "test"; +static char user[FN_LEN]= "root"; +static char password[FN_LEN]= ""; int master_port= 9306; int slave_port= 9307; #if !defined(__NETWARE__) && !defined(__WIN__) -static char master_socket[PATH_MAX]= "./var/tmp/master.sock"; -static char slave_socket[PATH_MAX]= "./var/tmp/slave.sock"; +static char master_socket[FN_REFLEN]= "./var/tmp/master.sock"; +static char slave_socket[FN_REFLEN]= "./var/tmp/slave.sock"; #endif /* comma delimited list of tests to skip or empty string */ #ifndef __WIN__ -static char skip_test[PATH_MAX]= " lowercase_table3 , system_mysql_db_fix "; +static char skip_test[FN_REFLEN]= " lowercase_table3 , system_mysql_db_fix "; #else /* The most ignore testes contain the calls of system command @@ -110,7 +110,7 @@ static char skip_test[PATH_MAX]= " lowercase_table3 , system_mysql_db_fix "; mysqldump contains a command system rpl000001 makes non-exit loop...temporary skiped */ -static char skip_test[PATH_MAX]= +static char skip_test[FN_REFLEN]= " lowercase_table3 ," " system_mysql_db_fix ," " sp ," @@ -123,44 +123,44 @@ static char skip_test[PATH_MAX]= " mysqldump ," " rpl000001 "; #endif -static char ignore_test[PATH_MAX]= ""; +static char ignore_test[FN_REFLEN]= ""; -static char bin_dir[PATH_MAX]; -static char mysql_test_dir[PATH_MAX]; -static char test_dir[PATH_MAX]; -static char mysql_tmp_dir[PATH_MAX]; -static char result_dir[PATH_MAX]; -static char master_dir[PATH_MAX]; -static char slave_dir[PATH_MAX]; -static char lang_dir[PATH_MAX]; -static char char_dir[PATH_MAX]; +static char bin_dir[FN_REFLEN]; +static char mysql_test_dir[FN_REFLEN]; +static char test_dir[FN_REFLEN]; +static char mysql_tmp_dir[FN_REFLEN]; +static char result_dir[FN_REFLEN]; +static char master_dir[FN_REFLEN]; +static char slave_dir[FN_REFLEN]; +static char lang_dir[FN_REFLEN]; +static char char_dir[FN_REFLEN]; -static char mysqladmin_file[PATH_MAX]; -static char mysqld_file[PATH_MAX]; -static char mysqltest_file[PATH_MAX]; +static char mysqladmin_file[FN_REFLEN]; +static char mysqld_file[FN_REFLEN]; +static char mysqltest_file[FN_REFLEN]; #ifndef __WIN__ -static char master_pid[PATH_MAX]; -static char slave_pid[PATH_MAX]; -static char sh_file[PATH_MAX]= "/bin/sh"; +static char master_pid[FN_REFLEN]; +static char slave_pid[FN_REFLEN]; +static char sh_file[FN_REFLEN]= "/bin/sh"; #else static HANDLE master_pid; static HANDLE slave_pid; #endif -static char master_opt[PATH_MAX]= ""; -static char slave_opt[PATH_MAX]= ""; +static char master_opt[FN_REFLEN]= ""; +static char slave_opt[FN_REFLEN]= ""; -static char slave_master_info[PATH_MAX]= ""; +static char slave_master_info[FN_REFLEN]= ""; -static char master_init_script[PATH_MAX]= ""; -static char slave_init_script[PATH_MAX]= ""; +static char master_init_script[FN_REFLEN]= ""; +static char slave_init_script[FN_REFLEN]= ""; /* OpenSSL */ -static char ca_cert[PATH_MAX]; -static char server_cert[PATH_MAX]; -static char server_key[PATH_MAX]; -static char client_cert[PATH_MAX]; -static char client_key[PATH_MAX]; +static char ca_cert[FN_REFLEN]; +static char server_cert[FN_REFLEN]; +static char server_key[FN_REFLEN]; +static char client_cert[FN_REFLEN]; +static char client_key[FN_REFLEN]; int total_skip= 0; int total_pass= 0; @@ -254,18 +254,18 @@ void install_db(char *datadir) { arg_list_t al; int err; - char input[PATH_MAX]; - char output[PATH_MAX]; - char error[PATH_MAX]; + char input[FN_REFLEN]; + char output[FN_REFLEN]; + char error[FN_REFLEN]; /* input file */ #ifdef __NETWARE__ - snprintf(input, PATH_MAX, "%s/bin/init_db.sql", base_dir); + snprintf(input, FN_REFLEN, "%s/bin/init_db.sql", base_dir); #else - snprintf(input, PATH_MAX, "%s/mysql-test/init_db.sql", base_dir); + snprintf(input, FN_REFLEN, "%s/mysql-test/init_db.sql", base_dir); #endif - snprintf(output, PATH_MAX, "%s/install.out", datadir); - snprintf(error, PATH_MAX, "%s/install.err", datadir); + snprintf(output, FN_REFLEN, "%s/install.out", datadir); + snprintf(error, FN_REFLEN, "%s/install.err", datadir); /* args */ init_args(&al); @@ -302,10 +302,10 @@ void install_db(char *datadir) void mysql_install_db() { - char temp[PATH_MAX]; + char temp[FN_REFLEN]; /* var directory */ - snprintf(temp, PATH_MAX, "%s/var", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var", mysql_test_dir); /* clean up old direcotry */ del_tree(temp); @@ -315,41 +315,41 @@ void mysql_install_db() mkdir(temp, S_IRWXU); /* create subdirectories */ mlog("Creating test-suite folders...\n"); - snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/run", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/tmp", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data/mysql", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data/test", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data/mysql", mysql_test_dir); mkdir(temp, S_IRWXU); - snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data/test", mysql_test_dir); mkdir(temp, S_IRWXU); #else mkdir(temp); /* create subdirectories */ mlog("Creating test-suite folders...\n"); - snprintf(temp, PATH_MAX, "%s/var/run", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/run", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/tmp", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/tmp", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/master-data", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/master-data/mysql", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data/mysql", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/master-data/test", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/master-data/test", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/slave-data", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/slave-data/mysql", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data/mysql", mysql_test_dir); mkdir(temp); - snprintf(temp, PATH_MAX, "%s/var/slave-data/test", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/var/slave-data/test", mysql_test_dir); mkdir(temp); #endif @@ -372,10 +372,10 @@ void start_master() { arg_list_t al; int err; - char master_out[PATH_MAX]; - char master_err[PATH_MAX]; -/* char temp[PATH_MAX]; */ - char temp2[PATH_MAX]; + char master_out[FN_REFLEN]; + char master_err[FN_REFLEN]; +/* char temp[FN_REFLEN]; */ + char temp2[FN_REFLEN]; /* remove old berkeley db log files that can confuse the server */ removef("%s/log.*", master_dir); @@ -405,7 +405,7 @@ void start_master() FILE *fp; /* create an empty index file */ - snprintf(temp, PATH_MAX, "%s/test/t1.MYI", master_dir); + snprintf(temp, FN_REFLEN, "%s/test/t1.MYI", master_dir); fp= fopen(temp, "wb+"); fputs("1", fp); @@ -418,19 +418,19 @@ void start_master() } /* redirection files */ - snprintf(master_out, PATH_MAX, "%s/var/run/master%u.out", + snprintf(master_out, FN_REFLEN, "%s/var/run/master%u.out", mysql_test_dir, restarts); - snprintf(master_err, PATH_MAX, "%s/var/run/master%u.err", + snprintf(master_err, FN_REFLEN, "%s/var/run/master%u.err", mysql_test_dir, restarts); #ifndef __WIN__ - snprintf(temp2,PATH_MAX,"%s/var",mysql_test_dir); + snprintf(temp2,FN_REFLEN,"%s/var",mysql_test_dir); mkdir(temp2,S_IRWXU); - snprintf(temp2,PATH_MAX,"%s/var/log",mysql_test_dir); + snprintf(temp2,FN_REFLEN,"%s/var/log",mysql_test_dir); mkdir(temp2,S_IRWXU); #else - snprintf(temp2,PATH_MAX,"%s/var",mysql_test_dir); + snprintf(temp2,FN_REFLEN,"%s/var",mysql_test_dir); mkdir(temp2); - snprintf(temp2,PATH_MAX,"%s/var/log",mysql_test_dir); + snprintf(temp2,FN_REFLEN,"%s/var/log",mysql_test_dir); mkdir(temp2); #endif /* args */ @@ -539,8 +539,8 @@ void start_slave() { arg_list_t al; int err; - char slave_out[PATH_MAX]; - char slave_err[PATH_MAX]; + char slave_out[FN_REFLEN]; + char slave_err[FN_REFLEN]; /* skip? */ if (skip_slave) return; @@ -568,7 +568,7 @@ void start_slave() if (strinstr(slave_init_script, "rpl000016-slave.sh") != 0) { /* create empty master.info file */ - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + snprintf(temp, FN_REFLEN, "%s/master.info", slave_dir); close(open(temp, O_WRONLY | O_CREAT,S_IRWXU|S_IRWXG|S_IRWXO)); } else if (strinstr(slave_init_script, "rpl000017-slave.sh") != 0) @@ -576,7 +576,7 @@ void start_slave() FILE *fp; /* create a master.info file */ - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + snprintf(temp, FN_REFLEN, "%s/master.info", slave_dir); fp= fopen(temp, "wb+"); fputs("master-bin.000001\n", fp); @@ -593,7 +593,7 @@ void start_slave() else if (strinstr(slave_init_script, "rpl_rotate_logs-slave.sh") != 0) { /* create empty master.info file */ - snprintf(temp, PATH_MAX, "%s/master.info", slave_dir); + snprintf(temp, FN_REFLEN, "%s/master.info", slave_dir); close(open(temp, O_WRONLY | O_CREAT,S_IRWXU|S_IRWXG|S_IRWXO)); } #elif !defined(__WIN__) @@ -602,9 +602,9 @@ void start_slave() } /* redirection files */ - snprintf(slave_out, PATH_MAX, "%s/var/run/slave%u.out", + snprintf(slave_out, FN_REFLEN, "%s/var/run/slave%u.out", mysql_test_dir, restarts); - snprintf(slave_err, PATH_MAX, "%s/var/run/slave%u.err", + snprintf(slave_err, FN_REFLEN, "%s/var/run/slave%u.err", mysql_test_dir, restarts); /* args */ @@ -859,14 +859,14 @@ int read_option(char *opt_file, char *opt) { int fd, err; char *p; - char buf[PATH_MAX]; + char buf[FN_REFLEN]; /* copy current option */ - strncpy(buf, opt, PATH_MAX); + strncpy(buf, opt, FN_REFLEN); /* open options file */ fd= open(opt_file, O_RDONLY); - err= read(fd, opt, PATH_MAX); + err= read(fd, opt, FN_REFLEN); close(fd); if (err > 0) @@ -890,7 +890,7 @@ int read_option(char *opt_file, char *opt) /* check for $MYSQL_TEST_DIR */ if ((p= strstr(opt, "$MYSQL_TEST_DIR")) != NULL) { - char temp[PATH_MAX]; + char temp[FN_REFLEN]; *p= 0; @@ -925,7 +925,7 @@ int read_option(char *opt_file, char *opt) void run_test(char *test) { - char temp[PATH_MAX]; + char temp[FN_REFLEN]; const char *rstr; int skip= FALSE, ignore=FALSE; int restart= FALSE; @@ -933,13 +933,13 @@ void run_test(char *test) struct stat info; /* skip tests in the skip list */ - snprintf(temp, PATH_MAX, " %s ", test); + snprintf(temp, FN_REFLEN, " %s ", test); skip= (strinstr(skip_test, temp) != 0); if (skip == FALSE) ignore= (strinstr(ignore_test, temp) != 0); - snprintf(master_init_script, PATH_MAX, "%s/%s-master.sh", test_dir, test); - snprintf(slave_init_script, PATH_MAX, "%s/%s-slave.sh", test_dir, test); + snprintf(master_init_script, FN_REFLEN, "%s/%s-master.sh", test_dir, test); + snprintf(slave_init_script, FN_REFLEN, "%s/%s-slave.sh", test_dir, test); #ifdef __WIN__ if (! stat(master_init_script, &info)) skip= TRUE; @@ -957,14 +957,14 @@ void run_test(char *test) } else if (!skip) /* skip test? */ { - char test_file[PATH_MAX]; - char master_opt_file[PATH_MAX]; - char slave_opt_file[PATH_MAX]; - char slave_master_info_file[PATH_MAX]; - char result_file[PATH_MAX]; - char reject_file[PATH_MAX]; - char out_file[PATH_MAX]; - char err_file[PATH_MAX]; + char test_file[FN_REFLEN]; + char master_opt_file[FN_REFLEN]; + char slave_opt_file[FN_REFLEN]; + char slave_master_info_file[FN_REFLEN]; + char result_file[FN_REFLEN]; + char reject_file[FN_REFLEN]; + char out_file[FN_REFLEN]; + char err_file[FN_REFLEN]; int err; arg_list_t al; #ifdef __WIN__ @@ -981,20 +981,20 @@ void run_test(char *test) if (flag != skip_slave) restart= TRUE; /* create files */ - snprintf(master_opt_file, PATH_MAX, "%s/%s-master.opt", test_dir, test); - snprintf(slave_opt_file, PATH_MAX, "%s/%s-slave.opt", test_dir, test); - snprintf(slave_master_info_file, PATH_MAX, "%s/%s.slave-mi", + snprintf(master_opt_file, FN_REFLEN, "%s/%s-master.opt", test_dir, test); + snprintf(slave_opt_file, FN_REFLEN, "%s/%s-slave.opt", test_dir, test); + snprintf(slave_master_info_file, FN_REFLEN, "%s/%s.slave-mi", test_dir, test); - snprintf(reject_file, PATH_MAX, "%s/%s%s", + snprintf(reject_file, FN_REFLEN, "%s/%s%s", result_dir, test, REJECT_SUFFIX); - snprintf(out_file, PATH_MAX, "%s/%s%s", result_dir, test, OUT_SUFFIX); - snprintf(err_file, PATH_MAX, "%s/%s%s", result_dir, test, ERR_SUFFIX); + snprintf(out_file, FN_REFLEN, "%s/%s%s", result_dir, test, OUT_SUFFIX); + snprintf(err_file, FN_REFLEN, "%s/%s%s", result_dir, test, ERR_SUFFIX); /* netware specific files */ - snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, NW_TEST_SUFFIX); + snprintf(test_file, FN_REFLEN, "%s/%s%s", test_dir, test, NW_TEST_SUFFIX); if (stat(test_file, &info)) { - snprintf(test_file, PATH_MAX, "%s/%s%s", test_dir, test, TEST_SUFFIX); + snprintf(test_file, FN_REFLEN, "%s/%s%s", test_dir, test, TEST_SUFFIX); if (access(test_file,0)) { printf("Invalid test name %s, %s file not found\n",test,test_file); @@ -1002,11 +1002,11 @@ void run_test(char *test) } } - snprintf(result_file, PATH_MAX, "%s/%s%s", + snprintf(result_file, FN_REFLEN, "%s/%s%s", result_dir, test, NW_RESULT_SUFFIX); if (stat(result_file, &info)) { - snprintf(result_file, PATH_MAX, "%s/%s%s", + snprintf(result_file, FN_REFLEN, "%s/%s%s", result_dir, test, RESULT_SUFFIX); } @@ -1248,8 +1248,8 @@ void die(const char *msg) void setup(char *file __attribute__((unused))) { - char temp[PATH_MAX]; - char file_path[PATH_MAX*2]; + char temp[FN_REFLEN]; + char file_path[FN_REFLEN*2]; char *p; int position; @@ -1257,14 +1257,14 @@ void setup(char *file __attribute__((unused))) #ifdef __WIN__ _putenv( "TZ=GMT-3" ); #else - setenv("TZ", "GMT-3", TRUE); + putenv((char *)"TZ=GMT-3"); #endif /* find base dir */ #ifdef __NETWARE__ strcpy(temp, strlwr(file)); while ((p= strchr(temp, '\\')) != NULL) *p= '/'; #else - getcwd(temp, PATH_MAX); + getcwd(temp, FN_REFLEN); position= strlen(temp); temp[position]= '/'; temp[position+1]= 0; @@ -1284,100 +1284,100 @@ void setup(char *file __attribute__((unused))) #ifdef __NETWARE__ /* setup paths */ - snprintf(bin_dir, PATH_MAX, "%s/bin", base_dir); - snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); - snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); - snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); - snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); - snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); - snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); - snprintf(lang_dir, PATH_MAX, "%s/share/english", base_dir); - snprintf(char_dir, PATH_MAX, "%s/share/charsets", base_dir); + snprintf(bin_dir, FN_REFLEN, "%s/bin", base_dir); + snprintf(mysql_test_dir, FN_REFLEN, "%s/mysql-test", base_dir); + snprintf(test_dir, FN_REFLEN, "%s/t", mysql_test_dir); + snprintf(mysql_tmp_dir, FN_REFLEN, "%s/var/tmp", mysql_test_dir); + snprintf(result_dir, FN_REFLEN, "%s/r", mysql_test_dir); + snprintf(master_dir, FN_REFLEN, "%s/var/master-data", mysql_test_dir); + snprintf(slave_dir, FN_REFLEN, "%s/var/slave-data", mysql_test_dir); + snprintf(lang_dir, FN_REFLEN, "%s/share/english", base_dir); + snprintf(char_dir, FN_REFLEN, "%s/share/charsets", base_dir); #ifdef HAVE_OPENSSL use_openssl= TRUE; #endif /* HAVE_OPENSSL */ /* OpenSSL paths */ - snprintf(ca_cert, PATH_MAX, "%s/SSL/cacert.pem", base_dir); - snprintf(server_cert, PATH_MAX, "%s/SSL/server-cert.pem", base_dir); - snprintf(server_key, PATH_MAX, "%s/SSL/server-key.pem", base_dir); - snprintf(client_cert, PATH_MAX, "%s/SSL/client-cert.pem", base_dir); - snprintf(client_key, PATH_MAX, "%s/SSL/client-key.pem", base_dir); + snprintf(ca_cert, FN_REFLEN, "%s/SSL/cacert.pem", base_dir); + snprintf(server_cert, FN_REFLEN, "%s/SSL/server-cert.pem", base_dir); + snprintf(server_key, FN_REFLEN, "%s/SSL/server-key.pem", base_dir); + snprintf(client_cert, FN_REFLEN, "%s/SSL/client-cert.pem", base_dir); + snprintf(client_key, FN_REFLEN, "%s/SSL/client-key.pem", base_dir); /* setup files */ - snprintf(mysqld_file, PATH_MAX, "%s/mysqld", bin_dir); - snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest", bin_dir); - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); - snprintf(master_pid, PATH_MAX, "%s/var/run/master.pid", mysql_test_dir); - snprintf(slave_pid, PATH_MAX, "%s/var/run/slave.pid", mysql_test_dir); + snprintf(mysqld_file, FN_REFLEN, "%s/mysqld", bin_dir); + snprintf(mysqltest_file, FN_REFLEN, "%s/mysqltest", bin_dir); + snprintf(mysqladmin_file, FN_REFLEN, "%s/mysqladmin", bin_dir); + snprintf(master_pid, FN_REFLEN, "%s/var/run/master.pid", mysql_test_dir); + snprintf(slave_pid, FN_REFLEN, "%s/var/run/slave.pid", mysql_test_dir); #elif __WIN__ /* setup paths */ #ifdef _DEBUG - snprintf(bin_dir, PATH_MAX, "%s/client_debug", base_dir); + snprintf(bin_dir, FN_REFLEN, "%s/client_debug", base_dir); #else - snprintf(bin_dir, PATH_MAX, "%s/client_release", base_dir); + snprintf(bin_dir, FN_REFLEN, "%s/client_release", base_dir); #endif - snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); - snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); - snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); - snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); - snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); - snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); - snprintf(lang_dir, PATH_MAX, "%s/share/english", base_dir); - snprintf(char_dir, PATH_MAX, "%s/share/charsets", base_dir); + snprintf(mysql_test_dir, FN_REFLEN, "%s/mysql-test", base_dir); + snprintf(test_dir, FN_REFLEN, "%s/t", mysql_test_dir); + snprintf(mysql_tmp_dir, FN_REFLEN, "%s/var/tmp", mysql_test_dir); + snprintf(result_dir, FN_REFLEN, "%s/r", mysql_test_dir); + snprintf(master_dir, FN_REFLEN, "%s/var/master-data", mysql_test_dir); + snprintf(slave_dir, FN_REFLEN, "%s/var/slave-data", mysql_test_dir); + snprintf(lang_dir, FN_REFLEN, "%s/share/english", base_dir); + snprintf(char_dir, FN_REFLEN, "%s/share/charsets", base_dir); #ifdef HAVE_OPENSSL use_openssl= TRUE; #endif /* HAVE_OPENSSL */ /* OpenSSL paths */ - snprintf(ca_cert, PATH_MAX, "%s/SSL/cacert.pem", base_dir); - snprintf(server_cert, PATH_MAX, "%s/SSL/server-cert.pem", base_dir); - snprintf(server_key, PATH_MAX, "%s/SSL/server-key.pem", base_dir); - snprintf(client_cert, PATH_MAX, "%s/SSL/client-cert.pem", base_dir); - snprintf(client_key, PATH_MAX, "%s/SSL/client-key.pem", base_dir); + snprintf(ca_cert, FN_REFLEN, "%s/SSL/cacert.pem", base_dir); + snprintf(server_cert, FN_REFLEN, "%s/SSL/server-cert.pem", base_dir); + snprintf(server_key, FN_REFLEN, "%s/SSL/server-key.pem", base_dir); + snprintf(client_cert, FN_REFLEN, "%s/SSL/client-cert.pem", base_dir); + snprintf(client_key, FN_REFLEN, "%s/SSL/client-key.pem", base_dir); /* setup files */ - snprintf(mysqld_file, PATH_MAX, "%s/mysqld.exe", bin_dir); - snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest.exe", bin_dir); - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin.exe", bin_dir); + snprintf(mysqld_file, FN_REFLEN, "%s/mysqld.exe", bin_dir); + snprintf(mysqltest_file, FN_REFLEN, "%s/mysqltest.exe", bin_dir); + snprintf(mysqladmin_file, FN_REFLEN, "%s/mysqladmin.exe", bin_dir); #else /* setup paths */ - snprintf(bin_dir, PATH_MAX, "%s/client", base_dir); - snprintf(mysql_test_dir, PATH_MAX, "%s/mysql-test", base_dir); - snprintf(test_dir, PATH_MAX, "%s/t", mysql_test_dir); - snprintf(mysql_tmp_dir, PATH_MAX, "%s/var/tmp", mysql_test_dir); - snprintf(result_dir, PATH_MAX, "%s/r", mysql_test_dir); - snprintf(master_dir, PATH_MAX, "%s/var/master-data", mysql_test_dir); - snprintf(slave_dir, PATH_MAX, "%s/var/slave-data", mysql_test_dir); - snprintf(lang_dir, PATH_MAX, "%s/sql/share/english", base_dir); - snprintf(char_dir, PATH_MAX, "%s/sql/share/charsets", base_dir); + snprintf(bin_dir, FN_REFLEN, "%s/client", base_dir); + snprintf(mysql_test_dir, FN_REFLEN, "%s/mysql-test", base_dir); + snprintf(test_dir, FN_REFLEN, "%s/t", mysql_test_dir); + snprintf(mysql_tmp_dir, FN_REFLEN, "%s/var/tmp", mysql_test_dir); + snprintf(result_dir, FN_REFLEN, "%s/r", mysql_test_dir); + snprintf(master_dir, FN_REFLEN, "%s/var/master-data", mysql_test_dir); + snprintf(slave_dir, FN_REFLEN, "%s/var/slave-data", mysql_test_dir); + snprintf(lang_dir, FN_REFLEN, "%s/sql/share/english", base_dir); + snprintf(char_dir, FN_REFLEN, "%s/sql/share/charsets", base_dir); #ifdef HAVE_OPENSSL use_openssl= TRUE; #endif /* HAVE_OPENSSL */ /* OpenSSL paths */ - snprintf(ca_cert, PATH_MAX, "%s/SSL/cacert.pem", base_dir); - snprintf(server_cert, PATH_MAX, "%s/SSL/server-cert.pem", base_dir); - snprintf(server_key, PATH_MAX, "%s/SSL/server-key.pem", base_dir); - snprintf(client_cert, PATH_MAX, "%s/SSL/client-cert.pem", base_dir); - snprintf(client_key, PATH_MAX, "%s/SSL/client-key.pem", base_dir); + snprintf(ca_cert, FN_REFLEN, "%s/SSL/cacert.pem", base_dir); + snprintf(server_cert, FN_REFLEN, "%s/SSL/server-cert.pem", base_dir); + snprintf(server_key, FN_REFLEN, "%s/SSL/server-key.pem", base_dir); + snprintf(client_cert, FN_REFLEN, "%s/SSL/client-cert.pem", base_dir); + snprintf(client_key, FN_REFLEN, "%s/SSL/client-key.pem", base_dir); /* setup files */ - snprintf(mysqld_file, PATH_MAX, "%s/sql/mysqld", base_dir); - snprintf(mysqltest_file, PATH_MAX, "%s/mysqltest", bin_dir); - snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); - snprintf(master_pid, PATH_MAX, "%s/var/run/master.pid", mysql_test_dir); - snprintf(slave_pid, PATH_MAX, "%s/var/run/slave.pid", mysql_test_dir); + snprintf(mysqld_file, FN_REFLEN, "%s/sql/mysqld", base_dir); + snprintf(mysqltest_file, FN_REFLEN, "%s/mysqltest", bin_dir); + snprintf(mysqladmin_file, FN_REFLEN, "%s/mysqladmin", bin_dir); + snprintf(master_pid, FN_REFLEN, "%s/var/run/master.pid", mysql_test_dir); + snprintf(slave_pid, FN_REFLEN, "%s/var/run/slave.pid", mysql_test_dir); - snprintf(master_socket,PATH_MAX, "%s/var/tmp/master.sock", mysql_test_dir); - snprintf(slave_socket,PATH_MAX, "%s/var/tmp/slave.sock", mysql_test_dir); + snprintf(master_socket,FN_REFLEN, "%s/var/tmp/master.sock", mysql_test_dir); + snprintf(slave_socket,FN_REFLEN, "%s/var/tmp/slave.sock", mysql_test_dir); #endif /* create log file */ - snprintf(temp, PATH_MAX, "%s/mysql-test-run.log", mysql_test_dir); + snprintf(temp, FN_REFLEN, "%s/mysql-test-run.log", mysql_test_dir); if ((log_fd= fopen(temp, "w+")) == NULL) { log_errno("Unable to create log file."); @@ -1386,46 +1386,47 @@ void setup(char *file __attribute__((unused))) /* prepare skip test list */ while ((p= strchr(skip_test, ',')) != NULL) *p= ' '; strcpy(temp, strlwr(skip_test)); - snprintf(skip_test, PATH_MAX, " %s ", temp); + snprintf(skip_test, FN_REFLEN, " %s ", temp); /* environment */ #ifdef __NETWARE__ setenv("MYSQL_TEST_DIR", mysql_test_dir, 1); - snprintf(file_path, PATH_MAX*2, + snprintf(file_path, FN_REFLEN*2, "%s/client/mysqldump --no-defaults -u root --port=%u", bin_dir, master_port); setenv("MYSQL_DUMP", file_path, 1); - snprintf(file_path, PATH_MAX*2, + snprintf(file_path, FN_REFLEN*2, "%s/client/mysqlbinlog --no-defaults --local-load=%s", bin_dir, mysql_tmp_dir); setenv("MYSQL_BINLOG", file_path, 1); #elif __WIN__ - snprintf(file_path,MAX_PATH,"MYSQL_TEST_DIR=%s",mysql_test_dir); + snprintf(file_path,FN_REFLEN,"MYSQL_TEST_DIR=%s",mysql_test_dir); _putenv(file_path); - snprintf(file_path, PATH_MAX*2, + snprintf(file_path, FN_REFLEN*2, "MYSQL_DUMP=%s/mysqldump.exe --no-defaults -u root --port=%u", bin_dir, master_port); _putenv(file_path); - snprintf(file_path, PATH_MAX*2, + snprintf(file_path, FN_REFLEN*2, "MYSQL_BINLOG=%s/mysqlbinlog.exe --no-defaults --local-load=%s", bin_dir, mysql_tmp_dir); _putenv(file_path); #else - setenv("MYSQL_TEST_DIR", mysql_test_dir, 1); - snprintf(file_path, PATH_MAX*2, - "%s/mysqldump --no-defaults -u root --port=%u --socket=%s", + snprintf(file_path,FN_REFLEN,"MYSQL_TEST_DIR=%s",mysql_test_dir); + putenv(file_path); + snprintf(file_path, FN_REFLEN*2, + "MYSQL_DUMP=%s/mysqldump --no-defaults -u root --port=%u --socket=%s", bin_dir, master_port, master_socket); - setenv("MYSQL_DUMP", file_path, 1); - snprintf(file_path, PATH_MAX*2, - "%s/mysqlbinlog --no-defaults --local-load=%s", + putenv(file_path); + snprintf(file_path, FN_REFLEN*2, + "MYSQL_BINLOG=%s/mysqlbinlog --no-defaults --local-load=%s", bin_dir, mysql_tmp_dir); - setenv("MYSQL_BINLOG", file_path, 1); + putenv(file_path); #endif #ifndef __WIN__ - setenv("MASTER_MYPORT", "9306", 1); - setenv("SLAVE_MYPORT", "9307", 1); - setenv("MYSQL_TCP_PORT", "3306", 1); + putenv((char *)"MASTER_MYPORT=9306"); + putenv((char *)"SLAVE_MYPORT=9307"); + putenv((char *)"MYSQL_TCP_PORT=3306"); #else _putenv("MASTER_MYPORT=9306"); _putenv("SLAVE_MYPORT=9307"); @@ -1461,7 +1462,7 @@ int main(int argc, char **argv) temp= strdup(strchr(argv[1],'=') + 1); for (token=str_tok(temp, ","); token != NULL; token=str_tok(NULL, ",")) { - if (strlen(ignore_test) + strlen(token) + 2 <= PATH_MAX-1) + if (strlen(ignore_test) + strlen(token) + 2 <= FN_REFLEN-1) sprintf(ignore_test+strlen(ignore_test), " %s ", token); else { @@ -1507,38 +1508,35 @@ int main(int argc, char **argv) { /* run all tests */ #ifndef __WIN__ - struct dirent **namelist; - int i,n; - char test[NAME_MAX]; - char *p; + struct dirent *entry; + DIR *parent; + char test[FN_LEN]; int position; - n= scandir(test_dir, &namelist, 0, alphasort); - if (n < 0) + /* FIXME are we sure the list is sorted if using readdir()? */ + if ((parent= opendir(test_dir)) == NULL) /* Not thread safe */ die("Unable to open tests directory."); else { - for (i= 0; i < n; i++) + while ((entry= readdir(parent)) != NULL) /* Not thread safe */ { - strcpy(test, strlwr(namelist[i]->d_name)); + strcpy(test, strlwr(entry->d_name)); /* find the test suffix */ if ((position= strinstr(test, TEST_SUFFIX)) != 0) { - p= test + position - 1; /* null terminate at the suffix */ - *p= 0; + *(test + position - 1)= '\0'; /* run test */ run_test(test); } - free(namelist[n]); } - free(namelist); + closedir(parent); } #else struct _finddata_t dir; intptr_t handle; - char test[NAME_MAX]; - char mask[PATH_MAX]; + char test[FN_LEN]; + char mask[FN_REFLEN]; char *p; int position; char **names= 0; @@ -1549,7 +1547,7 @@ int main(int argc, char **argv) /* single test */ single_test= FALSE; - snprintf(mask,MAX_PATH,"%s/*.test",test_dir); + snprintf(mask,FN_REFLEN,"%s/*.test",test_dir); if ((handle=_findfirst(mask,&dir)) == -1L) { @@ -1574,7 +1572,7 @@ int main(int argc, char **argv) *p= 0; /* insert test */ - *names= malloc(PATH_MAX); + *names= malloc(FN_REFLEN); strcpy(*names,test); names++; name_index++; From 761bee86479291ddf7d9cd347cc409f582800a94 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Tue, 9 Nov 2004 19:39:29 +0000 Subject: [PATCH 38/94] added management function to purge stale sessions in the management server --- ndb/include/mgmapi/mgmapi.h | 1 + ndb/include/util/Bitmask.hpp | 34 +++++++++ ndb/include/util/SocketServer.hpp | 4 +- ndb/src/common/util/SocketServer.cpp | 15 +++- ndb/src/mgmapi/mgmapi.cpp | 42 +++++++++++ ndb/src/mgmclient/CommandInterpreter.cpp | 46 +++++++++++++ ndb/src/mgmsrv/MgmtSrvr.cpp | 88 +++++++++++++++++++++--- ndb/src/mgmsrv/MgmtSrvr.hpp | 11 ++- ndb/src/mgmsrv/Services.cpp | 42 +++++++++++ ndb/src/mgmsrv/Services.hpp | 6 +- ndb/src/mgmsrv/main.cpp | 3 +- 11 files changed, 274 insertions(+), 18 deletions(-) diff --git a/ndb/include/mgmapi/mgmapi.h b/ndb/include/mgmapi/mgmapi.h index 6dcf58b44e2..f1ef357421b 100644 --- a/ndb/include/mgmapi/mgmapi.h +++ b/ndb/include/mgmapi/mgmapi.h @@ -733,6 +733,7 @@ extern "C" { int param, unsigned long long * value); int ndb_mgm_get_string_parameter(const ndb_mgm_configuration_iterator*, int param, const char ** value); + int ndb_mgm_purge_stale_sessions(NdbMgmHandle handle, char **); #ifdef __cplusplus } #endif diff --git a/ndb/include/util/Bitmask.hpp b/ndb/include/util/Bitmask.hpp index bb217adab5f..19aa604e4a1 100644 --- a/ndb/include/util/Bitmask.hpp +++ b/ndb/include/util/Bitmask.hpp @@ -104,6 +104,11 @@ public: */ static void bitXOR(unsigned size, Uint32 data[], const Uint32 data2[]); + /** + * bitXORC - Bitwise (x ^ ~y) into first operand. + */ + static void bitXORC(unsigned size, Uint32 data[], const Uint32 data2[]); + /** * contains - Check if all bits set in data2 are set in data */ @@ -261,6 +266,14 @@ BitmaskImpl::bitXOR(unsigned size, Uint32 data[], const Uint32 data2[]) } } +inline void +BitmaskImpl::bitXORC(unsigned size, Uint32 data[], const Uint32 data2[]) +{ + for (unsigned i = 0; i < size; i++) { + data[i] ^= ~data2[i]; + } +} + inline bool BitmaskImpl::contains(unsigned size, Uint32 data[], const Uint32 data2[]) { @@ -451,6 +464,12 @@ public: static void bitXOR(Uint32 data[], const Uint32 data2[]); BitmaskPOD& bitXOR(const BitmaskPOD& mask2); + /** + * bitXORC - Bitwise (x ^ ~y) into first operand. + */ + static void bitXORC(Uint32 data[], const Uint32 data2[]); + BitmaskPOD& bitXORC(const BitmaskPOD& mask2); + /** * contains - Check if all bits set in data2 (that) are also set in data (this) */ @@ -712,6 +731,21 @@ BitmaskPOD::bitXOR(const BitmaskPOD& mask2) return *this; } +template +inline void +BitmaskPOD::bitXORC(Uint32 data[], const Uint32 data2[]) +{ + BitmaskImpl::bitXORC(size,data, data2); +} + +template +inline BitmaskPOD& +BitmaskPOD::bitXORC(const BitmaskPOD& mask2) +{ + BitmaskPOD::bitXORC(rep.data, mask2.rep.data); + return *this; +} + template char * BitmaskPOD::getText(const Uint32 data[], char* buf) diff --git a/ndb/include/util/SocketServer.hpp b/ndb/include/util/SocketServer.hpp index 3860b9ca84b..2fad991e5f8 100644 --- a/ndb/include/util/SocketServer.hpp +++ b/ndb/include/util/SocketServer.hpp @@ -37,7 +37,7 @@ public: public: virtual ~Session() {} virtual void runSession(){} - virtual void stopSession(){} + virtual void stopSession(){ m_stop = true; } protected: friend class SocketServer; friend void* sessionThread_C(void*); @@ -98,6 +98,8 @@ public: */ void stopSessions(bool wait = false); + void foreachSession(void (*f)(SocketServer::Session*, void*), void *data); + private: struct SessionInstance { Service * m_service; diff --git a/ndb/src/common/util/SocketServer.cpp b/ndb/src/common/util/SocketServer.cpp index c3cffa1399b..8bee256684d 100644 --- a/ndb/src/common/util/SocketServer.cpp +++ b/ndb/src/common/util/SocketServer.cpp @@ -258,6 +258,15 @@ transfer(NDB_SOCKET_TYPE sock){ return true; } +void +SocketServer::foreachSession(void (*func)(SocketServer::Session*, void *), void *data) +{ + for(int i = m_sessions.size() - 1; i >= 0; i--){ + (*func)(m_sessions[i].m_session, data); + } + checkSessions(); +} + void SocketServer::checkSessions(){ for(int i = m_sessions.size() - 1; i >= 0; i--){ @@ -278,8 +287,10 @@ void SocketServer::stopSessions(bool wait){ int i; for(i = m_sessions.size() - 1; i>=0; i--) - m_sessions[i].m_session->m_stop = true; - + { + m_sessions[i].m_session->stopSession(); + m_sessions[i].m_session->m_stop = true; // to make sure + } for(i = m_services.size() - 1; i>=0; i--) m_services[i].m_service->stopSessions(); diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 4b62df968b3..66f0dbb1842 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -1834,4 +1834,46 @@ ndb_mgm_set_string_parameter(NdbMgmHandle handle, return res; } +extern "C" +int +ndb_mgm_purge_stale_sessions(NdbMgmHandle handle, char **purged){ + CHECK_HANDLE(handle, 0); + CHECK_CONNECTED(handle, 0); + + Properties args; + + const ParserRow reply[]= { + MGM_CMD("purge stale sessions reply", NULL, ""), + MGM_ARG("purged", String, Optional, ""), + MGM_ARG("result", String, Mandatory, "Error message"), + MGM_END() + }; + + const Properties *prop; + prop= ndb_mgm_call(handle, reply, "purge stale sessions", &args); + + if(prop == NULL) { + SET_ERROR(handle, EIO, "Unable to purge stale sessions"); + return -1; + } + + int res= -1; + do { + const char * buf; + if(!prop->get("result", &buf) || strcmp(buf, "Ok") != 0){ + ndbout_c("ERROR Message: %s\n", buf); + break; + } + if (purged) { + if (prop->get("purged", &buf)) + *purged= strdup(buf); + else + *purged= 0; + } + res= 0; + } while(0); + delete prop; + return res; +} + template class Vector*>; diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index e802ffff5ce..523c271ed9e 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -106,6 +106,7 @@ private: */ void executeHelp(char* parameters); void executeShow(char* parameters); + void executePurge(char* parameters); void executeShutdown(char* parameters); void executeRun(char* parameters); void executeInfo(char* parameters); @@ -264,6 +265,7 @@ static const char* helpText = #ifdef HAVE_GLOBAL_REPLICATION "REP CONNECT Connect to REP server on host:port\n" #endif +"PURGE STALE SESSIONS Reset reserved nodeid's in the mgmt server\n" "QUIT Quit management client\n" ; @@ -541,6 +543,10 @@ CommandInterpreter::execute(const char *_line, int _try_reconnect) executeAbortBackup(allAfterFirstToken); return true; } + else if (strcmp(firstToken, "PURGE") == 0) { + executePurge(allAfterFirstToken); + return true; + } #ifdef HAVE_GLOBAL_REPLICATION else if(strcmp(firstToken, "REPLICATION") == 0 || strcmp(firstToken, "REP") == 0) { @@ -982,6 +988,46 @@ print_nodes(ndb_mgm_cluster_state *state, ndb_mgm_configuration_iterator *it, ndbout << endl; } +void +CommandInterpreter::executePurge(char* parameters) +{ + int command_ok= 0; + do { + if (emptyString(parameters)) + break; + char* firstToken = strtok(parameters, " "); + char* nextToken = strtok(NULL, " \0"); + if (strcmp(firstToken,"STALE") == 0 && + nextToken && + strcmp(nextToken, "SESSIONS") == 0) { + command_ok= 1; + break; + } + } while(0); + + if (!command_ok) { + ndbout_c("Unexpected command, expected: PURGE STALE SESSIONS"); + return; + } + + int i; + char *str; + connect(); + + if (ndb_mgm_purge_stale_sessions(m_mgmsrv, &str)) { + ndbout_c("Command failed"); + return; + } + if (str) { + ndbout_c("Purged sessions with node id's: %s", str); + free(str); + } + else + { + ndbout_c("No sessions purged"); + } +} + void CommandInterpreter::executeShow(char* parameters) { diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index 2e30d73290b..a49b29af275 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -400,11 +400,13 @@ MgmtSrvr::getPort() const { /* Constructor */ MgmtSrvr::MgmtSrvr(NodeId nodeId, + SocketServer *socket_server, const BaseString &configFilename, LocalConfig &local_config, Config * config): _blockNumber(1), // Hard coded block number since it makes it easy to send // signals to other management servers. + m_socket_server(socket_server), _ownReference(0), m_local_config(local_config), theSignalIdleList(NULL), @@ -2094,6 +2096,25 @@ MgmtSrvr::getNodeType(NodeId nodeId) const return nodeTypes[nodeId]; } +void +MgmtSrvr::get_connected_nodes(NodeBitmask &connected_nodes) const +{ + if (theFacade && theFacade->theClusterMgr) + { + for(Uint32 i = 0; i < MAX_NODES; i++) + { + if (getNodeType(i) == NDB_MGM_NODE_TYPE_NDB) + { + const ClusterMgr::Node &node= theFacade->theClusterMgr->getNodeInfo(i); + if (node.connected) + { + connected_nodes.bitOR(node.m_state.m_connected_nodes); + } + } + } + } +} + bool MgmtSrvr::alloc_node_id(NodeId * nodeId, enum ndb_mgm_node_type type, @@ -2106,7 +2127,7 @@ MgmtSrvr::alloc_node_id(NodeId * nodeId, *nodeId, type, client_addr)); if (g_no_nodeid_checks) { if (*nodeId == 0) { - error_string.appfmt("no-nodeid-ckecks set in manegment server.\n" + error_string.appfmt("no-nodeid-checks set in management server.\n" "node id must be set explicitly in connectstring"); DBUG_RETURN(false); } @@ -2115,16 +2136,11 @@ MgmtSrvr::alloc_node_id(NodeId * nodeId, Guard g(m_node_id_mutex); int no_mgm= 0; NodeBitmask connected_nodes(m_reserved_nodes); - for(Uint32 i = 0; i < MAX_NODES; i++) + get_connected_nodes(connected_nodes); { - if (getNodeType(i) == NDB_MGM_NODE_TYPE_NDB && - theFacade && theFacade->theClusterMgr) { - const ClusterMgr::Node &node= theFacade->theClusterMgr->getNodeInfo(i); - if (node.connected) { - connected_nodes.bitOR(node.m_state.m_connected_nodes); - } - } else if (getNodeType(i) == NDB_MGM_NODE_TYPE_MGM) - no_mgm++; + for(Uint32 i = 0; i < MAX_NODES; i++) + if (getNodeType(i) == NDB_MGM_NODE_TYPE_MGM) + no_mgm++; } bool found_matching_id= false; bool found_matching_type= false; @@ -2227,6 +2243,10 @@ MgmtSrvr::alloc_node_id(NodeId * nodeId, m_connect_address[id_found].s_addr= 0; } m_reserved_nodes.set(id_found); + char tmp_str[128]; + m_reserved_nodes.getText(tmp_str); + g_EventLogger.info("Mgmt server state: nodeid %d reserved for ip %s, m_reserved_nodes %s.", + id_found, get_connect_address(id_found), tmp_str); DBUG_RETURN(true); } @@ -2283,6 +2303,36 @@ MgmtSrvr::alloc_node_id(NodeId * nodeId, error_string.appfmt("No node defined with id=%d in config file.", *nodeId); } + + g_EventLogger.warning("Allocate nodeid (%d) failed. Connection from ip %s. " + "Returned error string \"%s\"", + *nodeId, + client_addr != 0 ? inet_ntoa(((struct sockaddr_in *)(client_addr))->sin_addr) : "", + error_string.c_str()); + + NodeBitmask connected_nodes2; + get_connected_nodes(connected_nodes2); + { + BaseString tmp_connected, tmp_not_connected; + for(Uint32 i = 0; i < MAX_NODES; i++) + { + if (connected_nodes2.get(i)) + { + if (!m_reserved_nodes.get(i)) + tmp_connected.appfmt(" %d", i); + } + else if (m_reserved_nodes.get(i)) + { + tmp_not_connected.appfmt(" %d", i); + } + } + if (tmp_connected.length() > 0) + g_EventLogger.info("Mgmt server state: node id's %s connected but not reserved", + tmp_connected.c_str()); + if (tmp_not_connected.length() > 0) + g_EventLogger.info("Mgmt server state: node id's %s not connected but reserved", + tmp_not_connected.c_str()); + } DBUG_RETURN(false); } @@ -2531,10 +2581,15 @@ MgmtSrvr::Allocated_resources::~Allocated_resources() { Guard g(m_mgmsrv.m_node_id_mutex); if (!m_reserved_nodes.isclear()) { + m_mgmsrv.m_reserved_nodes.bitANDC(m_reserved_nodes); // node has been reserved, force update signal to ndb nodes global_flag_send_heartbeat_now= 1; + + char tmp_str[128]; + m_mgmsrv.m_reserved_nodes.getText(tmp_str); + g_EventLogger.info("Mgmt server state: nodeid %d freed, m_reserved_nodes %s.", + get_nodeid(), tmp_str); } - m_mgmsrv.m_reserved_nodes.bitANDC(m_reserved_nodes); } void @@ -2543,6 +2598,17 @@ MgmtSrvr::Allocated_resources::reserve_node(NodeId id) m_reserved_nodes.set(id); } +NodeId +MgmtSrvr::Allocated_resources::get_nodeid() const +{ + for(Uint32 i = 0; i < MAX_NODES; i++) + { + if (m_reserved_nodes.get(i)) + return i; + } + return 0; +} + int MgmtSrvr::setDbParameter(int node, int param, const char * value, BaseString& msg){ diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp index c796e1e9219..b3257491123 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.hpp +++ b/ndb/src/mgmsrv/MgmtSrvr.hpp @@ -96,7 +96,10 @@ public: // methods to reserve/allocate resources which // will be freed when running destructor void reserve_node(NodeId id); - bool is_reserved(NodeId nodeId) { return m_reserved_nodes.get(nodeId);} + bool is_reserved(NodeId nodeId) { return m_reserved_nodes.get(nodeId); } + bool is_reserved(NodeBitmask mask) { return !mask.bitAND(m_reserved_nodes).isclear(); } + bool isclear() { return m_reserved_nodes.isclear(); } + NodeId get_nodeid() const; private: MgmtSrvr &m_mgmsrv; NodeBitmask m_reserved_nodes; @@ -173,6 +176,7 @@ public: /* Constructor */ MgmtSrvr(NodeId nodeId, /* Local nodeid */ + SocketServer *socket_server, const BaseString &config_filename, /* Where to save config */ LocalConfig &local_config, /* Ndb.cfg filename */ Config * config); @@ -499,6 +503,9 @@ public: int setDbParameter(int node, int parameter, const char * value, BaseString&); const char *get_connect_address(Uint32 node_id) { return inet_ntoa(m_connect_address[node_id]); } + void get_connected_nodes(NodeBitmask &connected_nodes) const; + SocketServer *get_socket_server() { return m_socket_server; } + //************************************************************************** private: //************************************************************************** @@ -525,6 +532,8 @@ private: int _blockNumber; NodeId _ownNodeId; + SocketServer *m_socket_server; + BlockReference _ownReference; NdbMutex *m_configMutex; const Config * _config; diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp index 2672d8c9d4b..0394c4e80bb 100644 --- a/ndb/src/mgmsrv/Services.cpp +++ b/ndb/src/mgmsrv/Services.cpp @@ -242,6 +242,8 @@ ParserRow commands[] = { MGM_ARG("node", Int, Optional, "Node"), MGM_ARG("filter", String, Mandatory, "Event category"), + MGM_CMD("purge stale sessions", &MgmApiSession::purge_stale_sessions, ""), + MGM_END() }; @@ -1412,6 +1414,46 @@ done: m_output->println(""); } +struct PurgeStruct +{ + NodeBitmask free_nodes;/* free nodes as reported + * by ndbd in apiRegReqConf + */ + BaseString *str; +}; + +void +MgmApiSession::stop_session_if_not_connected(SocketServer::Session *_s, void *data) +{ + MgmApiSession *s= (MgmApiSession *)_s; + struct PurgeStruct &ps= *(struct PurgeStruct *)data; + if (s->m_allocated_resources->is_reserved(ps.free_nodes)) + { + ps.str->appfmt(" %d", s->m_allocated_resources->get_nodeid()); + s->stopSession(); + } +} + +void +MgmApiSession::purge_stale_sessions(Parser_t::Context &ctx, + const class Properties &args) +{ + struct PurgeStruct ps; + BaseString str; + ps.str = &str; + + m_mgmsrv.get_connected_nodes(ps.free_nodes); + ps.free_nodes.bitXORC(NodeBitmask()); // invert connected_nodes to get free nodes + + m_mgmsrv.get_socket_server()->foreachSession(stop_session_if_not_connected,&ps); + + m_output->println("purge stale sessions reply"); + if (str.length() > 0) + m_output->println("purged:%s",str.c_str()); + m_output->println("result: Ok"); + m_output->println(""); +} + template class MutexVector; template class Vector const*>; template class Vector; diff --git a/ndb/src/mgmsrv/Services.hpp b/ndb/src/mgmsrv/Services.hpp index e47820826b6..bfc915f18f1 100644 --- a/ndb/src/mgmsrv/Services.hpp +++ b/ndb/src/mgmsrv/Services.hpp @@ -28,7 +28,9 @@ /** Undefine this to remove backwards compatibility for "GET CONFIG". */ #define MGM_GET_CONFIG_BACKWARDS_COMPAT -class MgmApiSession : public SocketServer::Session { +class MgmApiSession : public SocketServer::Session +{ + static void stop_session_if_not_connected(SocketServer::Session *_s, void *data); private: typedef Parser Parser_t; @@ -84,6 +86,8 @@ public: void setParameter(Parser_t::Context &ctx, const class Properties &args); void listen_event(Parser_t::Context &ctx, const class Properties &args); + + void purge_stale_sessions(Parser_t::Context &ctx, const class Properties &args); void repCommand(Parser_t::Context &ctx, const class Properties &args); }; diff --git a/ndb/src/mgmsrv/main.cpp b/ndb/src/mgmsrv/main.cpp index 15767e4766d..7a57fdeb77a 100644 --- a/ndb/src/mgmsrv/main.cpp +++ b/ndb/src/mgmsrv/main.cpp @@ -83,7 +83,6 @@ struct MgmGlobals { int g_no_nodeid_checks= 0; static MgmGlobals glob; - /****************************************************************************** * Function prototypes ******************************************************************************/ @@ -226,7 +225,7 @@ int main(int argc, char** argv) if (!readGlobalConfig()) goto error_end; - glob.mgmObject = new MgmtSrvr(glob.localNodeId, + glob.mgmObject = new MgmtSrvr(glob.localNodeId, glob.socketServer, BaseString(glob.config_filename), local_config, glob.cluster_config); From aeafd88e195113439f07c7ffc9cfb30343401370 Mon Sep 17 00:00:00 2001 From: "joreland@mysql.com" <> Date: Wed, 10 Nov 2004 11:02:51 +0100 Subject: [PATCH 39/94] bug#6538 ndb: Fix return value in index_last wo/ rows --- sql/ha_ndbcluster.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 0d2b1676e3a..5971c1a6c2a 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2318,7 +2318,7 @@ int ha_ndbcluster::index_last(byte *buf) DBUG_RETURN(0); } } - DBUG_RETURN(1); + DBUG_RETURN(res); } From ee3e815e3baea0ca91d46a8b4cc0382d06856238 Mon Sep 17 00:00:00 2001 From: "wax@kishkin.ru" <> Date: Wed, 10 Nov 2004 15:03:59 +0500 Subject: [PATCH 40/94] replaced init_db.sql --- mysql-test/init_db.sql | 54 +++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/mysql-test/init_db.sql b/mysql-test/init_db.sql index 4613e5c0274..63483af00d6 100644 --- a/mysql-test/init_db.sql +++ b/mysql-test/init_db.sql @@ -3,24 +3,56 @@ CREATE DATABASE test; USE mysql; -CREATE TABLE db (Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, References_priv enum('N','Y') DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User)) comment='Database privileges'; +CREATE TABLE db (Host char(60) binary DEFAULT '' NOT NULL,Db char(64) binary DEFAULT '' NOT NULL,User char(16) binary DEFAULT '' NOT NULL,Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,References_priv enum('N','Y') DEFAULT 'N' NOT NULL,Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,PRIMARY KEY Host (Host,Db,User),KEY User (User)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; + INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y'); - -CREATE TABLE host (Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, References_priv enum('N','Y') DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db)) comment='Host privileges; Merged with database privileges'; -CREATE TABLE user (Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(45) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') DEFAULT 'N' NOT NULL, File_priv enum('N','Y') DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL, References_priv enum('N','Y') DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User)) comment='Users and global privileges'; -INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); -INSERT INTO user VALUES ('','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); +CREATE TABLE host (Host char(60) binary DEFAULT '' NOT NULL,Db char(64) binary DEFAULT '' NOT NULL,Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,References_priv enum('N','Y') DEFAULT 'N' NOT NULL,Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,PRIMARY KEY Host (Host,Db)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; -INSERT INTO user (host,user) values ('localhost',''); -INSERT INTO user (host,user) values ('',''); +CREATE TABLE user (Host char(60) binary DEFAULT '' NOT NULL,User char(16) binary DEFAULT '' NOT NULL,Password char(41) binary DEFAULT '' NOT NULL,Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,File_priv enum('N','Y') DEFAULT 'N' NOT NULL,Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,References_priv enum('N','Y') DEFAULT 'N' NOT NULL,Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL,Super_priv enum('N','Y') DEFAULT 'N' NOT NULL,Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL,Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL,Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL,Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL,Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL,ssl_type enum('','ANY','X509', 'SPECIFIED') DEFAULT '' NOT NULL,ssl_cipher BLOB NOT NULL,x509_issuer BLOB NOT NULL,x509_subject BLOB NOT NULL,max_questions int(11) unsigned DEFAULT 0 NOT NULL,max_updates int(11) unsigned DEFAULT 0 NOT NULL,max_connections int(11) unsigned DEFAULT 0 NOT NULL,PRIMARY KEY Host (Host,User)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; -CREATE TABLE func (name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') NOT NULL, PRIMARY KEY (name)) comment='User defined functions'; +INSERT INTO user VALUES ('%','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); +INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); +INSERT INTO user VALUES ('%','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0); -CREATE TABLE tables_priv (Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(60) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp(14), Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor)) comment='Table privileges'; +CREATE TABLE func (name char(64) binary DEFAULT '' NOT NULL,ret tinyint(1) DEFAULT '0' NOT NULL,dl char(128) DEFAULT '' NOT NULL,type enum ('function','aggregate') NOT NULL,PRIMARY KEY (name)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; + +CREATE TABLE tables_priv (Host char(60) binary DEFAULT '' NOT NULL,Db char(64) binary DEFAULT '' NOT NULL,User char(16) binary DEFAULT '' NOT NULL,Table_name char(64) binary DEFAULT '' NOT NULL,Grantor char(77) DEFAULT '' NOT NULL,Timestamp timestamp(14),Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,PRIMARY KEY (Host,Db,User,Table_name),KEY Grantor (Grantor)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges'; + +CREATE TABLE columns_priv (Host char(60) binary DEFAULT '' NOT NULL,Db char(64) binary DEFAULT '' NOT NULL,User char(16) binary DEFAULT '' NOT NULL,Table_name char(64) binary DEFAULT '' NOT NULL,Column_name char(64) binary DEFAULT '' NOT NULL,Timestamp timestamp(14),Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,PRIMARY KEY (Host,Db,User,Table_name,Column_name)) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges'; + +CREATE TABLE help_topic (help_topic_id int unsigned not null,name varchar(64) not null,help_category_id smallint unsigned not null,description text not null,example text not null,url varchar(128) not null,primary key (help_topic_id),unique index (name)) engine=MyISAM CHARACTER SET utf8 comment='help topics'; + +CREATE TABLE help_category (help_category_id smallint unsigned not null,name varchar(64) not null,parent_category_id smallint unsigned null,url varchar(128) not null,primary key (help_category_id),unique index (name)) engine=MyISAM CHARACTER SET utf8 comment='help categories'; + +CREATE TABLE help_keyword (help_keyword_id int unsigned not null,name varchar(64) not null,primary key (help_keyword_id),unique index (name)) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; + +CREATE TABLE help_relation (help_topic_id int unsigned not null references help_topic,help_keyword_id int unsigned not null references help_keyword,primary key (help_keyword_id, help_topic_id)) engine=MyISAM CHARACTER SET utf8 comment='keyword-topic relation'; + +CREATE TABLE time_zone_name (Name char(64) NOT NULL,Time_zone_id int unsigned NOT NULL,PRIMARY KEY Name (Name)) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; + +INSERT INTO time_zone_name (Name, Time_Zone_id) VALUES ('MET', 1), ('UTC', 2), ('Universal', 2), ('Europe/Moscow',3), ('leap/Europe/Moscow',4), ('Japan', 5); + + +CREATE TABLE time_zone (Time_zone_id int unsigned NOT NULL auto_increment,Use_leap_seconds enum('Y','N') DEFAULT 'N' NOT NULL,PRIMARY KEY TzId (Time_zone_id)) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; + +INSERT INTO time_zone (Time_zone_id, Use_leap_seconds) VALUES (1,'N'), (2,'N'), (3,'N'), (4,'Y'), (5,'N'); + + +CREATE TABLE time_zone_transition (Time_zone_id int unsigned NOT NULL,Transition_time bigint signed NOT NULL,Transition_type_id int unsigned NOT NULL,PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time)) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; + +INSERT INTO time_zone_transition (Time_zone_id, Transition_time, Transition_type_id) VALUES (1, -1693706400, 0) ,(1, -1680483600, 1),(1, -1663455600, 2) ,(1, -1650150000, 3),(1, -1632006000, 2) ,(1, -1618700400, 3),(1, -938905200, 2) ,(1, -857257200, 3),(1, -844556400, 2) ,(1, -828226800, 3),(1, -812502000, 2) ,(1, -796777200, 3),(1, 228877200, 2) ,(1, 243997200, 3),(1, 260326800, 2) ,(1, 276051600, 3),(1, 291776400, 2) ,(1, 307501200, 3),(1, 323830800, 2) ,(1, 338950800, 3),(1, 354675600, 2) ,(1, 370400400, 3),(1, 386125200, 2) ,(1, 401850000, 3),(1, 417574800, 2) ,(1, 433299600, 3),(1, 449024400, 2) ,(1, 465354000, 3),(1, 481078800, 2) ,(1, 496803600, 3),(1, 512528400, 2) ,(1, 528253200, 3),(1, 543978000, 2) ,(1, 559702800, 3),(1, 575427600, 2) ,(1, 591152400, 3),(1, 606877200, 2) ,(1, 622602000, 3),(1, 638326800, 2) ,(1, 654656400, 3),(1, 670381200, 2) ,(1, 686106000, 3),(1, 701830800, 2) ,(1, 717555600, 3),(1, 733280400, 2) ,(1, 749005200, 3),(1, 764730000, 2) ,(1, 780454800, 3),(1, 796179600, 2) ,(1, 811904400, 3),(1, 828234000, 2) ,(1, 846378000, 3),(1, 859683600, 2) ,(1, 877827600, 3),(1, 891133200, 2) ,(1, 909277200, 3),(1, 922582800, 2) ,(1, 941331600, 3),(1, 954032400, 2) ,(1, 972781200, 3),(1, 985482000, 2) ,(1, 1004230800, 3),(1, 1017536400, 2) ,(1, 1035680400, 3),(1, 1048986000, 2) ,(1, 1067130000, 3),(1, 1080435600, 2) ,(1, 1099184400, 3),(1, 1111885200, 2) ,(1, 1130634000, 3),(1, 1143334800, 2) ,(1, 1162083600, 3),(1, 1174784400, 2) ,(1, 1193533200, 3),(1, 1206838800, 2) ,(1, 1224982800, 3),(1, 1238288400, 2) ,(1, 1256432400, 3),(1, 1269738000, 2) ,(1, 1288486800, 3),(1, 1301187600, 2) ,(1, 1319936400, 3),(1, 1332637200, 2) ,(1, 1351386000, 3),(1, 1364691600, 2) ,(1, 1382835600, 3),(1, 1396141200, 2) ,(1, 1414285200, 3),(1, 1427590800, 2) ,(1, 1445734800, 3),(1, 1459040400, 2) ,(1, 1477789200, 3),(1, 1490490000, 2) ,(1, 1509238800, 3),(1, 1521939600, 2) ,(1, 1540688400, 3),(1, 1553994000, 2) ,(1, 1572138000, 3),(1, 1585443600, 2) ,(1, 1603587600, 3),(1, 1616893200, 2) ,(1, 1635642000, 3),(1, 1648342800, 2) ,(1, 1667091600, 3),(1, 1679792400, 2) ,(1, 1698541200, 3),(1, 1711846800, 2) ,(1, 1729990800, 3),(1, 1743296400, 2) ,(1, 1761440400, 3),(1, 1774746000, 2) ,(1, 1792890000, 3),(1, 1806195600, 2) ,(1, 1824944400, 3),(1, 1837645200, 2) ,(1, 1856394000, 3),(1, 1869094800, 2) ,(1, 1887843600, 3),(1, 1901149200, 2) ,(1, 1919293200, 3),(1, 1932598800, 2) ,(1, 1950742800, 3),(1, 1964048400, 2) ,(1, 1982797200, 3),(1, 1995498000, 2) ,(1, 2014246800, 3),(1, 2026947600, 2) ,(1, 2045696400, 3),(1, 2058397200, 2) ,(1, 2077146000, 3),(1, 2090451600, 2) ,(1, 2108595600, 3),(1, 2121901200, 2) ,(1, 2140045200, 3),(3, -1688265000, 2) ,(3, -1656819048, 1),(3, -1641353448, 2) ,(3, -1627965048, 3),(3, -1618716648, 1) ,(3, -1596429048, 3),(3, -1593829848, 5) ,(3, -1589860800, 4),(3, -1542427200, 5) ,(3, -1539493200, 6),(3, -1525323600, 5) ,(3, -1522728000, 4),(3, -1491188400, 7) ,(3, -1247536800, 4),(3, 354920400, 5) ,(3, 370728000, 4),(3, 386456400, 5) ,(3, 402264000, 4),(3, 417992400, 5) ,(3, 433800000, 4),(3, 449614800, 5) ,(3, 465346800, 8),(3, 481071600, 9) ,(3, 496796400, 8),(3, 512521200, 9) ,(3, 528246000, 8),(3, 543970800, 9) ,(3, 559695600, 8),(3, 575420400, 9) ,(3, 591145200, 8),(3, 606870000, 9) ,(3, 622594800, 8),(3, 638319600, 9) ,(3, 654649200, 8),(3, 670374000, 10) ,(3, 686102400, 11),(3, 695779200, 8) ,(3, 701812800, 5),(3, 717534000, 4) ,(3, 733273200, 9),(3, 748998000, 8) ,(3, 764722800, 9),(3, 780447600, 8) ,(3, 796172400, 9),(3, 811897200, 8) ,(3, 828226800, 9),(3, 846370800, 8) ,(3, 859676400, 9),(3, 877820400, 8) ,(3, 891126000, 9),(3, 909270000, 8) ,(3, 922575600, 9),(3, 941324400, 8) ,(3, 954025200, 9),(3, 972774000, 8) ,(3, 985474800, 9),(3, 1004223600, 8) ,(3, 1017529200, 9),(3, 1035673200, 8) ,(3, 1048978800, 9),(3, 1067122800, 8) ,(3, 1080428400, 9),(3, 1099177200, 8) ,(3, 1111878000, 9),(3, 1130626800, 8) ,(3, 1143327600, 9),(3, 1162076400, 8) ,(3, 1174777200, 9),(3, 1193526000, 8) ,(3, 1206831600, 9),(3, 1224975600, 8) ,(3, 1238281200, 9),(3, 1256425200, 8) ,(3, 1269730800, 9),(3, 1288479600, 8) ,(3, 1301180400, 9),(3, 1319929200, 8) ,(3, 1332630000, 9),(3, 1351378800, 8) ,(3, 1364684400, 9),(3, 1382828400, 8) ,(3, 1396134000, 9),(3, 1414278000, 8) ,(3, 1427583600, 9),(3, 1445727600, 8) ,(3, 1459033200, 9),(3, 1477782000, 8) ,(3, 1490482800, 9),(3, 1509231600, 8) ,(3, 1521932400, 9),(3, 1540681200, 8) ,(3, 1553986800, 9),(3, 1572130800, 8) ,(3, 1585436400, 9),(3, 1603580400, 8) ,(3, 1616886000, 9),(3, 1635634800, 8) ,(3, 1648335600, 9),(3, 1667084400, 8) ,(3, 1679785200, 9),(3, 1698534000, 8) ,(3, 1711839600, 9),(3, 1729983600, 8) ,(3, 1743289200, 9),(3, 1761433200, 8) ,(3, 1774738800, 9),(3, 1792882800, 8) ,(3, 1806188400, 9),(3, 1824937200, 8) ,(3, 1837638000, 9),(3, 1856386800, 8) ,(3, 1869087600, 9),(3, 1887836400, 8) ,(3, 1901142000, 9),(3, 1919286000, 8) ,(3, 1932591600, 9),(3, 1950735600, 8) ,(3, 1964041200, 9),(3, 1982790000, 8) ,(3, 1995490800, 9),(3, 2014239600, 8) ,(3, 2026940400, 9),(3, 2045689200, 8) ,(3, 2058390000, 9),(3, 2077138800, 8) ,(3, 2090444400, 9),(3, 2108588400, 8) ,(3, 2121894000, 9),(3, 2140038000, 8),(4, -1688265000, 2) ,(4, -1656819048, 1),(4, -1641353448, 2) ,(4, -1627965048, 3),(4, -1618716648, 1) ,(4, -1596429048, 3),(4, -1593829848, 5) ,(4, -1589860800, 4),(4, -1542427200, 5) ,(4, -1539493200, 6),(4, -1525323600, 5) ,(4, -1522728000, 4),(4, -1491188400, 7) ,(4, -1247536800, 4),(4, 354920409, 5) ,(4, 370728010, 4),(4, 386456410, 5) ,(4, 402264011, 4),(4, 417992411, 5) ,(4, 433800012, 4),(4, 449614812, 5) ,(4, 465346812, 8),(4, 481071612, 9) ,(4, 496796413, 8),(4, 512521213, 9) ,(4, 528246013, 8),(4, 543970813, 9) ,(4, 559695613, 8),(4, 575420414, 9) ,(4, 591145214, 8),(4, 606870014, 9) ,(4, 622594814, 8),(4, 638319615, 9) ,(4, 654649215, 8),(4, 670374016, 10) ,(4, 686102416, 11),(4, 695779216, 8) ,(4, 701812816, 5),(4, 717534017, 4) ,(4, 733273217, 9),(4, 748998018, 8) ,(4, 764722818, 9),(4, 780447619, 8) ,(4, 796172419, 9),(4, 811897219, 8) ,(4, 828226820, 9),(4, 846370820, 8) ,(4, 859676420, 9),(4, 877820421, 8) ,(4, 891126021, 9),(4, 909270021, 8) ,(4, 922575622, 9),(4, 941324422, 8) ,(4, 954025222, 9),(4, 972774022, 8) ,(4, 985474822, 9),(4, 1004223622, 8) ,(4, 1017529222, 9),(4, 1035673222, 8) ,(4, 1048978822, 9),(4, 1067122822, 8) ,(4, 1080428422, 9),(4, 1099177222, 8) ,(4, 1111878022, 9),(4, 1130626822, 8) ,(4, 1143327622, 9),(4, 1162076422, 8) ,(4, 1174777222, 9),(4, 1193526022, 8) ,(4, 1206831622, 9),(4, 1224975622, 8) ,(4, 1238281222, 9),(4, 1256425222, 8) ,(4, 1269730822, 9),(4, 1288479622, 8) ,(4, 1301180422, 9),(4, 1319929222, 8) ,(4, 1332630022, 9),(4, 1351378822, 8) ,(4, 1364684422, 9),(4, 1382828422, 8) ,(4, 1396134022, 9),(4, 1414278022, 8) ,(4, 1427583622, 9),(4, 1445727622, 8) ,(4, 1459033222, 9),(4, 1477782022, 8) ,(4, 1490482822, 9),(4, 1509231622, 8) ,(4, 1521932422, 9),(4, 1540681222, 8) ,(4, 1553986822, 9),(4, 1572130822, 8) ,(4, 1585436422, 9),(4, 1603580422, 8) ,(4, 1616886022, 9),(4, 1635634822, 8) ,(4, 1648335622, 9),(4, 1667084422, 8) ,(4, 1679785222, 9),(4, 1698534022, 8) ,(4, 1711839622, 9),(4, 1729983622, 8) ,(4, 1743289222, 9),(4, 1761433222, 8) ,(4, 1774738822, 9),(4, 1792882822, 8) ,(4, 1806188422, 9),(4, 1824937222, 8) ,(4, 1837638022, 9),(4, 1856386822, 8) ,(4, 1869087622, 9),(4, 1887836422, 8) ,(4, 1901142022, 9),(4, 1919286022, 8) ,(4, 1932591622, 9),(4, 1950735622, 8) ,(4, 1964041222, 9),(4, 1982790022, 8) ,(4, 1995490822, 9),(4, 2014239622, 8) ,(4, 2026940422, 9),(4, 2045689222, 8) ,(4, 2058390022, 9),(4, 2077138822, 8) ,(4, 2090444422, 9),(4, 2108588422, 8) ,(4, 2121894022, 9),(4, 2140038022, 8); + + +CREATE TABLE time_zone_transition_type (Time_zone_id int unsigned NOT NULL,Transition_type_id int unsigned NOT NULL,Offset int signed DEFAULT 0 NOT NULL,Is_DST tinyint unsigned DEFAULT 0 NOT NULL,Abbreviation char(8) DEFAULT '' NOT NULL,PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id)) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; + +INSERT INTO time_zone_transition_type (Time_zone_id,Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (1, 0, 7200, 1, 'MEST') ,(1, 1, 3600, 0, 'MET') ,(1, 2, 7200, 1, 'MEST') ,(1, 3, 3600, 0, 'MET') ,(2, 0, 0, 0, 'UTC') ,(3, 0, 9000, 0, 'MMT') ,(3, 1, 12648, 1, 'MST') ,(3, 2, 9048, 0, 'MMT') ,(3, 3, 16248, 1, 'MDST') ,(3, 4, 10800, 0, 'MSK') ,(3, 5, 14400, 1, 'MSD') ,(3, 6, 18000, 1, 'MSD') ,(3, 7, 7200, 0, 'EET') ,(3, 8, 10800, 0, 'MSK') ,(3, 9, 14400, 1, 'MSD') ,(3, 10, 10800, 1, 'EEST') ,(3, 11, 7200, 0, 'EET') ,(4, 0, 9000, 0, 'MMT') ,(4, 1, 12648, 1, 'MST') ,(4, 2, 9048, 0, 'MMT') ,(4, 3, 16248, 1, 'MDST') ,(4, 4, 10800, 0, 'MSK') ,(4, 5, 14400, 1, 'MSD') ,(4, 6, 18000, 1, 'MSD') ,(4, 7, 7200, 0, 'EET') ,(4, 8, 10800, 0, 'MSK') ,(4, 9, 14400, 1, 'MSD') ,(4, 10, 10800, 1, 'EEST') ,(4, 11, 7200, 0, 'EET') ,(5, 0, 32400, 0, 'CJT') ,(5, 1, 32400, 0, 'JST'); + +CREATE TABLE time_zone_leap_second (Transition_time bigint signed NOT NULL,Correction int signed NOT NULL,PRIMARY KEY TranTime (Transition_time)) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; + +INSERT INTO time_zone_leap_second (Transition_time, Correction) VALUES (78796800, 1) ,(94694401, 2) ,(126230402, 3) ,(157766403, 4) ,(189302404, 5) ,(220924805, 6) ,(252460806, 7) ,(283996807, 8) ,(315532808, 9) ,(362793609, 10) ,(394329610, 11) ,(425865611, 12) ,(489024012, 13) ,(567993613, 14) ,(631152014, 15) ,(662688015, 16) ,(709948816, 17) ,(741484817, 18) ,(773020818, 19) ,(820454419, 20) ,(867715220, 21) ,(915148821, 22); -CREATE TABLE columns_priv (Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp(14), Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name)) comment='Column privileges'; From c51d7acfcc30242101a5645f81b194f7330db87e Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Wed, 10 Nov 2004 14:05:28 +0400 Subject: [PATCH 41/94] 1. When mixing NULL to a character string, the result takes its charset/collation attributes from the character string, e.g. SELECT func(NULL, _latin2'string') now returns a latin2 result. This is done by introducing a new derivation (aka coercibility) level DERIVATION_IGNORABLE, which is used with Item_null. 2. 'Pure' NULL is now BINARY(0), not CHAR(0). I.e. NULL is now more typeless. --- mysql-test/r/metadata.result | 2 +- mysql-test/r/null.result | 94 ++++++++++++++++++++++++++++++++++ mysql-test/r/ps_2myisam.result | 4 +- mysql-test/r/ps_3innodb.result | 4 +- mysql-test/r/ps_4heap.result | 4 +- mysql-test/r/ps_5merge.result | 8 +-- mysql-test/r/ps_6bdb.result | 4 +- mysql-test/r/ps_7ndb.result | 4 +- mysql-test/t/null.test | 67 ++++++++++++++++++++++++ sql/item.cc | 4 +- sql/item.h | 3 ++ 11 files changed, 181 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index ced3ca61f80..2321a8998ac 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -5,7 +5,7 @@ def 1 8 1 1 N 32769 0 8 def 1.0 5 3 3 N 32769 1 8 def -1 8 1 2 N 32769 0 8 def hello 254 5 5 N 1 31 8 -def NULL 6 0 0 Y 32768 0 8 +def NULL 6 0 0 Y 32896 0 63 1 1.0 -1 hello NULL 1 1.0 -1 hello NULL create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp, l datetime, m enum('a','b'), n set('a','b'), o char(10)); diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index bd90b3fe3f3..3e233eb512a 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -175,3 +175,97 @@ explain select * from t1 where i=2 or i is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref i i 4 const 7 Using where; Using index drop table t1; +set names latin2; +create table t1 select +null as c00, +if(1, null, 'string') as c01, +if(0, null, 'string') as c02, +ifnull(null, 'string') as c03, +ifnull('string', null) as c04, +case when 0 then null else 'string' end as c05, +case when 1 then null else 'string' end as c06, +coalesce(null, 'string') as c07, +coalesce('string', null) as c08, +least('string',null) as c09, +least(null, 'string') as c10, +greatest('string',null) as c11, +greatest(null, 'string') as c12, +nullif('string', null) as c13, +nullif(null, 'string') as c14, +trim('string' from null) as c15, +trim(null from 'string') as c16, +substring_index('string', null, 1) as c17, +substring_index(null, 'string', 1) as c18, +elt(1, null, 'string') as c19, +elt(1, 'string', null) as c20, +concat('string', null) as c21, +concat(null, 'string') as c22, +concat_ws('sep', 'string', null) as c23, +concat_ws('sep', null, 'string') as c24, +concat_ws(null, 'string', 'string') as c25, +make_set(3, 'string', null) as c26, +make_set(3, null, 'string') as c27, +export_set(3, null, 'off', 'sep') as c29, +export_set(3, 'on', null, 'sep') as c30, +export_set(3, 'on', 'off', null) as c31, +replace(null, 'from', 'to') as c32, +replace('str', null, 'to') as c33, +replace('str', 'from', null) as c34, +insert('str', 1, 2, null) as c35, +insert(null, 1, 2, 'str') as c36, +lpad('str', 10, null) as c37, +rpad(null, 10, 'str') as c38; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c00` binary(0) default NULL, + `c01` varchar(6) character set latin2 default NULL, + `c02` varchar(6) character set latin2 default NULL, + `c03` varchar(6) character set latin2 NOT NULL default '', + `c04` varchar(6) character set latin2 default NULL, + `c05` varchar(6) character set latin2 default NULL, + `c06` varchar(6) character set latin2 default NULL, + `c07` varchar(6) character set latin2 default NULL, + `c08` varchar(6) character set latin2 default NULL, + `c09` varchar(6) character set latin2 NOT NULL default '', + `c10` varchar(6) character set latin2 NOT NULL default '', + `c11` varchar(6) character set latin2 NOT NULL default '', + `c12` varchar(6) character set latin2 NOT NULL default '', + `c13` varchar(6) character set latin2 default NULL, + `c14` char(0) character set latin2 default NULL, + `c15` char(0) character set latin2 default NULL, + `c16` varchar(6) character set latin2 default NULL, + `c17` varchar(6) character set latin2 default NULL, + `c18` char(0) character set latin2 default NULL, + `c19` varchar(6) character set latin2 default NULL, + `c20` varchar(6) character set latin2 default NULL, + `c21` varchar(6) character set latin2 default NULL, + `c22` varchar(6) character set latin2 default NULL, + `c23` varchar(9) character set latin2 default NULL, + `c24` varchar(9) character set latin2 default NULL, + `c25` varchar(12) character set latin2 default NULL, + `c26` varchar(7) character set latin2 default NULL, + `c27` varchar(7) character set latin2 default NULL, + `c29` longtext character set latin2, + `c30` longtext character set latin2, + `c31` varchar(192) character set latin2 default NULL, + `c32` char(0) character set latin2 default NULL, + `c33` char(3) character set latin2 default NULL, + `c34` char(3) character set latin2 default NULL, + `c35` char(3) character set latin2 default NULL, + `c36` char(3) character set latin2 default NULL, + `c37` varchar(10) character set latin2 default NULL, + `c38` varchar(10) character set latin2 default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +select +case 'str' when 'STR' then 'str' when null then 'null' end as c01, +case 'str' when null then 'null' when 'STR' then 'str' end as c02, +field(null, 'str1', 'str2') as c03, +field('str1','STR1', null) as c04, +field('str1', null, 'STR1') as c05, +'string' in ('STRING', null) as c08, +'string' in (null, 'STRING') as c09; +c01 c02 c03 c04 c05 c08 c09 +str str 0 1 2 1 1 +set names latin1; diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index 345929d8104..42b4580643e 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1790,7 +1790,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1820,7 +1820,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 45a3af8e6fa..bb001fe9e02 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1773,7 +1773,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1803,7 +1803,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 995224fcd21..263b389ffa4 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1774,7 +1774,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1804,7 +1804,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 7a0191b186a..0ec296717e0 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1713,7 +1713,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1743,7 +1743,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 @@ -4723,7 +4723,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -4753,7 +4753,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index d0549503bfe..bb28abeda69 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -1773,7 +1773,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1803,7 +1803,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index e90eff5d1cd..70118509d0b 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -1749,7 +1749,7 @@ t5 CREATE TABLE `t5` ( `param10` bigint(20) default NULL, `const11` int(4) default NULL, `param11` bigint(20) default NULL, - `const12` char(0) default NULL, + `const12` binary(0) default NULL, `param12` bigint(20) default NULL, `param13` double default NULL, `param14` longtext, @@ -1779,7 +1779,7 @@ def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 -def test t5 t5 const12 const12 254 0 0 Y 0 0 8 +def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index 7d30fd06ba7..9ddef252d67 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -119,3 +119,70 @@ alter table t1 change i i int not null; explain select * from t1 where i=2 or i is null; drop table t1; +# +# NULL has its own type BINARY(0) by default. +# But NULL should be weaker than a constant +# when mixing charsets/collations +# +set names latin2; +# Check that result type is taken from a non-null string +create table t1 select + null as c00, + if(1, null, 'string') as c01, + if(0, null, 'string') as c02, + ifnull(null, 'string') as c03, + ifnull('string', null) as c04, + case when 0 then null else 'string' end as c05, + case when 1 then null else 'string' end as c06, + coalesce(null, 'string') as c07, + coalesce('string', null) as c08, + least('string',null) as c09, + least(null, 'string') as c10, + greatest('string',null) as c11, + greatest(null, 'string') as c12, + nullif('string', null) as c13, + nullif(null, 'string') as c14, + trim('string' from null) as c15, + trim(null from 'string') as c16, + substring_index('string', null, 1) as c17, + substring_index(null, 'string', 1) as c18, + elt(1, null, 'string') as c19, + elt(1, 'string', null) as c20, + concat('string', null) as c21, + concat(null, 'string') as c22, + concat_ws('sep', 'string', null) as c23, + concat_ws('sep', null, 'string') as c24, + concat_ws(null, 'string', 'string') as c25, + make_set(3, 'string', null) as c26, + make_set(3, null, 'string') as c27, + export_set(3, null, 'off', 'sep') as c29, + export_set(3, 'on', null, 'sep') as c30, + export_set(3, 'on', 'off', null) as c31, + replace(null, 'from', 'to') as c32, + replace('str', null, 'to') as c33, + replace('str', 'from', null) as c34, + insert('str', 1, 2, null) as c35, + insert(null, 1, 2, 'str') as c36, + lpad('str', 10, null) as c37, + rpad(null, 10, 'str') as c38; + +show create table t1; +drop table t1; + +# +# Check that comparison is done according to +# non-null string collation, i.e. case insensitively, +# rather than according to NULL's collation, i.e. case sensitively +# +-- in field +select + case 'str' when 'STR' then 'str' when null then 'null' end as c01, + case 'str' when null then 'null' when 'STR' then 'str' end as c02, + field(null, 'str1', 'str2') as c03, + field('str1','STR1', null) as c04, + field('str1', null, 'STR1') as c05, + 'string' in ('STRING', null) as c08, + 'string' in (null, 'STRING') as c09; + +# Restore charset to the default value. +set names latin1; diff --git a/sql/item.cc b/sql/item.cc index b4e7322b7cc..0e7a2b50b51 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -376,13 +376,13 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) } else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) && derivation < dt.derivation && - dt.derivation == DERIVATION_COERCIBLE) + dt.derivation >= DERIVATION_COERCIBLE) { // Do nothing; } else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) && dt.derivation < derivation && - derivation == DERIVATION_COERCIBLE) + derivation >= DERIVATION_COERCIBLE) { set(dt); strong= nagg; diff --git a/sql/item.h b/sql/item.h index fea3aa010a8..547577a7ee0 100644 --- a/sql/item.h +++ b/sql/item.h @@ -31,6 +31,7 @@ void item_init(void); /* Init item functions */ enum Derivation { + DERIVATION_IGNORABLE= 4, DERIVATION_COERCIBLE= 3, DERIVATION_IMPLICIT= 2, DERIVATION_NONE= 1, @@ -98,6 +99,7 @@ public: { switch(derivation) { + case DERIVATION_IGNORABLE: return "IGNORABLE"; case DERIVATION_COERCIBLE: return "COERCIBLE"; case DERIVATION_IMPLICIT: return "IMPLICIT"; case DERIVATION_EXPLICIT: return "EXPLICIT"; @@ -440,6 +442,7 @@ public: max_length= 0; name= name_par ? name_par : (char*) "NULL"; fixed= 1; + collation.set(&my_charset_bin, DERIVATION_IGNORABLE); } enum Type type() const { return NULL_ITEM; } bool eq(const Item *item, bool binary_cmp) const; From f08a29d85a9f6d744ce427e50b2ebfa1e22223cf Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Wed, 10 Nov 2004 14:13:38 +0400 Subject: [PATCH 42/94] Adding new function prototype --- include/mysql.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/mysql.h b/include/mysql.h index 156d749234b..2c0197e2300 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -490,6 +490,8 @@ MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long from_length); +unsigned long STDCALL mysql_hex_string(char *to,const char *from, + unsigned long from_length); unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length); From 0c4363b6d0257d4234b12367c7746257f9472f17 Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Wed, 10 Nov 2004 15:07:55 +0100 Subject: [PATCH 43/94] Fix for BUG#6522 "Replication fails due to a rolled back transaction in the binlog" When we are writing a transaction to the binlog, we log BEGIN/COMMIT with zero error code. Example: all statements of trans succeeded, connection lost and so implicit rollback: we don't want ER_NET* errors to be logged in the BEGIN/ROLLBACK events, while statement events have 0. If there was really a serious error code, it's already in the statement events. --- sql/log.cc | 9 +++++++++ sql/sql_table.cc | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sql/log.cc b/sql/log.cc index aa5d9d8753b..b2d015c1a14 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1370,6 +1370,14 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) */ { Query_log_event qinfo(thd, "BEGIN", 5, TRUE); + /* + Imagine this is rollback due to net timeout, after all statements of + the transaction succeeded. Then we want a zero-error code in BEGIN. + In other words, if there was a really serious error code it's already + in the statement's events. + This is safer than thd->clear_error() against kills at shutdown. + */ + qinfo.error_code= 0; /* Now this Query_log_event has artificial log_pos 0. It must be adjusted to reflect the real position in the log. Not doing it would confuse the @@ -1403,6 +1411,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) commit_or_rollback ? "COMMIT" : "ROLLBACK", commit_or_rollback ? 6 : 8, TRUE); + qinfo.error_code= 0; qinfo.set_log_pos(this); if (qinfo.write(&log_file) || flush_io_cache(&log_file)) goto err; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 65690e56039..1e5237b1428 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -911,7 +911,6 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, } table->file->extra(HA_EXTRA_WRITE_CACHE); DBUG_RETURN(table); - /* Note that leaving the function resets binlogging properties */ } From dd1cd8aa463b05375eeaca632b8d850a413a968a Mon Sep 17 00:00:00 2001 From: "acurtis@pcgem.rdg.cyberkinetica.com" <> Date: Wed, 10 Nov 2004 15:07:11 +0000 Subject: [PATCH 44/94] Bug#6031 - To drop database you have to execute DROP DATABASE command twice. DROP DATABASE failed because of file ext not in TYPELIB of known extensions. General solution - construct a TYPELIB at runtime instead of a static list. --- mysql-test/r/ndb_basic.result | 7 +++++ mysql-test/t/ndb_basic.test | 15 ++++++++++ sql/ha_ndbcluster.cc | 2 +- sql/handler.cc | 56 +++++++++++++++++++++++++++++++++++ sql/handler.h | 2 +- sql/sql_db.cc | 7 +---- 6 files changed, 81 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/ndb_basic.result b/mysql-test/r/ndb_basic.result index ba8ee820ad9..6ec5338acbe 100644 --- a/mysql-test/r/ndb_basic.result +++ b/mysql-test/r/ndb_basic.result @@ -400,6 +400,13 @@ b attr1 9413 9412 drop table test.t1, t2; drop database mysqltest; +drop database if exists ndbtest1; +create database ndbtest1; +use ndbtest1; +create table t1(id int) engine=ndbcluster; +drop database ndbtest1; +drop database ndbtest1; +ERROR HY000: Can't drop database 'ndbtest1'; database doesn't exist use test; create table t1 (a int primary key, b char(0)); insert into t1 values (1,""); diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index b62d2a8e0e1..2671223ada8 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -360,6 +360,21 @@ select b,test.t1.attr1 from test.t1, t2 where test.t1.pk1 < a; drop table test.t1, t2; drop database mysqltest; +# +# BUG#6031 - DROP DATABASE doesn't drop database on first try +# + +--disable_warnings +drop database if exists ndbtest1; +--enable_warnings + +create database ndbtest1; +use ndbtest1; +create table t1(id int) engine=ndbcluster; +drop database ndbtest1; +--error 1008 +drop database ndbtest1; + # # test support of char(0) # diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 5971c1a6c2a..d9545d5cbb8 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2777,7 +2777,7 @@ int ha_ndbcluster::reset() const char **ha_ndbcluster::bas_ext() const -{ static const char *ext[]= { ".ndb", NullS }; return ext; } +{ static const char *ext[]= { ha_ndb_ext, NullS }; return ext; } /* diff --git a/sql/handler.cc b/sql/handler.cc index f7a1a6ef0bf..2c274c7989e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -109,6 +109,8 @@ const char *tx_isolation_names[] = TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"", tx_isolation_names, NULL}; +static TYPELIB known_extensions= {0,"known_exts", NULL, NULL}; + enum db_type ha_resolve_by_name(const char *name, uint namelen) { THD *thd=current_thd; @@ -1633,3 +1635,57 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key, return error; } +/* + Returns a list of all known extensions. + + SYNOPSIS + ha_known_exts() + + NOTES + No mutexes, worst case race is a minor surplus memory allocation + + RETURN VALUE + pointer pointer to TYPELIB structure +*/ +TYPELIB *ha_known_exts(void) +{ + if (!known_extensions.type_names) + { + show_table_type_st *types; + List found_exts; + List_iterator_fast it(found_exts); + const char *e, **ext; + + found_exts.push_back(".db"); + for (types= sys_table_types; types->type; types++) + { + if (*types->value == SHOW_OPTION_YES) + { + handler *file= get_new_handler(0,(enum db_type) types->db_type); + for (ext= file->bas_ext(); *ext; ext++) + { + while (e=it++) + if (e == *ext) + break; + + if (!e) + found_exts.push_back((char *)*ext); + + it.rewind(); + } + delete file; + } + } + ext= (const char **)my_once_alloc(sizeof(char *)* + (found_exts.elements+1), MYF(MY_WME)); + + DBUG_ASSERT(ext); + for (uint i=0; e=it++; i++) + ext[i]= e; + ext[found_exts.elements]= 0; + + known_extensions.count= found_exts.elements; + known_extensions.type_names= ext; + } + return &known_extensions; +} diff --git a/sql/handler.h b/sql/handler.h index a7ce4e708fd..54a416d80ad 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -567,5 +567,5 @@ int ha_discover(THD* thd, const char* dbname, const char* name, int ha_find_files(THD *thd,const char *db,const char *path, const char *wild, bool dir,List* files); int ha_table_exists(THD* thd, const char* db, const char* name); - +TYPELIB *ha_known_exts(void); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index e50796f2a33..350a7432990 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -30,11 +30,6 @@ const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS}; static TYPELIB deletable_extentions= {array_elements(del_exts)-1,"del_exts", del_exts, NULL}; -const char *known_exts[]= -{".ISM",".ISD",".ISM",".MRG",".MYI",".MYD",".db", ".ibd", NullS}; -static TYPELIB known_extentions= -{array_elements(known_exts)-1,"known_exts", known_exts, NULL}; - static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, const char *path, uint level); @@ -737,7 +732,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, extension= fn_ext(file->name); if (find_type(extension, &deletable_extentions,1+2) <= 0) { - if (find_type(extension, &known_extentions,1+2) <= 0) + if (find_type(extension, ha_known_exts(),1+2) <= 0) found_other_files++; continue; } From 17b2d671ee15410a8e9faba27d883f4b9aeb5df3 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Wed, 10 Nov 2004 16:05:28 +0000 Subject: [PATCH 45/94] added configure switch for ndb port number added new variable for ndb port 1186 changed meaning of ndb_port_base to be default tcp port setting changed to use split between port and port_base for ndbcluster so that ndb_port and ndb_port_base are propagated to startscript for ndbcluster added larger space to pid print moved readAndExecute out of CommandInterpreter to avoid linking lib with readline added c-api to Ndb_mgmclient pass also ndb_port to make --- acinclude.m4 | 7 ++- configure.in | 8 ++- mysql-test/mysql-test-run.sh | 11 ++-- mysql-test/ndb/Makefile.am | 2 + mysql-test/ndb/ndbcluster.sh | 16 ++--- ndb/src/common/mgmcommon/LocalConfig.cpp | 6 +- ndb/src/common/mgmcommon/Makefile.am | 2 +- ndb/src/common/mgmcommon/NdbConfig.c | 2 +- ndb/src/mgmclient/CommandInterpreter.cpp | 76 ++++++++---------------- ndb/src/mgmclient/main.cpp | 46 +++++++++++++- ndb/src/mgmclient/ndb_mgmclient.h | 33 ++++++++++ ndb/src/mgmclient/ndb_mgmclient.hpp | 8 +-- ndb/src/mgmsrv/ConfigInfo.cpp | 8 +-- ndb/src/mgmsrv/Makefile.am | 1 + 14 files changed, 148 insertions(+), 78 deletions(-) create mode 100644 ndb/src/mgmclient/ndb_mgmclient.h diff --git a/acinclude.m4 b/acinclude.m4 index 671e279a9f3..448bf7a2653 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1614,9 +1614,14 @@ AC_DEFUN([MYSQL_CHECK_NDB_OPTIONS], [ --with-ndb-docs Include the NDB Cluster ndbapi and mgmapi documentation], [ndb_docs="$withval"], [ndb_docs=no]) + AC_ARG_WITH([ndb-port], + [ + --with-ndb-port Port for NDB Cluster management server], + [ndb_port="$withval"], + [ndb_port="default"]) AC_ARG_WITH([ndb-port-base], [ - --with-ndb-port-base Base port for NDB Cluster], + --with-ndb-port-base Base port for NDB Cluster transporters], [ndb_port_base="$withval"], [ndb_port_base="default"]) diff --git a/configure.in b/configure.in index cd2daf10690..764261c6933 100644 --- a/configure.in +++ b/configure.in @@ -3052,9 +3052,15 @@ AC_SUBST([NDB_DEFS]) AC_SUBST([ndb_cxxflags_fix]) +if test X"$ndb_port" = Xdefault +then + ndb_port="1186" +fi +AC_SUBST([ndb_port]) + if test X"$ndb_port_base" = Xdefault then - ndb_port_base="2200" + ndb_port_base="2202" fi AC_SUBST([ndb_port_base]) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 65be9bf9c8e..fcb9e5eee2d 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -457,6 +457,9 @@ SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M" export MASTER_MYPORT MASTER_MYPORT1 SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1 +NDBCLUSTER_BASE_PORT=`expr $NDBCLUSTER_PORT + 2` +NDBCLUSTER_OPTS="--port=$NDBCLUSTER_PORT --port-base=$NDBCLUSTER_BASE_PORT --data-dir=$MYSQL_TEST_DIR/var" + if [ x$SOURCE_DIST = x1 ] ; then MY_BASEDIR=$MYSQL_TEST_DIR else @@ -939,11 +942,11 @@ start_ndbcluster() echo "Starting ndbcluster" if [ "$DO_BENCH" = 1 ] then - NDBCLUSTER_OPTS="" + NDBCLUSTER_EXTRA_OPTS="" else - NDBCLUSTER_OPTS="--small" + NDBCLUSTER_EXTRA_OPTS="--small" fi - ./ndb/ndbcluster --port-base=$NDBCLUSTER_PORT $NDBCLUSTER_OPTS --diskless --initial --data-dir=$MYSQL_TEST_DIR/var || exit 1 + ./ndb/ndbcluster $NDBCLUSTER_OPTS $NDBCLUSTER_EXTRA_OPTS --diskless --initial || exit 1 NDB_CONNECTSTRING="host=localhost:$NDBCLUSTER_PORT" else NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER" @@ -961,7 +964,7 @@ stop_ndbcluster() if [ -z "$USE_RUNNING_NDBCLUSTER" ] then # Kill any running ndbcluster stuff - ./ndb/ndbcluster --data-dir=$MYSQL_TEST_DIR/var --port-base=$NDBCLUSTER_PORT --stop + ./ndb/ndbcluster $NDBCLUSTER_OPTS --stop fi fi } diff --git a/mysql-test/ndb/Makefile.am b/mysql-test/ndb/Makefile.am index 3ed222344a6..502ccee099e 100644 --- a/mysql-test/ndb/Makefile.am +++ b/mysql-test/ndb/Makefile.am @@ -13,6 +13,8 @@ SUFFIXES = .sh .sh: @RM@ -f $@ $@-t @SED@ \ + -e 's!@''ndb_port''@!$(ndb_port)!g' \ + -e 's!@''ndb_port_base''@!$(ndb_port_base)!g' \ -e 's!@''ndbbindir''@!$(ndbbindir)!g' \ -e 's!@''ndbtoolsdir''@!$(ndbtoolsdir)!g' \ $< > $@-t diff --git a/mysql-test/ndb/ndbcluster.sh b/mysql-test/ndb/ndbcluster.sh index f5757a11056..3486a879eec 100644 --- a/mysql-test/ndb/ndbcluster.sh +++ b/mysql-test/ndb/ndbcluster.sh @@ -5,7 +5,8 @@ # This scripts starts the table handler ndbcluster # configurable parameters, make sure to change in mysqlcluterd as well -port_base="2200" +port=@ndb_port@ +port_base=@ndb_port_base@ fsdir=`pwd` # end configurable parameters @@ -84,6 +85,9 @@ while test $# -gt 0; do --data-dir=*) fsdir=`echo "$1" | sed -e "s;--data-dir=;;"` ;; + --port=*) + port=`echo "$1" | sed -e "s;--port=;;"` + ;; --port-base=*) port_base=`echo "$1" | sed -e "s;--port-base=;;"` ;; @@ -94,7 +98,7 @@ while test $# -gt 0; do shift done -fs_ndb="$fsdir/ndbcluster-$port_base" +fs_ndb="$fsdir/ndbcluster-$port" NDB_HOME= if [ ! -x "$fsdir" ]; then @@ -120,7 +124,7 @@ exec_ndb="$exec_ndb --no-defaults" exec_waiter="$exec_waiter --no-defaults" ndb_host="localhost" -ndb_mgmd_port=$port_base +ndb_mgmd_port=$port NDB_CONNECTSTRING="host=$ndb_host:$ndb_mgmd_port" export NDB_CONNECTSTRING @@ -158,10 +162,6 @@ if [ -d "$fs_ndb" ]; then :; else exit 1 fi -# set som help variables - -port_transporter=`expr $ndb_mgmd_port + 2` - # Start management server as deamon # Edit file system path and ports in config file @@ -176,7 +176,7 @@ sed \ -e s,"CHOOSE_HOSTNAME_".*,"$ndb_host",g \ -e s,"CHOOSE_FILESYSTEM","$fs_ndb",g \ -e s,"CHOOSE_PORT_MGM","$ndb_mgmd_port",g \ - -e s,"CHOOSE_PORT_TRANSPORTER","$port_transporter",g \ + -e s,"CHOOSE_PORT_TRANSPORTER","$port_base",g \ < ndb/ndb_config_2_node.ini \ > "$fs_ndb/config.ini" fi diff --git a/ndb/src/common/mgmcommon/LocalConfig.cpp b/ndb/src/common/mgmcommon/LocalConfig.cpp index 3cd4341c6b7..679de716be0 100644 --- a/ndb/src/common/mgmcommon/LocalConfig.cpp +++ b/ndb/src/common/mgmcommon/LocalConfig.cpp @@ -90,7 +90,7 @@ LocalConfig::init(const char *connectString, //7. Check { char buf[256]; - BaseString::snprintf(buf, sizeof(buf), "host=localhost:%s", NDB_BASE_PORT); + BaseString::snprintf(buf, sizeof(buf), "host=localhost:%s", NDB_PORT); if(readConnectString(buf, "default connect string")) return true; } @@ -124,12 +124,12 @@ void LocalConfig::printUsage() const { ndbout << "1. Put a Ndb.cfg file in the directory where you start"<export NDB_CONNECTSTRING=\"host=localhost:"<export NDB_CONNECTSTRING=\"host=localhost:"< 0) snprintf(tmp_buf, sizeof(tmp_buf), "ndb_%u", node_id); diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index 523c271ed9e..f1a953769b8 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -17,17 +17,6 @@ #include #include -// copied from mysql.cc to get readline -extern "C" { -#if defined( __WIN__) || defined(OS2) -#include -#elif !defined(__NETWARE__) -#include -extern "C" int add_history(const char *command); /* From readline directory */ -#define HAVE_READLINE -#endif -} - //#define HAVE_GLOBAL_REPLICATION #include @@ -65,7 +54,6 @@ public: * * @return true until quit/bye/exit has been typed */ - int readAndExecute(int _try_reconnect=-1); int execute(const char *_line, int _try_reconnect=-1); private: @@ -180,6 +168,7 @@ private: */ #include "ndb_mgmclient.hpp" +#include "ndb_mgmclient.h" Ndb_mgmclient::Ndb_mgmclient(const char *host) { @@ -189,10 +178,6 @@ Ndb_mgmclient::~Ndb_mgmclient() { delete m_cmd; } -int Ndb_mgmclient::read_and_execute(int _try_reconnect) -{ - return m_cmd->readAndExecute(_try_reconnect); -} int Ndb_mgmclient::execute(const char *_line, int _try_reconnect) { return m_cmd->execute(_line,_try_reconnect); @@ -203,7 +188,20 @@ Ndb_mgmclient::disconnect() return m_cmd->disconnect(); } - +extern "C" { + Ndb_mgmclient_handle ndb_mgmclient_handle_create(const char *connect_string) + { + return (Ndb_mgmclient_handle) new Ndb_mgmclient(connect_string); + } + int ndb_mgmclient_execute(Ndb_mgmclient_handle h, int argc, const char** argv) + { + return ((Ndb_mgmclient*)h)->execute(argc, argv, 1); + } + int ndb_mgmclient_handle_destroy(Ndb_mgmclient_handle h) + { + delete (Ndb_mgmclient*)h; + } +} /* * The CommandInterpreter */ @@ -227,6 +225,17 @@ Ndb_mgmclient::disconnect() #include #include +int Ndb_mgmclient::execute(int argc, const char** argv, int _try_reconnect) +{ + if (argc <= 0) + return 0; + BaseString _line(argv[0]); + for (int i= 1; i < argc; i++) + { + _line.appfmt(" %s", argv[i]); + } + return m_cmd->execute(_line.c_str(),_try_reconnect); +} /***************************************************************************** * HELP @@ -456,39 +465,6 @@ CommandInterpreter::disconnect() //***************************************************************************** //***************************************************************************** -int -CommandInterpreter::readAndExecute(int _try_reconnect) -{ - static char *line_read = (char *)NULL; - - /* If the buffer has already been allocated, return the memory - to the free pool. */ - if (line_read) - { - free (line_read); - line_read = (char *)NULL; - } -#ifdef HAVE_READLINE - /* Get a line from the user. */ - line_read = readline ("ndb_mgm> "); - /* If the line has any text in it, save it on the history. */ - if (line_read && *line_read) - add_history (line_read); -#else - static char linebuffer[254]; - fputs("ndb_mgm> ", stdout); - linebuffer[sizeof(linebuffer)-1]=0; - line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); - if (line_read == linebuffer) { - char *q=linebuffer; - while (*q > 31) q++; - *q=0; - line_read= strdup(linebuffer); - } -#endif - return execute(line_read,_try_reconnect); -} - int CommandInterpreter::execute(const char *_line, int _try_reconnect) { diff --git a/ndb/src/mgmclient/main.cpp b/ndb/src/mgmclient/main.cpp index 3415ede1985..8f5d9e6656c 100644 --- a/ndb/src/mgmclient/main.cpp +++ b/ndb/src/mgmclient/main.cpp @@ -17,6 +17,17 @@ #include #include +// copied from mysql.cc to get readline +extern "C" { +#if defined( __WIN__) || defined(OS2) +#include +#elif !defined(__NETWARE__) +#include +extern "C" int add_history(const char *command); /* From readline directory */ +#define HAVE_READLINE +#endif +} + #include #include #include @@ -90,6 +101,39 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), return 0; } +static int +read_and_execute(int _try_reconnect) +{ + static char *line_read = (char *)NULL; + + /* If the buffer has already been allocated, return the memory + to the free pool. */ + if (line_read) + { + free (line_read); + line_read = (char *)NULL; + } +#ifdef HAVE_READLINE + /* Get a line from the user. */ + line_read = readline ("ndb_mgm> "); + /* If the line has any text in it, save it on the history. */ + if (line_read && *line_read) + add_history (line_read); +#else + static char linebuffer[254]; + fputs("ndb_mgm> ", stdout); + linebuffer[sizeof(linebuffer)-1]=0; + line_read = fgets(linebuffer, sizeof(linebuffer)-1, stdin); + if (line_read == linebuffer) { + char *q=linebuffer; + while (*q > 31) q++; + *q=0; + line_read= strdup(linebuffer); + } +#endif + return com->execute(line_read,_try_reconnect); +} + int main(int argc, char** argv){ NDB_INIT(argv[0]); const char *_host = 0; @@ -128,7 +172,7 @@ int main(int argc, char** argv){ signal(SIGPIPE, handler); com = new Ndb_mgmclient(buf); - while(com->read_and_execute(_try_reconnect)); + while(read_and_execute(_try_reconnect)); delete com; return 0; diff --git a/ndb/src/mgmclient/ndb_mgmclient.h b/ndb/src/mgmclient/ndb_mgmclient.h new file mode 100644 index 00000000000..265e6bc67ec --- /dev/null +++ b/ndb/src/mgmclient/ndb_mgmclient.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2003 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#ifndef Ndb_mgmclient_h +#define Ndb_mgmclient_h + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void* Ndb_mgmclient_handle; +Ndb_mgmclient_handle ndb_mgmclient_handle_create(const char *connect_string); +int ndb_mgmclient_execute(Ndb_mgmclient_handle, int argc, const char** argv); +int ndb_mgmclient_handle_destroy(Ndb_mgmclient_handle); + +#ifdef __cplusplus +} +#endif + +#endif /* Ndb_mgmclient_h */ diff --git a/ndb/src/mgmclient/ndb_mgmclient.hpp b/ndb/src/mgmclient/ndb_mgmclient.hpp index 2f021a0f2b6..933d1bab5ce 100644 --- a/ndb/src/mgmclient/ndb_mgmclient.hpp +++ b/ndb/src/mgmclient/ndb_mgmclient.hpp @@ -14,8 +14,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef Ndb_mgmclient_h -#define Ndb_mgmclient_h +#ifndef Ndb_mgmclient_hpp +#define Ndb_mgmclient_hpp class CommandInterpreter; class Ndb_mgmclient @@ -23,11 +23,11 @@ class Ndb_mgmclient public: Ndb_mgmclient(const char*); ~Ndb_mgmclient(); - int read_and_execute(int _try_reconnect=-1); int execute(const char *_line, int _try_reconnect=-1); + int execute(int argc, const char** argv, int _try_reconnect=-1); int disconnect(); private: CommandInterpreter *m_cmd; }; -#endif // Ndb_mgmclient_h +#endif // Ndb_mgmclient_hpp diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index ad346b30ead..4af1556a0c0 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -1478,7 +1478,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::USED, false, ConfigInfo::INT, - NDB_BASE_PORT, + NDB_PORT, "0", STR_VALUE(MAX_INT_RNIL) }, @@ -1490,7 +1490,7 @@ const ConfigInfo::ParamInfo ConfigInfo::m_ParamInfo[] = { ConfigInfo::USED, false, ConfigInfo::INT, - "2199", + UNDEFINED, "0", STR_VALUE(MAX_INT_RNIL) }, @@ -3010,7 +3010,7 @@ fixPortNumber(InitConfigFileParser::Context & ctx, const char * data){ if(!(ctx.m_userDefaults && ctx.m_userDefaults->get("PortNumber", &base)) && !ctx.m_systemDefaults->get("PortNumber", &base)) { - base= strtoll(NDB_BASE_PORT,0,0)+2; + base= strtoll(NDB_BASE_PORT,0,0); // ctx.reportError("Cannot retrieve base port number"); // return false; } @@ -3442,7 +3442,7 @@ static bool add_server_ports(Vector§ions, #if 0 Properties * props= ctx.m_config; Properties computers(true); - Uint32 port_base = NDB_BASE_PORT+2; + Uint32 port_base = NDB_BASE_PORT; Uint32 nNodes; ctx.m_userProperties.get("NoOfNodes", &nNodes); diff --git a/ndb/src/mgmsrv/Makefile.am b/ndb/src/mgmsrv/Makefile.am index 4cb164d48fe..ee5220ef9f8 100644 --- a/ndb/src/mgmsrv/Makefile.am +++ b/ndb/src/mgmsrv/Makefile.am @@ -33,6 +33,7 @@ DEFS_LOC = -DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \ -DDATADIR="\"$(MYSQLDATAdir)\"" \ -DSHAREDIR="\"$(MYSQLSHAREdir)\"" \ -DMYSQLCLUSTERDIR="\"$(MYSQLCLUSTERdir)\"" \ + -DNDB_PORT="\"@ndb_port@\"" \ -DNDB_BASE_PORT="\"@ndb_port_base@\"" include $(top_srcdir)/ndb/config/common.mk.am From c7e85ef9b9a43db87899e172a621af44cf6add4c Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Wed, 10 Nov 2004 18:07:39 +0200 Subject: [PATCH 46/94] More debugging Print position in normal log for Binlog dump --- dbug/dbug.c | 56 ++++++++++++++++++++++++++++++++++------------- include/my_dbug.h | 3 +++ sql/field.cc | 10 +++++++-- sql/log.cc | 32 +++++++++++++++++++-------- sql/mysqld.cc | 2 +- sql/slave.cc | 2 +- sql/sql_class.h | 2 +- sql/sql_parse.cc | 11 ++++++---- 8 files changed, 85 insertions(+), 33 deletions(-) diff --git a/dbug/dbug.c b/dbug/dbug.c index 1796d883c5e..02175f8b091 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -227,14 +227,15 @@ static my_bool init_done = FALSE; /* Set to TRUE when initialization done */ static struct state *stack=0; typedef struct st_code_state { - int lineno; /* Current debugger output line number */ - int level; /* Current function nesting level */ const char *func; /* Name of current user function */ const char *file; /* Name of current user file */ char **framep; /* Pointer to current frame */ - int jmplevel; /* Remember nesting level at setjmp () */ const char *jmpfunc; /* Remember current function for setjmp */ const char *jmpfile; /* Remember current file for setjmp */ + int lineno; /* Current debugger output line number */ + int level; /* Current function nesting level */ + int disable_output; /* Set to it if output is disabled */ + int jmplevel; /* Remember nesting level at setjmp () */ /* * The following variables are used to hold the state information @@ -247,8 +248,8 @@ typedef struct st_code_state { */ uint u_line; /* User source code line number */ - const char *u_keyword; /* Keyword for current macro */ int locked; /* If locked with _db_lock_file */ + const char *u_keyword; /* Keyword for current macro */ } CODE_STATE; /* Parse a debug command string */ @@ -370,8 +371,10 @@ static CODE_STATE *code_state(void) #define code_state() (&static_code_state) #define pthread_mutex_lock(A) {} #define pthread_mutex_unlock(A) {} -static CODE_STATE static_code_state = { 0,0,"?func","?file",NULL,0,NULL, - NULL,0,"?",0}; +static CODE_STATE static_code_state= +{ + "?func", "?file", NULL, NullS, NullS, 0,0,0,0,0,0, NullS +}; #endif @@ -728,9 +731,12 @@ char ***_sframep_ __attribute__((unused))) if (DoProfile ()) { long stackused; - if (*state->framep == NULL) { + if (*state->framep == NULL) + { stackused = 0; - } else { + } + else + { stackused = ((long)(*state->framep)) - ((long)(state->framep)); stackused = stackused > 0 ? stackused : -stackused; } @@ -744,7 +750,7 @@ char ***_sframep_ __attribute__((unused))) (void) fflush (_db_pfp_); } #endif - if (DoTrace (state)) + if (DoTrace(state)) { if (!state->locked) pthread_mutex_lock(&THR_LOCK_dbug); @@ -754,7 +760,7 @@ char ***_sframep_ __attribute__((unused))) dbug_flush (state); /* This does a unlock */ } #ifdef SAFEMALLOC - if (stack -> flags & SANITY_CHECK_ON) + if (stack->flags & SANITY_CHECK_ON && !state->disable_output) if (_sanity(_file_,_line_)) /* Check of safemalloc */ stack -> flags &= ~SANITY_CHECK_ON; #endif @@ -809,9 +815,11 @@ uint *_slevel_) else { #ifdef SAFEMALLOC - if (stack -> flags & SANITY_CHECK_ON) + if (stack->flags & SANITY_CHECK_ON && !state->disable_output) + { if (_sanity(*_sfile_,_line_)) stack->flags &= ~SANITY_CHECK_ON; + } #endif #ifndef THREAD if (DoProfile ()) @@ -954,7 +962,6 @@ uint length) int pos; char dbuff[90]; CODE_STATE *state; - /* Sasha: pre-my_thread_init() safety */ if (!(state=code_state())) return; @@ -994,6 +1001,25 @@ uint length) } } + +/* + Enable/Disable output for this thread + + SYNOPSIS + _db_output_() + flag 1 = enable output, 0 = disable_output + +*/ + +void _db_output_(uint flag) +{ + CODE_STATE *state; + if (!(state=code_state())) + return; + state->disable_output= !flag; +} + + /* * FUNCTION * @@ -1159,7 +1185,7 @@ static BOOLEAN DoTrace (CODE_STATE *state) { reg2 BOOLEAN trace=FALSE; - if (TRACING && + if (TRACING && !state->disable_output && state->level <= stack -> maxdepth && InList (stack -> functions, state->func) && InList (stack -> processes, _db_process_)) @@ -1195,7 +1221,7 @@ static BOOLEAN DoProfile () state=code_state(); profile = FALSE; - if (PROFILING && + if (PROFILING && !state->disable_output && state->level <= stack -> maxdepth && InList (stack -> p_functions, state->func) && InList (stack -> processes, _db_process_)) @@ -1242,7 +1268,7 @@ const char *keyword) if (!(state=code_state())) return FALSE; result = FALSE; - if (DEBUGGING && + if (DEBUGGING && !state->disable_output && state->level <= stack -> maxdepth && InList (stack -> functions, state->func) && InList (stack -> keywords, keyword) && diff --git a/include/my_dbug.h b/include/my_dbug.h index 9174a8b1ef9..711ece4335c 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -38,6 +38,7 @@ extern void _db_pargs_(uint _line_,const char *keyword); extern void _db_doprnt_ _VARARGS((const char *format,...)); extern void _db_dump_(uint _line_,const char *keyword,const char *memory, uint length); +extern void _db_output_(); extern void _db_lock_file(); extern void _db_unlock_file(); @@ -66,6 +67,7 @@ extern void _db_unlock_file(); #define DEBUGGER_ON _no_db_=0 #define DBUG_LOCK_FILE { _db_lock_file(); } #define DBUG_UNLOCK_FILE { _db_unlock_file(); } +#define DBUG_OUTPUT(A) { _db_output_(A); } #define DBUG_ASSERT(A) assert(A) #else /* No debugger */ @@ -86,6 +88,7 @@ extern void _db_unlock_file(); #define DEBUGGER_ON #define DBUG_LOCK_FILE #define DBUG_UNLOCK_FILE +#define DBUG_OUTPUT(A) #define DBUG_ASSERT(A) {} #endif #ifdef __cplusplus diff --git a/sql/field.cc b/sql/field.cc index deb38048d42..f70a23e889a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5941,8 +5941,14 @@ Field *make_field(char *ptr, uint32 field_length, if (f_is_alpha(pack_flag)) { if (!f_is_packed(pack_flag)) - return new Field_string(ptr,field_length,null_pos,null_bit, - unireg_check, field_name, table, field_charset); + { + if (field_type == FIELD_TYPE_STRING || + field_type == FIELD_TYPE_VAR_STRING) + return new Field_string(ptr,field_length,null_pos,null_bit, + unireg_check, field_name, table, + field_charset); + return 0; // Error + } uint pack_length=calc_pack_length((enum_field_types) f_packtype(pack_flag), diff --git a/sql/log.cc b/sql/log.cc index ef57a57d3b4..bcd99326501 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1703,6 +1703,8 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, time_t current_time; if (!is_open()) return 0; + DBUG_ENTER("MYSQL_LOG::write"); + VOID(pthread_mutex_lock(&LOCK_log)); if (is_open()) { // Safety agains reopen @@ -1712,7 +1714,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, if (!(thd->options & OPTION_UPDATE_LOG)) { VOID(pthread_mutex_unlock(&LOCK_log)); - return 0; + DBUG_RETURN(0); } if (!(specialflag & SPECIAL_SHORT_LOG_FORMAT) || query_start_arg) { @@ -1812,7 +1814,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, } } VOID(pthread_mutex_unlock(&LOCK_log)); - return error; + DBUG_RETURN(error); } @@ -1832,16 +1834,19 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, THD::enter_cond() (see NOTES in sql_class.h). */ -void MYSQL_LOG:: wait_for_update(THD* thd, bool master_or_slave) +void MYSQL_LOG::wait_for_update(THD* thd, bool master_or_slave) { - const char* old_msg = thd->enter_cond(&update_cond, &LOCK_log, - master_or_slave ? - "Has read all relay log; waiting for \ -the slave I/O thread to update it" : - "Has sent all binlog to slave; \ -waiting for binlog to be updated"); + const char *old_msg; + DBUG_ENTER("wait_for_update"); + old_msg= thd->enter_cond(&update_cond, &LOCK_log, + master_or_slave ? + "Has read all relay log; waiting for the slave I/O " + "thread to update it" : + "Has sent all binlog to slave; waiting for binlog " + "to be updated"); pthread_cond_wait(&update_cond, &LOCK_log); thd->exit_cond(old_msg); + DBUG_VOID_RETURN; } @@ -2198,6 +2203,15 @@ void MYSQL_LOG::report_pos_in_innodb() DBUG_VOID_RETURN; } + +void MYSQL_LOG::signal_update() +{ + DBUG_ENTER("MYSQL_LOG::signal_update"); + pthread_cond_broadcast(&update_cond); + DBUG_VOID_RETURN; +} + + #ifdef __NT__ void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, uint length, int buffLen) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 078ee19fe6a..5622ac50a7b 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -540,7 +540,7 @@ static void close_connections(void) struct timespec abstime; int error; LINT_INIT(error); - DBUG_PRINT("info",("Waiting for select_thread")); + DBUG_PRINT("info",("Waiting for select thread")); #ifndef DONT_USE_THR_ALARM if (pthread_kill(select_thread,THR_CLIENT_ALARM)) diff --git a/sql/slave.cc b/sql/slave.cc index 4ef8715f1e6..ea1f3cceaf4 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2632,7 +2632,7 @@ static int request_dump(MYSQL* mysql, MASTER_INFO* mi, DBUG_ENTER("request_dump"); // TODO if big log files: Change next to int8store() - int4store(buf, (longlong) mi->master_log_pos); + int4store(buf, (ulong) mi->master_log_pos); int2store(buf + 4, binlog_flags); int4store(buf + 6, server_id); len = (uint) strlen(logname); diff --git a/sql/sql_class.h b/sql/sql_class.h index df6be559df2..312d9de9794 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -131,7 +131,7 @@ public: DBUG_VOID_RETURN; } void set_max_size(ulong max_size_arg); - void signal_update() { pthread_cond_broadcast(&update_cond);} + void signal_update(); void wait_for_update(THD* thd, bool master_or_slave); void set_need_start_event() { need_start_event = 1; } void init(enum_log_type log_type_arg, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 2bf977804af..226ead71ada 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1610,15 +1610,15 @@ bool dispatch_command(enum enum_server_command command, THD *thd, #ifndef EMBEDDED_LIBRARY case COM_BINLOG_DUMP: { + ulong pos; + ushort flags; + uint32 slave_server_id; + statistic_increment(com_other,&LOCK_status); thd->slow_command = TRUE; if (check_global_access(thd, REPL_SLAVE_ACL)) break; - mysql_log.write(thd,command, 0); - ulong pos; - ushort flags; - uint32 slave_server_id; /* TODO: The following has to be changed to an 8 byte integer */ pos = uint4korr(packet); flags = uint2korr(packet + 4); @@ -1626,6 +1626,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if ((slave_server_id= uint4korr(packet+6))) // mysqlbinlog.server_id==0 kill_zombie_dump_threads(slave_server_id); thd->server_id = slave_server_id; + + mysql_log.write(thd, command, "Log: '%s' Pos: %ld", packet+10, + (long) pos); mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags); unregister_slave(thd,1,1); // fake COM_QUIT -- if we get here, the thread needs to terminate From 6cd218cc56744bc3848e5e0707a822e1e325315d Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Wed, 10 Nov 2004 17:56:45 +0100 Subject: [PATCH 47/94] WL#1596 "make mysqldump --master-data --single-transaction able to do online dump of InnoDB AND report reliable binlog coordinates corresponding to the dump". The good news is that now mysqldump can be used to get an online backup of InnoDB *which works for point-in-time recovery and replication slave creation*. Formerly, mysqldump --master-data --single-transaction used to call in fact mysqldump --master-data, so the dump was not an online dump (took big lock all time of dump). The only lock which is now taken in this patch is at the beginning of the dump: mysqldump does: FLUSH TABLES WITH READ LOCK; START TRANSACTION WITH CONSISTENT SNAPSHOT; SHOW MASTER STATUS; UNLOCK TABLES; so the lock time is in fact the time FLUSH TABLES WITH READ LOCK takes to return (can be 0 or very long, if a table is undergoing a huge update). I have done some more minor changes listed in the paragraph of mysqldump.c. WL#2237 "WITH CONSISTENT SNAPSHOT clause for START TRANSACTION": it's a START TRANSACTION which additionally starts a consistent read on all capable storage engine (i.e. InnoDB). So, can serve as a replacement for BEGIN; SELECT * FROM some_innodb_table LIMIT 1; which starts a consistent read too. --- client/mysqldump.c | 331 ++++++++++++++---------- include/mysqld_error.h | 3 +- mysql-test/r/consistent_snapshot.result | 15 ++ mysql-test/t/consistent_snapshot.test | 41 +++ sql/handler.cc | 18 ++ sql/handler.h | 5 +- sql/lex.h | 2 + sql/share/czech/errmsg.txt | 1 + sql/share/danish/errmsg.txt | 1 + sql/share/dutch/errmsg.txt | 1 + sql/share/english/errmsg.txt | 1 + sql/share/estonian/errmsg.txt | 1 + sql/share/french/errmsg.txt | 1 + sql/share/german/errmsg.txt | 1 + sql/share/greek/errmsg.txt | 1 + sql/share/hungarian/errmsg.txt | 1 + sql/share/italian/errmsg.txt | 1 + sql/share/japanese/errmsg.txt | 1 + sql/share/korean/errmsg.txt | 1 + sql/share/norwegian-ny/errmsg.txt | 1 + sql/share/norwegian/errmsg.txt | 1 + sql/share/polish/errmsg.txt | 1 + sql/share/portuguese/errmsg.txt | 1 + sql/share/romanian/errmsg.txt | 1 + sql/share/russian/errmsg.txt | 1 + sql/share/serbian/errmsg.txt | 1 + sql/share/slovak/errmsg.txt | 1 + sql/share/spanish/errmsg.txt | 1 + sql/share/swedish/errmsg.txt | 1 + sql/share/ukrainian/errmsg.txt | 1 + sql/sql_lex.h | 2 +- sql/sql_parse.cc | 10 +- sql/sql_yacc.yy | 21 +- 33 files changed, 328 insertions(+), 143 deletions(-) create mode 100644 mysql-test/r/consistent_snapshot.result create mode 100644 mysql-test/t/consistent_snapshot.test diff --git a/client/mysqldump.c b/client/mysqldump.c index 1686278096b..8ee30d39f01 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -37,7 +37,7 @@ ** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov */ -#define DUMP_VERSION "10.8" +#define DUMP_VERSION "10.9" #include #include @@ -78,8 +78,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1, lock_tables=1,ignore_errors=0,flush_logs=0,replace=0, ignore=0,opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0, - opt_alldbs=0,opt_create_db=0,opt_first_slave=0,opt_set_charset, - opt_autocommit=0,opt_master_data,opt_disable_keys=1,opt_xml=0, + opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,opt_set_charset, + opt_autocommit=0,opt_disable_keys=1,opt_xml=0, opt_delete_master_logs=0, tty_password=0, opt_single_transaction=0, opt_comments= 0, opt_compact= 0, opt_hex_blob=0; @@ -93,7 +93,9 @@ static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, *err_ptr= 0; static char compatible_mode_normal_str[255]; static ulong opt_compatible_mode= 0; -static uint opt_mysql_port= 0, err_len= 0; +#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1 +#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2 +static uint opt_mysql_port= 0, err_len= 0, opt_master_data; static my_string opt_mysql_unix_port=0; static int first_error=0; static DYNAMIC_STRING extended_row; @@ -183,8 +185,9 @@ static struct my_option my_long_options[] = (gptr*) &opt_delayed, (gptr*) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"delete-master-logs", OPT_DELETE_MASTER_LOGS, - "Delete logs on master after backup. This automatically enables --first-slave.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + "Delete logs on master after backup. This automatically enables --master-data.", + (gptr*) &opt_delete_master_logs, (gptr*) &opt_delete_master_logs, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"disable-keys", 'K', "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (gptr*) &opt_disable_keys, (gptr*) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, @@ -203,13 +206,18 @@ static struct my_option my_long_options[] = (gptr*) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0}, {"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...", (gptr*) &escaped, (gptr*) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"first-slave", 'x', "Locks all tables across all databases.", - (gptr*) &opt_first_slave, (gptr*) &opt_first_slave, 0, GET_BOOL, NO_ARG, + {"first-slave", 'x', "Deprecated, renamed to --lock-all-tables.", + (gptr*) &opt_lock_all_tables, (gptr*) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"flush-logs", 'F', "Flush logs file in server before starting dump. " - "Note that if you dump many databases at once (using the option " - "--databases= or --all-databases), the logs will be flushed for " - "each database dumped.", + "Note that if you dump many databases at once (using the option " + "--databases= or --all-databases), the logs will be flushed for " + "each database dumped. The exception is when using --lock-all-tables " + "or --master-data: " + "in this case the logs will be flushed only once, corresponding " + "to the moment all tables are locked. So if you want your dump and " + "the log flush to happen at the same exact moment you should use " + "--lock-all-tables or --master-data with --flush-logs", (gptr*) &flush_logs, (gptr*) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"force", 'f', "Continue even if we get an sql-error.", @@ -222,17 +230,40 @@ static struct my_option my_long_options[] = {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", (gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"lock-all-tables", 'x', "Locks all tables across all databases. This " + "is achieved by taking a global read lock for the duration of the whole " + "dump. Automatically turns --single-transaction and --lock-tables off.", + (gptr*) &opt_lock_all_tables, (gptr*) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, {"lock-tables", 'l', "Lock all tables for read.", (gptr*) &lock_tables, (gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, {"master-data", OPT_MASTER_DATA, - "This causes the master position and filename to be appended to your output. This automatically enables --first-slave.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + "This causes the binary log position and filename to be appended to the " + "output. If equal to 1, will print it as a CHANGE MASTER command; if equal" + " to 2, that command will be prefixed with a comment symbol. " + "This option will turn --lock-all-tables on, unless " + "--single-transaction is specified too (in which case a " + "global read lock is only taken a short time at the beginning of the dump " + "- don't forget to read about --single-transaction below). In all cases " + "any action on logs will happen at the exact moment of the dump." + "Option automatically turns --lock-tables off.", + (gptr*) &opt_master_data, (gptr*) &opt_master_data, 0, + GET_UINT, REQUIRED_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0}, {"no-autocommit", OPT_AUTOCOMMIT, "Wrap tables with autocommit/commit statements.", (gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + /* + Note that the combination --single-transaction --master-data + will give bullet-proof binlog position only if server >=4.1.3. That's the + old "FLUSH TABLES WITH READ LOCK does not block commit" fixed bug. + */ {"single-transaction", OPT_TRANSACTION, - "Dump all tables in single transaction to get consistent snapshot. Mutually exclusive with --lock-tables.", + "Creates a consistent snapshot by dumping all tables in a single " + "transaction. Works ONLY for tables stored in storage engines which " + "support multiversioning (currently only InnoDB does); the dump is NOT " + "guaranteed to be consistent for other storage engines. Option " + "automatically turns off --lock-tables.", (gptr*) &opt_single_transaction, (gptr*) &opt_single_transaction, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-create-db", 'n', @@ -472,14 +503,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { switch (optid) { - case OPT_MASTER_DATA: - opt_master_data=1; - opt_first_slave=1; - break; - case OPT_DELETE_MASTER_LOGS: - opt_delete_master_logs=1; - opt_first_slave=1; - break; case 'p': if (argument) { @@ -527,7 +550,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case (int) OPT_OPTIMIZE: extended_insert= opt_drop= opt_lock= quick= create_options= opt_disable_keys= lock_tables= opt_set_charset= 1; - if (opt_single_transaction) lock_tables=0; break; case (int) OPT_SKIP_OPTIMIZATION: extended_insert= opt_drop= opt_lock= quick= create_options= @@ -623,7 +645,19 @@ static int get_options(int *argc, char ***argv) "%s: You must use option --tab with --fields-...\n", my_progname); return(1); } - if (opt_single_transaction) + + /* Ensure consistency of the set of binlog & locking options */ + if (opt_delete_master_logs && !opt_master_data) + opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL; + if (opt_single_transaction && opt_lock_all_tables) + { + fprintf(stderr, "%s: You can't use --single-transaction and " + "--lock-all-tables at the same time.\n", my_progname); + return(1); + } + if (opt_master_data) + opt_lock_all_tables= !opt_single_transaction; + if (opt_single_transaction || opt_lock_all_tables) lock_tables= 0; if (enclosed && opt_enclosed) { @@ -670,6 +704,36 @@ static void DBerror(MYSQL *mysql, const char *when) } /* DBerror */ +/* + Sends a query to server, optionally reads result, prints error message if + some. + + SYNOPSIS + mysql_query_with_error_report() + mysql_con connection to use + res if non zero, result will be put there with mysql_store_result + query query to send to server + + RETURN VALUES + 0 query sending and (if res!=0) result reading went ok + 1 error +*/ + +static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, + const char *query) +{ + if (mysql_query(mysql_con, query) || + (res && !((*res)= mysql_store_result(mysql_con)))) + { + my_printf_error(0, "%s: Couldn't execute '%s': %s (%d)", + MYF(0), my_progname, query, + mysql_error(mysql_con), mysql_errno(mysql_con)); + return 1; + } + return 0; +} + + static void safe_exit(int error) { if (!first_error) @@ -717,12 +781,15 @@ static int dbConnect(char *host, char *user,char *passwd) DBerror(&mysql_connection, "when trying to connect"); return 1; } + /* + As we're going to set SQL_MODE, it would be lost on reconnect, so we + cannot reconnect. + */ + sock->reconnect= 0; sprintf(buff, "/*!40100 SET @@SQL_MODE=\"%s\" */", compatible_mode_normal_str); - if (mysql_query(sock, buff)) + if (mysql_query_with_error_report(sock, 0, buff)) { - fprintf(stderr, "%s: Can't set the compatible mode %s (error %s)\n", - my_progname, compatible_mode_normal_str, mysql_error(sock)); mysql_close(sock); safe_exit(EX_MYSQLERR); return 1; @@ -961,7 +1028,7 @@ static uint getTableStructure(char *table, char* db) result_table= quote_name(table, table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); - if (!opt_xml && !mysql_query(sock,insert_pat)) + if (!opt_xml && !mysql_query_with_error_report(sock, 0, insert_pat)) { /* using SHOW CREATE statement */ if (!tFlag) @@ -970,10 +1037,8 @@ static uint getTableStructure(char *table, char* db) char buff[20+FN_REFLEN]; sprintf(buff,"show create table %s", result_table); - if (mysql_query(sock, buff)) + if (mysql_query_with_error_report(sock, 0, buff)) { - fprintf(stderr, "%s: Can't get CREATE TABLE for table %s (%s)\n", - my_progname, result_table, mysql_error(sock)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1010,10 +1075,8 @@ static uint getTableStructure(char *table, char* db) mysql_free_result(tableRes); } sprintf(insert_pat,"show fields from %s", result_table); - if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock))) + if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) { - fprintf(stderr, "%s: Can't get info about table: %s\nerror: %s\n", - my_progname, result_table, mysql_error(sock)); if (path) my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); @@ -1053,10 +1116,8 @@ static uint getTableStructure(char *table, char* db) my_progname, mysql_error(sock)); sprintf(insert_pat,"show fields from %s", result_table); - if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock))) + if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) { - fprintf(stderr, "%s: Can't get info about table: %s\nerror: %s\n", - my_progname, result_table, mysql_error(sock)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1150,17 +1211,14 @@ static uint getTableStructure(char *table, char* db) char buff[20+FN_REFLEN]; uint keynr,primary_key; sprintf(buff,"show keys from %s", result_table); - if (mysql_query(sock, buff)) + if (mysql_query_with_error_report(sock, &tableRes, buff)) { - fprintf(stderr, "%s: Can't get keys for table %s (%s)\n", - my_progname, result_table, mysql_error(sock)); if (path) my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } - tableRes=mysql_store_result(sock); /* Find first which key is primary key */ keynr=0; primary_key=INT_MAX; @@ -1224,7 +1282,7 @@ static uint getTableStructure(char *table, char* db) char show_name_buff[FN_REFLEN]; sprintf(buff,"show table status like %s", quote_for_like(table, show_name_buff)); - if (mysql_query(sock, buff)) + if (mysql_query_with_error_report(sock, &tableRes, buff)) { if (mysql_errno(sock) != ER_PARSE_ERROR) { /* If old MySQL version */ @@ -1234,8 +1292,7 @@ static uint getTableStructure(char *table, char* db) result_table,mysql_error(sock)); } } - else if (!(tableRes=mysql_store_result(sock)) || - !(row=mysql_fetch_row(tableRes))) + else if (!(row=mysql_fetch_row(tableRes))) { fprintf(stderr, "Error: Couldn't read status information for table %s (%s)\n", @@ -1439,22 +1496,14 @@ static void dumpTable(uint numFields, char *table) fputs("\n", md_result_file); check_io(md_result_file); } - if (mysql_query(sock, query)) - { + if (mysql_query_with_error_report(sock, 0, query)) DBerror(sock, "when retrieving data from server"); - error= EX_CONSCHECK; - goto err; - } if (quick) res=mysql_use_result(sock); else res=mysql_store_result(sock); if (!res) - { DBerror(sock, "when retrieving data from server"); - error= EX_CONSCHECK; - goto err; - } if (verbose) fprintf(stderr, "-- Retrieving rows...\n"); if (mysql_num_fields(res) != numFields) @@ -1784,13 +1833,8 @@ static int dump_all_databases() MYSQL_RES *tableres; int result=0; - if (mysql_query(sock, "SHOW DATABASES") || - !(tableres = mysql_store_result(sock))) - { - my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s", - MYF(0), mysql_error(sock)); + if (mysql_query_with_error_report(sock, &tableres, "SHOW DATABASES")) return 1; - } while ((row = mysql_fetch_row(tableres))) { if (dump_all_tables_in_db(row[0])) @@ -1843,7 +1887,7 @@ static int init_dumping(char *database) sprintf(qbuf,"SHOW CREATE DATABASE WITH IF NOT EXISTS %s", qdatabase); - if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock))) + if (mysql_query_with_error_report(sock, &dbinfo, qbuf)) { /* Old server version, dump generic CREATE DATABASE */ fprintf(md_result_file, @@ -1912,7 +1956,7 @@ static int dump_all_tables_in_db(char *database) check_io(md_result_file); } if (lock_tables) - mysql_query(sock,"UNLOCK TABLES"); + mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"); return 0; } /* dump_all_tables_in_db */ @@ -1961,11 +2005,76 @@ static int dump_selected_tables(char *db, char **table_names, int tables) check_io(md_result_file); } if (lock_tables) - mysql_query(sock,"UNLOCK TABLES"); + mysql_query_with_error_report(sock, 0, "UNLOCK TABLES"); return 0; } /* dump_selected_tables */ +static int do_show_master_status(MYSQL *mysql_con) +{ + MYSQL_ROW row; + MYSQL_RES *master; + const char *comment_prefix= + (opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : ""; + if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS")) + { + my_printf_error(0, "Error: Couldn't execute 'SHOW MASTER STATUS': %s", + MYF(0), mysql_error(mysql_con)); + return 1; + } + else + { + row = mysql_fetch_row(master); + if (row && row[0] && row[1]) + { + if (opt_comments) + fprintf(md_result_file, + "\n--\n-- Position to start replication or point-in-time " + "recovery from\n--\n\n"); + fprintf(md_result_file, + "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", + comment_prefix, row[0], row[1]); + check_io(md_result_file); + } + mysql_free_result(master); + } + return 0; +} + + +static int do_flush_tables_read_lock(MYSQL *mysql_con) +{ + return + mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES WITH READ LOCK"); +} + + +static int do_unlock_tables(MYSQL *mysql_con) +{ + return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES"); +} + + +static int do_reset_master(MYSQL *mysql_con) +{ + return mysql_query_with_error_report(mysql_con, 0, "RESET MASTER"); +} + + +static int start_transaction(MYSQL *mysql_con, my_bool consistent_read_now) +{ + /* + We use BEGIN for old servers. --single-transaction --master-data will fail + on old servers, but that's ok as it was already silently broken (it didn't + do a consistent read, so better tell people frankly, with the error). + */ + return (mysql_query_with_error_report(mysql_con, 0, + consistent_read_now ? + "START TRANSACTION " + "WITH CONSISTENT SNAPSHOT" : + "BEGIN")); +} + static ulong find_set(TYPELIB *lib, const char *x, uint length, char **err_pos, uint *err_len) @@ -2063,7 +2172,7 @@ static const char *check_if_ignore_table(const char *table_name) sprintf(buff,"show table status like %s", quote_for_like(table_name, show_name_buff)); - if (mysql_query(sock, buff)) + if (mysql_query_with_error_report(sock, &res, buff)) { if (mysql_errno(sock) != ER_PARSE_ERROR) { /* If old MySQL version */ @@ -2074,8 +2183,7 @@ static const char *check_if_ignore_table(const char *table_name) return 0; /* assume table is ok */ } } - if (!(res= mysql_store_result(sock)) || - !(row= mysql_fetch_row(res))) + if (!(row= mysql_fetch_row(res))) { fprintf(stderr, "Error: Couldn't read status information for table %s (%s)\n", @@ -2094,8 +2202,6 @@ static const char *check_if_ignore_table(const char *table_name) int main(int argc, char **argv) { - MYSQL_ROW row; - MYSQL_RES *master; compatible_mode_normal_str[0]= 0; MY_INIT(argv[0]); @@ -2109,28 +2215,24 @@ int main(int argc, char **argv) if (!path) write_header(md_result_file, *argv); - if (opt_first_slave) + if ((opt_lock_all_tables || opt_master_data) && + do_flush_tables_read_lock(sock)) + goto err; + if (opt_single_transaction && start_transaction(sock, test(opt_master_data))) + goto err; + if (opt_delete_master_logs && do_reset_master(sock)) + goto err; + if (opt_lock_all_tables || opt_master_data) { - lock_tables=0; /* No other locks needed */ - if (mysql_query(sock, "FLUSH TABLES WITH READ LOCK")) - { - my_printf_error(0, "Error: Couldn't execute 'FLUSH TABLES WITH READ LOCK': %s", - MYF(0), mysql_error(sock)); - my_end(0); - return(first_error); - } - } - else if (opt_single_transaction) - { - /* There is no sense to start transaction if all tables are locked */ - if (mysql_query(sock, "BEGIN")) - { - my_printf_error(0, "Error: Couldn't execute 'BEGIN': %s", - MYF(0), mysql_error(sock)); - my_end(0); - return(first_error); - } + if (flush_logs && mysql_refresh(sock, REFRESH_LOG)) + goto err; + flush_logs= 0; /* not anymore; that would not be sensible */ } + if (opt_master_data && do_show_master_status(sock)) + goto err; + if (opt_single_transaction && do_unlock_tables(sock)) // unlock but no commit! + goto err; + if (opt_alldbs) dump_all_databases(); else if (argc > 1 && !opt_databases) @@ -2143,57 +2245,16 @@ int main(int argc, char **argv) /* One or more databases, all tables */ dump_databases(argv); } - - if (opt_first_slave) - { - if (opt_delete_master_logs && mysql_query(sock, "FLUSH MASTER")) - { - my_printf_error(0, "Error: Couldn't execute 'FLUSH MASTER': %s", - MYF(0), mysql_error(sock)); - } - if (opt_master_data) - { - if (mysql_query(sock, "SHOW MASTER STATUS") || - !(master = mysql_store_result(sock))) - my_printf_error(0, "Error: Couldn't execute 'SHOW MASTER STATUS': %s", - MYF(0), mysql_error(sock)); - else - { - row = mysql_fetch_row(master); - if (row && row[0] && row[1]) - { - if (opt_comments) - fprintf(md_result_file, - "\n--\n-- Position to start replication from\n--\n\n"); - fprintf(md_result_file, - "CHANGE MASTER TO MASTER_LOG_FILE='%s', \ -MASTER_LOG_POS=%s ;\n",row[0],row[1]); - check_io(md_result_file); - } - mysql_free_result(master); - } - } - if (mysql_query(sock, "UNLOCK TABLES")) - my_printf_error(0, "Error: Couldn't execute 'UNLOCK TABLES': %s", - MYF(0), mysql_error(sock)); - } - else if (opt_single_transaction) /* Just to make it beautiful enough */ #ifdef HAVE_SMEM my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR)); #endif - { - /* - In case we were locking all tables, we did not start transaction - so there is no need to commit it. - */ - - /* This should just free locks as we did not change anything */ - if (mysql_query(sock, "COMMIT")) - { - my_printf_error(0, "Error: Couldn't execute 'COMMIT': %s", - MYF(0), mysql_error(sock)); - } - } + /* + No reason to explicitely COMMIT the transaction, neither to explicitely + UNLOCK TABLES: these will be automatically be done by the server when we + disconnect now. Saves some code here, some network trips, adds nothing to + server. + */ +err: dbDisconnect(current_host); if (!path) write_footer(md_result_file); diff --git a/include/mysqld_error.h b/include/mysqld_error.h index 776869ff045..67c2b0aba73 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -319,4 +319,5 @@ #define ER_INVALID_CHARACTER_STRING 1300 #define ER_WARN_ALLOWED_PACKET_OVERFLOWED 1301 #define ER_CONFLICTING_DECLARATIONS 1302 -#define ER_ERROR_MESSAGES 303 +#define ER_NO_CONS_READ_ENGINE 1303 +#define ER_ERROR_MESSAGES 304 diff --git a/mysql-test/r/consistent_snapshot.result b/mysql-test/r/consistent_snapshot.result new file mode 100644 index 00000000000..90606abbe4e --- /dev/null +++ b/mysql-test/r/consistent_snapshot.result @@ -0,0 +1,15 @@ +drop table if exists t1; +create table t1 (a int) engine=innodb; +start transaction with consistent snapshot; +insert into t1 values(1); +select * from t1; +a +commit; +delete from t1; +start transaction; +insert into t1 values(1); +select * from t1; +a +1 +commit; +drop table t1; diff --git a/mysql-test/t/consistent_snapshot.test b/mysql-test/t/consistent_snapshot.test new file mode 100644 index 00000000000..7afdae36325 --- /dev/null +++ b/mysql-test/t/consistent_snapshot.test @@ -0,0 +1,41 @@ +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists t1; +--enable_warnings + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); + +### Test 1: +### - While a consistent snapshot transaction is executed, +### no external inserts should be visible to the transaction. + +connection con1; +create table t1 (a int) engine=innodb; +start transaction with consistent snapshot; + +connection con2; +insert into t1 values(1); + +connection con1; +select * from t1; # if consistent snapshot was set as expected, we +# should see nothing. +commit; + +### Test 2: +### - For any non-consistent snapshot transaction, external +### committed inserts should be visible to the transaction. + +delete from t1; +start transaction; # Now we omit WITH CONSISTENT SNAPSHOT + +connection con2; +insert into t1 values(1); + +connection con1; +select * from t1; # if consistent snapshot was not set, as expected, we +# should see 1. +commit; + +drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index cb88ab463d8..0c12579cbfd 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -771,6 +771,24 @@ int ha_savepoint(THD *thd, char *savepoint_name) DBUG_RETURN(error); } + +int ha_start_consistent_snapshot(THD *thd) +{ +#ifdef HAVE_INNOBASE_DB + if ((have_innodb == SHOW_OPTION_YES) && + !innobase_start_trx_and_assign_read_view(thd)) + return 0; +#endif + /* + Same idea as when one wants to CREATE TABLE in one engine which does not + exist: + */ + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_NO_CONS_READ_ENGINE, ER(ER_NO_CONS_READ_ENGINE)); + return 0; +} + + bool ha_flush_logs() { bool result=0; diff --git a/sql/handler.h b/sql/handler.h index a7ce4e708fd..fa19f136abf 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -138,6 +138,8 @@ #define HA_CACHE_TBL_ASKTRANSACT 2 #define HA_CACHE_TBL_TRANSACT 4 +/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */ +#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1 enum db_type { @@ -567,5 +569,4 @@ int ha_discover(THD* thd, const char* dbname, const char* name, int ha_find_files(THD *thd,const char *db,const char *path, const char *wild, bool dir,List* files); int ha_table_exists(THD* thd, const char* db, const char* name); - - +int ha_start_consistent_snapshot(THD *thd); diff --git a/sql/lex.h b/sql/lex.h index c64a7069c32..325d052de90 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -114,6 +114,7 @@ static SYMBOL symbols[] = { { "COMMITTED", SYM(COMMITTED_SYM)}, { "COMPRESSED", SYM(COMPRESSED_SYM)}, { "CONCURRENT", SYM(CONCURRENT)}, + { "CONSISTENT", SYM(CONSISTENT_SYM)}, { "CONSTRAINT", SYM(CONSTRAINT)}, { "CONVERT", SYM(CONVERT_SYM)}, { "CREATE", SYM(CREATE)}, @@ -382,6 +383,7 @@ static SYMBOL symbols[] = { { "SIGNED", SYM(SIGNED_SYM)}, { "SIMPLE", SYM(SIMPLE_SYM)}, { "SLAVE", SYM(SLAVE)}, + { "SNAPSHOT", SYM(SNAPSHOT_SYM)}, { "SMALLINT", SYM(SMALLINT)}, { "SOME", SYM(ANY_SYM)}, { "SONAME", SYM(UDF_SONAME_SYM)}, diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index 022a624c921..d352a6e82f7 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -331,3 +331,4 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index 18ebe5712f8..e84ee22d5cf 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -322,3 +322,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 54377b5949a..d9d33c3bf59 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -331,3 +331,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 8ede3f61a0b..fd43a2c10c5 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -319,3 +319,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index 5aab524e0d9..ae4d5279f35 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -324,3 +324,4 @@ character-set=latin7 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 355e784b156..5217133274b 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -319,3 +319,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index 03e838dd805..15f98d36e87 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -332,3 +332,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index 06f31a79a73..fae5c508320 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -319,3 +319,4 @@ character-set=greek "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index af10c33ee2d..6f83de7a64d 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -324,3 +324,4 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index cd66f15db5f..7df71e92fc4 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -319,3 +319,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index eaab58d8403..9fc2ead10d6 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -323,3 +323,4 @@ character-set=ujis "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 1cff50432e9..4e40ffc6264 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -319,3 +319,4 @@ character-set=euckr "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index 27f7a18f029..d78c59357f1 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -321,3 +321,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index 772f30e5d94..d0a282c444d 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -321,3 +321,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index 634a4d93f42..de812697482 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -324,3 +324,4 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index c79c346008e..262c472a4fa 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -321,3 +321,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 7cb0427dc3f..377ebfbf698 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -324,3 +324,4 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index df354d5797f..4edfd39c836 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -324,3 +324,4 @@ character-set=koi8r "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index 45b56c8269c..e18fa6d2811 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -312,3 +312,4 @@ character-set=cp1250 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index 12c3eb2b6af..d935439a1ba 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -327,3 +327,4 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index bd2439c44a6..97fb1bf0be5 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -323,3 +323,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index da75e4fcede..8de68600509 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -319,3 +319,4 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index a19cf946cb1..cf44fea6553 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -325,3 +325,4 @@ character-set=koi8u "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" +"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 268198f74a2..90c020b3e93 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -613,7 +613,7 @@ typedef struct st_lex uint uint_geom_type; uint grant, grant_tot_col, which_columns; uint fk_delete_opt, fk_update_opt, fk_match_option; - uint slave_thd_opt; + uint slave_thd_opt, start_transaction_opt; uint8 describe; bool drop_if_exists, drop_temporary, local_file, one_shot_set; bool in_comment, ignore_space, verbose, no_write_to_binlog; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f5b9bc0638f..d58fe027acf 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3076,6 +3076,12 @@ purposes internal to the MySQL server", MYF(0)); } case SQLCOM_UNLOCK_TABLES: + /* + It is critical for mysqldump --single-transaction --master-data that + UNLOCK TABLES does not implicitely commit a connection which has only + done FLUSH TABLES WITH READ LOCK + BEGIN. If this assumption becomes + false, mysqldump will not work. + */ unlock_locked_tables(thd); if (thd->options & OPTION_TABLE_LOCK) { @@ -3462,7 +3468,9 @@ purposes internal to the MySQL server", MYF(0)); thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; - send_ok(thd); + if (!(lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) || + !(res= ha_start_consistent_snapshot(thd))) + send_ok(thd); } break; case SQLCOM_COMMIT: diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 4538cb6e6ac..1ef91bcb257 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -131,6 +131,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token CLIENT_SYM %token COMMENT_SYM %token COMMIT_SYM +%token CONSISTENT_SYM %token COUNT_SYM %token CREATE %token CROSS @@ -165,6 +166,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SELECT_SYM %token SHOW %token SLAVE +%token SNAPSHOT_SYM %token SQL_THREAD %token START_SYM %token STD_SYM @@ -618,6 +620,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); table_option opt_if_not_exists opt_no_write_to_binlog opt_var_type opt_var_ident_type delete_option opt_temporary all_or_any opt_distinct opt_ignore_leaves fulltext_options spatial_type union_option + start_transaction_opts %type ULONG_NUM raid_types merge_insert_types @@ -2095,10 +2098,20 @@ slave: start: - START_SYM TRANSACTION_SYM { Lex->sql_command = SQLCOM_BEGIN;} - {} + START_SYM TRANSACTION_SYM start_transaction_opts + { + Lex->sql_command = SQLCOM_BEGIN; + Lex->start_transaction_opt= $3; + } ; +start_transaction_opts: + /*empty*/ { $$ = 0; } + | WITH CONSISTENT_SYM SNAPSHOT_SYM + { + $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT; + } + slave_thread_opts: { Lex->slave_thd_opt= 0; } slave_thread_opt_list @@ -5122,6 +5135,7 @@ keyword: | COMMIT_SYM {} | COMPRESSED_SYM {} | CONCURRENT {} + | CONSISTENT_SYM {} | CUBE_SYM {} | DATA_SYM {} | DATETIME {} @@ -5262,6 +5276,7 @@ keyword: | SHARE_SYM {} | SHUTDOWN {} | SLAVE {} + | SNAPSHOT_SYM {} | SOUNDS_SYM {} | SQL_CACHE_SYM {} | SQL_BUFFER_RESULT {} @@ -5888,7 +5903,7 @@ grant_option: ; begin: - BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN;} opt_work {} + BEGIN_SYM { Lex->sql_command = SQLCOM_BEGIN; Lex->start_transaction_opt= 0;} opt_work {} ; opt_work: From b6272b85fd9d7c15d74e051457a9614f86c33c15 Mon Sep 17 00:00:00 2001 From: "acurtis@pcgem.rdg.cyberkinetica.com" <> Date: Wed, 10 Nov 2004 18:53:16 +0000 Subject: [PATCH 48/94] Bug#6469 - REVOKE ALL synonymy bug --- sql/sql_yacc.yy | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 94c0fe3cf0c..2c1416e1bfd 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5612,7 +5612,7 @@ revoke_command: grant_privileges ON opt_table FROM user_list {} | - ALL PRIVILEGES ',' GRANT OPTION FROM user_list + ALL opt_privileges ',' GRANT OPTION FROM user_list { Lex->sql_command = SQLCOM_REVOKE_ALL; } @@ -5638,10 +5638,14 @@ grant: grant_privileges: grant_privilege_list {} - | ALL PRIVILEGES { Lex->grant = GLOBAL_ACLS;} - | ALL { Lex->grant = GLOBAL_ACLS;} + | ALL opt_privileges { Lex->grant = GLOBAL_ACLS;} ; +opt_privileges: + /* empty */ + | PRIVILEGES + ; + grant_privilege_list: grant_privilege | grant_privilege_list ',' grant_privilege; From 68130e428a47b2a9f7af1921c461df46fdf09316 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Thu, 11 Nov 2004 00:36:18 +0200 Subject: [PATCH 49/94] Added possibility to detect if libmysqld is restarted (Needed to check if memory allocated with mysql_once_init() has been freed) --- include/my_sys.h | 1 + mysys/my_init.c | 7 ++++--- sql/handler.cc | 38 +++++++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 01a7482e4d0..a8e21ea2f98 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -214,6 +214,7 @@ extern ulong my_cache_w_requests, my_cache_write, my_cache_r_requests, my_cache_read; extern ulong my_blocks_used, my_blocks_changed; extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; +extern uint mysys_usage_id; extern my_bool my_init_done; /* Point to current my_message() */ diff --git a/mysys/my_init.c b/mysys/my_init.c index 0ef938b434c..e9a61b1833c 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -42,8 +42,8 @@ static void netware_init(); #define netware_init() #endif - -my_bool my_init_done=0; +my_bool my_init_done= 0; +uint mysys_usage_id= 0; /* Incremented for each my_init() */ static ulong atoi_octal(const char *str) { @@ -51,7 +51,7 @@ static ulong atoi_octal(const char *str) while (*str && my_isspace(&my_charset_latin1, *str)) str++; str2int(str, - (*str == '0' ? 8 : 10), /* Octalt or decimalt */ + (*str == '0' ? 8 : 10), /* Octalt or decimalt */ 0, INT_MAX, &tmp); return (ulong) tmp; } @@ -74,6 +74,7 @@ my_bool my_init(void) if (my_init_done) return 0; my_init_done=1; + mysys_usage_id++; #if defined(THREAD) && defined(SAFE_MUTEX) safe_mutex_global_init(); /* Must be called early */ #endif diff --git a/sql/handler.cc b/sql/handler.cc index 2c274c7989e..34a903cf2c0 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -110,6 +110,7 @@ TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"", tx_isolation_names, NULL}; static TYPELIB known_extensions= {0,"known_exts", NULL, NULL}; +uint known_extensions_id= 0; enum db_type ha_resolve_by_name(const char *name, uint namelen) { @@ -1635,6 +1636,7 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key, return error; } + /* Returns a list of all known extensions. @@ -1643,20 +1645,24 @@ int handler::index_read_idx(byte * buf, uint index, const byte * key, NOTES No mutexes, worst case race is a minor surplus memory allocation + We have to recreate the extension map if mysqld is restarted (for example + within libmysqld) RETURN VALUE pointer pointer to TYPELIB structure */ + TYPELIB *ha_known_exts(void) { - if (!known_extensions.type_names) + if (!known_extensions.type_names || mysys_usage_id != known_extensions_id) { show_table_type_st *types; List found_exts; List_iterator_fast it(found_exts); - const char *e, **ext; - - found_exts.push_back(".db"); + const char **ext, *old_ext; + + known_extensions_id= mysys_usage_id; + found_exts.push_back((char*) ".db"); for (types= sys_table_types; types->type; types++) { if (*types->value == SHOW_OPTION_YES) @@ -1664,28 +1670,30 @@ TYPELIB *ha_known_exts(void) handler *file= get_new_handler(0,(enum db_type) types->db_type); for (ext= file->bas_ext(); *ext; ext++) { - while (e=it++) - if (e == *ext) + while ((old_ext= it++)) + { + if (!strcmp(old_ext, *ext)) break; - - if (!e) - found_exts.push_back((char *)*ext); + } + if (!old_ext) + found_exts.push_back((char *) *ext); it.rewind(); } delete file; } } - ext= (const char **)my_once_alloc(sizeof(char *)* - (found_exts.elements+1), MYF(MY_WME)); + ext= (const char **) my_once_alloc(sizeof(char *)* + (found_exts.elements+1), + MYF(MY_WME | MY_FAE)); DBUG_ASSERT(ext); - for (uint i=0; e=it++; i++) - ext[i]= e; - ext[found_exts.elements]= 0; - known_extensions.count= found_exts.elements; known_extensions.type_names= ext; + + while ((old_ext= it++)) + *ext++= old_ext; + *ext= 0; } return &known_extensions; } From 09da85338cdc7e61507a3f0a638c4eb25db2c325 Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Thu, 11 Nov 2004 00:00:17 +0100 Subject: [PATCH 50/94] no new message in 4.1 (causes merge issues with 5.0). Using ER_UNKNOW_ERROR and hardcoded message string instead. --- include/mysqld_error.h | 3 +-- sql/handler.cc | 5 +++-- sql/share/czech/errmsg.txt | 1 - sql/share/danish/errmsg.txt | 1 - sql/share/dutch/errmsg.txt | 1 - sql/share/english/errmsg.txt | 1 - sql/share/estonian/errmsg.txt | 1 - sql/share/french/errmsg.txt | 1 - sql/share/german/errmsg.txt | 1 - sql/share/greek/errmsg.txt | 1 - sql/share/hungarian/errmsg.txt | 1 - sql/share/italian/errmsg.txt | 1 - sql/share/japanese/errmsg.txt | 1 - sql/share/korean/errmsg.txt | 1 - sql/share/norwegian-ny/errmsg.txt | 1 - sql/share/norwegian/errmsg.txt | 1 - sql/share/polish/errmsg.txt | 1 - sql/share/portuguese/errmsg.txt | 1 - sql/share/romanian/errmsg.txt | 1 - sql/share/russian/errmsg.txt | 1 - sql/share/serbian/errmsg.txt | 1 - sql/share/slovak/errmsg.txt | 1 - sql/share/spanish/errmsg.txt | 1 - sql/share/swedish/errmsg.txt | 1 - sql/share/ukrainian/errmsg.txt | 1 - 25 files changed, 4 insertions(+), 27 deletions(-) diff --git a/include/mysqld_error.h b/include/mysqld_error.h index 67c2b0aba73..776869ff045 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -319,5 +319,4 @@ #define ER_INVALID_CHARACTER_STRING 1300 #define ER_WARN_ALLOWED_PACKET_OVERFLOWED 1301 #define ER_CONFLICTING_DECLARATIONS 1302 -#define ER_NO_CONS_READ_ENGINE 1303 -#define ER_ERROR_MESSAGES 304 +#define ER_ERROR_MESSAGES 303 diff --git a/sql/handler.cc b/sql/handler.cc index 32f5ad6ff1d..c1a105a4633 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -785,8 +785,9 @@ int ha_start_consistent_snapshot(THD *thd) Same idea as when one wants to CREATE TABLE in one engine which does not exist: */ - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_NO_CONS_READ_ENGINE, ER(ER_NO_CONS_READ_ENGINE)); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, + "This MySQL server does not support any " + "consistent-read capable storage engine"); return 0; } diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index d352a6e82f7..022a624c921 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -331,4 +331,3 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index e84ee22d5cf..18ebe5712f8 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -322,4 +322,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index d9d33c3bf59..54377b5949a 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -331,4 +331,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index fd43a2c10c5..8ede3f61a0b 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -319,4 +319,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index ae4d5279f35..5aab524e0d9 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -324,4 +324,3 @@ character-set=latin7 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 5217133274b..355e784b156 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -319,4 +319,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index 15f98d36e87..03e838dd805 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -332,4 +332,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index fae5c508320..06f31a79a73 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -319,4 +319,3 @@ character-set=greek "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index 6f83de7a64d..af10c33ee2d 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -324,4 +324,3 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index 7df71e92fc4..cd66f15db5f 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -319,4 +319,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index 9fc2ead10d6..eaab58d8403 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -323,4 +323,3 @@ character-set=ujis "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 4e40ffc6264..1cff50432e9 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -319,4 +319,3 @@ character-set=euckr "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index d78c59357f1..27f7a18f029 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -321,4 +321,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index d0a282c444d..772f30e5d94 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -321,4 +321,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index de812697482..634a4d93f42 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -324,4 +324,3 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 262c472a4fa..c79c346008e 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -321,4 +321,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 377ebfbf698..7cb0427dc3f 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -324,4 +324,3 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 4edfd39c836..df354d5797f 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -324,4 +324,3 @@ character-set=koi8r "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index e18fa6d2811..45b56c8269c 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -312,4 +312,3 @@ character-set=cp1250 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index d935439a1ba..12c3eb2b6af 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -327,4 +327,3 @@ character-set=latin2 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 97fb1bf0be5..bd2439c44a6 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -323,4 +323,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index 8de68600509..da75e4fcede 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -319,4 +319,3 @@ character-set=latin1 "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index cf44fea6553..a19cf946cb1 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -325,4 +325,3 @@ character-set=koi8u "Invalid %s character string: '%.64s'", "Result of %s() was larger than max_allowed_packet (%ld) - truncated" "Conflicting declarations: '%s%s' and '%s%s'" -"This MySQL server does not support any consistent-read capable storage engine" From 9ee3bf9efa9f73617b2a693283f18ffaf9f4ebae Mon Sep 17 00:00:00 2001 From: "paul@ice.snake.net" <> Date: Wed, 10 Nov 2004 22:43:09 -0600 Subject: [PATCH 51/94] fill_help_tables.sh: Handle some additional Texinfo tags that were being missed. --- scripts/fill_help_tables.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/fill_help_tables.sh b/scripts/fill_help_tables.sh index cb5437f7178..1f44e9fa488 100644 --- a/scripts/fill_help_tables.sh +++ b/scripts/fill_help_tables.sh @@ -197,6 +197,9 @@ sub prepare_name $a =~ s/(\@node(.*?)\n)/ /g; $a =~ s/(\@tab)/\t/g; $a =~ s/\@item/ /g; + $a =~ s/\@minus\{\}/-/g; + $a =~ s/\@var\{((.|\n)+?)\}/$1/go; + $a =~ s/\@command\{((.|\n)+?)\}/$1/go; $a =~ s/\@code\{((.|\n)+?)\}/$1/go; $a =~ s/\@strong\{(.+?)\}/$1/go; $a =~ s/\@samp\{(.+?)\}/$1/go; @@ -244,6 +247,9 @@ sub prepare_description $a =~ s/(\@item)/ /g; $a =~ s/(\@tindex\s(.*?)\n)//g; $a =~ s/(\@c\s(.*?)\n)//g; + $a =~ s/\@minus\{\}/-/g; + $a =~ s/\@var\{((.|\n)+?)\}/$1/go; + $a =~ s/\@command\{((.|\n)+?)\}/$1/go; $a =~ s/\@code\{((.|\n)+?)\}/$1/go; $a =~ s/\@strong\{(.+?)\}/$1/go; $a =~ s/\@samp\{(.+?)\}/$1/go; @@ -273,6 +279,7 @@ sub prepare_example $a =~ s/(^\@c for_help_topic(.*?)\n)//g; + $a =~ s/\@var\{((.|\n)+?)\}/$1/go; $a =~ s/\\/\\\\/g; $a =~ s/(\@{)/{/g; $a =~ s/(\@})/}/g; From 582f9a8900e6a58ba361e71be83aa580e6cfd98e Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Thu, 11 Nov 2004 10:50:46 +0400 Subject: [PATCH 52/94] Added ending ';' for the start_transaction_opts: --- sql/sql_yacc.yy | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1852101fcfb..7fa6549686b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2111,6 +2111,7 @@ start_transaction_opts: { $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT; } + ; slave_thread_opts: { Lex->slave_thd_opt= 0; } From 1d967b8dcf86ea644dabd39b9f0fe0695ec79c17 Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Thu, 11 Nov 2004 12:35:55 +0400 Subject: [PATCH 53/94] A fix (bug #6551: UMASK_DIR & UMASK not taken into account (mysqld.cc my_init.c inconsistency)). my_umask and my_umask_dir initialization has been moved to the my_init() func. --- mysys/my_init.c | 2 ++ sql/mysqld.cc | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysys/my_init.c b/mysys/my_init.c index e9a61b1833c..c32fcfe6a09 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -75,6 +75,8 @@ my_bool my_init(void) return 0; my_init_done=1; mysys_usage_id++; + my_umask= 0660; /* Default umask for new files */ + my_umask_dir= 0700; /* Default umask for new directories */ #if defined(THREAD) && defined(SAFE_MUTEX) safe_mutex_global_init(); /* Must be called early */ #endif diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5622ac50a7b..4b70e8552b5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2305,8 +2305,6 @@ bool init_global_datetime_format(timestamp_type format_type, static int init_common_variables(const char *conf_file_name, int argc, char **argv, const char **groups) { - my_umask=0660; // Default umask for new files - my_umask_dir=0700; // Default umask for new directories umask(((~my_umask) & 0666)); tzset(); // Set tzname From 91a40d42208c3b2b0778f6ac82c0a6241046960d Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Thu, 11 Nov 2004 10:24:16 +0100 Subject: [PATCH 54/94] Fix for autobuild failure: forgotten ';' (bison 1.875 accepts if it's not there, but 1.75 does not) --- sql/sql_yacc.yy | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1852101fcfb..7fa6549686b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2111,6 +2111,7 @@ start_transaction_opts: { $$= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT; } + ; slave_thread_opts: { Lex->slave_thd_opt= 0; } From 6a9cbe487e957f83d20d85ee78afcbe84b6d5b47 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 10:05:28 +0000 Subject: [PATCH 55/94] added ndb error codes and better explanations --- ndb/src/ndbapi/ndberror.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index 17a80082023..b0e59e9ead2 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -124,7 +124,8 @@ ErrorBundle ErrorCodes[] = { { 217, TR, "217" }, { 218, TR, "218" }, { 219, TR, "219" }, - { 233, TR, "Out of operation records in transaction coordinator" }, + { 233, TR, + "Out of operation records in transaction coordinator (increase MaxNoOfConcurrentOperations)" }, { 275, TR, "275" }, { 279, TR, "Out of transaction markers in transaction coordinator" }, { 414, TR, "414" }, @@ -137,7 +138,7 @@ ErrorBundle ErrorCodes[] = { { 830, TR, "Out of add fragment operation records" }, { 873, TR, "Out of attrinfo records for scan in tuple manager" }, { 1217, TR, "1217" }, - { 1219, TR, "Out of operation records in local data manager" }, + { 1219, TR, "Out of operation records in local data manager (increase MaxNoOfLocalOperations)" }, { 1220, TR, "1220" }, { 1222, TR, "Out of transaction markers in LQH" }, { 4021, TR, "Out of Send Buffer space in NDB API" }, @@ -149,9 +150,10 @@ ErrorBundle ErrorCodes[] = { */ { 623, IS, "623" }, { 624, IS, "624" }, - { 625, IS, "Out of memory in Ndb Kernel, index part" }, + { 625, IS, "Out of memory in Ndb Kernel, index part (increase IndexMemory)" }, + { 800, IS, "Too many ordered indexes (increase MaxNoOfOrderedIndexes)" }, { 826, IS, "Too many tables and attributes (increase MaxNoOfAttributes)" }, - { 827, IS, "Out of memory in Ndb Kernel, data part" }, + { 827, IS, "Out of memory in Ndb Kernel, data part (increase DataMemory)" }, { 832, IS, "832" }, /** @@ -168,10 +170,10 @@ ErrorBundle ErrorCodes[] = { * OverloadError */ { 410, OL, "Out of log file space temporarily" }, - { 677, OL, "Index UNDO buffers overloaded" }, - { 891, OL, "Data UNDO buffers overloaded" }, - { 1221, OL, "REDO log buffers overloaded" }, - { 4006, OL, "Connect failure - out of connection objects" }, + { 677, OL, "Index UNDO buffers overloaded (increase UndoIndexBuffer)" }, + { 891, OL, "Data UNDO buffers overloaded (increase UndoDataBuffer)" }, + { 1221, OL, "REDO log buffers overloaded (increase RedoBuffer)" }, + { 4006, OL, "Connect failure - out of connection objects (increase MaxNoOfConcurrentTransactions)" }, @@ -241,9 +243,9 @@ ErrorBundle ErrorCodes[] = { { 884, AE, "Stack overflow in interpreter" }, { 885, AE, "Stack underflow in interpreter" }, { 886, AE, "More than 65535 instructions executed in interpreter" }, - { 4256, AE, "Must call Ndb::init() before this function" }, + { 4256, AE, "Must call Ndb::init() before this function" }, { 880, AE, "Tried to read too much - too many getValue calls" }, - { 4257, AE, "Tried to read too much - too many getValue calls" }, + { 4257, AE, "Tried to read too much - too many getValue calls" }, /** * Scan application errors From fd39778fcf692b5fcaa2716ac26f4fdcf827c094 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 11:08:37 +0000 Subject: [PATCH 56/94] ndbcluster.sh: fixed typo --- mysql-test/ndb/ndbcluster.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/ndb/ndbcluster.sh b/mysql-test/ndb/ndbcluster.sh index 3486a879eec..60188705857 100644 --- a/mysql-test/ndb/ndbcluster.sh +++ b/mysql-test/ndb/ndbcluster.sh @@ -36,7 +36,7 @@ else exec_mgmtsrvr=$BASEDIR/bin/ndb_mgmd fi exec_waiter=$BASEDIR/bin/ndb_waiter - exec_waiter=$BASEDIR/bin/ndb_test_platform + exec_test=$BASEDIR/bin/ndb_test_platform exec_mgmtclient=$BASEDIR/bin/ndb_mgm fi From 20eb74dcdaec9525b759982294253bccfef85c5b Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Thu, 11 Nov 2004 14:59:13 +0200 Subject: [PATCH 57/94] Write fatal errors even if silent is used in client_test --- mysql-test/t/client_test.test | 2 +- tests/client_test.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/t/client_test.test b/mysql-test/t/client_test.test index 830c5f1b8a2..66f5e69eb36 100644 --- a/mysql-test/t/client_test.test +++ b/mysql-test/t/client_test.test @@ -1,2 +1,2 @@ --disable_result_log ---exec $TESTS_BINDIR/client_test --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent +--exec $TESTS_BINDIR/client_test --no-defaults --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent diff --git a/tests/client_test.c b/tests/client_test.c index 3c5598ee75a..45d66a92977 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -215,6 +215,7 @@ static void client_connect() if (!(mysql= mysql_init(NULL))) { + opt_silent= 0; myerror("mysql_init() failed"); exit(1); } @@ -223,6 +224,7 @@ static void client_connect() opt_password, opt_db ? opt_db:"test", opt_port, opt_unix_socket, 0))) { + opt_silent= 0; myerror("connection failed"); mysql_close(mysql); fprintf(stdout, "\n Check the connection options using --help or -?\n"); From e0a3e48f7ef6eb1991dfa74020ddb172f4fee15b Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 13:22:33 +0000 Subject: [PATCH 58/94] forgot a return 0 removed some errorcodes not used --- ndb/src/mgmclient/CommandInterpreter.cpp | 1 + ndb/src/ndbapi/ndberror.c | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index f1a953769b8..fde4e5a2e91 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -200,6 +200,7 @@ extern "C" { int ndb_mgmclient_handle_destroy(Ndb_mgmclient_handle h) { delete (Ndb_mgmclient*)h; + return 0; } } /* diff --git a/ndb/src/ndbapi/ndberror.c b/ndb/src/ndbapi/ndberror.c index b0e59e9ead2..1a0d8132d71 100644 --- a/ndb/src/ndbapi/ndberror.c +++ b/ndb/src/ndbapi/ndberror.c @@ -152,7 +152,7 @@ ErrorBundle ErrorCodes[] = { { 624, IS, "624" }, { 625, IS, "Out of memory in Ndb Kernel, index part (increase IndexMemory)" }, { 800, IS, "Too many ordered indexes (increase MaxNoOfOrderedIndexes)" }, - { 826, IS, "Too many tables and attributes (increase MaxNoOfAttributes)" }, + { 826, IS, "Too many tables and attributes (increase MaxNoOfAttributes or MaxNoOfTables)" }, { 827, IS, "Out of memory in Ndb Kernel, data part (increase DataMemory)" }, { 832, IS, "832" }, @@ -290,7 +290,7 @@ ErrorBundle ErrorCodes[] = { { 283, SE, "Table is being dropped" }, { 284, SE, "Table not defined in transaction coordinator" }, { 285, SE, "Unknown table error in transaction coordinator" }, - { 881, SE, "Unable to create table, out of data pages" }, + { 881, SE, "Unable to create table, out of data pages (increase DataMemory) " }, { 1225, SE, "Table not defined in local query handler" }, { 1226, SE, "Table is being dropped" }, { 1228, SE, "Cannot use drop table for drop index" }, @@ -346,17 +346,11 @@ ErrorBundle ErrorCodes[] = { { 4327, AE, "Distribution Group with 1 byte attribute is not allowed" }, { 4328, AE, "Disk memory attributes not yet supported" }, { 4329, AE, "Variable stored attributes not yet supported" }, - { 4330, AE, "Table names limited to 127 bytes" }, - { 4331, AE, "Attribute names limited to 31 bytes" }, - { 4332, AE, "Maximum 2000 attributes in a table" }, - { 4333, AE, "Maximum 4092 bytes long keys allowed" }, - { 4334, AE, "Attribute properties length limited to 127 bytes" }, { 4400, AE, "Status Error in NdbSchemaCon" }, { 4401, AE, "Only one schema operation per schema transaction" }, { 4402, AE, "No schema operation defined before calling execute" }, - { 4500, AE, "Cannot handle more than 2048 tables in NdbApi" }, { 4501, AE, "Insert in hash table failed when getting table information from Ndb" }, { 4502, AE, "GetValue not allowed in Update operation" }, { 4503, AE, "GetValue not allowed in Insert operation" }, From 4f0421787936ead1927aa3d33d6942023559ad4a Mon Sep 17 00:00:00 2001 From: "jani@a80-186-24-72.elisa-laajakaista.fi" <> Date: Thu, 11 Nov 2004 16:20:39 +0200 Subject: [PATCH 59/94] Removed check for .ini file elsewhere, except on Windows. --- mysys/default.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mysys/default.c b/mysys/default.c index 416de09b661..d260dd4b370 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -60,7 +60,11 @@ DATADIR, NullS, }; +#ifdef __WIN__ static const char *f_extensions[]= { ".ini", ".cnf", 0 }; +#else +static const char *f_extensions[]= { ".cnf", 0 }; +#endif static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, const char *dir, const char *config_file, From 98df9313c014310890dc744a6913e8f71260999c Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Thu, 11 Nov 2004 18:20:40 +0400 Subject: [PATCH 60/94] A fix (bug #6564: QUOTE(NULL) returns NULL, not the string 'NULL') --- mysql-test/r/func_str.result | 5 ++++- mysql-test/t/func_str.test | 6 ++++++ sql/item_strfunc.cc | 14 +++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index b4d1be5bd54..d38a2edfa1a 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -167,6 +167,9 @@ length(quote(concat(char(0),"test"))) select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))); hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))) 27E0E3E6E7E8EAEB27 +select concat('a', quote(NULL)); +concat('a', quote(NULL)) +aNULL select reverse(""); reverse("") @@ -278,7 +281,7 @@ insert into t1 values ('one'),(NULL),('two'),('four'); select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1; a quote(a) isnull(quote(a)) quote(a) is null ifnull(quote(a), 'n') one 'one' 0 0 'one' -NULL NULL 1 1 n +NULL NULL 0 0 NULL two 'two' 0 0 'two' four 'four' 0 0 'four' drop table t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index ba6a8b55236..1ae4db3a42a 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -69,6 +69,12 @@ select quote(1/0), quote('\0\Z'); select length(quote(concat(char(0),"test"))); select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235)))); +# +# Bug #6564: QUOTE(NULL +# + +select concat('a', quote(NULL)); + # # Wrong usage of functions # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9248cbc0217..53a9d3fe219 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2142,9 +2142,12 @@ String* Item_func_inet_ntoa::val_str(String* str) This function is very useful when you want to generate SQL statements - RETURN VALUES + NOTE + QUOTE(NULL) returns the string 'NULL' (4 letters, without quotes). + + RETURN VALUES str Quoted string - NULL Argument to QUOTE() was NULL or out of memory. + NULL Out of memory. */ #define get_esc_bit(mask, num) (1 & (*((mask) + ((num) >> 3))) >> ((num) & 7)) @@ -2168,7 +2171,12 @@ String *Item_func_quote::val_str(String *str) String *arg= args[0]->val_str(str); uint arg_length, new_length; if (!arg) // Null argument - goto null; + { + str->copy("NULL", 4); // Return the string 'NULL' + null_value= 0; + return str; + } + arg_length= arg->length(); new_length= arg_length+2; /* for beginning and ending ' signs */ From 54dac2cfacd931a3afc972d380ae2a27ee38be6b Mon Sep 17 00:00:00 2001 From: "jani@a80-186-24-72.elisa-laajakaista.fi" <> Date: Thu, 11 Nov 2004 16:59:36 +0200 Subject: [PATCH 61/94] Some code clean-up and optimization. --- mysys/default.c | 90 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/mysys/default.c b/mysys/default.c index d260dd4b370..16e166a3ca5 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -68,7 +68,12 @@ static const char *f_extensions[]= { ".cnf", 0 }; static int search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, const char *dir, const char *config_file, - const char *ext, TYPELIB *group); + TYPELIB *group); + +static int search_default_file_with_ext(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, + const char *dir, const char *ext, + const char *config_file, + TYPELIB *group); static char *remove_end_comment(char *ptr); @@ -164,15 +169,16 @@ int load_defaults(const char *conf_file, const char **groups, goto err; if (forced_default_file) { - if ((error= search_default_file(&args, &alloc, "", - forced_default_file, "", &group)) < 0) + if ((error= search_default_file_with_ext(&args, &alloc, "", "", + forced_default_file, + &group)) < 0) goto err; } else if (dirname_length(conf_file)) { for (ext= (char**) f_extensions; *ext; *ext++) if ((error= search_default_file(&args, &alloc, NullS, conf_file, - *ext, &group)) < 0) + &group)) < 0) goto err; } else @@ -180,33 +186,31 @@ int load_defaults(const char *conf_file, const char **groups, #ifdef __WIN__ char system_dir[FN_REFLEN]; GetWindowsDirectory(system_dir,sizeof(system_dir)); - for (ext= (char**) f_extensions; *ext; *ext++) - if ((search_default_file(&args, &alloc, system_dir, conf_file, - *ext, &group))) - goto err; + if ((search_default_file(&args, &alloc, system_dir, conf_file, &group))) + goto err; #endif #if defined(__EMX__) || defined(OS2) - for (ext= (char**) f_extensions; *ext; *ext++) - if (getenv("ETC") && - (search_default_file(&args, &alloc, getenv("ETC"), conf_file, - *ext, &group)) < 0) - goto err; + { + const char *etc; + if ((etc= getenv("ETC")) && + (search_default_file(&args, &alloc, etc, conf_file, + &group)) < 0) + goto err; + } #endif for (dirs=default_directories ; *dirs; dirs++) { if (**dirs) { - for (ext= (char**) f_extensions; *ext; *ext++) - if (search_default_file(&args, &alloc, *dirs, conf_file, - *ext, &group) < 0) - goto err; + if (search_default_file(&args, &alloc, *dirs, conf_file, + &group) < 0) + goto err; } else if (defaults_extra_file) { - for (ext= (char**) f_extensions; *ext; *ext++) - if (search_default_file(&args, &alloc, NullS, defaults_extra_file, - *ext, &group) < 0) - goto err; /* Fatal error */ + if (search_default_file(&args, &alloc, NullS, defaults_extra_file, + &group) < 0) + goto err; /* Fatal error */ } } } @@ -267,11 +271,28 @@ void free_defaults(char **argv) } +static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, + const char *dir, + const char *config_file, TYPELIB *group) +{ + char **ext; + + for (ext= (char**) f_extensions; *ext; *ext++) + { + int error; + if ((error= search_default_file_with_ext(args, alloc, dir, *ext, + config_file, group)) < 0) + return error; + } + return 0; +} + + /* Open a configuration file (if exists) and read given options from it SYNOPSIS - search_default_file() + search_default_file_with_ext() args Store pointer to found options here alloc Allocate strings in this object dir directory to read @@ -286,9 +307,10 @@ void free_defaults(char **argv) 2 File is not a regular file (Warning) */ -static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group) +static int search_default_file_with_ext(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, + const char *dir, const char *ext, + const char *config_file, + TYPELIB *group) { char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp; FILE *fp; @@ -482,7 +504,7 @@ static char *remove_end_comment(char *ptr) void print_defaults(const char *conf_file, const char **groups) { #ifdef __WIN__ - bool have_ext=fn_ext(conf_file)[0] != 0; + my_bool have_ext= fn_ext(conf_file)[0] != 0; #endif char name[FN_REFLEN], **ext; const char **dirs; @@ -495,16 +517,24 @@ void print_defaults(const char *conf_file, const char **groups) { #ifdef __WIN__ GetWindowsDirectory(name,sizeof(name)); - if (have_ext) + if (!have_ext) + { for (ext= (char**) f_extensions; *ext; *ext++) printf("%s\\%s%s ", name, conf_file, *ext); + } else printf("%s\\%s ", name, conf_file); #endif #if defined(__EMX__) || defined(OS2) - for (ext= (char**) f_extensions; *ext; *ext++) - if (getenv("ETC")) - printf("%s\\%s%s ", getenv("ETC"), conf_file, *ext); + { + const char *etc; + + if ((etc= getenv("ETC"))) + { + for (ext= (char**) f_extensions; *ext; *ext++) + printf("%s\\%s%s ", etc, conf_file, *ext); + } + } #endif for (dirs=default_directories ; *dirs; dirs++) { From 399ad08e4fbe3c7ba9da89a4c7a947a16c7e3e4b Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 15:53:33 +0000 Subject: [PATCH 62/94] basestring_vsnprintf fix for size==0 --- ndb/src/common/util/basestring_vsnprintf.c | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/ndb/src/common/util/basestring_vsnprintf.c b/ndb/src/common/util/basestring_vsnprintf.c index 1b4d88679c1..8a58ca0fe5c 100644 --- a/ndb/src/common/util/basestring_vsnprintf.c +++ b/ndb/src/common/util/basestring_vsnprintf.c @@ -20,6 +20,10 @@ #include #include + +/* + #define SNPRINTF_RETURN_TRUNC +*/ int basestring_snprintf(char *str, size_t size, const char *format, ...) { @@ -47,13 +51,27 @@ static char basestring_vsnprintf_buf[16*1024]; int basestring_vsnprintf(char *str, size_t size, const char *format, va_list ap) { - int ret= BASESTRING_VSNPRINTF_FUNC(str, size, format, ap); + if (size == 0) + { #ifdef SNPRINTF_RETURN_TRUNC - if (ret == size-1 || ret == -1) { - ret= BASESTRING_VSNPRINTF_FUNC(basestring_vsnprintf_buf, - sizeof(basestring_vsnprintf_buf), - format, ap); - } + return BASESTRING_VSNPRINTF_FUNC(basestring_vsnprintf_buf, + sizeof(basestring_vsnprintf_buf), + format, ap); +#else + char buf[1]; + return BASESTRING_VSNPRINTF_FUNC(buf, 1, format, ap); #endif - return ret; + } + { + int ret= BASESTRING_VSNPRINTF_FUNC(str, size, format, ap); +#ifdef SNPRINTF_RETURN_TRUNC + if (ret == size-1 || ret == -1) + { + ret= BASESTRING_VSNPRINTF_FUNC(basestring_vsnprintf_buf, + sizeof(basestring_vsnprintf_buf), + format, ap); + } +#endif + return ret; + } } From 33bb73da6797e906f51fc6dee17714e39b7cd6ae Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 16:06:47 +0000 Subject: [PATCH 63/94] mysql-test-run.sh: made sleep time for second master larger so that it has time to start --- mysql-test/mysql-test-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index fcb9e5eee2d..27eae89922c 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -227,7 +227,7 @@ DO_CLIENT_GDB="" SLEEP_TIME_AFTER_RESTART=1 SLEEP_TIME_FOR_DELETE=10 SLEEP_TIME_FOR_FIRST_MASTER=400 # Enough time to create innodb tables -SLEEP_TIME_FOR_SECOND_MASTER=30 +SLEEP_TIME_FOR_SECOND_MASTER=400 SLEEP_TIME_FOR_FIRST_SLAVE=400 SLEEP_TIME_FOR_SECOND_SLAVE=30 CHARACTER_SET=latin1 From 37d1b4ecd57047423414edd23aefacf065329b6b Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 16:38:15 +0000 Subject: [PATCH 64/94] waiter.cpp: fixed so that connectring option works --- ndb/tools/waiter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndb/tools/waiter.cpp b/ndb/tools/waiter.cpp index c9e76bb8ed3..be572d7c275 100644 --- a/ndb/tools/waiter.cpp +++ b/ndb/tools/waiter.cpp @@ -86,7 +86,7 @@ int main(int argc, char** argv){ if (_hostName == NULL){ LocalConfig lcfg; - if(!lcfg.init()) + if(!lcfg.init(opt_connect_str, 0)) { lcfg.printError(); lcfg.printUsage(); From 09ee97341148b37c972b411770d118e4c4c52385 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 11 Nov 2004 16:51:38 +0000 Subject: [PATCH 65/94] ndb_test_platform.cpp: better printouts in ndb_test_platform --- ndb/tools/ndb_test_platform.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ndb/tools/ndb_test_platform.cpp b/ndb/tools/ndb_test_platform.cpp index 2b8bbd0274b..72dd146dacd 100644 --- a/ndb/tools/ndb_test_platform.cpp +++ b/ndb/tools/ndb_test_platform.cpp @@ -32,19 +32,21 @@ int test_snprintf(const char * fmt, int buf_sz, int result) if(ret < 0) { - printf("BaseString::snprint returns %d\n", ret); + printf("BaseString::snprint returns %d with size=%d and strlen(fmt)=%d\n", + ret, buf_sz, strlen(fmt)); return -1; } if(ret+1 == buf_sz) { - printf("BaseString::snprint truncates\n"); + printf("BaseString::snprint truncates returns %d with size=%d and strlen(fmt)=%d\n", + ret, buf_sz, strlen(fmt)); return -1; } if(ret != result) { - printf("BaseString::snprint returns incorrect value: %d != %d\n", + printf("BaseString::snprint returns incorrect value: returned=%d != expected=%d\n", ret, result); return -1; } @@ -54,7 +56,7 @@ int test_snprintf(const char * fmt, int buf_sz, int result) if(buf[ret] != fmt[ret]) { printf("BaseString::snprint Incorrect value in output buffer: " - "%d %d %d %d %d\n", + "size=%d returned=expected=%d at pos=%d result=%d != expected=%d\n", buf_sz, result, ret, buf[ret], fmt[ret]); return -1; } From 38cae36c878abe35eb266f50bc390a9330a3d0ec Mon Sep 17 00:00:00 2001 From: "heikki@hundin.mysql.fi" <> Date: Thu, 11 Nov 2004 21:17:44 +0200 Subject: [PATCH 66/94] trx0purge.c: Remove duplicated innodb max purge lag code --- innobase/trx/trx0purge.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/innobase/trx/trx0purge.c b/innobase/trx/trx0purge.c index 6726d7ca609..5c62640e011 100644 --- a/innobase/trx/trx0purge.c +++ b/innobase/trx/trx0purge.c @@ -1069,30 +1069,6 @@ trx_purge(void) } } - /* Determine how much data manipulation language (DML) statements - need to be delayed in order to reduce the lagging of the purge - thread. */ - srv_dml_needed_delay = 0; /* in microseconds; default: no delay */ - - /* If we cannot advance the 'purge view' because of an old - 'consistent read view', then the DML statements cannot be delayed. - Also, srv_max_purge_lag <= 0 means 'infinity'. */ - if (srv_max_purge_lag > 0 - && !UT_LIST_GET_LAST(trx_sys->view_list)) { - float ratio = (float) trx_sys->rseg_history_len - / srv_max_purge_lag; - if (ratio > ULINT_MAX / 10000) { - /* Avoid overflow: maximum delay is 4295 seconds */ - srv_dml_needed_delay = ULINT_MAX; - } else if (ratio > 1) { - /* If the history list length exceeds the - innodb_max_purge_lag, the - data manipulation statements are delayed - by at least 5000 microseconds. */ - srv_dml_needed_delay = (ulint) ((ratio - .5) * 10000); - } - } - purge_sys->view = read_view_oldest_copy_or_open_new(NULL, purge_sys->heap); mutex_exit(&kernel_mutex); From 0be3c55594b2ca0307f5e35ceb6150312660fb18 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Thu, 11 Nov 2004 21:26:24 +0100 Subject: [PATCH 67/94] mi_write: fix for ft2 when found word (in the tree) has different length as the word to insert --- myisam/mi_check.c | 8 ++++++++ myisam/mi_write.c | 1 + 2 files changed, 9 insertions(+) diff --git a/myisam/mi_check.c b/myisam/mi_check.c index 1df518a2712..bf684270c0a 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -656,6 +656,14 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, if (chk_index_down(param,info,&info->s->ft2_keyinfo,record, temp_buff,&tmp_keys,key_checksum,1)) goto err; + if (tmp_keys + subkeys) + { + mi_check_print_error(param,"Number of words in the 2nd level tree " + "does not match the number in the header. " + "Parent word in on the page %s, offset %d", + llstr(page,llbuff), old_keypos-buff); + goto err; + } (*keys)+=tmp_keys-1; continue; } diff --git a/myisam/mi_write.c b/myisam/mi_write.c index dc596672a84..e059bbb569f 100644 --- a/myisam/mi_write.c +++ b/myisam/mi_write.c @@ -372,6 +372,7 @@ static int w_search(register MI_INFO *info, register MI_KEYDEF *keyinfo, /* popular word. two-level tree. going down */ my_off_t root=info->dupp_key_pos; keyinfo=&info->s->ft2_keyinfo; + get_key_full_length_rdonly(off, key); key+=off; keypos-=keyinfo->keylength+nod_flag; /* we'll modify key entry 'in vivo' */ error=_mi_ck_real_write_btree(info, keyinfo, key, 0, From af8d3612174ee18abd02c3e2b289b82ea669365e Mon Sep 17 00:00:00 2001 From: "paul@kite-hub.kitebird.com" <> Date: Thu, 11 Nov 2004 14:55:55 -0600 Subject: [PATCH 68/94] mysqldump.c: Reorder options, revise --hex-blob help string. --- client/mysqldump.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index dbc11f1ab90..864fe38a204 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -150,6 +150,9 @@ static struct my_option my_long_options[] = {"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are.", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"comments", 'i', "Write additional information.", + (gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG, + 1, 0, 0, 0, 0, 0}, {"compatible", OPT_COMPATIBLE, "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.", (gptr*) &opt_compatible_mode_str, (gptr*) &opt_compatible_mode_str, 0, @@ -225,6 +228,9 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0, 0}, {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"hex-blob", OPT_HEXBLOB, "Dump binary strings (BINARY, " + "VARBINARY, BLOB) in hexadecimal format.", + (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"host", 'h', "Connect to host.", (gptr*) ¤t_host, (gptr*) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", @@ -344,13 +350,7 @@ static struct my_option my_long_options[] = {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, - MALLOC_OVERHEAD-1024, 1024, 0}, - {"comments", 'i', "Write additional information.", - (gptr*) &opt_comments, (gptr*) &opt_comments, 0, GET_BOOL, NO_ARG, - 1, 0, 0, 0, 0, 0}, - {"hex-blob", OPT_HEXBLOB, "Dump BLOBs in HEX.", - (gptr*) &opt_hex_blob, (gptr*) &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} + MALLOC_OVERHEAD-1024, 1024, 0} }; static const char *load_default_groups[]= { "mysqldump","client",0 }; From 2ad7d5c662d785664ac3690240e89ce8d11ed21f Mon Sep 17 00:00:00 2001 From: "acurtis@pcgem.rdg.cyberkinetica.com" <> Date: Thu, 11 Nov 2004 20:59:03 +0000 Subject: [PATCH 69/94] Bug#6123 - GRANT USAGE creates useless mysql.db row Prevent creation of a row which grants no rights Test included --- mysql-test/r/grant.result | 6 ++++++ mysql-test/t/grant.test | 9 +++++++++ sql/sql_acl.cc | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index d4d8dd1f026..f0e5d16e916 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -150,3 +150,9 @@ GRANT SELECT ON `ab%`.* TO 'test11'@'localhost' GRANT SELECT ON `a%`.* TO 'test11'@'localhost' delete from mysql.user where user='test11'; delete from mysql.db where user='test11'; +create database db6123; +grant usage on db6123.* to test6123 identified by 'magic123'; +select host,db,user,select_priv,insert_priv from mysql.db where db="db6123"; +host db user select_priv insert_priv +delete from mysql.user where user='test6123'; +drop database db6123; diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index a278b9d5928..21173a356ce 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -105,3 +105,12 @@ flush privileges; show grants for test11@localhost; delete from mysql.user where user='test11'; delete from mysql.db where user='test11'; + +# +# Bug#6123: GRANT USAGE inserts useless Db row +# +create database db6123; +grant usage on db6123.* to test6123 identified by 'magic123'; +select host,db,user,select_priv,insert_priv from mysql.db where db="db6123"; +delete from mysql.user where user='test6123'; +drop database db6123; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index b3bc5a1e4f2..67ca62357ec 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1587,7 +1587,7 @@ static int replace_db_table(TABLE *table, const char *db, goto table_error; /* purecov: deadcode */ } } - else if ((error=table->file->write_row(table->record[0]))) + else if (rights && (error=table->file->write_row(table->record[0]))) { if (error && error != HA_ERR_FOUND_DUPP_KEY) /* purecov: inspected */ goto table_error; /* purecov: deadcode */ @@ -1597,6 +1597,7 @@ static int replace_db_table(TABLE *table, const char *db, if (old_row_exists) acl_update_db(combo.user.str,combo.host.str,db,rights); else + if (rights) acl_insert_db(combo.user.str,combo.host.str,db,rights); table->file->index_end(); DBUG_RETURN(0); From 3e4ca194f8fc912a5d0e5216c52df87260828c06 Mon Sep 17 00:00:00 2001 From: "brian@avenger.(none)" <> Date: Thu, 11 Nov 2004 19:01:46 -0800 Subject: [PATCH 70/94] Mainly resolving Guilhem's 4.1 patch to 5.0 --- client/mysqlbinlog.cc | 332 ++++-- client/mysqldump.c | 224 +++- sql/handler.cc | 195 +++- sql/lex.h | 71 +- sql/log.cc | 161 +-- sql/log_event.cc | 1646 ++++++++++++++++++++-------- sql/sql_parse.cc | 1731 ++++++++++++++++++++++-------- sql/sql_yacc.yy | 2375 +++++++++++++++++++++++++++++++++++++---- 8 files changed, 5390 insertions(+), 1345 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 8015871428e..ff90c77a2e8 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -14,11 +14,28 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + + TODO: print the catalog (some USE catalog.db ????). + + Standalone program to read a MySQL binary log (or relay log); + can read files produced by 3.23, 4.x, 5.0 servers. + + Can read binlogs from 3.23/4.x/5.0 and relay logs from 4.x/5.0. + Should be able to read any file of these categories, even with + --start-position. + An important fact: the Format_desc event of the log is at most the 3rd event + of the log; if it is the 3rd then there is this combination: + Format_desc_of_slave, Rotate_of_master, Format_desc_of_master. +*/ + #define MYSQL_CLIENT #undef MYSQL_SERVER #include "client_priv.h" #include #include "log_event.h" +/* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */ +#include "mysql_priv.h" #define BIN_LOG_HEADER_SIZE 4 #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) @@ -66,6 +83,14 @@ static MYSQL* mysql = NULL; static const char* dirname_for_local_load= 0; static bool stop_passed= 0; +/* + check_header() will set the pointer below. + Why do we need here a pointer on an event instead of an event ? + This is because the event will be created (alloced) in read_log_event() + (which returns a pointer) in check_header(). +*/ +Format_description_log_event* description_event; + static int dump_local_log_entries(const char* logname); static int dump_remote_log_entries(const char* logname); static int dump_log_entries(const char* logname); @@ -305,8 +330,8 @@ int Load_log_processor::process(Append_block_log_event *ae) /* There is no Create_file event (a bad binlog or a big - --position). Assuming it's a big --position, we just do nothing and - print a warning. + --start-position). Assuming it's a big --start-position, we just do + nothing and print a warning. */ fprintf(stderr,"Warning: ignoring Append_block as there is no \ Create_file event for file_id: %u\n",ae->file_id); @@ -316,30 +341,49 @@ Create_file event for file_id: %u\n",ae->file_id); Load_log_processor load_processor; + /* + Process an event + + SYNOPSIS + process_event() + RETURN 0 ok and continue 1 error and terminate -1 ok and terminate - + TODO This function returns 0 even in some error cases. This should be changed. */ -int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) + + + +int process_event(LAST_EVENT_INFO *last_event_info, Log_event *ev, + my_off_t pos) { char ll_buff[21]; + Log_event_type ev_type= ev->get_type_code(); DBUG_ENTER("process_event"); + /* + Format events are not concerned by --offset and such, we always need to + read them to be able to process the wanted events. + */ if ((rec_count >= offset) && - ((my_time_t)(ev->when) >= start_datetime)) + ((my_time_t)(ev->when) >= start_datetime) || + (ev_type == FORMAT_DESCRIPTION_EVENT)) { - /* - We have found an event after start_datetime, from now on print - everything (in case the binlog has timestamps increasing and decreasing, - we do this to avoid cutting the middle). - */ - start_datetime= 0; - offset= 0; // print everything and protect against cycling rec_count + if (ev_type != FORMAT_DESCRIPTION_EVENT) + { + /* + We have found an event after start_datetime, from now on print + everything (in case the binlog has timestamps increasing and + decreasing, we do this to avoid cutting the middle). + */ + start_datetime= 0; + offset= 0; // print everything and protect against cycling rec_count + } if (((my_time_t)(ev->when) >= stop_datetime) || (pos >= stop_position_mot)) { @@ -349,7 +393,7 @@ int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) if (!short_form) fprintf(result_file, "# at %s\n",llstr(pos,ll_buff)); - switch (ev->get_type_code()) { + switch (ev_type) { case QUERY_EVENT: if (one_database) { @@ -357,7 +401,7 @@ int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) if ((log_dbname != NULL) && (strcmp(log_dbname, database))) goto end; } - ev->print(result_file, short_form, last_db); + ev->print(result_file, short_form, last_event_info); break; case CREATE_FILE_EVENT: { @@ -381,8 +425,9 @@ int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) filename and use LOCAL), prepared in the 'case EXEC_LOAD_EVENT' below. */ - ce->print(result_file, short_form, last_db, TRUE); - if (!old_format) + ce->print(result_file, short_form, last_event_info, TRUE); + // If this binlog is not 3.23 ; why this test?? + if (description_event->binlog_version >= 3) { if (load_processor.process(ce)) break; // Error @@ -391,23 +436,23 @@ int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) break; } case APPEND_BLOCK_EVENT: - ev->print(result_file, short_form, last_db); + ev->print(result_file, short_form, last_event_info); if (load_processor.process((Append_block_log_event*) ev)) break; // Error break; case EXEC_LOAD_EVENT: { - ev->print(result_file, short_form, last_db); + ev->print(result_file, short_form, last_event_info); Execute_load_log_event *exv= (Execute_load_log_event*)ev; Create_file_log_event *ce= load_processor.grab_event(exv->file_id); /* if ce is 0, it probably means that we have not seen the Create_file - event (a bad binlog, or most probably --position is after the + event (a bad binlog, or most probably --start-position is after the Create_file event). Print a warning comment. */ if (ce) { - ce->print(result_file, short_form, last_db, TRUE); + ce->print(result_file, short_form, last_event_info, TRUE); my_free((char*)ce->fname,MYF(MY_WME)); delete ce; } @@ -416,8 +461,20 @@ int process_event(char *last_db, Log_event *ev, my_off_t pos, int old_format) Create_file event for file_id: %u\n",exv->file_id); break; } + case FORMAT_DESCRIPTION_EVENT: + delete description_event; + description_event= (Format_description_log_event*) ev; + ev->print(result_file, short_form, last_event_info); + /* + We don't want this event to be deleted now, so let's hide it (I + (Guilhem) should later see if this triggers a non-serious Valgrind + error). Not serious error, because we will free description_event + later. + */ + ev= 0; + break; default: - ev->print(result_file, short_form, last_db); + ev->print(result_file, short_form, last_event_info); } } @@ -558,7 +615,7 @@ static void die(const char* fmt, ...) static void print_version() { - printf("%s Ver 3.0 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); + printf("%s Ver 3.1 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); NETWARE_SET_SCREEN_MODE(1); } @@ -701,12 +758,17 @@ static int dump_log_entries(const char* logname) } -static int check_master_version(MYSQL* mysql) +/* + This is not as smart as check_header() (used for local log); it will not work + for a binlog which mixes format. TODO: fix this. +*/ +static int check_master_version(MYSQL* mysql, + Format_description_log_event + **description_event) { MYSQL_RES* res = 0; MYSQL_ROW row; const char* version; - int old_format = 0; if (mysql_query(mysql, "SELECT VERSION()") || !(res = mysql_store_result(mysql))) @@ -731,11 +793,18 @@ static int check_master_version(MYSQL* mysql) switch (*version) { case '3': - old_format = 1; + *description_event= new Format_description_log_event(1); break; case '4': + *description_event= new Format_description_log_event(3); case '5': - old_format = 0; + /* + The server is soon going to send us its Format_description log + event, unless it is a 5.0 server with 3.23 or 4.0 binlogs. + So we first assume that this is 4.0 (which is enough to read the + Format_desc event if one comes). + */ + *description_event= new Format_description_log_event(3); break; default: sql_print_error("Master reported unrecognized MySQL version '%s'", @@ -745,18 +814,17 @@ static int check_master_version(MYSQL* mysql) return 1; } mysql_free_result(res); - return old_format; + return 0; } static int dump_remote_log_entries(const char* logname) + { char buf[128]; - char last_db[FN_REFLEN+1] = ""; - ulong len; - uint logname_len; + LAST_EVENT_INFO last_event_info; + uint len, logname_len; NET* net; - int old_format; int error= 0; my_off_t old_off= start_position_mot; char fname[FN_REFLEN+1]; @@ -769,7 +837,18 @@ static int dump_remote_log_entries(const char* logname) */ mysql= safe_connect(); net= &mysql->net; - old_format = check_master_version(mysql); + + if (check_master_version(mysql, &description_event)) + { + fprintf(stderr, "Could not find server version"); + DBUG_RETURN(1); + } + if (!description_event || !description_event->is_valid()) + { + fprintf(stderr, "Invalid Format_description log event; \ +could be out of memory"); + DBUG_RETURN(1); + } /* COM_BINLOG_DUMP accepts only 4 bytes for the position, so we are forced to @@ -798,6 +877,8 @@ static int dump_remote_log_entries(const char* logname) for (;;) { const char *error_msg; + Log_event *ev; + len = net_safe_read(mysql); if (len == packet_error) { @@ -810,9 +891,9 @@ static int dump_remote_log_entries(const char* logname) break; // end of data DBUG_PRINT("info",( "len= %u, net->read_pos[5] = %d\n", len, net->read_pos[5])); - Log_event *ev = Log_event::read_log_event((const char*) net->read_pos + 1 , - len - 1, &error_msg, old_format); - if (!ev) + if (!(ev= Log_event::read_log_event((const char*) net->read_pos + 1 , + len - 1, &error_msg, + description_event))) { fprintf(stderr, "Could not construct log event object\n"); error= 1; @@ -820,25 +901,27 @@ static int dump_remote_log_entries(const char* logname) } Log_event_type type= ev->get_type_code(); - if (!old_format || ( type != LOAD_EVENT && type != CREATE_FILE_EVENT)) + if (description_event->binlog_version >= 3 || + (type != LOAD_EVENT && type != CREATE_FILE_EVENT)) { - if (ev->get_type_code() == ROTATE_EVENT) + /* + If this is a Rotate event, maybe it's the end of the requested binlog; + in this case we are done (stop transfer). + This is suitable for binlogs, not relay logs (but for now we don't read + relay logs remotely because the server is not able to do that). If one + day we read relay logs remotely, then we will have a problem with the + detection below: relay logs contain Rotate events which are about the + binlogs, so which would trigger the end-detection below. + */ + if (type == ROTATE_EVENT) { Rotate_log_event *rev= (Rotate_log_event *)ev; /* - mysqld is sending us all its binlogs after the requested one, but we - don't want them. If this is a fake Rotate event, and not about our log, we can stop transfer. If this a real Rotate event (so it's not about our log, it's in our log describing the next log), we print it (because it's part of our log) and then we will stop when we receive the fake one soon. - This is suitable for binlogs, not relay logs (but for now we don't - read relay logs remotely because the server is not able to do - that). If one day we read relay logs remotely, then we will have a - problem with the detection below: relay logs contain Rotate events - which are about the binlogs, so which would trigger the end-detection - below. */ if (rev->when == 0) { @@ -861,7 +944,7 @@ static int dump_remote_log_entries(const char* logname) len= 1; // fake Rotate, so don't increment old_off } } - if ((error= process_event(last_db,ev,old_off,old_format))) + if ((error= process_event(&last_event_info,ev,old_off))) { error= ((error < 0) ? 0 : 1); goto err; @@ -873,64 +956,135 @@ static int dump_remote_log_entries(const char* logname) const char *old_fname= le->fname; uint old_len= le->fname_len; File file; - + if ((file= load_processor.prepare_new_file_for_old_format(le,fname)) < 0) { error= 1; goto err; } - - if ((error= process_event(last_db,ev,old_off,old_format))) + + if ((error= process_event(&last_event_info,ev,old_off))) { - my_close(file,MYF(MY_WME)); + my_close(file,MYF(MY_WME)); error= ((error < 0) ? 0 : 1); goto err; } - if (load_processor.load_old_format_file(net,old_fname,old_len,file)) + error= load_processor.load_old_format_file(net,old_fname,old_len,file); + my_close(file,MYF(MY_WME)); + if (error) { - my_close(file,MYF(MY_WME)); error= 1; goto err; } - my_close(file,MYF(MY_WME)); } - /* Let's adjust offset for remote log as for local log to produce similar text. */ old_off+= len-1; } + err: mysql_close(mysql); DBUG_RETURN(error); } -static int check_header(IO_CACHE* file) +static void check_header(IO_CACHE* file, + Format_description_log_event **description_event) { byte header[BIN_LOG_HEADER_SIZE]; byte buf[PROBE_HEADER_LEN]; - int old_format=0; - DBUG_ENTER("check_header"); + my_off_t tmp_pos, pos; - my_off_t pos = my_b_tell(file); + *description_event= new Format_description_log_event(3); + pos= my_b_tell(file); my_b_seek(file, (my_off_t)0); if (my_b_read(file, header, sizeof(header))) die("Failed reading header; Probably an empty file"); if (memcmp(header, BINLOG_MAGIC, sizeof(header))) die("File is not a binary log file"); - if (!my_b_read(file, buf, sizeof(buf))) + + /* + Imagine we are running with --start-position=1000. We still need + to know the binlog format's. So we still need to find, if there is + one, the Format_desc event, or to know if this is a 3.23 + binlog. So we need to first read the first events of the log, + those around offset 4. Even if we are reading a 3.23 binlog from + the start (no --start-position): we need to know the header length + (which is 13 in 3.23, 19 in 4.x) to be able to successfully print + the first event (Start_log_event_v3). So even in this case, we + need to "probe" the first bytes of the log *before* we do a real + read_log_event(). Because read_log_event() needs to know the + header's length to work fine. + */ + for(;;) { - if (buf[4] == START_EVENT) + tmp_pos= my_b_tell(file); /* should be 4 the first time */ + if (my_b_read(file, buf, sizeof(buf))) { - uint event_len; - event_len = uint4korr(buf + EVENT_LEN_OFFSET); - old_format = (event_len < (LOG_EVENT_HEADER_LEN + START_HEADER_LEN)); + if (file->error) + die("\ +Could not read entry at offset %lu : Error in log format or read error", + tmp_pos); + /* + Otherwise this is just EOF : this log currently contains 0-2 + events. Maybe it's going to be filled in the next + milliseconds; then we are going to have a problem if this a + 3.23 log (imagine we are locally reading a 3.23 binlog which + is being written presently): we won't know it in + read_log_event() and will fail(). Similar problems could + happen with hot relay logs if --start-position is used (but a + --start-position which is posterior to the current size of the log). + These are rare problems anyway (reading a hot log + when we + read the first events there are not all there yet + when we + read a bit later there are more events + using a strange + --start-position). + */ + break; + } + else + { + DBUG_PRINT("info",("buf[4]=%d", buf[4])); + /* always test for a Start_v3, even if no --start-position */ + if (buf[4] == START_EVENT_V3) /* This is 3.23 or 4.x */ + { + if (uint4korr(buf + EVENT_LEN_OFFSET) < + (LOG_EVENT_MINIMAL_HEADER_LEN + START_V3_HEADER_LEN)) + { + /* This is 3.23 (format 1) */ + delete *description_event; + *description_event= new Format_description_log_event(1); + } + break; + } + else if (tmp_pos >= start_position) + break; + else if (buf[4] == FORMAT_DESCRIPTION_EVENT) /* This is 5.0 */ + { + my_b_seek(file, tmp_pos); /* seek back to event's start */ + if (!(*description_event= (Format_description_log_event*) + Log_event::read_log_event(file, *description_event))) + /* EOF can't be hit here normally, so it's a real error */ + die("Could not read a Format_description_log_event event \ +at offset %lu ; this could be a log format error or read error", + tmp_pos); + DBUG_PRINT("info",("Setting description_event")); + } + else if (buf[4] == ROTATE_EVENT) + { + my_b_seek(file, tmp_pos); /* seek back to event's start */ + if (!Log_event::read_log_event(file, *description_event)) + /* EOF can't be hit here normally, so it's a real error */ + die("Could not read a Rotate_log_event event \ +at offset %lu ; this could be a log format error or read error", + tmp_pos); + } + else + break; } } my_b_seek(file, pos); - DBUG_RETURN(old_format); } @@ -938,13 +1092,10 @@ static int dump_local_log_entries(const char* logname) { File fd = -1; IO_CACHE cache,*file= &cache; - char last_db[FN_REFLEN+1]; + LAST_EVENT_INFO last_event_info; byte tmp_buff[BIN_LOG_HEADER_SIZE]; - bool old_format = 0; int error= 0; - last_db[0]= 0; - if (logname && logname[0] != '-') { if ((fd = my_open(logname, O_RDONLY | O_BINARY, MYF(MY_WME))) < 0) @@ -953,16 +1104,16 @@ static int dump_local_log_entries(const char* logname) MYF(MY_WME | MY_NABP))) { my_close(fd, MYF(MY_WME)); - exit(1); + return 1; } - old_format = check_header(file); + check_header(file, &description_event); } - else + else // reading from stdin; TODO: check that it works { if (init_io_cache(file, fileno(result_file), 0, READ_CACHE, (my_off_t) 0, 0, MYF(MY_WME | MY_NABP | MY_DONT_CHECK_FILESIZE))) return 1; - old_format = check_header(file); + check_header(file, &description_event); if (start_position) { /* skip 'start_position' characters from stdout */ @@ -972,46 +1123,44 @@ static int dump_local_log_entries(const char* logname) { tmp=min(length,sizeof(buff)); if (my_b_read(file, buff, (uint) tmp)) - { - error= 1; - goto end; - } + { + error= 1; + goto end; + } } } file->pos_in_file= start_position_mot; file->seek_not_done=0; } - if (!start_position) - { - // Skip header - if (my_b_read(file, tmp_buff, BIN_LOG_HEADER_SIZE)) - { - error= 1; - goto end; - } - } + if (!description_event || !description_event->is_valid()) + die("Invalid Format_description log event; could be out of memory"); + if (!start_position && my_b_read(file, tmp_buff, BIN_LOG_HEADER_SIZE)) + { + error= 1; + goto end; + } for (;;) { char llbuff[21]; my_off_t old_off = my_b_tell(file); - Log_event* ev = Log_event::read_log_event(file, old_format); + Log_event* ev = Log_event::read_log_event(file, description_event); if (!ev) { if (file->error) { fprintf(stderr, - "Could not read entry at offset %s:" - "Error in log format or read error\n", - llstr(old_off,llbuff)); - error= 1; + "Could not read entry at offset %s:" + "Error in log format or read error\n", + llstr(old_off,llbuff)); + error= 1; } // file->error == 0 means EOF, that's OK, we break in this case break; } - if ((error= process_event(last_db,ev,old_off,false))) + if ((error= process_event(&last_event_info,ev,old_off))) { if (error < 0) error= 0; @@ -1023,6 +1172,7 @@ end: if (fd >= 0) my_close(fd, MYF(MY_WME)); end_io_cache(file); + delete description_event; return error; } diff --git a/client/mysqldump.c b/client/mysqldump.c index dbc11f1ab90..76211c4244e 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -108,6 +108,8 @@ static uint opt_protocol= 0; static char *default_charset= (char*) MYSQL_UNIVERSAL_CLIENT_CHARSET; static CHARSET_INFO *charset_info= &my_charset_latin1; const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace"; +/* do we met VIEWs during tables scaning */ +my_bool was_views= 0; const char *compatible_mode_names[]= { @@ -367,6 +369,8 @@ static int dump_databases(char **); static int dump_all_databases(); static char *quote_name(const char *name, char *buff, my_bool force); static const char *check_if_ignore_table(const char *table_name); +static my_bool getViewStructure(char *table, char* db); +static my_bool dump_all_views_in_db(char *database); #include @@ -1035,6 +1039,7 @@ static uint getTableStructure(char *table, char* db) { /* Make an sql-file, if path was given iow. option -T was given */ char buff[20+FN_REFLEN]; + MYSQL_FIELD *field; sprintf(buff,"show create table %s", result_table); if (mysql_query_with_error_report(sock, 0, buff)) @@ -1068,8 +1073,16 @@ static uint getTableStructure(char *table, char* db) check_io(sql_file); } - tableRes=mysql_store_result(sock); - row=mysql_fetch_row(tableRes); + tableRes= mysql_store_result(sock); + field= mysql_fetch_field_direct(tableRes, 0); + if (strcmp(field->name, "View") == 0) + { + if (verbose) + fprintf(stderr, "-- It's a view, skipped\n"); + was_views= 1; + DBUG_RETURN(0); + } + row= mysql_fetch_row(tableRes); fprintf(sql_file, "%s;\n", row[1]); check_io(sql_file); mysql_free_result(tableRes); @@ -1213,6 +1226,14 @@ static uint getTableStructure(char *table, char* db) sprintf(buff,"show keys from %s", result_table); if (mysql_query_with_error_report(sock, &tableRes, buff)) { + if (mysql_errno(sock) == ER_WRONG_OBJECT) + { + /* it is VIEW */ + fputs("\t\t\n", sql_file); + goto continue_xml; + } + fprintf(stderr, "%s: Can't get keys for table %s (%s)\n", + my_progname, result_table, mysql_error(sock)); if (path) my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); @@ -1316,6 +1337,7 @@ static uint getTableStructure(char *table, char* db) } mysql_free_result(tableRes); /* Is always safe to free */ } +continue_xml: if (!opt_xml) fputs(";\n", sql_file); else @@ -1845,6 +1867,21 @@ static int dump_all_databases() if (dump_all_tables_in_db(row[0])) result=1; } + if (was_views) + { + if (mysql_query(sock, "SHOW DATABASES") || + !(tableres = mysql_store_result(sock))) + { + my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s", + MYF(0), mysql_error(sock)); + return 1; + } + while ((row = mysql_fetch_row(tableres))) + { + if (dump_all_views_in_db(row[0])) + result=1; + } + } return result; } /* dump_all_databases */ @@ -1853,11 +1890,20 @@ static int dump_all_databases() static int dump_databases(char **db_names) { int result=0; - for ( ; *db_names ; db_names++) + char **db; + for (db= db_names ; *db ; db++) { - if (dump_all_tables_in_db(*db_names)) + if (dump_all_tables_in_db(*db)) result=1; } + if (!result && was_views) + { + for (db= db_names ; *db ; db++) + { + if (dump_all_views_in_db(*db)) + result=1; + } + } return result; } /* dump_databases */ @@ -1965,11 +2011,64 @@ static int dump_all_tables_in_db(char *database) return 0; } /* dump_all_tables_in_db */ +/* + dump structure of views of database + SYNOPSIS + dump_all_views_in_db() + database database name + + RETURN + 0 OK + 1 ERROR +*/ + +static my_bool dump_all_views_in_db(char *database) +{ + char *table; + uint numrows; + char table_buff[NAME_LEN*2+3]; + + if (init_dumping(database)) + return 1; + if (opt_xml) + print_xml_tag1(md_result_file, "", "database name=", database, "\n"); + if (lock_tables) + { + DYNAMIC_STRING query; + init_dynamic_string(&query, "LOCK TABLES ", 256, 1024); + for (numrows= 0 ; (table= getTableName(1)); numrows++) + { + dynstr_append(&query, quote_name(table, table_buff, 1)); + dynstr_append(&query, " READ /*!32311 LOCAL */,"); + } + if (numrows && mysql_real_query(sock, query.str, query.length-1)) + DBerror(sock, "when using LOCK TABLES"); + /* We shall continue here, if --force was given */ + dynstr_free(&query); + } + if (flush_logs) + { + if (mysql_refresh(sock, REFRESH_LOG)) + DBerror(sock, "when doing refresh"); + /* We shall continue here, if --force was given */ + } + while ((table= getTableName(0))) + getViewStructure(table, database); + if (opt_xml) + { + fputs("\n", md_result_file); + check_io(md_result_file); + } + if (lock_tables) + mysql_query(sock,"UNLOCK TABLES"); + return 0; +} /* dump_all_tables_in_db */ static int dump_selected_tables(char *db, char **table_names, int tables) { uint numrows; + int i; char table_buff[NAME_LEN*+3]; if (init_dumping(db)) @@ -1977,7 +2076,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables) if (lock_tables) { DYNAMIC_STRING query; - int i; init_dynamic_string(&query, "LOCK TABLES ", 256, 1024); for (i=0 ; i < tables ; i++) @@ -1998,11 +2096,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables) } if (opt_xml) print_xml_tag1(md_result_file, "", "database name=", db, "\n"); - for (; tables > 0 ; tables-- , table_names++) + for (i=0 ; i < tables ; i++) { - numrows = getTableStructure(*table_names, db); + numrows = getTableStructure(table_names[i], db); if (!dFlag && numrows > 0) - dumpTable(numrows, *table_names); + dumpTable(numrows, table_names[i]); + } + if (was_views) + { + for (i=0 ; i < tables ; i++) + getViewStructure(table_names[i], db); } if (opt_xml) { @@ -2197,14 +2300,113 @@ static const char *check_if_ignore_table(const char *table_name) mysql_free_result(res); return 0; /* assume table is ok */ } - if (strcmp(row[1], (result= "MRG_MyISAM")) && - strcmp(row[1], (result= "MRG_ISAM"))) - result= 0; + if (!(row[1])) + result= "VIEW"; + else + { + if (strcmp(row[1], (result= "MRG_MyISAM")) && + strcmp(row[1], (result= "MRG_ISAM"))) + result= 0; + } mysql_free_result(res); return result; } +/* + Getting VIEW structure + + SYNOPSIS + getViewStructure() + table view name + db db name + + RETURN + 0 OK + 1 ERROR +*/ + +static my_bool getViewStructure(char *table, char* db) +{ + MYSQL_RES *tableRes; + MYSQL_ROW row; + MYSQL_FIELD *field; + char *result_table, *opt_quoted_table; + char table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3]; + char buff[20+FN_REFLEN]; + FILE *sql_file = md_result_file; + DBUG_ENTER("getViewStructure"); + + if (tFlag) + DBUG_RETURN(0); + + if (verbose) + fprintf(stderr, "-- Retrieving view structure for table %s...\n", table); + + sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", + (opt_quoted || opt_keywords)); + result_table= quote_name(table, table_buff, 1); + opt_quoted_table= quote_name(table, table_buff2, 0); + + sprintf(buff,"show create table %s", result_table); + if (mysql_query(sock, buff)) + { + fprintf(stderr, "%s: Can't get CREATE TABLE for view %s (%s)\n", + my_progname, result_table, mysql_error(sock)); + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); + } + + if (path) + { + char filename[FN_REFLEN], tmp_path[FN_REFLEN]; + convert_dirname(tmp_path,path,NullS); + sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), + O_WRONLY, MYF(MY_WME)); + if (!sql_file) /* If file couldn't be opened */ + { + safe_exit(EX_MYSQLERR); + DBUG_RETURN(1); + } + write_header(sql_file, db); + } + tableRes= mysql_store_result(sock); + field= mysql_fetch_field_direct(tableRes, 0); + if (strcmp(field->name, "View") != 0) + { + if (verbose) + fprintf(stderr, "-- It's base table, skipped\n"); + DBUG_RETURN(0); + } + + if (!opt_xml && opt_comments) + { + fprintf(sql_file, "\n--\n-- View structure for view %s\n--\n\n", + result_table); + check_io(sql_file); + } + if (opt_drop) + { + fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n", opt_quoted_table); + check_io(sql_file); + } + + row= mysql_fetch_row(tableRes); + fprintf(sql_file, "%s;\n", row[1]); + check_io(sql_file); + mysql_free_result(tableRes); + + if (sql_file != md_result_file) + { + fputs("\n", sql_file); + write_footer(sql_file); + my_fclose(sql_file, MYF(MY_WME)); + } + DBUG_RETURN(0); +} + + int main(int argc, char **argv) { compatible_mode_normal_str[0]= 0; diff --git a/sql/handler.cc b/sql/handler.cc index 5dae7950390..b2acb262763 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -54,11 +54,7 @@ static int NEAR_F delete_file(const char *name,const char *ext,int extflag); -ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, - ha_read_key_count, ha_read_next_count, ha_read_prev_count, - ha_read_first_count, ha_read_last_count, - ha_commit_count, ha_rollback_count, - ha_read_rnd_count, ha_read_rnd_next_count, ha_discover_count; +ulong ha_read_count, ha_discover_count; static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; @@ -114,7 +110,7 @@ uint known_extensions_id= 0; enum db_type ha_resolve_by_name(const char *name, uint namelen) { - THD *thd=current_thd; + THD *thd= current_thd; if (thd && !my_strcasecmp(&my_charset_latin1, name, "DEFAULT")) { return (enum db_type) thd->variables.table_type; } @@ -145,6 +141,7 @@ const char *ha_get_storage_engine(enum db_type db_type) enum db_type ha_checktype(enum db_type database_type) { show_table_type_st *types; + THD *thd= current_thd; for (types= sys_table_types; types->type; types++) { if ((database_type == types->db_type) && @@ -163,12 +160,11 @@ enum db_type ha_checktype(enum db_type database_type) break; } - return - DB_TYPE_UNKNOWN != (enum db_type) current_thd->variables.table_type ? - (enum db_type) current_thd->variables.table_type : - DB_TYPE_UNKNOWN != (enum db_type) global_system_variables.table_type ? - (enum db_type) global_system_variables.table_type : - DB_TYPE_MYISAM; + return ((enum db_type) thd->variables.table_type != DB_TYPE_UNKNOWN ? + (enum db_type) thd->variables.table_type : + (enum db_type) global_system_variables.table_type != + DB_TYPE_UNKNOWN ? + (enum db_type) global_system_variables.table_type : DB_TYPE_MYISAM); } /* ha_checktype */ @@ -565,7 +561,7 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) thd->variables.tx_isolation=thd->session_tx_isolation; if (operation_done) { - statistic_increment(ha_commit_count,&LOCK_status); + statistic_increment(thd->status_var.ha_commit_count,&LOCK_status); thd->transaction.cleanup(); } if (need_start_waiters) @@ -734,7 +730,7 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name) operation_done=1; #endif if (operation_done) - statistic_increment(ha_rollback_count,&LOCK_status); + statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status); } #endif /* USING_TRANSACTIONS */ @@ -816,10 +812,14 @@ bool ha_flush_logs() int ha_delete_table(enum db_type table_type, const char *path) { + handler *file; char tmp_path[FN_REFLEN]; - handler *file=get_new_handler((TABLE*) 0, table_type); - if (!file) + + /* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */ + if (table_type == DB_TYPE_UNKNOWN || + ! (file=get_new_handler((TABLE*) 0, table_type))) return ENOENT; + if (lower_case_table_names == 2 && !(file->table_flags() & HA_FILE_BASED)) { /* Ensure that table handler get path in lower case */ @@ -948,7 +948,7 @@ int handler::read_first_row(byte * buf, uint primary_key) register int error; DBUG_ENTER("handler::read_first_row"); - statistic_increment(ha_read_first_count,&LOCK_status); + statistic_increment(current_thd->status_var.ha_read_first_count,&LOCK_status); /* If there is very few deleted rows in the table, find the first row by @@ -972,41 +972,163 @@ int handler::read_first_row(byte * buf, uint primary_key) /* - Updates field with field_type NEXT_NUMBER according to following: - if field = 0 change field to the next free key in database. + Generate the next auto-increment number based on increment and offset + + In most cases increment= offset= 1, in which case we get: + 1,2,3,4,5,... + If increment=10 and offset=5 and previous number is 1, we get: + 1,5,15,25,35,... +*/ + +inline ulonglong +next_insert_id(ulonglong nr,struct system_variables *variables) +{ + nr= (((nr+ variables->auto_increment_increment - + variables->auto_increment_offset)) / + (ulonglong) variables->auto_increment_increment); + return (nr* (ulonglong) variables->auto_increment_increment + + variables->auto_increment_offset); +} + + +/* + Updates columns with type NEXT_NUMBER if: + + - If column value is set to NULL (in which case + auto_increment_field_not_null is 0) + - If column is set to 0 and (sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) is not + set. In the future we will only set NEXT_NUMBER fields if one sets them + to NULL (or they are not included in the insert list). + + + There are two different cases when the above is true: + + - thd->next_insert_id == 0 (This is the normal case) + In this case we set the set the column for the first row to the value + next_insert_id(get_auto_increment(column))) which is normally + max-used-column-value +1. + + We call get_auto_increment() only for the first row in a multi-row + statement. For the following rows we generate new numbers based on the + last used number. + + - thd->next_insert_id != 0. This happens when we have read a statement + from the binary log or when one has used SET LAST_INSERT_ID=#. + + In this case we will set the column to the value of next_insert_id. + The next row will be given the id + next_insert_id(next_insert_id) + + The idea is that generated auto_increment values are predictable and + independent of the column values in the table. This is needed to be + able to replicate into a table that already has rows with a higher + auto-increment value than the one that is inserted. + + After we have already generated an auto-increment number and the user + inserts a column with a higher value than the last used one, we will + start counting from the inserted value. + + thd->next_insert_id is cleared after it's been used for a statement. */ void handler::update_auto_increment() { - longlong nr; - THD *thd; + ulonglong nr; + THD *thd= table->in_use; + struct system_variables *variables= &thd->variables; DBUG_ENTER("handler::update_auto_increment"); - if (table->next_number_field->val_int() != 0 || + + /* + We must save the previous value to be able to restore it if the + row was not inserted + */ + thd->prev_insert_id= thd->next_insert_id; + + if ((nr= table->next_number_field->val_int()) != 0 || table->auto_increment_field_not_null && - current_thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) + thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO) { + /* Clear flag for next row */ table->auto_increment_field_not_null= FALSE; + /* Mark that we didn't generate a new value **/ auto_increment_column_changed=0; + + /* Update next_insert_id if we have already generated a value */ + if (thd->clear_next_insert_id && nr >= thd->next_insert_id) + { + if (variables->auto_increment_increment != 1) + nr= next_insert_id(nr, variables); + else + nr++; + thd->next_insert_id= nr; + DBUG_PRINT("info",("next_insert_id: %lu", (ulong) nr)); + } DBUG_VOID_RETURN; } table->auto_increment_field_not_null= FALSE; - thd=current_thd; - if ((nr=thd->next_insert_id)) - thd->next_insert_id=0; // Clear after use - else - nr=get_auto_increment(); - if (!table->next_number_field->store(nr)) + if (!(nr= thd->next_insert_id)) + { + nr= get_auto_increment(); + if (variables->auto_increment_increment != 1) + nr= next_insert_id(nr-1, variables); + /* + Update next row based on the found value. This way we don't have to + call the handler for every generated auto-increment value on a + multi-row statement + */ + thd->next_insert_id= nr; + } + + DBUG_PRINT("info",("auto_increment: %lu", (ulong) nr)); + + /* Mark that we should clear next_insert_id before next stmt */ + thd->clear_next_insert_id= 1; + + if (!table->next_number_field->store((longlong) nr)) thd->insert_id((ulonglong) nr); else thd->insert_id(table->next_number_field->val_int()); + + /* + We can't set next_insert_id if the auto-increment key is not the + first key part, as there is no guarantee that the first parts will be in + sequence + */ + if (!table->next_number_key_offset) + { + /* + Set next insert id to point to next auto-increment value to be able to + handle multi-row statements + This works even if auto_increment_increment > 1 + */ + thd->next_insert_id= next_insert_id(nr, variables); + } + else + thd->next_insert_id= 0; + + /* Mark that we generated a new value */ auto_increment_column_changed=1; DBUG_VOID_RETURN; } +/* + restore_auto_increment -longlong handler::get_auto_increment() + In case of error on write, we restore the last used next_insert_id value + because the previous value was not used. +*/ + +void handler::restore_auto_increment() { - longlong nr; + THD *thd= table->in_use; + if (thd->next_insert_id) + thd->next_insert_id= thd->prev_insert_id; +} + + +ulonglong handler::get_auto_increment() +{ + ulonglong nr; int error; (void) extra(HA_EXTRA_KEYREAD); @@ -1018,7 +1140,8 @@ longlong handler::get_auto_increment() else { byte key[MAX_KEY_LENGTH]; - key_copy(key,table,table->next_number_index, + key_copy(key, table->record[0], + table->key_info + table->next_number_index, table->next_number_key_offset); error=index_read(table->record[1], key, table->next_number_key_offset, HA_READ_PREFIX_LAST); @@ -1027,8 +1150,8 @@ longlong handler::get_auto_increment() if (error) nr=1; else - nr=(longlong) table->next_number_field-> - val_int_offset(table->rec_buff_length)+1; + nr=((ulonglong) table->next_number_field-> + val_int_offset(table->rec_buff_length)+1); index_end(); (void) extra(HA_EXTRA_NO_KEYREAD); return nr; @@ -1271,7 +1394,7 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, char name_buff[FN_REFLEN]; DBUG_ENTER("ha_create_table"); - if (openfrm(name,"",0,(uint) READ_ALL, 0, &table)) + if (openfrm(current_thd, name,"",0,(uint) READ_ALL, 0, &table)) DBUG_RETURN(1); if (update_create_info) { @@ -1336,7 +1459,7 @@ int ha_create_table_from_engine(THD* thd, if ((error = writefrm(path, frmblob, frmlen))) goto err_end; - if (openfrm(path,"",0,(uint) READ_ALL, 0, &table)) + if (openfrm(thd, path,"",0,(uint) READ_ALL, 0, &table)) DBUG_RETURN(1); update_create_info_from_table(&create_info, &table); diff --git a/sql/lex.h b/sql/lex.h index 325d052de90..db31b3af994 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -65,6 +65,7 @@ static SYMBOL symbols[] = { { "AGAINST", SYM(AGAINST)}, { "AGGREGATE", SYM(AGGREGATE_SYM)}, { "ALL", SYM(ALL)}, + { "ALGORITHM", SYM(ALGORITHM_SYM)}, { "ALTER", SYM(ALTER)}, { "ANALYZE", SYM(ANALYZE_SYM)}, { "AND", SYM(AND_SYM)}, @@ -72,6 +73,7 @@ static SYMBOL symbols[] = { { "AS", SYM(AS)}, { "ASC", SYM(ASC)}, { "ASCII", SYM(ASCII_SYM)}, + { "ASENSITIVE", SYM(ASENSITIVE_SYM)}, { "AUTO_INCREMENT", SYM(AUTO_INC)}, { "AVG", SYM(AVG_SYM)}, { "AVG_ROW_LENGTH", SYM(AVG_ROW_LENGTH)}, @@ -93,7 +95,9 @@ static SYMBOL symbols[] = { { "BY", SYM(BY)}, { "BYTE", SYM(BYTE_SYM)}, { "CACHE", SYM(CACHE_SYM)}, + { "CALL", SYM(CALL_SYM)}, { "CASCADE", SYM(CASCADE)}, + { "CASCADED", SYM(CASCADED)}, { "CASE", SYM(CASE_SYM)}, { "CHANGE", SYM(CHANGE)}, { "CHANGED", SYM(CHANGED)}, @@ -114,8 +118,12 @@ static SYMBOL symbols[] = { { "COMMITTED", SYM(COMMITTED_SYM)}, { "COMPRESSED", SYM(COMPRESSED_SYM)}, { "CONCURRENT", SYM(CONCURRENT)}, + { "CONDITION", SYM(CONDITION_SYM)}, + { "CONNECTION", SYM(CONNECTION_SYM)}, { "CONSISTENT", SYM(CONSISTENT_SYM)}, { "CONSTRAINT", SYM(CONSTRAINT)}, + { "CONTAINS", SYM(CONTAINS_SYM)}, + { "CONTINUE", SYM(CONTINUE_SYM)}, { "CONVERT", SYM(CONVERT_SYM)}, { "CREATE", SYM(CREATE)}, { "CROSS", SYM(CROSS)}, @@ -124,6 +132,7 @@ static SYMBOL symbols[] = { { "CURRENT_TIME", SYM(CURTIME)}, { "CURRENT_TIMESTAMP", SYM(NOW_SYM)}, { "CURRENT_USER", SYM(CURRENT_USER)}, + { "CURSOR", SYM(CURSOR_SYM)}, { "DATA", SYM(DATA_SYM)}, { "DATABASE", SYM(DATABASE)}, { "DATABASES", SYM(DATABASES)}, @@ -137,13 +146,16 @@ static SYMBOL symbols[] = { { "DEALLOCATE", SYM(DEALLOCATE_SYM)}, { "DEC", SYM(DECIMAL_SYM)}, { "DECIMAL", SYM(DECIMAL_SYM)}, + { "DECLARE", SYM(DECLARE_SYM)}, { "DEFAULT", SYM(DEFAULT)}, + { "DEFINER", SYM(DEFINER_SYM)}, { "DELAYED", SYM(DELAYED_SYM)}, { "DELAY_KEY_WRITE", SYM(DELAY_KEY_WRITE_SYM)}, { "DELETE", SYM(DELETE_SYM)}, { "DESC", SYM(DESC)}, { "DESCRIBE", SYM(DESCRIBE)}, { "DES_KEY_FILE", SYM(DES_KEY_FILE)}, + { "DETERMINISTIC", SYM(DETERMINISTIC_SYM)}, { "DIRECTORY", SYM(DIRECTORY_SYM)}, { "DISABLE", SYM(DISABLE_SYM)}, { "DISCARD", SYM(DISCARD)}, @@ -157,7 +169,9 @@ static SYMBOL symbols[] = { { "DUMPFILE", SYM(DUMPFILE)}, { "DUPLICATE", SYM(DUPLICATE_SYM)}, { "DYNAMIC", SYM(DYNAMIC_SYM)}, + { "EACH", SYM(EACH_SYM)}, { "ELSE", SYM(ELSE)}, + { "ELSEIF", SYM(ELSEIF_SYM)}, { "ENABLE", SYM(ENABLE_SYM)}, { "ENCLOSED", SYM(ENCLOSED)}, { "END", SYM(END)}, @@ -170,11 +184,13 @@ static SYMBOL symbols[] = { { "EVENTS", SYM(EVENTS_SYM)}, { "EXECUTE", SYM(EXECUTE_SYM)}, { "EXISTS", SYM(EXISTS)}, + { "EXIT", SYM(EXIT_SYM)}, { "EXPANSION", SYM(EXPANSION_SYM)}, { "EXPLAIN", SYM(DESCRIBE)}, { "EXTENDED", SYM(EXTENDED_SYM)}, { "FALSE", SYM(FALSE_SYM)}, { "FAST", SYM(FAST_SYM)}, + { "FETCH", SYM(FETCH_SYM)}, { "FIELDS", SYM(COLUMNS)}, { "FILE", SYM(FILE_SYM)}, { "FIRST", SYM(FIRST_SYM)}, @@ -186,14 +202,17 @@ static SYMBOL symbols[] = { { "FOR", SYM(FOR_SYM)}, { "FORCE", SYM(FORCE_SYM)}, { "FOREIGN", SYM(FOREIGN)}, + { "FOUND", SYM(FOUND_SYM)}, + { "FRAC_SECOND", SYM(FRAC_SECOND_SYM)}, { "FROM", SYM(FROM)}, { "FULL", SYM(FULL)}, { "FULLTEXT", SYM(FULLTEXT_SYM)}, - { "FUNCTION", SYM(UDF_SYM)}, + { "FUNCTION", SYM(FUNCTION_SYM)}, { "GEOMETRY", SYM(GEOMETRY_SYM)}, { "GEOMETRYCOLLECTION",SYM(GEOMETRYCOLLECTION)}, { "GET_FORMAT", SYM(GET_FORMAT)}, { "GLOBAL", SYM(GLOBAL_SYM)}, + { "GOTO", SYM(GOTO_SYM)}, { "GRANT", SYM(GRANT)}, { "GRANTS", SYM(GRANTS)}, { "GROUP", SYM(GROUP)}, @@ -218,6 +237,8 @@ static SYMBOL symbols[] = { { "INNER", SYM(INNER_SYM)}, { "INNOBASE", SYM(INNOBASE_SYM)}, { "INNODB", SYM(INNOBASE_SYM)}, + { "INOUT", SYM(INOUT_SYM)}, + { "INSENSITIVE", SYM(INSENSITIVE_SYM)}, { "INSERT", SYM(INSERT)}, { "INSERT_METHOD", SYM(INSERT_METHOD)}, { "INT", SYM(INT_SYM)}, @@ -233,12 +254,17 @@ static SYMBOL symbols[] = { { "IS", SYM(IS)}, { "ISOLATION", SYM(ISOLATION)}, { "ISSUER", SYM(ISSUER_SYM)}, + { "ITERATE", SYM(ITERATE_SYM)}, + { "INVOKER", SYM(INVOKER_SYM)}, { "JOIN", SYM(JOIN_SYM)}, { "KEY", SYM(KEY_SYM)}, { "KEYS", SYM(KEYS)}, { "KILL", SYM(KILL_SYM)}, + { "LABEL", SYM(LABEL_SYM)}, + { "LANGUAGE", SYM(LANGUAGE_SYM)}, { "LAST", SYM(LAST_SYM)}, { "LEADING", SYM(LEADING)}, + { "LEAVE", SYM(LEAVE_SYM)}, { "LEAVES", SYM(LEAVES)}, { "LEFT", SYM(LEFT)}, { "LEVEL", SYM(LEVEL_SYM)}, @@ -256,6 +282,7 @@ static SYMBOL symbols[] = { { "LONG", SYM(LONG_SYM)}, { "LONGBLOB", SYM(LONGBLOB)}, { "LONGTEXT", SYM(LONGTEXT)}, + { "LOOP", SYM(LOOP_SYM)}, { "LOW_PRIORITY", SYM(LOW_PRIORITY)}, { "MASTER", SYM(MASTER_SYM)}, { "MASTER_CONNECT_RETRY", SYM(MASTER_CONNECT_RETRY_SYM)}, @@ -281,6 +308,7 @@ static SYMBOL symbols[] = { { "MEDIUMBLOB", SYM(MEDIUMBLOB)}, { "MEDIUMINT", SYM(MEDIUMINT)}, { "MEDIUMTEXT", SYM(MEDIUMTEXT)}, + { "MERGE", SYM(MERGE_SYM)}, { "MICROSECOND", SYM(MICROSECOND_SYM)}, { "MIDDLEINT", SYM(MEDIUMINT)}, /* For powerbuilder */ { "MINUTE", SYM(MINUTE_SYM)}, @@ -289,11 +317,13 @@ static SYMBOL symbols[] = { { "MIN_ROWS", SYM(MIN_ROWS)}, { "MOD", SYM(MOD_SYM)}, { "MODE", SYM(MODE_SYM)}, + { "MODIFIES", SYM(MODIFIES_SYM)}, { "MODIFY", SYM(MODIFY_SYM)}, { "MONTH", SYM(MONTH_SYM)}, { "MULTILINESTRING", SYM(MULTILINESTRING)}, { "MULTIPOINT", SYM(MULTIPOINT)}, { "MULTIPOLYGON", SYM(MULTIPOLYGON)}, + { "NAME", SYM(NAME_SYM)}, { "NAMES", SYM(NAMES_SYM)}, { "NATIONAL", SYM(NATIONAL_SYM)}, { "NATURAL", SYM(NATURAL)}, @@ -319,6 +349,7 @@ static SYMBOL symbols[] = { { "OPTIONALLY", SYM(OPTIONALLY)}, { "OR", SYM(OR_SYM)}, { "ORDER", SYM(ORDER_SYM)}, + { "OUT", SYM(OUT_SYM)}, { "OUTER", SYM(OUTER)}, { "OUTFILE", SYM(OUTFILE)}, { "PACK_KEYS", SYM(PACK_KEYS_SYM)}, @@ -335,6 +366,7 @@ static SYMBOL symbols[] = { { "PROCESS" , SYM(PROCESS)}, { "PROCESSLIST", SYM(PROCESSLIST_SYM)}, { "PURGE", SYM(PURGE)}, + { "QUARTER", SYM(QUARTER_SYM)}, { "QUERY", SYM(QUERY_SYM)}, { "QUICK", SYM(QUICK)}, { "RAID0", SYM(RAID_0_SYM)}, @@ -342,6 +374,7 @@ static SYMBOL symbols[] = { { "RAID_CHUNKSIZE", SYM(RAID_CHUNKSIZE)}, { "RAID_TYPE", SYM(RAID_TYPE)}, { "READ", SYM(READ_SYM)}, + { "READS", SYM(READS_SYM)}, { "REAL", SYM(REAL)}, { "REFERENCES", SYM(REFERENCES)}, { "REGEXP", SYM(REGEXP)}, @@ -354,11 +387,13 @@ static SYMBOL symbols[] = { { "REPEATABLE", SYM(REPEATABLE_SYM)}, { "REPLACE", SYM(REPLACE)}, { "REPLICATION", SYM(REPLICATION)}, + { "REPEAT", SYM(REPEAT_SYM)}, { "REQUIRE", SYM(REQUIRE_SYM)}, { "RESET", SYM(RESET_SYM)}, { "RESTORE", SYM(RESTORE_SYM)}, { "RESTRICT", SYM(RESTRICT)}, - { "RETURNS", SYM(UDF_RETURNS_SYM)}, + { "RETURN", SYM(RETURN_SYM)}, + { "RETURNS", SYM(RETURNS_SYM)}, { "REVOKE", SYM(REVOKE)}, { "RIGHT", SYM(RIGHT)}, { "RLIKE", SYM(REGEXP)}, /* Like in mSQL2 */ @@ -369,9 +404,13 @@ static SYMBOL symbols[] = { { "ROW_FORMAT", SYM(ROW_FORMAT_SYM)}, { "RTREE", SYM(RTREE_SYM)}, { "SAVEPOINT", SYM(SAVEPOINT_SYM)}, + { "SCHEMA", SYM(DATABASE)}, + { "SCHEMAS", SYM(DATABASES)}, { "SECOND", SYM(SECOND_SYM)}, { "SECOND_MICROSECOND", SYM(SECOND_MICROSECOND_SYM)}, + { "SECURITY", SYM(SECURITY_SYM)}, { "SELECT", SYM(SELECT_SYM)}, + { "SENSITIVE", SYM(SENSITIVE_SYM)}, { "SEPARATOR", SYM(SEPARATOR_SYM)}, { "SERIAL", SYM(SERIAL_SYM)}, { "SERIALIZABLE", SYM(SERIALIZABLE_SYM)}, @@ -389,6 +428,11 @@ static SYMBOL symbols[] = { { "SONAME", SYM(UDF_SONAME_SYM)}, { "SOUNDS", SYM(SOUNDS_SYM)}, { "SPATIAL", SYM(SPATIAL_SYM)}, + { "SPECIFIC", SYM(SPECIFIC_SYM)}, + { "SQL", SYM(SQL_SYM)}, + { "SQLEXCEPTION", SYM(SQLEXCEPTION_SYM)}, + { "SQLSTATE", SYM(SQLSTATE_SYM)}, + { "SQLWARNING", SYM(SQLWARNING_SYM)}, { "SQL_BIG_RESULT", SYM(SQL_BIG_RESULT)}, { "SQL_BUFFER_RESULT", SYM(SQL_BUFFER_RESULT)}, { "SQL_CACHE", SYM(SQL_CACHE_SYM)}, @@ -396,6 +440,15 @@ static SYMBOL symbols[] = { { "SQL_NO_CACHE", SYM(SQL_NO_CACHE_SYM)}, { "SQL_SMALL_RESULT", SYM(SQL_SMALL_RESULT)}, { "SQL_THREAD", SYM(SQL_THREAD)}, + { "SQL_TSI_FRAC_SECOND", SYM(FRAC_SECOND_SYM)}, + { "SQL_TSI_SECOND", SYM(SECOND_SYM)}, + { "SQL_TSI_MINUTE", SYM(MINUTE_SYM)}, + { "SQL_TSI_HOUR", SYM(HOUR_SYM)}, + { "SQL_TSI_DAY", SYM(DAY_SYM)}, + { "SQL_TSI_WEEK", SYM(WEEK_SYM)}, + { "SQL_TSI_MONTH", SYM(MONTH_SYM)}, + { "SQL_TSI_QUARTER", SYM(QUARTER_SYM)}, + { "SQL_TSI_YEAR", SYM(YEAR_SYM)}, { "SSL", SYM(SSL_SYM)}, { "START", SYM(START_SYM)}, { "STARTING", SYM(STARTING)}, @@ -411,22 +464,28 @@ static SYMBOL symbols[] = { { "TABLES", SYM(TABLES)}, { "TABLESPACE", SYM(TABLESPACE)}, { "TEMPORARY", SYM(TEMPORARY)}, + { "TEMPTABLE", SYM(TEMPTABLE_SYM)}, { "TERMINATED", SYM(TERMINATED)}, { "TEXT", SYM(TEXT_SYM)}, { "THEN", SYM(THEN_SYM)}, { "TIME", SYM(TIME_SYM)}, { "TIMESTAMP", SYM(TIMESTAMP)}, + { "TIMESTAMPADD", SYM(TIMESTAMP_ADD)}, + { "TIMESTAMPDIFF", SYM(TIMESTAMP_DIFF)}, { "TINYBLOB", SYM(TINYBLOB)}, { "TINYINT", SYM(TINYINT)}, { "TINYTEXT", SYM(TINYTEXT)}, { "TO", SYM(TO_SYM)}, { "TRAILING", SYM(TRAILING)}, { "TRANSACTION", SYM(TRANSACTION_SYM)}, + { "TRIGGER", SYM(TRIGGER_SYM)}, { "TRUE", SYM(TRUE_SYM)}, { "TRUNCATE", SYM(TRUNCATE_SYM)}, { "TYPE", SYM(TYPE_SYM)}, { "TYPES", SYM(TYPES_SYM)}, { "UNCOMMITTED", SYM(UNCOMMITTED_SYM)}, + { "UNDEFINED", SYM(UNDEFINED_SYM)}, + { "UNDO", SYM(UNDO_SYM)}, { "UNICODE", SYM(UNICODE_SYM)}, { "UNION", SYM(UNION_SYM)}, { "UNIQUE", SYM(UNIQUE_SYM)}, @@ -451,8 +510,11 @@ static SYMBOL symbols[] = { { "VARIABLES", SYM(VARIABLES)}, { "VARYING", SYM(VARYING)}, { "WARNINGS", SYM(WARNINGS)}, + { "WEEK", SYM(WEEK_SYM)}, { "WHEN", SYM(WHEN_SYM)}, { "WHERE", SYM(WHERE)}, + { "WHILE", SYM(WHILE_SYM)}, + { "VIEW", SYM(VIEW_SYM)}, { "WITH", SYM(WITH)}, { "WORK", SYM(WORK_SYM)}, { "WRITE", SYM(WRITE_SYM)}, @@ -499,7 +561,6 @@ static SYMBOL sql_functions[] = { { "CONCAT", SYM(CONCAT)}, { "CONCAT_WS", SYM(CONCAT_WS)}, { "CONNECTION_ID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_connection_id)}, - { "CONTAINS", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_contains)}, { "CONV", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_conv)}, { "CONVERT_TZ", SYM(CONVERT_TZ_SYM)}, { "COUNT", SYM(COUNT_SYM)}, @@ -636,14 +697,13 @@ static SYMBOL sql_functions[] = { { "POSITION", SYM(POSITION_SYM)}, { "POW", F_SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)}, { "POWER", F_SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)}, - { "QUARTER", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_quarter)}, { "QUOTE", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_quote)}, { "RADIANS", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_radians)}, { "RAND", SYM(RAND)}, { "RELEASE_LOCK", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_release_lock)}, - { "REPEAT", F_SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_repeat)}, { "REVERSE", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_reverse)}, { "ROUND", SYM(ROUND)}, + { "ROW_COUNT", SYM(ROW_COUNT_SYM)}, { "RPAD", F_SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_rpad)}, { "RTRIM", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_rtrim)}, { "SEC_TO_TIME", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sec_to_time)}, @@ -686,7 +746,6 @@ static SYMBOL sql_functions[] = { { "UUID", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_uuid)}, { "VARIANCE", SYM(VARIANCE_SYM)}, { "VERSION", F_SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_version)}, - { "WEEK", SYM(WEEK_SYM)}, { "WEEKDAY", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekday)}, { "WEEKOFYEAR", F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekofyear)}, { "WITHIN", F_SYM(FUNC_ARG2),0,CREATE_FUNC_GEOM(create_func_within)}, diff --git a/sql/log.cc b/sql/log.cc index bcd99326501..86b76ed883e 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -35,7 +35,7 @@ #include "message.h" #endif -MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; +MYSQL_LOG mysql_log, mysql_slow_log, mysql_bin_log; ulong sync_binlog_counter= 0; static bool test_if_number(const char *str, @@ -129,7 +129,8 @@ static int find_uniq_filename(char *name) MYSQL_LOG::MYSQL_LOG() :bytes_written(0), last_time(0), query_start(0), name(0), file_id(1), open_count(1), log_type(LOG_CLOSED), write_error(0), inited(0), - need_start_event(1) + need_start_event(1), description_event_for_exec(0), + description_event_for_queue(0) { /* We don't want to initialize LOCK_Log here as such initialization depends on @@ -157,6 +158,8 @@ void MYSQL_LOG::cleanup() { inited= 0; close(LOG_CLOSE_INDEX); + delete description_event_for_queue; + delete description_event_for_exec; (void) pthread_mutex_destroy(&LOCK_log); (void) pthread_mutex_destroy(&LOCK_index); (void) pthread_cond_destroy(&update_cond); @@ -226,7 +229,8 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, const char *new_name, const char *index_file_name_arg, enum cache_type io_cache_type_arg, bool no_auto_events_arg, - ulong max_size_arg) + ulong max_size_arg, + bool null_created_arg) { char buff[512]; File file= -1, index_file_nr= -1; @@ -324,8 +328,8 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, if (my_b_safe_write(&log_file, (byte*) BINLOG_MAGIC, BIN_LOG_HEADER_SIZE)) goto err; - bytes_written += BIN_LOG_HEADER_SIZE; - write_file_name_to_index_file=1; + bytes_written+= BIN_LOG_HEADER_SIZE; + write_file_name_to_index_file= 1; } if (!my_b_inited(&index_file)) @@ -355,10 +359,50 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, } if (need_start_event && !no_auto_events) { - need_start_event=0; - Start_log_event s; - s.set_log_pos(this); - s.write(&log_file); + /* + In 4.x we set need_start_event=0 here, but in 5.0 we want a Start event + even if this is not the very first binlog. + */ + Format_description_log_event s(BINLOG_VERSION); + if (!s.is_valid()) + goto err; + if (null_created_arg) + s.created= 0; + if (s.write(&log_file)) + goto err; + bytes_written+= s.data_written; + } + if (description_event_for_queue && + description_event_for_queue->binlog_version>=4) + { + /* + This is a relay log written to by the I/O slave thread. + Write the event so that others can later know the format of this relay + log. + Note that this event is very close to the original event from the + master (it has binlog version of the master, event types of the + master), so this is suitable to parse the next relay log's event. It + has been produced by + Format_description_log_event::Format_description_log_event(char* + buf,). + Why don't we want to write the description_event_for_queue if this + event is for format<4 (3.23 or 4.x): this is because in that case, the + description_event_for_queue describes the data received from the + master, but not the data written to the relay log (*conversion*), + which is in format 4 (slave's). + */ + /* + Set 'created' to 0, so that in next relay logs this event does not + trigger cleaning actions on the slave in + Format_description_log_event::exec_event(). + */ + description_event_for_queue->created= 0; + /* Don't set log_pos in event header */ + description_event_for_queue->artificial_event=1; + + if (description_event_for_queue->write(&log_file)) + goto err; + bytes_written+= description_event_for_queue->data_written; } if (flush_io_cache(&log_file) || my_sync(log_file.file, MYF(MY_WME))) @@ -654,7 +698,7 @@ bool MYSQL_LOG::reset_logs(THD* thd) if (!thd->slave_thread) need_start_event=1; open(save_name, save_log_type, 0, index_file_name, - io_cache_type, no_auto_events, max_size); + io_cache_type, no_auto_events, max_size, 0); my_free((gptr) save_name, MYF(0)); err: @@ -836,22 +880,18 @@ int MYSQL_LOG::purge_logs(const char *to_log, while ((strcmp(to_log,log_info.log_file_name) || (exit_loop=included)) && !log_in_use(log_info.log_file_name)) { - ulong tmp; - LINT_INIT(tmp); + ulong file_size= 0; if (decrease_log_space) //stat the file we want to delete { MY_STAT s; + + /* + If we could not stat, we can't know the amount + of space that deletion will free. In most cases, + deletion won't work either, so it's not a problem. + */ if (my_stat(log_info.log_file_name,&s,MYF(0))) - tmp= s.st_size; - else - { - /* - If we could not stat, we can't know the amount - of space that deletion will free. In most cases, - deletion won't work either, so it's not a problem. - */ - tmp= 0; - } + file_size= s.st_size; } /* It's not fatal if we can't delete a log file ; @@ -859,7 +899,7 @@ int MYSQL_LOG::purge_logs(const char *to_log, */ DBUG_PRINT("info",("purging %s",log_info.log_file_name)); if (!my_delete(log_info.log_file_name, MYF(0)) && decrease_log_space) - *decrease_log_space-= tmp; + *decrease_log_space-= file_size; if (find_next_log(&log_info, 0) || exit_loop) break; } @@ -1024,9 +1064,8 @@ void MYSQL_LOG::new_file(bool need_lock) */ THD *thd = current_thd; /* may be 0 if we are reacting to SIGHUP */ Rotate_log_event r(thd,new_name+dirname_length(new_name)); - r.set_log_pos(this); r.write(&log_file); - bytes_written += r.get_event_len(); + bytes_written += r.data_written; } /* Update needs to be signalled even if there is no rotate event @@ -1044,8 +1083,17 @@ void MYSQL_LOG::new_file(bool need_lock) Note that at this point, log_type != LOG_CLOSED (important for is_open()). */ + /* + new_file() is only used for rotation (in FLUSH LOGS or because size > + max_binlog_size or max_relay_log_size). + If this is a binary log, the Format_description_log_event at the beginning of + the new file should have created=0 (to distinguish with the + Format_description_log_event written at server startup, which should + trigger temp tables deletion on slaves. + */ + open(old_name, save_log_type, new_name_ptr, index_file_name, io_cache_type, - no_auto_events, max_size); + no_auto_events, max_size, 1); if (this == &mysql_bin_log) report_pos_in_innodb(); my_free(old_name,MYF(0)); @@ -1076,7 +1124,7 @@ bool MYSQL_LOG::append(Log_event* ev) error=1; goto err; } - bytes_written += ev->get_event_len(); + bytes_written+= ev->data_written; DBUG_PRINT("info",("max_size: %lu",max_size)); if ((uint) my_b_append_tell(&log_file) > max_size) { @@ -1129,7 +1177,7 @@ err: /* Write to normal (not rotable) log - This is the format for the 'normal', 'slow' and 'update' logs. + This is the format for the 'normal' log. */ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command, @@ -1220,11 +1268,15 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command, inline bool sync_binlog(IO_CACHE *cache) { - return (sync_binlog_period && - (sync_binlog_period == ++sync_binlog_counter) && - (sync_binlog_counter= 0, my_sync(cache->file, MYF(MY_WME)))); + if (sync_binlog_period == ++sync_binlog_counter && sync_binlog_period) + { + sync_binlog_counter= 0; + return my_sync(cache->file, MYF(MY_WME)); + } + return 0; } + /* Write an event to the binary log */ @@ -1292,7 +1344,7 @@ bool MYSQL_LOG::write(Log_event* event_info) if (thd) { -#if MYSQL_VERSION_ID < 50000 + /* NOTE: CHARSET AND TZ REPL WILL BE REWRITTEN SHORTLY */ /* To make replication of charsets working in 4.1 we are writing values of charset related variables before every statement in the binlog, @@ -1318,7 +1370,6 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", (uint) thd->variables.collation_database->number, (uint) thd->variables.collation_server->number); Query_log_event e(thd, buf, written, 0); - e.set_log_pos(this); if (e.write(file)) goto err; } @@ -1334,31 +1385,26 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", thd->variables.time_zone->get_name()->ptr(), "'", NullS); Query_log_event e(thd, buf, buf_end - buf, 0); - e.set_log_pos(this); if (e.write(file)) goto err; } -#endif if (thd->last_insert_id_used) { Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT, thd->current_insert_id); - e.set_log_pos(this); if (e.write(file)) goto err; } if (thd->insert_id_used) { Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id); - e.set_log_pos(this); if (e.write(file)) goto err; } if (thd->rand_used) { Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2); - e.set_log_pos(this); if (e.write(file)) goto err; } @@ -1374,7 +1420,6 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", user_var_event->length, user_var_event->type, user_var_event->charset_number); - e.set_log_pos(this); if (e.write(file)) goto err; } @@ -1386,48 +1431,17 @@ COLLATION_CONNECTION=%u,COLLATION_DATABASE=%u,COLLATION_SERVER=%u", p= strmov(strmov(buf, "SET CHARACTER SET "), thd->variables.convert_set->name); Query_log_event e(thd, buf, (ulong) (p - buf), 0); - e.set_log_pos(this); if (e.write(file)) goto err; } #endif - - /* - If the user has set FOREIGN_KEY_CHECKS=0 we wrap every SQL - command in the binlog inside: - SET FOREIGN_KEY_CHECKS=0; - ; - SET FOREIGN_KEY_CHECKS=1; - */ - - if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) - { - Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=0", 24, 0); - e.set_log_pos(this); - if (e.write(file)) - goto err; - } } /* Write the SQL command */ - event_info->set_log_pos(this); if (event_info->write(file)) goto err; - /* Write log events to reset the 'run environment' of the SQL command */ - - if (thd) - { - if (thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) - { - Query_log_event e(thd, "SET FOREIGN_KEY_CHECKS=1", 24, 0); - e.set_log_pos(this); - if (e.write(file)) - goto err; - } - } - /* Tell for transactional table handlers up to which position in the binlog file we wrote. The table handler can store this info, and @@ -1604,7 +1618,6 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) master's binlog, which would result in wrong positions being shown to the user, MASTER_POS_WAIT undue waiting etc. */ - qinfo.set_log_pos(this); if (qinfo.write(&log_file)) goto err; } @@ -1630,7 +1643,6 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool commit_or_rollback) commit_or_rollback ? "COMMIT" : "ROLLBACK", commit_or_rollback ? 6 : 8, TRUE); - qinfo.set_log_pos(this); if (qinfo.write(&log_file) || flush_io_cache(&log_file) || sync_binlog(&log_file)) goto err; @@ -1692,8 +1704,7 @@ err: /* - Write update log in a format suitable for incremental backup - This is also used by the slow query log. + Write to the slow query log. */ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, @@ -1877,8 +1888,8 @@ void MYSQL_LOG::close(uint exiting) (exiting & LOG_CLOSE_STOP_EVENT)) { Stop_log_event s; - s.set_log_pos(this); s.write(&log_file); + bytes_written+= s.data_written; signal_update(); } #endif /* HAVE_REPLICATION */ diff --git a/sql/log_event.cc b/sql/log_event.cc index 091566c5d90..7fba19cb000 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -180,10 +180,12 @@ static void cleanup_load_tmpdir() write_str() */ -static bool write_str(IO_CACHE *file, char *str, byte length) +static bool write_str(IO_CACHE *file, char *str, uint length) { - return (my_b_safe_write(file, &length, 1) || - my_b_safe_write(file, (byte*) str, (int) length)); + byte tmp[1]; + tmp[0]= (byte) length; + return (my_b_safe_write(file, tmp, sizeof(tmp)) || + my_b_safe_write(file, (byte*) str, length)); } @@ -191,17 +193,18 @@ static bool write_str(IO_CACHE *file, char *str, byte length) read_str() */ -static inline int read_str(char * &buf, char *buf_end, char * &str, - uint8 &len) +static inline int read_str(char **buf, char *buf_end, char **str, + uint8 *len) { - if (buf + (uint) (uchar) *buf >= buf_end) + if (*buf + ((uint) (uchar) **buf) >= buf_end) return 1; - len = (uint8) *buf; - str= buf+1; - buf+= (uint) len+1; + *len= (uint8) **buf; + *str= (*buf)+1; + (*buf)+= (uint) *len+1; return 0; } + /* Transforms a string into "" or its expression in 0x... form. */ @@ -225,9 +228,25 @@ static char *str_to_hex(char *to, char *from, uint len) return p; // pointer to end 0 of 'to' } +/* + Prints a "session_var=value" string. Used by mysqlbinlog to print some SET + commands just before it prints a query. +*/ + +static void print_set_option(FILE* file, uint32 bits_changed, uint32 option, + uint32 flags, const char* name, bool* need_comma) +{ + if (bits_changed & option) + { + if (*need_comma) + fprintf(file,", "); + fprintf(file,"%s=%d", name, (bool)(flags & option)); + *need_comma= 1; + } +} /************************************************************************** - Log_event methods + Log_event methods (= the parent class of all events) **************************************************************************/ /* @@ -237,7 +256,7 @@ static char *str_to_hex(char *to, char *from, uint len) const char* Log_event::get_type_str() { switch(get_type_code()) { - case START_EVENT: return "Start"; + case START_EVENT_V3: return "Start_v3"; case STOP_EVENT: return "Stop"; case QUERY_EVENT: return "Query"; case ROTATE_EVENT: return "Rotate"; @@ -251,6 +270,7 @@ const char* Log_event::get_type_str() case EXEC_LOAD_EVENT: return "Exec_load"; case RAND_EVENT: return "RAND"; case USER_VAR_EVENT: return "User var"; + case FORMAT_DESCRIPTION_EVENT: return "Format_desc"; default: return "Unknown"; /* impossible */ } } @@ -262,8 +282,7 @@ const char* Log_event::get_type_str() #ifndef MYSQL_CLIENT Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) - :log_pos(0), temp_buf(0), exec_time(0), cached_event_len(0), - flags(flags_arg), thd(thd_arg) + :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg) { server_id= thd->server_id; when= thd->start_time; @@ -280,7 +299,7 @@ Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans) */ Log_event::Log_event() - :temp_buf(0), exec_time(0), cached_event_len(0), flags(0), cache_stmt(0), + :temp_buf(0), exec_time(0), flags(0), cache_stmt(0), thd(0) { server_id= ::server_id; @@ -294,24 +313,70 @@ Log_event::Log_event() Log_event::Log_event() */ -Log_event::Log_event(const char* buf, bool old_format) - :temp_buf(0), cached_event_len(0), cache_stmt(0) +Log_event::Log_event(const char* buf, + const Format_description_log_event* description_event) + :temp_buf(0), cache_stmt(0) { - when = uint4korr(buf); - server_id = uint4korr(buf + SERVER_ID_OFFSET); - if (old_format) - { - log_pos=0; - flags=0; - } - else - { - log_pos = uint4korr(buf + LOG_POS_OFFSET); - flags = uint2korr(buf + FLAGS_OFFSET); - } #ifndef MYSQL_CLIENT thd = 0; #endif + when = uint4korr(buf); + server_id = uint4korr(buf + SERVER_ID_OFFSET); + if (description_event->binlog_version==1) + { + log_pos= 0; + flags= 0; + return; + } + /* 4.0 or newer */ + log_pos= uint4korr(buf + LOG_POS_OFFSET); + /* + If the log is 4.0 (so here it can only be a 4.0 relay log read by the SQL + thread or a 4.0 master binlog read by the I/O thread), log_pos is the + beginning of the event: we transform it into the end of the event, which is + more useful. + But how do you know that the log is 4.0: you know it if description_event + is version 3 *and* you are not reading a Format_desc (remember that + mysqlbinlog starts by assuming that 5.0 logs are in 4.0 format, until it + finds a Format_desc). + */ + if (description_event->binlog_version==3 && + buf[EVENT_TYPE_OFFSET]group_master_log_pos" (see + inc_group_relay_log_pos()). As it is unreal log_pos, adding the event + len's is nonsense. For example, a fake Rotate event should + not have its log_pos (which is 0) changed or it will modify + Exec_master_log_pos in SHOW SLAVE STATUS, displaying a nonsense value + of (a non-zero offset which does not exist in the master's binlog, so + which will cause problems if the user uses this value in + CHANGE MASTER). + */ + log_pos+= uint4korr(buf + EVENT_LEN_OFFSET); + } + DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos)); + + flags= uint2korr(buf + FLAGS_OFFSET); + if ((buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT) || + (buf[EVENT_TYPE_OFFSET] == ROTATE_EVENT)) + { + /* + These events always have a header which stops here (i.e. their header is + FROZEN). + */ + /* + Initialization to zero of all other Log_event members as they're not + specified. Currently there are no such members; in the future there will + be an event UID (but Format_description and Rotate don't need this UID, + as they are not propagated through --log-slave-updates (remember the UID + is used to not play a query twice when you have two masters which are + slaves of a 3rd master). Then we are done. + */ + return; + } + /* otherwise, go on with reading the header from buf (nothing now) */ } #ifndef MYSQL_CLIENT @@ -364,10 +429,10 @@ int Log_event::exec_event(struct st_relay_log_info* rli) has already been updated. */ if ((thd->options & OPTION_BEGIN) && opt_using_transactions) - rli->inc_event_relay_log_pos(get_event_len()); + rli->inc_event_relay_log_pos(); else { - rli->inc_group_relay_log_pos(get_event_len(),log_pos); + rli->inc_group_relay_log_pos(log_pos); flush_relay_log_info(rli); /* Note that Rotate_log_event::exec_event() does not call this function, @@ -429,49 +494,95 @@ void Log_event::init_show_field_list(List* field_list) field_list->push_back(new Item_empty_string("Event_type", 20)); field_list->push_back(new Item_return_int("Server_id", 10, MYSQL_TYPE_LONG)); - field_list->push_back(new Item_return_int("Orig_log_pos", 11, + field_list->push_back(new Item_return_int("End_log_pos", 11, MYSQL_TYPE_LONGLONG)); field_list->push_back(new Item_empty_string("Info", 20)); } #endif /* !MYSQL_CLIENT */ + /* Log_event::write() */ -int Log_event::write(IO_CACHE* file) +bool Log_event::write_header(IO_CACHE* file, ulong event_data_length) { - return (write_header(file) || write_data(file)) ? -1 : 0; -} + byte header[LOG_EVENT_HEADER_LEN]; + DBUG_ENTER("Log_event::write_header"); + /* Store number of bytes that will be written by this event */ + data_written= event_data_length + sizeof(header); -/* - Log_event::write_header() -*/ + /* + log_pos != 0 if this is relay-log event. In this case we should not + change the position + */ -int Log_event::write_header(IO_CACHE* file) -{ - char buf[LOG_EVENT_HEADER_LEN]; - char* pos = buf; - int4store(pos, (ulong) when); // timestamp - pos += 4; - *pos++ = get_type_code(); // event type code - int4store(pos, server_id); - pos += 4; - long tmp=get_data_size() + LOG_EVENT_HEADER_LEN; - int4store(pos, tmp); - pos += 4; - int4store(pos, log_pos); - pos += 4; - int2store(pos, flags); - pos += 2; - return (my_b_safe_write(file, (byte*) buf, (uint) (pos - buf))); + if (is_artificial_event()) + { + /* + We should not do any cleanup on slave when reading this. We + mark this by setting log_pos to 0. Start_log_event_v3() will + detect this on reading and set artificial_event=1 for the event. + */ + log_pos= 0; + } + else if (!log_pos) + { + /* + Calculate position of end of event + + Note that with a SEQ_READ_APPEND cache, my_b_tell() does not + work well. So this will give slightly wrong positions for the + Format_desc/Rotate/Stop events which the slave writes to its + relay log. For example, the initial Format_desc will have + end_log_pos=91 instead of 95. Because after writing the first 4 + bytes of the relay log, my_b_tell() still reports 0. Because + my_b_append() does not update the counter which my_b_tell() + later uses (one should probably use my_b_append_tell() to work + around this). To get right positions even when writing to the + relay log, we use the (new) my_b_safe_tell(). + + Note that this raises a question on the correctness of all these + DBUG_ASSERT(my_b_tell()=rli->event_relay_log_pos). + + If in a transaction, the log_pos which we calculate below is not + very good (because then my_b_safe_tell() returns start position + of the BEGIN, so it's like the statement was at the BEGIN's + place), but it's not a very serious problem (as the slave, when + it is in a transaction, does not take those end_log_pos into + account (as it calls inc_event_relay_log_pos()). To be fixed + later, so that it looks less strange. But not bug. + */ + + log_pos= my_b_safe_tell(file)+data_written; + } + + /* + Header will be of size LOG_EVENT_HEADER_LEN for all events, except for + FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT, where it will be + LOG_EVENT_MINIMAL_HEADER_LEN (remember these 2 have a frozen header, + because we read them before knowing the format). + */ + + int4store(header, (ulong) when); // timestamp + header[EVENT_TYPE_OFFSET]= get_type_code(); + int4store(header+ SERVER_ID_OFFSET, server_id); + int4store(header+ EVENT_LEN_OFFSET, data_written); + int4store(header+ LOG_POS_OFFSET, log_pos); + int2store(header+ FLAGS_OFFSET, flags); + + DBUG_RETURN(my_b_safe_write(file, header, sizeof(header)) != 0); } /* Log_event::read_log_event() + + This needn't be format-tolerant, because we only read + LOG_EVENT_MINIMAL_HEADER_LEN (we just want to read the event's length). + */ #ifndef MYSQL_CLIENT @@ -480,7 +591,7 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, { ulong data_len; int result=0; - char buf[LOG_EVENT_HEADER_LEN]; + char buf[LOG_EVENT_MINIMAL_HEADER_LEN]; DBUG_ENTER("read_log_event"); if (log_lock) @@ -500,24 +611,25 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, goto end; } data_len= uint4korr(buf + EVENT_LEN_OFFSET); - if (data_len < LOG_EVENT_HEADER_LEN || + if (data_len < LOG_EVENT_MINIMAL_HEADER_LEN || data_len > current_thd->variables.max_allowed_packet) { DBUG_PRINT("error",("data_len: %ld", data_len)); - result= ((data_len < LOG_EVENT_HEADER_LEN) ? LOG_READ_BOGUS : + result= ((data_len < LOG_EVENT_MINIMAL_HEADER_LEN) ? LOG_READ_BOGUS : LOG_READ_TOO_LARGE); goto end; } packet->append(buf, sizeof(buf)); - data_len-= LOG_EVENT_HEADER_LEN; + data_len-= LOG_EVENT_MINIMAL_HEADER_LEN; if (data_len) { if (packet->append(file, data_len)) { /* - Here we should never hit EOF in a non-error condition. + Here if we hit EOF it's really an error: as data_len is >=0 + there's supposed to be more bytes available. EOF means we are reading the event partially, which should - never happen. + never happen: either we read badly or the binlog is truncated. */ result= file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO; /* Implicit goto end; */ @@ -545,24 +657,42 @@ end: Log_event::read_log_event() NOTE: - Allocates memory; The caller is responsible for clean-up + Allocates memory; The caller is responsible for clean-up. */ #ifndef MYSQL_CLIENT Log_event* Log_event::read_log_event(IO_CACHE* file, pthread_mutex_t* log_lock, - bool old_format) + const Format_description_log_event *description_event) #else -Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) +Log_event* Log_event::read_log_event(IO_CACHE* file, + const Format_description_log_event *description_event) #endif { - char head[LOG_EVENT_HEADER_LEN]; - uint header_size= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; + DBUG_ASSERT(description_event); + char head[LOG_EVENT_MINIMAL_HEADER_LEN]; + /* + First we only want to read at most LOG_EVENT_MINIMAL_HEADER_LEN, just to + check the event for sanity and to know its length; no need to really parse + it. We say "at most" because this could be a 3.23 master, which has header + of 13 bytes, whereas LOG_EVENT_MINIMAL_HEADER_LEN is 19 bytes (it's "minimal" + over the set {MySQL >=4.0}). + */ + uint header_size= min(description_event->common_header_len, + LOG_EVENT_MINIMAL_HEADER_LEN); LOCK_MUTEX; + DBUG_PRINT("info", ("my_b_tell=%lu", my_b_tell(file))); if (my_b_read(file, (byte *) head, header_size)) { + DBUG_PRINT("info", ("Log_event::read_log_event(IO_CACHE*,Format_desc*) \ +failed my_b_read")); UNLOCK_MUTEX; + /* + No error here; it could be that we are at the file's end. However if the + next my_b_read() fails (below), it will be an error as we were able to + read the first bytes. + */ return 0; } @@ -596,7 +726,8 @@ Log_event* Log_event::read_log_event(IO_CACHE* file, bool old_format) error = "read error"; goto err; } - if ((res = read_log_event(buf, data_len, &error, old_format))) + if ((res= read_log_event(buf, data_len, &error, + description_event))) res->register_temp_buf(buf); err: @@ -623,13 +754,18 @@ Error in Log_event::read_log_event(): '%s', data_len: %d, event_type: %d", /* Log_event::read_log_event() + Binlog format tolerance is in (buf, event_len, description_event) + constructors. */ -Log_event* Log_event::read_log_event(const char* buf, int event_len, - const char **error, bool old_format) +Log_event* Log_event::read_log_event(const char* buf, uint event_len, + const char **error, + const Format_description_log_event *description_event) { - DBUG_ENTER("Log_event::read_log_event"); - + Log_event* ev; + DBUG_ENTER("Log_event::read_log_event(char*,...)"); + DBUG_ASSERT(description_event); + DBUG_PRINT("info", ("binlog_version: %d", description_event->binlog_version)); if (event_len < EVENT_LEN_OFFSET || (uint) event_len != uint4korr(buf+EVENT_LEN_OFFSET)) { @@ -637,74 +773,87 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len, DBUG_RETURN(NULL); // general sanity check - will fail on a partial read } - Log_event* ev = NULL; - switch(buf[EVENT_TYPE_OFFSET]) { case QUERY_EVENT: - ev = new Query_log_event(buf, event_len, old_format); + ev = new Query_log_event(buf, event_len, description_event); break; case LOAD_EVENT: - ev = new Create_file_log_event(buf, event_len, old_format); + ev = new Create_file_log_event(buf, event_len, description_event); break; case NEW_LOAD_EVENT: - ev = new Load_log_event(buf, event_len, old_format); + ev = new Load_log_event(buf, event_len, description_event); break; case ROTATE_EVENT: - ev = new Rotate_log_event(buf, event_len, old_format); + ev = new Rotate_log_event(buf, event_len, description_event); break; #ifdef HAVE_REPLICATION - case SLAVE_EVENT: + case SLAVE_EVENT: /* can never happen (unused event) */ ev = new Slave_log_event(buf, event_len); break; #endif /* HAVE_REPLICATION */ case CREATE_FILE_EVENT: - ev = new Create_file_log_event(buf, event_len, old_format); + ev = new Create_file_log_event(buf, event_len, description_event); break; case APPEND_BLOCK_EVENT: - ev = new Append_block_log_event(buf, event_len); + ev = new Append_block_log_event(buf, event_len, description_event); break; case DELETE_FILE_EVENT: - ev = new Delete_file_log_event(buf, event_len); + ev = new Delete_file_log_event(buf, event_len, description_event); break; case EXEC_LOAD_EVENT: - ev = new Execute_load_log_event(buf, event_len); + ev = new Execute_load_log_event(buf, event_len, description_event); break; - case START_EVENT: - ev = new Start_log_event(buf, old_format); + case START_EVENT_V3: /* this is sent only by MySQL <=4.x */ + ev = new Start_log_event_v3(buf, description_event); break; #ifdef HAVE_REPLICATION case STOP_EVENT: - ev = new Stop_log_event(buf, old_format); + ev = new Stop_log_event(buf, description_event); break; #endif /* HAVE_REPLICATION */ case INTVAR_EVENT: - ev = new Intvar_log_event(buf, old_format); + ev = new Intvar_log_event(buf, description_event); break; case RAND_EVENT: - ev = new Rand_log_event(buf, old_format); + ev = new Rand_log_event(buf, description_event); break; case USER_VAR_EVENT: - ev = new User_var_log_event(buf, old_format); + ev = new User_var_log_event(buf, description_event); + break; + case FORMAT_DESCRIPTION_EVENT: + ev = new Format_description_log_event(buf, event_len, description_event); break; default: + DBUG_PRINT("error",("Unknown evernt code: %d",(int) buf[EVENT_TYPE_OFFSET])); + ev= NULL; break; } + /* + is_valid() are small event-specific sanity tests which are important; for + example there are some my_malloc() in constructors + (e.g. Query_log_event::Query_log_event(char*...)); when these my_malloc() + fail we can't return an error out of the constructor (because constructor + is "void") ; so instead we leave the pointer we wanted to allocate + (e.g. 'query') to 0 and we test it in is_valid(). Same for + Format_description_log_event, member 'post_header_len'. + */ if (!ev || !ev->is_valid()) { + DBUG_PRINT("error",("Found invalid event in binary log")); + delete ev; #ifdef MYSQL_CLIENT - if (!force_opt) + if (!force_opt) /* then mysqlbinlog dies */ { *error= "Found invalid event in binary log"; DBUG_RETURN(0); } - ev= new Unknown_log_event(buf, old_format); + ev= new Unknown_log_event(buf, description_event); #else *error= "Found invalid event in binary log"; DBUG_RETURN(0); #endif } - ev->cached_event_len = event_len; DBUG_RETURN(ev); } @@ -719,7 +868,7 @@ void Log_event::print_header(FILE* file) char llbuff[22]; fputc('#', file); print_timestamp(file); - fprintf(file, " server id %d log_pos %s ", server_id, + fprintf(file, " server id %d end_log_pos %s ", server_id, llstr(log_pos,llbuff)); } @@ -751,19 +900,6 @@ void Log_event::print_timestamp(FILE* file, time_t* ts) #endif /* MYSQL_CLIENT */ -/* - Log_event::set_log_pos() -*/ - -#ifndef MYSQL_CLIENT -void Log_event::set_log_pos(MYSQL_LOG* log) -{ - if (!log_pos) - log_pos = my_b_tell(&log->log_file); -} -#endif /* !MYSQL_CLIENT */ - - /************************************************************************** Query_log_event methods **************************************************************************/ @@ -772,10 +908,15 @@ void Log_event::set_log_pos(MYSQL_LOG* log) /* Query_log_event::pack_info() + This (which is used only for SHOW BINLOG EVENTS) could be updated to + print SET @@session_var=. But this is not urgent, as SHOW BINLOG EVENTS is + only an information, it does not produce suitable queries to replay (for + example it does not print LOAD DATA INFILE). */ void Query_log_event::pack_info(Protocol *protocol) { + // TODO: show the catalog ?? char *buf, *pos; if (!(buf= my_malloc(9 + db_len + q_len, MYF(MY_WME)))) return; @@ -799,31 +940,27 @@ void Query_log_event::pack_info(Protocol *protocol) /* Query_log_event::write() + + NOTES: + In this event we have to modify the header to have the correct + EVENT_LEN_OFFSET as we don't yet know how many status variables we + will print! */ -int Query_log_event::write(IO_CACHE* file) +bool Query_log_event::write(IO_CACHE* file) { - return query ? Log_event::write(file) : -1; -} - - -/* - Query_log_event::write_data() -*/ - -int Query_log_event::write_data(IO_CACHE* file) -{ - char buf[QUERY_HEADER_LEN]; + uchar buf[QUERY_HEADER_LEN+1+4+1+8+1+1+FN_REFLEN+5], *start, *start_of_status; + ulong event_length; if (!query) - return -1; - + return 1; // Something wrong with event + /* We want to store the thread id: (- as an information for the user when he reads the binlog) - if the query uses temporary table: for the slave SQL thread to know to which master connection the temp table belongs. - Now imagine we (write_data()) are called by the slave SQL thread (we are + Now imagine we (write()) are called by the slave SQL thread (we are logging a query executed by this thread; the slave runs with --log-slave-updates). Then this query will be logged with thread_id=the_thread_id_of_the_SQL_thread. Imagine that 2 temp tables of @@ -860,9 +997,77 @@ int Query_log_event::write_data(IO_CACHE* file) buf[Q_DB_LEN_OFFSET] = (char) db_len; int2store(buf + Q_ERR_CODE_OFFSET, error_code); - return (my_b_safe_write(file, (byte*) buf, QUERY_HEADER_LEN) || - my_b_safe_write(file, (db) ? (byte*) db : (byte*)"", db_len + 1) || - my_b_safe_write(file, (byte*) query, q_len)) ? -1 : 0; + /* + You MUST always write status vars in increasing order of code. This + guarantees that a slightly older slave will be able to parse those he + knows. + */ + start_of_status= start= buf+QUERY_HEADER_LEN; + if (flags2_inited) + { + *(start++)= Q_FLAGS2_CODE; + int4store(start, flags2); + start+= 4; + } + if (sql_mode_inited) + { + *(start++)= Q_SQL_MODE_CODE; + int8store(start, sql_mode); + start+= 8; + } + if (catalog_len >= 0) // i.e. "catalog inited" (false for 4.0 events) + { + *(start++)= Q_CATALOG_CODE; + *(start++)= (uchar) catalog_len; + bmove(start, catalog, catalog_len); + start+= catalog_len; + /* + We write a \0 at the end. As we also have written the length, it's + apparently useless; but in fact it enables us to just do + catalog= a_pointer_to_the_buffer_of_the_read_event + later in the slave SQL thread. + If we didn't have the \0, we would need to memdup to build the catalog in + the slave SQL thread. + And still the interest of having the length too is that in the slave SQL + thread we immediately know at which position the catalog ends (no need to + search for '\0'. In other words: length saves search, \0 saves mem alloc, + at the cost of 1 redundant byte on the disk. + Note that this is only a fix until we change 'catalog' to LEX_STRING + (then we won't need the \0). + */ + *(start++)= '\0'; + } + if (auto_increment_increment != 1) + { + *start++= Q_AUTO_INCREMENT; + int2store(start, auto_increment_increment); + int2store(start+2, auto_increment_offset); + start+= 4; + } + /* + Here there could be code like + if (command-line-option-which-says-"log_this_variable") + { + *(start++)= Q_THIS_VARIABLE_CODE; + int4store(start, this_variable); + start+= 4; + } + */ + + /* Store length of status variables */ + status_vars_len= (uint) (start-start_of_status); + int2store(buf + Q_STATUS_VARS_LEN_OFFSET, status_vars_len); + + /* + Calculate length of whole event + The "1" below is the \0 in the db's length + */ + event_length= (uint) (start-buf) + db_len + 1 + q_len; + + return (write_header(file, event_length) || + my_b_safe_write(file, (byte*) buf, (uint) (start-buf)) || + my_b_safe_write(file, (db) ? (byte*) db : (byte*)"", db_len + 1) || + my_b_safe_write(file, (byte*) query, q_len)) ? 1 : 0; } @@ -875,60 +1080,162 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length, bool using_trans) :Log_event(thd_arg, !thd_arg->tmp_table_used ? 0 : LOG_EVENT_THREAD_SPECIFIC_F, using_trans), - data_buf(0), query(query_arg), + data_buf(0), query(query_arg), catalog(thd_arg->catalog), db(thd_arg->db), q_len((uint32) query_length), - error_code(thd_arg->killed ? + error_code((thd_arg->killed != THD::NOT_KILLED) ? ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ? - 0 : ER_SERVER_SHUTDOWN) : thd_arg->net.last_errno), + 0 : thd->killed_errno()) : thd_arg->net.last_errno), thread_id(thd_arg->thread_id), /* save the original thread id; we already know the server id */ - slave_proxy_id(thd_arg->variables.pseudo_thread_id) + slave_proxy_id(thd_arg->variables.pseudo_thread_id), + flags2_inited(1), sql_mode_inited(1), flags2(0), + sql_mode(thd_arg->variables.sql_mode), + auto_increment_increment(thd_arg->variables.auto_increment_increment), + auto_increment_offset(thd_arg->variables.auto_increment_offset) { time_t end_time; time(&end_time); exec_time = (ulong) (end_time - thd->start_time); + catalog_len = (catalog) ? (uint32) strlen(catalog) : 0; + status_vars_len= 1+4+1+8+1+1+catalog_len+1; db_len = (db) ? (uint32) strlen(db) : 0; + /* + If we don't use flags2 for anything else than options contained in + thd->options, it would be more efficient to flags2=thd_arg->options + (OPTIONS_WRITTEN_TO_BINLOG would be used only at reading time). + But it's likely that we don't want to use 32 bits for 3 bits; in the future + we will probably want to reclaim the 29 bits. So we need the &. + */ + flags2= thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG; + + DBUG_PRINT("info",("Query_log_event has flags2=%lu sql_mode=%lu",flags2,sql_mode)); } #endif /* MYSQL_CLIENT */ /* Query_log_event::Query_log_event() + This is used by the SQL slave thread to prepare the event before execution. */ -Query_log_event::Query_log_event(const char* buf, int event_len, - bool old_format) - :Log_event(buf, old_format),data_buf(0), query(NULL), db(NULL) +Query_log_event::Query_log_event(const char* buf, uint event_len, + const Format_description_log_event *description_event) + :Log_event(buf, description_event), data_buf(0), query(NullS), catalog(NullS), + db(NullS), catalog_len(0), status_vars_len(0), + flags2_inited(0), sql_mode_inited(0) { ulong data_len; - if (old_format) - { - if ((uint)event_len < OLD_HEADER_LEN + QUERY_HEADER_LEN) - return; - data_len = event_len - (QUERY_HEADER_LEN + OLD_HEADER_LEN); - buf += OLD_HEADER_LEN; - } - else - { - if ((uint)event_len < QUERY_EVENT_OVERHEAD) - return; - data_len = event_len - QUERY_EVENT_OVERHEAD; - buf += LOG_EVENT_HEADER_LEN; - } + uint32 tmp; + uint8 common_header_len, post_header_len; + const char *start, *end; + DBUG_ENTER("Query_log_event::Query_log_event(char*,...)"); + common_header_len= description_event->common_header_len; + post_header_len= description_event->post_header_len[QUERY_EVENT-1]; + DBUG_PRINT("info",("event_len=%ld, common_header_len=%d, post_header_len=%d", + event_len, common_header_len, post_header_len)); + + /* + We test if the event's length is sensible, and if so we compute data_len. + We cannot rely on QUERY_HEADER_LEN here as it would not be format-tolerant. + We use QUERY_HEADER_MINIMAL_LEN which is the same for 3.23, 4.0 & 5.0. + */ + if (event_len < (uint)(common_header_len + post_header_len)) + DBUG_VOID_RETURN; + data_len = event_len - (common_header_len + post_header_len); + buf+= common_header_len; + + slave_proxy_id= thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET); exec_time = uint4korr(buf + Q_EXEC_TIME_OFFSET); - error_code = uint2korr(buf + Q_ERR_CODE_OFFSET); - - if (!(data_buf = (char*) my_malloc(data_len + 1, MYF(MY_WME)))) - return; - - memcpy(data_buf, buf + Q_DATA_OFFSET, data_len); - slave_proxy_id= thread_id= uint4korr(buf + Q_THREAD_ID_OFFSET); - db = data_buf; db_len = (uint)buf[Q_DB_LEN_OFFSET]; - query=data_buf + db_len + 1; - q_len = data_len - 1 - db_len; - *((char*)query+q_len) = 0; + error_code = uint2korr(buf + Q_ERR_CODE_OFFSET); + /* If auto_increment is not set by query_event, they should not be used */ + auto_increment_increment= auto_increment_offset= 1; + + /* + 5.0 format starts here. + Depending on the format, we may or not have affected/warnings etc + The remnent post-header to be parsed has length: + */ + tmp= post_header_len - QUERY_HEADER_MINIMAL_LEN; + if (tmp) + { + status_vars_len= uint2korr(buf + Q_STATUS_VARS_LEN_OFFSET); + data_len-= status_vars_len; + DBUG_PRINT("info", ("Query_log_event has status_vars_len: %u", + (uint) status_vars_len)); + tmp-= 2; + } + /* we have parsed everything we know in the post header */ +#ifndef DBUG_OFF + if (tmp) /* this is probably a master newer than us */ + DBUG_PRINT("info", ("Query_log_event has longer post header than we know\ + (%d more bytes)", tmp)); +#endif + + /* variable-part: the status vars; only in MySQL 5.0 */ + + start= (char*) (buf+post_header_len); + end= (char*) (start+status_vars_len); + for (const uchar* pos= (const uchar*) start; pos < (const uchar*) end;) + { + switch (*pos++) { + case Q_FLAGS2_CODE: + flags2_inited= 1; + flags2= uint4korr(pos); + DBUG_PRINT("info",("In Query_log_event, read flags2: %lu", flags2)); + pos+= 4; + break; + case Q_SQL_MODE_CODE: + { +#ifndef DBUG_OFF + char buff[22]; +#endif + sql_mode_inited= 1; + sql_mode= (ulong) uint8korr(pos); // QQ: Fix when sql_mode is ulonglong + DBUG_PRINT("info",("In Query_log_event, read sql_mode: %s", + llstr(sql_mode, buff))); + pos+= 8; + break; + } + case Q_CATALOG_CODE: + catalog_len= *pos; + if (catalog_len) + catalog= (char*) pos+1; // Will be copied later + pos+= catalog_len+2; + break; + case Q_AUTO_INCREMENT: + auto_increment_increment= uint2korr(pos); + auto_increment_offset= uint2korr(pos+2); + pos+= 4; + break; + default: + /* That's why you must write status vars in growing order of code */ + DBUG_PRINT("info",("Query_log_event has unknown status vars (first has\ + code: %u), skipping the rest of them", (uint) *(pos-1))); + pos= (const uchar*) end; // Break look + } + } + + /* A 2nd variable part; this is common to all versions */ + + if (!(start= data_buf = (char*) my_malloc(catalog_len + data_len +2, MYF(MY_WME)))) + DBUG_VOID_RETURN; + if (catalog) // If catalog is given + { + memcpy((char*) start, catalog, catalog_len+1); // Copy name and end \0 + catalog= start; + start+= catalog_len+1; + } + memcpy((char*) start, end, data_len); // Copy db and query + ((char*) start)[data_len]= '\0'; // End query with \0 (For safetly) + db= start; + query= start + db_len + 1; + q_len= data_len - db_len -1; + /* This is used to detect wrong parsing. Could be removed in the future. */ + DBUG_PRINT("info", ("catalog: '%s' len: %u db: '%s' len: %u q_len: %lu", + catalog, (uint) catalog_len, db, (uint) db_len,q_len)); + DBUG_VOID_RETURN; } @@ -937,9 +1244,14 @@ Query_log_event::Query_log_event(const char* buf, int event_len, */ #ifdef MYSQL_CLIENT -void Query_log_event::print(FILE* file, bool short_form, char* last_db) +void Query_log_event::print(FILE* file, bool short_form, + LAST_EVENT_INFO* last_event_info) { + // TODO: print the catalog ?? char buff[40],*end; // Enough for SET TIMESTAMP + bool different_db= 1; + uint32 tmp; + if (!short_form) { print_header(file); @@ -947,12 +1259,10 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) (ulong) thread_id, (ulong) exec_time, error_code); } - bool different_db= 1; - - if (db && last_db) + if (db) { - if (different_db= memcmp(last_db, db, db_len + 1)) - memcpy(last_db, db, db_len + 1); + if ((different_db = memcmp(last_event_info->db, db, db_len + 1))) + memcpy(last_event_info->db, db, db_len + 1); } if (db && db[0] && different_db) @@ -963,8 +1273,76 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) my_fwrite(file, (byte*) buff, (uint) (end-buff),MYF(MY_NABP | MY_WME)); if (flags & LOG_EVENT_THREAD_SPECIFIC_F) fprintf(file,"SET @@session.pseudo_thread_id=%lu;\n",(ulong)thread_id); + /* + Now the session variables; + it's more efficient to pass SQL_MODE as a number instead of a + comma-separated list. + FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS are session-only + variables (they have no global version; they're not listed in sql_class.h), + The tests below work for pure binlogs or pure relay logs. Won't work for + mixed relay logs but we don't create mixed relay logs (that is, there is no + relay log with a format change except within the 3 first events, which + mysqlbinlog handles gracefully). So this code should always be good. + */ + + if (likely(flags2_inited)) /* likely as this will mainly read 5.0 logs */ + { + /* tmp is a bitmask of bits which have changed. */ + if (likely(last_event_info->flags2_inited)) + /* All bits which have changed */ + tmp= (last_event_info->flags2) ^ flags2; + else /* that's the first Query event we read */ + { + last_event_info->flags2_inited= 1; + tmp= ~((uint32)0); /* all bits have changed */ + } + + if (unlikely(tmp)) /* some bits have changed */ + { + bool need_comma= 0; + fprintf(file, "SET "); + print_set_option(file, tmp, OPTION_NO_FOREIGN_KEY_CHECKS, ~flags2, + "@@session.foreign_key_checks", &need_comma); + print_set_option(file, tmp, OPTION_AUTO_IS_NULL, flags2, + "@@session.sql_auto_is_null", &need_comma); + print_set_option(file, tmp, OPTION_RELAXED_UNIQUE_CHECKS, ~flags2, + "@@session.unique_checks", &need_comma); + fprintf(file,";\n"); + last_event_info->flags2= flags2; + } + } + + /* + If flags2_inited==0, this is an event from 3.23 or 4.0; nothing to print + (remember we don't produce mixed relay logs so there cannot be 5.0 events + before that one so there is nothing to reset). + */ + + if (likely(sql_mode_inited)) + { + if (unlikely(!last_event_info->sql_mode_inited)) /* first Query event */ + { + last_event_info->sql_mode_inited= 1; + /* force a difference to force write */ + last_event_info->sql_mode= ~sql_mode; + } + if (unlikely(last_event_info->sql_mode != sql_mode)) + { + fprintf(file,"SET @@session.sql_mode=%lu;\n",(ulong)sql_mode); + last_event_info->sql_mode= sql_mode; + } + } + if (last_event_info->auto_increment_increment != auto_increment_increment || + last_event_info->auto_increment_offset != auto_increment_offset) + { + fprintf(file,"SET @@session.auto_increment_increment=%lu, @@session.auto_increment_offset=%lu;\n", + auto_increment_increment,auto_increment_offset); + last_event_info->auto_increment_increment= auto_increment_increment; + last_event_info->auto_increment_offset= auto_increment_offset; + } + my_fwrite(file, (byte*) query, q_len, MYF(MY_NABP | MY_WME)); - fprintf(file, ";\n"); + fputs(";\n", file); } #endif /* MYSQL_CLIENT */ @@ -977,20 +1355,30 @@ void Query_log_event::print(FILE* file, bool short_form, char* last_db) int Query_log_event::exec_event(struct st_relay_log_info* rli) { int expected_error,actual_error= 0; - thd->db_length= db_len; - thd->db= (char*) rewrite_db(db, &thd->db_length); + /* + Colleagues: please never free(thd->catalog) in MySQL. This would lead to + bugs as here thd->catalog is a part of an alloced block, not an entire + alloced block (see Query_log_event::exec_event()). Same for thd->db. + Thank you. + */ + thd->catalog= (char*) catalog; + thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed + thd->variables.auto_increment_increment= auto_increment_increment; + thd->variables.auto_increment_offset= auto_increment_offset; /* - InnoDB internally stores the master log position it has processed so far; - position to store is of the END of the current log event. + InnoDB internally stores the master log position it has executed so far, + i.e. the position just after the COMMIT event. + When InnoDB will want to store, the positions in rli won't have + been updated yet, so group_master_log_* will point to old BEGIN + and event_master_log* will point to the beginning of current COMMIT. + But log_pos of the COMMIT Query event is what we want, i.e. the pos of the + END of the current log event (COMMIT). We save it in rli so that InnoDB can + access it. */ -#if MYSQL_VERSION_ID < 50000 - rli->future_group_master_log_pos= log_pos + get_event_len() - - (rli->mi->old_format ? (LOG_EVENT_HEADER_LEN - OLD_HEADER_LEN) : 0); -#else - /* In 5.0 we store the end_log_pos in the relay log so no problem */ rli->future_group_master_log_pos= log_pos; -#endif + DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos)); + clear_all_errors(thd, rli); if (db_ok(thd->db, replicate_do_db, replicate_ignore_db)) @@ -1002,9 +1390,33 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) thd->query_id = query_id++; VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->variables.pseudo_thread_id= thread_id; // for temp tables - mysql_log.write(thd,COM_QUERY,"%s",thd->query); DBUG_PRINT("query",("%s",thd->query)); + + if (flags2_inited) + /* + all bits of thd->options which are 1 in OPTIONS_WRITTEN_TO_BIN_LOG must + take their value from flags2. + */ + thd->options= flags2|(thd->options & ~(ulong)OPTIONS_WRITTEN_TO_BIN_LOG); + /* + else, we are in a 3.23/4.0 binlog; we previously received a + Rotate_log_event which reset thd->options and sql_mode, so nothing to do. + */ + + /* + We do not replicate IGNORE_DIR_IN_CREATE. That is, if the master is a + slave which runs with SQL_MODE=IGNORE_DIR_IN_CREATE, this should not + force us to ignore the dir too. Imagine you are a ring of machines, and + one has a disk problem so that you temporarily need IGNORE_DIR_IN_CREATE + on this machine; you don't want it to propagate elsewhere (you don't want + all slaves to start ignoring the dirs). + */ + if (sql_mode_inited) + thd->variables.sql_mode= + (ulong) ((thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) | + (sql_mode & ~(ulong) MODE_NO_DIR_IN_CREATE)); + if (ignored_error_code((expected_error= error_code)) || !check_expected_error(thd,rli,expected_error)) mysql_parse(thd, thd->query, q_len); @@ -1032,20 +1444,20 @@ START SLAVE; . Query: '%s'", expected_error, thd->query); } goto end; } - + /* If we expected a non-zero error code, and we don't get the same error code, and none of them should be ignored. */ DBUG_PRINT("info",("expected_error: %d last_errno: %d", - expected_error, thd->net.last_errno)); + expected_error, thd->net.last_errno)); if ((expected_error != (actual_error= thd->net.last_errno)) && - expected_error && - !ignored_error_code(actual_error) && - !ignored_error_code(expected_error)) + expected_error && + !ignored_error_code(actual_error) && + !ignored_error_code(expected_error)) { slave_print_error(rli, 0, - "\ + "\ Query caused different errors on master and slave. \ Error on master: '%s' (%d), Error on slave: '%s' (%d). \ Default database: '%s'. Query: '%s'", @@ -1053,14 +1465,14 @@ Default database: '%s'. Query: '%s'", expected_error, actual_error ? thd->net.last_error: "no error", actual_error, - print_slave_db_safe(thd->db), query); + print_slave_db_safe(db), query); thd->query_error= 1; } /* If we get the same error code as expected, or they should be ignored. */ else if (expected_error == actual_error || - ignored_error_code(actual_error)) + ignored_error_code(actual_error)) { DBUG_PRINT("info",("error ignored")); clear_all_errors(thd, rli); @@ -1077,11 +1489,43 @@ Default database: '%s'. Query: '%s'", print_slave_db_safe(thd->db), query); thd->query_error= 1; } + + /* + TODO: compare the values of "affected rows" around here. Something + like: + if ((uint32) affected_in_event != (uint32) affected_on_slave) + { + sql_print_error("Slave: did not get the expected number of affected \ + rows running query from master - expected %d, got %d (this numbers \ + should have matched modulo 4294967296).", 0, ...); + thd->query_error = 1; + } + We may also want an option to tell the slave to ignore "affected" + mismatch. This mismatch could be implemented with a new ER_ code, and + to ignore it you would use --slave-skip-errors... + + To do the comparison we need to know the value of "affected" which the + above mysql_parse() computed. And we need to know the value of + "affected" in the master's binlog. Both will be implemented later. The + important thing is that we now have the format ready to log the values + of "affected" in the binlog. So we can release 5.0.0 before effectively + logging "affected" and effectively comparing it. + */ } /* End of if (db_ok(... */ end: VOID(pthread_mutex_lock(&LOCK_thread_count)); - thd->db= 0; // prevent db from being freed + /* + Probably we have set thd->query, thd->db, thd->catalog to point to places + in the data_buf of this event. Now the event is going to be deleted + probably, so data_buf will be freed, so the thd->... listed above will be + pointers to freed memory. + So we must set them to 0, so that those bad pointers values are not later + used. Note that "cleanup" queries (automatic DO RELEASE_LOCK() and DROP + TEMPORARY TABLE don't suffer from these assignments to 0 as DROP TEMPORARY + TABLE uses the db.table syntax). + */ + thd->db= thd->catalog= 0; // prevent db from being freed thd->query= 0; // just to be sure thd->query_length= thd->db_length =0; VOID(pthread_mutex_unlock(&LOCK_thread_count)); @@ -1094,22 +1538,30 @@ end: updating query. */ return (thd->query_error ? thd->query_error : - (thd->one_shot_set ? (rli->inc_event_relay_log_pos(get_event_len()),0) : + (thd->one_shot_set ? (rli->inc_event_relay_log_pos(),0) : Log_event::exec_event(rli))); } #endif /************************************************************************** - Start_log_event methods + Start_log_event_v3 methods **************************************************************************/ +#ifndef MYSQL_CLIENT +Start_log_event_v3::Start_log_event_v3() :Log_event(), binlog_version(BINLOG_VERSION), artificial_event(0) +{ + created= when; + memcpy(server_version, ::server_version, ST_SERVER_VER_LEN); +} +#endif + /* - Start_log_event::pack_info() + Start_log_event_v3::pack_info() */ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) -void Start_log_event::pack_info(Protocol *protocol) +void Start_log_event_v3::pack_info(Protocol *protocol) { char buf[12 + ST_SERVER_VER_LEN + 14 + 22], *pos; pos= strmov(buf, "Server ver: "); @@ -1122,57 +1574,69 @@ void Start_log_event::pack_info(Protocol *protocol) /* - Start_log_event::print() + Start_log_event_v3::print() */ #ifdef MYSQL_CLIENT -void Start_log_event::print(FILE* file, bool short_form, char* last_db) +void Start_log_event_v3::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { - if (short_form) - return; - - print_header(file); - fprintf(file, "\tStart: binlog v %d, server v %s created ", binlog_version, - server_version); - print_timestamp(file); - if (created) - fprintf(file," at startup"); - fputc('\n', file); + if (!short_form) + { + print_header(file); + fprintf(file, "\tStart: binlog v %d, server v %s created ", binlog_version, + server_version); + print_timestamp(file); + if (created) + fprintf(file," at startup"); + fputc('\n', file); + } +#ifdef WHEN_WE_HAVE_THE_RESET_CONNECTION_SQL_COMMAND + /* + This is for mysqlbinlog: like in replication, we want to delete the stale + tmp files left by an unclean shutdown of mysqld (temporary tables). Probably + this can be done with RESET CONNECTION (syntax to be defined). + */ + fprintf(file,"RESET CONNECTION;\n"); +#endif fflush(file); } #endif /* MYSQL_CLIENT */ /* - Start_log_event::Start_log_event() + Start_log_event_v3::Start_log_event_v3() */ -Start_log_event::Start_log_event(const char* buf, - bool old_format) - :Log_event(buf, old_format) +Start_log_event_v3::Start_log_event_v3(const char* buf, + const Format_description_log_event* description_event) + :Log_event(buf, description_event) { - buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; - binlog_version = uint2korr(buf+ST_BINLOG_VER_OFFSET); + buf+= description_event->common_header_len; + binlog_version= uint2korr(buf+ST_BINLOG_VER_OFFSET); memcpy(server_version, buf+ST_SERVER_VER_OFFSET, ST_SERVER_VER_LEN); - created = uint4korr(buf+ST_CREATED_OFFSET); + created= uint4korr(buf+ST_CREATED_OFFSET); + /* We use log_pos to mark if this was an artificial event or not */ + artificial_event= (log_pos == 0); } /* - Start_log_event::write_data() + Start_log_event_v3::write() */ -int Start_log_event::write_data(IO_CACHE* file) +bool Start_log_event_v3::write(IO_CACHE* file) { - char buff[START_HEADER_LEN]; + char buff[START_V3_HEADER_LEN]; int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version); memcpy(buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN); int4store(buff + ST_CREATED_OFFSET,created); - return (my_b_safe_write(file, (byte*) buff, sizeof(buff)) ? -1 : 0); + return (write_header(file, sizeof(buff)) || + my_b_safe_write(file, (byte*) buff, sizeof(buff))); } + /* - Start_log_event::exec_event() + Start_log_event_v3::exec_event() The master started @@ -1191,23 +1655,29 @@ int Start_log_event::write_data(IO_CACHE* file) */ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) -int Start_log_event::exec_event(struct st_relay_log_info* rli) +int Start_log_event_v3::exec_event(struct st_relay_log_info* rli) { - DBUG_ENTER("Start_log_event::exec_event"); - + DBUG_ENTER("Start_log_event_v3::exec_event"); /* If the I/O thread has not started, mi->old_format is BINLOG_FORMAT_CURRENT (that's what the MASTER_INFO constructor does), so the test below is not perfect at all. */ - switch (rli->mi->old_format) { - case BINLOG_FORMAT_CURRENT: - /* - This is 4.x, so a Start_log_event is only at master startup, - so we are sure the master has restarted and cleared his temp tables. + switch (rli->relay_log.description_event_for_exec->binlog_version) + { + case 3: + case 4: + /* + This can either be 4.x (then a Start_log_event_v3 is only at master + startup so we are sure the master has restarted and cleared his temp + tables; the event always has 'created'>0) or 5.0 (then we have to test + 'created'). */ - close_temporary_tables(thd); - cleanup_load_tmpdir(); + if (created) + { + close_temporary_tables(thd); + cleanup_load_tmpdir(); + } /* As a transaction NEVER spans on 2 or more binlogs: if we have an active transaction at this point, the master died while @@ -1215,8 +1685,12 @@ int Start_log_event::exec_event(struct st_relay_log_info* rli) cache to the binlog. As the write was started, the transaction had been committed on the master, so we lack of information to replay this transaction on the slave; all we can do is stop with error. + Note: this event could be sent by the master to inform us of the format + of its binlog; in other words maybe it is not at its original place when + it comes to us; we'll know this by checking log_pos ("artificial" events + have log_pos == 0). */ - if (thd->options & OPTION_BEGIN) + if (!artificial_event && (thd->options & OPTION_BEGIN)) { slave_print_error(rli, 0, "\ Rolling back unfinished transaction (no COMMIT or ROLLBACK) from relay log. \ @@ -1230,33 +1704,274 @@ binary log."); Now the older formats; in that case load_tmpdir is cleaned up by the I/O thread. */ - case BINLOG_FORMAT_323_LESS_57: - /* - Cannot distinguish a Start_log_event generated at master startup and - one generated by master FLUSH LOGS, so cannot be sure temp tables - have to be dropped. So do nothing. - */ - break; - case BINLOG_FORMAT_323_GEQ_57: - /* - Can distinguish, based on the value of 'created', - which was generated at master startup. - */ - if (created) + case 1: + if (strncmp(rli->relay_log.description_event_for_exec->server_version, + "3.23.57",7) >= 0 && created) + { + /* + Can distinguish, based on the value of 'created': this event was + generated at master startup. + */ close_temporary_tables(thd); + } + /* + Otherwise, can't distinguish a Start_log_event generated at + master startup and one generated by master FLUSH LOGS, so cannot + be sure temp tables have to be dropped. So do nothing. + */ break; default: /* this case is impossible */ - return 1; + DBUG_RETURN(1); } - DBUG_RETURN(Log_event::exec_event(rli)); } #endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */ -/************************************************************************** - Load_log_event methods -**************************************************************************/ +/*************************************************************************** + Format_description_log_event methods +****************************************************************************/ + +/* + Format_description_log_event 1st ctor. + + SYNOPSIS + Format_description_log_event::Format_description_log_event + binlog_version the binlog version for which we want to build + an event. Can be 1 (=MySQL 3.23), 3 (=4.0.x + x>=2 and 4.1) or 4 (MySQL 5.0). Note that the + old 4.0 (binlog version 2) is not supported; + it should not be used for replication with + 5.0. + + DESCRIPTION + Ctor. Can be used to create the event to write to the binary log (when the + server starts or when FLUSH LOGS), or to create artificial events to parse + binlogs from MySQL 3.23 or 4.x. + When in a client, only the 2nd use is possible. + + TODO + Update this code with the new event for LOAD DATA, once they are pushed (in + 4.1 or 5.0). If it's in 5.0, only the "case 4" block should be updated. + +*/ + +Format_description_log_event:: +Format_description_log_event(uint8 binlog_ver, + const char* server_ver) + :Start_log_event_v3() +{ + created= when; + binlog_version= binlog_ver; + switch (binlog_ver) { + case 4: /* MySQL 5.0 */ + memcpy(server_version, ::server_version, ST_SERVER_VER_LEN); + common_header_len= LOG_EVENT_HEADER_LEN; + number_of_event_types= LOG_EVENT_TYPES; + /* we'll catch my_malloc() error in is_valid() */ + post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8), + MYF(0)); + /* + This long list of assignments is not beautiful, but I see no way to + make it nicer, as the right members are #defines, not array members, so + it's impossible to write a loop. + */ + if (post_header_len) + { + post_header_len[START_EVENT_V3-1]= START_V3_HEADER_LEN; + post_header_len[QUERY_EVENT-1]= QUERY_HEADER_LEN; + post_header_len[STOP_EVENT-1]= 0; + post_header_len[ROTATE_EVENT-1]= ROTATE_HEADER_LEN; + post_header_len[INTVAR_EVENT-1]= 0; + post_header_len[LOAD_EVENT-1]= LOAD_HEADER_LEN; + post_header_len[SLAVE_EVENT-1]= 0; + post_header_len[CREATE_FILE_EVENT-1]= CREATE_FILE_HEADER_LEN; + post_header_len[APPEND_BLOCK_EVENT-1]= APPEND_BLOCK_HEADER_LEN; + post_header_len[EXEC_LOAD_EVENT-1]= EXEC_LOAD_HEADER_LEN; + post_header_len[DELETE_FILE_EVENT-1]= DELETE_FILE_HEADER_LEN; + post_header_len[NEW_LOAD_EVENT-1]= post_header_len[LOAD_EVENT-1]; + post_header_len[RAND_EVENT-1]= 0; + post_header_len[USER_VAR_EVENT-1]= 0; + post_header_len[FORMAT_DESCRIPTION_EVENT-1]= FORMAT_DESCRIPTION_HEADER_LEN; + } + break; + + case 1: /* 3.23 */ + case 3: /* 4.0.x x>=2 */ + /* + We build an artificial (i.e. not sent by the master) event, which + describes what those old master versions send. + */ + if (binlog_ver==1) + strmov(server_version, server_ver ? server_ver : "3.23"); + else + strmov(server_version, server_ver ? server_ver : "4.0"); + common_header_len= binlog_ver==1 ? OLD_HEADER_LEN : + LOG_EVENT_MINIMAL_HEADER_LEN; + /* + The first new event in binlog version 4 is Format_desc. So any event type + after that does not exist in older versions. We use the events known by + version 3, even if version 1 had only a subset of them (this is not a + problem: it uses a few bytes for nothing but unifies code; it does not + make the slave detect less corruptions). + */ + number_of_event_types= FORMAT_DESCRIPTION_EVENT - 1; + post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8), + MYF(0)); + if (post_header_len) + { + post_header_len[START_EVENT_V3-1]= START_V3_HEADER_LEN; + post_header_len[QUERY_EVENT-1]= QUERY_HEADER_MINIMAL_LEN; + post_header_len[STOP_EVENT-1]= 0; + post_header_len[ROTATE_EVENT-1]= (binlog_ver==1) ? 0 : ROTATE_HEADER_LEN; + post_header_len[INTVAR_EVENT-1]= 0; + post_header_len[LOAD_EVENT-1]= LOAD_HEADER_LEN; + post_header_len[SLAVE_EVENT-1]= 0; + post_header_len[CREATE_FILE_EVENT-1]= CREATE_FILE_HEADER_LEN; + post_header_len[APPEND_BLOCK_EVENT-1]= APPEND_BLOCK_HEADER_LEN; + post_header_len[EXEC_LOAD_EVENT-1]= EXEC_LOAD_HEADER_LEN; + post_header_len[DELETE_FILE_EVENT-1]= DELETE_FILE_HEADER_LEN; + post_header_len[NEW_LOAD_EVENT-1]= post_header_len[LOAD_EVENT-1]; + post_header_len[RAND_EVENT-1]= 0; + post_header_len[USER_VAR_EVENT-1]= 0; + } + break; + default: /* Includes binlog version 2 i.e. 4.0.x x<=1 */ + post_header_len= 0; /* will make is_valid() fail */ + break; + } +} + + +/* + The problem with this constructor is that the fixed header may have a + length different from this version, but we don't know this length as we + have not read the Format_description_log_event which says it, yet. This + length is in the post-header of the event, but we don't know where the + post-header starts. + So this type of event HAS to: + - either have the header's length at the beginning (in the header, at a + fixed position which will never be changed), not in the post-header. That + would make the header be "shifted" compared to other events. + - or have a header of size LOG_EVENT_MINIMAL_HEADER_LEN (19), in all future + versions, so that we know for sure. + I (Guilhem) chose the 2nd solution. Rotate has the same constraint (because + it is sent before Format_description_log_event). +*/ + +Format_description_log_event:: +Format_description_log_event(const char* buf, + uint event_len, + const + Format_description_log_event* + description_event) + :Start_log_event_v3(buf, description_event) +{ + DBUG_ENTER("Format_description_log_event::Format_description_log_event(char*,...)"); + buf+= LOG_EVENT_MINIMAL_HEADER_LEN; + if ((common_header_len=buf[ST_COMMON_HEADER_LEN_OFFSET]) < OLD_HEADER_LEN) + DBUG_VOID_RETURN; /* sanity check */ + number_of_event_types= + event_len-(LOG_EVENT_MINIMAL_HEADER_LEN+ST_COMMON_HEADER_LEN_OFFSET+1); + DBUG_PRINT("info", ("common_header_len=%d number_of_event_types=%d", + common_header_len, number_of_event_types)); + /* If alloc fails, we'll detect it in is_valid() */ + post_header_len= (uint8*) my_memdup((byte*)buf+ST_COMMON_HEADER_LEN_OFFSET+1, + number_of_event_types* + sizeof(*post_header_len), + MYF(0)); + DBUG_VOID_RETURN; +} + + +bool Format_description_log_event::write(IO_CACHE* file) +{ + /* + We don't call Start_log_event_v3::write() because this would make 2 + my_b_safe_write(). + */ + byte buff[FORMAT_DESCRIPTION_HEADER_LEN]; + int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version); + memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN); + int4store(buff + ST_CREATED_OFFSET,created); + buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN; + memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (byte*) post_header_len, + LOG_EVENT_TYPES); + return (write_header(file, sizeof(buff)) || + my_b_safe_write(file, buff, sizeof(buff))); +} + +/* + SYNOPSIS + Format_description_log_event::exec_event() + + IMPLEMENTATION + Save the information which describes the binlog's format, to be able to + read all coming events. + Call Start_log_event_v3::exec_event(). +*/ + +#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) +int Format_description_log_event::exec_event(struct st_relay_log_info* rli) +{ + DBUG_ENTER("Format_description_log_event::exec_event"); + + /* save the information describing this binlog */ + delete rli->relay_log.description_event_for_exec; + rli->relay_log.description_event_for_exec= this; + + /* + If this event comes from ourselves, there is no cleaning task to perform, + we don't call Start_log_event_v3::exec_event() (this was just to update the + log's description event). + */ + if (server_id == (uint32) ::server_id) + { + /* + Do not modify rli->group_master_log_pos, as this event did not exist on + the master. That is, just update the *relay log* coordinates; this is + done by passing log_pos=0 to inc_group_relay_log_pos, like we do in + Stop_log_event::exec_event(). + If in a transaction, don't touch group_* coordinates. + */ + if (thd->options & OPTION_BEGIN) + rli->inc_event_relay_log_pos(); + else + { + rli->inc_group_relay_log_pos(0); + flush_relay_log_info(rli); + } + DBUG_RETURN(0); + } + + /* + If the event was not requested by the slave i.e. the master sent it while + the slave asked for a position >4, the event will make + rli->group_master_log_pos advance. Say that the slave asked for position + 1000, and the Format_desc event's end is 95. Then in the beginning of + replication rli->group_master_log_pos will be 0, then 95, then jump to first + really asked event (which is >95). So this is ok. + */ + DBUG_RETURN(Start_log_event_v3::exec_event(rli)); +} +#endif + + /************************************************************************** + Load_log_event methods + General note about Load_log_event: the binlogging of LOAD DATA INFILE is + going to be changed in 5.0 (or maybe in 4.1; not decided yet). + However, the 5.0 slave could still have to read such events (from a 4.x + master), convert them (which just means maybe expand the header, when 5.0 + servers have a UID in events) (remember that whatever is after the header + will be like in 4.x, as this event's format is not modified in 5.0 as we + will use new types of events to log the new LOAD DATA INFILE features). + To be able to read/convert, we just need to not assume that the common + header is of length LOG_EVENT_HEADER_LEN (we must use the description + event). + Note that I (Guilhem) manually tested replication of a big LOAD DATA INFILE + between 3.23 and 5.0, and between 4.0 and 5.0, and it works fine (and the + positions displayed in SHOW SLAVE STATUS then are fine too). + **************************************************************************/ /* Load_log_event::pack_info() @@ -1363,7 +2078,7 @@ void Load_log_event::pack_info(Protocol *protocol) Load_log_event::write_data_header() */ -int Load_log_event::write_data_header(IO_CACHE* file) +bool Load_log_event::write_data_header(IO_CACHE* file) { char buf[LOAD_HEADER_LEN]; int4store(buf + L_THREAD_ID_OFFSET, slave_proxy_id); @@ -1372,7 +2087,7 @@ int Load_log_event::write_data_header(IO_CACHE* file) buf[L_TBL_LEN_OFFSET] = (char)table_name_len; buf[L_DB_LEN_OFFSET] = (char)db_len; int4store(buf + L_NUM_FIELDS_OFFSET, num_fields); - return my_b_safe_write(file, (byte*)buf, LOAD_HEADER_LEN); + return my_b_safe_write(file, (byte*)buf, LOAD_HEADER_LEN) != 0; } @@ -1380,7 +2095,7 @@ int Load_log_event::write_data_header(IO_CACHE* file) Load_log_event::write_data_body() */ -int Load_log_event::write_data_body(IO_CACHE* file) +bool Load_log_event::write_data_body(IO_CACHE* file) { if (sql_ex.write_data(file)) return 1; @@ -1483,6 +2198,7 @@ Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, } #endif /* !MYSQL_CLIENT */ + /* Load_log_event::Load_log_event() @@ -1491,15 +2207,25 @@ Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex, constructed event. */ -Load_log_event::Load_log_event(const char *buf, int event_len, - bool old_format) - :Log_event(buf, old_format), num_fields(0), fields(0), - field_lens(0), field_block_len(0), +Load_log_event::Load_log_event(const char *buf, uint event_len, + const Format_description_log_event *description_event) + :Log_event(buf, description_event), num_fields(0), fields(0), + field_lens(0),field_block_len(0), table_name(0), db(0), fname(0), local_fname(FALSE) { DBUG_ENTER("Load_log_event"); - if (event_len) // derived class, will call copy_log_event() itself - copy_log_event(buf, event_len, old_format); + /* + I (Guilhem) manually tested replication of LOAD DATA INFILE for 3.23->5.0, + 4.0->5.0 and 5.0->5.0 and it works. + */ + if (event_len) + copy_log_event(buf, event_len, + ((buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? + LOAD_HEADER_LEN + + description_event->common_header_len : + LOAD_HEADER_LEN + LOG_EVENT_HEADER_LEN), + description_event); + /* otherwise it's a derived class, will call copy_log_event() itself */ DBUG_VOID_RETURN; } @@ -1509,14 +2235,14 @@ Load_log_event::Load_log_event(const char *buf, int event_len, */ int Load_log_event::copy_log_event(const char *buf, ulong event_len, - bool old_format) + int body_offset, + const Format_description_log_event *description_event) { + DBUG_ENTER("Load_log_event::copy_log_event"); uint data_len; char* buf_end = (char*)buf + event_len; - uint header_len= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; - const char* data_head = buf + header_len; - DBUG_ENTER("Load_log_event::copy_log_event"); - + /* this is the beginning of the post-header */ + const char* data_head = buf + description_event->common_header_len; slave_proxy_id= thread_id= uint4korr(data_head + L_THREAD_ID_OFFSET); exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET); skip_lines = uint4korr(data_head + L_SKIP_LINES_OFFSET); @@ -1524,21 +2250,17 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, db_len = (uint)data_head[L_DB_LEN_OFFSET]; num_fields = uint4korr(data_head + L_NUM_FIELDS_OFFSET); - int body_offset = ((buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? - LOAD_HEADER_LEN + header_len : - get_data_body_offset()); - if ((int) event_len < body_offset) DBUG_RETURN(1); /* Sql_ex.init() on success returns the pointer to the first byte after the sql_ex structure, which is the start of field lengths array. */ - if (!(field_lens=(uchar*)sql_ex.init((char*)buf + body_offset, - buf_end, - buf[EVENT_TYPE_OFFSET] != LOAD_EVENT))) + if (!(field_lens= (uchar*)sql_ex.init((char*)buf + body_offset, + buf_end, + buf[EVENT_TYPE_OFFSET] != LOAD_EVENT))) DBUG_RETURN(1); - + data_len = event_len - body_offset; if (num_fields > data_len) // simple sanity check against corruption DBUG_RETURN(1); @@ -1551,6 +2273,12 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, fname = db + db_len + 1; fname_len = strlen(fname); // null termination is accomplished by the caller doing buf[event_len]=0 + + /* + In 5.0 this event will have the same format, as we are planning to log LOAD + DATA INFILE in a completely different way (as a plain-text query) since 4.1 + or 5.0 (Dmitri's WL#874) + */ DBUG_RETURN(0); } @@ -1560,13 +2288,13 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, */ #ifdef MYSQL_CLIENT -void Load_log_event::print(FILE* file, bool short_form, char* last_db) +void Load_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { - print(file, short_form, last_db, 0); + print(file, short_form, last_event_info, 0); } -void Load_log_event::print(FILE* file, bool short_form, char* last_db, +void Load_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info, bool commented) { DBUG_ENTER("Load_log_event::print"); @@ -1578,7 +2306,7 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db, } bool different_db= 1; - if (db && last_db) + if (db) { /* If the database is different from the one of the previous statement, we @@ -1586,9 +2314,9 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db, But if commented, the "use" is going to be commented so we should not update the last_db. */ - if ((different_db= memcmp(last_db, db, db_len + 1)) && + if ((different_db= memcmp(last_event_info->db, db, db_len + 1)) && !commented) - memcpy(last_db, db, db_len + 1); + memcpy(last_event_info->db, db, db_len + 1); } if (db && db[0] && different_db) @@ -1715,15 +2443,12 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, mysql_init_query(thd, 0, 0); if (!use_rli_only_for_errors) { -#if MYSQL_VERSION_ID < 50000 - rli->future_group_master_log_pos= log_pos + get_event_len() - - (rli->mi->old_format ? (LOG_EVENT_HEADER_LEN - OLD_HEADER_LEN) : 0); -#else + /* Saved for InnoDB, see comment in Query_log_event::exec_event() */ rli->future_group_master_log_pos= log_pos; -#endif + DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos)); } - - /* + + /* We test replicate_*_db rules. Note that we have already prepared the file to load, even if we are going to ignore and delete it now. So it is possible that we did a lot of disk writes for nothing. In other words, a @@ -1832,7 +2557,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, thd->net.pkt_nr = net->pkt_nr; } if (mysql_load(thd, &ex, &tables, field_list, handle_dup, net != 0, - TL_WRITE)) + TL_WRITE, 0)) thd->query_error = 1; if (thd->cuted_fields) { @@ -1863,7 +2588,7 @@ Slave: load data infile on table '%s' at log position %s in log \ thd->net.vio = 0; char *save_db= thd->db; VOID(pthread_mutex_lock(&LOCK_thread_count)); - thd->db= 0; + thd->db= thd->catalog= 0; thd->query= 0; thd->query_length= thd->db_length= 0; VOID(pthread_mutex_unlock(&LOCK_thread_count)); @@ -1930,17 +2655,17 @@ void Rotate_log_event::pack_info(Protocol *protocol) */ #ifdef MYSQL_CLIENT -void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) +void Rotate_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { char buf[22]; + if (short_form) return; - print_header(file); fprintf(file, "\tRotate to "); if (new_log_ident) my_fwrite(file, (byte*) new_log_ident, (uint)ident_len, - MYF(MY_NABP | MY_WME)); + MYF(MY_NABP | MY_WME)); fprintf(file, " pos: %s", llstr(pos, buf)); fputc('\n', file); fflush(file); @@ -1952,31 +2677,22 @@ void Rotate_log_event::print(FILE* file, bool short_form, char* last_db) Rotate_log_event::Rotate_log_event() */ -Rotate_log_event::Rotate_log_event(const char* buf, int event_len, - bool old_format) - :Log_event(buf, old_format),new_log_ident(NULL),alloced(0) +Rotate_log_event::Rotate_log_event(const char* buf, uint event_len, + const Format_description_log_event* description_event) + :Log_event(buf, description_event) ,new_log_ident(NULL),alloced(0) { + DBUG_ENTER("Rotate_log_event::Rotate_log_event(char*,...)"); // The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET - int header_size = (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; + uint8 header_size= description_event->common_header_len; + uint8 post_header_len= description_event->post_header_len[ROTATE_EVENT-1]; uint ident_offset; - DBUG_ENTER("Rotate_log_event"); - if (event_len < header_size) DBUG_VOID_RETURN; - buf += header_size; - if (old_format) - { - ident_len = (uint)(event_len - OLD_HEADER_LEN); - pos = 4; - ident_offset = 0; - } - else - { - ident_len = (uint)(event_len - ROTATE_EVENT_OVERHEAD); - pos = uint8korr(buf + R_POS_OFFSET); - ident_offset = ROTATE_HEADER_LEN; - } + pos = post_header_len ? uint8korr(buf + R_POS_OFFSET) : 4; + ident_len = (uint)(event_len - + (header_size+post_header_len)); + ident_offset = post_header_len; set_if_smaller(ident_len,FN_REFLEN-1); if (!(new_log_ident= my_strdup_with_length((byte*) buf + ident_offset, @@ -1989,29 +2705,31 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len, /* - Rotate_log_event::write_data() + Rotate_log_event::write() */ -int Rotate_log_event::write_data(IO_CACHE* file) +bool Rotate_log_event::write(IO_CACHE* file) { char buf[ROTATE_HEADER_LEN]; int8store(buf + R_POS_OFFSET, pos); - return (my_b_safe_write(file, (byte*)buf, ROTATE_HEADER_LEN) || - my_b_safe_write(file, (byte*)new_log_ident, (uint) ident_len)); + return (write_header(file, ROTATE_HEADER_LEN + ident_len) || + my_b_safe_write(file, (byte*)buf, ROTATE_HEADER_LEN) || + my_b_safe_write(file, (byte*)new_log_ident, (uint) ident_len)); } /* Rotate_log_event::exec_event() - Got a rotate log even from the master + Got a rotate log event from the master IMPLEMENTATION This is mainly used so that we can later figure out the logname and position for the master. - We can't rotate the slave as this will cause infinitive rotations + We can't rotate the slave's BINlog as this will cause infinitive rotations in a A -> B -> A setup. + The NOTES below is a wrong comment which will disappear when 4.1 is merged. RETURN VALUES 0 ok @@ -2023,7 +2741,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli) DBUG_ENTER("Rotate_log_event::exec_event"); pthread_mutex_lock(&rli->data_lock); - rli->event_relay_log_pos += get_event_len(); + rli->event_relay_log_pos= my_b_tell(rli->cur_log); /* If we are in a transaction: the only normal case is when the I/O thread was copying a big transaction, then it was stopped and restarted: we have this @@ -2035,15 +2753,28 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli) COMMIT or ROLLBACK In that case, we don't want to touch the coordinates which correspond to the beginning of the transaction. + Starting from 5.0.0, there also are some rotates from the slave itself, in + the relay log. */ if (!(thd->options & OPTION_BEGIN)) { memcpy(rli->group_master_log_name, new_log_ident, ident_len+1); rli->notify_group_master_log_name_update(); - rli->group_master_log_pos = pos; - rli->group_relay_log_pos = rli->event_relay_log_pos; - DBUG_PRINT("info", ("group_master_log_pos: %lu", + rli->group_master_log_pos= pos; + rli->group_relay_log_pos= rli->event_relay_log_pos; + DBUG_PRINT("info", ("group_master_log_name: '%s' group_master_log_pos:\ +%lu", + rli->group_master_log_name, (ulong) rli->group_master_log_pos)); + /* + Reset thd->options and sql_mode, because this could be the signal of a + master's downgrade from 5.0 to 4.0. + However, no need to reset description_event_for_exec: indeed, if the next + master is 5.0 (even 5.0.1) we will soon get a Format_desc; if the next + master is 4.0 then the events are in the slave's format (conversion). + */ + set_slave_thread_options(thd); + thd->variables.sql_mode= global_system_variables.sql_mode; } pthread_mutex_unlock(&rli->data_lock); pthread_cond_broadcast(&rli->data_cond); @@ -2077,12 +2808,13 @@ void Intvar_log_event::pack_info(Protocol *protocol) Intvar_log_event::Intvar_log_event() */ -Intvar_log_event::Intvar_log_event(const char* buf, bool old_format) - :Log_event(buf, old_format) +Intvar_log_event::Intvar_log_event(const char* buf, + const Format_description_log_event* description_event) + :Log_event(buf, description_event) { - buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; - type = buf[I_TYPE_OFFSET]; - val = uint8korr(buf+I_VAL_OFFSET); + buf+= description_event->common_header_len; + type= buf[I_TYPE_OFFSET]; + val= uint8korr(buf+I_VAL_OFFSET); } @@ -2101,15 +2833,16 @@ const char* Intvar_log_event::get_var_type_name() /* - Intvar_log_event::write_data() + Intvar_log_event::write() */ -int Intvar_log_event::write_data(IO_CACHE* file) +bool Intvar_log_event::write(IO_CACHE* file) { - char buf[9]; - buf[I_TYPE_OFFSET] = type; + byte buf[9]; + buf[I_TYPE_OFFSET]= (byte) type; int8store(buf + I_VAL_OFFSET, val); - return my_b_safe_write(file, (byte*) buf, sizeof(buf)); + return (write_header(file, sizeof(buf)) || + my_b_safe_write(file, buf, sizeof(buf))); } @@ -2118,7 +2851,8 @@ int Intvar_log_event::write_data(IO_CACHE* file) */ #ifdef MYSQL_CLIENT -void Intvar_log_event::print(FILE* file, bool short_form, char* last_db) +void Intvar_log_event::print(FILE* file, bool short_form, + LAST_EVENT_INFO* last_event_info) { char llbuff[22]; const char *msg; @@ -2161,7 +2895,7 @@ int Intvar_log_event::exec_event(struct st_relay_log_info* rli) thd->next_insert_id = val; break; } - rli->inc_event_relay_log_pos(get_event_len()); + rli->inc_event_relay_log_pos(); return 0; } #endif @@ -2184,26 +2918,28 @@ void Rand_log_event::pack_info(Protocol *protocol) #endif -Rand_log_event::Rand_log_event(const char* buf, bool old_format) - :Log_event(buf, old_format) +Rand_log_event::Rand_log_event(const char* buf, + const Format_description_log_event* description_event) + :Log_event(buf, description_event) { - buf += (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; - seed1 = uint8korr(buf+RAND_SEED1_OFFSET); - seed2 = uint8korr(buf+RAND_SEED2_OFFSET); + buf+= description_event->common_header_len; + seed1= uint8korr(buf+RAND_SEED1_OFFSET); + seed2= uint8korr(buf+RAND_SEED2_OFFSET); } -int Rand_log_event::write_data(IO_CACHE* file) +bool Rand_log_event::write(IO_CACHE* file) { - char buf[16]; + byte buf[16]; int8store(buf + RAND_SEED1_OFFSET, seed1); int8store(buf + RAND_SEED2_OFFSET, seed2); - return my_b_safe_write(file, (byte*) buf, sizeof(buf)); + return (write_header(file, sizeof(buf)) || + my_b_safe_write(file, buf, sizeof(buf))); } #ifdef MYSQL_CLIENT -void Rand_log_event::print(FILE* file, bool short_form, char* last_db) +void Rand_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { char llbuff[22],llbuff2[22]; if (!short_form) @@ -2223,7 +2959,7 @@ int Rand_log_event::exec_event(struct st_relay_log_info* rli) { thd->rand.seed1= (ulong) seed1; thd->rand.seed2= (ulong) seed2; - rli->inc_event_relay_log_pos(get_event_len()); + rli->inc_event_relay_log_pos(); return 0; } #endif /* !MYSQL_CLIENT */ @@ -2294,10 +3030,12 @@ void User_var_log_event::pack_info(Protocol* protocol) #endif /* !MYSQL_CLIENT */ -User_var_log_event::User_var_log_event(const char* buf, bool old_format) - :Log_event(buf, old_format) +User_var_log_event:: +User_var_log_event(const char* buf, + const Format_description_log_event* description_event) + :Log_event(buf, description_event) { - buf+= (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN; + buf+= description_event->common_header_len; name_len= uint4korr(buf); name= (char *) buf + UV_NAME_LEN_SIZE; buf+= UV_NAME_LEN_SIZE + name_len; @@ -2321,13 +3059,14 @@ User_var_log_event::User_var_log_event(const char* buf, bool old_format) } -int User_var_log_event::write_data(IO_CACHE* file) +bool User_var_log_event::write(IO_CACHE* file) { char buf[UV_NAME_LEN_SIZE]; char buf1[UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE + UV_CHARSET_NUMBER_SIZE + UV_VAL_LEN_SIZE]; char buf2[8], *pos= buf2; uint buf1_length; + ulong event_length; int4store(buf, name_len); @@ -2359,7 +3098,12 @@ int User_var_log_event::write_data(IO_CACHE* file) return 0; } } - return (my_b_safe_write(file, (byte*) buf, sizeof(buf)) || + + /* Length of the whole event */ + event_length= sizeof(buf)+ name_len + buf1_length + val_len; + + return (write_header(file, event_length) || + my_b_safe_write(file, (byte*) buf, sizeof(buf)) || my_b_safe_write(file, (byte*) name, name_len) || my_b_safe_write(file, (byte*) buf1, buf1_length) || my_b_safe_write(file, (byte*) pos, val_len)); @@ -2371,7 +3115,7 @@ int User_var_log_event::write_data(IO_CACHE* file) */ #ifdef MYSQL_CLIENT -void User_var_log_event::print(FILE* file, bool short_form, char* last_db) +void User_var_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { if (!short_form) { @@ -2504,7 +3248,7 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli) e.update_hash(val, val_len, type, charset, DERIVATION_NONE); free_root(thd->mem_root,0); - rli->inc_event_relay_log_pos(get_event_len()); + rli->inc_event_relay_log_pos(); return 0; } #endif /* !MYSQL_CLIENT */ @@ -2516,7 +3260,7 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli) #ifdef HAVE_REPLICATION #ifdef MYSQL_CLIENT -void Unknown_log_event::print(FILE* file, bool short_form, char* last_db) +void Unknown_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { if (short_form) return; @@ -2546,7 +3290,7 @@ void Slave_log_event::pack_info(Protocol *protocol) #ifndef MYSQL_CLIENT Slave_log_event::Slave_log_event(THD* thd_arg, struct st_relay_log_info* rli) - :Log_event(thd_arg, 0, 0), mem_pool(0), master_host(0) + :Log_event(thd_arg, 0, 0) , mem_pool(0), master_host(0) { DBUG_ENTER("Slave_log_event"); if (!rli->inited) // QQ When can this happen ? @@ -2587,7 +3331,7 @@ Slave_log_event::~Slave_log_event() #ifdef MYSQL_CLIENT -void Slave_log_event::print(FILE* file, bool short_form, char* last_db) +void Slave_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { char llbuff[22]; if (short_form) @@ -2607,12 +3351,15 @@ int Slave_log_event::get_data_size() } -int Slave_log_event::write_data(IO_CACHE* file) +bool Slave_log_event::write(IO_CACHE* file) { + ulong event_length= get_data_size(); int8store(mem_pool + SL_MASTER_POS_OFFSET, master_pos); int2store(mem_pool + SL_MASTER_PORT_OFFSET, master_port); // log and host are already there - return my_b_safe_write(file, (byte*)mem_pool, get_data_size()); + + return (write_header(file, event_length) || + my_b_safe_write(file, (byte*) mem_pool, event_length)); } @@ -2633,12 +3380,13 @@ void Slave_log_event::init_from_mem_pool(int data_size) } -Slave_log_event::Slave_log_event(const char* buf, int event_len) - :Log_event(buf,0),mem_pool(0),master_host(0) +/* This code is not used, so has not been updated to be format-tolerant */ +Slave_log_event::Slave_log_event(const char* buf, uint event_len) + :Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0) { - event_len -= LOG_EVENT_HEADER_LEN; - if (event_len < 0) + if (event_len < LOG_EVENT_HEADER_LEN) return; + event_len -= LOG_EVENT_HEADER_LEN; if (!(mem_pool = (char*) my_malloc(event_len + 1, MYF(MY_WME)))) return; memcpy(mem_pool, buf + LOG_EVENT_HEADER_LEN, event_len); @@ -2666,7 +3414,7 @@ int Slave_log_event::exec_event(struct st_relay_log_info* rli) */ #ifdef MYSQL_CLIENT -void Stop_log_event::print(FILE* file, bool short_form, char* last_db) +void Stop_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_event_info) { if (short_form) return; @@ -2688,7 +3436,7 @@ void Stop_log_event::print(FILE* file, bool short_form, char* last_db) We used to clean up slave_load_tmpdir, but this is useless as it has been cleared at the end of LOAD DATA INFILE. So we have nothing to do here. - The place were we must do this cleaning is in Start_log_event::exec_event(), + The place were we must do this cleaning is in Start_log_event_v3::exec_event(), not here. Because if we come here, the master was sane. */ @@ -2702,8 +3450,13 @@ int Stop_log_event::exec_event(struct st_relay_log_info* rli) could give false triggers in MASTER_POS_WAIT() that we have reached the target position when in fact we have not. */ - rli->inc_group_relay_log_pos(get_event_len(), 0); - flush_relay_log_info(rli); + if (thd->options & OPTION_BEGIN) + rli->inc_event_relay_log_pos(); + else + { + rli->inc_group_relay_log_pos(0); + flush_relay_log_info(rli); + } return 0; } #endif /* !MYSQL_CLIENT */ @@ -2740,13 +3493,13 @@ Create_file_log_event(THD* thd_arg, sql_exchange* ex, Create_file_log_event::write_data_body() */ -int Create_file_log_event::write_data_body(IO_CACHE* file) +bool Create_file_log_event::write_data_body(IO_CACHE* file) { - int res; - if ((res = Load_log_event::write_data_body(file)) || fake_base) + bool res; + if ((res= Load_log_event::write_data_body(file)) || fake_base) return res; return (my_b_safe_write(file, (byte*) "", 1) || - my_b_safe_write(file, (byte*) block, block_len)); + my_b_safe_write(file, (byte*) block, block_len)); } @@ -2754,14 +3507,14 @@ int Create_file_log_event::write_data_body(IO_CACHE* file) Create_file_log_event::write_data_header() */ -int Create_file_log_event::write_data_header(IO_CACHE* file) +bool Create_file_log_event::write_data_header(IO_CACHE* file) { - int res; - if ((res = Load_log_event::write_data_header(file)) || fake_base) - return res; + bool res; byte buf[CREATE_FILE_HEADER_LEN]; + if ((res= Load_log_event::write_data_header(file)) || fake_base) + return res; int4store(buf + CF_FILE_ID_OFFSET, file_id); - return my_b_safe_write(file, buf, CREATE_FILE_HEADER_LEN); + return my_b_safe_write(file, buf, CREATE_FILE_HEADER_LEN) != 0; } @@ -2769,12 +3522,12 @@ int Create_file_log_event::write_data_header(IO_CACHE* file) Create_file_log_event::write_base() */ -int Create_file_log_event::write_base(IO_CACHE* file) +bool Create_file_log_event::write_base(IO_CACHE* file) { - int res; - fake_base = 1; // pretend we are Load event - res = write(file); - fake_base = 0; + bool res; + fake_base= 1; // pretend we are Load event + res= write(file); + fake_base= 0; return res; } @@ -2783,28 +3536,43 @@ int Create_file_log_event::write_base(IO_CACHE* file) Create_file_log_event ctor */ -Create_file_log_event::Create_file_log_event(const char* buf, int len, - bool old_format) - :Load_log_event(buf,0,old_format),fake_base(0),block(0),inited_from_old(0) +Create_file_log_event::Create_file_log_event(const char* buf, uint len, + const Format_description_log_event* description_event) + :Load_log_event(buf,0,description_event),fake_base(0),block(0),inited_from_old(0) { - int block_offset; - DBUG_ENTER("Create_file_log_event"); - - /* - We must make copy of 'buf' as this event may have to live over a - rotate log entry when used in mysqlbinlog - */ + DBUG_ENTER("Create_file_log_event::Create_file_log_event(char*,...)"); + uint block_offset; + uint header_len= description_event->common_header_len; + uint8 load_header_len= description_event->post_header_len[LOAD_EVENT-1]; + uint8 create_file_header_len= description_event->post_header_len[CREATE_FILE_EVENT-1]; if (!(event_buf= my_memdup((byte*) buf, len, MYF(MY_WME))) || - (copy_log_event(event_buf, len, old_format))) + copy_log_event(event_buf,len, + ((buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) ? + load_header_len + header_len : + (fake_base ? (header_len+load_header_len) : + (header_len+load_header_len) + + create_file_header_len)), + description_event)) DBUG_VOID_RETURN; - - if (!old_format) + if (description_event->binlog_version!=1) { - file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + - + LOAD_HEADER_LEN + CF_FILE_ID_OFFSET); - // + 1 for \0 terminating fname - block_offset = (LOG_EVENT_HEADER_LEN + Load_log_event::get_data_size() + - CREATE_FILE_HEADER_LEN + 1); + file_id= uint4korr(buf + + header_len + + load_header_len + CF_FILE_ID_OFFSET); + /* + Note that it's ok to use get_data_size() below, because it is computed + with values we have already read from this event (because we called + copy_log_event()); we are not using slave's format info to decode + master's format, we are really using master's format info. + Anyway, both formats should be identical (except the common_header_len) + as these Load events are not changed between 4.0 and 5.0 (as logging of + LOAD DATA INFILE does not use Load_log_event in 5.0). + + The + 1 is for \0 terminating fname + */ + block_offset= (description_event->common_header_len + + Load_log_event::get_data_size() + + create_file_header_len + 1); if (len < block_offset) return; block = (char*)buf + block_offset; @@ -2825,18 +3593,18 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len, #ifdef MYSQL_CLIENT void Create_file_log_event::print(FILE* file, bool short_form, - char* last_db, bool enable_local) + LAST_EVENT_INFO* last_event_info, bool enable_local) { if (short_form) { if (enable_local && check_fname_outside_temp_buf()) - Load_log_event::print(file, 1, last_db); + Load_log_event::print(file, 1, last_event_info); return; } if (enable_local) { - Load_log_event::print(file, 1, last_db, !check_fname_outside_temp_buf()); + Load_log_event::print(file, 1, last_event_info, !check_fname_outside_temp_buf()); /* That one is for "file_id: etc" below: in mysqlbinlog we want the #, in SHOW BINLOG EVENTS we don't. @@ -2849,9 +3617,9 @@ void Create_file_log_event::print(FILE* file, bool short_form, void Create_file_log_event::print(FILE* file, bool short_form, - char* last_db) + LAST_EVENT_INFO* last_event_info) { - print(file,short_form,last_db,0); + print(file,short_form,last_event_info,0); } #endif /* MYSQL_CLIENT */ @@ -2968,28 +3736,34 @@ Append_block_log_event::Append_block_log_event(THD* thd_arg, const char* db_arg, Append_block_log_event ctor */ -Append_block_log_event::Append_block_log_event(const char* buf, int len) - :Log_event(buf, 0),block(0) +Append_block_log_event::Append_block_log_event(const char* buf, uint len, + const Format_description_log_event* description_event) + :Log_event(buf, description_event),block(0) { - DBUG_ENTER("Append_block_log_event"); - if ((uint)len < APPEND_BLOCK_EVENT_OVERHEAD) + DBUG_ENTER("Append_block_log_event::Append_block_log_event(char*,...)"); + uint8 common_header_len= description_event->common_header_len; + uint8 append_block_header_len= + description_event->post_header_len[APPEND_BLOCK_EVENT-1]; + uint total_header_len= common_header_len+append_block_header_len; + if (len < total_header_len) DBUG_VOID_RETURN; - file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + AB_FILE_ID_OFFSET); - block = (char*)buf + APPEND_BLOCK_EVENT_OVERHEAD; - block_len = len - APPEND_BLOCK_EVENT_OVERHEAD; + file_id= uint4korr(buf + common_header_len + AB_FILE_ID_OFFSET); + block= (char*)buf + total_header_len; + block_len= len - total_header_len; DBUG_VOID_RETURN; } /* - Append_block_log_event::write_data() + Append_block_log_event::write() */ -int Append_block_log_event::write_data(IO_CACHE* file) +bool Append_block_log_event::write(IO_CACHE* file) { byte buf[APPEND_BLOCK_HEADER_LEN]; int4store(buf + AB_FILE_ID_OFFSET, file_id); - return (my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) || + return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) || + my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) || my_b_safe_write(file, (byte*) block, block_len)); } @@ -3000,7 +3774,7 @@ int Append_block_log_event::write_data(IO_CACHE* file) #ifdef MYSQL_CLIENT void Append_block_log_event::print(FILE* file, bool short_form, - char* last_db) + LAST_EVENT_INFO* last_event_info) { if (short_form) return; @@ -3086,24 +3860,28 @@ Delete_file_log_event::Delete_file_log_event(THD *thd_arg, const char* db_arg, Delete_file_log_event ctor */ -Delete_file_log_event::Delete_file_log_event(const char* buf, int len) - :Log_event(buf, 0),file_id(0) +Delete_file_log_event::Delete_file_log_event(const char* buf, uint len, + const Format_description_log_event* description_event) + :Log_event(buf, description_event),file_id(0) { - if ((uint)len < DELETE_FILE_EVENT_OVERHEAD) + uint8 common_header_len= description_event->common_header_len; + uint8 delete_file_header_len= description_event->post_header_len[DELETE_FILE_EVENT-1]; + if (len < (uint)(common_header_len + delete_file_header_len)) return; - file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + AB_FILE_ID_OFFSET); + file_id= uint4korr(buf + common_header_len + DF_FILE_ID_OFFSET); } /* - Delete_file_log_event::write_data() + Delete_file_log_event::write() */ -int Delete_file_log_event::write_data(IO_CACHE* file) +bool Delete_file_log_event::write(IO_CACHE* file) { byte buf[DELETE_FILE_HEADER_LEN]; int4store(buf + DF_FILE_ID_OFFSET, file_id); - return my_b_safe_write(file, buf, DELETE_FILE_HEADER_LEN); + return (write_header(file, sizeof(buf)) || + my_b_safe_write(file, buf, sizeof(buf))); } @@ -3113,7 +3891,7 @@ int Delete_file_log_event::write_data(IO_CACHE* file) #ifdef MYSQL_CLIENT void Delete_file_log_event::print(FILE* file, bool short_form, - char* last_db) + LAST_EVENT_INFO* last_event_info) { if (short_form) return; @@ -3176,24 +3954,28 @@ Execute_load_log_event::Execute_load_log_event(THD *thd_arg, const char* db_arg, Execute_load_log_event ctor */ -Execute_load_log_event::Execute_load_log_event(const char* buf, int len) - :Log_event(buf, 0), file_id(0) +Execute_load_log_event::Execute_load_log_event(const char* buf, uint len, + const Format_description_log_event* description_event) + :Log_event(buf, description_event), file_id(0) { - if ((uint)len < EXEC_LOAD_EVENT_OVERHEAD) + uint8 common_header_len= description_event->common_header_len; + uint8 exec_load_header_len= description_event->post_header_len[EXEC_LOAD_EVENT-1]; + if (len < (uint)(common_header_len+exec_load_header_len)) return; - file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + EL_FILE_ID_OFFSET); + file_id= uint4korr(buf + common_header_len + EL_FILE_ID_OFFSET); } /* - Execute_load_log_event::write_data() + Execute_load_log_event::write() */ -int Execute_load_log_event::write_data(IO_CACHE* file) +bool Execute_load_log_event::write(IO_CACHE* file) { byte buf[EXEC_LOAD_HEADER_LEN]; int4store(buf + EL_FILE_ID_OFFSET, file_id); - return my_b_safe_write(file, buf, EXEC_LOAD_HEADER_LEN); + return (write_header(file, sizeof(buf)) || + my_b_safe_write(file, buf, sizeof(buf))); } @@ -3203,7 +3985,7 @@ int Execute_load_log_event::write_data(IO_CACHE* file) #ifdef MYSQL_CLIENT void Execute_load_log_event::print(FILE* file, bool short_form, - char* last_db) + LAST_EVENT_INFO* last_event_info) { if (short_form) return; @@ -3250,8 +4032,8 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) goto err; } if (!(lev = (Load_log_event*)Log_event::read_log_event(&file, - (pthread_mutex_t*)0, - (bool)0)) || + (pthread_mutex_t*)0, + rli->relay_log.description_event_for_exec)) || lev->get_type_code() != NEW_LOAD_EVENT) { slave_print_error(rli,0, "Error in Exec_load event: file '%s' appears corrupted", fname); @@ -3266,15 +4048,7 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) mysql_load()). */ -#if MYSQL_VERSION_ID < 40100 - rli->future_master_log_pos= log_pos + get_event_len() - - (rli->mi->old_format ? (LOG_EVENT_HEADER_LEN - OLD_HEADER_LEN) : 0); -#elif MYSQL_VERSION_ID < 50000 - rli->future_group_master_log_pos= log_pos + get_event_len() - - (rli->mi->old_format ? (LOG_EVENT_HEADER_LEN - OLD_HEADER_LEN) : 0); -#else - rli->future_group_master_log_pos= log_pos; -#endif + rli->future_group_master_log_pos= log_pos; if (lev->exec_event(0,rli,1)) { /* @@ -3332,15 +4106,15 @@ err: sql_ex_info::write_data() */ -int sql_ex_info::write_data(IO_CACHE* file) +bool sql_ex_info::write_data(IO_CACHE* file) { if (new_format()) { - return (write_str(file, field_term, field_term_len) || - write_str(file, enclosed, enclosed_len) || - write_str(file, line_term, line_term_len) || - write_str(file, line_start, line_start_len) || - write_str(file, escaped, escaped_len) || + return (write_str(file, field_term, (uint) field_term_len) || + write_str(file, enclosed, (uint) enclosed_len) || + write_str(file, line_term, (uint) line_term_len) || + write_str(file, line_start, (uint) line_start_len) || + write_str(file, escaped, (uint) escaped_len) || my_b_safe_write(file,(byte*) &opt_flags,1)); } else @@ -3353,7 +4127,7 @@ int sql_ex_info::write_data(IO_CACHE* file) old_ex.escaped= *escaped; old_ex.opt_flags= opt_flags; old_ex.empty_flags=empty_flags; - return my_b_safe_write(file, (byte*) &old_ex, sizeof(old_ex)); + return my_b_safe_write(file, (byte*) &old_ex, sizeof(old_ex)) != 0; } } @@ -3375,11 +4149,11 @@ char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format) the case when we have old format because we will be reusing net buffer to read the actual file before we write out the Create_file event. */ - if (read_str(buf, buf_end, field_term, field_term_len) || - read_str(buf, buf_end, enclosed, enclosed_len) || - read_str(buf, buf_end, line_term, line_term_len) || - read_str(buf, buf_end, line_start, line_start_len) || - read_str(buf, buf_end, escaped, escaped_len)) + if (read_str(&buf, buf_end, &field_term, &field_term_len) || + read_str(&buf, buf_end, &enclosed, &enclosed_len) || + read_str(&buf, buf_end, &line_term, &line_term_len) || + read_str(&buf, buf_end, &line_start, &line_start_len) || + read_str(&buf, buf_end, &escaped, &escaped_len)) return 0; opt_flags = *buf++; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9d755731cb7..5e9162b52b2 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -26,6 +26,9 @@ #include "ha_innodb.h" #endif +#include "sp_head.h" +#include "sp.h" + #ifdef HAVE_OPENSSL /* Without SSL the handshake consists of one packet. This packet @@ -44,6 +47,15 @@ #define MIN_HANDSHAKE_SIZE 6 #endif /* HAVE_OPENSSL */ +/* Used in error handling only */ +#define SP_TYPE_STRING(LP) \ + ((LP)->sphead->m_type == TYPE_ENUM_FUNCTION ? "FUNCTION" : "PROCEDURE") +#define SP_COM_STRING(LP) \ + ((LP)->sql_command == SQLCOM_CREATE_SPFUNCTION || \ + (LP)->sql_command == SQLCOM_ALTER_FUNCTION || \ + (LP)->sql_command == SQLCOM_DROP_FUNCTION ? \ + "FUNCTION" : "PROCEDURE") + #ifdef SOLARIS extern "C" int gethostname(char *name, int namelen); #endif @@ -57,6 +69,7 @@ static void remove_escape(char *name); static void refresh_status(void); static bool append_file_to_dir(THD *thd, const char **filename_ptr, const char *table_name); +static bool check_sp_definer_access(THD *thd, sp_head *sp); const char *any_db="*any*"; // Special symbol for check_access @@ -66,7 +79,7 @@ const char *command_name[]={ "Connect","Kill","Debug","Ping","Time","Delayed insert","Change user", "Binlog Dump","Table Dump", "Connect Out", "Register Slave", "Prepare", "Prepare Execute", "Long Data", "Close stmt", - "Reset stmt", "Set option", + "Reset stmt", "Set option", "Fetch", "Error" // Last command number }; @@ -96,7 +109,7 @@ static void unlock_locked_tables(THD *thd) if (thd->locked_tables) { thd->lock=thd->locked_tables; - thd->locked_tables=0; // Will be automaticly closed + thd->locked_tables=0; // Will be automatically closed close_thread_tables(thd); // Free tables } } @@ -193,13 +206,13 @@ end: command originator of the check: now check_user is called during connect and change user procedures; used for logging. - passwd scrambled password recieved from client + passwd scrambled password received from client passwd_len length of scrambled password db database name to connect to, may be NULL check_count dont know exactly Note, that host, user and passwd may point to communication buffer. - Current implementation does not depened on that, but future changes + Current implementation does not depend on that, but future changes should be done with this in mind; 'thd' is INOUT, all other params are 'IN'. @@ -257,7 +270,7 @@ int check_user(THD *thd, enum enum_server_command command, /* Clear thd->db as it points to something, that will be freed when - connection is closed. We don't want to accidently free a wrong pointer + connection is closed. We don't want to accidentally free a wrong pointer if connect failed. Also in case of 'CHANGE USER' failure, current database will be switched to 'no database selected'. */ @@ -284,9 +297,10 @@ int check_user(THD *thd, enum enum_server_command command, thd->user, thd->host_or_ip); DBUG_RETURN(-1); } + /* We have to read very specific packet size */ if (send_old_password_request(thd) || - my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) // We have to read very - { // specific packet size + my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) + { inc_host_errors(&thd->remote.sin_addr); DBUG_RETURN(ER_HANDSHAKE_ERROR); } @@ -298,7 +312,7 @@ int check_user(THD *thd, enum enum_server_command command, /* here res is always >= 0 */ if (res == 0) { - if (!(thd->master_access & NO_ACCESS)) // authentification is OK + if (!(thd->master_access & NO_ACCESS)) // authentication is OK { DBUG_PRINT("info", ("Capabilities: %d packet_length: %ld Host: '%s' " @@ -533,6 +547,8 @@ void init_update_queries(void) uc_update_queries[SQLCOM_DELETE_MULTI]=1; uc_update_queries[SQLCOM_DROP_INDEX]=1; uc_update_queries[SQLCOM_UPDATE_MULTI]=1; + uc_update_queries[SQLCOM_CREATE_VIEW]=1; + uc_update_queries[SQLCOM_DROP_VIEW]=1; } bool is_update_query(enum enum_sql_command command) @@ -621,8 +637,9 @@ static void reset_mqh(THD *thd, LEX_USER *lu, bool get_them= 0) uc->conn_per_hour=0; } } - else // for FLUSH PRIVILEGES and FLUSH USER_RESOURCES + else { + /* for FLUSH PRIVILEGES and FLUSH USER_RESOURCES */ for (uint idx=0;idx < hash_user_connections.records; idx++) { USER_CONN *uc=(struct user_conn *) hash_element(&hash_user_connections, @@ -721,7 +738,7 @@ static int check_connection(THD *thd) #endif /* HAVE_COMPRESS */ #ifdef HAVE_OPENSSL if (ssl_acceptor_fd) - client_flags |= CLIENT_SSL; /* Wow, SSL is avalaible! */ + client_flags |= CLIENT_SSL; /* Wow, SSL is available! */ #endif /* HAVE_OPENSSL */ end= strnmov(buff, server_version, SERVER_VERSION_LENGTH) + 1; @@ -948,7 +965,7 @@ pthread_handler_decl(handle_one_connection,arg) pthread_detach_this_thread(); #if !defined( __WIN__) && !defined(OS2) // Win32 calls this in pthread_create - // The following calls needs to be done before we call DBUG_ macros + /* The following calls needs to be done before we call DBUG_ macros */ if (!(test_flags & TEST_NO_THREADS) & my_thread_init()) { close_connection(thd, ER_OUT_OF_RESOURCES, 1); @@ -967,7 +984,7 @@ pthread_handler_decl(handle_one_connection,arg) */ DBUG_PRINT("info", ("handle_one_connection called by thread %d\n", thd->thread_id)); - // now that we've called my_thread_init(), it is safe to call DBUG_* + /* now that we've called my_thread_init(), it is safe to call DBUG_* */ #if defined(__WIN__) init_signals(); // IRENA; testing ? @@ -1013,24 +1030,28 @@ pthread_handler_decl(handle_one_connection,arg) thd->proc_info= 0; thd->set_time(); thd->init_for_queries(); + if (sys_init_connect.value_length && !(thd->master_access & SUPER_ACL)) { execute_init_command(thd, &sys_init_connect, &LOCK_sys_init_connect); if (thd->query_error) - thd->killed= 1; + thd->killed= THD::KILL_CONNECTION; } - while (!net->error && net->vio != 0 && !thd->killed) + + thd->proc_info=0; + thd->set_time(); + thd->init_for_queries(); + while (!net->error && net->vio != 0 && !(thd->killed == THD::KILL_CONNECTION)) { if (do_command(thd)) break; } if (thd->user_connect) decrease_user_connections(thd->user_connect); - free_root(thd->mem_root,MYF(0)); if (net->error && net->vio != 0 && net->report_error) { if (!thd->killed && thd->variables.log_warnings > 1) - sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION), + sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION), thd->thread_id,(thd->db ? thd->db : "unconnected"), thd->user ? thd->user : "unauthenticated", thd->host_or_ip, @@ -1116,6 +1137,10 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) thd->query_length=length; thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1); thd->query[length] = '\0'; + /* + We don't need to obtain LOCK_thread_count here because in bootstrap + mode we have only one thread. + */ thd->query_id=query_id++; if (mqh_used && thd->user_connect && check_mqh(thd, SQLCOM_END)) { @@ -1149,8 +1174,10 @@ end: void free_items(Item *item) { + DBUG_ENTER("free_items"); for (; item ; item=item->next) item->delete_self(); + DBUG_VOID_RETURN; } /* This works because items are allocated with sql_alloc() */ @@ -1170,10 +1197,10 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd) db = (db && db[0]) ? db : thd->db; if (!(table_list = (TABLE_LIST*) thd->calloc(sizeof(TABLE_LIST)))) DBUG_RETURN(1); // out of memory - table_list->db = db; - table_list->real_name = table_list->alias = tbl_name; - table_list->lock_type = TL_READ_NO_INSERT; - table_list->next = 0; + table_list->db= db; + table_list->real_name= table_list->alias= tbl_name; + table_list->lock_type= TL_READ_NO_INSERT; + table_list->prev_global= &table_list; // can be removed after merge with 4.1 if (!db || check_db_name(db)) { @@ -1237,7 +1264,7 @@ bool do_command(THD *thd) packet=0; old_timeout=net->read_timeout; - // Wait max for 8 hours + /* Wait max for 8 hours */ net->read_timeout=(uint) thd->variables.net_wait_timeout; thd->clear_error(); // Clear error message @@ -1259,6 +1286,9 @@ bool do_command(THD *thd) } else { + if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA) + thd->killed= THD::NOT_KILLED; + packet=(char*) net->read_pos; command = (enum enum_server_command) (uchar) packet[0]; if (command >= COM_END) @@ -1310,6 +1340,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, this so that they will not get logged to the slow query log */ thd->slow_command=FALSE; + thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */ thd->set_time(); VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_id=query_id; @@ -1325,7 +1356,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_INIT_DB: { LEX_STRING tmp; - statistic_increment(com_stat[SQLCOM_CHANGE_DB],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB], + &LOCK_status); thd->convert_string(&tmp, system_charset_info, packet, strlen(packet), thd->charset()); if (!mysql_change_db(thd, tmp.str)) @@ -1346,7 +1378,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, uint db_len= *(uchar*) packet; uint tbl_len= *(uchar*) (packet + db_len + 1); - statistic_increment(com_other, &LOCK_status); + statistic_increment(thd->status_var.com_other, &LOCK_status); thd->slow_command= TRUE; db= thd->alloc(db_len + tbl_len + 2); tbl_name= strmake(db, packet + 1, db_len)+1; @@ -1360,7 +1392,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->change_user(); thd->clear_error(); // if errors from rollback - statistic_increment(com_other, &LOCK_status); + statistic_increment(thd->status_var.com_other, &LOCK_status); char *user= (char*) packet; char *passwd= strend(user)+1; /* @@ -1374,7 +1406,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, *passwd++ : strlen(passwd); db+= passwd_len + 1; #ifndef EMBEDDED_LIBRARY - /* Small check for incomming packet */ + /* Small check for incoming packet */ if ((uint) ((uchar*) db - net->read_pos) > packet_length) { send_error(thd, ER_UNKNOWN_COM_ERROR); @@ -1410,7 +1442,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (res) { - /* authentification failure, we shall restore old user */ + /* authentication failure, we shall restore old user */ if (res > 0) send_error(thd, ER_UNKNOWN_COM_ERROR); x_free(thd->user); @@ -1437,6 +1469,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd, mysql_stmt_execute(thd, packet, packet_length); break; } + case COM_FETCH: + { + mysql_stmt_fetch(thd, packet, packet_length); + break; + } case COM_LONG_DATA: { mysql_stmt_get_longdata(thd, packet, packet_length); @@ -1523,20 +1560,20 @@ bool dispatch_command(enum enum_server_command command, THD *thd, TABLE_LIST table_list; LEX_STRING conv_name; - statistic_increment(com_stat[SQLCOM_SHOW_FIELDS],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS], + &LOCK_status); bzero((char*) &table_list,sizeof(table_list)); if (!(table_list.db=thd->db)) { send_error(thd,ER_NO_DB_ERROR); break; } - thd->free_list=0; pend= strend(packet); thd->convert_string(&conv_name, system_charset_info, packet, (uint) (pend-packet), thd->charset()); table_list.alias= table_list.real_name= conv_name.str; packet= pend+1; - // command not cachable => no gap for data base name + /* command not cachable => no gap for data base name */ if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1))) break; mysql_log.write(thd,command,"%s %s",table_list.real_name,fields); @@ -1550,9 +1587,18 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (grant_option && check_grant(thd, SELECT_ACL, &table_list, 2, UINT_MAX, 0)) break; + /* init structures for VIEW processing */ + table_list.select_lex= &(thd->lex->select_lex); + mysql_init_query(thd, (uchar*)"", 0); + thd->lex-> + select_lex.table_list.link_in_list((byte*) &table_list, + (byte**) &table_list.next_local); + + /* switch on VIEW optimisation: do not fill temporary tables */ + thd->lex->sql_command= SQLCOM_SHOW_FIELDS; mysqld_list_fields(thd,&table_list,fields); - free_items(thd->free_list); - thd->free_list= 0; + thd->lex->unit.cleanup(); + thd->cleanup_after_query(); break; } #endif @@ -1568,7 +1614,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, char *db=thd->strdup(packet), *alias; HA_CREATE_INFO create_info; - statistic_increment(com_stat[SQLCOM_CREATE_DB],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_CREATE_DB], + &LOCK_status); // null test to handle EOM if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { @@ -1586,9 +1633,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_DROP_DB: // QQ: To be removed { - statistic_increment(com_stat[SQLCOM_DROP_DB],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_DROP_DB], + &LOCK_status); char *db=thd->strdup(packet), *alias; - // null test to handle EOM + /* null test to handle EOM */ if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { net_printf(thd,ER_WRONG_DB_NAME, db ? db : "NULL"); @@ -1614,7 +1662,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ushort flags; uint32 slave_server_id; - statistic_increment(com_other,&LOCK_status); + statistic_increment(thd->status_var.com_other,&LOCK_status); thd->slow_command = TRUE; if (check_global_access(thd, REPL_SLAVE_ACL)) break; @@ -1631,7 +1679,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, (long) pos); mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags); unregister_slave(thd,1,1); - // fake COM_QUIT -- if we get here, the thread needs to terminate + /* fake COM_QUIT -- if we get here, the thread needs to terminate */ error = TRUE; net->error = 0; break; @@ -1639,7 +1687,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, #endif case COM_REFRESH: { - statistic_increment(com_stat[SQLCOM_FLUSH],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_FLUSH], + &LOCK_status); ulong options= (ulong) (uchar) packet[0]; if (check_global_access(thd,RELOAD_ACL)) break; @@ -1653,7 +1702,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, #ifndef EMBEDDED_LIBRARY case COM_SHUTDOWN: { - statistic_increment(com_other,&LOCK_status); + statistic_increment(thd->status_var.com_other, &LOCK_status); if (check_global_access(thd,SHUTDOWN_ACL)) break; /* purecov: inspected */ /* @@ -1684,8 +1733,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, #endif close_connection(thd, 0, 1); close_thread_tables(thd); // Free before kill - free_root(thd->mem_root,MYF(0)); - free_root(&thd->transaction.mem_root,MYF(0)); kill_mysql(); error=TRUE; break; @@ -1694,7 +1741,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_STATISTICS: { mysql_log.write(thd,command,NullS); - statistic_increment(com_stat[SQLCOM_SHOW_STATUS],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS], + &LOCK_status); #ifndef EMBEDDED_LIBRARY char buff[200]; #else @@ -1704,8 +1752,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, sprintf((char*) buff, "Uptime: %ld Threads: %d Questions: %lu Slow queries: %ld Opens: %ld Flush tables: %ld Open tables: %u Queries per second avg: %.3f", uptime, - (int) thread_count,thd->query_id,long_query_count, - opened_tables,refresh_version, cached_tables(), + (int) thread_count,thd->query_id,thd->status_var.long_query_count, + thd->status_var.opened_tables,refresh_version, cached_tables(), uptime ? (float)thd->query_id/(float)uptime : 0); #ifdef SAFEMALLOC if (sf_malloc_cur_memory) // Using SAFEMALLOC @@ -1720,11 +1768,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } case COM_PING: - statistic_increment(com_other,&LOCK_status); + statistic_increment(thd->status_var.com_other, &LOCK_status); send_ok(thd); // Tell client we are alive break; case COM_PROCESS_INFO: - statistic_increment(com_stat[SQLCOM_SHOW_PROCESSLIST],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST], + &LOCK_status); if (!thd->priv_user[0] && check_global_access(thd,PROCESS_ACL)) break; mysql_log.write(thd,command,NullS); @@ -1734,14 +1783,15 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; case COM_PROCESS_KILL: { - statistic_increment(com_stat[SQLCOM_KILL],&LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_KILL], &LOCK_status); ulong id=(ulong) uint4korr(packet); - kill_one_thread(thd,id); + kill_one_thread(thd,id,false); break; } case COM_SET_OPTION: { - statistic_increment(com_stat[SQLCOM_SET_OPTION], &LOCK_status); + statistic_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION], + &LOCK_status); enum_mysql_set_option command= (enum_mysql_set_option) uint2korr(packet); switch (command) { case MYSQL_OPTION_MULTI_STATEMENTS_ON: @@ -1759,7 +1809,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } case COM_DEBUG: - statistic_increment(com_other,&LOCK_status); + statistic_increment(thd->status_var.com_other, &LOCK_status); if (check_global_access(thd, SUPER_ACL)) break; /* purecov: inspected */ mysql_print_status(thd); @@ -1798,7 +1848,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) && (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES))) { - long_query_count++; + thd->status_var.long_query_count++; mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } } @@ -1811,6 +1861,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thread_running--; VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory + free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); DBUG_RETURN(error); } @@ -1870,23 +1921,54 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) ** Execute command saved in thd and current_lex->sql_command ****************************************************************************/ -void +int mysql_execute_command(THD *thd) { int res= 0; LEX *lex= thd->lex; + /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */ SELECT_LEX *select_lex= &lex->select_lex; - TABLE_LIST *tables= (TABLE_LIST*) select_lex->table_list.first; + /* first table of first SELECT_LEX */ + TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first; + /* list of all tables in query */ + TABLE_LIST *all_tables; + /* most outer SELECT_LEX_UNIT of query */ SELECT_LEX_UNIT *unit= &lex->unit; DBUG_ENTER("mysql_execute_command"); + /* + In many cases first table of main SELECT_LEX have special meaning => + check that it is first table in global list and relink it first in + queries_tables list if it is necessary (we need such relinking only + for queries with subqueries in select list, in this case tables of + subqueries will go to global list first) + + all_tables will differ from first_table only if most upper SELECT_LEX + do not contain tables. + + Because of above in place where should be at least one table in most + outer SELECT_LEX we have following check: + DBUG_ASSERT(first_table == all_tables); + DBUG_ASSERT(first_table == all_tables && first_table != 0); + */ + lex->first_lists_tables_same(); + /* should be assigned after making first tables same */ + all_tables= lex->query_tables; + + if (lex->sql_command != SQLCOM_CREATE_PROCEDURE && + lex->sql_command != SQLCOM_CREATE_SPFUNCTION) + { + if (sp_cache_functions(thd, lex)) + DBUG_RETURN(-1); + } + /* Reset warning count for each query that uses tables A better approach would be to reset this for any commands that is not a SHOW command or a select that only access local variables, but for now this is probably good enough. */ - if (tables || &lex->select_lex != lex->all_selects_list) + if (all_tables || &lex->select_lex != lex->all_selects_list) mysql_reset_errors(thd); #ifdef HAVE_REPLICATION @@ -1896,11 +1978,11 @@ mysql_execute_command(THD *thd) Skip if we are in the slave thread, some table rules have been given and the table list says the query should not be replicated */ - if (all_tables_not_ok(thd,tables)) + if (all_tables_not_ok(thd, all_tables)) { /* we warn the slave SQL thread */ my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); - DBUG_VOID_RETURN; + DBUG_RETURN(0); } #ifndef TO_BE_DELETED /* @@ -1916,10 +1998,20 @@ mysql_execute_command(THD *thd) #endif } #endif /* !HAVE_REPLICATION */ - if ((&lex->select_lex != lex->all_selects_list || - lex->time_zone_tables_used) && - lex->unit.create_total_list(thd, lex, &tables)) - DBUG_VOID_RETURN; + + if (lex->time_zone_tables_used) + { + TABLE_LIST *tmp; + if ((tmp= my_tz_get_table_list(thd, &lex->query_tables_last)) == + &fake_time_zone_tables_list) + { + send_error(thd, 0); + DBUG_RETURN(-1); + } + lex->time_zone_tables_used= tmp; + if (!all_tables) + all_tables= tmp; + } /* When option readonly is set deny operations which change tables. @@ -1930,10 +2022,11 @@ mysql_execute_command(THD *thd) (uc_update_queries[lex->sql_command] > 0)) { net_printf(thd, ER_OPTION_PREVENTS_STATEMENT, "--read-only"); - DBUG_VOID_RETURN; + DBUG_RETURN(-1); } - statistic_increment(com_stat[lex->sql_command],&LOCK_status); + statistic_increment(thd->status_var.com_stat[lex->sql_command], + &LOCK_status); switch (lex->sql_command) { case SQLCOM_SELECT: { @@ -1945,42 +2038,31 @@ mysql_execute_command(THD *thd) } select_result *result=lex->result; - if (tables) + if (all_tables) { - res=check_table_access(thd, - lex->exchange ? SELECT_ACL | FILE_ACL : - SELECT_ACL, - tables,0); + res= check_table_access(thd, + lex->exchange ? SELECT_ACL | FILE_ACL : + SELECT_ACL, + all_tables, 0); } else - res=check_access(thd, lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL, - any_db,0,0,0); + res= check_access(thd, + lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL, + any_db, 0, 0, 0); if (res) { res=0; break; // Error message is given } - /* - In case of single SELECT unit->global_parameters points on first SELECT - TODO: move counters to SELECT_LEX - */ - unit->offset_limit_cnt= (ha_rows) unit->global_parameters->offset_limit; - unit->select_limit_cnt= (ha_rows) (unit->global_parameters->select_limit+ - unit->global_parameters->offset_limit); - if (unit->select_limit_cnt < - (ha_rows) unit->global_parameters->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // no limit - if (unit->select_limit_cnt == HA_POS_ERROR && !select_lex->next_select()) - select_lex->options&= ~OPTION_FOUND_ROWS; - if (!(res=open_and_lock_tables(thd,tables))) + if (!(res= open_and_lock_tables(thd, all_tables))) { if (lex->describe) { if (!(result= new select_send())) { send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_VOID_RETURN; + goto error; } else thd->send_explain_fields(result); @@ -2005,7 +2087,7 @@ mysql_execute_command(THD *thd) res= -1; break; } - query_cache_store_query(thd, tables); + query_cache_store_query(thd, all_tables); res= handle_select(thd, lex, result); if (result != lex->result) delete result; @@ -2127,8 +2209,9 @@ mysql_execute_command(THD *thd) break; } case SQLCOM_DO: - if (tables && ((res= check_table_access(thd, SELECT_ACL, tables,0)) || - (res= open_and_lock_tables(thd,tables)))) + if (all_tables && + ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || + (res= open_and_lock_tables(thd, all_tables)))) break; res= mysql_do(thd, *lex->insert_list); @@ -2149,7 +2232,7 @@ mysql_execute_command(THD *thd) { if (check_global_access(thd, SUPER_ACL)) goto error; - // PURGE MASTER LOGS TO 'file' + /* PURGE MASTER LOGS TO 'file' */ res = purge_master_logs(thd, lex->to_log); break; } @@ -2157,7 +2240,7 @@ mysql_execute_command(THD *thd) { if (check_global_access(thd, SUPER_ACL)) goto error; - // PURGE MASTER LOGS BEFORE 'data' + /* PURGE MASTER LOGS BEFORE 'data' */ res = purge_master_logs_before_date(thd, lex->purge_time); break; } @@ -2210,41 +2293,45 @@ mysql_execute_command(THD *thd) case SQLCOM_BACKUP_TABLE: { - if (check_db_used(thd,tables) || - check_table_access(thd,SELECT_ACL, tables,0) || + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL, all_tables, 0) || check_global_access(thd, FILE_ACL)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - res = mysql_backup_table(thd, tables); + res = mysql_backup_table(thd, first_table); break; } case SQLCOM_RESTORE_TABLE: { - if (check_db_used(thd,tables) || - check_table_access(thd, INSERT_ACL, tables,0) || + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, INSERT_ACL, all_tables, 0) || check_global_access(thd, FILE_ACL)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - res = mysql_restore_table(thd, tables); + res = mysql_restore_table(thd, first_table); break; } case SQLCOM_ASSIGN_TO_KEYCACHE: { - if (check_db_used(thd, tables) || - check_access(thd, INDEX_ACL, tables->db, - &tables->grant.privilege, 0, 0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_access(thd, INDEX_ACL, first_table->db, + &first_table->grant.privilege, 0, 0)) goto error; - res= mysql_assign_to_keycache(thd, tables, &lex->name_and_length); + res= mysql_assign_to_keycache(thd, first_table, &lex->name_and_length); break; } case SQLCOM_PRELOAD_KEYS: { - if (check_db_used(thd, tables) || - check_access(thd, INDEX_ACL, tables->db, - &tables->grant.privilege, 0, 0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_access(thd, INDEX_ACL, first_table->db, + &first_table->grant.privilege, 0, 0)) goto error; - res = mysql_preload_keys(thd, tables); + res = mysql_preload_keys(thd, first_table); break; } #ifdef HAVE_REPLICATION @@ -2297,19 +2384,21 @@ mysql_execute_command(THD *thd) #ifdef HAVE_REPLICATION case SQLCOM_LOAD_MASTER_TABLE: { - if (!tables->db) - tables->db=thd->db; - if (check_access(thd,CREATE_ACL,tables->db,&tables->grant.privilege,0,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (!first_table->db) + first_table->db= thd->db; + if (check_access(thd, CREATE_ACL, first_table->db, + &first_table->grant.privilege, 0, 0)) goto error; /* purecov: inspected */ if (grant_option) { /* Check that the first table has CREATE privilege */ - if (check_grant(thd, CREATE_ACL, tables, 0, 1, 0)) + if (check_grant(thd, CREATE_ACL, all_tables, 0, 1, 0)) goto error; } - if (strlen(tables->real_name) > NAME_LEN) + if (strlen(first_table->real_name) > NAME_LEN) { - net_printf(thd,ER_WRONG_TABLE_NAME, tables->real_name); + net_printf(thd, ER_WRONG_TABLE_NAME, first_table->real_name); break; } pthread_mutex_lock(&LOCK_active_mi); @@ -2317,7 +2406,7 @@ mysql_execute_command(THD *thd) fetch_master_table will send the error to the client on failure. Give error if the table already exists. */ - if (!fetch_master_table(thd, tables->db, tables->real_name, + if (!fetch_master_table(thd, first_table->db, first_table->real_name, active_mi, 0, 0)) { send_ok(thd); @@ -2329,12 +2418,13 @@ mysql_execute_command(THD *thd) case SQLCOM_CREATE_TABLE: { - /* Skip first table, which is the table we are creating */ - TABLE_LIST *create_table, *create_table_local; - tables= lex->unlink_first_table(tables, &create_table, - &create_table_local); + DBUG_ASSERT(first_table == all_tables && first_table != 0); + bool link_to_local; + // Skip first table, which is the table we are creating + TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local); + TABLE_LIST *select_tables= lex->query_tables; - if ((res= create_table_precheck(thd, tables, create_table))) + if ((res= create_table_precheck(thd, select_tables, create_table))) goto unsent_create_error; #ifndef HAVE_READLINK @@ -2343,7 +2433,7 @@ mysql_execute_command(THD *thd) /* Fix names if symlinked tables */ if (append_file_to_dir(thd, &lex->create_info.data_file_name, create_table->real_name) || - append_file_to_dir(thd,&lex->create_info.index_file_name, + append_file_to_dir(thd, &lex->create_info.index_file_name, create_table->real_name)) { res=-1; @@ -2351,7 +2441,7 @@ mysql_execute_command(THD *thd) } #endif /* - If we are using SET CHARSET without DEFAULT, add an implicite + If we are using SET CHARSET without DEFAULT, add an implicit DEFAULT to not confuse old users. (This may change). */ if ((lex->create_info.used_fields & @@ -2368,21 +2458,42 @@ mysql_execute_command(THD *thd) select_result *result; select_lex->options|= SELECT_NO_UNLOCK; - unit->offset_limit_cnt= select_lex->offset_limit; - unit->select_limit_cnt= select_lex->select_limit+ - select_lex->offset_limit; - if (unit->select_limit_cnt < select_lex->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // No limit + unit->set_limit(select_lex, select_lex); - if (!(res=open_and_lock_tables(thd,tables))) + if (!(res= open_and_lock_tables(thd, select_tables))) { - res= -1; // If error - if ((result=new select_create(create_table->db, - create_table->real_name, - &lex->create_info, - lex->create_list, - lex->key_list, - select_lex->item_list,lex->duplicates))) + /* + Is table which we are changing used somewhere in other parts + of query + */ + if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && + unique_table(create_table, select_tables)) + { + net_printf(thd, ER_UPDATE_TABLE_USED, create_table->real_name); + goto create_error; + } + /* If we create merge table, we have to test tables in merge, too */ + if (lex->create_info.used_fields & HA_CREATE_USED_UNION) + { + TABLE_LIST *tab; + for (tab= (TABLE_LIST*) lex->create_info.merge_list.first; + tab; + tab= tab->next_local) + { + if (unique_table(tab, select_tables)) + { + net_printf(thd, ER_UPDATE_TABLE_USED, tab->real_name); + goto create_error; + } + } + } + + if ((result= new select_create(create_table, + &lex->create_info, + lex->create_list, + lex->key_list, + select_lex->item_list, + lex->duplicates))) { /* CREATE from SELECT give its SELECT_LEX for SELECT, @@ -2391,49 +2502,48 @@ mysql_execute_command(THD *thd) select_lex->resolve_mode= SELECT_LEX::SELECT_MODE; res=handle_select(thd, lex, result); select_lex->resolve_mode= SELECT_LEX::NOMATTER_MODE; + delete result; } - //reset for PS + /* reset for PS */ lex->create_list.empty(); lex->key_list.empty(); } } - else // regular create + else { + /* regular create */ if (lex->name) res= mysql_create_like_table(thd, create_table, &lex->create_info, (Table_ident *)lex->name); else { - res= mysql_create_table(thd,create_table->db, - create_table->real_name, &lex->create_info, - lex->create_list, - lex->key_list,0,0); + res= mysql_create_table(thd, create_table->db, + create_table->real_name, &lex->create_info, + lex->create_list, + lex->key_list, 0, 0); } if (!res) send_ok(thd); } - - // put tables back for PS rexecuting - tables= lex->link_first_table_back(tables, create_table, - create_table_local); + lex->link_first_table_back(create_table, link_to_local); break; create_error: - res= 1; //error reported + res= 1; //error reported unsent_create_error: - // put tables back for PS rexecuting - tables= lex->link_first_table_back(tables, create_table, - create_table_local); + /* put tables back for PS rexecuting */ + lex->link_first_table_back(create_table, link_to_local); break; } case SQLCOM_CREATE_INDEX: - if (check_one_table_access(thd, INDEX_ACL, tables)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_one_table_access(thd, INDEX_ACL, all_tables)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; if (end_active_trans(thd)) res= -1; else - res = mysql_create_index(thd, tables, lex->key_list); + res = mysql_create_index(thd, first_table, lex->key_list); break; #ifdef HAVE_REPLICATION @@ -2461,7 +2571,7 @@ unsent_create_error: if (thd->locked_tables || thd->active_transaction()) { send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); - break; + goto error; } { pthread_mutex_lock(&LOCK_active_mi); @@ -2472,9 +2582,10 @@ unsent_create_error: #endif /* HAVE_REPLICATION */ case SQLCOM_ALTER_TABLE: + DBUG_ASSERT(first_table == all_tables && first_table != 0); #if defined(DONT_ALLOW_SHOW_COMMANDS) send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - break; + goto error; #else { ulong priv=0; @@ -2485,16 +2596,17 @@ unsent_create_error: break; } if (!select_lex->db) - select_lex->db=tables->db; - if (check_access(thd,ALTER_ACL,tables->db,&tables->grant.privilege,0,0) || + select_lex->db= first_table->db; + if (check_access(thd, ALTER_ACL, first_table->db, + &first_table->grant.privilege, 0, 0) || check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0)|| - check_merge_table_access(thd, tables->db, + check_merge_table_access(thd, first_table->db, (TABLE_LIST *) lex->create_info.merge_list.first)) goto error; /* purecov: inspected */ if (grant_option) { - if (check_grant(thd, ALTER_ACL, tables, 0, UINT_MAX, 0)) + if (check_grant(thd, ALTER_ACL, all_tables, 0, UINT_MAX, 0)) goto error; if (lex->name && !test_all_bits(priv,INSERT_ACL | CREATE_ACL)) { // Rename of table @@ -2518,7 +2630,7 @@ unsent_create_error: thd->slow_command=TRUE; res= mysql_alter_table(thd, select_lex->db, lex->name, &lex->create_info, - tables, lex->create_list, + first_table, lex->create_list, lex->key_list, select_lex->order_list.elements, (ORDER *) select_lex->order_list.first, @@ -2529,38 +2641,37 @@ unsent_create_error: #endif /*DONT_ALLOW_SHOW_COMMANDS*/ case SQLCOM_RENAME_TABLE: { + DBUG_ASSERT(first_table == all_tables && first_table != 0); TABLE_LIST *table; - if (check_db_used(thd,tables)) + if (check_db_used(thd, all_tables)) goto error; - for (table=tables ; table ; table=table->next->next) + for (table= first_table; table; table= table->next_local->next_local) { if (check_access(thd, ALTER_ACL | DROP_ACL, table->db, &table->grant.privilege,0,0) || - check_access(thd, INSERT_ACL | CREATE_ACL, table->next->db, - &table->next->grant.privilege,0,0)) + check_access(thd, INSERT_ACL | CREATE_ACL, table->next_local->db, + &table->next_local->grant.privilege, 0, 0)) goto error; if (grant_option) { - TABLE_LIST old_list,new_list; + TABLE_LIST old_list, new_list; /* we do not need initialize old_list and new_list because we will come table[0] and table->next[0] there */ - old_list=table[0]; - new_list=table->next[0]; - old_list.next=new_list.next=0; - if (check_grant(thd, ALTER_ACL, &old_list, 0, UINT_MAX, 0) || - (!test_all_bits(table->next->grant.privilege, + old_list= table[0]; + new_list= table->next_local[0]; + if (check_grant(thd, ALTER_ACL, &old_list, 0, 1, 0) || + (!test_all_bits(table->next_local->grant.privilege, INSERT_ACL | CREATE_ACL) && - check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, 0, - UINT_MAX, 0))) + check_grant(thd, INSERT_ACL | CREATE_ACL, &new_list, 0, 1, 0))) goto error; } } - query_cache_invalidate3(thd, tables, 0); + query_cache_invalidate3(thd, first_table, 0); if (end_active_trans(thd)) res= -1; - else if (mysql_rename_tables(thd,tables)) + else if (mysql_rename_tables(thd, first_table)) res= -1; break; } @@ -2568,7 +2679,7 @@ unsent_create_error: case SQLCOM_SHOW_BINLOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { if (check_global_access(thd, SUPER_ACL)) @@ -2579,38 +2690,40 @@ unsent_create_error: #endif #endif /* EMBEDDED_LIBRARY */ case SQLCOM_SHOW_CREATE: + DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { - if (check_db_used(thd, tables) || - check_access(thd, SELECT_ACL | EXTRA_ACL, tables->db, - &tables->grant.privilege,0,0)) + if (check_db_used(thd, all_tables) || + check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db, + &first_table->grant.privilege, 0, 0)) goto error; - res = mysqld_show_create(thd, tables); + res = mysqld_show_create(thd, first_table); break; } #endif case SQLCOM_CHECKSUM: { - if (check_db_used(thd,tables) || - check_table_access(thd, SELECT_ACL | EXTRA_ACL , tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL | EXTRA_ACL, all_tables, 0)) goto error; /* purecov: inspected */ - res = mysql_checksum_table(thd, tables, &lex->check_opt); + res = mysql_checksum_table(thd, first_table, &lex->check_opt); break; } case SQLCOM_REPAIR: { - if (check_db_used(thd,tables) || - check_table_access(thd,SELECT_ACL | INSERT_ACL, tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - res = mysql_repair_table(thd, tables, &lex->check_opt); + res= mysql_repair_table(thd, first_table, &lex->check_opt); /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -2622,24 +2735,25 @@ unsent_create_error: } case SQLCOM_CHECK: { - if (check_db_used(thd,tables) || - check_table_access(thd, SELECT_ACL | EXTRA_ACL , tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL | EXTRA_ACL , all_tables, 0)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - res = mysql_check_table(thd, tables, &lex->check_opt); + res = mysql_check_table(thd, first_table, &lex->check_opt); break; } case SQLCOM_ANALYZE: { - if (check_db_used(thd,tables) || - check_table_access(thd,SELECT_ACL | INSERT_ACL, tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; - res = mysql_analyze_table(thd, tables, &lex->check_opt); + res = mysql_analyze_table(thd, first_table, &lex->check_opt); /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -2652,17 +2766,17 @@ unsent_create_error: case SQLCOM_OPTIMIZE: { - if (check_db_used(thd,tables) || - check_table_access(thd,SELECT_ACL | INSERT_ACL, tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0)) goto error; /* purecov: inspected */ thd->slow_command=TRUE; res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ? - mysql_recreate_table(thd, tables, 1) : - mysql_optimize_table(thd, tables, &lex->check_opt); + mysql_recreate_table(thd, first_table, 1) : + mysql_optimize_table(thd, first_table, &lex->check_opt); /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -2673,9 +2787,10 @@ unsent_create_error: break; } case SQLCOM_UPDATE: - if (update_precheck(thd, tables)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (update_precheck(thd, all_tables)) break; - res= mysql_update(thd,tables, + res= mysql_update(thd, all_tables, select_lex->item_list, lex->value_list, select_lex->where, @@ -2688,9 +2803,10 @@ unsent_create_error: break; case SQLCOM_UPDATE_MULTI: { - if ((res= multi_update_precheck(thd, tables))) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if ((res= multi_update_precheck(thd, all_tables))) break; - res= mysql_multi_update(thd,tables, + res= mysql_multi_update(thd, all_tables, &select_lex->item_list, &lex->value_list, select_lex->where, @@ -2701,67 +2817,81 @@ unsent_create_error: case SQLCOM_REPLACE: case SQLCOM_INSERT: { - if ((res= insert_precheck(thd, tables))) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if ((res= insert_precheck(thd, all_tables))) break; - res = mysql_insert(thd,tables,lex->field_list,lex->many_values, - select_lex->item_list, lex->value_list, - lex->duplicates); + res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values, + select_lex->item_list, lex->value_list, + (lex->value_list.elements ? + DUP_UPDATE : lex->duplicates)); if (thd->net.report_error) res= -1; + if (first_table->view && !first_table->contain_auto_increment) + thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it break; } case SQLCOM_REPLACE_SELECT: case SQLCOM_INSERT_SELECT: { - TABLE_LIST *first_local_table= (TABLE_LIST *) select_lex->table_list.first; - if ((res= insert_select_precheck(thd, tables))) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if ((res= insert_select_precheck(thd, all_tables))) break; /* Fix lock for first table */ - if (tables->lock_type == TL_WRITE_DELAYED) - tables->lock_type= TL_WRITE; + if (first_table->lock_type == TL_WRITE_DELAYED) + first_table->lock_type= TL_WRITE; /* Don't unlock tables until command is written to binary log */ select_lex->options|= SELECT_NO_UNLOCK; select_result *result; - unit->offset_limit_cnt= select_lex->offset_limit; - unit->select_limit_cnt= select_lex->select_limit+select_lex->offset_limit; - if (unit->select_limit_cnt < select_lex->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // No limit + unit->set_limit(select_lex, select_lex); - if (find_real_table_in_list(tables->next, tables->db, tables->real_name)) + if (!(res= open_and_lock_tables(thd, all_tables))) { - /* Using same table for INSERT and SELECT */ - select_lex->options |= OPTION_BUFFER_RESULT; - } - - - if (!(res= open_and_lock_tables(thd, tables)) && - (result= new select_insert(tables->table, &lex->field_list, - lex->duplicates))) - { - /* Skip first table, which is the table we are inserting in */ - lex->select_lex.table_list.first= (byte*) first_local_table->next; /* - insert/replace from SELECT give its SELECT_LEX for SELECT, - and item_list belong to SELECT + Is table which we are changing used somewhere in other parts of + query */ - lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; - res= handle_select(thd, lex, result); - /* revert changes for SP */ - lex->select_lex.table_list.first= (byte*) first_local_table; - lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE; - delete result; + if (unique_table(first_table, all_tables->next_global)) + { + /* Using same table for INSERT and SELECT */ + select_lex->options |= OPTION_BUFFER_RESULT; + } + + if ((res= mysql_insert_select_prepare(thd))) + break; + if ((result= new select_insert(first_table, first_table->table, + &lex->field_list, lex->duplicates, + lex->duplicates == DUP_IGNORE))) + { + /* Skip first table, which is the table we are inserting in */ + lex->select_lex.table_list.first= (byte*) first_table->next_local; + /* + insert/replace from SELECT give its SELECT_LEX for SELECT, + and item_list belong to SELECT + */ + lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; + res= handle_select(thd, lex, result); + /* revert changes for SP */ + lex->select_lex.table_list.first= (byte*) first_table; + lex->select_lex.resolve_mode= SELECT_LEX::INSERT_MODE; + delete result; + } if (thd->net.report_error) res= -1; } else res= -1; + + if (first_table->view && !first_table->contain_auto_increment) + thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it + break; } case SQLCOM_TRUNCATE: - if (check_one_table_access(thd, DELETE_ACL, tables)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_one_table_access(thd, DELETE_ACL, all_tables)) goto error; /* Don't allow this within a transaction because we want to use @@ -2772,13 +2902,15 @@ unsent_create_error: send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION,NullS); goto error; } - res=mysql_truncate(thd, tables, 0); + + res= mysql_truncate(thd, first_table, 0); break; case SQLCOM_DELETE: { - if ((res= delete_precheck(thd, tables))) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if ((res= delete_precheck(thd, all_tables))) break; - res = mysql_delete(thd,tables, select_lex->where, + res = mysql_delete(thd, all_tables, select_lex->where, &select_lex->order_list, select_lex->select_limit, select_lex->options); if (thd->net.report_error) @@ -2787,13 +2919,13 @@ unsent_create_error: } case SQLCOM_DELETE_MULTI: { + DBUG_ASSERT(first_table == all_tables && first_table != 0); TABLE_LIST *aux_tables= (TABLE_LIST *)thd->lex->auxilliary_table_list.first; - TABLE_LIST *target_tbl; uint table_count; multi_delete *result; - if ((res= multi_delete_precheck(thd, tables, &table_count))) + if ((res= multi_delete_precheck(thd, all_tables, &table_count))) break; /* condition will be TRUE on SP re-excuting */ @@ -2806,28 +2938,9 @@ unsent_create_error: } thd->proc_info="init"; - if ((res=open_and_lock_tables(thd,tables))) + if ((res= open_and_lock_tables(thd, all_tables)) || + (res= mysql_multi_delete_prepare(thd))) break; - /* Fix tables-to-be-deleted-from list to point at opened tables */ - for (target_tbl= (TABLE_LIST*) aux_tables; - target_tbl; - target_tbl= target_tbl->next) - { - TABLE_LIST *orig= target_tbl->table_list; - target_tbl->table= orig->table; - /* - Multi-delete can't be constructed over-union => we always have - single SELECT on top and have to check underlying SELECTs of it - */ - if (lex->select_lex.check_updateable_in_subqueries(orig->db, - orig->real_name)) - { - my_error(ER_UPDATE_TABLE_USED, MYF(0), - orig->real_name); - res= -1; - break; - } - } if (!thd->is_fatal_error && (result= new multi_delete(thd,aux_tables, table_count))) @@ -2853,9 +2966,10 @@ unsent_create_error: } case SQLCOM_DROP_TABLE: { + DBUG_ASSERT(first_table == all_tables && first_table != 0); if (!lex->drop_temporary) { - if (check_table_access(thd,DROP_ACL,tables,0)) + if (check_table_access(thd, DROP_ACL, all_tables, 0)) goto error; /* purecov: inspected */ if (end_active_trans(thd)) { @@ -2876,21 +2990,23 @@ unsent_create_error: if (thd->slave_thread) lex->drop_if_exists= 1; } - res= mysql_rm_table(thd,tables,lex->drop_if_exists, lex->drop_temporary); + res= mysql_rm_table(thd, first_table, lex->drop_if_exists, + lex->drop_temporary); } break; case SQLCOM_DROP_INDEX: - if (check_one_table_access(thd, INDEX_ACL, tables)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_one_table_access(thd, INDEX_ACL, all_tables)) goto error; /* purecov: inspected */ if (end_active_trans(thd)) res= -1; else - res = mysql_drop_index(thd, tables, &lex->alter_info); + res = mysql_drop_index(thd, first_table, &lex->alter_info); break; case SQLCOM_SHOW_DATABASES: #if defined(DONT_ALLOW_SHOW_COMMANDS) send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else if ((specialflag & SPECIAL_SKIP_SHOW_DB) && check_global_access(thd, SHOW_DB_ACL)) @@ -2915,18 +3031,28 @@ unsent_create_error: res= mysqld_show_column_types(thd); break; case SQLCOM_SHOW_STATUS: - res= mysqld_show(thd,(lex->wild ? lex->wild->ptr() : NullS),status_vars, - OPT_GLOBAL, &LOCK_status); + STATUS_VAR tmp; + if (lex->option_type == OPT_GLOBAL) + { + pthread_mutex_lock(&LOCK_status); + calc_sum_of_all_status(&tmp); + } + res= mysqld_show(thd, (lex->wild ? lex->wild->ptr() : NullS), + status_vars, OPT_GLOBAL, &LOCK_status, + (lex->option_type == OPT_GLOBAL ? + &tmp: &thd->status_var)); + if (lex->option_type == OPT_GLOBAL) + pthread_mutex_unlock(&LOCK_status); break; case SQLCOM_SHOW_VARIABLES: res= mysqld_show(thd, (lex->wild ? lex->wild->ptr() : NullS), init_vars, lex->option_type, - &LOCK_global_system_variables); + &LOCK_global_system_variables, 0); break; case SQLCOM_SHOW_LOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { if (grant_option && check_access(thd, FILE_ACL, any_db,0,0,0)) @@ -2939,13 +3065,13 @@ unsent_create_error: /* FALL THROUGH */ #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { char *db=select_lex->db ? select_lex->db : thd->db; if (!db) { - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ goto error; /* purecov: inspected */ } remove_escape(db); // Fix escaped '_' @@ -2969,8 +3095,9 @@ unsent_create_error: res= mysqld_extend_show_tables(thd,db, (lex->wild ? lex->wild->ptr() : NullS)); else - res= mysqld_show_tables(thd,db, - (lex->wild ? lex->wild->ptr() : NullS)); + res= mysqld_show_tables(thd, db, + (lex->wild ? lex->wild->ptr() : NullS), + lex->verbose); break; } #endif @@ -2984,40 +3111,42 @@ unsent_create_error: res= mysqld_show_collations(thd,(lex->wild ? lex->wild->ptr() : NullS)); break; case SQLCOM_SHOW_FIELDS: + DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { - char *db=tables->db; + char *db= first_table->db; remove_escape(db); // Fix escaped '_' - remove_escape(tables->real_name); + remove_escape(first_table->real_name); if (check_access(thd,SELECT_ACL | EXTRA_ACL,db, - &tables->grant.privilege, 0, 0)) + &first_table->grant.privilege, 0, 0)) goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd, SELECT_ACL, tables, 2, UINT_MAX, 0)) + if (grant_option && check_grant(thd, SELECT_ACL, first_table, 2, UINT_MAX, 0)) goto error; - res= mysqld_show_fields(thd,tables, + res= mysqld_show_fields(thd, first_table, (lex->wild ? lex->wild->ptr() : NullS), lex->verbose); break; } #endif case SQLCOM_SHOW_KEYS: + DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - DBUG_VOID_RETURN; + goto error; #else { - char *db=tables->db; + char *db= first_table->db; remove_escape(db); // Fix escaped '_' - remove_escape(tables->real_name); + remove_escape(first_table->real_name); if (check_access(thd,SELECT_ACL | EXTRA_ACL,db, - &tables->grant.privilege, 0, 0)) + &first_table->grant.privilege, 0, 0)) goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd, SELECT_ACL, tables, 2, UINT_MAX, 0)) + if (grant_option && check_grant(thd, SELECT_ACL, all_tables, 2, UINT_MAX, 0)) goto error; - res= mysqld_show_keys(thd,tables); + res= mysqld_show_keys(thd, first_table); break; } #endif @@ -3027,12 +3156,13 @@ unsent_create_error: case SQLCOM_LOAD: { + DBUG_ASSERT(first_table == all_tables && first_table != 0); uint privilege= (lex->duplicates == DUP_REPLACE ? INSERT_ACL | DELETE_ACL : INSERT_ACL); if (!lex->local_file) { - if (check_access(thd,privilege | FILE_ACL,tables->db,0,0,0)) + if (check_access(thd, privilege | FILE_ACL, first_table->db, 0, 0, 0)) goto error; } else @@ -3043,19 +3173,21 @@ unsent_create_error: send_error(thd,ER_NOT_ALLOWED_COMMAND); goto error; } - if (check_one_table_access(thd, privilege, tables)) + if (check_one_table_access(thd, privilege, all_tables)) goto error; } - res=mysql_load(thd, lex->exchange, tables, lex->field_list, - lex->duplicates, (bool) lex->local_file, lex->lock_option); + res= mysql_load(thd, lex->exchange, first_table, lex->field_list, + lex->duplicates, (bool) lex->local_file, + lex->lock_option, lex->duplicates == DUP_IGNORE); break; } case SQLCOM_SET_OPTION: { List *lex_var_list= &lex->var_list; - if (tables && ((res= check_table_access(thd, SELECT_ACL, tables,0)) || - (res= open_and_lock_tables(thd,tables)))) + if (all_tables && + ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || + (res= open_and_lock_tables(thd, all_tables)))) break; if (lex->one_shot_set && not_all_support_one_shot(lex_var_list)) { @@ -3097,17 +3229,18 @@ purposes internal to the MySQL server", MYF(0)); break; case SQLCOM_LOCK_TABLES: unlock_locked_tables(thd); - if (check_db_used(thd,tables) || end_active_trans(thd)) + if (check_db_used(thd, all_tables) || end_active_trans(thd)) goto error; - if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, tables,0)) + if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables, 0)) goto error; thd->in_lock_tables=1; thd->options|= OPTION_TABLE_LOCK; - if (!(res= open_and_lock_tables(thd, tables))) + + if (!(res= open_and_lock_tables(thd, all_tables))) { #ifdef HAVE_QUERY_CACHE if (thd->variables.query_cache_wlock_invalidate) - query_cache.invalidate_locked_for_write(tables); + query_cache.invalidate_locked_for_write(first_table); #endif /*HAVE_QUERY_CACHE*/ thd->locked_tables=thd->lock; thd->lock=0; @@ -3232,26 +3365,24 @@ purposes internal to the MySQL server", MYF(0)); res=mysqld_show_create_db(thd,lex->name,&lex->create_info); break; } - case SQLCOM_CREATE_FUNCTION: + case SQLCOM_CREATE_FUNCTION: // UDF function + { + sp_head *sph; if (check_access(thd,INSERT_ACL,"mysql",0,1,0)) break; #ifdef HAVE_DLOPEN + if ((sph= sp_find_function(thd, lex->spname))) + { + net_printf(thd, ER_UDF_EXISTS, lex->spname->m_name.str); + goto error; + } if (!(res = mysql_create_function(thd,&lex->udf))) send_ok(thd); #else res= -1; #endif break; - case SQLCOM_DROP_FUNCTION: - if (check_access(thd,DELETE_ACL,"mysql",0,1,0)) - break; -#ifdef HAVE_DLOPEN - if (!(res = mysql_drop_function(thd,&lex->udf.name))) - send_ok(thd); -#else - res= -1; -#endif - break; + } #ifndef NO_EMBEDDED_ACCESS_CHECKS case SQLCOM_DROP_USER: { @@ -3259,7 +3390,6 @@ purposes internal to the MySQL server", MYF(0)); break; if (!(res= mysql_drop_user(thd, lex->users_list))) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); @@ -3275,7 +3405,6 @@ purposes internal to the MySQL server", MYF(0)); break; if (!(res = mysql_revoke_all(thd, lex->users_list))) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); @@ -3289,34 +3418,12 @@ purposes internal to the MySQL server", MYF(0)); case SQLCOM_GRANT: { if (check_access(thd, lex->grant | lex->grant_tot_col | GRANT_ACL, - tables && tables->db ? tables->db : select_lex->db, - tables ? &tables->grant.privilege : 0, - tables ? 0 : 1,0)) + ((first_table && first_table->db) ? + first_table->db : select_lex->db), + first_table ? &first_table->grant.privilege : 0, + first_table ? 0 : 1, 0)) goto error; - /* - Check that the user isn't trying to change a password for another - user if he doesn't have UPDATE privilege to the MySQL database - */ - - if (thd->user) // If not replication - { - LEX_USER *user; - List_iterator user_list(lex->users_list); - while ((user=user_list++)) - { - if (user->password.str && - (strcmp(thd->user,user->user.str) || - user->host.str && - my_strcasecmp(&my_charset_latin1, - user->host.str, thd->host_or_ip))) - { - if (check_access(thd, UPDATE_ACL, "mysql",0,1,0)) - goto error; - break; // We are allowed to do changes - } - } - } if (specialflag & SPECIAL_NO_RESOLVE) { LEX_USER *user; @@ -3330,24 +3437,21 @@ purposes internal to the MySQL server", MYF(0)); user->host.str); } } - if (tables) + if (first_table) { if (grant_option && check_grant(thd, (lex->grant | lex->grant_tot_col | GRANT_ACL), - tables, 0, UINT_MAX, 0)) + all_tables, 0, UINT_MAX, 0)) goto error; - if (!(res = mysql_table_grant(thd,tables,lex->users_list, lex->columns, - lex->grant, - lex->sql_command == SQLCOM_REVOKE))) + if (!(res = mysql_table_grant(thd, all_tables, lex->users_list, + lex->columns, lex->grant, + lex->sql_command == SQLCOM_REVOKE)) && + mysql_bin_log.is_open()) { - mysql_update_log.write(thd, thd->query, thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, 0); - mysql_bin_log.write(&qinfo); - } + thd->clear_error(); + Query_log_event qinfo(thd, thd->query, thd->query_length, 0); + mysql_bin_log.write(&qinfo); } } else @@ -3362,7 +3466,6 @@ purposes internal to the MySQL server", MYF(0)); lex->sql_command == SQLCOM_REVOKE); if (!res) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { thd->clear_error(); @@ -3389,14 +3492,14 @@ purposes internal to the MySQL server", MYF(0)); lex->no_write_to_binlog= 1; case SQLCOM_FLUSH: { - if (check_global_access(thd,RELOAD_ACL) || check_db_used(thd, tables)) + if (check_global_access(thd,RELOAD_ACL) || check_db_used(thd, all_tables)) goto error; /* reload_acl_and_cache() will tell us if we are allowed to write to the binlog or not. */ bool write_to_binlog; - if (reload_acl_and_cache(thd, lex->type, tables, &write_to_binlog)) + if (reload_acl_and_cache(thd, lex->type, first_table, &write_to_binlog)) send_error(thd, 0); else { @@ -3406,7 +3509,6 @@ purposes internal to the MySQL server", MYF(0)); */ if (!lex->no_write_to_binlog && write_to_binlog) { - mysql_update_log.write(thd, thd->query, thd->query_length); if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); @@ -3418,7 +3520,7 @@ purposes internal to the MySQL server", MYF(0)); break; } case SQLCOM_KILL: - kill_one_thread(thd,lex->thread_id); + kill_one_thread(thd,lex->thread_id, lex->type & ONLY_KILL_QUERY); break; #ifndef NO_EMBEDDED_ACCESS_CHECKS case SQLCOM_SHOW_GRANTS: @@ -3432,34 +3534,37 @@ purposes internal to the MySQL server", MYF(0)); break; #endif case SQLCOM_HA_OPEN: - if (check_db_used(thd,tables) || - check_table_access(thd,SELECT_ACL, tables,0)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables) || + check_table_access(thd, SELECT_ACL, all_tables, 0)) goto error; - res = mysql_ha_open(thd, tables); + res= mysql_ha_open(thd, first_table); break; case SQLCOM_HA_CLOSE: - if (check_db_used(thd,tables)) + DBUG_ASSERT(first_table == all_tables && first_table != 0); + if (check_db_used(thd, all_tables)) goto error; - res = mysql_ha_close(thd, tables); + res= mysql_ha_close(thd, first_table); break; case SQLCOM_HA_READ: + DBUG_ASSERT(first_table == all_tables && first_table != 0); /* There is no need to check for table permissions here, because if a user has no permissions to read a table, he won't be able to open it (with SQLCOM_HA_OPEN) in the first place. */ - if (check_db_used(thd,tables)) + if (check_db_used(thd, all_tables)) goto error; - res = mysql_ha_read(thd, tables, lex->ha_read_mode, lex->backup_dir, - lex->insert_list, lex->ha_rkey_mode, select_lex->where, - select_lex->select_limit, select_lex->offset_limit); + res= mysql_ha_read(thd, first_table, lex->ha_read_mode, lex->backup_dir, + lex->insert_list, lex->ha_rkey_mode, select_lex->where, + select_lex->select_limit, select_lex->offset_limit); break; case SQLCOM_BEGIN: if (thd->locked_tables) { thd->lock=thd->locked_tables; - thd->locked_tables=0; // Will be automaticly closed + thd->locked_tables=0; // Will be automatically closed close_thread_tables(thd); // Free tables } if (end_active_trans(thd)) @@ -3532,11 +3637,353 @@ purposes internal to the MySQL server", MYF(0)); else res= -1; break; + case SQLCOM_CREATE_PROCEDURE: + case SQLCOM_CREATE_SPFUNCTION: + { + uint namelen; + char *name; + + if (!lex->sphead) + { + res= -1; // Shouldn't happen + break; + } + + if (! lex->sphead->m_db.str) + { + send_error(thd,ER_NO_DB_ERROR); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + + name= lex->sphead->name(&namelen); +#ifdef HAVE_DLOPEN + if (lex->sphead->m_type == TYPE_ENUM_FUNCTION) + { + udf_func *udf = find_udf(name, namelen); + + if (udf) + { + net_printf(thd, ER_UDF_EXISTS, name); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + } +#endif + if (lex->sphead->m_type == TYPE_ENUM_FUNCTION && + !lex->sphead->m_has_return) + { + net_printf(thd, ER_SP_NORETURN, name); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + + res= lex->sphead->create(thd); + switch (res) { + case SP_OK: + send_ok(thd); + lex->unit.cleanup(); + delete lex->sphead; + lex->sphead= 0; + break; + case SP_WRITE_ROW_FAILED: + net_printf(thd, ER_SP_ALREADY_EXISTS, SP_TYPE_STRING(lex), name); + lex->unit.cleanup(); + delete lex->sphead; + lex->sphead= 0; + goto error; + case SP_NO_DB_ERROR: + net_printf(thd, ER_BAD_DB_ERROR, lex->sphead->m_db.str); + lex->unit.cleanup(); + delete lex->sphead; + lex->sphead= 0; + goto error; + default: + net_printf(thd, ER_SP_STORE_FAILED, SP_TYPE_STRING(lex), name); + lex->unit.cleanup(); + delete lex->sphead; + lex->sphead= 0; + goto error; + } + break; + } + case SQLCOM_CALL: + { + sp_head *sp; + + if (!(sp= sp_find_procedure(thd, lex->spname))) + { + net_printf(thd, ER_SP_DOES_NOT_EXIST, "PROCEDURE", + lex->spname->m_qname.str); + goto error; + } + else + { +#ifndef NO_EMBEDDED_ACCESS_CHECKS + st_sp_security_context save_ctx; +#endif + ha_rows select_limit; + uint smrx; + LINT_INIT(smrx); + + /* In case the arguments are subselects... */ + if (all_tables && + ((res= check_table_access(thd, SELECT_ACL, all_tables, 0)) || + (res= open_and_lock_tables(thd, all_tables)))) + { + break; + } + +#ifndef EMBEDDED_LIBRARY + /* + When executing substatements, they're assumed to send_error when + it happens, but not to send_ok. + */ + my_bool nsok= thd->net.no_send_ok; + thd->net.no_send_ok= TRUE; +#endif + if (sp->m_multi_results) + { + if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) + { + send_error(thd, ER_SP_BADSELECT); +#ifndef EMBEDDED_LIBRARY + thd->net.no_send_ok= nsok; +#endif + goto error; + } + smrx= thd->server_status & SERVER_MORE_RESULTS_EXISTS; + thd->server_status |= SERVER_MORE_RESULTS_EXISTS; + } + +#ifndef NO_EMBEDDED_ACCESS_CHECKS + sp_change_security_context(thd, sp, &save_ctx); +#endif + select_limit= thd->variables.select_limit; + thd->variables.select_limit= HA_POS_ERROR; + + thd->row_count_func= 0; + res= sp->execute_procedure(thd, &lex->value_list); + + thd->variables.select_limit= select_limit; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + sp_restore_security_context(thd, sp, &save_ctx); +#endif + +#ifndef EMBEDDED_LIBRARY + thd->net.no_send_ok= nsok; +#endif + if (sp->m_multi_results) + { + if (! smrx) + thd->server_status &= ~SERVER_MORE_RESULTS_EXISTS; + } + + if (res == 0) + send_ok(thd, (ulong) (thd->row_count_func < 0 ? 0 : thd->row_count_func)); + else + goto error; // Substatement should already have sent error + } + break; + } + case SQLCOM_ALTER_PROCEDURE: + case SQLCOM_ALTER_FUNCTION: + { + sp_head *sp; + st_sp_chistics chistics; + + memcpy(&chistics, &lex->sp_chistics, sizeof(chistics)); + if (lex->sql_command == SQLCOM_ALTER_PROCEDURE) + sp= sp_find_procedure(thd, lex->spname); + else + sp= sp_find_function(thd, lex->spname); + mysql_reset_errors(thd); + if (! sp) + res= SP_KEY_NOT_FOUND; + else + { + if (check_sp_definer_access(thd, sp)) + { + res= -1; + break; + } + memcpy(&lex->sp_chistics, &chistics, sizeof(lex->sp_chistics)); + if (lex->sql_command == SQLCOM_ALTER_PROCEDURE) + res= sp_update_procedure(thd, lex->spname, &lex->sp_chistics); + else + res= sp_update_function(thd, lex->spname, &lex->sp_chistics); + } + switch (res) + { + case SP_OK: + send_ok(thd); + break; + case SP_KEY_NOT_FOUND: + net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex), + lex->spname->m_qname.str); + goto error; + default: + net_printf(thd, ER_SP_CANT_ALTER, SP_COM_STRING(lex), + lex->spname->m_qname.str); + goto error; + } + break; + } + case SQLCOM_DROP_PROCEDURE: + case SQLCOM_DROP_FUNCTION: + { + sp_head *sp; + + if (lex->sql_command == SQLCOM_DROP_PROCEDURE) + sp= sp_find_procedure(thd, lex->spname); + else + sp= sp_find_function(thd, lex->spname); + mysql_reset_errors(thd); + if (! sp) + res= SP_KEY_NOT_FOUND; + else + { + if (check_sp_definer_access(thd, sp)) + { + res= -1; + break; + } + if (lex->sql_command == SQLCOM_DROP_PROCEDURE) + res= sp_drop_procedure(thd, lex->spname); + else + { + res= sp_drop_function(thd, lex->spname); +#ifdef HAVE_DLOPEN + if (res == SP_KEY_NOT_FOUND) + { + udf_func *udf = find_udf(lex->spname->m_name.str, + lex->spname->m_name.length); + if (udf) + { + if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 0)) + goto error; + if (!(res = mysql_drop_function(thd,&lex->spname->m_name))) + { + send_ok(thd); + break; + } + } + } +#endif + } + } + switch (res) + { + case SP_OK: + send_ok(thd); + break; + case SP_KEY_NOT_FOUND: + if (lex->drop_if_exists) + { + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + SP_COM_STRING(lex), lex->spname->m_name.str); + res= 0; + send_ok(thd); + break; + } + net_printf(thd, ER_SP_DOES_NOT_EXIST, SP_COM_STRING(lex), + lex->spname->m_qname.str); + goto error; + default: + net_printf(thd, ER_SP_DROP_FAILED, SP_COM_STRING(lex), + lex->spname->m_qname.str); + goto error; + } + break; + } + case SQLCOM_SHOW_CREATE_PROC: + { + res= -1; + if (lex->spname->m_name.length > NAME_LEN) + { + net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str); + goto error; + } + res= sp_show_create_procedure(thd, lex->spname); + if (res != SP_OK) + { /* We don't distinguish between errors for now */ + net_printf(thd, ER_SP_DOES_NOT_EXIST, + SP_COM_STRING(lex), lex->spname->m_name.str); + res= 0; + goto error; + } + break; + } + case SQLCOM_SHOW_CREATE_FUNC: + { + if (lex->spname->m_name.length > NAME_LEN) + { + net_printf(thd, ER_TOO_LONG_IDENT, lex->spname->m_name.str); + goto error; + } + res= sp_show_create_function(thd, lex->spname); + if (res != SP_OK) + { /* We don't distinguish between errors for now */ + net_printf(thd, ER_SP_DOES_NOT_EXIST, + SP_COM_STRING(lex), lex->spname->m_name.str); + res= 0; + goto error; + } + res= 0; + break; + } + case SQLCOM_SHOW_STATUS_PROC: + { + res= sp_show_status_procedure(thd, (lex->wild ? + lex->wild->ptr() : NullS)); + break; + } + case SQLCOM_SHOW_STATUS_FUNC: + { + res= sp_show_status_function(thd, (lex->wild ? + lex->wild->ptr() : NullS)); + break; + } + case SQLCOM_CREATE_VIEW: + { + res= mysql_create_view(thd, thd->lex->create_view_mode); + break; + } + case SQLCOM_DROP_VIEW: + { + if (check_table_access(thd, DROP_ACL, all_tables, 0)) + goto error; + if (end_active_trans(thd)) + { + res= -1; + break; + } + res= mysql_drop_view(thd, first_table, thd->lex->drop_mode); + break; + } + case SQLCOM_CREATE_TRIGGER: + { + /* We don't care much about trigger body at that point */ + delete lex->sphead; + lex->sphead= 0; + + res= mysql_create_or_drop_trigger(thd, all_tables, 1); + break; + } + case SQLCOM_DROP_TRIGGER: + { + res= mysql_create_or_drop_trigger(thd, all_tables, 0); + break; + } default: /* Impossible */ send_ok(thd); break; } - thd->proc_info="query end"; // QQ + thd->proc_info="query end"; if (thd->one_shot_set) { /* @@ -3561,11 +4008,38 @@ purposes internal to the MySQL server", MYF(0)); thd->one_shot_set= 0; } } + + /* + The return value for ROW_COUNT() is "implementation dependent" if + the statement is not DELETE, INSERT or UPDATE (or a CALL executing + such a statement), but -1 is what JDBC and ODBC wants. + */ + switch (lex->sql_command) { + case SQLCOM_UPDATE: + case SQLCOM_UPDATE_MULTI: + case SQLCOM_REPLACE: + case SQLCOM_INSERT: + case SQLCOM_REPLACE_SELECT: + case SQLCOM_INSERT_SELECT: + case SQLCOM_DELETE: + case SQLCOM_DELETE_MULTI: + case SQLCOM_CALL: + break; + default: + thd->row_count_func= -1; + } + + /* + We end up here if res == 0 and send_ok() has been done, + or res != 0 and no send_error() has yet been done. + */ if (res < 0) - send_error(thd,thd->killed ? ER_SERVER_SHUTDOWN : 0); + send_error(thd,thd->killed_errno()); + DBUG_RETURN(res); error: - DBUG_VOID_RETURN; + /* We end up here if send_error() has already been done. */ + DBUG_RETURN(-1); } @@ -3576,28 +4050,29 @@ error: SYNOPSIS check_one_table_access() thd Thread handler - privilege requested privelage - tables table list of command + privilege requested privilege + all_tables global table list of query RETURN 0 - OK 1 - access denied, error is sent to client */ -int check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables) +bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *all_tables) { - if (check_access(thd, privilege, tables->db, &tables->grant.privilege,0,0)) + if (check_access(thd, privilege, all_tables->db, + &all_tables->grant.privilege, 0, 0)) return 1; /* Show only 1 table for check_grant */ - if (grant_option && check_grant(thd, privilege, tables, 0, 1, 0)) + if (grant_option && check_grant(thd, privilege, all_tables, 0, 1, 0)) return 1; /* Check rights on tables of subselect (if exists) */ TABLE_LIST *subselects_tables; - if ((subselects_tables= tables->next)) + if ((subselects_tables= all_tables->next_global)) { - if ((check_table_access(thd, SELECT_ACL, subselects_tables,0))) + if ((check_table_access(thd, SELECT_ACL, subselects_tables, 0))) return 1; } return 0; @@ -3627,13 +4102,13 @@ bool check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, bool dont_check_global_grants, bool no_errors) { - DBUG_ENTER("check_access"); - DBUG_PRINT("enter",("db: '%s' want_access: %lu master_access: %lu", - db ? db : "", want_access, thd->master_access)); #ifndef NO_EMBEDDED_ACCESS_CHECKS ulong db_access; #endif ulong dummy; + DBUG_ENTER("check_access"); + DBUG_PRINT("enter",("db: %s want_access: %lu master_access: %lu", + db ? db : "", want_access, thd->master_access)); if (save_priv) *save_priv=0; else @@ -3641,8 +4116,9 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) { + DBUG_PRINT("error",("No database")); if (!no_errors) - send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */ + send_error(thd,ER_NO_DB_ERROR); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -3667,6 +4143,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, if (((want_access & ~thd->master_access) & ~(DB_ACLS | EXTRA_ACL)) || ! db && dont_check_global_grants) { // We can never grant this + DBUG_PRINT("error",("No possible access")); if (!no_errors) net_printf(thd,ER_ACCESS_DENIED_ERROR, thd->priv_user, @@ -3686,13 +4163,17 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_PRINT("info",("db_access: %lu", db_access)); /* Remove SHOW attribute and access rights we already have */ want_access &= ~(thd->master_access | EXTRA_ACL); + DBUG_PRINT("info",("db_access: %lu want_access: %lu", + db_access, want_access)); db_access= ((*save_priv=(db_access | thd->master_access)) & want_access); /* grant_option is set if there exists a single table or column grant */ if (db_access == want_access || - ((grant_option && !dont_check_global_grants) && + (grant_option && !dont_check_global_grants && !(want_access & ~(db_access | TABLE_ACLS)))) DBUG_RETURN(FALSE); /* Ok */ + + DBUG_PRINT("error",("Access denied")); if (!no_errors) net_printf(thd,ER_DBACCESS_DENIED_ERROR, thd->priv_user, @@ -3712,7 +4193,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, want_access Use should have any of these global rights WARNING - One gets access rigth if one has ANY of the rights in want_access + One gets access right if one has ANY of the rights in want_access This is useful as one in most cases only need one global right, but in some case we want to check if the user has SUPER or REPL_CLIENT_ACL rights. @@ -3750,7 +4231,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, uint found=0; ulong found_access=0; TABLE_LIST *org_tables=tables; - for (; tables ; tables=tables->next) + for (; tables; tables= tables->next_global) { if (tables->derived || (tables->table && (int)tables->table->tmp_table) || @@ -3783,6 +4264,42 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, return FALSE; } + +/* + Check if the given table has any of the asked privileges + + SYNOPSIS + check_some_access() + thd Thread handler + want_access Bitmap of possible privileges to check for + + RETURN + 0 ok + 1 error +*/ + + +bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) +{ + ulong access; + DBUG_ENTER("check_some_access"); + + /* This loop will work as long as we have less than 32 privileges */ + for (access= 1; access < want_access ; access<<= 1) + { + if (access & want_access) + { + if (!check_access(thd, access, table->db, + &table->grant.privilege, 0, 1) && + !grant_option || !check_grant(thd, access, table, 0, 1, 1)) + DBUG_RETURN(0); + } + } + DBUG_PRINT("exit",("no matching access rights")); + DBUG_RETURN(1); +} + + bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list) { @@ -3791,7 +4308,7 @@ bool check_merge_table_access(THD *thd, char *db, { /* Check that all tables use the current database */ TABLE_LIST *tmp; - for (tmp=table_list; tmp ; tmp=tmp->next) + for (tmp= table_list; tmp; tmp= tmp->next_local) { if (!tmp->db || !tmp->db[0]) tmp->db=db; @@ -3805,7 +4322,7 @@ bool check_merge_table_access(THD *thd, char *db, static bool check_db_used(THD *thd,TABLE_LIST *tables) { - for (; tables ; tables=tables->next) + for (; tables; tables= tables->next_global) { if (!tables->db) { @@ -3819,6 +4336,41 @@ static bool check_db_used(THD *thd,TABLE_LIST *tables) return FALSE; } + +/* + Check if the given SP is owned by thd->priv_user/host, or priv_user is root. + QQ This is not quite complete, but it will do as a basic security check + for now. The question is exactly which rights should 'root' have? + Should root have access regardless of host for instance? + + SYNOPSIS + check_sp_definer_access() + thd Thread handler + sp The SP pointer + + RETURN + 0 ok + 1 error Error message has been sent +*/ + +static bool +check_sp_definer_access(THD *thd, sp_head *sp) +{ + LEX_STRING *usr, *hst; + + if (strcmp("root", thd->priv_user) == 0) + return FALSE; /* QQ Any root is ok now */ + usr= &sp->m_definer_user; + hst= &sp->m_definer_host; + if (strncmp(thd->priv_user, usr->str, usr->length) == 0 && + strncmp(thd->priv_host, hst->str, hst->length) == 0) + return FALSE; /* Both user and host must match */ + + my_error(ER_SP_ACCESS_DENIED_ERROR, MYF(0), sp->m_qname.str); + return TRUE; /* Not definer or root */ +} + + /**************************************************************************** Check stack size; Send error if there isn't enough stack to continue ****************************************************************************/ @@ -3883,6 +4435,7 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize) return 0; } + /**************************************************************************** Initialize global thd variables needed for query ****************************************************************************/ @@ -3915,13 +4468,13 @@ void mysql_reset_thd_for_next_command(THD *thd) DBUG_ENTER("mysql_reset_thd_for_next_command"); thd->free_list= 0; thd->select_number= 1; - thd->total_warn_count= 0; // Warnings for this query + thd->total_warn_count=0; // Warnings for this query thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0; thd->sent_row_count= thd->examined_row_count= 0; thd->is_fatal_error= thd->rand_used= thd->time_zone_used= 0; thd->server_status&= ~ (SERVER_MORE_RESULTS_EXISTS | - SERVER_QUERY_NO_INDEX_USED | - SERVER_QUERY_NO_GOOD_INDEX_USED); + SERVER_QUERY_NO_INDEX_USED | + SERVER_QUERY_NO_GOOD_INDEX_USED); thd->tmp_table_used= 0; if (opt_bin_log) reset_dynamic(&thd->user_var_events); @@ -3940,7 +4493,6 @@ mysql_init_select(LEX *lex) { DBUG_ASSERT(lex->result == 0); lex->exchange= 0; - lex->proc_list.first= 0; } } @@ -3954,6 +4506,7 @@ mysql_new_select(LEX *lex, bool move_down) select_lex->select_number= ++lex->thd->select_number; select_lex->init_query(); select_lex->init_select(); + select_lex->parent_lex= lex; if (move_down) { /* first select_lex of subselect or derived table */ @@ -3969,10 +4522,15 @@ mysql_new_select(LEX *lex, bool move_down) unit->link_prev= 0; unit->return_to= lex->current_select; select_lex->include_down(unit); - // TODO: assign resolve_mode for fake subquery after merging with new tree + /* TODO: assign resolve_mode for fake subquery after merging with new tree */ } else { + if (lex->current_select->order_list.first && !lex->current_select->braces) + { + net_printf(lex->thd, ER_WRONG_USAGE, "UNION", "ORDER BY"); + return 1; + } select_lex->include_neighbour(lex->current_select); SELECT_LEX_UNIT *unit= select_lex->master_unit(); SELECT_LEX *fake= unit->fake_select_lex; @@ -4040,6 +4598,8 @@ void mysql_init_multi_delete(LEX *lex) lex->select_lex.select_limit= lex->unit.select_limit_cnt= HA_POS_ERROR; lex->select_lex.table_list.save_and_clear(&lex->auxilliary_table_list); + lex->query_tables= 0; + lex->query_tables_last= &lex->query_tables; } @@ -4068,22 +4628,42 @@ void mysql_parse(THD *thd, char *inBuf, uint length) #endif { if (thd->net.report_error) + { send_error(thd, 0, NullS); + if (thd->lex->sphead) + { + if (lex != thd->lex) + thd->lex->sphead->restore_lex(thd); + delete thd->lex->sphead; + thd->lex->sphead= NULL; + } + } else { mysql_execute_command(thd); query_cache_end_of_result(thd); } } + lex->unit.cleanup(); } else { DBUG_PRINT("info",("Command aborted. Fatal_error: %d", thd->is_fatal_error)); query_cache_abort(&thd->net); + lex->unit.cleanup(); + if (thd->lex->sphead) + { + /* Clean up after failed stored procedure/function */ + if (lex != thd->lex) + thd->lex->sphead->restore_lex(thd); + delete thd->lex->sphead; + thd->lex->sphead= NULL; + } } thd->proc_info="freeing items"; thd->end_statement(); + thd->cleanup_after_query(); DBUG_ASSERT(thd->change_list.is_empty()); } DBUG_VOID_RETURN; @@ -4104,17 +4684,20 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length) { LEX *lex= thd->lex; bool error= 0; + DBUG_ENTER("mysql_test_parse_for_slave"); mysql_init_query(thd, (uchar*) inBuf, length); if (!yyparse((void*) thd) && ! thd->is_fatal_error && all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first)) - error= 1; /* Ignore question */ + error= 1; /* Ignore question */ thd->end_statement(); - return error; + thd->cleanup_after_query(); + DBUG_RETURN(error); } #endif + /* Calculate interval lengths. Strip trailing spaces from all strings. @@ -4156,6 +4739,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, register create_field *new_field; LEX *lex= thd->lex; uint allowed_type_modifier=0; + uint sign_len; char warn_buff[MYSQL_ERRMSG_SIZE]; DBUG_ENTER("add_field_to_list"); @@ -4247,9 +4831,19 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, new_field->comment.str= (char*) comment->str; new_field->comment.length=comment->length; } + /* + Set flag if this field doesn't have a default value + Enum values has always the first value as a default (set in + make_empty_rec(). + */ + if (!default_value && !(type_modifier & AUTO_INCREMENT_FLAG) && + (type_modifier & NOT_NULL_FLAG) && type != FIELD_TYPE_TIMESTAMP && + type != FIELD_TYPE_ENUM) + new_field->flags|= NO_DEFAULT_VALUE_FLAG; + if (length && !(new_field->length= (uint) atoi(length))) length=0; /* purecov: inspected */ - uint sign_len=type_modifier & UNSIGNED_FLAG ? 0 : 1; + sign_len=type_modifier & UNSIGNED_FLAG ? 0 : 1; if (new_field->length && new_field->decimals && new_field->length < new_field->decimals+1 && @@ -4302,7 +4896,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, new_field->sql_type= FIELD_TYPE_BLOB; sprintf(warn_buff, ER(ER_AUTO_CONVERT), field_name, "CHAR", (cs == &my_charset_bin) ? "BLOB" : "TEXT"); - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_AUTO_CONVERT, + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT, warn_buff); /* fall through */ case FIELD_TYPE_BLOB: @@ -4423,11 +5017,11 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, If we have TIMESTAMP NULL column without explicit DEFAULT value we treat it as having DEFAULT NULL attribute. */ - new_field->unireg_check= on_update_value ? - Field::TIMESTAMP_UN_FIELD : - (new_field->flags & NOT_NULL_FLAG ? - Field::TIMESTAMP_OLD_FIELD: - Field::NONE); + new_field->unireg_check= (on_update_value ? + Field::TIMESTAMP_UN_FIELD : + (new_field->flags & NOT_NULL_FLAG ? + Field::TIMESTAMP_OLD_FIELD: + Field::NONE)); } break; case FIELD_TYPE_DATE: // Old date type @@ -4601,6 +5195,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc) order->asc = asc; order->free_me=0; order->used=0; + order->counter_used= 0; list.link_in_list((byte*) order,(byte**) &order->next); DBUG_RETURN(0); } @@ -4636,6 +5231,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { register TABLE_LIST *ptr; char *alias_str; + LEX *lex= thd->lex; DBUG_ENTER("add_table_to_list"); if (!table) @@ -4689,6 +5285,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX); ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES); ptr->derived= table->sel; + ptr->select_lex= lex->current_select; ptr->cacheable_table= 1; if (use_index_arg) ptr->use_index=(List *) thd->memdup((gptr) use_index_arg, @@ -4702,7 +5299,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { for (TABLE_LIST *tables=(TABLE_LIST*) table_list.first ; tables ; - tables=tables->next) + tables=tables->next_local) { if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && !strcmp(ptr->db, tables->db)) @@ -4712,11 +5309,245 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, } } } - table_list.link_in_list((byte*) ptr, (byte**) &ptr->next); + /* Link table in local list (list for current select) */ + table_list.link_in_list((byte*) ptr, (byte**) &ptr->next_local); + /* Link table in global list (all used tables) */ + lex->add_to_query_tables(ptr); DBUG_RETURN(ptr); } +/* + Initialize a new table list for a nested join + + SYNOPSIS + init_table_list() + thd current thread + + DESCRIPTION + The function initializes a structure of the TABLE_LIST type + for a nested join. It sets up its nested join list as empty. + The created structure is added to the front of the current + join list in the st_select_lex object. Then the function + changes the current nest level for joins to refer to the newly + created empty list after having saved the info on the old level + in the initialized structure. + + RETURN VALUE + 0, if success + 1, otherwise +*/ + +bool st_select_lex::init_nested_join(THD *thd) +{ + TABLE_LIST *ptr; + NESTED_JOIN *nested_join; + DBUG_ENTER("init_nested_join"); + + if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))) || + !(nested_join= ptr->nested_join= + (NESTED_JOIN *) thd->calloc(sizeof(NESTED_JOIN)))) + DBUG_RETURN(1); + join_list->push_front(ptr); + ptr->embedding= embedding; + ptr->join_list= join_list; + embedding= ptr; + join_list= &nested_join->join_list; + join_list->empty(); + DBUG_RETURN(0); +} + + +/* + End a nested join table list + + SYNOPSIS + end_nested_join() + thd current thread + + DESCRIPTION + The function returns to the previous join nest level. + If the current level contains only one member, the function + moves it one level up, eliminating the nest. + + RETURN VALUE + Pointer to TABLE_LIST element added to the total table list, if success + 0, otherwise +*/ + +TABLE_LIST *st_select_lex::end_nested_join(THD *thd) +{ + TABLE_LIST *ptr; + DBUG_ENTER("end_nested_join"); + ptr= embedding; + join_list= ptr->join_list; + embedding= ptr->embedding; + NESTED_JOIN *nested_join= ptr->nested_join; + if (nested_join->join_list.elements == 1) + { + TABLE_LIST *embedded= nested_join->join_list.head(); + join_list->pop(); + embedded->join_list= join_list; + embedded->embedding= embedding; + join_list->push_front(embedded); + ptr= embedded; + } + DBUG_RETURN(ptr); +} + + +/* + Nest last join operation + + SYNOPSIS + nest_last_join() + thd current thread + + DESCRIPTION + The function nest last join operation as if it was enclosed in braces. + + RETURN VALUE + Pointer to TABLE_LIST element created for the new nested join, if success + 0, otherwise +*/ + +TABLE_LIST *st_select_lex::nest_last_join(THD *thd) +{ + TABLE_LIST *ptr; + NESTED_JOIN *nested_join; + DBUG_ENTER("nest_last_join"); + + if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))) || + !(nested_join= ptr->nested_join= + (NESTED_JOIN *) thd->calloc(sizeof(NESTED_JOIN)))) + DBUG_RETURN(0); + ptr->embedding= embedding; + ptr->join_list= join_list; + List *embedded_list= &nested_join->join_list; + embedded_list->empty(); + for (int i=0; i < 2; i++) + { + TABLE_LIST *table= join_list->pop(); + table->join_list= embedded_list; + table->embedding= ptr; + embedded_list->push_back(table); + } + join_list->push_front(ptr); + nested_join->used_tables= nested_join->not_null_tables= (table_map) 0; + DBUG_RETURN(ptr); +} + + +/* + Save names for a join with using clause + + SYNOPSIS + save_names_for_using_list + tab1 left table in join + tab2 right table in join + + DESCRIPTION + The function saves the full names of the tables in st_select_lex + to be able to build later an on expression to replace the using clause. + + RETURN VALUE + None +*/ + +void st_select_lex::save_names_for_using_list(TABLE_LIST *tab1, + TABLE_LIST *tab2) +{ + while (tab1->nested_join) + { + tab1= tab1->nested_join->join_list.head(); + } + db1= tab1->db; + table1= tab1->alias; + while (tab2->nested_join) + { + TABLE_LIST *next; + List_iterator_fast it(tab2->nested_join->join_list); + tab2= it++; + while ((next= it++)) + tab2= next; + } + db2= tab2->db; + table2= tab2->alias; +} + + +/* + Add a table to the current join list + + SYNOPSIS + add_joined_table() + table the table to add + + DESCRIPTION + The function puts a table in front of the current join list + of st_select_lex object. + Thus, joined tables are put into this list in the reverse order + (the most outer join operation follows first). + + RETURN VALUE + None +*/ + +void st_select_lex::add_joined_table(TABLE_LIST *table) +{ + DBUG_ENTER("add_joined_table"); + join_list->push_front(table); + table->join_list= join_list; + table->embedding= embedding; + DBUG_VOID_RETURN; +} + + +/* + Convert a right join into equivalent left join + + SYNOPSIS + convert_right_join() + thd current thread + + DESCRIPTION + The function takes the current join list t[0],t[1] ... and + effectively converts it into the list t[1],t[0] ... + Although the outer_join flag for the new nested table contains + JOIN_TYPE_RIGHT, it will be handled as the inner table of a left join + operation. + + EXAMPLES + SELECT * FROM t1 RIGHT JOIN t2 ON on_expr => + SELECT * FROM t2 LEFT JOIN t1 ON on_expr + + SELECT * FROM t1,t2 RIGHT JOIN t3 ON on_expr => + SELECT * FROM t1,t3 LEFT JOIN t2 ON on_expr + + SELECT * FROM t1,t2 RIGHT JOIN (t3,t4) ON on_expr => + SELECT * FROM t1,(t3,t4) LEFT JOIN t2 ON on_expr + + SELECT * FROM t1 LEFT JOIN t2 ON on_expr1 RIGHT JOIN t3 ON on_expr2 => + SELECT * FROM t3 LEFT JOIN (t1 LEFT JOIN t2 ON on_expr2) ON on_expr1 + + RETURN + Pointer to the table representing the inner table, if success + 0, otherwise +*/ + +TABLE_LIST *st_select_lex::convert_right_join() +{ + TABLE_LIST *tab2= join_list->pop(); + TABLE_LIST *tab1= join_list->pop(); + DBUG_ENTER("convert_right_join"); + + join_list->push_front(tab2); + join_list->push_front(tab1); + tab1->outer_join|= JOIN_TYPE_RIGHT; + + DBUG_RETURN(tab1); +} + /* Set lock for all tables in current select level @@ -4737,9 +5568,9 @@ void st_select_lex::set_lock_for_tables(thr_lock_type lock_type) DBUG_PRINT("enter", ("lock_type: %d for_update: %d", lock_type, for_update)); - for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first ; - tables ; - tables=tables->next) + for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first; + tables; + tables= tables->next_local) { tables->lock_type= lock_type; tables->updating= for_update; @@ -4756,7 +5587,7 @@ void add_join_on(TABLE_LIST *b,Item *expr) b->on_expr=expr; else { - // This only happens if you have both a right and left join + /* This only happens if you have both a right and left join */ b->on_expr=new Item_cond_and(b->on_expr,expr); } b->on_expr->top_level_item(); @@ -4771,7 +5602,7 @@ void add_join_on(TABLE_LIST *b,Item *expr) add_join_natural() a Table to do normal join with b Do normal join with this table - + IMPLEMENTATION This function just marks that table b should be joined with a. The function setup_cond() will create in b->on_expr a list @@ -4836,7 +5667,6 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, */ tmp_write_to_binlog= 0; mysql_log.new_file(1); - mysql_update_log.new_file(1); mysql_bin_log.new_file(1); mysql_slow_log.new_file(1); #ifdef HAVE_REPLICATION @@ -4859,7 +5689,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, if (options & REFRESH_QUERY_CACHE_FREE) { query_cache.pack(); // FLUSH QUERY CACHE - options &= ~REFRESH_QUERY_CACHE; //don't flush all cache, just free memory + options &= ~REFRESH_QUERY_CACHE; // Don't flush cache, just free memory } if (options & (REFRESH_TABLES | REFRESH_QUERY_CACHE)) { @@ -4939,7 +5769,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, This is written such that we have a short lock on LOCK_thread_count */ -void kill_one_thread(THD *thd, ulong id) +void kill_one_thread(THD *thd, ulong id, bool only_kill_query) { THD *tmp; uint error=ER_NO_SUCH_THREAD; @@ -4959,7 +5789,7 @@ void kill_one_thread(THD *thd, ulong id) if ((thd->master_access & SUPER_ACL) || !strcmp(thd->user,tmp->user)) { - tmp->awake(1 /*prepare to die*/); + tmp->awake(only_kill_query ? THD::KILL_QUERY : THD::KILL_CONNECTION); error=0; } else @@ -4993,6 +5823,13 @@ static void refresh_status(void) (char*) &dflt_key_cache_var)); *(ulong*) value= 0; } + else if (ptr->type == SHOW_LONG_STATUS) + { + THD *thd= current_thd; + /* We must update the global status before cleaning up the thread */ + add_to_status(&global_status_var, &thd->status_var); + bzero((char*) &thd->status_var, sizeof(thd->status_var)); + } } pthread_mutex_unlock(&LOCK_status); } @@ -5137,7 +5974,6 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys) List fields; ALTER_INFO alter_info; alter_info.flags= ALTER_ADD_INDEX; - alter_info.is_simple= 0; HA_CREATE_INFO create_info; DBUG_ENTER("mysql_create_index"); bzero((char*) &create_info,sizeof(create_info)); @@ -5161,7 +5997,6 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) create_info.default_table_charset= thd->variables.collation_database; alter_info->clear(); alter_info->flags= ALTER_DROP_INDEX; - alter_info->is_simple= 0; DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name, &create_info, table_list, fields, keys, 0, (ORDER*)0, @@ -5175,7 +6010,7 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) SYNOPSIS multi_update_precheck() thd Thread handler - tables Global table list + tables Global/local table list (have to be the same) RETURN VALUE 0 OK @@ -5185,12 +6020,11 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info) int multi_update_precheck(THD *thd, TABLE_LIST *tables) { - DBUG_ENTER("multi_update_precheck"); const char *msg= 0; TABLE_LIST *table; LEX *lex= thd->lex; SELECT_LEX *select_lex= &lex->select_lex; - TABLE_LIST *update_list= (TABLE_LIST*)select_lex->table_list.first; + DBUG_ENTER("multi_update_precheck"); if (select_lex->item_list.elements != lex->value_list.elements) { @@ -5201,7 +6035,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) Ensure that we have UPDATE or SELECT privilege for each table The exact privilege is checked in mysql_multi_update() */ - for (table= update_list; table; table= table->next) + for (table= tables; table; table= table->next_local) { if (table->derived) table->grant.privilege= SELECT_ACL; @@ -5209,17 +6043,12 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) &table->grant.privilege, 0, 1) || grant_option && check_grant(thd, UPDATE_ACL, table, 0, 1, 1)) && - (check_access(thd, SELECT_ACL, table->db, - &table->grant.privilege, 0, 0) || - grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0))) + (check_access(thd, SELECT_ACL, table->db, + &table->grant.privilege, 0, 0) || + grant_option && check_grant(thd, SELECT_ACL, table, 0, 1, 0))) DBUG_RETURN(1); - /* - We assign following flag only to copy of table, because it will - be checked only if query contains subqueries i.e. only if copy exists - */ - if (table->table_list) - table->table_list->table_in_update_from_clause= 1; + table->table_in_first_from_clause= 1; } /* Is there tables of subqueries? @@ -5227,19 +6056,9 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) if (&lex->select_lex != lex->all_selects_list) { DBUG_PRINT("info",("Checking sub query list")); - for (table= tables; table; table= table->next) + for (table= tables; table; table= table->next_global) { - if (table->table_in_update_from_clause) - { - /* - If we check table by local TABLE_LIST copy then we should copy - grants to global table list, because it will be used for table - opening. - */ - if (table->table_list) - table->grant= table->table_list->grant; - } - else if (!table->derived) + if (!table->table_in_first_from_clause && table->derived) { if (check_access(thd, SELECT_ACL, table->db, &table->grant.privilege, 0, 0) || @@ -5268,7 +6087,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) SYNOPSIS multi_delete_precheck() thd Thread handler - tables Global table list + tables Global/local table list table_count Pointer to table counter RETURN VALUE @@ -5278,12 +6097,11 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) */ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) { - DBUG_ENTER("multi_delete_precheck"); SELECT_LEX *select_lex= &thd->lex->select_lex; TABLE_LIST *aux_tables= (TABLE_LIST *)thd->lex->auxilliary_table_list.first; - TABLE_LIST *delete_tables= (TABLE_LIST *)select_lex->table_list.first; TABLE_LIST *target_tbl; + DBUG_ENTER("multi_delete_precheck"); *table_count= 0; @@ -5298,12 +6116,12 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); DBUG_RETURN(-1); } - for (target_tbl= aux_tables; target_tbl; target_tbl= target_tbl->next) + for (target_tbl= aux_tables; target_tbl; target_tbl= target_tbl->next_local) { (*table_count)++; /* All tables in aux_tables must be found in FROM PART */ TABLE_LIST *walk; - for (walk= delete_tables; walk; walk= walk->next) + for (walk= tables; walk; walk= walk->next_local) { if (!my_strcasecmp(table_alias_charset, target_tbl->alias, walk->alias) && @@ -5316,14 +6134,8 @@ int multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) "MULTI DELETE"); DBUG_RETURN(-1); } - if (walk->derived) - { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), target_tbl->real_name, - "DELETE"); - DBUG_RETURN(-1); - } walk->lock_type= target_tbl->lock_type; - target_tbl->table_list= walk; // Remember corresponding table + target_tbl->correspondent_table= walk; // Remember corresponding table } DBUG_RETURN(0); } @@ -5427,9 +6239,9 @@ int insert_precheck(THD *thd, TABLE_LIST *tables) LEX *lex= thd->lex; DBUG_ENTER("insert_precheck"); - ulong privilege= INSERT_ACL | - (lex->duplicates == DUP_REPLACE ? DELETE_ACL : 0) | - (lex->duplicates == DUP_UPDATE ? UPDATE_ACL : 0); + ulong privilege= (INSERT_ACL | + (lex->duplicates == DUP_REPLACE ? DELETE_ACL : 0) | + (lex->value_list.elements ? UPDATE_ACL : 0)); if (check_one_table_access(thd, privilege, tables)) DBUG_RETURN(1); @@ -5484,33 +6296,24 @@ int create_table_precheck(THD *thd, TABLE_LIST *tables, /* Check permissions for used tables in CREATE TABLE ... SELECT */ /* - For temporary tables or PREPARED STATEMETNS we don't have to check - if the created table exists + Only do the check for PS, becasue we on execute we have to check that + against the opened tables to ensure we don't use a table that is part + of the view (which can only be done after the table has been opened). */ - if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && - ! thd->current_arena->is_stmt_prepare() && - find_real_table_in_list(tables, create_table->db, - create_table->real_name)) + if (thd->current_arena->is_stmt_prepare()) { - net_printf(thd,ER_UPDATE_TABLE_USED, create_table->real_name); - - goto err; - } - if (lex->create_info.used_fields & HA_CREATE_USED_UNION) - { - TABLE_LIST *tab; - for (tab= tables; tab; tab= tab->next) + /* + For temporary tables we don't have to check if the created table exists + */ + if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && + find_table_in_global_list(tables, create_table->db, + create_table->real_name)) { - if (find_real_table_in_list((TABLE_LIST*) lex->create_info. - merge_list.first, - tables->db, tab->real_name)) - { - net_printf(thd, ER_UPDATE_TABLE_USED, tab->real_name); - goto err; - } - } - } + net_printf(thd,ER_UPDATE_TABLE_USED, create_table->real_name); + goto err; + } + } if (tables && check_table_access(thd, SELECT_ACL, tables,0)) goto err; } @@ -5526,7 +6329,7 @@ err: SYNOPSIS negate_expression() - thd therad handler + thd thread handler expr expression for negation RETURN diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d842b4b66bb..fe5ce7640ea 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -35,6 +35,10 @@ #include "sql_acl.h" #include "lex_symbol.h" #include "item_create.h" +#include "sp_head.h" +#include "sp_pcontext.h" +#include "sp_rcontext.h" +#include "sp.h" #include #include @@ -83,10 +87,14 @@ inline Item *or_or_concat(THD *thd, Item* A, Item* B) enum Item_udftype udf_type; CHARSET_INFO *charset; thr_lock_type lock_type; - interval_type interval; + interval_type interval, interval_time_st; timestamp_type date_time_type; st_select_lex *select_lex; chooser_compare_func_creator boolfunc2creator; + struct sp_cond_type *spcondtype; + struct { int vars, conds, hndlrs, curs; } spblock; + sp_name *spname; + struct st_lex *lex; } %{ @@ -127,6 +135,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token AVG_SYM %token BEGIN_SYM %token BINLOG_SYM +%token CALL_SYM %token CHANGE %token CLIENT_SYM %token COMMENT_SYM @@ -136,7 +145,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token CREATE %token CROSS %token CUBE_SYM +%token DEFINER_SYM %token DELETE_SYM +%token DETERMINISTIC_SYM %token DUAL_SYM %token DO_SYM %token DROP @@ -167,6 +178,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SHOW %token SLAVE %token SNAPSHOT_SYM +%token SQL_SYM %token SQL_THREAD %token START_SYM %token STD_SYM @@ -182,6 +194,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token ACTION %token AGGREGATE_SYM +%token ALGORITHM_SYM %token ALL %token AND_SYM %token AS @@ -200,6 +213,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token BYTE_SYM %token CACHE_SYM %token CASCADE +%token CASCADED %token CAST_SYM %token CHARSET %token CHECKSUM_SYM @@ -210,11 +224,16 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token COLUMNS %token COLUMN_SYM %token CONCURRENT +%token CONDITION_SYM +%token CONNECTION_SYM %token CONSTRAINT +%token CONTAINS_SYM +%token CONTINUE_SYM %token CONVERT_SYM %token CURRENT_USER %token DATABASES %token DATA_SYM +%token DECLARE_SYM %token DEFAULT %token DELAYED_SYM %token DELAY_KEY_WRITE_SYM @@ -226,20 +245,24 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token DISTINCT %token DUPLICATE_SYM %token DYNAMIC_SYM +%token EACH_SYM %token ENABLE_SYM %token ENCLOSED %token ESCAPED %token DIRECTORY_SYM %token ESCAPE_SYM %token EXISTS +%token EXIT_SYM %token EXTENDED_SYM %token FALSE_SYM +%token FETCH_SYM %token FILE_SYM %token FIRST_SYM %token FIXED_SYM %token FLOAT_NUM %token FORCE_SYM %token FOREIGN +%token FOUND_SYM %token FROM %token FULL %token FULLTEXT_SYM @@ -262,8 +285,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token INFILE %token INNER_SYM %token INNOBASE_SYM +%token INOUT_SYM %token INTO %token IN_SYM +%token INVOKER_SYM %token ISOLATION %token JOIN_SYM %token KEYS @@ -273,14 +298,17 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token LEAVES %token LEVEL_SYM %token LEX_HOSTNAME +%token LANGUAGE_SYM %token LIKE %token LINES %token LOCAL_SYM +%token LOCATOR_SYM %token LOG_SYM %token LOGS_SYM %token LONG_NUM %token LONG_SYM %token LOW_PRIORITY +%token MERGE_SYM %token MASTER_HOST_SYM %token MASTER_USER_SYM %token MASTER_LOG_FILE_SYM @@ -305,6 +333,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token MEDIUM_SYM %token MIN_ROWS %token NAMES_SYM +%token NAME_SYM %token NATIONAL_SYM %token NATURAL %token NDBCLUSTER_SYM @@ -325,6 +354,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token OR_SYM %token OR_OR_CONCAT %token ORDER_SYM +%token OUT_SYM %token OUTER %token OUTFILE %token DUMPFILE @@ -341,6 +371,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token RAID_CHUNKS %token RAID_CHUNKSIZE %token READ_SYM +%token READS_SYM %token REAL_NUM %token REFERENCES %token REGEXP @@ -356,6 +387,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token ROW_FORMAT_SYM %token ROW_SYM %token RTREE_SYM +%token SECURITY_SYM %token SET %token SEPARATOR_SYM %token SERIAL_SYM @@ -364,6 +396,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SIMPLE_SYM %token SHUTDOWN %token SPATIAL_SYM +%token SPECIFIC_SYM +%token SQLEXCEPTION_SYM +%token SQLSTATE_SYM +%token SQLWARNING_SYM %token SSL_SYM %token STARTING %token STATUS_SYM @@ -374,11 +410,13 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token TABLE_SYM %token TABLESPACE %token TEMPORARY +%token TEMPTABLE_SYM %token TERMINATED %token TEXT_STRING %token TO_SYM %token TRAILING %token TRANSACTION_SYM +%token TRIGGER_SYM %token TRUE_SYM %token TYPE_SYM %token TYPES_SYM @@ -386,11 +424,15 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token FUNC_ARG1 %token FUNC_ARG2 %token FUNC_ARG3 -%token UDF_RETURNS_SYM +%token RETURN_SYM +%token RETURNS_SYM %token UDF_SONAME_SYM -%token UDF_SYM +%token UDF_RETURNS_SYM +%token FUNCTION_SYM %token UNCOMMITTED_SYM +%token UNDEFINED_SYM %token UNDERSCORE_CHARSET +%token UNDO_SYM %token UNICODE_SYM %token UNION_SYM %token UNIQUE_SYM @@ -401,6 +443,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token VALUE_SYM %token VALUES %token VARIABLES +%token VIEW_SYM %token WHERE %token WITH %token WRITE_SYM @@ -408,6 +451,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token X509_SYM %token XOR %token COMPRESSED_SYM +%token ROW_COUNT_SYM %token ERRORS %token WARNINGS @@ -444,6 +488,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token STRING_SYM %token TEXT_SYM %token TIMESTAMP +%token TIMESTAMP_ADD +%token TIMESTAMP_DIFF %token TIME_SYM %token TINYBLOB %token TINYINT @@ -490,6 +536,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token FIELD_FUNC %token FORMAT_SYM %token FOR_SYM +%token FRAC_SECOND_SYM %token FROM_UNIXTIME %token GEOMCOLLFROMTEXT %token GEOMFROMTEXT @@ -518,6 +565,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token MINUTE_SECOND_SYM %token MINUTE_SYM %token MODE_SYM +%token MODIFIES_SYM %token MODIFY_SYM %token MONTH_SYM %token MLINEFROMTEXT @@ -535,6 +583,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token POLYGON %token POSITION_SYM %token PROCEDURE +%token QUARTER_SYM %token RAND %token REPLACE %token RIGHT @@ -546,12 +595,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SUBSTRING %token SUBSTRING_INDEX %token TRIM -%token UDA_CHAR_SUM -%token UDA_FLOAT_SUM -%token UDA_INT_SUM -%token UDF_CHAR_FUNC -%token UDF_FLOAT_FUNC -%token UDF_INT_FUNC %token UNIQUE_USERS %token UNIX_TIMESTAMP %token USER @@ -575,6 +618,20 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SQL_SMALL_RESULT %token SQL_BUFFER_RESULT +%token CURSOR_SYM +%token ELSEIF_SYM +%token ITERATE_SYM +%token GOTO_SYM +%token LABEL_SYM +%token LEAVE_SYM +%token LOOP_SYM +%token REPEAT_SYM +%token UNTIL_SYM +%token WHILE_SYM +%token ASENSITIVE_SYM +%token INSENSITIVE_SYM +%token SENSITIVE_SYM + %token ISSUER_SYM %token SUBJECT_SYM %token CIPHER_SYM @@ -600,6 +657,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); LEX_HOSTNAME ULONGLONG_NUM field_ident select_alias ident ident_or_text UNDERSCORE_CHARSET IDENT_sys TEXT_STRING_sys TEXT_STRING_literal NCHAR_STRING opt_component key_cache_name + sp_opt_label %type opt_table_alias @@ -634,17 +692,20 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %type literal text_literal insert_ident order_ident simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr - table_wild no_in_expr expr_expr simple_expr no_and_expr + table_wild no_in_expr expr_expr simple_expr no_and_expr udf_expr using_list expr_or_default set_expr_or_default interval_expr param_marker singlerow_subselect singlerow_subselect_init exists_subselect exists_subselect_init geometry_function signed_literal now_or_signed_literal opt_escape + sp_opt_default + simple_ident_nospvar simple_ident_q %type NUM_literal %type - expr_list udf_expr_list when_list ident_list ident_list_arg + expr_list udf_expr_list udf_expr_list2 when_list + ident_list ident_list_arg %type key_type opt_unique_or_fulltext constraint_key_type @@ -660,14 +721,13 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %type join_table_list join_table - -%type - UDF_CHAR_FUNC UDF_FLOAT_FUNC UDF_INT_FUNC - UDA_CHAR_SUM UDA_FLOAT_SUM UDA_INT_SUM + table_factor table_ref %type date_time_type; %type interval +%type interval_time_st + %type storage_engines %type row_types @@ -711,7 +771,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); select_item_list select_item values_list no_braces opt_limit_clause delete_limit_clause fields opt_values values procedure_list procedure_list2 procedure_item - when_list2 expr_list2 handler + when_list2 expr_list2 udf_expr_list3 handler opt_precision opt_ignore opt_column opt_restrict grant revoke set lock unlock string_list field_options field_option field_opt_list opt_binary table_lock_list table_lock @@ -732,8 +792,17 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); subselect_end select_var_list select_var_list_init help opt_len opt_extended_describe prepare prepare_src execute deallocate + statement sp_suid opt_view_list view_list or_replace algorithm + sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic END_OF_INPUT +%type call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt +%type sp_decl_idents sp_opt_inout sp_handler_type sp_hcond_list +%type sp_cond sp_hcond +%type sp_decls sp_decl +%type sp_cursor_stmt +%type sp_name + %type '-' '+' '*' '/' '%' '(' ')' ',' '!' '{' '}' '&' '|' AND_SYM OR_SYM OR_OR_CONCAT BETWEEN_SYM CASE_SYM @@ -759,10 +828,16 @@ query: | verb_clause END_OF_INPUT {}; verb_clause: + statement + | begin + ; + +/* Verb clauses, except begin */ +statement: alter | analyze | backup - | begin + | call | change | check | checksum @@ -1063,19 +1138,1267 @@ create: lex->name=$4.str; lex->create_info.options=$3; } - | CREATE udf_func_type UDF_SYM IDENT_sys + | CREATE udf_func_type FUNCTION_SYM sp_name + { + LEX *lex=Lex; + lex->spname= $4; + lex->udf.type= $2; + } + create_function_tail + {} + | CREATE PROCEDURE sp_name + { + LEX *lex= Lex; + sp_head *sp; + + if (lex->sphead) + { + net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "PROCEDURE"); + YYABORT; + } + /* Order is important here: new - reset - init */ + sp= new sp_head(); + sp->reset_thd_mem_root(YYTHD); + sp->init(lex); + + sp->m_type= TYPE_ENUM_PROCEDURE; + lex->sphead= sp; + /* + * We have to turn of CLIENT_MULTI_QUERIES while parsing a + * stored procedure, otherwise yylex will chop it into pieces + * at each ';'. + */ + sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES; + YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES); + } + '(' + { + LEX *lex= Lex; + + lex->sphead->m_param_begin= lex->tok_start+1; + } + sp_pdparam_list + ')' + { + LEX *lex= Lex; + + lex->sphead->m_param_end= lex->tok_start; + bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); + } + sp_c_chistics + { + LEX *lex= Lex; + + lex->sphead->m_chistics= &lex->sp_chistics; + lex->sphead->m_body_begin= lex->tok_start; + } + sp_proc_stmt + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + if (sp->check_backpatch(YYTHD)) + YYABORT; + sp->init_strings(YYTHD, lex, $3); + lex->sql_command= SQLCOM_CREATE_PROCEDURE; + /* Restore flag if it was cleared above */ + if (sp->m_old_cmq) + YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES; + sp->restore_thd_mem_root(YYTHD); + } + | CREATE or_replace algorithm VIEW_SYM table_ident + { + THD *thd= YYTHD; + LEX *lex= thd->lex; + lex->sql_command= SQLCOM_CREATE_VIEW; + lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; + /* first table in list is target VIEW name */ + if (!lex->select_lex.add_table_to_list(thd, $5, NULL, 0)) + YYABORT; + } + opt_view_list AS select_init check_option + {} + | CREATE TRIGGER_SYM ident trg_action_time trg_event + ON table_ident FOR_SYM EACH_SYM ROW_SYM + { + LEX *lex= Lex; + sp_head *sp; + + if (lex->sphead) + { + net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "TRIGGER"); + YYABORT; + } + + sp= new sp_head(); + sp->reset_thd_mem_root(YYTHD); + sp->init(lex); + + sp->m_type= TYPE_ENUM_TRIGGER; + lex->sphead= sp; + /* + We have to turn of CLIENT_MULTI_QUERIES while parsing a + stored procedure, otherwise yylex will chop it into pieces + at each ';'. + */ + sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES; + YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES; + + bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); + lex->sphead->m_chistics= &lex->sp_chistics; + lex->sphead->m_body_begin= lex->tok_start; + } + sp_proc_stmt + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + lex->sql_command= SQLCOM_CREATE_TRIGGER; + sp->init_strings(YYTHD, lex, NULL); + /* Restore flag if it was cleared above */ + if (sp->m_old_cmq) + YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES; + sp->restore_thd_mem_root(YYTHD); + + lex->name_and_length= $3; + + /* + We have to do it after parsing trigger body, because some of + sp_proc_stmt alternatives are not saving/restoring LEX, so + lex->query_tables can be wiped out. + + QQ: What are other consequences of this? + + QQ: Could we loosen lock type in certain cases ? + */ + if (!lex->select_lex.add_table_to_list(YYTHD, $7, + (LEX_STRING*) 0, + TL_OPTION_UPDATING, + TL_WRITE)) + YYABORT; + } + ; + +sp_name: + IDENT_sys '.' IDENT_sys + { + $$= new sp_name($1, $3); + $$->init_qname(YYTHD); + } + | IDENT_sys + { + $$= sp_name_current_db_new(YYTHD, $1); + } + ; + +create_function_tail: + RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys { LEX *lex=Lex; lex->sql_command = SQLCOM_CREATE_FUNCTION; - lex->udf.name = $4; - lex->udf.type= $2; + lex->udf.name = lex->spname->m_name; + lex->udf.returns=(Item_result) $2; + lex->udf.dl=$4.str; } - UDF_RETURNS_SYM udf_type UDF_SONAME_SYM TEXT_STRING_sys + | '(' { - LEX *lex=Lex; - lex->udf.returns=(Item_result) $7; - lex->udf.dl=$9.str; + LEX *lex= Lex; + sp_head *sp; + + if (lex->sphead) + { + net_printf(YYTHD, ER_SP_NO_RECURSIVE_CREATE, "FUNCTION"); + YYABORT; + } + /* Order is important here: new - reset - init */ + sp= new sp_head(); + sp->reset_thd_mem_root(YYTHD); + sp->init(lex); + + sp->m_type= TYPE_ENUM_FUNCTION; + lex->sphead= sp; + /* + * We have to turn of CLIENT_MULTI_QUERIES while parsing a + * stored procedure, otherwise yylex will chop it into pieces + * at each ';'. + */ + sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES; + YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES; + lex->sphead->m_param_begin= lex->tok_start+1; } + sp_fdparam_list ')' + { + LEX *lex= Lex; + + lex->sphead->m_param_end= lex->tok_start; + } + RETURNS_SYM + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + sp->m_returns_begin= lex->tok_start; + sp->m_returns_cs= lex->charset= NULL; + } + type + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + sp->m_returns_end= lex->tok_start; + sp->m_returns= (enum enum_field_types)$8; + sp->m_returns_cs= lex->charset; + bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); + } + sp_c_chistics + { + LEX *lex= Lex; + + lex->sphead->m_chistics= &lex->sp_chistics; + lex->sphead->m_body_begin= lex->tok_start; + } + sp_proc_stmt + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + if (sp->check_backpatch(YYTHD)) + YYABORT; + lex->sql_command= SQLCOM_CREATE_SPFUNCTION; + sp->init_strings(YYTHD, lex, lex->spname); + /* Restore flag if it was cleared above */ + if (sp->m_old_cmq) + YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES; + sp->restore_thd_mem_root(YYTHD); + } + ; + +sp_a_chistics: + /* Empty */ {} + | sp_a_chistics sp_chistic {} + ; + +sp_c_chistics: + /* Empty */ {} + | sp_c_chistics sp_c_chistic {} + ; + +/* Characteristics for both create and alter */ +sp_chistic: + COMMENT_SYM TEXT_STRING_sys + { Lex->sp_chistics.comment= $2; } + | LANGUAGE_SYM SQL_SYM + { /* Just parse it, we only have one language for now. */ } + | NO_SYM SQL_SYM + { Lex->sp_chistics.daccess= SP_NO_SQL; } + | CONTAINS_SYM SQL_SYM + { Lex->sp_chistics.daccess= SP_CONTAINS_SQL; } + | READS_SYM SQL_SYM DATA_SYM + { Lex->sp_chistics.daccess= SP_READS_SQL_DATA; } + | MODIFIES_SYM SQL_SYM DATA_SYM + { Lex->sp_chistics.daccess= SP_MODIFIES_SQL_DATA; } + | sp_suid + { } + ; + +/* Create characteristics */ +sp_c_chistic: + sp_chistic { } + | DETERMINISTIC_SYM { Lex->sp_chistics.detistic= TRUE; } + | NOT DETERMINISTIC_SYM { Lex->sp_chistics.detistic= FALSE; } + ; + +sp_suid: + SQL_SYM SECURITY_SYM DEFINER_SYM + { + Lex->sp_chistics.suid= SP_IS_SUID; + } + | SQL_SYM SECURITY_SYM INVOKER_SYM + { + Lex->sp_chistics.suid= SP_IS_NOT_SUID; + } + ; + +call: + CALL_SYM sp_name + { + LEX *lex = Lex; + + lex->sql_command= SQLCOM_CALL; + lex->spname= $2; + lex->value_list.empty(); + } + '(' sp_cparam_list ')' {} + ; + +/* CALL parameters */ +sp_cparam_list: + /* Empty */ + | sp_cparams + ; + +sp_cparams: + sp_cparams ',' expr + { + Lex->value_list.push_back($3); + } + | expr + { + Lex->value_list.push_back($1); + } + ; + +/* Stored FUNCTION parameter declaration list */ +sp_fdparam_list: + /* Empty */ + | sp_fdparams + ; + +sp_fdparams: + sp_fdparams ',' sp_fdparam + | sp_fdparam + ; + +sp_fdparam: + ident type + { + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + + if (spc->find_pvar(&$1, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_PARAM, $1.str); + YYABORT; + } + spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in); + } + ; + +/* Stored PROCEDURE parameter declaration list */ +sp_pdparam_list: + /* Empty */ + | sp_pdparams + ; + +sp_pdparams: + sp_pdparams ',' sp_pdparam + | sp_pdparam + ; + +sp_pdparam: + sp_opt_inout ident type + { + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + + if (spc->find_pvar(&$2, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_PARAM, $2.str); + YYABORT; + } + spc->push_pvar(&$2, (enum enum_field_types)$3, + (sp_param_mode_t)$1); + } + ; + +sp_opt_inout: + /* Empty */ { $$= sp_param_in; } + | IN_SYM { $$= sp_param_in; } + | OUT_SYM { $$= sp_param_out; } + | INOUT_SYM { $$= sp_param_inout; } + ; + +sp_proc_stmts: + /* Empty */ {} + | sp_proc_stmts { Lex->query_tables= 0; } sp_proc_stmt ';' + ; + +sp_proc_stmts1: + sp_proc_stmt ';' {} + | sp_proc_stmts1 { Lex->query_tables= 0; } sp_proc_stmt ';' + ; + +sp_decls: + /* Empty */ + { + $$.vars= $$.conds= $$.hndlrs= $$.curs= 0; + } + | sp_decls sp_decl ';' + { + /* We check for declarations out of (standard) order this way + because letting the grammar rules reflect it caused tricky + shift/reduce conflicts with the wrong result. (And we get + better error handling this way.) */ + if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs)) + { /* Variable or condition following cursor or handler */ + send_error(YYTHD, ER_SP_VARCOND_AFTER_CURSHNDLR); + YYABORT; + } + if ($2.curs && $1.hndlrs) + { /* Cursor following handler */ + send_error(YYTHD, ER_SP_CURSOR_AFTER_HANDLER); + YYABORT; + } + $$.vars= $1.vars + $2.vars; + $$.conds= $1.conds + $2.conds; + $$.hndlrs= $1.hndlrs + $2.hndlrs; + $$.curs= $1.curs + $2.curs; + } + ; + +sp_decl: + DECLARE_SYM sp_decl_idents type sp_opt_default + { + LEX *lex= Lex; + sp_pcontext *ctx= lex->spcont; + uint max= ctx->context_pvars(); + enum enum_field_types type= (enum enum_field_types)$3; + Item *it= $4; + + for (uint i = max-$2 ; i < max ; i++) + { + ctx->set_type(i, type); + if (! it) + ctx->set_isset(i, FALSE); + else + { + sp_instr_set *in= new sp_instr_set(lex->sphead->instructions(), + ctx, + ctx->pvar_context2index(i), + it, type); + + in->tables= lex->query_tables; + lex->query_tables= 0; + lex->sphead->add_instr(in); + ctx->set_isset(i, TRUE); + ctx->set_default(i, it); + } + } + $$.vars= $2; + $$.conds= $$.hndlrs= $$.curs= 0; + } + | DECLARE_SYM ident CONDITION_SYM FOR_SYM sp_cond + { + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + + if (spc->find_cond(&$2, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_COND, $2.str); + YYABORT; + } + YYTHD->lex->spcont->push_cond(&$2, $5); + $$.vars= $$.hndlrs= $$.curs= 0; + $$.conds= 1; + } + | DECLARE_SYM sp_handler_type HANDLER_SYM FOR_SYM + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + sp_instr_hpush_jump *i= + new sp_instr_hpush_jump(sp->instructions(), ctx, $2, + ctx->current_pvars()); + + sp->add_instr(i); + sp->push_backpatch(i, ctx->push_label((char *)"", 0)); + ctx->add_handler(); + sp->m_in_handler= TRUE; + } + sp_hcond_list sp_proc_stmt + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + sp_label_t *hlab= lex->spcont->pop_label(); /* After this hdlr */ + sp_instr_hreturn *i; + + if ($2 == SP_HANDLER_CONTINUE) + { + i= new sp_instr_hreturn(sp->instructions(), ctx, + ctx->current_pvars()); + sp->add_instr(i); + } + else + { /* EXIT or UNDO handler, just jump to the end of the block */ + i= new sp_instr_hreturn(sp->instructions(), ctx, 0); + + sp->add_instr(i); + sp->push_backpatch(i, lex->spcont->last_label()); /* Block end */ + } + lex->sphead->backpatch(hlab); + sp->m_in_handler= FALSE; + $$.vars= $$.conds= $$.curs= 0; + $$.hndlrs= $6; + } + | DECLARE_SYM ident CURSOR_SYM FOR_SYM sp_cursor_stmt + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + uint offp; + sp_instr_cpush *i; + + if (ctx->find_cursor(&$2, &offp, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_CURS, $2.str); + delete $5; + YYABORT; + } + i= new sp_instr_cpush(sp->instructions(), ctx, $5); + sp->add_instr(i); + ctx->push_cursor(&$2); + $$.vars= $$.conds= $$.hndlrs= 0; + $$.curs= 1; + } + ; + +sp_cursor_stmt: + { + Lex->sphead->reset_lex(YYTHD); + + /* We use statement here just be able to get a better + error message. Using 'select' works too, but will then + result in a generic "syntax error" if a non-select + statement is given. */ + } + statement + { + LEX *lex= Lex; + + if (lex->sql_command != SQLCOM_SELECT) + { + send_error(YYTHD, ER_SP_BAD_CURSOR_QUERY); + YYABORT; + } + if (lex->result) + { + send_error(YYTHD, ER_SP_BAD_CURSOR_SELECT); + YYABORT; + } + lex->sp_lex_in_use= TRUE; + $$= lex; + lex->sphead->restore_lex(YYTHD); + } + ; + +sp_handler_type: + EXIT_SYM { $$= SP_HANDLER_EXIT; } + | CONTINUE_SYM { $$= SP_HANDLER_CONTINUE; } +/* | UNDO_SYM { QQ No yet } */ + ; + +sp_hcond_list: + sp_hcond + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction(); + + i->add_condition($1); + $$= 1; + } + | sp_hcond_list ',' sp_hcond + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_instr_hpush_jump *i= (sp_instr_hpush_jump *)sp->last_instruction(); + + i->add_condition($3); + $$= $1 + 1; + } + ; + +sp_cond: + ULONG_NUM + { /* mysql errno */ + $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t)); + $$->type= sp_cond_type_t::number; + $$->mysqlerr= $1; + } + | SQLSTATE_SYM opt_value TEXT_STRING_literal + { /* SQLSTATE */ + uint len= ($3.length < sizeof($$->sqlstate)-1 ? + $3.length : sizeof($$->sqlstate)-1); + + $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t)); + $$->type= sp_cond_type_t::state; + memcpy($$->sqlstate, $3.str, len); + $$->sqlstate[len]= '\0'; + } + ; + +opt_value: + /* Empty */ {} + | VALUE_SYM {} + ; + +sp_hcond: + sp_cond + { + $$= $1; + } + | ident /* CONDITION name */ + { + $$= Lex->spcont->find_cond(&$1); + if ($$ == NULL) + { + net_printf(YYTHD, ER_SP_COND_MISMATCH, $1.str); + YYABORT; + } + } + | SQLWARNING_SYM /* SQLSTATEs 01??? */ + { + $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t)); + $$->type= sp_cond_type_t::warning; + } + | NOT FOUND_SYM /* SQLSTATEs 02??? */ + { + $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t)); + $$->type= sp_cond_type_t::notfound; + } + | SQLEXCEPTION_SYM /* All other SQLSTATEs */ + { + $$= (sp_cond_type_t *)YYTHD->alloc(sizeof(sp_cond_type_t)); + $$->type= sp_cond_type_t::exception; + } + ; + +sp_decl_idents: + ident + { + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + + if (spc->find_pvar(&$1, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_VAR, $1.str); + YYABORT; + } + spc->push_pvar(&$1, (enum_field_types)0, sp_param_in); + $$= 1; + } + | sp_decl_idents ',' ident + { + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + + if (spc->find_pvar(&$3, TRUE)) + { + net_printf(YYTHD, ER_SP_DUP_VAR, $3.str); + YYABORT; + } + spc->push_pvar(&$3, (enum_field_types)0, sp_param_in); + $$= $1 + 1; + } + ; + +sp_opt_default: + /* Empty */ { $$ = NULL; } + | DEFAULT expr { $$ = $2; } + ; + +sp_proc_stmt: + { + LEX *lex= Lex; + + lex->sphead->reset_lex(YYTHD); + lex->sphead->m_tmp_query= lex->tok_start; + } + statement + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + + if ((lex->sql_command == SQLCOM_SELECT && !lex->result) || + sp_multi_results_command(lex->sql_command)) + { + /* We maybe have one or more SELECT without INTO */ + sp->m_multi_results= TRUE; + } + if (lex->sql_command == SQLCOM_CHANGE_DB) + { /* "USE db" doesn't work in a procedure */ + send_error(YYTHD, ER_SP_NO_USE); + YYABORT; + } + /* Don't add an instruction for empty SET statements. + ** (This happens if the SET only contained local variables, + ** which get their set instructions generated separately.) + */ + if (lex->sql_command != SQLCOM_SET_OPTION || + ! lex->var_list.is_empty()) + { + /* + Currently we can't handle queries inside a FUNCTION or + TRIGGER, because of the way table locking works. This is + unfortunate, and limits the usefulness of functions and + especially triggers a tremendously, but it's nothing we + can do about this at the moment. + */ + if (sp->m_type != TYPE_ENUM_PROCEDURE) + { + send_error(YYTHD, ER_SP_BADSTATEMENT); + YYABORT; + } + else + { + sp_instr_stmt *i=new sp_instr_stmt(sp->instructions(), + lex->spcont); + + /* Extract the query statement from the tokenizer: + The end is either lex->tok_end or tok->ptr. */ + if (lex->ptr - lex->tok_end > 1) + i->m_query.length= lex->ptr - sp->m_tmp_query; + else + i->m_query.length= lex->tok_end - sp->m_tmp_query; + i->m_query.str= strmake_root(YYTHD->mem_root, + (char *)sp->m_tmp_query, + i->m_query.length); + i->set_lex(lex); + sp->add_instr(i); + lex->sp_lex_in_use= TRUE; + } + } + sp->restore_lex(YYTHD); + } + | RETURN_SYM expr + { + LEX *lex= Lex; + + if (lex->sphead->m_type == TYPE_ENUM_PROCEDURE) + { + send_error(YYTHD, ER_SP_BADRETURN); + YYABORT; + } + else + { + sp_instr_freturn *i; + + if ($2->type() == Item::SUBSELECT_ITEM) + { /* QQ For now, just disallow subselects as values */ + send_error(lex->thd, ER_SP_BADSTATEMENT); + YYABORT; + } + i= new sp_instr_freturn(lex->sphead->instructions(), + lex->spcont, + $2, lex->sphead->m_returns); + lex->sphead->add_instr(i); + lex->sphead->m_has_return= TRUE; + } + } + | IF sp_if END IF {} + | CASE_SYM WHEN_SYM + { + Lex->sphead->m_simple_case= FALSE; + } + sp_case END CASE_SYM {} + | CASE_SYM expr WHEN_SYM + { + /* We "fake" this by using an anonymous variable which we + set to the expression. Note that all WHENs are evaluate + at the same frame level, so we then know that it's the + top-most variable in the frame. */ + LEX *lex= Lex; + uint offset= lex->spcont->current_pvars(); + sp_instr_set *i = new sp_instr_set(lex->sphead->instructions(), + lex->spcont, + offset, $2, MYSQL_TYPE_STRING); + LEX_STRING dummy; + + dummy.str= (char *)""; + dummy.length= 0; + lex->spcont->push_pvar(&dummy, MYSQL_TYPE_STRING, sp_param_in); + i->tables= lex->query_tables; + lex->query_tables= 0; + lex->sphead->add_instr(i); + lex->sphead->m_simple_case= TRUE; + } + sp_case END CASE_SYM + { + Lex->spcont->pop_pvar(); + } + | sp_labeled_control + {} + | { /* Unlabeled controls get a secret label. */ + LEX *lex= Lex; + + lex->spcont->push_label((char *)"", lex->sphead->instructions()); + } + sp_unlabeled_control + { + LEX *lex= Lex; + + lex->sphead->backpatch(lex->spcont->pop_label()); + } + | LEAVE_SYM IDENT + { + LEX *lex= Lex; + sp_head *sp = lex->sphead; + sp_pcontext *ctx= lex->spcont; + sp_label_t *lab= ctx->find_label($2.str); + + if (! lab) + { + net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "LEAVE", $2.str); + YYABORT; + } + else + { + uint ip= sp->instructions(); + sp_instr_jump *i; + sp_instr_hpop *ih; + sp_instr_cpop *ic; + + ih= new sp_instr_hpop(ip++, ctx, 0); + sp->push_backpatch(ih, lab); + sp->add_instr(ih); + ic= new sp_instr_cpop(ip++, ctx, 0); + sp->push_backpatch(ic, lab); + sp->add_instr(ic); + i= new sp_instr_jump(ip, ctx); + sp->push_backpatch(i, lab); /* Jumping forward */ + sp->add_instr(i); + } + } + | ITERATE_SYM IDENT + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + sp_label_t *lab= ctx->find_label($2.str); + + if (! lab || lab->type != SP_LAB_ITER) + { + net_printf(YYTHD, ER_SP_LILABEL_MISMATCH, "ITERATE", $2.str); + YYABORT; + } + else + { + sp_instr_jump *i; + uint ip= sp->instructions(); + uint n; + + n= ctx->diff_handlers(lab->ctx); + if (n) + sp->add_instr(new sp_instr_hpop(ip++, ctx, n)); + n= ctx->diff_cursors(lab->ctx); + if (n) + sp->add_instr(new sp_instr_cpop(ip++, ctx, n)); + i= new sp_instr_jump(ip, ctx, lab->ip); /* Jump back */ + sp->add_instr(i); + } + } + | LABEL_SYM IDENT + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + sp_label_t *lab= ctx->find_label($2.str); + + if (lab) + { + net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $2.str); + YYABORT; + } + else + { + lab= ctx->push_label($2.str, sp->instructions()); + lab->type= SP_LAB_GOTO; + lab->ctx= ctx; + sp->backpatch(lab); + } + } + | GOTO_SYM IDENT + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + uint ip= lex->sphead->instructions(); + sp_label_t *lab; + sp_instr_jump *i; + sp_instr_hpop *ih; + sp_instr_cpop *ic; + + if (sp->m_in_handler) + { + send_error(lex->thd, ER_SP_GOTO_IN_HNDLR); + YYABORT; + } + lab= ctx->find_label($2.str); + if (! lab) + { + lab= (sp_label_t *)YYTHD->alloc(sizeof(sp_label_t)); + lab->name= $2.str; + lab->ip= 0; + lab->type= SP_LAB_REF; + lab->ctx= ctx; + + ih= new sp_instr_hpop(ip++, ctx, 0); + sp->push_backpatch(ih, lab); + sp->add_instr(ih); + ic= new sp_instr_cpop(ip++, ctx, 0); + sp->add_instr(ic); + sp->push_backpatch(ic, lab); + i= new sp_instr_jump(ip, ctx); + sp->push_backpatch(i, lab); /* Jumping forward */ + sp->add_instr(i); + } + else + { + uint n; + + n= ctx->diff_handlers(lab->ctx); + if (n) + { + ih= new sp_instr_hpop(ip++, ctx, n); + sp->add_instr(ih); + } + n= ctx->diff_cursors(lab->ctx); + if (n) + { + ic= new sp_instr_cpop(ip++, ctx, n); + sp->add_instr(ic); + } + i= new sp_instr_jump(ip, ctx, lab->ip); /* Jump back */ + sp->add_instr(i); + } + } + | OPEN_SYM ident + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + uint offset; + sp_instr_copen *i; + + if (! lex->spcont->find_cursor(&$2, &offset)) + { + net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str); + YYABORT; + } + i= new sp_instr_copen(sp->instructions(), lex->spcont, offset); + sp->add_instr(i); + } + | FETCH_SYM sp_opt_fetch_noise ident INTO + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + uint offset; + sp_instr_cfetch *i; + + if (! lex->spcont->find_cursor(&$3, &offset)) + { + net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $3.str); + YYABORT; + } + i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset); + sp->add_instr(i); + } + sp_fetch_list + { } + | CLOSE_SYM ident + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + uint offset; + sp_instr_cclose *i; + + if (! lex->spcont->find_cursor(&$2, &offset)) + { + net_printf(YYTHD, ER_SP_CURSOR_MISMATCH, $2.str); + YYABORT; + } + i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset); + sp->add_instr(i); + } + ; + +sp_opt_fetch_noise: + /* Empty */ + | NEXT_SYM FROM + | FROM + ; + +sp_fetch_list: + ident + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *spc= lex->spcont; + sp_pvar_t *spv; + + if (!spc || !(spv = spc->find_pvar(&$1))) + { + net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str); + YYABORT; + } + else + { + /* An SP local variable */ + sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction(); + + i->add_to_varlist(spv); + spv->isset= TRUE; + } + } + | + sp_fetch_list ',' ident + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *spc= lex->spcont; + sp_pvar_t *spv; + + if (!spc || !(spv = spc->find_pvar(&$3))) + { + net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $3.str); + YYABORT; + } + else + { + /* An SP local variable */ + sp_instr_cfetch *i= (sp_instr_cfetch *)sp->last_instruction(); + + i->add_to_varlist(spv); + spv->isset= TRUE; + } + } + ; + +sp_if: + expr THEN_SYM + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + uint ip= sp->instructions(); + sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, ctx, $1); + + i->tables= lex->query_tables; + lex->query_tables= 0; + sp->push_backpatch(i, ctx->push_label((char *)"", 0)); + sp->add_instr(i); + } + sp_proc_stmts1 + { + sp_head *sp= Lex->sphead; + sp_pcontext *ctx= Lex->spcont; + uint ip= sp->instructions(); + sp_instr_jump *i = new sp_instr_jump(ip, ctx); + + sp->add_instr(i); + sp->backpatch(ctx->pop_label()); + sp->push_backpatch(i, ctx->push_label((char *)"", 0)); + } + sp_elseifs + { + LEX *lex= Lex; + + lex->sphead->backpatch(lex->spcont->pop_label()); + } + ; + +sp_elseifs: + /* Empty */ + | ELSEIF_SYM sp_if + | ELSE sp_proc_stmts1 + ; + +sp_case: + expr THEN_SYM + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= Lex->spcont; + uint ip= sp->instructions(); + sp_instr_jump_if_not *i; + + if (! sp->m_simple_case) + i= new sp_instr_jump_if_not(ip, ctx, $1); + else + { /* Simple case: = */ + LEX_STRING ivar; + + ivar.str= (char *)"_tmp_"; + ivar.length= 5; + Item *var= (Item*) new Item_splocal(ivar, + ctx->current_pvars()-1); + Item *expr= new Item_func_eq(var, $1); + + i= new sp_instr_jump_if_not(ip, ctx, expr); + lex->variables_used= 1; + } + sp->push_backpatch(i, ctx->push_label((char *)"", 0)); + i->tables= lex->query_tables; + lex->query_tables= 0; + sp->add_instr(i); + } + sp_proc_stmts1 + { + sp_head *sp= Lex->sphead; + sp_pcontext *ctx= Lex->spcont; + uint ip= sp->instructions(); + sp_instr_jump *i = new sp_instr_jump(ip, ctx); + + sp->add_instr(i); + sp->backpatch(ctx->pop_label()); + sp->push_backpatch(i, ctx->push_label((char *)"", 0)); + } + sp_whens + { + LEX *lex= Lex; + + lex->sphead->backpatch(lex->spcont->pop_label()); + } + ; + +sp_whens: + /* Empty */ + { + sp_head *sp= Lex->sphead; + uint ip= sp->instructions(); + sp_instr_error *i= new sp_instr_error(ip, Lex->spcont, + ER_SP_CASE_NOT_FOUND); + + sp->add_instr(i); + } + | ELSE sp_proc_stmts1 {} + | WHEN_SYM sp_case {} + ; + +sp_labeled_control: + IDENT ':' + { + LEX *lex= Lex; + sp_pcontext *ctx= lex->spcont; + sp_label_t *lab= ctx->find_label($1.str); + + if (lab) + { + net_printf(YYTHD, ER_SP_LABEL_REDEFINE, $1.str); + YYABORT; + } + else + { + lab= lex->spcont->push_label($1.str, + lex->sphead->instructions()); + lab->type= SP_LAB_ITER; + } + } + sp_unlabeled_control sp_opt_label + { + LEX *lex= Lex; + + if ($5.str) + { + sp_label_t *lab= lex->spcont->find_label($5.str); + + if (!lab || + my_strcasecmp(system_charset_info, $5.str, lab->name) != 0) + { + net_printf(YYTHD, ER_SP_LABEL_MISMATCH, $5.str); + YYABORT; + } + } + lex->sphead->backpatch(lex->spcont->pop_label()); + } + ; + +sp_opt_label: + /* Empty */ + { $$.str= NULL; $$.length= 0; } + | IDENT + { $$= $1; } + ; + +sp_unlabeled_control: + BEGIN_SYM + { /* QQ This is just a dummy for grouping declarations and statements + together. No [[NOT] ATOMIC] yet, and we need to figure out how + make it coexist with the existing BEGIN COMMIT/ROLLBACK. */ + LEX *lex= Lex; + sp_label_t *lab= lex->spcont->last_label(); + + lab->type= SP_LAB_BEGIN; + lex->spcont= lex->spcont->push_context(); + } + sp_decls + sp_proc_stmts + END + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + sp_pcontext *ctx= lex->spcont; + + sp->backpatch(ctx->last_label()); /* We always have a label */ + if ($3.hndlrs) + sp->add_instr(new sp_instr_hpop(sp->instructions(), ctx, + $3.hndlrs)); + if ($3.curs) + sp->add_instr(new sp_instr_cpop(sp->instructions(), ctx, + $3.curs)); + lex->spcont= ctx->pop_context(); + } + | LOOP_SYM + sp_proc_stmts1 END LOOP_SYM + { + LEX *lex= Lex; + uint ip= lex->sphead->instructions(); + sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */ + sp_instr_jump *i = new sp_instr_jump(ip, lex->spcont, lab->ip); + + lex->sphead->add_instr(i); + } + | WHILE_SYM expr DO_SYM + { + LEX *lex= Lex; + sp_head *sp= lex->sphead; + uint ip= sp->instructions(); + sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, lex->spcont, + $2); + + /* Jumping forward */ + sp->push_backpatch(i, lex->spcont->last_label()); + i->tables= lex->query_tables; + lex->query_tables= 0; + sp->add_instr(i); + } + sp_proc_stmts1 END WHILE_SYM + { + LEX *lex= Lex; + uint ip= lex->sphead->instructions(); + sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */ + sp_instr_jump *i = new sp_instr_jump(ip, lex->spcont, lab->ip); + + lex->sphead->add_instr(i); + } + | REPEAT_SYM sp_proc_stmts1 UNTIL_SYM expr END REPEAT_SYM + { + LEX *lex= Lex; + uint ip= lex->sphead->instructions(); + sp_label_t *lab= lex->spcont->last_label(); /* Jumping back */ + sp_instr_jump_if_not *i = new sp_instr_jump_if_not(ip, lex->spcont, + $4, lab->ip); + + i->tables= lex->query_tables; + lex->query_tables= 0; + lex->sphead->add_instr(i); + } + ; + +trg_action_time: + BEFORE_SYM + { Lex->trg_chistics.action_time= TRG_ACTION_BEFORE; } + | AFTER_SYM + { Lex->trg_chistics.action_time= TRG_ACTION_AFTER; } + ; + +trg_event: + INSERT + { Lex->trg_chistics.event= TRG_EVENT_INSERT; } + | UPDATE_SYM + { Lex->trg_chistics.event= TRG_EVENT_UPDATE; } + | DELETE_SYM + { Lex->trg_chistics.event= TRG_EVENT_DELETE; } ; create2: @@ -1117,6 +2440,10 @@ create_select: lex->sql_command= SQLCOM_INSERT_SELECT; else if (lex->sql_command == SQLCOM_REPLACE) lex->sql_command= SQLCOM_REPLACE_SELECT; + /* + The following work only with the local list, the global list + is created correctly in this case + */ lex->current_select->table_list.save_and_clear(&lex->save_list); mysql_init_select(lex); lex->current_select->parsing_place= SELECT_LIST; @@ -1126,7 +2453,13 @@ create_select: Select->parsing_place= NO_MATTER; } opt_select_from - { Lex->current_select->table_list.push_front(&Lex->save_list); } + { + /* + The following work only with the local list, the global list + is created correctly in this case + */ + Lex->current_select->table_list.push_front(&Lex->save_list); + } ; opt_as: @@ -1174,19 +2507,19 @@ create_table_options: | create_table_option ',' create_table_options; create_table_option: - ENGINE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; } - | TYPE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); } + ENGINE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } + | TYPE_SYM opt_equal storage_engines { Lex->create_info.db_type= $3; WARN_DEPRECATED("TYPE=storage_engine","ENGINE=storage_engine"); Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE; } | MAX_ROWS opt_equal ulonglong_num { Lex->create_info.max_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MAX_ROWS;} | MIN_ROWS opt_equal ulonglong_num { Lex->create_info.min_rows= $3; Lex->create_info.used_fields|= HA_CREATE_USED_MIN_ROWS;} | AVG_ROW_LENGTH opt_equal ULONG_NUM { Lex->create_info.avg_row_length=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AVG_ROW_LENGTH;} - | PASSWORD opt_equal TEXT_STRING_sys { Lex->create_info.password=$3.str; } - | COMMENT_SYM opt_equal TEXT_STRING_sys { Lex->create_info.comment=$3.str; } + | PASSWORD opt_equal TEXT_STRING_sys { Lex->create_info.password=$3.str; Lex->create_info.used_fields|= HA_CREATE_USED_PASSWORD; } + | COMMENT_SYM opt_equal TEXT_STRING_sys { Lex->create_info.comment=$3.str; Lex->create_info.used_fields|= HA_CREATE_USED_COMMENT; } | AUTO_INC opt_equal ulonglong_num { Lex->create_info.auto_increment_value=$3; Lex->create_info.used_fields|= HA_CREATE_USED_AUTO;} | PACK_KEYS_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_PACK_KEYS : HA_OPTION_NO_PACK_KEYS; Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;} | PACK_KEYS_SYM opt_equal DEFAULT { Lex->create_info.table_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS); Lex->create_info.used_fields|= HA_CREATE_USED_PACK_KEYS;} - | CHECKSUM_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; } - | DELAY_KEY_WRITE_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; } - | ROW_FORMAT_SYM opt_equal row_types { Lex->create_info.row_type= $3; } + | CHECKSUM_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM; Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM; } + | DELAY_KEY_WRITE_SYM opt_equal ULONG_NUM { Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE; Lex->create_info.used_fields|= HA_CREATE_USED_DELAY_KEY_WRITE; } + | ROW_FORMAT_SYM opt_equal row_types { Lex->create_info.row_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_ROW_FORMAT; } | RAID_TYPE opt_equal raid_types { Lex->create_info.raid_type= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;} | RAID_CHUNKS opt_equal ULONG_NUM { Lex->create_info.raid_chunks= $3; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;} | RAID_CHUNKSIZE opt_equal ULONG_NUM { Lex->create_info.raid_chunksize= $3*RAID_BLOCK_SIZE; Lex->create_info.used_fields|= HA_CREATE_USED_RAID;} @@ -1197,18 +2530,20 @@ create_table_option: TABLE_LIST *table_list= lex->select_lex.get_table_list(); lex->create_info.merge_list= lex->select_lex.table_list; lex->create_info.merge_list.elements--; - lex->create_info.merge_list.first= (byte*) (table_list->next); + lex->create_info.merge_list.first= + (byte*) (table_list->next_local); lex->select_lex.table_list.elements=1; - lex->select_lex.table_list.next= (byte**) &(table_list->next); - table_list->next=0; + lex->select_lex.table_list.next= + (byte**) &(table_list->next_local); + table_list->next_local= 0; lex->create_info.used_fields|= HA_CREATE_USED_UNION; } | default_charset | default_collation | INSERT_METHOD opt_equal merge_insert_types { Lex->create_info.merge_insert_method= $3; Lex->create_info.used_fields|= HA_CREATE_USED_INSERT_METHOD;} - | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys - { Lex->create_info.data_file_name= $4.str; } - | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; }; + | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.data_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR; } + | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR; } + ; default_charset: opt_default charset opt_equal charset_name_or_default @@ -1823,14 +3158,12 @@ key_part: | ident '(' NUM ')' { int key_part_len= atoi($3.str); -#if MYSQL_VERSION_ID < 50000 if (!key_part_len) { my_printf_error(ER_UNKNOWN_ERROR, "Key part '%s' length cannot be 0", MYF(0), $1.str); } -#endif $$=new key_part_spec($1.str,(uint) key_part_len); }; @@ -1869,8 +3202,7 @@ alter: lex->create_info.db_type= DB_TYPE_DEFAULT; lex->create_info.default_table_charset= NULL; lex->create_info.row_type= ROW_TYPE_NOT_USED; - lex->alter_info.reset(); - lex->alter_info.is_simple= 1; + lex->alter_info.reset(); lex->alter_info.flags= 0; } alter_list @@ -1885,8 +3217,48 @@ alter: LEX *lex=Lex; lex->sql_command=SQLCOM_ALTER_DB; lex->name=$3.str; - }; + } + | ALTER PROCEDURE sp_name + { + LEX *lex= Lex; + bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); + } + sp_a_chistics + { + THD *thd= YYTHD; + LEX *lex=Lex; + + lex->sql_command= SQLCOM_ALTER_PROCEDURE; + lex->spname= $3; + } + | ALTER FUNCTION_SYM sp_name + { + LEX *lex= Lex; + + bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); + } + sp_a_chistics + { + THD *thd= YYTHD; + LEX *lex=Lex; + + lex->sql_command= SQLCOM_ALTER_FUNCTION; + lex->spname= $3; + } + | ALTER algorithm VIEW_SYM table_ident + { + THD *thd= YYTHD; + LEX *lex= thd->lex; + lex->sql_command= SQLCOM_CREATE_VIEW; + lex->create_view_mode= VIEW_ALTER; + lex->select_lex.resolve_mode= SELECT_LEX::SELECT_MODE; + /* first table in list is target VIEW name */ + lex->select_lex.add_table_to_list(thd, $4, NULL, 0); + } + opt_view_list AS select_init check_option + {} + ; alter_list: | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; } @@ -1895,27 +3267,27 @@ alter_list: | alter_list ',' alter_list_item; add_column: - ADD opt_column + ADD opt_column { LEX *lex=Lex; - lex->change=0; - lex->alter_info.flags|= ALTER_ADD_COLUMN; + lex->change=0; + lex->alter_info.flags|= ALTER_ADD_COLUMN; }; alter_list_item: - add_column column_def opt_place { Lex->alter_info.is_simple= 0; } - | ADD key_def - { - LEX *lex=Lex; - lex->alter_info.is_simple= 0; - lex->alter_info.flags|= ALTER_ADD_INDEX; + add_column column_def opt_place { } + | ADD key_def + { + Lex->alter_info.flags|= ALTER_ADD_INDEX; } - | add_column '(' field_list ')' { Lex->alter_info.is_simple= 0; } + | add_column '(' field_list ')' + { + Lex->alter_info.flags|= ALTER_ADD_COLUMN | ALTER_ADD_INDEX; + } | CHANGE opt_column field_ident { LEX *lex=Lex; - lex->change= $3.str; - lex->alter_info.is_simple= 0; + lex->change= $3.str; lex->alter_info.flags|= ALTER_CHANGE_COLUMN; } field_spec opt_place @@ -1926,7 +3298,6 @@ alter_list_item: lex->default_value= lex->on_update_value= 0; lex->comment=0; lex->charset= NULL; - lex->alter_info.is_simple= 0; lex->alter_info.flags|= ALTER_CHANGE_COLUMN; } type opt_attribute @@ -1946,17 +3317,18 @@ alter_list_item: { LEX *lex=Lex; lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::COLUMN, - $3.str)); - lex->alter_info.is_simple= 0; + $3.str)); lex->alter_info.flags|= ALTER_DROP_COLUMN; } - | DROP FOREIGN KEY_SYM opt_ident { Lex->alter_info.is_simple= 0; } + | DROP FOREIGN KEY_SYM opt_ident + { + Lex->alter_info.flags|= ALTER_DROP_INDEX; + } | DROP PRIMARY_SYM KEY_SYM { LEX *lex=Lex; lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY, primary_key_name)); - lex->alter_info.is_simple= 0; lex->alter_info.flags|= ALTER_DROP_INDEX; } | DROP key_or_index field_ident @@ -1964,25 +3336,32 @@ alter_list_item: LEX *lex=Lex; lex->alter_info.drop_list.push_back(new Alter_drop(Alter_drop::KEY, $3.str)); - lex->alter_info.is_simple= 0; lex->alter_info.flags|= ALTER_DROP_INDEX; } - | DISABLE_SYM KEYS { Lex->alter_info.keys_onoff= DISABLE; } - | ENABLE_SYM KEYS { Lex->alter_info.keys_onoff= ENABLE; } + | DISABLE_SYM KEYS + { + LEX *lex=Lex; + lex->alter_info.keys_onoff= DISABLE; + lex->alter_info.flags|= ALTER_KEYS_ONOFF; + } + | ENABLE_SYM KEYS + { + LEX *lex=Lex; + lex->alter_info.keys_onoff= ENABLE; + lex->alter_info.flags|= ALTER_KEYS_ONOFF; + } | ALTER opt_column field_ident SET DEFAULT signed_literal { LEX *lex=Lex; lex->alter_info.alter_list.push_back(new Alter_column($3.str,$6)); - lex->alter_info.is_simple= 0; - lex->alter_info.flags|= ALTER_CHANGE_COLUMN; + lex->alter_info.flags|= ALTER_CHANGE_COLUMN_DEFAULT; } | ALTER opt_column field_ident DROP DEFAULT { LEX *lex=Lex; lex->alter_info.alter_list.push_back(new Alter_column($3.str, (Item*) 0)); - lex->alter_info.is_simple= 0; - lex->alter_info.flags|= ALTER_CHANGE_COLUMN; + lex->alter_info.flags|= ALTER_CHANGE_COLUMN_DEFAULT; } | RENAME opt_to table_ident { @@ -2012,22 +3391,20 @@ alter_list_item: YYABORT; } LEX *lex= Lex; - lex->create_info.table_charset= + lex->create_info.table_charset= lex->create_info.default_table_charset= $5; lex->create_info.used_fields|= (HA_CREATE_USED_CHARSET | HA_CREATE_USED_DEFAULT_CHARSET); - lex->alter_info.is_simple= 0; + lex->alter_info.flags|= ALTER_CONVERT; } - | create_table_options_space_separated + | create_table_options_space_separated { LEX *lex=Lex; - lex->alter_info.is_simple= 0; lex->alter_info.flags|= ALTER_OPTIONS; } - | order_clause + | order_clause { LEX *lex=Lex; - lex->alter_info.is_simple= 0; lex->alter_info.flags|= ALTER_ORDER; }; @@ -2040,9 +3417,10 @@ opt_ignore: | IGNORE_SYM { Lex->duplicates=DUP_IGNORE; }; opt_restrict: - /* empty */ {} - | RESTRICT {} - | CASCADE {}; + /* empty */ { Lex->drop_mode= DROP_DEFAULT; } + | RESTRICT { Lex->drop_mode= DROP_RESTRICT; } + | CASCADE { Lex->drop_mode= DROP_CASCADE; } + ; opt_place: /* empty */ {} @@ -2060,7 +3438,7 @@ opt_to: */ slave: - START_SYM SLAVE slave_thread_opts + START_SYM SLAVE slave_thread_opts { LEX *lex=Lex; lex->sql_command = SQLCOM_SLAVE_START; @@ -2542,8 +3920,12 @@ select_item: YYABORT; if ($4.str) $2->set_name($4.str,$4.length,system_charset_info); - else if (!$2->name) - $2->set_name($1,(uint) ($3 - $1), YYTHD->charset()); + else if (!$2->name) { + char *str = $1; + if (str[-1] == '`') + str--; + $2->set_name(str,(uint) ($3 - str), YYTHD->charset()); + } }; remember_name: @@ -2767,12 +4149,16 @@ simple_expr: | '@' ident_or_text SET_VAR expr { $$= new Item_func_set_user_var($2,$4); - Lex->uncacheable(UNCACHEABLE_RAND); + LEX *lex= Lex; + lex->uncacheable(UNCACHEABLE_RAND); + lex->variables_used= 1; } | '@' ident_or_text { $$= new Item_func_get_user_var($2); - Lex->uncacheable(UNCACHEABLE_RAND); + LEX *lex= Lex; + lex->uncacheable(UNCACHEABLE_RAND); + lex->variables_used= 1; } | '@' '@' opt_var_ident_type ident_or_text opt_component { @@ -2784,6 +4170,7 @@ simple_expr: } if (!($$= get_system_var(YYTHD, (enum_var_type) $3, $4, $5))) YYABORT; + Lex->variables_used= 1; } | sum_expr | '+' expr %prec NEG { $$= $2; } @@ -2888,6 +4275,8 @@ simple_expr: { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);} | ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')' { $$= new Item_date_add_interval($3, $6, $7, 0); } + | REPEAT_SYM '(' expr ',' expr ')' + { $$= new Item_func_repeat($3,$5); } | ATAN '(' expr ')' { $$= new Item_func_atan($3); } | ATAN '(' expr ',' expr ')' @@ -2904,6 +4293,8 @@ simple_expr: { $$= new Item_func_concat(* $3); } | CONCAT_WS '(' expr ',' expr_list ')' { $5->push_front($3); $$= new Item_func_concat_ws(*$5); } + | CONTAINS_SYM '(' expr ',' expr ')' + { $$= create_func_contains($3, $5); } | CONVERT_TZ_SYM '(' expr ',' expr ',' expr ')' { Lex->time_zone_tables_used= &fake_time_zone_tables_list; @@ -3059,6 +4450,8 @@ simple_expr: { $$= new Item_func_old_password($3); } | POSITION_SYM '(' no_in_expr IN_SYM expr ')' { $$ = new Item_func_locate($5,$3); } + | QUARTER_SYM '(' expr ')' + { $$ = new Item_func_quarter($3); } | RAND '(' expr ')' { $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);} | RAND '(' ')' @@ -3070,6 +4463,11 @@ simple_expr: | ROUND '(' expr ')' { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); } | ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); } + | ROW_COUNT_SYM '(' ')' + { + $$= new Item_func_row_count(); + Lex->safe_to_cache_query= 0; + } | SUBDATE_SYM '(' expr ',' expr ')' { $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);} | SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')' @@ -3092,6 +4490,10 @@ simple_expr: { $$= new Item_datetime_typecast($3); } | TIMESTAMP '(' expr ',' expr ')' { $$= new Item_func_add_time($3, $5, 1, 0); } + | TIMESTAMP_ADD '(' interval_time_st ',' expr ',' expr ')' + { $$= new Item_date_add_interval($7,$5,$3,0); } + | TIMESTAMP_DIFF '(' interval_time_st ',' expr ',' expr ')' + { $$= new Item_func_timestamp_diff($5,$7,$3); } | TRIM '(' expr ')' { $$= new Item_func_trim($3); } | TRIM '(' LEADING expr FROM expr ')' @@ -3112,48 +4514,90 @@ simple_expr: { $$= new Item_func_round($3,$5,1); } | TRUE_SYM { $$= new Item_int((char*) "TRUE",1,1); } - | UDA_CHAR_SUM '(' udf_expr_list ')' + | ident '.' ident '(' udf_expr_list ')' { - if ($3 != NULL) - $$ = new Item_sum_udf_str($1, *$3); + LEX *lex= Lex; + sp_name *name= new sp_name($1, $3); + + name->init_qname(YYTHD); + sp_add_fun_to_lex(Lex, name); + if ($5) + $$= new Item_func_sp(name, *$5); else - $$ = new Item_sum_udf_str($1); - } - | UDA_FLOAT_SUM '(' udf_expr_list ')' - { - if ($3 != NULL) - $$ = new Item_sum_udf_float($1, *$3); - else - $$ = new Item_sum_udf_float($1); - } - | UDA_INT_SUM '(' udf_expr_list ')' - { - if ($3 != NULL) - $$ = new Item_sum_udf_int($1, *$3); - else - $$ = new Item_sum_udf_int($1); - } - | UDF_CHAR_FUNC '(' udf_expr_list ')' - { - if ($3 != NULL) - $$ = new Item_func_udf_str($1, *$3); - else - $$ = new Item_func_udf_str($1); - } - | UDF_FLOAT_FUNC '(' udf_expr_list ')' - { - if ($3 != NULL) - $$ = new Item_func_udf_float($1, *$3); - else - $$ = new Item_func_udf_float($1); - } - | UDF_INT_FUNC '(' udf_expr_list ')' - { - if ($3 != NULL) - $$ = new Item_func_udf_int($1, *$3); - else - $$ = new Item_func_udf_int($1); + $$= new Item_func_sp(name); } + | IDENT_sys '(' udf_expr_list ')' + { +#ifdef HAVE_DLOPEN + udf_func *udf; + + if (using_udf_functions && (udf=find_udf($1.str, $1.length))) + { + switch (udf->returns) { + case STRING_RESULT: + if (udf->type == UDFTYPE_FUNCTION) + { + if ($3 != NULL) + $$ = new Item_func_udf_str(udf, *$3); + else + $$ = new Item_func_udf_str(udf); + } + else + { + if ($3 != NULL) + $$ = new Item_sum_udf_str(udf, *$3); + else + $$ = new Item_sum_udf_str(udf); + } + break; + case REAL_RESULT: + if (udf->type == UDFTYPE_FUNCTION) + { + if ($3 != NULL) + $$ = new Item_func_udf_float(udf, *$3); + else + $$ = new Item_func_udf_float(udf); + } + else + { + if ($3 != NULL) + $$ = new Item_sum_udf_float(udf, *$3); + else + $$ = new Item_sum_udf_float(udf); + } + break; + case INT_RESULT: + if (udf->type == UDFTYPE_FUNCTION) + { + if ($3 != NULL) + $$ = new Item_func_udf_int(udf, *$3); + else + $$ = new Item_func_udf_int(udf); + } + else + { + if ($3 != NULL) + $$ = new Item_sum_udf_int(udf, *$3); + else + $$ = new Item_sum_udf_int(udf); + } + break; + default: + YYABORT; + } + } + else +#endif /* HAVE_DLOPEN */ + { + sp_name *name= sp_name_current_db_new(YYTHD, $1); + + sp_add_fun_to_lex(Lex, name); + if ($3) + $$= new Item_func_sp(name, *$3); + else + $$= new Item_func_sp(name); + } + } | UNIQUE_USERS '(' text_literal ',' NUM ',' NUM ',' expr_list ')' { $$= new Item_func_unique_users($3,atoi($5.str),atoi($7.str), * $9); @@ -3261,8 +4705,37 @@ fulltext_options: ; udf_expr_list: - /* empty */ { $$= NULL; } - | expr_list { $$= $1;}; + /* empty */ { $$= NULL; } + | udf_expr_list2 { $$= $1;} + ; + +udf_expr_list2: + { Select->expr_list.push_front(new List); } + udf_expr_list3 + { $$= Select->expr_list.pop(); } + ; + +udf_expr_list3: + udf_expr + { + Select->expr_list.head()->push_back($1); + } + | udf_expr_list3 ',' udf_expr + { + Select->expr_list.head()->push_back($3); + } + ; + +udf_expr: + remember_name expr remember_end select_alias + { + if ($4.str) + $2->set_name($4.str,$4.length,system_charset_info); + else + $2->set_name($1,(uint) ($3 - $1), YYTHD->charset()); + $$= $2; + } + ; sum_expr: AVG_SYM '(' in_sum_expr ')' @@ -3287,14 +4760,25 @@ sum_expr: { $$= new Item_sum_unique_users($3,atoi($5.str),atoi($7.str),$9); } | MIN_SYM '(' in_sum_expr ')' { $$=new Item_sum_min($3); } +/* + According to ANSI SQL, DISTINCT is allowed and has + no sence inside MIN and MAX grouping functions; so MIN|MAX(DISTINCT ...) + is processed like an ordinary MIN | MAX() + */ + | MIN_SYM '(' DISTINCT in_sum_expr ')' + { $$=new Item_sum_min($4); } | MAX_SYM '(' in_sum_expr ')' { $$=new Item_sum_max($3); } + | MAX_SYM '(' DISTINCT in_sum_expr ')' + { $$=new Item_sum_max($4); } | STD_SYM '(' in_sum_expr ')' { $$=new Item_sum_std($3); } | VARIANCE_SYM '(' in_sum_expr ')' { $$=new Item_sum_variance($3); } | SUM_SYM '(' in_sum_expr ')' { $$=new Item_sum_sum($3); } + | SUM_SYM '(' DISTINCT in_sum_expr ')' + { $$=new Item_sum_sum_distinct($4); } | GROUP_CONCAT_SYM '(' opt_distinct { Select->in_sum_expr++; } expr_list opt_gorder_clause @@ -3408,59 +4892,80 @@ when_list2: sel->when_list.head()->push_back($5); }; +table_ref: + table_factor { $$=$1; } + | join_table { $$=$1; } + { + LEX *lex= Lex; + if (!($$= lex->current_select->nest_last_join(lex->thd))) + YYABORT; + } + ; + join_table_list: - '(' join_table_list ')' { $$=$2; } - | join_table { $$=$1; } - | join_table_list ',' join_table_list { $$=$3; } - | join_table_list normal_join join_table_list { $$=$3; } - | join_table_list STRAIGHT_JOIN join_table_list - { $$=$3 ; $1->next->straight=1; } - | join_table_list normal_join join_table_list ON expr + table_ref { $$=$1; } + | join_table_list ',' table_ref { $$=$3; } + ; + +join_table: + table_ref normal_join table_ref { $$=$3; } + | table_ref STRAIGHT_JOIN table_factor + { $3->straight=1; $$=$3 ; } + | table_ref normal_join table_ref ON expr { add_join_on($3,$5); $$=$3; } - | join_table_list normal_join join_table_list + | table_ref normal_join table_ref USING { SELECT_LEX *sel= Select; - sel->db1=$1->db; sel->table1=$1->alias; - sel->db2=$3->db; sel->table2=$3->alias; + sel->save_names_for_using_list($1, $3); } '(' using_list ')' { add_join_on($3,$7); $$=$3; } - | join_table_list LEFT opt_outer JOIN_SYM join_table_list ON expr + | table_ref LEFT opt_outer JOIN_SYM table_ref ON expr { add_join_on($5,$7); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; } - | join_table_list LEFT opt_outer JOIN_SYM join_table_list + | table_ref LEFT opt_outer JOIN_SYM table_factor { SELECT_LEX *sel= Select; - sel->db1=$1->db; sel->table1=$1->alias; - sel->db2=$5->db; sel->table2=$5->alias; + sel->save_names_for_using_list($1, $5); } USING '(' using_list ')' { add_join_on($5,$9); $5->outer_join|=JOIN_TYPE_LEFT; $$=$5; } - | join_table_list NATURAL LEFT opt_outer JOIN_SYM join_table_list + | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor { - add_join_natural($1,$1->next); - $1->next->outer_join|=JOIN_TYPE_LEFT; + add_join_natural($1,$6); + $6->outer_join|=JOIN_TYPE_LEFT; $$=$6; } - | join_table_list RIGHT opt_outer JOIN_SYM join_table_list ON expr - { add_join_on($1,$7); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; } - | join_table_list RIGHT opt_outer JOIN_SYM join_table_list + | table_ref RIGHT opt_outer JOIN_SYM table_ref ON expr + { + LEX *lex= Lex; + if (!($$= lex->current_select->convert_right_join())) + YYABORT; + add_join_on($$, $7); + } + | table_ref RIGHT opt_outer JOIN_SYM table_factor { SELECT_LEX *sel= Select; - sel->db1=$1->db; sel->table1=$1->alias; - sel->db2=$5->db; sel->table2=$5->alias; + sel->save_names_for_using_list($1, $5); } USING '(' using_list ')' - { add_join_on($1,$9); $1->outer_join|=JOIN_TYPE_RIGHT; $$=$5; } - | join_table_list NATURAL RIGHT opt_outer JOIN_SYM join_table_list + { + LEX *lex= Lex; + if (!($$= lex->current_select->convert_right_join())) + YYABORT; + add_join_on($$, $9); + } + | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor { - add_join_natural($1->next,$1); - $1->outer_join|=JOIN_TYPE_RIGHT; - $$=$6; + add_join_natural($6,$1); + LEX *lex= Lex; + if (!($$= lex->current_select->convert_right_join())) + YYABORT; } - | join_table_list NATURAL JOIN_SYM join_table_list - { add_join_natural($1,$1->next); $$=$4; }; + | table_ref NATURAL JOIN_SYM table_factor + { add_join_natural($1,$4); $$=$4; }; + normal_join: JOIN_SYM {} @@ -3468,7 +4973,7 @@ normal_join: | CROSS JOIN_SYM {} ; -join_table: +table_factor: { SELECT_LEX *sel= Select; sel->use_index_ptr=sel->ignore_index_ptr=0; @@ -3484,8 +4989,21 @@ join_table: sel->get_use_index(), sel->get_ignore_index()))) YYABORT; + sel->add_joined_table($$); } - | '{' ident join_table LEFT OUTER JOIN_SYM join_table ON expr '}' + | '(' + { + LEX *lex= Lex; + if (lex->current_select->init_nested_join(lex->thd)) + YYABORT; + } + join_table_list ')' + { + LEX *lex= Lex; + if (!($$= lex->current_select->end_nested_join(lex->thd))) + YYABORT; + } + | '{' ident table_ref LEFT OUTER JOIN_SYM table_ref ON expr '}' { add_join_on($7,$9); $7->outer_join|=JOIN_TYPE_LEFT; $$=$7; } | '(' SELECT_SYM select_derived ')' opt_table_alias { @@ -3498,12 +5016,13 @@ join_table: (List *)0))) YYABORT; + lex->current_select->add_joined_table($$); }; select_derived: { LEX *lex= Lex; - lex->derived_tables= 1; + lex->derived_tables|= DERIVED_SUBQUERY; if (((int)lex->sql_command >= (int)SQLCOM_HA_OPEN && lex->sql_command <= (int)SQLCOM_HA_READ) || lex->sql_command == (int)SQLCOM_KILL) @@ -3594,23 +5113,29 @@ using_list: }; interval: - DAY_HOUR_SYM { $$=INTERVAL_DAY_HOUR; } + interval_time_st {} + | DAY_HOUR_SYM { $$=INTERVAL_DAY_HOUR; } | DAY_MICROSECOND_SYM { $$=INTERVAL_DAY_MICROSECOND; } | DAY_MINUTE_SYM { $$=INTERVAL_DAY_MINUTE; } | DAY_SECOND_SYM { $$=INTERVAL_DAY_SECOND; } - | DAY_SYM { $$=INTERVAL_DAY; } | HOUR_MICROSECOND_SYM { $$=INTERVAL_HOUR_MICROSECOND; } | HOUR_MINUTE_SYM { $$=INTERVAL_HOUR_MINUTE; } | HOUR_SECOND_SYM { $$=INTERVAL_HOUR_SECOND; } - | HOUR_SYM { $$=INTERVAL_HOUR; } | MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; } | MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; } | MINUTE_SECOND_SYM { $$=INTERVAL_MINUTE_SECOND; } + | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; } + | YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; }; + +interval_time_st: + DAY_SYM { $$=INTERVAL_DAY; } + | WEEK_SYM { $$=INTERVAL_WEEK; } + | HOUR_SYM { $$=INTERVAL_HOUR; } + | FRAC_SECOND_SYM { $$=INTERVAL_MICROSECOND; } | MINUTE_SYM { $$=INTERVAL_MINUTE; } | MONTH_SYM { $$=INTERVAL_MONTH; } - | SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; } + | QUARTER_SYM { $$=INTERVAL_QUARTER; } | SECOND_SYM { $$=INTERVAL_SECOND; } - | YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; } | YEAR_SYM { $$=INTERVAL_YEAR; } ; @@ -3671,8 +5196,11 @@ having_clause: opt_escape: ESCAPE_SYM simple_expr { $$= $2; } | /* empty */ - { - $$= new Item_string("\\", 1, &my_charset_latin1); + { + + $$= ((YYTHD->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) ? + new Item_string("", 0, &my_charset_latin1) : + new Item_string("\\", 1, &my_charset_latin1)); } ; @@ -3885,12 +5413,33 @@ select_var_list: | select_var_ident {} ; -select_var_ident: '@' ident_or_text +select_var_ident: + '@' ident_or_text { LEX *lex=Lex; - if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING)))) + if (lex->result) + ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0,(enum_field_types)0)); + else YYABORT; } + | ident_or_text + { + LEX *lex=Lex; + sp_pvar_t *t; + + if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1))) + { + net_printf(YYTHD, ER_SP_UNDECLARED_VAR, $1.str); + YYABORT; + } + if (! lex->result) + YYABORT; + else + { + ((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset,t->type)); + t->isset= TRUE; + } + } ; into: @@ -3966,11 +5515,29 @@ drop: lex->drop_if_exists=$3; lex->name=$4.str; } - | DROP UDF_SYM IDENT_sys + | DROP FUNCTION_SYM if_exists sp_name { LEX *lex=Lex; + if (lex->sphead) + { + net_printf(YYTHD, ER_SP_NO_DROP_SP, "FUNCTION"); + YYABORT; + } lex->sql_command = SQLCOM_DROP_FUNCTION; - lex->udf.name = $3; + lex->drop_if_exists= $3; + lex->spname= $4; + } + | DROP PROCEDURE if_exists sp_name + { + LEX *lex=Lex; + if (lex->sphead) + { + net_printf(YYTHD, ER_SP_NO_DROP_SP, "PROCEDURE"); + YYABORT; + } + lex->sql_command = SQLCOM_DROP_PROCEDURE; + lex->drop_if_exists= $3; + lex->spname= $4; } | DROP USER { @@ -3980,8 +5547,28 @@ drop: } user_list {} - ; + | DROP VIEW_SYM if_exists table_list opt_restrict + { + THD *thd= YYTHD; + LEX *lex= thd->lex; + lex->sql_command= SQLCOM_DROP_VIEW; + lex->drop_if_exists= $3; + } + | DROP TRIGGER_SYM ident '.' ident + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_DROP_TRIGGER; + /* QQ: Could we loosen lock type in certain cases ? */ + if (!lex->select_lex.add_table_to_list(YYTHD, + new Table_ident($3), + (LEX_STRING*) 0, + TL_OPTION_UPDATING, + TL_WRITE)) + YYABORT; + lex->name_and_length= $5; + } + ; table_list: table_name @@ -4041,7 +5628,6 @@ replace: } insert_field_spec {} - {} ; insert_lock_option: @@ -4107,7 +5693,7 @@ ident_eq_list: ident_eq_value; ident_eq_value: - simple_ident equal expr_or_default + simple_ident_nospvar equal expr_or_default { LEX *lex=Lex; if (lex->field_list.push_back($1) || @@ -4173,7 +5759,6 @@ opt_insert_update: yyerror(ER(ER_SYNTAX_ERROR)); YYABORT; } - lex->duplicates= DUP_UPDATE; } KEY_SYM UPDATE_SYM update_list ; @@ -4211,12 +5796,12 @@ update: ; update_list: - update_list ',' simple_ident equal expr_or_default + update_list ',' simple_ident_nospvar equal expr_or_default { if (add_item_to_list(YYTHD, $3) || add_value_to_list(YYTHD, $5)) YYABORT; } - | simple_ident equal expr_or_default + | simple_ident_nospvar equal expr_or_default { if (add_item_to_list(YYTHD, $1) || add_value_to_list(YYTHD, $3)) YYABORT; @@ -4321,11 +5906,11 @@ show: SHOW show_param: DATABASES wild { Lex->sql_command= SQLCOM_SHOW_DATABASES; } - | TABLES opt_db wild + | opt_full TABLES opt_db wild { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLES; - lex->select_lex.db= $2; + lex->select_lex.db= $3; } | TABLE_SYM STATUS_SYM opt_db wild { @@ -4411,8 +5996,12 @@ show_param: { Lex->sql_command = SQLCOM_SHOW_WARNS;} | ERRORS opt_limit_clause_init { Lex->sql_command = SQLCOM_SHOW_ERRORS;} - | STATUS_SYM wild - { Lex->sql_command= SQLCOM_SHOW_STATUS; } + | opt_var_type STATUS_SYM wild + { + THD *thd= YYTHD; + thd->lex->sql_command= SQLCOM_SHOW_STATUS; + thd->lex->option_type= (enum_var_type) $1; + } | INNOBASE_SYM STATUS_SYM { Lex->sql_command = SQLCOM_SHOW_INNODB_STATUS; WARN_DEPRECATED("SHOW INNODB STATUS", "SHOW ENGINE INNODB STATUS"); } | opt_full PROCESSLIST_SYM @@ -4469,9 +6058,19 @@ show_param: } | CREATE TABLE_SYM table_ident { - Lex->sql_command = SQLCOM_SHOW_CREATE; - if (!Select->add_table_to_list(YYTHD, $3, NULL,0)) + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE; + if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0)) YYABORT; + lex->only_view= 0; + } + | CREATE VIEW_SYM table_ident + { + LEX *lex= Lex; + lex->sql_command = SQLCOM_SHOW_CREATE; + if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL, 0)) + YYABORT; + lex->only_view= 1; } | MASTER_SYM STATUS_SYM { @@ -4480,7 +6079,29 @@ show_param: | SLAVE STATUS_SYM { Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT; - }; + } + | CREATE PROCEDURE sp_name + { + LEX *lex= Lex; + + lex->sql_command = SQLCOM_SHOW_CREATE_PROC; + lex->spname= $3; + } + | CREATE FUNCTION_SYM sp_name + { + LEX *lex= Lex; + + lex->sql_command = SQLCOM_SHOW_CREATE_FUNC; + lex->spname= $3; + } + | PROCEDURE STATUS_SYM wild + { + Lex->sql_command = SQLCOM_SHOW_STATUS_PROC; + } + | FUNCTION_SYM STATUS_SYM wild + { + Lex->sql_command = SQLCOM_SHOW_STATUS_FUNC; + }; show_engine_param: STATUS_SYM @@ -4670,18 +6291,23 @@ purge_option: /* kill threads */ kill: - KILL_SYM expr + KILL_SYM kill_option expr { LEX *lex=Lex; - if ($2->fix_fields(lex->thd, 0, &$2) || $2->check_cols(1)) + if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1)) { send_error(lex->thd, ER_SET_CONSTANTS_ONLY); YYABORT; } lex->sql_command=SQLCOM_KILL; - lex->thread_id= (ulong) $2->val_int(); + lex->thread_id= (ulong) $3->val_int(); }; +kill_option: + /* empty */ { Lex->type= 0; } + | CONNECTION_SYM { Lex->type= 0; } + | QUERY_SYM { Lex->type= ONLY_KILL_QUERY; }; + /* change database */ use: USE_SYM ident @@ -4892,8 +6518,24 @@ NUM_literal: NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); } | LONG_NUM { int error; $$ = new Item_int($1.str, (longlong) my_strtoll10($1.str, NULL, &error), $1.length); } | ULONGLONG_NUM { $$ = new Item_uint($1.str, $1.length); } - | REAL_NUM { $$ = new Item_real($1.str, $1.length); } - | FLOAT_NUM { $$ = new Item_float($1.str, $1.length); } + | REAL_NUM + { + $$= new Item_real($1.str, $1.length); + if (YYTHD->net.report_error) + { + send_error(YYTHD, 0, NullS); + YYABORT; + } + } + | FLOAT_NUM + { + $$ = new Item_float($1.str, $1.length); + if (YYTHD->net.report_error) + { + send_error(YYTHD, 0, NullS); + YYABORT; + } + } ; /********************************************************************** @@ -4901,7 +6543,7 @@ NUM_literal: **********************************************************************/ insert_ident: - simple_ident { $$=$1; } + simple_ident_nospvar { $$=$1; } | table_wild { $$=$1; }; table_wild: @@ -4923,30 +6565,110 @@ order_ident: expr { $$=$1; }; simple_ident: + ident + { + sp_pvar_t *spv; + LEX *lex = Lex; + sp_pcontext *spc = lex->spcont; + + if (spc && (spv = spc->find_pvar(&$1))) + { /* We're compiling a stored procedure and found a variable */ + $$ = (Item*) new Item_splocal($1, spv->offset); + lex->variables_used= 1; + lex->safe_to_cache_query=0; + } + else + { + SELECT_LEX *sel=Select; + $$= (sel->parsing_place != IN_HAVING || + sel->get_in_sum_expr() > 0) ? + (Item*) new Item_field(NullS,NullS,$1.str) : + (Item*) new Item_ref(NullS,NullS,$1.str); + } + } + | simple_ident_q { $$= $1; } + ; + +simple_ident_nospvar: ident { SELECT_LEX *sel=Select; $$= (sel->parsing_place != IN_HAVING || sel->get_in_sum_expr() > 0) ? (Item*) new Item_field(NullS,NullS,$1.str) : - (Item*) new Item_ref(NullS, NullS, $1.str); + (Item*) new Item_ref(NullS,NullS,$1.str); } - | ident '.' ident + | simple_ident_q { $$= $1; } + ; + +simple_ident_q: + ident '.' ident { THD *thd= YYTHD; LEX *lex= thd->lex; - SELECT_LEX *sel= lex->current_select; - if (sel->no_table_names_allowed) - { - my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, - ER(ER_TABLENAME_NOT_ALLOWED_HERE), - MYF(0), $1.str, thd->where); - } - $$= (sel->parsing_place != IN_HAVING || - sel->get_in_sum_expr() > 0) ? - (Item*) new Item_field(NullS,$1.str,$3.str) : - (Item*) new Item_ref(NullS, $1.str, $3.str); - } + + /* + FIXME This will work ok in simple_ident_nospvar case because + we can't meet simple_ident_nospvar in trigger now. But it + should be changed in future. + */ + if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER && + (!my_strcasecmp(system_charset_info, $1.str, "NEW") || + !my_strcasecmp(system_charset_info, $1.str, "OLD"))) + { + bool new_row= ($1.str[0]=='N' || $1.str[0]=='n'); + + if (lex->trg_chistics.event == TRG_EVENT_INSERT && + !new_row) + { + net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "OLD", + "on INSERT"); + YYABORT; + } + + if (lex->trg_chistics.event == TRG_EVENT_DELETE && + new_row) + { + net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW", + "on DELETE"); + YYABORT; + } + + Item_trigger_field *trg_fld= + new Item_trigger_field(new_row ? Item_trigger_field::NEW_ROW : + Item_trigger_field::OLD_ROW, + $3.str); + + if (lex->trg_table && + trg_fld->setup_field(thd, lex->trg_table, + lex->trg_chistics.event)) + { + /* + FIXME. Far from perfect solution. See comment for + "SET NEW.field_name:=..." for more info. + */ + net_printf(YYTHD, ER_BAD_FIELD_ERROR, $3.str, + new_row ? "NEW": "OLD"); + YYABORT; + } + + $$= (Item *)trg_fld; + } + else + { + SELECT_LEX *sel= lex->current_select; + if (sel->no_table_names_allowed) + { + my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, + ER(ER_TABLENAME_NOT_ALLOWED_HERE), + MYF(0), $1.str, thd->where); + } + $$= (sel->parsing_place != IN_HAVING || + sel->get_in_sum_expr() > 0) ? + (Item*) new Item_field(NullS,$1.str,$3.str) : + (Item*) new Item_ref(NullS,$1.str,$3.str); + } + } | '.' ident '.' ident { THD *thd= YYTHD; @@ -5109,6 +6831,7 @@ keyword: | AFTER_SYM {} | AGAINST {} | AGGREGATE_SYM {} + | ALGORITHM_SYM {} | ANY_SYM {} | ASCII_SYM {} | AUTO_INC {} @@ -5124,6 +6847,7 @@ keyword: | BYTE_SYM {} | BTREE_SYM {} | CACHE_SYM {} + | CASCADED {} | CHANGED {} | CHARSET {} | CHECKSUM_SYM {} @@ -5137,12 +6861,14 @@ keyword: | COMPRESSED_SYM {} | CONCURRENT {} | CONSISTENT_SYM {} + | CONTAINS_SYM {} | CUBE_SYM {} | DATA_SYM {} | DATETIME {} | DATE_SYM {} | DAY_SYM {} | DEALLOCATE_SYM {} + | DEFINER_SYM {} | DELAY_KEY_WRITE_SYM {} | DES_KEY_FILE {} | DIRECTORY_SYM {} @@ -5162,6 +6888,7 @@ keyword: | EXPANSION_SYM {} | EXTENDED_SYM {} | FAST_SYM {} + | FOUND_SYM {} | DISABLE_SYM {} | ENABLE_SYM {} | FULL {} @@ -5169,6 +6896,7 @@ keyword: | FIRST_SYM {} | FIXED_SYM {} | FLUSH_SYM {} + | FRAC_SECOND_SYM {} | GEOMETRY_SYM {} | GEOMETRYCOLLECTION {} | GET_FORMAT {} @@ -5180,6 +6908,7 @@ keyword: | HOSTS_SYM {} | HOUR_SYM {} | IDENTIFIED_SYM {} + | INVOKER_SYM {} | IMPORT {} | INDEXES {} | ISOLATION {} @@ -5187,6 +6916,8 @@ keyword: | INNOBASE_SYM {} | INSERT_METHOD {} | RELAY_THREAD {} + | LABEL_SYM {} + | LANGUAGE_SYM {} | LAST_SYM {} | LEAVES {} | LEVEL_SYM {} @@ -5214,6 +6945,7 @@ keyword: | MAX_QUERIES_PER_HOUR {} | MAX_UPDATES_PER_HOUR {} | MEDIUM_SYM {} + | MERGE_SYM {} | MICROSECOND_SYM {} | MINUTE_SYM {} | MIN_ROWS {} @@ -5223,6 +6955,7 @@ keyword: | MULTILINESTRING {} | MULTIPOINT {} | MULTIPOLYGON {} + | NAME_SYM {} | NAMES_SYM {} | NATIONAL_SYM {} | NCHAR_SYM {} @@ -5245,6 +6978,7 @@ keyword: | PREV_SYM {} | PROCESS {} | PROCESSLIST_SYM {} + | QUARTER_SYM {} | QUERY_SYM {} | QUICK {} | RAID_0_SYM {} @@ -5261,6 +6995,7 @@ keyword: | RESET_SYM {} | RESOURCES {} | RESTORE_SYM {} + | RETURNS_SYM {} | ROLLBACK_SYM {} | ROLLUP_SYM {} | ROWS_SYM {} @@ -5269,6 +7004,7 @@ keyword: | RTREE_SYM {} | SAVEPOINT_SYM {} | SECOND_SYM {} + | SECURITY_SYM {} | SERIAL_SYM {} | SERIALIZABLE_SYM {} | SESSION_SYM {} @@ -5293,23 +7029,29 @@ keyword: | SUPER_SYM {} | TABLESPACE {} | TEMPORARY {} + | TEMPTABLE_SYM {} | TEXT_SYM {} | TRANSACTION_SYM {} | TRUNCATE_SYM {} | TIMESTAMP {} + | TIMESTAMP_ADD {} + | TIMESTAMP_DIFF {} | TIME_SYM {} | TYPE_SYM {} | TYPES_SYM {} | UDF_RETURNS_SYM {} - | UDF_SYM {} + | FUNCTION_SYM {} | UNCOMMITTED_SYM {} + | UNDEFINED_SYM {} | UNICODE_SYM {} | UNTIL_SYM {} | USER {} | USE_FRM {} | VARIABLES {} + | VIEW_SYM {} | VALUE_SYM {} | WARNINGS {} + | WEEK_SYM {} | WORK_SYM {} | X509_SYM {} | YEAR_SYM {} @@ -5361,15 +7103,107 @@ opt_var_ident_type: ; option_value: - '@' ident_or_text equal expr - { - Lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4))); - } + '@' ident_or_text equal expr + { + LEX *lex= Lex; + + if (lex->sphead && lex->sphead->m_type != TYPE_ENUM_PROCEDURE) + { + /* + We have to use special instruction in functions and triggers + because sp_instr_stmt will close all tables and thus ruin + execution of statement invoking function or trigger. + + We also do not want to allow expression with subselects in + this case. + */ + if (lex->query_tables) + { + send_error(YYTHD, ER_SP_SUBSELECT_NYI); + YYABORT; + } + sp_instr_set_user_var *i= + new sp_instr_set_user_var(lex->sphead->instructions(), + lex->spcont, $2, $4); + lex->sphead->add_instr(i); + } + else + lex->var_list.push_back(new set_var_user(new Item_func_set_user_var($2,$4))); + + } | internal_variable_name equal set_expr_or_default { LEX *lex=Lex; - lex->var_list.push_back(new set_var(lex->option_type, $1.var, - &$1.base_name, $3)); + + if ($1.var == &trg_new_row_fake_var) + { + /* We are in trigger and assigning value to field of new row */ + Item *it; + sp_instr_set_trigger_field *i; + if (lex->query_tables) + { + send_error(YYTHD, ER_SP_SUBSELECT_NYI); + YYABORT; + } + if ($3) + it= $3; + else + { + /* QQ: Shouldn't this be field's default value ? */ + it= new Item_null(); + } + i= new sp_instr_set_trigger_field(lex->sphead->instructions(), + lex->spcont, $1.base_name, it); + if (lex->trg_table && i->setup_field(YYTHD, lex->trg_table, + lex->trg_chistics.event)) + { + /* + FIXME. Now we are catching this kind of errors only + during opening tables. But this doesn't save us from most + common user error - misspelling field name, because we + will bark too late in this case... Moreover it is easy to + make table unusable with such kind of error... + + So in future we either have to parse trigger definition + second time during create trigger or gather all trigger + fields in one list and perform setup_field() for them as + separate stage. + + Error message also should be improved. + */ + net_printf(YYTHD, ER_BAD_FIELD_ERROR, $1.base_name, "NEW"); + YYABORT; + } + lex->sphead->add_instr(i); + } + else if ($1.var) + { /* System variable */ + lex->var_list.push_back(new set_var(lex->option_type, $1.var, + &$1.base_name, $3)); + } + else + { + /* An SP local variable */ + sp_pcontext *ctx= lex->spcont; + sp_pvar_t *spv; + sp_instr_set *i; + Item *it; + + spv= ctx->find_pvar(&$1.base_name); + + if ($3) + it= $3; + else if (spv->dflt) + it= spv->dflt; + else + it= new Item_null(); + i= new sp_instr_set(lex->sphead->instructions(), ctx, + spv->offset, it, spv->type); + i->tables= lex->query_tables; + lex->query_tables= 0; + lex->sphead->add_instr(i); + spv->isset= TRUE; + } } | '@' '@' opt_var_ident_type internal_variable_name equal set_expr_or_default { @@ -5427,33 +7261,76 @@ option_value: internal_variable_name: ident { - sys_var *tmp=find_sys_var($1.str, $1.length); - if (!tmp) - YYABORT; - $$.var= tmp; - $$.base_name.str=0; - $$.base_name.length=0; - /* - If this is time_zone variable we should open time zone - describing tables - */ - if (tmp == &sys_time_zone) - Lex->time_zone_tables_used= &fake_time_zone_tables_list; + LEX *lex= Lex; + sp_pcontext *spc= lex->spcont; + sp_pvar_t *spv; + + /* We have to lookup here since local vars can shadow sysvars */ + if (!spc || !(spv = spc->find_pvar(&$1))) + { + /* Not an SP local variable */ + sys_var *tmp=find_sys_var($1.str, $1.length); + if (!tmp) + YYABORT; + $$.var= tmp; + $$.base_name.str=0; + $$.base_name.length=0; + /* + If this is time_zone variable we should open time zone + describing tables + */ + if (tmp == &sys_time_zone) + Lex->time_zone_tables_used= &fake_time_zone_tables_list; + } + else + { + /* An SP local variable */ + $$.var= NULL; + $$.base_name= $1; + } } | ident '.' ident { + LEX *lex= Lex; if (check_reserved_words(&$1)) { yyerror(ER(ER_SYNTAX_ERROR)); YYABORT; } - sys_var *tmp=find_sys_var($3.str, $3.length); - if (!tmp) - YYABORT; - if (!tmp->is_struct()) - net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str); - $$.var= tmp; - $$.base_name= $1; + if (lex->sphead && lex->sphead->m_type == TYPE_ENUM_TRIGGER && + (!my_strcasecmp(system_charset_info, $1.str, "NEW") || + !my_strcasecmp(system_charset_info, $1.str, "OLD"))) + { + if ($1.str[0]=='O' || $1.str[0]=='o') + { + net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "OLD", ""); + YYABORT; + } + if (lex->trg_chistics.event == TRG_EVENT_DELETE) + { + net_printf(YYTHD, ER_TRG_NO_SUCH_ROW_IN_TRG, "NEW", + "on DELETE"); + YYABORT; + } + if (lex->trg_chistics.action_time == TRG_ACTION_AFTER) + { + net_printf(YYTHD, ER_TRG_CANT_CHANGE_ROW, "NEW", "after "); + YYABORT; + } + /* This special combination will denote field of NEW row */ + $$.var= &trg_new_row_fake_var; + $$.base_name= $3; + } + else + { + sys_var *tmp=find_sys_var($3.str, $3.length); + if (!tmp) + YYABORT; + if (!tmp->is_struct()) + net_printf(YYTHD, ER_VARIABLE_IS_NOT_STRUCT, $3.str); + $$.var= tmp; + $$.base_name= $1; + } } | DEFAULT '.' ident { @@ -5687,8 +7564,10 @@ grant_privilege: | SUPER_SYM { Lex->grant |= SUPER_ACL;} | CREATE TEMPORARY TABLES { Lex->grant |= CREATE_TMP_ACL;} | LOCK_SYM TABLES { Lex->grant |= LOCK_TABLES_ACL; } - | REPLICATION SLAVE { Lex->grant |= REPL_SLAVE_ACL;} - | REPLICATION CLIENT_SYM { Lex->grant |= REPL_CLIENT_ACL;} + | REPLICATION SLAVE { Lex->grant |= REPL_SLAVE_ACL; } + | REPLICATION CLIENT_SYM { Lex->grant |= REPL_CLIENT_ACL; } + | CREATE VIEW_SYM { Lex->grant |= CREATE_VIEW_ACL; } + | SHOW VIEW_SYM { Lex->grant |= SHOW_VIEW_ACL; } ; @@ -6077,3 +7956,47 @@ subselect_end: lex->current_select = lex->current_select->return_after_parsing(); }; +opt_view_list: + /* empty */ {} + | '(' view_list ')' + ; + +view_list: + ident + { + Lex->view_list.push_back((LEX_STRING*) + sql_memdup(&$1, sizeof(LEX_STRING))); + } + | view_list ',' ident + { + Lex->view_list.push_back((LEX_STRING*) + sql_memdup(&$3, sizeof(LEX_STRING))); + } + ; + +or_replace: + /* empty */ { Lex->create_view_mode= VIEW_CREATE_NEW; } + | OR_SYM REPLACE { Lex->create_view_mode= VIEW_CREATE_OR_REPLACE; } + ; + +algorithm: + /* empty */ + { Lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; } + | ALGORITHM_SYM EQ UNDEFINED_SYM + { Lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; } + | ALGORITHM_SYM EQ MERGE_SYM + { Lex->create_view_algorithm= VIEW_ALGORITHM_MERGE; } + | ALGORITHM_SYM EQ TEMPTABLE_SYM + { Lex->create_view_algorithm= VIEW_ALGORITHM_TMPTABLE; } + ; +check_option: + /* empty */ + { Lex->create_view_check= VIEW_CHECK_NONE; } + | WITH CHECK_SYM OPTION + { Lex->create_view_check= VIEW_CHECK_CASCADED; } + | WITH CASCADED CHECK_SYM OPTION + { Lex->create_view_check= VIEW_CHECK_CASCADED; } + | WITH LOCAL_SYM CHECK_SYM OPTION + { Lex->create_view_check= VIEW_CHECK_LOCAL; } + ; + From b95560a8fc3afa3a0355a718826e948a3625de24 Mon Sep 17 00:00:00 2001 From: "pem@mysql.comhem.se" <> Date: Fri, 12 Nov 2004 11:37:59 +0100 Subject: [PATCH 71/94] Build fixes to make it compile. --- sql/handler.cc | 2 +- sql/log_event.cc | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index b2acb262763..b61d28e035a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -656,7 +656,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) } thd->variables.tx_isolation=thd->session_tx_isolation; if (operation_done) - statistic_increment(ha_rollback_count,&LOCK_status); + statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status); thd->proc_info= save_proc_info; } #endif /* USING_TRANSACTIONS */ diff --git a/sql/log_event.cc b/sql/log_event.cc index 7fba19cb000..e8dc6a8827b 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1362,7 +1362,8 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli) Thank you. */ thd->catalog= (char*) catalog; - thd->db= (char*) rewrite_db(db); // thd->db_length is set later if needed + thd->db_length= db_len; + thd->db= (char*) rewrite_db(db, &thd->db_length); thd->variables.auto_increment_increment= auto_increment_increment; thd->variables.auto_increment_offset= auto_increment_offset; From a7ee4f336f3fff4c62079686b43b9ccc5eef6256 Mon Sep 17 00:00:00 2001 From: "pem@mysql.comhem.se" <> Date: Fri, 12 Nov 2004 12:28:34 +0100 Subject: [PATCH 72/94] Various build fixes. --- sql/mysql_priv.h | 4 ++-- sql/net_serv.cc | 2 +- sql/sql_base.cc | 3 ++- sql/sql_show.cc | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 20ede9a623e..7d1ffe97e08 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -566,8 +566,8 @@ int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type, int mysql_union(THD *thd, LEX *lex, select_result *result, SELECT_LEX_UNIT *unit); int mysql_handle_derived(LEX *lex, int (*processor)(THD *thd, - st_lex *lex, - st_table_list *table)); + LEX *lex, + TABLE_LIST *table)); int mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t); int mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t); Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, diff --git a/sql/net_serv.cc b/sql/net_serv.cc index bcb1f8634c0..02fc1691b8b 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -96,7 +96,7 @@ extern void query_cache_insert(NET *net, const char *packet, ulong length); #define update_statistics(A) A #else #define update_statistics(A) -#define thd_increment_bytes_sent() +#define thd_increment_bytes_sent(N) #endif #define TEST_BLOCKING 8 diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b518af80a43..eeb34f6b600 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3056,6 +3056,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) SELECT_LEX *select_lex= thd->lex->current_select; Item_arena *arena= thd->current_arena, backup; bool save_wrapper= thd->lex->current_select->no_wrap_view_item; + TABLE_LIST *table= NULL; // For HP compilers DBUG_ENTER("setup_conds"); if (select_lex->conds_processed_with_permanent_arena || @@ -3075,7 +3076,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) } /* Check if we are using outer joins */ - for (TABLE_LIST *table= tables; table; table= table->next_local) + for (table= tables; table; table= table->next_local) { TABLE_LIST *embedded; TABLE_LIST *embedding= table; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 557ec1bd5d2..7043379bf8f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1965,7 +1965,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, switch (show_type) { case SHOW_LONG_STATUS: case SHOW_LONG_CONST_STATUS: - value= ((char *) status_var + (uint) value); + value= ((char *) status_var + (ulong) value); /* fall through */ case SHOW_LONG: case SHOW_LONG_CONST: From 232abd5f6ee8c1deb83533631441b8a5a91a800d Mon Sep 17 00:00:00 2001 From: "pem@mysql.comhem.se" <> Date: Fri, 12 Nov 2004 13:02:17 +0100 Subject: [PATCH 73/94] Fixed merge bug(?) in mysqldump.c. --- client/mysqldump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 40dfb304a21..3544786ab1c 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -352,7 +352,8 @@ static struct my_option my_long_options[] = {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, - MALLOC_OVERHEAD-1024, 1024, 0} + MALLOC_OVERHEAD-1024, 1024, 0}, + {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; static const char *load_default_groups[]= { "mysqldump","client",0 }; From 31f7811183b6dd197cb7643abbe1b56cec72b602 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Fri, 12 Nov 2004 14:34:00 +0200 Subject: [PATCH 74/94] post-review fixes --- mysql-test/r/rpl_rotate_logs.result | 2 +- mysql-test/t/rpl_rotate_logs.test | 1 + mysys/my_error.c | 12 ++ sql/filesort.cc | 3 +- sql/ha_innodb.cc | 6 +- sql/handler.cc | 23 ++- sql/item.cc | 34 ++-- sql/item_cmpfunc.cc | 9 +- sql/item_func.cc | 29 +-- sql/item_strfunc.cc | 17 +- sql/item_subselect.cc | 3 +- sql/item_sum.cc | 9 +- sql/lock.cc | 6 +- sql/log.cc | 5 +- sql/mysql_priv.h | 10 +- sql/mysqld.cc | 3 +- sql/parse_file.cc | 39 ++-- sql/protocol.cc | 3 +- sql/protocol_cursor.cc | 3 +- sql/repl_failsafe.cc | 28 +-- sql/set_var.cc | 69 ++++--- sql/slave.cc | 14 +- sql/sp.cc | 3 +- sql/sp_head.cc | 7 +- sql/sp_rcontext.cc | 15 +- sql/sql_acl.cc | 81 ++++---- sql/sql_analyse.cc | 15 +- sql/sql_base.cc | 79 ++++++-- sql/sql_class.cc | 17 +- sql/sql_class.h | 4 +- sql/sql_db.cc | 32 ++-- sql/sql_delete.cc | 26 +-- sql/sql_handler.cc | 4 +- sql/sql_help.cc | 2 +- sql/sql_insert.cc | 38 ++-- sql/sql_lex.cc | 2 +- sql/sql_load.cc | 9 +- sql/sql_map.cc | 8 +- sql/sql_parse.cc | 283 +++++++++++++++++----------- sql/sql_prepare.cc | 2 +- sql/sql_rename.cc | 9 +- sql/sql_repl.cc | 29 +-- sql/sql_select.cc | 18 +- sql/sql_show.cc | 13 +- sql/sql_table.cc | 135 ++++++++----- sql/sql_trigger.cc | 14 +- sql/sql_udf.cc | 23 ++- sql/sql_union.cc | 2 +- sql/sql_update.cc | 54 +++--- sql/sql_view.cc | 36 ++-- sql/sql_yacc.yy | 217 +++++++++++++-------- sql/table.cc | 22 ++- sql/unireg.cc | 4 +- 53 files changed, 938 insertions(+), 593 deletions(-) diff --git a/mysql-test/r/rpl_rotate_logs.result b/mysql-test/r/rpl_rotate_logs.result index 29dd1ead381..cfd296fd44b 100644 --- a/mysql-test/r/rpl_rotate_logs.result +++ b/mysql-test/r/rpl_rotate_logs.result @@ -1,7 +1,7 @@ drop table if exists t1, t2, t3, t4; drop table if exists t1, t2, t3, t4; start slave; -ERROR HY000: File '/home/bell/mysql/bk/work-error-5.0/mysql-test/var/slave-data/master.info' not found (Errcode: 13) +ERROR HY000: File 'TESTDIR/var/slave-data/master.info' not found (Errcode: 13) start slave; ERROR HY000: Could not initialize master info structure; more error messages can be found in the MySQL error log change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root'; diff --git a/mysql-test/t/rpl_rotate_logs.test b/mysql-test/t/rpl_rotate_logs.test index 4bb1acbf748..63ddf495347 100644 --- a/mysql-test/t/rpl_rotate_logs.test +++ b/mysql-test/t/rpl_rotate_logs.test @@ -23,6 +23,7 @@ drop table if exists t1, t2, t3, t4; # START SLAVE will fail because it can't read the file (mode 000) # (system error 13) +--replace_result $MYSQL_TEST_DIR TESTDIR --error 1105 start slave; system chmod 600 var/slave-data/master.info; diff --git a/mysys/my_error.c b/mysys/my_error.c index 8a377f63c7e..75aa84efca0 100644 --- a/mysys/my_error.c +++ b/mysys/my_error.c @@ -22,6 +22,18 @@ /* Define some external variables for error handling */ +/* + WARNING! + my_error family functions have to be used according following rules: + - if message have not parameters use my_message(ER_CODE, ER(ER_CODE), MYF(N)) + - if message have only integer parameters, string constants (created + inside program) or string put (and cut if it is need) in some limited + length buffer before passing it as parameter then you can use + my_error(ER_CODE, MYF(N), ...). Never pass string get from user to + my_error. + - in all other cases use my_printf_error(ER_CODE, ER(ER_CODE), MYF(N), ...) +*/ + const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; diff --git a/sql/filesort.cc b/sql/filesort.cc index ef8148616e5..09d51e31291 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -278,7 +278,8 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, } } if (error) - my_error(ER_FILSORT_ABORT,MYF(ME_ERROR+ME_WAITTANG)); + my_message(ER_FILSORT_ABORT, ER(ER_FILSORT_ABORT), + MYF(ME_ERROR+ME_WAITTANG)); else statistic_add(thd->status_var.filesort_rows, (ulong) records, &LOCK_status); diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 547acb63766..c93edef0795 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -462,8 +462,10 @@ innobase_mysql_tmpfile(void) if (fd2 < 0) { DBUG_PRINT("error",("Got error %d on dup",fd2)); my_errno=errno; - my_error(EE_OUT_OF_FILERESOURCES, - MYF(ME_BELL+ME_WAITTANG), filename, my_errno); + my_printf_error(EE_OUT_OF_FILERESOURCES, + ER(EE_OUT_OF_FILERESOURCES), + MYF(ME_BELL+ME_WAITTANG), + filename, my_errno); } my_close(fd, MYF(MY_WME)); } diff --git a/sql/handler.cc b/sql/handler.cc index 5185e7f8921..62b6b591b3d 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -515,7 +515,8 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) if ((error=ndbcluster_commit(thd,trans->ndb_tid))) { if (error == -1) - my_error(ER_ERROR_DURING_COMMIT, MYF(0)); + my_message_(ER_ERROR_DURING_COMMIT, ER(ER_ERROR_DURING_COMMIT), + MYF(0)); error=1; } if (trans == &thd->transaction.all) @@ -584,7 +585,8 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) if ((error=ndbcluster_rollback(thd, trans->ndb_tid))) { if (error == -1) - my_error(ER_ERROR_DURING_ROLLBACK, MYF(0)); + my_message(ER_ERROR_DURING_ROLLBACK, ER(ER_ERROR_DURING_ROLLBACK), + MYF(0)); error=1; } trans->ndb_tid = 0; @@ -1183,7 +1185,8 @@ void handler::print_error(int error, myf errflag) str.length(max_length-4); str.append("..."); } - my_error(ER_DUP_ENTRY,MYF(0),str.c_ptr(),key_nr+1); + my_printf_error(ER_DUP_ENTRY, ER(ER_DUP_ENTRY), MYF(0), + str.c_ptr(), key_nr+1); DBUG_VOID_RETURN; } textno=ER_DUP_KEY; @@ -1205,7 +1208,7 @@ void handler::print_error(int error, myf errflag) textno=ER_CRASHED_ON_REPAIR; break; case HA_ERR_OUT_OF_MEM: - my_error(ER_OUT_OF_RESOURCES,errflag); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), errflag); DBUG_VOID_RETURN; case HA_ERR_WRONG_COMMAND: textno=ER_ILLEGAL_HA; @@ -1251,9 +1254,13 @@ void handler::print_error(int error, myf errflag) { const char* engine= table_type(); if (temporary) - my_error(ER_GET_TEMPORARY_ERRMSG,MYF(0),error,str.ptr(),engine); + my_printf_error(ER_GET_TEMPORARY_ERRMSG, + ER(ER_GET_TEMPORARY_ERRMSG), MYF(0), + error, str.ptr(), engine); else - my_error(ER_GET_ERRMSG,MYF(0),error,str.ptr(),engine); + my_printf_error(ER_GET_ERRMSG, + ER(ER_GET_ERRMSG), MYF(0), + error, str.ptr(), engine); } else my_error(ER_GET_ERRNO,errflag,error); @@ -1381,7 +1388,9 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, error=table.file->create(name,&table,create_info); VOID(closefrm(&table)); if (error) - my_error(ER_CANT_CREATE_TABLE,MYF(ME_BELL+ME_WAITTANG),name,error); + my_printf_error(ER_CANT_CREATE_TABLE, ER(ER_CANT_CREATE_TABLE), + MYF(ME_BELL+ME_WAITTANG), + name,error); DBUG_RETURN(error != 0); } diff --git a/sql/item.cc b/sql/item.cc index 7279c18099b..ff6b74144a8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1512,8 +1512,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { if (!(*refer)->fixed) { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, - "forward reference in item list"); + my_printf_error(ER_ILLEGAL_REFERENCE, ER(ER_ILLEGAL_REFERENCE), + MYF(0), name, "forward reference in item list"); return TRUE; } @@ -2418,8 +2418,9 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) { if (!(*ref)->fixed) { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, - "forward reference in item list"); + my_printf_error(ER_ILLEGAL_REFERENCE, + ER(ER_ILLEGAL_REFERENCE), MYF(0), + name, "forward reference in item list"); return TRUE; } mark_as_dependent(thd, last, thd->lex->current_select, @@ -2433,8 +2434,9 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) { if (!(*ref)->fixed) { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, - "forward reference in item list"); + my_printf_error(ER_ILLEGAL_REFERENCE, + ER(ER_ILLEGAL_REFERENCE), MYF(0), + name, "forward reference in item list"); return TRUE; } ref= thd->lex->current_select->ref_pointer_array + counter; @@ -2454,10 +2456,11 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) thd->lex->current_select->having_fix_field))) || !(*ref)->fixed) { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), name, - ((*ref)->with_sum_func? - "reference on group function": - "forward reference in item list")); + my_printf_error(ER_ILLEGAL_REFERENCE, ER(ER_ILLEGAL_REFERENCE), MYF(0), + name, + ((*ref)->with_sum_func? + "reference on group function": + "forward reference in item list")); return TRUE; } max_length= (*ref)->max_length; @@ -3115,11 +3118,12 @@ bool Item_type_holder::join_types(THD *thd, Item *item) *old_derivation= collation.derivation_name(); if (item_type == STRING_RESULT && collation.aggregate(item->collation)) { - my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), - old_cs, old_derivation, - item->collation.collation->name, - item->collation.derivation_name(), - "UNION"); + my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, + ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), + old_cs, old_derivation, + item->collation.collation->name, + item->collation.derivation_name(), + "UNION"); return 1; } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index f680ab1f20f..59d21cdfc59 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -53,10 +53,11 @@ static void agg_cmp_type(Item_result *type, Item **items, uint nitems) static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), - c1.collation->name,c1.derivation_name(), - c2.collation->name,c2.derivation_name(), - fname); + my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, + ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), + c1.collation->name,c1.derivation_name(), + c2.collation->name,c2.derivation_name(), + fname); } diff --git a/sql/item_func.cc b/sql/item_func.cc index b09824fb184..f9cf7341405 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -45,10 +45,11 @@ bool check_reserved_words(LEX_STRING *name) static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), - c1.collation->name,c1.derivation_name(), - c2.collation->name,c2.derivation_name(), - fname); + my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, + ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + fname); } static void my_coll_agg_error(DTCollation &c1, @@ -56,11 +57,12 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c3, const char *fname) { - my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0), - c1.collation->name,c1.derivation_name(), - c2.collation->name,c2.derivation_name(), - c3.collation->name,c3.derivation_name(), - fname); + my_printf_error(ER_CANT_AGGREGATE_3COLLATIONS, + ER(ER_CANT_AGGREGATE_3COLLATIONS), MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + c3.collation->name, c3.derivation_name(), + fname); } @@ -74,7 +76,8 @@ static void my_coll_agg_error(Item** args, uint count, const char *fname) args[2]->collation, fname); else - my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname); + my_printf_error(ER_CANT_AGGREGATE_NCOLLATIONS, + ER(ER_CANT_AGGREGATE_NCOLLATIONS), MYF(0),fname); } @@ -3112,7 +3115,8 @@ err: key=NO_SUCH_KEY; return 0; } - my_error(ER_FT_MATCHING_KEY_NOT_FOUND,MYF(0)); + my_message(ER_FT_MATCHING_KEY_NOT_FOUND, + ER(ER_FT_MATCHING_KEY_NOT_FOUND), MYF(0)); return 1; } @@ -3241,7 +3245,8 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, { if (!var->is_struct()) { - my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str); + my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, ER(ER_VARIABLE_IS_NOT_STRUCT), + MYF(0), base_name->str); return 0; } } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b3665edad39..6e9467a7a71 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -42,10 +42,11 @@ String my_empty_string("",default_charset_info); static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), - c1.collation->name,c1.derivation_name(), - c2.collation->name,c2.derivation_name(), - fname); + my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, + ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + fname); } uint nr_of_decimals(const char *str) @@ -2243,7 +2244,8 @@ void Item_func_set_collation::fix_length_and_dec() { if (!(set_collation= get_charset_by_name(colname,MYF(0)))) { - my_error(ER_UNKNOWN_COLLATION, MYF(0), colname); + my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), + colname); return; } } @@ -2251,8 +2253,9 @@ void Item_func_set_collation::fix_length_and_dec() if (!set_collation || !my_charset_same(args[0]->collation.collation,set_collation)) { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - colname,args[0]->collation.collation->csname); + my_printf_error(ER_COLLATION_CHARSET_MISMATCH, + ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), + colname, args[0]->collation.collation->csname); return; } collation.set(set_collation, DERIVATION_EXPLICIT); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8fe6e5c81dd..d2d9aa8c8b6 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -167,7 +167,8 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref) // We can't substitute aggregate functions like "SELECT (max(i))" if (substype() == SINGLEROW_SUBS && (*ref)->with_sum_func) { - my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0)); + my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + MYF(0)); return TRUE; } return ret; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index b355cc15806..8ec2e8fa9d9 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -220,7 +220,8 @@ Item_sum_num::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!thd->allow_sum_func) { - my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); + my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + MYF(0)); return TRUE; } thd->allow_sum_func=0; // No included group funcs @@ -255,7 +256,8 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) Item *item= args[0]; if (!thd->allow_sum_func) { - my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); + my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + MYF(0)); return TRUE; } thd->allow_sum_func=0; // No included group funcs @@ -2065,7 +2067,8 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!thd->allow_sum_func) { - my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0)); + my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), + MYF(0)); return TRUE; } diff --git a/sql/lock.cc b/sql/lock.cc index debfb900c23..e11c48a7a7e 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -430,7 +430,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, *write_lock_used=table; if (table->db_stat & HA_READ_ONLY) { - my_error(ER_OPEN_AS_READONLY,MYF(0),table->table_name); + my_printf_error(ER_OPEN_AS_READONLY, ER(ER_OPEN_AS_READONLY), MYF(0), + table->table_name); my_free((gptr) sql_lock,MYF(0)); return 0; } @@ -794,7 +795,8 @@ bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh, { if (thd->global_read_lock) // This thread had the read locks { - my_error(ER_CANT_UPDATE_WITH_READLOCK,MYF(0)); + my_message(ER_CANT_UPDATE_WITH_READLOCK, + ER(ER_CANT_UPDATE_WITH_READLOCK), MYF(0)); (void) pthread_mutex_unlock(&LOCK_open); DBUG_RETURN(1); } diff --git a/sql/log.cc b/sql/log.cc index ab080366f95..429ef8bd339 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1515,9 +1515,10 @@ err: if (error) { if (my_errno == EFBIG) - my_error(ER_TRANS_CACHE_FULL, MYF(0)); + my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(0)); else - my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno); + my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), + name, errno); write_error=1; } if (file == &log_file) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index a8ca32f3d7e..aa6ce7ba888 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -608,8 +608,8 @@ bool mysql_rename_table(enum db_type base, bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys); bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info); -int mysql_prepare_update(THD *thd, TABLE_LIST *table_list, - Item **conds, uint order_num, ORDER *order); +bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, + Item **conds, uint order_num, ORDER *order); bool mysql_update(THD *thd,TABLE_LIST *tables,List &fields, List &values,COND *conds, uint order_num, ORDER *order, ha_rows limit, @@ -813,8 +813,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table, bool return_if_owned_by_thd=0); bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables); void copy_field_from_tmp_record(Field *field,int offset); -int fill_record(List &fields,List &values, bool ignore_errors); -int fill_record(Field **field,List &values, bool ignore_errors); +bool fill_record(THD *thd, List &fields, List &values, + bool ignore_errors); +bool fill_record(THD *thd, Field **field, List &values, + bool ignore_errors); OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild); inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f2c235cac99..4a8c12b5d76 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1145,7 +1145,8 @@ static void server_init(void) WSADATA WsaData; if (SOCKET_ERROR == WSAStartup (0x0101, &WsaData)) { - my_error(ER_WSAS_FAILED, MYF(0)); + /* errors are not read yet, so we use test here */ + my_message(ER_WSAS_FAILED, "WSAStartup Failed", MYF(0)); unireg_abort(1); } } diff --git a/sql/parse_file.cc b/sql/parse_file.cc index f548c16d808..61b5b301503 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -350,7 +350,8 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, if (stat_info.st_size > INT_MAX-1) { - my_error(ER_FPARSER_TOO_BIG_FILE, MYF(0), file_name->str); + my_printf_error(ER_FPARSER_TOO_BIG_FILE, + ER(ER_FPARSER_TOO_BIG_FILE), MYF(0), file_name->str); DBUG_RETURN(0); } @@ -412,7 +413,8 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, frm_error: if (bad_format_errors) { - my_error(ER_FPARSER_BAD_HEADER, MYF(0), file_name->str); + my_printf_error(ER_FPARSER_BAD_HEADER, ER(ER_FPARSER_BAD_HEADER), MYF(0), + file_name->str); DBUG_RETURN(0); } else @@ -627,7 +629,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, // it is comment if (!(ptr= strchr(ptr, '\n'))) { - my_error(ER_FPARSER_EOF_IN_COMMENT, MYF(0), line); + my_printf_error(ER_FPARSER_EOF_IN_COMMENT, + ER(ER_FPARSER_EOF_IN_COMMENT), MYF(0), line); DBUG_RETURN(TRUE); } ptr++; @@ -669,8 +672,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, (LEX_STRING *)(base + parameter->offset)))) { - my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), - parameter->name.str, line); + my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, + ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } break; @@ -681,8 +685,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, (LEX_STRING *) (base + parameter->offset)))) { - my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), - parameter->name.str, line); + my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, + ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } break; @@ -691,8 +696,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, case FILE_OPTIONS_REV: if (!(eol= strchr(ptr, '\n'))) { - my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), - parameter->name.str, line); + my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, + ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } { @@ -709,8 +715,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, /* yyyy-mm-dd HH:MM:SS = 19(PARSE_FILE_TIMESTAMPLENGTH) characters */ if (ptr[PARSE_FILE_TIMESTAMPLENGTH] != '\n') { - my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), - parameter->name.str, line); + my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, + ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } memcpy(val->str, ptr, PARSE_FILE_TIMESTAMPLENGTH); @@ -763,8 +770,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, break; list_err_w_message: - my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), - parameter->name.str, line); + my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, + ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), + parameter->name.str, line); list_err: if (change_mem) my_pthread_setspecific_ptr(THR_MALLOC, sql_mem); @@ -779,8 +787,9 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, // skip unknown parameter if (!(ptr= strchr(ptr, '\n'))) { - my_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, MYF(0), - line); + my_printf_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, + ER(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER), MYF(0), + line); DBUG_RETURN(TRUE); } ptr++; diff --git a/sql/protocol.cc b/sql/protocol.cc index b8414e45c97..710618b0647 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -611,7 +611,8 @@ bool Protocol::send_fields(List *list, int flags) DBUG_RETURN(prepare_for_send(list)); err: - my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), + MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } diff --git a/sql/protocol_cursor.cc b/sql/protocol_cursor.cc index 0954bb5466f..3106420a0e5 100644 --- a/sql/protocol_cursor.cc +++ b/sql/protocol_cursor.cc @@ -85,7 +85,8 @@ bool Protocol_cursor::send_fields(List *list, int flags) DBUG_RETURN(FALSE); err: - my_error(ER_OUT_OF_RESOURCES, MYF(0)); /* purecov: inspected */ + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), + MYF(0)); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */ } diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 6ba1ce6267f..0d6ed33e952 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -451,8 +451,9 @@ bool show_new_master(THD* thd) if (translate_master(thd, lex_mi, errmsg)) { if (errmsg[0]) - my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), - "SHOW NEW MASTER", errmsg); + my_printf_error(ER_ERROR_WHEN_EXECUTING_COMMAND, + ER(ER_ERROR_WHEN_EXECUTING_COMMAND), MYF(0), + "SHOW NEW MASTER", errmsg); DBUG_RETURN(TRUE); } else @@ -783,7 +784,7 @@ bool load_master_data(THD* thd) (error=terminate_slave_threads(active_mi,restart_thread_mask, 1 /*skip lock*/))) { - my_error(error, MYF(0)); + my_message(error, ER(error), MYF(0)); unlock_slave_threads(active_mi); pthread_mutex_unlock(&LOCK_active_mi); return TRUE; @@ -791,7 +792,8 @@ bool load_master_data(THD* thd) if (connect_to_master(thd, &mysql, active_mi)) { - my_error(error= ER_CONNECT_TO_MASTER, MYF(0), mysql_error(&mysql)); + my_printf_error(error= ER_CONNECT_TO_MASTER, + ER(ER_CONNECT_TO_MASTER), MYF(0), mysql_error(&mysql)); goto err; } @@ -803,7 +805,8 @@ bool load_master_data(THD* thd) if (mysql_real_query(&mysql, "SHOW DATABASES", 14) || !(db_res = mysql_store_result(&mysql))) { - my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); + my_printf_error(error = ER_QUERY_ON_MASTER, + ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); goto err; } @@ -816,7 +819,7 @@ bool load_master_data(THD* thd) if (!(table_res = (MYSQL_RES**)thd->alloc(num_dbs * sizeof(MYSQL_RES*)))) { - my_error(error = ER_OUTOFMEMORY, MYF(0)); + my_message(error = ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0)); goto err; } @@ -830,7 +833,8 @@ bool load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW MASTER STATUS",18) || !(master_status_res = mysql_store_result(&mysql))) { - my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); + my_printf_error(error = ER_QUERY_ON_MASTER, + ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); goto err; } @@ -883,7 +887,8 @@ bool load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW TABLES", 11) || !(*cur_table_res = mysql_store_result(&mysql))) { - my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); + my_printf_error(error = ER_QUERY_ON_MASTER, + ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); cleanup_mysql_results(db_res, cur_table_res - 1, table_res); goto err; } @@ -921,7 +926,7 @@ bool load_master_data(THD* thd) if (init_master_info(active_mi, master_info_file, relay_log_info_file, 0)) - my_error(ER_MASTER_INFO, MYF(0)); + my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0)); strmake(active_mi->master_log_name, row[0], sizeof(active_mi->master_log_name)); active_mi->master_log_pos= my_strtoll10(row[1], (char**) 0, &error); @@ -940,7 +945,8 @@ bool load_master_data(THD* thd) if (mysql_real_query(&mysql, "UNLOCK TABLES", 13)) { - my_error(error = ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); + my_printf_error(error = ER_QUERY_ON_MASTER, + ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); goto err; } } @@ -949,7 +955,7 @@ bool load_master_data(THD* thd) 0 /* not only reset, but also reinit */, &errmsg)) { - my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); + my_printf_error(ER_RELAY_LOG_FAIL, ER(ER_RELAY_LOG_FAIL), MYF(0), errmsg); unlock_slave_threads(active_mi); pthread_mutex_unlock(&LOCK_active_mi); return TRUE; diff --git a/sql/set_var.cc b/sql/set_var.cc index 8195792419e..59ca464182d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -884,8 +884,8 @@ bool sys_var_str::check(THD *thd, set_var *var) return 0; if ((res=(*check_func)(thd, var)) < 0) - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, - var->value->str_value.ptr()); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), + name, var->value->str_value.ptr()); return res; } @@ -1159,7 +1159,8 @@ static int check_max_delayed_threads(THD *thd, set_var *var) val != (longlong) global_system_variables.max_insert_delayed_threads) { char buf[64]; - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf)); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), + MYF(0), var->var->name, llstr(val, buf)); return 1; } return 0; @@ -1457,7 +1458,8 @@ bool sys_var::check_enum(THD *thd, set_var *var, TYPELIB *enum_names) return 0; err: - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), + name, value); return 1; } @@ -1496,7 +1498,8 @@ bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) return 0; err: - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), + MYF(0), name, buff); return 1; } @@ -1520,8 +1523,9 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) { if (var_type != OPT_DEFAULT) { - my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), - name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); + my_printf_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, + ER(ER_INCORRECT_GLOBAL_LOCAL_VAR), MYF(0), + name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); return 0; } /* As there was no local variable, return the global value */ @@ -1564,7 +1568,8 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) return tmp; } default: - my_error(ER_VAR_CANT_BE_READ, MYF(0), name); + my_printf_error(ER_VAR_CANT_BE_READ, ER(ER_VAR_CANT_BE_READ), MYF(0), + name); } return 0; } @@ -1676,7 +1681,8 @@ bool sys_var_thd_date_time_format::check(THD *thd, set_var *var) if (!(format= date_time_format_make(date_time_type, res->ptr(), res->length()))) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr()); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), + name, res->c_ptr()); return 1; } @@ -1774,12 +1780,14 @@ bool sys_var_collation::check(THD *thd, set_var *var) String str(buff,sizeof(buff), system_charset_info), *res; if (!(res=var->value->val_str(&str))) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), + MYF(0), name, "NULL"); return 1; } if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) { - my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr()); + my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), + res->c_ptr()); return 1; } } @@ -1789,7 +1797,8 @@ bool sys_var_collation::check(THD *thd, set_var *var) { char buf[20]; int10_to_str((int) var->value->val_int(), buf, -10); - my_error(ER_UNKNOWN_COLLATION, MYF(0), buf); + my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), + buf); return 1; } } @@ -1810,7 +1819,8 @@ bool sys_var_character_set::check(THD *thd, set_var *var) { if (!nullable) { - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); + my_printf_error(ER_WRONG_VALUE_FOR_VAR, + ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), name, "NULL"); return 1; } tmp= NULL; @@ -1818,7 +1828,8 @@ bool sys_var_character_set::check(THD *thd, set_var *var) else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && !(tmp=get_old_charset_by_name(res->c_ptr()))) { - my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); + my_printf_error(ER_UNKNOWN_CHARACTER_SET, ER(ER_UNKNOWN_CHARACTER_SET), + MYF(0), res->c_ptr()); return 1; } } @@ -2336,7 +2347,7 @@ bool sys_var_slave_skip_counter::check(THD *thd, set_var *var) pthread_mutex_lock(&active_mi->rli.run_lock); if (active_mi->rli.slave_running) { - my_error(ER_SLAVE_MUST_STOP, MYF(0)); + my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0)); result=1; } pthread_mutex_unlock(&active_mi->rli.run_lock); @@ -2415,7 +2426,8 @@ bool sys_var_thd_time_zone::check(THD *thd, set_var *var) if (!(var->save_result.time_zone= my_tz_find(res, thd->lex->time_zone_tables_used))) { - my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL"); + my_printf_error(ER_UNKNOWN_TIME_ZONE, ER(ER_UNKNOWN_TIME_ZONE), MYF(0), + res ? res->c_ptr() : "NULL"); return 1; } return 0; @@ -2697,7 +2709,8 @@ sys_var *find_sys_var(const char *str, uint length) length ? length : strlen(str)); if (!var) - my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); + my_printf_error(ER_UNKNOWN_SYSTEM_VARIABLE, ER(ER_UNKNOWN_SYSTEM_VARIABLE), + MYF(0), (char*) str); return var; } @@ -2783,9 +2796,8 @@ int set_var::check(THD *thd) { if (var->check_type(type)) { - my_error(type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE, - MYF(0), - var->name); + int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; + my_printf_error(err, ER(err), MYF(0), var->name); return -1; } if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL))) @@ -2795,7 +2807,7 @@ int set_var::check(THD *thd) { if (var->check_default(type)) { - my_error(ER_NO_DEFAULT, MYF(0), var->name); + my_printf_error(ER_NO_DEFAULT, ER(ER_NO_DEFAULT), MYF(0), var->name); return -1; } return 0; @@ -2805,7 +2817,8 @@ int set_var::check(THD *thd) return -1; if (var->check_update_type(value->result_type())) { - my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name); + my_printf_error(ER_WRONG_TYPE_FOR_VAR, ER(ER_WRONG_TYPE_FOR_VAR), MYF(0), + var->name); return -1; } return var->check(thd, this) ? -1 : 0; @@ -2828,9 +2841,8 @@ int set_var::light_check(THD *thd) { if (var->check_type(type)) { - my_error(type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE, - MYF(0), - var->name); + int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; + my_printf_error(err, ER(err), MYF(0), var->name); return -1; } if (type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)) @@ -2896,7 +2908,7 @@ int set_var_user::update(THD *thd) if (user_var_item->update()) { /* Give an error if it's not given already */ - my_error(ER_SET_CONSTANTS_ONLY, MYF(0)); + my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0)); return -1; } return 0; @@ -2957,8 +2969,9 @@ bool sys_var_thd_storage_engine::check(THD *thd, set_var *var) value= "unknown"; err: - my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value); - return 1; + my_printf_error(ER_UNKNOWN_STORAGE_ENGINE, ER(ER_UNKNOWN_STORAGE_ENGINE), + MYF(0), value); + return 1; } diff --git a/sql/slave.cc b/sql/slave.cc index 2ed554e65c8..68e51eacc1e 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1489,7 +1489,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, packet_len= my_net_read(net); // read create table statement if (packet_len == packet_error) { - my_error(ER_MASTER_NET_READ, MYF(0)); + my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0)); DBUG_RETURN(1); } if (net->read_pos[0] == 255) // error from master @@ -1498,7 +1498,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, err_msg= (char*) net->read_pos + ((mysql->server_capabilities & CLIENT_PROTOCOL_41) ? 3+SQLSTATE_LENGTH+1 : 3); - my_error(ER_MASTER, MYF(0), err_msg); + my_printf_error(ER_MASTER, ER(ER_MASTER), MYF(0), err_msg); DBUG_RETURN(1); } thd->command = COM_TABLE_DUMP; @@ -1507,7 +1507,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, if (!(query = thd->strmake((char*) net->read_pos, packet_len))) { sql_print_error("create_table_from_dump: out of memory"); - my_error(ER_GET_ERRNO, MYF(0), "Out of memory"); + my_message(ER_GET_ERRNO, "Out of memory", MYF(0)); DBUG_RETURN(1); } thd->query= query; @@ -1552,7 +1552,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, /* Copy the data file */ if (file->net_read_dump(net)) { - my_error(ER_MASTER_NET_READ, MYF(0)); + my_message(ER_MASTER_NET_READ, ER(ER_MASTER_NET_READ), MYF(0)); sql_print_error("create_table_from_dump: failed in\ handler::net_read_dump()"); goto err; @@ -1572,7 +1572,8 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, error=file->repair(thd,&check_opt) != 0; thd->net.vio = save_vio; if (error) - my_error(ER_INDEX_REBUILD, MYF(0), tables.table->real_name); + my_printf_error(ER_INDEX_REBUILD, ER(ER_INDEX_REBUILD), MYF(0), + tables.table->real_name); err: close_thread_tables(thd); @@ -1599,7 +1600,8 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, } if (connect_to_master(thd, mysql, mi)) { - my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql)); + my_printf_error(ER_CONNECT_TO_MASTER, ER(ER_CONNECT_TO_MASTER), MYF(0), + mysql_error(mysql)); mysql_close(mysql); DBUG_RETURN(1); } diff --git a/sql/sp.cc b/sql/sp.cc index db03900f44a..4f937e0ad8e 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1001,7 +1001,8 @@ sp_cache_functions(THD *thd, LEX *lex) { delete newlex; thd->lex= oldlex; - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", ls->str); + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), + "FUNCTION", ls->str); ret= 1; break; } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 30c7524032f..9ca986a0f6a 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -623,7 +623,7 @@ sp_head::execute_procedure(THD *thd, List *args) if (args->elements != params) { - my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), + my_printf_error(ER_SP_WRONG_NO_OF_ARGS, ER(ER_SP_WRONG_NO_OF_ARGS), MYF(0), "PROCEDURE", m_name.str, params, args->elements); DBUG_RETURN(-1); } @@ -893,7 +893,8 @@ sp_head::check_backpatch(THD *thd) { if (bp->lab->type == SP_LAB_REF) { - my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "GOTO", bp->lab->name); + my_printf_error(ER_SP_LILABEL_MISMATCH, ER(ER_SP_LILABEL_MISMATCH), + MYF(0), "GOTO", bp->lab->name); return -1; } } @@ -1786,7 +1787,7 @@ sp_instr_error::execute(THD *thd, uint *nextp) { DBUG_ENTER("sp_instr_error::execute"); - my_error(m_errcode, MYF(0)); + my_message(m_errcode, ER(m_errcode), MYF(0)); *nextp= m_ip+1; DBUG_RETURN(-1); } diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index db298974c45..609882b84c6 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -153,7 +153,8 @@ sp_cursor::pre_open(THD *thd) { if (m_isopen) { - my_error(ER_SP_CURSOR_ALREADY_OPEN, MYF(0)); + my_message(ER_SP_CURSOR_ALREADY_OPEN, ER(ER_SP_CURSOR_ALREADY_OPEN), + MYF(0)); return NULL; } @@ -187,7 +188,7 @@ sp_cursor::close(THD *thd) { if (! m_isopen) { - my_error(ER_SP_CURSOR_NOT_OPEN, MYF(0)); + my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0)); return -1; } destroy(); @@ -217,12 +218,12 @@ sp_cursor::fetch(THD *thd, List *vars) if (! m_isopen) { - my_error(ER_SP_CURSOR_NOT_OPEN, MYF(0)); + my_message(ER_SP_CURSOR_NOT_OPEN, ER(ER_SP_CURSOR_NOT_OPEN), MYF(0)); return -1; } if (m_current_row == NULL) { - my_error(ER_SP_FETCH_NO_DATA, MYF(0)); + my_message(ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA), MYF(0)); return -1; } @@ -234,7 +235,8 @@ sp_cursor::fetch(THD *thd, List *vars) if (fldcount >= m_prot->get_field_count()) { - my_error(ER_SP_WRONG_NO_OF_FETCH_ARGS, MYF(0)); + my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS, + ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); return -1; } s= row[fldcount]; @@ -260,7 +262,8 @@ sp_cursor::fetch(THD *thd, List *vars) } if (fldcount < m_prot->get_field_count()) { - my_error(ER_SP_WRONG_NO_OF_FETCH_ARGS, MYF(0)); + my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS, + ER(ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); return -1; } m_current_row= m_current_row->next; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 5a419746b5d..8092c93c11e 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1237,7 +1237,8 @@ bool check_change_password(THD *thd, const char *host, const char *user, } if (!thd->slave_thread && !thd->user[0]) { - my_error(ER_PASSWORD_ANONYMOUS_USER, MYF(0)); + my_message(ER_PASSWORD_ANONYMOUS_USER, ER(ER_PASSWORD_ANONYMOUS_USER), + MYF(0)); return(1); } uint len=strlen(new_password); @@ -1282,7 +1283,7 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(acl_user= find_acl_user(host, user))) { VOID(pthread_mutex_unlock(&acl_cache->lock)); - my_error(ER_PASSWORD_NO_MATCH, MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(1); } /* update loaded acl entry: */ @@ -1467,7 +1468,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user, (byte*) table->field[0]->ptr,0, HA_READ_KEY_EXACT)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */ + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + MYF(0)); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } store_record(table,record[1]); @@ -1549,10 +1551,12 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, if (!create_user) { if (what == 'N') - my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); + my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRANT), + MYF(0), combo.user.str, combo.host.str); else - my_error(ER_NO_PERMISSION_TO_CREATE_USER, MYF(0), - thd->user, thd->host_or_ip); + my_printf_error(ER_NO_PERMISSION_TO_CREATE_USER, + ER(ER_NO_PERMISSION_TO_CREATE_USER), MYF(0), + thd->user, thd->host_or_ip); goto end; } old_row_exists = 0; @@ -1717,7 +1721,7 @@ static int replace_db_table(TABLE *table, const char *db, /* Check if there is such a user in user table in memory? */ if (!find_acl_user(combo.host.str,combo.user.str)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(-1); } @@ -1729,7 +1733,8 @@ static int replace_db_table(TABLE *table, const char *db, { if (what == 'N') { // no row, no revoke - my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); + my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRANT), MYF(0), + combo.user.str, combo.host.str); goto abort; } old_row_exists = 0; @@ -2036,8 +2041,10 @@ static int replace_column_table(GRANT_TABLE *g_t, { if (revoke_grant) { - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - combo.user.str, combo.host.str, table_name); /* purecov: inspected */ + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: inspected */ result= -1; /* purecov: inspected */ continue; /* purecov: inspected */ } @@ -2180,7 +2187,8 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, */ if (!find_acl_user(combo.host.str,combo.user.str)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */ + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + MYF(0)); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } @@ -2202,9 +2210,10 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, */ if (revoke_grant) { // no row, no revoke - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - combo.user.str, combo.host.str, - table_name); /* purecov: deadcode */ + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } old_row_exists = 0; @@ -2311,7 +2320,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, } if (rights & ~TABLE_ACLS) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE,MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + MYF(0)); DBUG_RETURN(TRUE); } @@ -2332,8 +2342,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, column->column.length(), 0, 0, 0, 0, &unused_field_idx)) { - my_error(ER_BAD_FIELD_ERROR, MYF(0), - column->column.c_ptr(), table_list->alias); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + column->column.c_ptr(), table_list->alias); DBUG_RETURN(TRUE); } column_priv|= column->rights; @@ -2348,7 +2358,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, fn_format(buf,buf,"","",4+16+32); if (access(buf,F_OK)) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + table_list->db, table_list->alias); DBUG_RETURN(TRUE); } } @@ -2406,7 +2417,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (Str->host.length > HOSTNAME_LENGTH || Str->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); result= TRUE; continue; } @@ -2435,8 +2447,9 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (revoke_grant) { - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - Str->user.str, Str->host.str, table_list->real_name); + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + Str->user.str, Str->host.str, table_list->real_name); result= TRUE; continue; } @@ -2581,7 +2594,8 @@ bool mysql_grant(THD *thd, const char *db, List &list, if (Str->host.length > HOSTNAME_LENGTH || Str->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); result= -1; continue; } @@ -2876,11 +2890,12 @@ err: command= "create view"; else if (want_access & SHOW_VIEW_ACL) command= "show create view"; - my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), - command, - thd->priv_user, - thd->host_or_ip, - table ? table->real_name : "unknown"); + my_printf_error(ER_TABLEACCESS_DENIED_ERROR, + ER(ER_TABLEACCESS_DENIED_ERROR), MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + table ? table->real_name : "unknown"); } DBUG_RETURN(1); } @@ -3168,7 +3183,8 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) if (lex_user->host.length > HOSTNAME_LENGTH || lex_user->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); DBUG_RETURN(TRUE); } @@ -3186,8 +3202,9 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) } if (counter == acl_users.elements) { - my_error(ER_NONEXISTING_GRANT, MYF(0), - lex_user->user.str, lex_user->host.str); + my_printf_error(ER_NONEXISTING_GRANT, + ER(ER_NONEXISTING_GRANT), MYF(0), + lex_user->user.str, lex_user->host.str); DBUG_RETURN(TRUE); } @@ -3700,7 +3717,7 @@ bool mysql_drop_user(THD *thd, List &list) rw_unlock(&LOCK_grant); close_thread_tables(thd); if (result) - my_error(ER_DROP_USER, MYF(0)); + my_message(ER_DROP_USER, ER(ER_DROP_USER), MYF(0)); DBUG_RETURN(result); } @@ -3804,7 +3821,7 @@ bool mysql_revoke_all(THD *thd, List &list) /* when this code is deleted, the error slot (error 1268) can be reused, as this error code was not present in any MySQL release */ if (result) - my_error(ER_REVOKE_GRANTS, MYF(0)); + my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0)); DBUG_RETURN(result); } diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 3f75dadb6f0..c83bd978bfe 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -81,14 +81,18 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val() < 0) { delete pc; - my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); + my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, + ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), + proc_name); DBUG_RETURN(0); } pc->max_tree_elements = (uint) (*param->item)->val_int(); param = param->next; if (param->next) // no third parameter possible { - my_error(ER_WRONG_PARAMCOUNT_TO_PROCEDURE, MYF(0), proc_name); + my_printf_error(ER_WRONG_PARAMCOUNT_TO_PROCEDURE, + ER(ER_WRONG_PARAMCOUNT_TO_PROCEDURE), MYF(0), + proc_name); DBUG_RETURN(0); } // second parameter @@ -96,7 +100,9 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val() < 0) { delete pc; - my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); + my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, + ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), + proc_name); DBUG_RETURN(0); } pc->max_treemem = (uint) (*param->item)->val_int(); @@ -105,7 +111,8 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val() < 0) { delete pc; - my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); + my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, + ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), proc_name); DBUG_RETURN(0); } // if only one parameter was given, it will be the value of max_tree_elements diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 1f52c532737..a6a7e99ecec 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1224,7 +1224,8 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh) next=table->next; if (!tables || (!db_stat && reopen_table(table,1))) { - my_error(ER_CANT_REOPEN_TABLE,MYF(0),table->table_name); + my_printf_error(ER_CANT_REOPEN_TABLE, ER(ER_CANT_REOPEN_TABLE), + MYF(0),table->table_name); VOID(hash_delete(&open_cache,(byte*) table)); error=1; } @@ -1509,7 +1510,8 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db, { /* Give right error message */ thd->clear_error(); - my_error(ER_NOT_KEYFILE, MYF(0), name, my_errno); + my_printf_error(ER_NOT_KEYFILE, ER(ER_NOT_KEYFILE), MYF(0), + name, my_errno); sql_print_error("Error: Couldn't repair table: %s.%s",db,name); if (entry->file) closefrm(entry); @@ -1574,7 +1576,8 @@ err: { TABLE_LIST * view= table_desc->belong_to_view; thd->clear_error(); - my_error(ER_VIEW_INVALID, MYF(0), view->view_db.str, view->view_name.str); + my_printf_error(ER_VIEW_INVALID, ER(ER_VIEW_INVALID), MYF(0), + view->view_db.str, view->view_name.str); } DBUG_RETURN(1); } @@ -2738,8 +2741,9 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, (pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <= 0) { - my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), name->c_ptr(), - table->real_name); + my_printf_error(ER_KEY_COLUMN_DOES_NOT_EXITS, + ER(ER_KEY_COLUMN_DOES_NOT_EXITS), MYF(0), + name->c_ptr(), table->real_name); map->set_all(); return 1; } @@ -2954,9 +2958,10 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, DBUG_RETURN(0); if (!table_name) - my_error(ER_NO_TABLES_USED, MYF(0)); + my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0)); else - my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name); + my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), + table_name); err: DBUG_RETURN(1); @@ -3176,8 +3181,25 @@ err_no_arena: ** Returns : 1 if some field has wrong type ******************************************************************************/ -int -fill_record(List &fields,List &values, bool ignore_errors) + +/* + Fill fields with given items. + + SYNOPSIS + fill_record() + thd thread handler + fields Item_fields list to be filled + values values to fill with + ignore_errors TRUE if we should ignore errors + + RETURN + FALSE OK + TRUE error occured +*/ + +bool +fill_record(THD * thd, List &fields, List &values, + bool ignore_errors) { List_iterator_fast f(fields),v(values); Item *value; @@ -3192,14 +3214,32 @@ fill_record(List &fields,List &values, bool ignore_errors) if (rfield == table->next_number_field) table->auto_increment_field_not_null= TRUE; if ((value->save_in_field(rfield, 0) < 0) && !ignore_errors) - DBUG_RETURN(1); + { + my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0)); + DBUG_RETURN(TRUE); + } } - DBUG_RETURN(0); + DBUG_RETURN(thd->net.report_error); } -int -fill_record(Field **ptr,List &values, bool ignore_errors) +/* + Fill field buffer with values from Field list + + SYNOPSIS + fill_record() + thd thread handler + ptr pointer on pointer to record + values list of fields + ignore_errors TRUE if we should ignore errors + + RETURN + FALSE OK + TRUE error occured +*/ + +bool +fill_record(THD *thd, Field **ptr, List &values, bool ignore_errors) { List_iterator_fast v(values); Item *value; @@ -3213,9 +3253,12 @@ fill_record(Field **ptr,List &values, bool ignore_errors) if (field == table->next_number_field) table->auto_increment_field_not_null= TRUE; if ((value->save_in_field(field, 0) < 0) && !ignore_errors) - DBUG_RETURN(1); + { + my_message(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), MYF(0)); + DBUG_RETURN(TRUE); + } } - DBUG_RETURN(0); + DBUG_RETURN(thd->net.report_error); } @@ -3439,7 +3482,8 @@ open_new_frm(const char *path, const char *alias, { if (table_desc == 0 || table_desc->required_type == FRMTYPE_TABLE) { - my_error(ER_WRONG_OBJECT, MYF(0), db, table_name, "BASE TABLE"); + my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), + db, table_name, "BASE TABLE"); goto err; } if (mysql_make_view(parser, table_desc)) @@ -3448,7 +3492,8 @@ open_new_frm(const char *path, const char *alias, else { /* only VIEWs are supported now */ - my_error(ER_FRM_UNKNOWN_TYPE, MYF(0), path, parser->type()->str); + my_printf_error(ER_FRM_UNKNOWN_TYPE, ER(ER_FRM_UNKNOWN_TYPE), MYF(0), + path, parser->type()->str); goto err; } DBUG_RETURN(0); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a543222a4a1..966b7de6712 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -695,8 +695,8 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length) key_length + 1); if (!new_table) { - my_error(EE_OUTOFMEMORY, MYF(ME_BELL), - ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); + my_printf_error(EE_OUTOFMEMORY, ER(EE_OUTOFMEMORY), MYF(ME_BELL), + ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); killed= KILL_CONNECTION; return 0; } @@ -953,7 +953,8 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange, (void) fn_format(path, exchange->file_name, path, "", option); if (!access(path, F_OK)) { - my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); + my_printf_error(ER_FILE_EXISTS_ERROR, ER(ER_FILE_EXISTS_ERROR), MYF(0), + exchange->file_name); return -1; } /* Create the file world readable */ @@ -1184,7 +1185,7 @@ bool select_dump::send_data(List &items) } if (row_count++ > 1) { - my_error(ER_TOO_MANY_ROWS, MYF(0)); + my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); goto err; } while ((item=li++)) @@ -1197,7 +1198,8 @@ bool select_dump::send_data(List &items) } else if (my_b_write(&cache,(byte*) res->ptr(),res->length())) { - my_error(ER_ERROR_ON_WRITE,MYF(0), path, my_errno); + my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), + path, my_errno); goto err; } } @@ -1356,7 +1358,8 @@ int select_dumpvar::prepare(List &list, SELECT_LEX_UNIT *u) if (var_list.elements != list.elements) { - my_error(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, MYF(0)); + my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT, + ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0)); return 1; } while ((item=li++)) @@ -1626,7 +1629,7 @@ bool select_dumpvar::send_data(List &items) } if (row_count++) { - my_error(ER_TOO_MANY_ROWS, MYF(0)); + my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0)); DBUG_RETURN(1); } while ((zz=my_li++) && (item=it++)) diff --git a/sql/sql_class.h b/sql/sql_class.h index 46cf8ca4899..8de38782d3e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -41,6 +41,7 @@ enum enum_check_fields { CHECK_FIELD_IGNORE, CHECK_FIELD_WARN, CHECK_FIELD_ERROR_FOR_NULL }; extern char internal_table_name[2]; +extern const char **errmesg; /* log info errors */ #define LOG_INFO_EOF -1 @@ -1133,7 +1134,8 @@ public: } inline void send_kill_message() const { - my_error(killed_errno(), MYF(0)); + int err= killed_errno(); + my_message(err, ER(err), MYF(0)); } /* return TRUE if we will abort query if we make a warning now */ inline bool really_abort_on_warning() diff --git a/sql/sql_db.cc b/sql/sql_db.cc index df3c27b9b72..e3a19ea32a7 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -413,7 +413,8 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, { if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS)) { - my_error(ER_DB_CREATE_EXISTS,MYF(0),db); + my_printf_error(ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), MYF(0), + db); error= -1; goto exit; } @@ -423,12 +424,13 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, { if (my_errno != ENOENT) { - my_error(EE_STAT, MYF(0),path,my_errno); + my_printf_error(EE_STAT, ER(EE_STAT), MYF(0), path, my_errno); goto exit; } if (my_mkdir(path,0777,MYF(0)) < 0) { - my_error(ER_CANT_CREATE_DB,MYF(0),db,my_errno); + my_printf_error(ER_CANT_CREATE_DB, ER(ER_CANT_CREATE_DB), + MYF(0), db, my_errno); error= -1; goto exit; } @@ -582,7 +584,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) if (!if_exists) { error= -1; - my_error(ER_DB_DROP_EXISTS,MYF(0),db); + my_printf_error(ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS), MYF(0), db); goto exit; } else @@ -806,7 +808,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, */ if (found_other_files) { - my_error(ER_DB_DROP_RMDIR, MYF(0), org_path, EEXIST); + my_printf_error(ER_DB_DROP_RMDIR, ER(ER_DB_DROP_RMDIR), MYF(0), + org_path, EEXIST); DBUG_RETURN(-1); } else @@ -869,7 +872,8 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error) *--pos=0; if (rmdir(path) < 0 && send_error) { - my_error(ER_DB_DROP_RMDIR, MYF(0), path, errno); + my_printf_error(ER_DB_DROP_RMDIR, ER(ER_DB_DROP_RMDIR), MYF(0), + path, errno); DBUG_RETURN(-1); } DBUG_RETURN(0); @@ -985,12 +989,13 @@ bool mysql_change_db(THD *thd, const char *name) if (!dbname || !(db_length= strlen(dbname))) { x_free(dbname); /* purecov: inspected */ - my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: inspected */ + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), + MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } if (check_db_name(dbname)) { - my_error(ER_WRONG_DB_NAME, MYF(0), dbname); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname); x_free(dbname); DBUG_RETURN(1); } @@ -1003,10 +1008,11 @@ bool mysql_change_db(THD *thd, const char *name) thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->priv_user, - thd->priv_host, - dbname); + my_printf_error(ER_DBACCESS_DENIED_ERROR, + ER(ER_DBACCESS_DENIED_ERROR), MYF(0), + thd->priv_user, + thd->priv_host, + dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->priv_host, @@ -1021,7 +1027,7 @@ bool mysql_change_db(THD *thd, const char *name) path[length-1]=0; // remove ending '\' if (access(path,F_OK)) { - my_error(ER_BAD_DB_ERROR, MYF(0), dbname); + my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname); my_free(dbname,MYF(0)); DBUG_RETURN(1); } diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 54c6cd1ebc5..26b37efb773 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -55,7 +55,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, safe_update=test(thd->options & OPTION_SAFE_UPDATES); if (safe_update && const_cond) { - my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); + my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, + ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } @@ -103,7 +104,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, { delete select; free_underlaid_joins(thd, &thd->lex->select_lex); - my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); + my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, + ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } } @@ -259,7 +261,7 @@ cleanup: send_ok(thd,deleted); DBUG_PRINT("info",("%d records deleted",deleted)); } - DBUG_RETURN(FALSE); + DBUG_RETURN(error >= 0 || thd->net.report_error); } @@ -287,12 +289,14 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) DBUG_RETURN(TRUE); if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), MYF(0), + table_list->alias, "DELETE"); DBUG_RETURN(TRUE); } if (unique_table(table_list, table_list->next_independent())) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), MYF(0), + table_list->real_name); DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, conds); @@ -349,8 +353,8 @@ bool mysql_multi_delete_prepare(THD *thd) if (!target_tbl->correspondent_table->updatable || check_key_in_view(thd, target_tbl->correspondent_table)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), target_tbl->real_name, - "DELETE"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), + MYF(0), target_tbl->real_name, "DELETE"); DBUG_RETURN(TRUE); } /* @@ -367,8 +371,8 @@ bool mysql_multi_delete_prepare(THD *thd) un->check_updateable(target_tbl->correspondent_table->db, target_tbl->correspondent_table->real_name)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), - target_tbl->correspondent_table->real_name); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), + MYF(0), target_tbl->correspondent_table->real_name); DBUG_RETURN(TRUE); } } @@ -729,8 +733,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) db_type table_type; if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, - table_list->real_name); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + table_list->db, table_list->real_name); DBUG_RETURN(TRUE); } if (!ha_supports_generate(table_type)) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 6bab90a786e..37079fbc856 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -341,7 +341,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, break; } default: - my_error(ER_ILLEGAL_HA, MYF(0)); + my_message(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0)); goto err; } @@ -370,7 +370,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, if (item->send(thd->protocol, &buffer)) { protocol->free(); // Free used - my_error(ER_OUT_OF_RESOURCES,MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); goto err; } } diff --git a/sql/sql_help.cc b/sql/sql_help.cc index d108f6f69b4..cfa3325be8a 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -276,7 +276,7 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations, (iindex_relations= find_type((char*) primary_key_name, &relations->keynames, 1+2)-1)<0) { - my_error(ER_CORRUPT_HELP_DB, 0); + my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0)); DBUG_RETURN(-1); } rtopic_id= find_fields[help_relation_help_topic_id].field; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 81f80378763..4ba09e12811 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -100,7 +100,8 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, if (check_unique && thd->dupp_field) { - my_error(ER_FIELD_SPECIFIED_TWICE,MYF(0), thd->dupp_field->field_name); + my_printf_error(ER_FIELD_SPECIFIED_TWICE, ER(ER_FIELD_SPECIFIED_TWICE), + MYF(0), thd->dupp_field->field_name); return -1; } if (table->timestamp_field && // Don't set timestamp if used @@ -291,7 +292,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (fields.elements || !value_count) { restore_record(table,default_values); // Get empty record - if (fill_record(fields, *values, 0)|| thd->net.report_error) + if (fill_record(thd, fields, *values, 0)) { if (values_list.elements != 1 && !thd->net.report_error) { @@ -299,14 +300,10 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, continue; } /* - Field::store methods can't send errors - TODO: set thd->abort_on_warning if values_list.elements == 1 and check that all items return warning in case of problem with storing field. */ - if (!thd->net.report_error) - my_error(ER_UNKNOWN_ERROR, MYF(0)); error=1; break; } @@ -317,16 +314,13 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, restore_record(table,default_values); // Get empty record else table->record[0][0]=table->default_values[0]; // Fix delete marker - if (fill_record(table->field,*values, 0) || thd->net.report_error) + if (fill_record(thd, table->field, *values, 0)) { if (values_list.elements != 1 && ! thd->net.report_error) { info.records++; continue; } - /* Field::store methods can't send errors */ - if (!thd->net.report_error) - my_error(ER_UNKNOWN_ERROR, MYF(0)); error=1; break; } @@ -608,7 +602,8 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, (insert_into_view && check_view_insertability(table_list, thd->query_id))) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "INSERT"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), + MYF(0), table_list->alias, "INSERT"); DBUG_RETURN(1); } DBUG_RETURN(0); @@ -655,7 +650,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, if (unique_table(table_list, table_list->next_independent())) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), + MYF(0), table_list->real_name); DBUG_RETURN(TRUE); } thd->lex->select_lex.first_execution= 0; @@ -751,13 +747,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) */ store_record(table,insert_values); restore_record(table,record[1]); - if (fill_record(*info->update_fields, *info->update_values, 0)) - { - /* Field::store methods can't send errors */ - if (!thd->net.report_error) - my_error(ER_UNKNOWN_ERROR, MYF(0)); + if (fill_record(thd, *info->update_fields, *info->update_values, 0)) goto err; - } /* CHECK OPTION for VIEW ... ON DUPLICATE KEY UPDATE ... */ if (info->view && @@ -1018,7 +1009,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) { delete tmp; thd->fatal_error(); - my_error(ER_OUT_OF_RESOURCES,MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); pthread_mutex_unlock(&LOCK_delayed_create); DBUG_RETURN(0); } @@ -1335,7 +1326,8 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) if (!(di->table->file->table_flags() & HA_CAN_INSERT_DELAYED)) { thd->fatal_error(); - my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.real_name); + my_printf_error(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0), + di->table_list.real_name); goto end; } di->table->copy_blobs=1; @@ -1761,9 +1753,9 @@ bool select_insert::send_data(List &values) DBUG_RETURN(0); } if (fields->elements) - fill_record(*fields, values, 1); + fill_record(thd, *fields, values, 1); else - fill_record(table->field, values, 1); + fill_record(thd, table->field, values, 1); switch (table_list->view_check_option(thd, thd->lex->duplicates == DUP_IGNORE)) { @@ -1934,7 +1926,7 @@ bool select_create::send_data(List &values) unit->offset_limit_cnt--; return 0; } - fill_record(field, values, 1); + fill_record(thd, field, values, 1); if (thd->net.report_error || write_record(thd, table, &info)) return 1; if (table->next_number_field) // Clear for next record diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 73f99d0dd68..145ef84d57a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1273,7 +1273,7 @@ bool st_select_lex::test_limit() if (select_limit != HA_POS_ERROR) { my_error(ER_NOT_SUPPORTED_YET, MYF(0), - "LIMIT & IN/ALL/ANY/SOME subquery"); + "LIMIT & IN/ALL/ANY/SOME subquery"); return(1); } // We need only 1 row to determinate existence diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 0be4d9ecdc1..70fa097c8f8 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -125,7 +125,8 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, DBUG_RETURN(-1); if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), + MYF(0), table_list->alias, "LOAD"); DBUG_RETURN(TRUE); } table= table_list->table; @@ -148,7 +149,8 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, DBUG_RETURN(TRUE); if (thd->dupp_field) { - my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name); + my_printf_error(ER_FIELD_SPECIFIED_TWICE, ER(ER_FIELD_SPECIFIED_TWICE), + MYF(0), thd->dupp_field->field_name); DBUG_RETURN(TRUE); } if (check_that_all_fields_are_given_values(thd, table)) @@ -222,7 +224,8 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ((stat_info.st_mode & S_IFREG) == S_IFREG || (stat_info.st_mode & S_IFIFO) == S_IFIFO))) { - my_error(ER_TEXTFILE_NOT_READABLE,MYF(0),name); + my_printf_error(ER_TEXTFILE_NOT_READABLE, + ER(ER_TEXTFILE_NOT_READABLE), MYF(0), name); DBUG_RETURN(TRUE); } if ((stat_info.st_mode & S_IFIFO) == S_IFIFO) diff --git a/sql/sql_map.cc b/sql/sql_map.cc index c6637474908..917a8f2c30f 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -47,12 +47,13 @@ mapped_files::mapped_files(const my_string filename,byte *magic,uint magic_lengt 0L))) { error=errno; - my_error(ER_NO_FILE_MAPPING,MYF(0), (my_string) name, error); + my_printf_error(ER_NO_FILE_MAPPING, ER(ER_NO_FILE_MAPPING), MYF(0), + (my_string) name, error); } } if (map && memcmp(map,magic,magic_length)) { - my_error(ER_WRONG_MAGIC, MYF(0), name); + my_printf_error(ER_WRONG_MAGIC, ER(ER_WRONG_MAGIC), MYF(0), name); VOID(munmap(map,size)); map=0; } @@ -111,7 +112,8 @@ mapped_files *map_file(const my_string name,byte *magic,uint magic_length) { map->use_count++; if (!map->map) - my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error); + my_printf_error(ER_NO_FILE_MAPPING, ER(ER_NO_FILE_MAPPING), MYF(0), + path, map->error); } VOID(pthread_mutex_unlock(&LOCK_mapped_file)); return map; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 316f5ebdf60..5156d1e0d33 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1115,7 +1115,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) if (buff[length-1]!='\n' && !feof(file)) { net_send_error(thd, ER_NET_PACKET_TOO_LARGE, NullS); - thd->is_fatal_error= 1; + thd->fatal_error(); break; } while (length && (my_isspace(thd->charset(), buff[length-1]) || @@ -1192,7 +1192,8 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd) if (!db || check_db_name(db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + db ? db : "NULL"); goto err; } if (lower_case_table_names) @@ -1396,7 +1397,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* Small check for incoming packet */ if ((uint) ((uchar*) db - net->read_pos) > packet_length) { - my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); break; } #endif @@ -1418,7 +1419,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (!(thd->user= my_strdup(user, MYF(0)))) { thd->user= save_user; - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); break; } @@ -1430,7 +1431,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { /* authentication failure, we shall restore old user */ if (res > 0) - my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); x_free(thd->user); thd->user= save_user; thd->priv_user= save_priv_user; @@ -1538,7 +1539,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_FIELD_LIST: // This isn't actually needed #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ break; #else { @@ -1551,7 +1553,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, bzero((char*) &table_list,sizeof(table_list)); if (!(table_list.db=thd->db)) { - my_error(ER_NO_DB_ERROR, MYF(0)); + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); break; } pend= strend(packet); @@ -1604,7 +1606,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, // null test to handle EOM if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + db ? db : "NULL"); break; } if (check_access(thd,CREATE_ACL,db,0,1,0)) @@ -1621,14 +1624,16 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* null test to handle EOM */ if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), + MYF(0), db ? db : "NULL"); break; } if (check_access(thd,DROP_ACL,db,0,1,0)) break; if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); break; } mysql_log.write(thd,command,db); @@ -1777,7 +1782,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, send_eof(thd); break; default: - my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); break; } break; @@ -1796,7 +1801,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_DELAYED_INSERT: case COM_END: default: - my_error(ER_UNKNOWN_COM_ERROR, MYF(0)); + my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0)); break; } if (thd->lock || thd->open_tables || thd->derived_tables) @@ -1808,7 +1813,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* report error issued during command execution */ if (thd->killed_errno() && !thd->net.report_error) thd->send_kill_message(); - if (thd->is_fatal_error || thd->net.report_error) + if (thd->net.report_error) net_send_error(thd); time_t start_of_query=thd->start_time; @@ -1958,7 +1963,7 @@ mysql_execute_command(THD *thd) if (all_tables_not_ok(thd, all_tables)) { /* we warn the slave SQL thread */ - my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); DBUG_RETURN(0); } #ifndef TO_BE_DELETED @@ -2159,9 +2164,11 @@ mysql_execute_command(THD *thd) } else { - my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), - lex->prepared_stmt_name.length, lex->prepared_stmt_name.str, - "DEALLOCATE PREPARE"); + my_printf_error(ER_UNKNOWN_STMT_HANDLER, ER(ER_UNKNOWN_STMT_HANDLER), + MYF(0), + lex->prepared_stmt_name.length, + lex->prepared_stmt_name.str, + "DEALLOCATE PREPARE"); goto error; } break; @@ -2354,7 +2361,8 @@ mysql_execute_command(THD *thd) } if (strlen(first_table->real_name) > NAME_LEN) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->real_name); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), + first_table->real_name); break; } pthread_mutex_lock(&LOCK_active_mi); @@ -2425,7 +2433,8 @@ mysql_execute_command(THD *thd) if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && unique_table(create_table, select_tables)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->real_name); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), + MYF(0), create_table->real_name); goto create_error; } /* If we create merge table, we have to test tables in merge, too */ @@ -2438,7 +2447,8 @@ mysql_execute_command(THD *thd) { if (unique_table(tab, select_tables)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->real_name); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), + MYF(0), tab->real_name); goto create_error; } } @@ -2524,7 +2534,8 @@ create_error: */ if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), + MYF(0)); goto error; } { @@ -2538,14 +2549,16 @@ create_error: case SQLCOM_ALTER_TABLE: DBUG_ASSERT(first_table == all_tables && first_table != 0); #if defined(DONT_ALLOW_SHOW_COMMANDS) - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { ulong priv=0; if (lex->name && (!lex->name[0] || strlen(lex->name) > NAME_LEN)) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), lex->name); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), + lex->name); goto error; } if (!select_lex->db) @@ -2629,7 +2642,8 @@ create_error: #ifndef EMBEDDED_LIBRARY case SQLCOM_SHOW_BINLOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { @@ -2643,7 +2657,8 @@ create_error: case SQLCOM_SHOW_CREATE: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { @@ -2841,7 +2856,8 @@ create_error: */ if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } @@ -2939,7 +2955,8 @@ create_error: break; case SQLCOM_SHOW_DATABASES: #if defined(DONT_ALLOW_SHOW_COMMANDS) - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else if ((specialflag & SPECIAL_SKIP_SHOW_DB) && @@ -2985,7 +3002,8 @@ create_error: break; case SQLCOM_SHOW_LOGS: #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { @@ -2998,30 +3016,33 @@ create_error: case SQLCOM_SHOW_TABLES: /* FALL THROUGH */ #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { char *db=select_lex->db ? select_lex->db : thd->db; if (!db) { - my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: inspected */ + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), + MYF(0)); /* purecov: inspected */ goto error; /* purecov: inspected */ } remove_escape(db); // Fix escaped '_' if (check_db_name(db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), db); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), db); goto error; } if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) goto error; /* purecov: inspected */ if (!thd->col_access && check_grant_db(thd,db)) { - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->priv_user, - thd->priv_host, - db); + my_printf_error(ER_DBACCESS_DENIED_ERROR, + ER(ER_DBACCESS_DENIED_ERROR), MYF(0), + thd->priv_user, + thd->priv_host, + db); goto error; } /* grant is checked in mysqld_show_tables */ @@ -3047,7 +3068,8 @@ create_error: case SQLCOM_SHOW_FIELDS: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { @@ -3068,7 +3090,8 @@ create_error: case SQLCOM_SHOW_KEYS: DBUG_ASSERT(first_table == all_tables && first_table != 0); #ifdef DONT_ALLOW_SHOW_COMMANDS - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), + MYF(0)); /* purecov: inspected */ goto error; #else { @@ -3104,7 +3127,7 @@ create_error: if (!(thd->client_capabilities & CLIENT_LOCAL_FILES) || ! opt_local_infile) { - my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); + my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); goto error; } if (check_one_table_access(thd, privilege, all_tables)) @@ -3179,7 +3202,8 @@ create_error: char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + lex->name); break; } /* @@ -3194,7 +3218,7 @@ create_error: (!db_ok(lex->name, replicate_do_db, replicate_ignore_db) || !db_ok_with_wild_table(lex->name))) { - my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } #endif @@ -3209,7 +3233,8 @@ create_error: char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + lex->name); break; } /* @@ -3224,7 +3249,7 @@ create_error: (!db_ok(lex->name, replicate_do_db, replicate_ignore_db) || !db_ok_with_wild_table(lex->name))) { - my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } #endif @@ -3232,7 +3257,8 @@ create_error: break; if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } res=mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : lex->name), @@ -3243,7 +3269,8 @@ create_error: { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + lex->name); break; } /* @@ -3258,7 +3285,7 @@ create_error: (!db_ok(lex->name, replicate_do_db, replicate_ignore_db) || !db_ok_with_wild_table(lex->name))) { - my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); + my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0)); break; } #endif @@ -3266,7 +3293,8 @@ create_error: break; if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } res=mysql_alter_db(thd,lex->name,&lex->create_info); @@ -3276,14 +3304,16 @@ create_error: { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), + lex->name); break; } if (check_access(thd,SELECT_ACL,lex->name,0,1,0)) break; if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); goto error; } res=mysqld_show_create_db(thd,lex->name,&lex->create_info); @@ -3297,7 +3327,8 @@ create_error: #ifdef HAVE_DLOPEN if ((sph= sp_find_function(thd, lex->spname))) { - my_error(ER_UDF_EXISTS, MYF(0), lex->spname->m_name.str); + my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), + lex->spname->m_name.str); goto error; } if (!(res = mysql_create_function(thd,&lex->udf))) @@ -3405,7 +3436,8 @@ create_error: { if (lex->columns.elements) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + MYF(0)); goto error; } else @@ -3588,7 +3620,7 @@ create_error: if (! lex->sphead->m_db.str) { - my_error(ER_NO_DB_ERROR, MYF(0)); + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); delete lex->sphead; lex->sphead= 0; goto error; @@ -3602,7 +3634,7 @@ create_error: if (udf) { - my_error(ER_UDF_EXISTS, MYF(0), name); + my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; @@ -3612,7 +3644,7 @@ create_error: if (lex->sphead->m_type == TYPE_ENUM_FUNCTION && !lex->sphead->m_has_return) { - my_error(ER_SP_NORETURN, MYF(0), name); + my_printf_error(ER_SP_NORETURN, ER(ER_SP_NORETURN), MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; @@ -3627,19 +3659,22 @@ create_error: lex->sphead= 0; break; case SP_WRITE_ROW_FAILED: - my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name); + my_printf_error(ER_SP_ALREADY_EXISTS, ER(ER_SP_ALREADY_EXISTS), MYF(0), + SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; case SP_NO_DB_ERROR: - my_error(ER_BAD_DB_ERROR, MYF(0), lex->sphead->m_db.str); + my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), + lex->sphead->m_db.str); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; default: - my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(lex), name); + my_printf_error(ER_SP_STORE_FAILED, ER(ER_SP_STORE_FAILED), MYF(0), + SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; @@ -3653,7 +3688,8 @@ create_error: if (!(sp= sp_find_procedure(thd, lex->spname))) { - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PROCEDURE", + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), + MYF(0), "PROCEDURE", lex->spname->m_qname.str); goto error; } @@ -3680,7 +3716,7 @@ create_error: { if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) { - my_error(ER_SP_BADSELECT, MYF(0)); + my_message(ER_SP_BADSELECT, ER(ER_SP_BADSELECT), MYF(0)); #ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; #endif @@ -3751,12 +3787,12 @@ create_error: send_ok(thd); break; case SP_KEY_NOT_FOUND: - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; default: - my_error(ER_SP_CANT_ALTER, MYF(0), SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_printf_error(ER_SP_CANT_ALTER, ER(ER_SP_CANT_ALTER), MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; } break; @@ -3818,12 +3854,12 @@ create_error: send_ok(thd); break; } - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; default: - my_error(ER_SP_DROP_FAILED, MYF(0), SP_COM_STRING(lex), - lex->spname->m_qname.str); + my_printf_error(ER_SP_DROP_FAILED, ER(ER_SP_DROP_FAILED), MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; } break; @@ -3832,13 +3868,14 @@ create_error: { if (lex->spname->m_name.length > NAME_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); + my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), + lex->spname->m_name.str); goto error; } if (sp_show_create_procedure(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), - SP_COM_STRING(lex), lex->spname->m_name.str); + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } break; @@ -3847,13 +3884,14 @@ create_error: { if (lex->spname->m_name.length > NAME_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); + my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), + lex->spname->m_name.str); goto error; } if (sp_show_create_function(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - my_error(ER_SP_DOES_NOT_EXIST, MYF(0), - SP_COM_STRING(lex), lex->spname->m_name.str); + my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } break; @@ -4029,7 +4067,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { DBUG_PRINT("error",("No database")); if (!no_errors) - my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: tested */ + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), + MYF(0)); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -4056,10 +4095,13 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { // We can never grant this DBUG_PRINT("error",("No possible access")); if (!no_errors) - my_error(ER_ACCESS_DENIED_ERROR, MYF(0), - thd->priv_user, - thd->priv_host, - thd->password ? ER(ER_YES) : ER(ER_NO));/* purecov: tested */ + my_printf_error(ER_ACCESS_DENIED_ERROR, + ER(ER_ACCESS_DENIED_ERROR), MYF(0), + thd->priv_user, + thd->priv_host, + (thd->password ? + ER(ER_YES) : + ER(ER_NO)));/* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -4085,10 +4127,13 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_PRINT("error",("Access denied")); if (!no_errors) - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->priv_user, - thd->priv_host, - db ? db : thd->db ? thd->db : "unknown"); /* purecov: tested */ + my_printf_error(ER_DBACCESS_DENIED_ERROR, + ER(ER_DBACCESS_DENIED_ERROR), MYF(0), + thd->priv_user, + thd->priv_host, + (db ? db : (thd->db ? + thd->db : + "unknown"))); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4122,7 +4167,8 @@ bool check_global_access(THD *thd, ulong want_access) if ((thd->master_access & want_access)) return 0; get_privilege_desc(command, sizeof(command), want_access); - my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); + my_printf_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, + ER(ER_SPECIFIC_ACCESS_DENIED_ERROR), MYF(0), command); return 1; #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4234,7 +4280,8 @@ static bool check_db_used(THD *thd,TABLE_LIST *tables) { if (!(tables->db=thd->db)) { - my_error(ER_NO_DB_ERROR, MYF(0)); /* purecov: tested */ + my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), + MYF(0)); /* purecov: tested */ return TRUE; /* purecov: tested */ } } @@ -4272,7 +4319,8 @@ check_sp_definer_access(THD *thd, sp_head *sp) strncmp(thd->priv_host, hst->str, hst->length) == 0) return FALSE; /* Both user and host must match */ - my_error(ER_SP_ACCESS_DENIED_ERROR, MYF(0), sp->m_qname.str); + my_printf_error(ER_SP_ACCESS_DENIED_ERROR, ER(ER_SP_ACCESS_DENIED_ERROR), + MYF(0), sp->m_qname.str); return TRUE; /* Not definer or root */ } @@ -4636,7 +4684,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if (strlen(field_name) > NAME_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), field_name); /* purecov: inspected */ + my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), + field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } if (type_modifier & PRI_KEY_FLAG) @@ -4667,7 +4716,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC && type == FIELD_TYPE_TIMESTAMP)) { - my_error(ER_INVALID_DEFAULT, MYF(0), field_name); + my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), + field_name); DBUG_RETURN(1); } else if (default_value->type() == Item::NULL_ITEM) @@ -4676,20 +4726,23 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG) { - my_error(ER_INVALID_DEFAULT, MYF(0), field_name); + my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), + field_name); DBUG_RETURN(1); } } else if (type_modifier & AUTO_INCREMENT_FLAG) { - my_error(ER_INVALID_DEFAULT, MYF(0), field_name); + my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), + field_name); DBUG_RETURN(1); } } if (on_update_value && type != FIELD_TYPE_TIMESTAMP) { - my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name); + my_printf_error(ER_INVALID_ON_UPDATE, ER(ER_INVALID_ON_UPDATE), MYF(0), + field_name); DBUG_RETURN(1); } @@ -4815,8 +4868,9 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res=default_value->val_str(&str); if (res->length()) { - my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), - field_name); /* purecov: inspected */ + my_printf_error(ER_BLOB_CANT_HAVE_DEFAULT, + ER(ER_BLOB_CANT_HAVE_DEFAULT), MYF(0), + field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->def=0; @@ -4836,7 +4890,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, uint tmp_length=new_field->length; if (tmp_length > PRECISION_FOR_DOUBLE) { - my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); + my_printf_error(ER_WRONG_FIELD_SPEC, ER(ER_WRONG_FIELD_SPEC), MYF(0), + field_name); DBUG_RETURN(1); } else if (tmp_length > PRECISION_FOR_FLOAT) @@ -4922,7 +4977,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, { if (interval->count > sizeof(longlong)*8) { - my_error(ER_TOO_BIG_SET, MYF(0), field_name); /* purecov: inspected */ + my_printf_error(ER_TOO_BIG_SET, ER(ER_TOO_BIG_SET), MYF(0), + field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->pack_length=(interval->count+7)/8; @@ -4952,7 +5008,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, ¬_used2, ¬_used3); if (thd->cuted_fields) { - my_error(ER_INVALID_DEFAULT, MYF(0), field_name); + my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), + field_name); DBUG_RETURN(1); } } @@ -4978,7 +5035,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res->strip_sp(); if (!find_type(interval, res->ptr(), res->length(), 0)) { - my_error(ER_INVALID_DEFAULT, MYF(0), field_name); + my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), + field_name); DBUG_RETURN(1); } } @@ -4992,14 +5050,15 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY)) { - my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), field_name, - MAX_FIELD_CHARLENGTH); /* purecov: inspected */ + my_printf_error(ER_TOO_BIG_FIELDLENGTH, ER(ER_TOO_BIG_FIELDLENGTH), MYF(0), + field_name, MAX_FIELD_CHARLENGTH);/* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } type_modifier&= AUTO_INCREMENT_FLAG; if ((~allowed_type_modifier) & type_modifier) { - my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); + my_printf_error(ER_WRONG_FIELD_SPEC, ER(ER_WRONG_FIELD_SPEC), MYF(0), + field_name); DBUG_RETURN(1); } if (!new_field->pack_length) @@ -5129,7 +5188,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (check_table_name(table->table.str,table->table.length) || table->db.str && check_db_name(table->db.str)) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), + table->table.str); DBUG_RETURN(0); } @@ -5137,7 +5197,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { if (table->sel) { - my_error(ER_DERIVED_MUST_HAVE_ALIAS, MYF(0)); + my_message(ER_DERIVED_MUST_HAVE_ALIAS, + ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); DBUG_RETURN(0); } if (!(alias_str=thd->memdup(alias_str,table->table.length+1))) @@ -5191,7 +5252,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && !strcmp(ptr->db, tables->db)) { - my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */ + my_printf_error(ER_NONUNIQ_TABLE, ER(ER_NONUNIQ_TABLE), MYF(0), + alias_str); /* purecov: tested */ DBUG_RETURN(0); /* purecov: tested */ } } @@ -5735,7 +5797,8 @@ static bool append_file_to_dir(THD *thd, const char **filename_ptr, if (strlen(*filename_ptr)+strlen(table_name) >= FN_REFLEN-1 || !test_if_hard_path(*filename_ptr)) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), *filename_ptr); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), + *filename_ptr); return 1; } /* Fix is using unix filename format on dos */ @@ -5768,7 +5831,8 @@ bool check_simple_select() char command[80]; strmake(command, thd->lex->yylval->symbol.str, min(thd->lex->yylval->symbol.length, sizeof(command)-1)); - my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command); + my_printf_error(ER_CANT_USE_OPTION_HERE, ER(ER_CANT_USE_OPTION_HERE), + MYF(0), command); return 1; } return 0; @@ -5916,7 +5980,7 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) if (select_lex->item_list.elements != lex->value_list.elements) { - my_error(ER_WRONG_VALUE_COUNT, MYF(0)); + my_printf_error(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } /* @@ -5997,7 +6061,8 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) DBUG_RETURN(TRUE); if ((thd->options & OPTION_SAFE_UPDATES) && !select_lex->where) { - my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, MYF(0)); + my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, + ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); DBUG_RETURN(TRUE); } for (target_tbl= aux_tables; target_tbl; target_tbl= target_tbl->next_local) @@ -6014,8 +6079,8 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) } if (!walk) { - my_error(ER_UNKNOWN_TABLE, MYF(0), target_tbl->real_name, - "MULTI DELETE"); + my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), + target_tbl->real_name, "MULTI DELETE"); DBUG_RETURN(TRUE); } walk->lock_type= target_tbl->lock_type; @@ -6069,7 +6134,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables) DBUG_ENTER("update_precheck"); if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements) { - my_error(ER_WRONG_VALUE_COUNT, MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } DBUG_RETURN(check_db_used(thd, tables) || @@ -6127,7 +6192,7 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables, bool update) if (lex->select_lex.item_list.elements != lex->value_list.elements) { - my_error(ER_WRONG_VALUE_COUNT, MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index aa5da98f56f..17f1b0eacfd 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1451,7 +1451,7 @@ static int send_prepare_results(Prepared_statement *stmt, bool text_protocol) All other is not supported yet */ res= -1; - my_error(ER_UNSUPPORTED_PS, MYF(0)); + my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0)); goto error; } if (res == 0) diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 3298eb68a91..25874e1335a 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -44,7 +44,8 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list) if (thd->locked_tables || thd->active_transaction()) { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION,MYF(0)); + my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, + ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); DBUG_RETURN(1); } @@ -156,7 +157,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) unpack_filename(name, name); if (!access(name,F_OK)) { - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_alias); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), new_alias); DBUG_RETURN(ren_table); // This can't be skipped } sprintf(name,"%s/%s/%s%s",mysql_data_home, @@ -165,7 +167,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) unpack_filename(name, name); if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN) { - my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); + my_printf_error(ER_FILE_NOT_FOUND, ER(ER_FILE_NOT_FOUND), MYF(0), + name, my_errno); if (!skip_error) DBUG_RETURN(ren_table); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 16daba09954..aea65d13386 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -296,7 +296,7 @@ bool purge_error_message(THD* thd, int res) if (errmsg) { - my_error(errmsg, MYF(0)); + my_message(errmsg, ER(errmsg), MYF(0)); return TRUE; } send_ok(thd); @@ -867,7 +867,7 @@ int start_slave(THD* thd , MASTER_INFO* mi, bool net_report) if (slave_errno) { if (net_report) - my_error(slave_errno, MYF(0)); + my_message(slave_errno, ER(slave_errno), MYF(0)); DBUG_RETURN(1); } else if (net_report) @@ -917,7 +917,7 @@ int stop_slave(THD* thd, MASTER_INFO* mi, bool net_report ) if (slave_errno) { if (net_report) - my_error(slave_errno, MYF(0)); + my_message(slave_errno, ER(slave_errno), MYF(0)); return 1; } else if (net_report) @@ -998,8 +998,8 @@ int reset_slave(THD *thd, MASTER_INFO* mi) err: unlock_slave_threads(mi); - if (error) - my_error(sql_errno, MYF(0), errmsg); + if (error) + my_printf_error(sql_errno, ER(sql_errno), MYF(0), errmsg); DBUG_RETURN(error); } @@ -1063,7 +1063,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) init_thread_mask(&thread_mask,mi,0 /*not inverse*/); if (thread_mask) // We refuse if any slave thread is running { - my_error(ER_SLAVE_MUST_STOP, MYF(0)); + my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0)); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1073,7 +1073,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) // TODO: see if needs re-write if (init_master_info(mi, master_info_file, relay_log_info_file, 0)) { - my_error(ER_MASTER_INFO, MYF(0)); + my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0)); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1192,7 +1192,8 @@ bool change_master(THD* thd, MASTER_INFO* mi) 0 /* not only reset, but also reinit */, &errmsg)) { - my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); + my_printf_error(ER_RELAY_LOG_FAIL, ER(ER_RELAY_LOG_FAIL), MYF(0), + errmsg); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1208,7 +1209,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) 0 /*no data lock*/, &msg, 0)) { - my_error(ER_RELAY_LOG_INIT, MYF(0), msg); + my_printf_error(ER_RELAY_LOG_INIT, ER(ER_RELAY_LOG_INIT), MYF(0), msg); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1259,7 +1260,8 @@ int reset_master(THD* thd) { if (!mysql_bin_log.is_open()) { - my_error(ER_FLUSH_MASTER_BINLOG_CLOSED, MYF(ME_BELL+ME_WAITTANG)); + my_message(ER_FLUSH_MASTER_BINLOG_CLOSED, + ER(ER_FLUSH_MASTER_BINLOG_CLOSED), MYF(ME_BELL+ME_WAITTANG)); return 1; } return mysql_bin_log.reset_logs(thd); @@ -1401,8 +1403,9 @@ err: if (errmsg) { - my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), - "SHOW BINLOG EVENTS", errmsg); + my_printf_error(ER_ERROR_WHEN_EXECUTING_COMMAND, + ER(ER_ERROR_WHEN_EXECUTING_COMMAND), MYF(0), + "SHOW BINLOG EVENTS", errmsg); DBUG_RETURN(TRUE); } @@ -1470,7 +1473,7 @@ bool show_binlogs(THD* thd) if (!mysql_bin_log.is_open()) { - my_error(ER_NO_BINARY_LOGGING, MYF(0)); + my_message(ER_NO_BINARY_LOGGING, ER(ER_NO_BINARY_LOGGING), MYF(0)); return 1; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index df7e943d1f6..eed16be059a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -377,7 +377,8 @@ JOIN::prepare(Item ***rref_pointer_array, } if (flag == 3) { - my_error(ER_MIX_OF_GROUP_FUNC_AND_FIELDS,MYF(0)); + my_message(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, + ER(ER_MIX_OF_GROUP_FUNC_AND_FIELDS), MYF(0)); DBUG_RETURN(-1); } } @@ -404,7 +405,8 @@ JOIN::prepare(Item ***rref_pointer_array, { if (!test_if_subpart(procedure->group,group_list)) { /* purecov: inspected */ - my_error(ER_DIFF_GROUPS_PROC, MYF(0)); /* purecov: inspected */ + my_message(ER_DIFF_GROUPS_PROC, ER(ER_DIFF_GROUPS_PROC), + MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } } @@ -417,7 +419,8 @@ JOIN::prepare(Item ***rref_pointer_array, #endif if (order && (procedure->flags & PROC_NO_SORT)) { /* purecov: inspected */ - my_error(ER_ORDER_WITH_PROC, MYF(0)); /* purecov: inspected */ + my_message(ER_ORDER_WITH_PROC, ER(ER_ORDER_WITH_PROC), + MYF(0)); /* purecov: inspected */ goto err; /* purecov: inspected */ } } @@ -1805,7 +1808,7 @@ Cursor::fetch(ulong num_rows) if (thd->killed) /* Aborted by user */ { - my_error(ER_SERVER_SHUTDOWN,MYF(0)); + my_message(ER_SERVER_SHUTDOWN, ER(ER_SERVER_SHUTDOWN), MYF(0)); return -1; } @@ -2209,7 +2212,7 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds, if (s->dependent & s->table->map) { join->tables=0; // Don't use join->table - my_error(ER_WRONG_OUTER_JOIN,MYF(0)); + my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0)); DBUG_RETURN(1); } s->key_dependent= s->dependent; @@ -5622,7 +5625,8 @@ bool error_if_full_join(JOIN *join) { if (tab->type == JT_ALL && (!tab->select || !tab->select->quick)) { - my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0)); + my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, + ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0)); return(1); } } @@ -10664,7 +10668,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field, } if (copy_blobs(first_field)) { - my_error(ER_OUTOFMEMORY,MYF(0)); + my_message(ER_OUTOFMEMORY, ER(ER_OUTOFMEMORY), MYF(0)); error=0; goto err; } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 17e1a77645a..f8243e8568e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -866,8 +866,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) /* TODO: add environment variables show when it become possible */ if (thd->lex->only_view && !table_list->view) { - my_error(ER_WRONG_OBJECT, MYF(0), table_list->db, - table_list->real_name, "VIEW"); + my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), + table_list->db, table_list->real_name, "VIEW"); DBUG_RETURN(TRUE); } @@ -936,7 +936,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname, if (check_db_name(dbname)) { - my_error(ER_WRONG_DB_NAME, MYF(0), dbname); + my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname); DBUG_RETURN(TRUE); } @@ -948,8 +948,9 @@ bool mysqld_show_create_db(THD *thd, char *dbname, thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), - thd->priv_user, thd->host_or_ip, dbname); + my_printf_error(ER_DBACCESS_DENIED_ERROR, + ER(ER_DBACCESS_DENIED_ERROR), MYF(0), + thd->priv_user, thd->host_or_ip, dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->host_or_ip, dbname); DBUG_RETURN(TRUE); @@ -966,7 +967,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname, } if (access(path,F_OK)) { - my_error(ER_BAD_DB_ERROR, MYF(0), dbname); + my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname); DBUG_RETURN(TRUE); } if (found_libchar) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d84611ae496..77a5ab340b3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -78,8 +78,9 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, { if (thd->global_read_lock) { - my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE,MYF(0), - tables->real_name); + my_printf_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, + ER(ER_TABLE_NOT_LOCKED_FOR_WRITE), MYF(0), + tables->real_name); error= TRUE; goto err; } @@ -261,9 +262,10 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, if (wrong_tables.length()) { if (!foreign_key_error) - my_error(ER_BAD_TABLE_ERROR,MYF(0), wrong_tables.c_ptr()); + my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), + wrong_tables.c_ptr()); else - my_error(ER_ROW_IS_REFERENCED, MYF(0)); + my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0)); error= 1; } @@ -463,7 +465,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (check_column_name(sql_field->field_name)) { - my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name); + my_printf_error(ER_WRONG_COLUMN_NAME, ER(ER_WRONG_COLUMN_NAME), MYF(0), + sql_field->field_name); DBUG_RETURN(-1); } @@ -480,7 +483,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, */ if (field_no < select_field_pos || dup_no >= select_field_pos) { - my_error(ER_DUP_FIELDNAME,MYF(0),sql_field->field_name); + my_printf_error(ER_DUP_FIELDNAME, ER(ER_DUP_FIELDNAME), MYF(0), + sql_field->field_name); DBUG_RETURN(-1); } else @@ -619,24 +623,27 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (timestamps_with_niladic > 1) { - my_error(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS,MYF(0)); + my_message(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS, + ER(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS), MYF(0)); DBUG_RETURN(-1); } if (auto_increment > 1) { - my_error(ER_WRONG_AUTO_KEY,MYF(0)); + my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0)); DBUG_RETURN(-1); } if (auto_increment && (file->table_flags() & HA_NO_AUTO_INCREMENT)) { - my_error(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT,MYF(0)); + my_message(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT, + ER(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT), MYF(0)); DBUG_RETURN(-1); } if (blob_columns && (file->table_flags() & HA_NO_BLOBS)) { - my_error(ER_TABLE_CANT_HANDLE_BLOB,MYF(0)); + my_message(ER_TABLE_CANT_HANDLE_BLOB, ER(ER_TABLE_CANT_HANDLE_BLOB), + MYF(0)); DBUG_RETURN(-1); } @@ -662,9 +669,11 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (fk_key->ref_columns.elements && fk_key->ref_columns.elements != fk_key->columns.elements) { - my_error(ER_WRONG_FK_DEF, MYF(0), fk_key->name ? fk_key->name : - "foreign key without name", - ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); + my_printf_error(ER_WRONG_FK_DEF, ER(ER_WRONG_FK_DEF), MYF(0), + (fk_key->name ? + fk_key->name : + "foreign key without name"), + ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); DBUG_RETURN(-1); } continue; @@ -678,7 +687,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (key->name && strlen(key->name) > NAME_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), key->name); + my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), + key->name); DBUG_RETURN(-1); } key_iterator2.rewind (); @@ -718,7 +728,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (key->name && !tmp_table && !my_strcasecmp(system_charset_info,key->name,primary_key_name)) { - my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name); + my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), + MYF(0), key->name); DBUG_RETURN(-1); } } @@ -786,7 +797,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { if (!(file->table_flags() & HA_CAN_FULLTEXT)) { - my_error(ER_TABLE_CANT_HANDLE_FT, MYF(0)); + my_message(ER_TABLE_CANT_HANDLE_FT, ER(ER_TABLE_CANT_HANDLE_FT), + MYF(0)); DBUG_RETURN(-1); } } @@ -927,7 +939,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (key->type == Key::SPATIAL) { - my_error(ER_SPATIAL_CANT_HAVE_NULL, MYF(0)); + my_message(ER_SPATIAL_CANT_HAVE_NULL, + ER(ER_SPATIAL_CANT_HAVE_NULL), MYF(0)); DBUG_RETURN(-1); } } @@ -973,7 +986,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, (key_info->flags & HA_NOSAME))) && column->length != length))) { - my_error(ER_WRONG_SUB_KEY,MYF(0)); + my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0)); DBUG_RETURN(-1); } else if (!(file->table_flags() & HA_NO_PREFIX_CHAR_KEYS)) @@ -1026,7 +1039,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { if (primary_key) { - my_error(ER_MULTIPLE_PRI_KEY,MYF(0)); + my_message(ER_MULTIPLE_PRI_KEY, ER(ER_MULTIPLE_PRI_KEY), + MYF(0)); DBUG_RETURN(-1); } key_name=primary_key_name; @@ -1037,7 +1051,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, key_info_buffer,key_info); if (check_if_keyname_exists(key_name,key_info_buffer,key_info)) { - my_error(ER_DUP_KEYNAME,MYF(0),key_name); + my_printf_error(ER_DUP_KEYNAME, ER(ER_DUP_KEYNAME), MYF(0), + key_name); DBUG_RETURN(-1); } key_info->name=(char*) key_name; @@ -1045,7 +1060,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (!key_info->name || check_column_name(key_info->name)) { - my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name); + my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), + MYF(0), key_info->name); DBUG_RETURN(-1); } if (!(key_info->flags & HA_NULL_PART_KEY)) @@ -1062,12 +1078,12 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (!unique_key && !primary_key && (file->table_flags() & HA_REQUIRE_PRIMARY_KEY)) { - my_error(ER_REQUIRES_PRIMARY_KEY,MYF(0)); + my_message(ER_REQUIRES_PRIMARY_KEY, ER(ER_REQUIRES_PRIMARY_KEY), MYF(0)); DBUG_RETURN(-1); } if (auto_increment > 0) { - my_error(ER_WRONG_AUTO_KEY,MYF(0)); + my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0)); DBUG_RETURN(-1); } /* Sort keys in optimized order */ @@ -1123,7 +1139,8 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, /* Check for duplicate fields and check type of table to create */ if (!fields.elements) { - my_error(ER_TABLE_MUST_HAVE_COLUMNS,MYF(0)); + my_message(ER_TABLE_MUST_HAVE_COLUMNS, ER(ER_TABLE_MUST_HAVE_COLUMNS), + MYF(0)); DBUG_RETURN(TRUE); } if ((new_db_type= ha_checktype(create_info->db_type)) != @@ -1153,7 +1170,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, if ((create_info->options & HA_LEX_CREATE_TMP_TABLE) && (file->table_flags() & HA_NO_TEMP_TABLES)) { - my_error(ER_ILLEGAL_HA,MYF(0),table_name); + my_printf_error(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0), table_name); DBUG_RETURN(TRUE); } #endif @@ -1204,7 +1221,8 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, create_info->table_existed= 1; // Mark that table existed DBUG_RETURN(FALSE); } - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), MYF(0), + alias); DBUG_RETURN(TRUE); } if (wait_if_global_read_lock(thd, 0, 1)) @@ -1220,7 +1238,8 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, error= FALSE; } else - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); + my_printf_error(ER_TABLE_EXISTS_ERROR, + ER(ER_TABLE_EXISTS_ERROR), MYF(0), table_name); goto end; } } @@ -1249,7 +1268,8 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, error= FALSE; } else - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); + my_printf_error(ER_TABLE_EXISTS_ERROR, + ER(ER_TABLE_EXISTS_ERROR), MYF(0), table_name); goto end; } } @@ -1457,7 +1477,8 @@ mysql_rename_table(enum db_type base, } delete file; if (error) - my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error); + my_printf_error(ER_ERROR_ON_RENAME, ER(ER_ERROR_ON_RENAME), + MYF(0), from, to, error); DBUG_RETURN(error != 0); } @@ -1999,7 +2020,8 @@ bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, if (!(key_cache= get_key_cache(key_cache_name))) { pthread_mutex_unlock(&LOCK_global_system_variables); - my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str); + my_printf_error(ER_UNKNOWN_KEY_CACHE, ER(ER_UNKNOWN_KEY_CACHE), MYF(0), + key_cache_name->str); DBUG_RETURN(TRUE); } pthread_mutex_unlock(&LOCK_global_system_variables); @@ -2109,7 +2131,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, check_table_name(src_table,table_ident->table.length)) || table_ident->db.str && check_db_name((src_db= table_ident->db.str))) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), src_table); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), + src_table); DBUG_RETURN(TRUE); } @@ -2128,7 +2151,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, reg_ext, NullS); if (access(src_path, F_OK)) { - my_error(ER_BAD_TABLE_ERROR, MYF(0), src_table); + my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), + src_table); goto err; } } @@ -2211,7 +2235,8 @@ table_exists: res= FALSE; } else - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), MYF(0), + table_name); err: pthread_mutex_lock(&LOCK_open); @@ -2467,7 +2492,8 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list, } if (idx>= table->keys) { - my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), drop_key->name); + my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, ER(ER_CANT_DROP_FIELD_OR_KEY), + MYF(0), drop_key->name); /*don't need to free((gptr) key_numbers);*/ DBUG_RETURN(-1); } @@ -2590,7 +2616,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (find_temporary_table(thd,new_db,new_name_buff)) { - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name_buff); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), new_name_buff); DBUG_RETURN(TRUE); } } @@ -2600,7 +2627,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, F_OK)) { /* Table will be closed in do_command() */ - my_error(ER_TABLE_EXISTS_ERROR,MYF(0), new_alias); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), new_alias); DBUG_RETURN(TRUE); } } @@ -2640,7 +2668,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, error=0; if (!access(new_name_buff,F_OK)) { - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), new_name); error= -1; } else @@ -2783,7 +2812,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (def->sql_type == FIELD_TYPE_BLOB) { - my_error(ER_BLOB_CANT_HAVE_DEFAULT,MYF(0),def->change); + my_printf_error(ER_BLOB_CANT_HAVE_DEFAULT, + ER(ER_BLOB_CANT_HAVE_DEFAULT), MYF(0), def->change); DBUG_RETURN(TRUE); } def->def=alter->def; // Use new default @@ -2797,7 +2827,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (def->change && ! def->field) { - my_error(ER_BAD_FIELD_ERROR,MYF(0),def->change,table_name); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + def->change, table_name); DBUG_RETURN(TRUE); } if (!def->after) @@ -2815,7 +2846,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } if (!find) { - my_error(ER_BAD_FIELD_ERROR,MYF(0),def->after,table_name); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), + MYF(0), def->after, table_name); DBUG_RETURN(TRUE); } find_it.after(def); // Put element after this @@ -2823,13 +2855,14 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } if (alter_info->alter_list.elements) { - my_error(ER_BAD_FIELD_ERROR,MYF(0),alter_info->alter_list.head()->name, - table_name); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + alter_info->alter_list.head()->name, table_name); DBUG_RETURN(TRUE); } if (!create_list.elements) { - my_error(ER_CANT_REMOVE_ALL_FIELDS,MYF(0)); + my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS), + MYF(0)); DBUG_RETURN(TRUE); } @@ -2918,7 +2951,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (key->name && !my_strcasecmp(system_charset_info,key->name,primary_key_name)) { - my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name); + my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), + MYF(0), key->name); DBUG_RETURN(TRUE); } } @@ -2926,14 +2960,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (alter_info->drop_list.elements) { - my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0), - alter_info->drop_list.head()->name); + my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, + ER(ER_CANT_DROP_FIELD_OR_KEY), MYF(0), + alter_info->drop_list.head()->name); goto err; } if (alter_info->alter_list.elements) { - my_error(ER_CANT_DROP_FIELD_OR_KEY,MYF(0), - alter_info->alter_list.head()->name); + my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, + ER(ER_CANT_DROP_FIELD_OR_KEY), MYF(0), + alter_info->alter_list.head()->name); goto err; } @@ -3121,7 +3157,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (!access(new_name_buff,F_OK)) { error=1; - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_name_buff); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), new_name_buff); VOID(quick_rm_table(new_db_type,new_db,tmp_name)); VOID(pthread_mutex_unlock(&LOCK_open)); goto err; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index b71bb4ba42a..13f127cc54b 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -74,7 +74,8 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) */ if (tables->view || table->tmp_table != NO_TMP_TABLE) { - my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias); + my_printf_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, + ER(ER_TRG_ON_VIEW_OR_TEMP_TABLE), MYF(0), tables->alias); DBUG_RETURN(TRUE); } @@ -82,7 +83,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) { if (!create) { - my_error(ER_TRG_DOES_NOT_EXIST, MYF(0)); + my_message(ER_TRG_DOES_NOT_EXIST, ER(ER_TRG_DOES_NOT_EXIST), MYF(0)); DBUG_RETURN(TRUE); } @@ -142,7 +143,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables) /* We don't allow creation of several triggers of the same type yet */ if (bodies[lex->trg_chistics.event][lex->trg_chistics.action_time]) { - my_error(ER_TRG_ALREADY_EXISTS, MYF(0)); + my_message(ER_TRG_ALREADY_EXISTS, ER(ER_TRG_ALREADY_EXISTS), MYF(0)); return 1; } @@ -152,7 +153,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables) if (my_strcasecmp(system_charset_info, lex->name_and_length.str, name->str) == 0) { - my_error(ER_TRG_ALREADY_EXISTS, MYF(0)); + my_message(ER_TRG_ALREADY_EXISTS, ER(ER_TRG_ALREADY_EXISTS), MYF(0)); return 1; } } @@ -266,7 +267,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables) } } - my_error(ER_TRG_DOES_NOT_EXIST, MYF(0)); + my_message(ER_TRG_DOES_NOT_EXIST, ER(ER_TRG_DOES_NOT_EXIST), MYF(0)); return 1; } @@ -433,7 +434,8 @@ err_with_lex_cleanup: We don't care about this error message much because .TRG files will be merged into .FRM anyway. */ - my_error(ER_WRONG_OBJECT, MYF(0), table_name, triggers_file_ext, "TRIGGER"); + my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), + table_name, triggers_file_ext, "TRIGGER"); DBUG_RETURN(1); } diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index d27b72c02a7..903b80e6949 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -369,7 +369,7 @@ int mysql_create_function(THD *thd,udf_func *udf) if (!initialized) { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); DBUG_RETURN(1); } @@ -380,19 +380,20 @@ int mysql_create_function(THD *thd,udf_func *udf) */ if (strchr(udf->dl, '/')) { - my_error(ER_UDF_NO_PATHS, MYF(0)); + my_message(ER_UDF_NO_PATHS, ER(ER_UDF_NO_PATHS), MYF(0)); DBUG_RETURN(1); } if (udf->name.length > NAME_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name); + my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), + udf->name); DBUG_RETURN(1); } rw_wrlock(&THR_LOCK_udf); if ((hash_search(&udf_hash,(byte*) udf->name.str, udf->name.length))) { - my_error(ER_UDF_EXISTS, MYF(0), udf->name); + my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), udf->name); goto err; } if (!(dl = find_udf_dl(udf->dl))) @@ -401,7 +402,8 @@ int mysql_create_function(THD *thd,udf_func *udf) { DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)", udf->dl,errno,dlerror())); - my_error(ER_CANT_OPEN_LIBRARY, MYF(0), udf->dl, errno, dlerror()); + my_printf_error(ER_CANT_OPEN_LIBRARY, ER(ER_CANT_OPEN_LIBRARY), MYF(0), + udf->dl, errno, dlerror()); goto err; } new_dl=1; @@ -411,7 +413,8 @@ int mysql_create_function(THD *thd,udf_func *udf) if (udf->func == NULL) { - my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), udf->name); + my_printf_error(ER_CANT_FIND_DL_ENTRY, ER(ER_CANT_FIND_DL_ENTRY), MYF(0), + udf->name); goto err; } udf->name.str=strdup_root(&mem,udf->name.str); @@ -445,7 +448,8 @@ int mysql_create_function(THD *thd,udf_func *udf) close_thread_tables(thd); if (error) { - my_error(ER_ERROR_ON_WRITE, MYF(0), "func@mysql", error); + my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), + "func@mysql", error); del_udf(u_d); goto err; } @@ -468,14 +472,15 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) DBUG_ENTER("mysql_drop_function"); if (!initialized) { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); DBUG_RETURN(1); } rw_wrlock(&THR_LOCK_udf); if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name->str, (uint) udf_name->length))) { - my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str); + my_printf_error(ER_FUNCTION_NOT_DEFINED, ER(ER_FUNCTION_NOT_DEFINED), + MYF(0), udf_name->str); goto err; } del_udf(udf); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 6a2d11ba7f5..5969f1ce3fa 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -75,7 +75,7 @@ bool select_union::send_data(List &values) unit->offset_limit_cnt--; return 0; } - fill_record(table->field, values, 1); + fill_record(thd, table->field, values, 1); if (thd->net.report_error || write_record(thd, table,&info)) { if (thd->net.last_errno == ER_RECORD_FILE_FULL) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 8d64d30a9e0..ccdc64638bb 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -73,7 +73,8 @@ static bool check_fields(THD *thd, List &items) if (!(field= item->filed_for_view_update())) { /* item has name, because it comes from VIEW SELECT list */ - my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name); + my_printf_error(ER_NONUPDATEABLE_COLUMN, ER(ER_NONUPDATEABLE_COLUMN), + MYF(0), item->name); return TRUE; } /* @@ -164,7 +165,8 @@ bool mysql_update(THD *thd, } if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), + MYF(0), table_list->alias, "UPDATE"); DBUG_RETURN(TRUE); } if (table->timestamp_field) @@ -362,16 +364,9 @@ bool mysql_update(THD *thd, if (!(select && select->skip_record())) { store_record(table,record[1]); - if (fill_record(fields,values, 0) || thd->net.report_error) - { - /* Field::store methods can't send errors */ - if (!thd->net.report_error) - { - /* TODO: convert last warning to error */ - my_error(ER_UNKNOWN_ERROR, MYF(0)); - } + if (fill_record(thd, fields, values, 0)) break; /* purecov: inspected */ - } + found++; if (table->triggers) @@ -478,7 +473,7 @@ bool mysql_update(THD *thd, thd->count_cuted_fields= CHECK_FIELD_IGNORE; /* calc cuted fields */ thd->abort_on_warning= 0; free_io_cache(table); - DBUG_RETURN(FALSE); + DBUG_RETURN(error >= 0 || thd->net.report_error); err: delete select; @@ -504,11 +499,10 @@ err: order - ORDER BY clause list RETURN VALUE - 0 - OK - 1 - error (message is sent to user) - -1 - error (message is not sent to user) + FALSE OK + TRUE error */ -int mysql_prepare_update(THD *thd, TABLE_LIST *table_list, +bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, Item **conds, uint order_num, ORDER *order) { TABLE *table= table_list->table; @@ -532,16 +526,17 @@ int mysql_prepare_update(THD *thd, TABLE_LIST *table_list, setup_order(thd, select_lex->ref_pointer_array, table_list, all_fields, all_fields, order) || setup_ftfuncs(select_lex)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); /* Check that we are not using table that we are updating in a sub select */ if (unique_table(table_list, table_list->next_independent())) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); - DBUG_RETURN(-1); + my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), MYF(0), + table_list->real_name); + DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, conds); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -655,7 +650,8 @@ bool mysql_multi_update_prepare(THD *thd) if ((readonly_tables & tl->table->map) && (tables_for_update & tl->table->map)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), tl->alias, "UPDATE"); + my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), + MYF(0), tl->alias, "UPDATE"); DBUG_RETURN(TRUE); } } @@ -741,7 +737,7 @@ int multi_update::prepare(List ¬_used_values, if (!tables_to_update) { - my_error(ER_NO_TABLES_USED, MYF(0)); + my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0)); DBUG_RETURN(1); } @@ -1028,16 +1024,10 @@ bool multi_update::send_data(List ¬_used_values) { table->status|= STATUS_UPDATED; store_record(table,record[1]); - if (fill_record(*fields_for_table[offset], *values_for_table[offset], 0)) - { - /* Field::store methods can't send errors */ - if (!thd->net.report_error) - { - /* TODO: convert last warning to error */ - my_error(ER_UNKNOWN_ERROR, MYF(0)); - } + if (fill_record(thd, *fields_for_table[offset], + *values_for_table[offset], 0)) DBUG_RETURN(1); - } + found++; if (compare_record(table, thd->query_id)) { @@ -1075,7 +1065,7 @@ bool multi_update::send_data(List ¬_used_values) { int error; TABLE *tmp_table= tmp_tables[offset]; - fill_record(tmp_table->field+1, *values_for_table[offset], 1); + fill_record(thd, tmp_table->field+1, *values_for_table[offset], 1); found++; /* Store pointer to row */ memcpy((char*) tmp_table->field[0]->ptr, diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 7894287aee4..296d6c16590 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -71,9 +71,10 @@ bool mysql_create_view(THD *thd, if (lex->derived_tables || lex->variables_used || lex->param_list.elements) { - my_error((lex->derived_tables ? + int err= (lex->derived_tables ? ER_VIEW_SELECT_DERIVED : - ER_VIEW_SELECT_VARIABLE), MYF(0)); + ER_VIEW_SELECT_VARIABLE); + my_message(err, ER(err), MYF(0)); res= TRUE; goto err; } @@ -188,7 +189,8 @@ bool mysql_create_view(THD *thd, /* is this table temporary and is not view? */ if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view) { - my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); + my_printf_error(ER_VIEW_SELECT_TMPTABLE, + ER(ER_VIEW_SELECT_TMPTABLE), MYF(0), tbl->alias); res= TRUE; goto err; } @@ -198,7 +200,8 @@ bool mysql_create_view(THD *thd, strcmp(tbl->view_db.str, view->db) == 0 && strcmp(tbl->view_name.str, view->real_name) == 0) { - my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + tbl->view_db.str, tbl->view_name.str); res= TRUE; goto err; } @@ -253,7 +256,8 @@ bool mysql_create_view(THD *thd, { if (strcmp(item->name, check->name) == 0) { - my_error(ER_DUP_FIELDNAME, MYF(0), item->name); + my_printf_error(ER_DUP_FIELDNAME, ER(ER_DUP_FIELDNAME), + MYF(0), item->name); DBUG_RETURN(TRUE); } } @@ -426,7 +430,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, { if (mode == VIEW_CREATE_NEW) { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), view->alias); + my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), + MYF(0), view->alias); DBUG_RETURN(-1); } @@ -436,8 +441,9 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, if (!parser->ok() || strncmp("VIEW", parser->type()->str, parser->type()->length)) { - my_error(ER_WRONG_OBJECT, MYF(0), (view->db ? view->db : thd->db), - view->real_name, "VIEW"); + my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), + (view->db ? view->db : thd->db), + view->real_name, "VIEW"); DBUG_RETURN(-1); } @@ -457,7 +463,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, { if (mode == VIEW_ALTER) { - my_error(ER_NO_SUCH_TABLE, MYF(0), view->db, view->alias); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + view->db, view->alias); DBUG_RETURN(-1); } } @@ -500,7 +507,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, if (view->with_check != VIEW_CHECK_NONE && !view->updatable_view) { - my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->real_name); + my_printf_error(ER_VIEW_NONUPD_CHECK, ER(ER_VIEW_NONUPD_CHECK), MYF(0), + view->db, view->real_name); DBUG_RETURN(-1); } @@ -671,7 +679,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) if (check_table_access(thd, SELECT_ACL, view_tables, 1) && check_table_access(thd, SHOW_VIEW_ACL, table, 1)) { - my_error(ER_VIEW_NO_EXPLAIN, MYF(0)); + my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0)); goto err; } } @@ -851,9 +859,11 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) continue; } if (type) - my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->real_name, "VIEW"); + my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), + view->db, view->real_name, "VIEW"); else - my_error(ER_BAD_TABLE_ERROR, MYF(0), name); + my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), + name); goto err; } if (my_delete(path, MYF(MY_WME))) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index bdeb5a7d98d..ccffefc4b8e 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -813,7 +813,7 @@ query: if (!thd->bootstrap && (!(thd->lex->select_lex.options & OPTION_FOUND_COMMENT))) { - my_error(ER_EMPTY_QUERY, MYF(0)); + my_message(ER_EMPTY_QUERY, ER(ER_EMPTY_QUERY), MYF(0)); YYABORT; } else @@ -1463,7 +1463,8 @@ sp_fdparam: if (spc->find_pvar(&$1, TRUE)) { - my_error(ER_SP_DUP_PARAM, MYF(0), $1.str); + my_printf_error(ER_SP_DUP_PARAM, ER(ER_SP_DUP_PARAM), MYF(0), + $1.str); YYABORT; } spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in); @@ -1489,7 +1490,8 @@ sp_pdparam: if (spc->find_pvar(&$2, TRUE)) { - my_error(ER_SP_DUP_PARAM, MYF(0), $2.str); + my_printf_error(ER_SP_DUP_PARAM, ER(ER_SP_DUP_PARAM), MYF(0), + $2.str); YYABORT; } spc->push_pvar(&$2, (enum enum_field_types)$3, @@ -1523,12 +1525,14 @@ sp_decls: better error handling this way.) */ if (($2.vars || $2.conds) && ($1.curs || $1.hndlrs)) { /* Variable or condition following cursor or handler */ - my_error(ER_SP_VARCOND_AFTER_CURSHNDLR, MYF(0)); + my_message(ER_SP_VARCOND_AFTER_CURSHNDLR, + ER(ER_SP_VARCOND_AFTER_CURSHNDLR), MYF(0)); YYABORT; } if ($2.curs && $1.hndlrs) { /* Cursor following handler */ - my_error(ER_SP_CURSOR_AFTER_HANDLER, MYF(0)); + my_message(ER_SP_CURSOR_AFTER_HANDLER, + ER(ER_SP_CURSOR_AFTER_HANDLER), MYF(0)); YYABORT; } $$.vars= $1.vars + $2.vars; @@ -1576,7 +1580,8 @@ sp_decl: if (spc->find_cond(&$2, TRUE)) { - my_error(ER_SP_DUP_COND, MYF(0), $2.str); + my_printf_error(ER_SP_DUP_COND, ER(ER_SP_DUP_COND), MYF(0), + $2.str); YYABORT; } YYTHD->lex->spcont->push_cond(&$2, $5); @@ -1633,7 +1638,8 @@ sp_decl: if (ctx->find_cursor(&$2, &offp, TRUE)) { - my_error(ER_SP_DUP_CURS, MYF(0), $2.str); + my_printf_error(ER_SP_DUP_CURS, ER(ER_SP_DUP_CURS), MYF(0), + $2.str); delete $5; YYABORT; } @@ -1660,12 +1666,14 @@ sp_cursor_stmt: if (lex->sql_command != SQLCOM_SELECT) { - my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0)); + my_message(ER_SP_BAD_CURSOR_QUERY, ER(ER_SP_BAD_CURSOR_QUERY), + MYF(0)); YYABORT; } if (lex->result) { - my_error(ER_SP_BAD_CURSOR_SELECT, MYF(0)); + my_message(ER_SP_BAD_CURSOR_SELECT, ER(ER_SP_BAD_CURSOR_SELECT), + MYF(0)); YYABORT; } lex->sp_lex_in_use= TRUE; @@ -1735,7 +1743,8 @@ sp_hcond: $$= Lex->spcont->find_cond(&$1); if ($$ == NULL) { - my_error(ER_SP_COND_MISMATCH, MYF(0), $1.str); + my_printf_error(ER_SP_COND_MISMATCH, ER(ER_SP_COND_MISMATCH), + MYF(0), $1.str); YYABORT; } } @@ -1764,7 +1773,8 @@ sp_decl_idents: if (spc->find_pvar(&$1, TRUE)) { - my_error(ER_SP_DUP_VAR, MYF(0), $1.str); + my_printf_error(ER_SP_DUP_VAR, ER(ER_SP_DUP_VAR), MYF(0), + $1.str); YYABORT; } spc->push_pvar(&$1, (enum_field_types)0, sp_param_in); @@ -1777,7 +1787,8 @@ sp_decl_idents: if (spc->find_pvar(&$3, TRUE)) { - my_error(ER_SP_DUP_VAR, MYF(0), $3.str); + my_printf_error(ER_SP_DUP_VAR, ER(ER_SP_DUP_VAR), MYF(0), + $3.str); YYABORT; } spc->push_pvar(&$3, (enum_field_types)0, sp_param_in); @@ -1810,7 +1821,7 @@ sp_proc_stmt: } if (lex->sql_command == SQLCOM_CHANGE_DB) { /* "USE db" doesn't work in a procedure */ - my_error(ER_SP_NO_USE, MYF(0)); + my_message(ER_SP_NO_USE, ER(ER_SP_NO_USE), MYF(0)); YYABORT; } /* Don't add an instruction for empty SET statements. @@ -1829,7 +1840,7 @@ sp_proc_stmt: */ if (sp->m_type != TYPE_ENUM_PROCEDURE) { - my_error(ER_SP_BADSTATEMENT, MYF(0)); + my_message(ER_SP_BADSTATEMENT, ER(ER_SP_BADSTATEMENT), MYF(0)); YYABORT; } else @@ -1859,7 +1870,7 @@ sp_proc_stmt: if (lex->sphead->m_type == TYPE_ENUM_PROCEDURE) { - my_error(ER_SP_BADRETURN, MYF(0)); + my_message(ER_SP_BADRETURN, ER(ER_SP_BADRETURN), MYF(0)); YYABORT; } else @@ -1868,7 +1879,7 @@ sp_proc_stmt: if ($2->type() == Item::SUBSELECT_ITEM) { /* QQ For now, just disallow subselects as values */ - my_error(ER_SP_BADSTATEMENT, MYF(0)); + my_message(ER_SP_BADSTATEMENT, ER(ER_SP_BADSTATEMENT), MYF(0)); YYABORT; } i= new sp_instr_freturn(lex->sphead->instructions(), @@ -1931,7 +1942,9 @@ sp_proc_stmt: if (! lab) { - my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "LEAVE", $2.str); + my_printf_error(ER_SP_LILABEL_MISMATCH, + ER(ER_SP_LILABEL_MISMATCH), MYF(0), + "LEAVE", $2.str); YYABORT; } else @@ -1961,7 +1974,9 @@ sp_proc_stmt: if (! lab || lab->type != SP_LAB_ITER) { - my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "ITERATE", $2.str); + my_printf_error(ER_SP_LILABEL_MISMATCH, + ER(ER_SP_LILABEL_MISMATCH), MYF(0), + "ITERATE", $2.str); YYABORT; } else @@ -1989,7 +2004,8 @@ sp_proc_stmt: if (lab) { - my_error(ER_SP_LABEL_REDEFINE, MYF(0), $2.str); + my_printf_error(ER_SP_LABEL_REDEFINE, + ER(ER_SP_LABEL_REDEFINE), MYF(0), $2.str); YYABORT; } else @@ -2013,7 +2029,7 @@ sp_proc_stmt: if (sp->m_in_handler) { - my_error(ER_SP_GOTO_IN_HNDLR, MYF(0)); + my_message(ER_SP_GOTO_IN_HNDLR, ER(ER_SP_GOTO_IN_HNDLR), MYF(0)); YYABORT; } lab= ctx->find_label($2.str); @@ -2064,7 +2080,8 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); + my_printf_error(ER_SP_CURSOR_MISMATCH, + ER(ER_SP_CURSOR_MISMATCH), MYF(0), $2.str); YYABORT; } i= new sp_instr_copen(sp->instructions(), lex->spcont, offset); @@ -2079,7 +2096,8 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); + my_printf_error(ER_SP_CURSOR_MISMATCH, + ER(ER_SP_CURSOR_MISMATCH), MYF(0), $2.str); YYABORT; } i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset); @@ -2096,7 +2114,8 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); + my_printf_error(ER_SP_CURSOR_MISMATCH, + ER(ER_SP_CURSOR_MISMATCH), MYF(0), $2.str); YYABORT; } i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset); @@ -2114,7 +2133,8 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$1))) { - my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); + my_printf_error(ER_SP_UNDECLARED_VAR, + ER(ER_SP_UNDECLARED_VAR), MYF(0), $1.str); YYABORT; } else @@ -2136,7 +2156,8 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$3))) { - my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str); + my_printf_error(ER_SP_UNDECLARED_VAR, + ER(ER_SP_UNDECLARED_VAR), MYF(0), $3.str); YYABORT; } else @@ -2260,7 +2281,8 @@ sp_labeled_control: if (lab) { - my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str); + my_printf_error(ER_SP_LABEL_REDEFINE, + ER(ER_SP_LABEL_REDEFINE), MYF(0), $1.str); YYABORT; } else @@ -2281,7 +2303,8 @@ sp_labeled_control: if (!lab || my_strcasecmp(system_charset_info, $5.str, lab->name) != 0) { - my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str); + my_printf_error(ER_SP_LABEL_MISMATCH, + ER(ER_SP_LABEL_MISMATCH), MYF(0), $5.str); YYABORT; } } @@ -2539,9 +2562,11 @@ default_charset: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - my_error(ER_CONFLICTING_DECLARATIONS, MYF(0), - "CHARACTER SET ", cinfo->default_table_charset->csname, - "CHARACTER SET ", $4->csname); + my_printf_error(ER_CONFLICTING_DECLARATIONS, + ER(ER_CONFLICTING_DECLARATIONS), MYF(0), + "CHARACTER SET ", + cinfo->default_table_charset->csname, + "CHARACTER SET ", $4->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2556,8 +2581,9 @@ default_collation: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - $4->name, cinfo->default_table_charset->csname); + my_printf_error(ER_COLLATION_CHARSET_MISMATCH, + ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), + $4->name, cinfo->default_table_charset->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2569,7 +2595,8 @@ storage_engines: { $$ = ha_resolve_by_name($1.str,$1.length); if ($$ == DB_TYPE_UNKNOWN) { - my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str); + my_printf_error(ER_UNKNOWN_STORAGE_ENGINE, + ER(ER_UNKNOWN_STORAGE_ENGINE), MYF(0), $1.str); YYABORT; } }; @@ -2755,9 +2782,10 @@ type: Lex->uint_geom_type= (uint)$1; $$=FIELD_TYPE_GEOMETRY; #else - my_error(ER_FEATURE_DISABLED, MYF(0) - sym_group_geom.name, - sym_group_geom.needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0) + sym_group_geom.name, + sym_group_geom.needed_define); YYABORT; #endif } @@ -2924,8 +2952,9 @@ attribute: { if (Lex->charset && !my_charset_same(Lex->charset,$2)) { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - $2->name,Lex->charset->csname); + my_printf_error(ER_COLLATION_CHARSET_MISMATCH, + ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), + $2->name,Lex->charset->csname); YYABORT; } else @@ -2950,7 +2979,8 @@ charset_name: { if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0)))) { - my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); + my_printf_error(ER_UNKNOWN_CHARACTER_SET, + ER(ER_UNKNOWN_CHARACTER_SET), MYF(0), $1.str); YYABORT; } } @@ -2968,7 +2998,8 @@ old_or_new_charset_name: if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) && !($$=get_old_charset_by_name($1.str))) { - my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); + my_printf_error(ER_UNKNOWN_CHARACTER_SET, + ER(ER_UNKNOWN_CHARACTER_SET), MYF(0), $1.str); YYABORT; } } @@ -2984,7 +3015,8 @@ collation_name: { if (!($$=get_charset_by_name($1.str,MYF(0)))) { - my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str); + my_printf_error(ER_UNKNOWN_COLLATION, + ER(ER_UNKNOWN_COLLATION), MYF(0), $1.str); YYABORT; } }; @@ -3073,8 +3105,9 @@ key_type: #ifdef HAVE_SPATIAL $$= Key::SPATIAL; #else - my_error(ER_FEATURE_DISABLED, MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif }; @@ -3106,7 +3139,7 @@ opt_unique_or_fulltext: #ifdef HAVE_SPATIAL $$= Key::SPATIAL; #else - my_error(ER_FEATURE_DISABLED, MYF(0), + my_message(ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED), MYF(0), sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif @@ -3332,7 +3365,8 @@ alter_list_item: if (check_table_name($3->table.str,$3->table.length) || $3->db.str && check_db_name($3->db.str)) { - my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str); + my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), + MYF(0), $3->table.str); YYABORT; } lex->alter_info.flags|= ALTER_RENAME; @@ -3347,8 +3381,9 @@ alter_list_item: $5= $5 ? $5 : $4; if (!my_charset_same($4,$5)) { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - $5->name, $4->csname); + my_printf_error(ER_COLLATION_CHARSET_MISMATCH, + ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), + $5->name, $4->csname); YYABORT; } LEX *lex= Lex; @@ -3470,7 +3505,8 @@ slave_until: !((lex->mi.log_file_name && lex->mi.pos) || (lex->mi.relay_log_name && lex->mi.relay_log_pos))) { - my_error(ER_BAD_SLAVE_UNTIL_COND, MYF(0)); + my_message(ER_BAD_SLAVE_UNTIL_COND, + ER(ER_BAD_SLAVE_UNTIL_COND), MYF(0)); YYABORT; } @@ -4183,9 +4219,10 @@ simple_expr: { if (!$1.symbol->create_func) { - my_error(ER_FEATURE_DISABLED, MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(void))($1.symbol->create_func))(); @@ -4194,9 +4231,10 @@ simple_expr: { if (!$1.symbol->create_func) { - my_error(ER_FEATURE_DISABLED, MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*))($1.symbol->create_func))($3); @@ -4205,9 +4243,10 @@ simple_expr: { if (!$1.symbol->create_func) { - my_error(ER_FEATURE_DISABLED, MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5); @@ -4216,9 +4255,10 @@ simple_expr: { if (!$1.symbol->create_func) { - my_error(ER_FEATURE_DISABLED, MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7); @@ -4321,8 +4361,9 @@ simple_expr: #ifdef HAVE_SPATIAL $$= $1; #else - my_error(ER_FEATURE_DISABLED, MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_printf_error(ER_FEATURE_DISABLED, + ER(ER_FEATURE_DISABLED), MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif } @@ -5378,7 +5419,8 @@ select_var_ident: if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1))) { - my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); + my_printf_error(ER_SP_UNDECLARED_VAR, + ER(ER_SP_UNDECLARED_VAR), MYF(0), $1.str); YYABORT; } if (! lex->result) @@ -5733,8 +5775,9 @@ update: else if (lex->select_lex.get_table_list()->derived) { /* it is single table update and it is update of derived table */ - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), - lex->select_lex.get_table_list()->alias, "UPDATE"); + my_printf_error(ER_NON_UPDATABLE_TABLE, + ER(ER_NON_UPDATABLE_TABLE), MYF(0), + lex->select_lex.get_table_list()->alias, "UPDATE"); YYABORT; } } @@ -6241,7 +6284,8 @@ kill: LEX *lex=Lex; if ($3->fix_fields(lex->thd, 0, &$3) || $3->check_cols(1)) { - my_error(ER_SET_CONSTANTS_ONLY, MYF(0)); + my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), + MYF(0)); YYABORT; } lex->sql_command=SQLCOM_KILL; @@ -6388,7 +6432,7 @@ param_marker: (uchar *) thd->query)); if (!($$= item) || lex->param_list.push_back(item)) { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); YYABORT; } } @@ -6564,8 +6608,9 @@ simple_ident_q: FIXME. Far from perfect solution. See comment for "SET NEW.field_name:=..." for more info. */ - my_error(ER_BAD_FIELD_ERROR, MYF(0), $3.str, - new_row ? "NEW": "OLD"); + my_printf_error(ER_BAD_FIELD_ERROR, + ER(ER_BAD_FIELD_ERROR), MYF(0), + $3.str, new_row ? "NEW": "OLD"); YYABORT; } @@ -6652,8 +6697,9 @@ IDENT_sys: $1.length); if (wlen < $1.length) { - my_error(ER_INVALID_CHARACTER_STRING, MYF(0), cs->csname, - $1.str + wlen); + my_printf_error(ER_INVALID_CHARACTER_STRING, + ER(ER_INVALID_CHARACTER_STRING), MYF(0), + cs->csname, $1.str + wlen); YYABORT; } $$= $1; @@ -7032,7 +7078,8 @@ option_value: */ if (lex->query_tables) { - my_error(ER_SP_SUBSELECT_NYI, MYF(0)); + my_message(ER_SP_SUBSELECT_NYI, ER(ER_SP_SUBSELECT_NYI), + MYF(0)); YYABORT; } sp_instr_set_user_var *i= @@ -7055,7 +7102,8 @@ option_value: sp_instr_set_trigger_field *i; if (lex->query_tables) { - my_error(ER_SP_SUBSELECT_NYI, MYF(0)); + my_message(ER_SP_SUBSELECT_NYI, ER(ER_SP_SUBSELECT_NYI), + MYF(0)); YYABORT; } if ($3) @@ -7084,7 +7132,8 @@ option_value: Error message also should be improved. */ - my_error(ER_BAD_FIELD_ERROR, MYF(0), $1.base_name, "NEW"); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), + MYF(0), $1.base_name, "NEW"); YYABORT; } lex->sphead->add_instr(i); @@ -7150,8 +7199,9 @@ option_value: $3= $3 ? $3 : $2; if (!my_charset_same($2,$3)) { - my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), - $3->name, $2->csname); + my_printf_error(ER_COLLATION_CHARSET_MISMATCH, + ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), + $3->name, $2->csname); YYABORT; } lex->var_list.push_back(new set_var_collation_client($3,$3,$3)); @@ -7241,7 +7291,8 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); + my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, + ER(ER_VARIABLE_IS_NOT_STRUCT), MYF(0), $3.str); $$.var= tmp; $$.base_name= $1; } @@ -7252,7 +7303,8 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); + my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, + ER(ER_VARIABLE_IS_NOT_STRUCT), MYF(0), $3.str); $$.var= tmp; $$.base_name.str= (char*) "default"; $$.base_name.length= 7; @@ -7533,7 +7585,8 @@ opt_table: lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, + ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); YYABORT; } } @@ -7545,7 +7598,8 @@ opt_table: lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, + ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); YYABORT; } } @@ -7557,7 +7611,8 @@ opt_table: lex->grant= GLOBAL_ACLS & ~GRANT_ACL; else if (lex->columns.elements) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE, MYF(0)); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, + ER(ER_ILLEGAL_GRANT_FOR_TABLE), MYF(0)); YYABORT; } } diff --git a/sql/table.cc b/sql/table.cc index e372de57177..97b5a420279 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -957,11 +957,12 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype) uint length=dirname_part(buff,name); buff[length-1]=0; db=buff+dirname_length(buff); - my_error(ER_NO_SUCH_TABLE,MYF(0),db,form->real_name); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + db, form->real_name); } else - my_error(ER_FILE_NOT_FOUND,errortype, - fn_format(buff,name,form_dev,reg_ext,0),my_errno); + my_printf_error(ER_FILE_NOT_FOUND, ER(ER_FILE_NOT_FOUND), errortype, + fn_format(buff, name, form_dev, reg_ext, 0), my_errno); break; case 2: { @@ -969,14 +970,15 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype) datext= datext==NullS ? "" : datext; err_no= (my_errno == ENOENT) ? ER_FILE_NOT_FOUND : (my_errno == EAGAIN) ? ER_FILE_USED : ER_CANT_OPEN_FILE; - my_error(err_no,errortype, - fn_format(buff,form->real_name,form_dev,datext,2),my_errno); + my_printf_error(err_no, ER(err_no), errortype, + fn_format(buff, form->real_name, form_dev, datext, 2), + my_errno); break; } default: /* Better wrong error than none */ case 4: - my_error(ER_NOT_FORM_FILE,errortype, - fn_format(buff,name,form_dev,reg_ext,0)); + my_printf_error(ER_NOT_FORM_FILE, ER(ER_NOT_FORM_FILE), errortype, + fn_format(buff, name, form_dev, reg_ext, 0)); break; } DBUG_VOID_RETURN; @@ -1694,7 +1696,8 @@ err: if (thd->net.last_errno == ER_BAD_FIELD_ERROR) { thd->clear_error(); - my_error(ER_VIEW_INVALID, MYF(0), view_db.str, view_name.str); + my_printf_error(ER_VIEW_INVALID, ER(ER_VIEW_INVALID), MYF(0), + view_db.str, view_name.str); } thd->lex->select_lex.no_wrap_view_item= save_wrapper; thd->lex->current_select= current_select_save; @@ -1730,7 +1733,8 @@ int st_table_list::view_check_option(THD *thd, bool ignore_failure) } else { - my_error(ER_VIEW_CHECK_FAILED, MYF(0), view_db.str, view_name.str); + my_printf_error(ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED), MYF(0), + view_db.str, view_name.str); return(VIEW_CHECK_ERROR); } } diff --git a/sql/unireg.cc b/sql/unireg.cc index 2a6abdb1cfd..8988c847476 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -383,7 +383,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (create_fields.elements > MAX_FIELDS) { - my_error(ER_TOO_MANY_FIELDS,MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } @@ -448,7 +448,7 @@ static bool pack_header(uchar *forminfo, enum db_type table_type, if (info_length+(ulong) create_fields.elements*FCOMP+288+ n_length+int_length+com_length > 65535L || int_count > 255) { - my_error(ER_TOO_MANY_FIELDS,MYF(0)); + my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0)); DBUG_RETURN(1); } From a2cca076171c2960e6e5c7a72778fe4ef0f3a812 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 12 Nov 2004 14:38:01 +0200 Subject: [PATCH 75/94] Ensure that new connections are in state SLEEP (for nicer show processlist) --- sql/sql_parse.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a14a3da8391..c680b4e420d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1028,6 +1028,7 @@ pthread_handler_decl(handle_one_connection,arg) thd->version= refresh_version; thd->proc_info= 0; + thd->command= COM_SLEEP; thd->set_time(); thd->init_for_queries(); From d927503a9670bef6d8435428013c0f8e08e8d221 Mon Sep 17 00:00:00 2001 From: "paul@ice.snake.net" <> Date: Fri, 12 Nov 2004 07:13:46 -0600 Subject: [PATCH 76/94] mysqldump.c: Add missing sentinel. --- client/mysqldump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 864fe38a204..a8c1d3c692b 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -350,7 +350,8 @@ static struct my_option my_long_options[] = {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, - MALLOC_OVERHEAD-1024, 1024, 0} + MALLOC_OVERHEAD-1024, 1024, 0}, + {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; static const char *load_default_groups[]= { "mysqldump","client",0 }; From e7a24660244e7f2a779f32ae4a89f2489aa77e5f Mon Sep 17 00:00:00 2001 From: "dlenev@brandersnatch.localdomain" <> Date: Fri, 12 Nov 2004 17:04:07 +0300 Subject: [PATCH 77/94] Fix for bug #5890 "Triggers fail for DELETE without WHERE". If we have DELETE with always true WHERE clause we should not use optimized delete_all_rows() method for tables with DELETE triggers, because in this case we will lose side-effect of deletion. --- mysql-test/r/trigger.result | 12 ++++++++++++ mysql-test/t/trigger.test | 17 +++++++++++++++++ sql/sql_delete.cc | 9 +++++++-- sql/sql_trigger.h | 6 ++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 2a2e10dbbd5..b45aaea0cbe 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -174,3 +174,15 @@ create trigger tx1 before insert on t1 for each row set new.x1col = 'x'; insert into t1 values ('y'); drop trigger t1.tx1; drop table t1; +create table t1 (i int) engine=myisam; +insert into t1 values (1), (2); +create trigger trg1 before delete on t1 for each row set @del_before:= @del_before + old.i; +create trigger trg2 after delete on t1 for each row set @del_after:= @del_after + old.i; +set @del_before:=0, @del_after:= 0; +delete from t1; +select @del_before, @del_after; +@del_before @del_after +3 3 +drop trigger t1.trg1; +drop trigger t1.trg2; +drop table t1; diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index f842d561dc1..7dc976cf716 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -207,3 +207,20 @@ create trigger tx1 before insert on t1 for each row set new.x1col = 'x'; insert into t1 values ('y'); drop trigger t1.tx1; drop table t1; + +# +# Test for bug #5890 "Triggers fail for DELETE without WHERE". +# If we are going to delete all rows in table but DELETE triggers exist +# we should perform row-by-row deletion instead of using optimized +# delete_all_rows() method. +# +create table t1 (i int) engine=myisam; +insert into t1 values (1), (2); +create trigger trg1 before delete on t1 for each row set @del_before:= @del_before + old.i; +create trigger trg2 after delete on t1 for each row set @del_after:= @del_after + old.i; +set @del_before:=0, @del_after:= 0; +delete from t1; +select @del_before, @del_after; +drop trigger t1.trg1; +drop trigger t1.trg2; +drop table t1; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 8bdf19195f3..1cd0d0177f6 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -62,9 +62,14 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, if (thd->lex->duplicates == DUP_IGNORE) thd->lex->select_lex.no_error= 1; - /* Test if the user wants to delete all rows */ + /* + Test if the user wants to delete all rows and deletion doesn't have + any side-effects (because of triggers), so we can use optimized + handler::delete_all_rows() method. + */ if (!using_limit && const_cond && (!conds || conds->val_int()) && - !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE))) + !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) && + !(table->triggers && table->triggers->has_delete_triggers())) { deleted= table->file->records; if (!(error=table->file->delete_all_rows())) diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 8ab2ab003f8..d0376f056d9 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -58,5 +58,11 @@ public: static bool check_n_load(THD *thd, const char *db, const char *table_name, TABLE *table); + bool has_delete_triggers() + { + return (bodies[TRG_EVENT_DELETE][TRG_ACTION_BEFORE] || + bodies[TRG_EVENT_DELETE][TRG_ACTION_AFTER]); + } + friend class Item_trigger_field; }; From 1288f453cc834ba5cf432282ae054a2d69efcf71 Mon Sep 17 00:00:00 2001 From: "paul@ice.snake.net" <> Date: Fri, 12 Nov 2004 08:45:58 -0600 Subject: [PATCH 78/94] fill_help_tables.sh: Recognize another Texinfo tag. --- scripts/fill_help_tables.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/fill_help_tables.sh b/scripts/fill_help_tables.sh index 1f44e9fa488..78dfe7b6088 100644 --- a/scripts/fill_help_tables.sh +++ b/scripts/fill_help_tables.sh @@ -198,6 +198,7 @@ sub prepare_name $a =~ s/(\@tab)/\t/g; $a =~ s/\@item/ /g; $a =~ s/\@minus\{\}/-/g; + $a =~ s/\@dots\{\}/.../g; $a =~ s/\@var\{((.|\n)+?)\}/$1/go; $a =~ s/\@command\{((.|\n)+?)\}/$1/go; $a =~ s/\@code\{((.|\n)+?)\}/$1/go; @@ -248,6 +249,7 @@ sub prepare_description $a =~ s/(\@tindex\s(.*?)\n)//g; $a =~ s/(\@c\s(.*?)\n)//g; $a =~ s/\@minus\{\}/-/g; + $a =~ s/\@dots\{\}/.../g; $a =~ s/\@var\{((.|\n)+?)\}/$1/go; $a =~ s/\@command\{((.|\n)+?)\}/$1/go; $a =~ s/\@code\{((.|\n)+?)\}/$1/go; @@ -280,6 +282,7 @@ sub prepare_example $a =~ s/(^\@c for_help_topic(.*?)\n)//g; $a =~ s/\@var\{((.|\n)+?)\}/$1/go; + $a =~ s/\@dots\{\}/.../g; $a =~ s/\\/\\\\/g; $a =~ s/(\@{)/{/g; $a =~ s/(\@})/}/g; From e20732b073af46e065ad67af944ba538330c1355 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Fri, 12 Nov 2004 16:41:53 +0100 Subject: [PATCH 79/94] typos in error messages fixed --- sql/share/french/errmsg.txt | 2 +- sql/share/greek/errmsg.txt | 2 +- sql/share/portuguese/errmsg.txt | 2 +- sql/share/romanian/errmsg.txt | 2 +- sql/share/serbian/errmsg.txt | 2 +- sql/share/spanish/errmsg.txt | 6 +++--- sql/share/swedish/errmsg.txt | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index 355e784b156..bb2bd29171a 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -209,7 +209,7 @@ character-set=latin1 "Erreur d'écriture réseau reçue du maître", "Impossible de trouver un index FULLTEXT correspondant à cette liste de colonnes", "Impossible d'exécuter la commande car vous avez des tables verrouillées ou une transaction active", -"Variable système '%-.64' inconnue", +"Variable système '%-.64s' inconnue", "La table '%-.64s' est marquée 'crashed' et devrait être réparée", "La table '%-.64s' est marquée 'crashed' et le dernier 'repair' a échoué", "Attention: certaines tables ne supportant pas les transactions ont été changées et elles ne pourront pas être restituées", diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index 06f31a79a73..87168431595 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -168,7 +168,7 @@ character-set=greek "You have an error in your SQL syntax", "Delayed insert thread couldn't get requested lock for table %-.64s", "Too many delayed threads in use", -"Aborted connection %ld to db: '%-.64s' user: '%-32s' (%-.64s)", +"Aborted connection %ld to db: '%-.64s' user: '%-.32s' (%-.64s)", "Got a packet bigger than 'max_allowed_packet' bytes", "Got a read error from the connection pipe", "Got an error from fcntl()", diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index c79c346008e..65d80918072 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -211,7 +211,7 @@ character-set=latin1 "Erro de rede gravando no 'master'", "Não pode encontrar um índice para o texto todo que combine com a lista de colunas", "Não pode executar o comando dado porque você tem tabelas ativas travadas ou uma transação ativa", -"Variável de sistema '%-.64' desconhecida", +"Variável de sistema '%-.64s' desconhecida", "Tabela '%-.64s' está marcada como danificada e deve ser reparada", "Tabela '%-.64s' está marcada como danificada e a última reparação (automática?) falhou", "Aviso: Algumas tabelas não-transacionais alteradas não puderam ser reconstituídas (rolled back)", diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 7cb0427dc3f..01c22f00119 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -173,7 +173,7 @@ character-set=latin2 "Aveti o eroare in sintaxa RSQL", "Thread-ul pentru inserarea aminata nu a putut obtine lacatul (lock) pentru tabela %-.64s", "Prea multe threaduri aminate care sint in uz", -"Conectie terminata %ld la baza de date: '%-.64s' utilizator: '%-32s' (%-.64s)", +"Conectie terminata %ld la baza de date: '%-.64s' utilizator: '%-.32s' (%-.64s)", "Un packet mai mare decit 'max_allowed_packet' a fost primit", "Eroare la citire din cauza lui 'connection pipe'", "Eroare obtinuta de la fcntl()", diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index 45b56c8269c..06270f621e4 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -202,7 +202,7 @@ character-set=cp1250 "Greška u slanju mrežnih paketa na glavni server u klasteru", "Ne mogu da pronaðem 'FULLTEXT' indeks koli odgovara listi kolona", "Ne mogu da izvršim datu komandu zbog toga što su tabele zakljuèane ili je transakcija u toku", -"Nepoznata sistemska promenljiva '%-.64'", +"Nepoznata sistemska promenljiva '%-.64s'", "Tabela '%-.64s' je markirana kao ošteæena i trebala bi biti popravljena", "Tabela '%-.64s' je markirana kao ošteæena, a zadnja (automatska?) popravka je bila neuspela", "Upozorenje: Neke izmenjene tabele ne podržavaju komandu 'ROLLBACK'", diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index bd2439c44a6..c5b4fd34eca 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -238,9 +238,9 @@ character-set=latin1 "No puede adicionar clave extranjera constraint", "No puede adicionar una línea hijo: falla de clave extranjera constraint", "No puede deletar una línea padre: falla de clave extranjera constraint", -"Error de coneccion a master: %-128s", -"Error executando el query en master: %-128%", -"Error de %s: %-128%", +"Error de coneccion a master: %-.128s", +"Error executando el query en master: %-.128s", +"Error de %s: %-.128s", "Equivocado uso de %s y %s", "El comando SELECT usado tiene diferente número de columnas", "No puedo ejecutar el query porque usted tiene conflicto de traba de lectura", diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index da75e4fcede..4dc42389d89 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -101,7 +101,7 @@ character-set=latin1 "Tabellen '%-.64s' har inget index som motsvarar det angivna i CREATE INDEX. Skapa om tabellen", "Fältseparatorerna är vad som förväntades. Kontrollera mot manualen", "Man kan inte använda fast radlängd med blobs. Använd 'fields terminated by'", -"Textfilen '%' måste finnas i databasbiblioteket eller vara läsbar för alla", +"Textfilen '%.64s' måste finnas i databasbiblioteket eller vara läsbar för alla", "Filen '%-.64s' existerar redan", "Rader: %ld Bortagna: %ld Dubletter: %ld Varningar: %ld", "Rader: %ld Dubletter: %ld", @@ -200,7 +200,7 @@ character-set=latin1 "Fick fel %d vid ROLLBACK", "Fick fel %d vid FLUSH_LOGS", "Fick fel %d vid CHECKPOINT", -"Avbröt länken för tråd %ld till db '%-.64s', användare '%-.32s', host '%-.64s' (%.-64s)", +"Avbröt länken för tråd %ld till db '%-.64s', användare '%-.32s', host '%-.64s' (%-.64s)", "Tabellhanteraren klarar inte en binär kopiering av tabellen", "Binärloggen stängdes medan FLUSH MASTER utfördes", "Failed rebuilding the index of dumped table '%-.64s'", From e9c3887b583e06c7df5df3ca64c367022486a9fc Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 12 Nov 2004 17:44:17 +0200 Subject: [PATCH 80/94] After merge fixes --- client/mysqldump.c | 18 +++---- client/mysqltest.c | 3 +- myisam/mi_check.c | 9 ++-- mysql-test/r/grant.result | 50 ++++++++++---------- mysql-test/r/mix_innodb_myisam_binlog.result | 2 +- mysql-test/r/ps_1general.result | 42 ++++++++-------- mysql-test/r/timezone3.result | 4 +- mysql-test/t/ps_1general.test | 35 +++++++++----- sql-common/my_time.c | 23 +++++++-- sql/sql_acl.cc | 7 ++- 10 files changed, 112 insertions(+), 81 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index a501370f306..83967d62813 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -255,6 +255,14 @@ static struct my_option my_long_options[] = "Option automatically turns --lock-tables off.", (gptr*) &opt_master_data, (gptr*) &opt_master_data, 0, GET_UINT, REQUIRED_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0}, + {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", + (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, + GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, + (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, + {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", + (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, + GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, + MALLOC_OVERHEAD-1024, 1024, 0}, {"no-autocommit", OPT_AUTOCOMMIT, "Wrap tables with autocommit/commit statements.", (gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG, @@ -343,14 +351,7 @@ static struct my_option my_long_options[] = (gptr*) &where, (gptr*) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", - (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, - GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, - (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, - {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", - (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, - GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, - MALLOC_OVERHEAD-1024, 1024, 0} + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; static const char *load_default_groups[]= { "mysqldump","client",0 }; @@ -1679,7 +1680,6 @@ static void dumpTable(uint numFields, char *table) else if (opt_hex_blob && is_blob) { /* sakaik got the idea to to provide blob's in hex notation. */ - ulong counter; unsigned char *ptr= row[i], *end= ptr+ lengths[i]; fputs("0x", md_result_file); for (; ptr < end ; ptr++) diff --git a/client/mysqltest.c b/client/mysqltest.c index a207da21af5..dfaf48dd60e 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3351,7 +3351,8 @@ static void init_var_hash(MYSQL *mysql) my_hash_insert(&var_hash, (byte*) v); v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0); my_hash_insert(&var_hash, (byte*) v); - + v= var_init(0,"DB", 2, db, 0); + my_hash_insert(&var_hash, (byte*) v); DBUG_VOID_RETURN; } diff --git a/myisam/mi_check.c b/myisam/mi_check.c index bf684270c0a..2999482549c 100644 --- a/myisam/mi_check.c +++ b/myisam/mi_check.c @@ -658,10 +658,11 @@ static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, goto err; if (tmp_keys + subkeys) { - mi_check_print_error(param,"Number of words in the 2nd level tree " - "does not match the number in the header. " - "Parent word in on the page %s, offset %d", - llstr(page,llbuff), old_keypos-buff); + mi_check_print_error(param, + "Number of words in the 2nd level tree " + "does not match the number in the header. " + "Parent word in on the page %s, offset %u", + llstr(page,llbuff), (uint) (old_keypos-buff)); goto err; } (*keys)+=tmp_keys-1; diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index df3669e5927..f903e35fa1f 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -134,6 +134,31 @@ ERROR HY000: Incorrect usage of DB GRANT and GLOBAL PRIVILEGES select 1; 1 1 +insert into mysql.user (host, user) values ('localhost', 'test11'); +insert into mysql.db (host, db, user, select_priv) values +('localhost', 'a%', 'test11', 'Y'), ('localhost', 'ab%', 'test11', 'Y'); +alter table mysql.db order by db asc; +flush privileges; +show grants for test11@localhost; +Grants for test11@localhost +GRANT USAGE ON *.* TO 'test11'@'localhost' +GRANT SELECT ON `ab%`.* TO 'test11'@'localhost' +GRANT SELECT ON `a%`.* TO 'test11'@'localhost' +alter table mysql.db order by db desc; +flush privileges; +show grants for test11@localhost; +Grants for test11@localhost +GRANT USAGE ON *.* TO 'test11'@'localhost' +GRANT SELECT ON `ab%`.* TO 'test11'@'localhost' +GRANT SELECT ON `a%`.* TO 'test11'@'localhost' +delete from mysql.user where user='test11'; +delete from mysql.db where user='test11'; +create database mysqltest1; +grant usage on mysqltest1.* to test6123 identified by 'magic123'; +select host,db,user,select_priv,insert_priv from mysql.db where db="mysqltest1"; +host db user select_priv insert_priv +delete from mysql.user where user='test6123'; +drop database mysqltest1; create table t1 (a int); grant ALL PRIVILEGES on *.* to drop_user2@localhost with GRANT OPTION; show grants for drop_user2@localhost; @@ -229,31 +254,6 @@ GRANT SELECT ( REVOKE SELECT (ËÏÌ) ON ÂÄ.ÔÁÂ FROM ÀÚÅÒ@localhost; DROP DATABASE ÂÄ; SET NAMES latin1; -insert into mysql.user (host, user) values ('localhost', 'test11'); -insert into mysql.db (host, db, user, select_priv) values -('localhost', 'a%', 'test11', 'Y'), ('localhost', 'ab%', 'test11', 'Y'); -alter table mysql.db order by db asc; -flush privileges; -show grants for test11@localhost; -Grants for test11@localhost -GRANT USAGE ON *.* TO 'test11'@'localhost' -GRANT SELECT ON `ab%`.* TO 'test11'@'localhost' -GRANT SELECT ON `a%`.* TO 'test11'@'localhost' -alter table mysql.db order by db desc; -flush privileges; -show grants for test11@localhost; -Grants for test11@localhost -GRANT USAGE ON *.* TO 'test11'@'localhost' -GRANT SELECT ON `ab%`.* TO 'test11'@'localhost' -GRANT SELECT ON `a%`.* TO 'test11'@'localhost' -delete from mysql.user where user='test11'; -delete from mysql.db where user='test11'; -create database db6123; -grant usage on db6123.* to test6123 identified by 'magic123'; -select host,db,user,select_priv,insert_priv from mysql.db where db="db6123"; -host db user select_priv insert_priv -delete from mysql.user where user='test6123'; -drop database db6123; USE test; CREATE TABLE t1 (a int ); CREATE TABLE t2 LIKE t1; diff --git a/mysql-test/r/mix_innodb_myisam_binlog.result b/mysql-test/r/mix_innodb_myisam_binlog.result index a2717c68a4f..72288d1027b 100644 --- a/mysql-test/r/mix_innodb_myisam_binlog.result +++ b/mysql-test/r/mix_innodb_myisam_binlog.result @@ -194,7 +194,7 @@ select (@before:=unix_timestamp())*0; begin; select * from t1 for update; insert into t2 values (20); -Lock wait timeout exceeded; Try restarting transaction +ERROR HY000: Lock wait timeout exceeded; try restarting transaction select (@after:=unix_timestamp())*0; (@after:=unix_timestamp())*0 0 diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index ccf2945d488..5f8cb2597c6 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -1,4 +1,5 @@ -use test; +drop table if exists t5, t6, t7, t8; +drop database if exists mysqltest ; test_sequence ------ basic tests ------ drop table if exists t1, t9 ; @@ -558,7 +559,6 @@ execute stmt3; ERROR 42S01: Table 'new_t2' already exists rename table new_t2 to t2; drop table t2; -drop table if exists t5, t6, t7, t8 ; prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ; create table t5 (a int) ; execute stmt1 ; @@ -810,21 +810,24 @@ test_sequence ------ grant/revoke/drop affects a parallel session test ------ show grants for second_user@localhost ; ERROR 42000: There is no such grant defined for user 'second_user' on host 'localhost' -grant usage on test.* to second_user@localhost +create database mysqltest; +use mysqltest; +use test; +grant usage on mysqltest.* to second_user@localhost identified by 'looser' ; -grant select on test.t9 to second_user@localhost +grant select on mysqltest.t9 to second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' select current_user(); current_user() second_user@localhost show grants for current_user(); Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' prepare s_t9 from 'select c1 as my_col from t9 where c1= 1' ; execute s_t9 ; @@ -832,24 +835,24 @@ my_col 1 select a as my_col from t1; ERROR 42000: select command denied to user 'second_user'@'localhost' for table 't1' -grant select on test.t1 to second_user@localhost +grant select on mysqltest.t1 to second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t1` TO 'second_user'@'localhost' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' -drop table t9 ; +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost' +drop table mysqltest.t9 ; show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t1` TO 'second_user'@'localhost' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost' show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t1` TO 'second_user'@'localhost' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost' prepare s_t1 from 'select a as my_col from t1' ; execute s_t1 ; my_col @@ -858,17 +861,17 @@ my_col 3 4 execute s_t9 ; -ERROR 42S02: Table 'test.t9' doesn't exist -revoke all privileges on test.t1 from second_user@localhost +ERROR 42S02: Table 'mysqltest.t9' doesn't exist +revoke all privileges on mysqltest.t1 from second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' show grants for second_user@localhost ; Grants for second_user@localhost GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3' -GRANT SELECT ON `test`.`t9` TO 'second_user'@'localhost' +GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost' execute s_t1 ; ERROR 42000: select command denied to user 'second_user'@'localhost' for table 't1' revoke all privileges, grant option from second_user@localhost ; @@ -879,4 +882,5 @@ drop user second_user@localhost ; commit ; show grants for second_user@localhost ; ERROR 42000: There is no such grant defined for user 'second_user' on host 'localhost' -drop table t1 ; +drop table t1,t9 ; +drop database mysqltest; diff --git a/mysql-test/r/timezone3.result b/mysql-test/r/timezone3.result index 2135dd33511..ec0b6045f93 100644 --- a/mysql-test/r/timezone3.result +++ b/mysql-test/r/timezone3.result @@ -36,6 +36,6 @@ create table t1 (ts timestamp); insert into t1 values (19730101235900), (20040101235900); select * from t1; ts -19730101235900 -20040101235900 +1973-01-01 23:59:00 +2004-01-01 23:59:00 drop table t1; diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index 9e4acc2bf24..baa37dbf41d 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -8,7 +8,11 @@ # NOTE: PLEASE SEE THE DETAILED DESCRIPTION AT THE BOTTOM OF THIS FILE # BEFORE ADDING NEW TEST CASES HERE !!! -use test; +--disable_warnings +drop table if exists t5, t6, t7, t8; +drop database if exists mysqltest ; +--enable_warnings + --disable_query_log select '------ basic tests ------' as test_sequence ; --enable_query_log @@ -590,12 +594,9 @@ rename table new_t2 to t2; drop table t2; ## RENAME more than on TABLE within one statement # cases derived from client_test.c: test_rename() ---disable_warnings -drop table if exists t5, t6, t7, t8 ; ---enable_warnings prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ; create table t5 (a int) ; -# rename must fail, tc does not exist +# rename must fail, t7 does not exist --error 1017 execute stmt1 ; create table t7 (a int) ; @@ -864,15 +865,23 @@ select '------ grant/revoke/drop affects a parallel session test ------' --error 1141 show grants for second_user@localhost ; ## create a new user account by using GRANT statements on t9 -grant usage on test.* to second_user@localhost +create database mysqltest; +# create the tables (t1 and t9) used in many tests +use mysqltest; +--disable_query_log +--source include/ps_create.inc +--source include/ps_renew.inc +--enable_query_log +eval use $DB; +grant usage on mysqltest.* to second_user@localhost identified by 'looser' ; -grant select on test.t9 to second_user@localhost +grant select on mysqltest.t9 to second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; #### establish a second session to the new user account -connect (con3,localhost,second_user,looser,test); +connect (con3,localhost,second_user,looser,mysqltest); ## switch to the second session connection con3; # Who am I ? @@ -890,10 +899,10 @@ select a as my_col from t1; #### give access rights to t1 and drop table t9 ## switch back to the first session connection default; -grant select on test.t1 to second_user@localhost +grant select on mysqltest.t1 to second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; -drop table t9 ; +drop table mysqltest.t9 ; show grants for second_user@localhost ; @@ -912,7 +921,7 @@ execute s_t9 ; #### revoke the access rights to t1 ## switch back to the first session connection default; -revoke all privileges on test.t1 from second_user@localhost +revoke all privileges on mysqltest.t1 from second_user@localhost identified by 'looser' ; show grants for second_user@localhost ; @@ -937,8 +946,8 @@ commit ; --error 1141 show grants for second_user@localhost ; - -drop table t1 ; +drop table t1,t9 ; +drop database mysqltest; ##### RULES OF THUMB TO PRESERVE THE SYSTEMATICS OF THE PS TEST CASES ##### diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 6c020466e1e..d1a36a75a5a 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -664,6 +664,10 @@ my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap) I couldn't come up with a better way to get a repeatable result :( We can't use mktime() as it's buggy on many platforms and not thread safe. + + Note: this code assumes that our time_t estimation is not too far away + from real value (we assume that localtime_r(tmp) will return something + within 24 hrs from t) which is probably true for all current time zones. */ tmp=(time_t) (((calc_daynr((uint) t->year,(uint) t->month,(uint) t->day) - (long) days_at_timestart)*86400L + (long) t->hour*3600L + @@ -676,7 +680,8 @@ my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap) for (loop=0; loop < 2 && (t->hour != (uint) l_time->tm_hour || - t->minute != (uint) l_time->tm_min); + t->minute != (uint) l_time->tm_min || + t->second != (uint) l_time->tm_sec); loop++) { /* One check should be enough ? */ /* Get difference in days */ @@ -686,15 +691,22 @@ my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap) else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) + - (long) (60*((int) t->minute - (int) l_time->tm_min))); + (long) (60*((int) t->minute - (int) l_time->tm_min)) + + (long) ((int) t->second - (int) l_time->tm_sec)); current_timezone+= diff+3600; /* Compensate for -3600 above */ tmp+= (time_t) diff; localtime_r(&tmp,&tm_tmp); l_time=&tm_tmp; } /* - Fix that if we are in the not existing daylight saving time hour - we move the start of the next real hour + Fix that if we are in the non existing daylight saving time hour + we move the start of the next real hour. + + This code doesn't handle such exotical thing as time-gaps whose length + is more than one hour or non-integer (latter can theoretically happen + if one of seconds will be removed due leap correction, or because of + general time correction like it happened for Africa/Monrovia time zone + in year 1972). */ if (loop == 2 && t->hour != (uint) l_time->tm_hour) { @@ -704,7 +716,8 @@ my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, bool *in_dst_time_gap) else if (days > 1) days= -1; diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+ - (long) (60*((int) t->minute - (int) l_time->tm_min))); + (long) (60*((int) t->minute - (int) l_time->tm_min)) + + (long) ((int) t->second - (int) l_time->tm_sec)); if (diff == 3600) tmp+=3600 - t->minute*60 - t->second; /* Move to next hour */ else if (diff == -3600) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 9067d01a06d..98af43e17a7 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -970,6 +970,7 @@ ulong acl_get(const char *host, const char *ip, db_access=0; host_access= ~0; char key[ACL_KEY_LENGTH],*tmp_db,*end; acl_entry *entry; + DBUG_ENTER("acl_get"); VOID(pthread_mutex_lock(&acl_cache->lock)); end=strmov((tmp_db=strmov(strmov(key, ip ? ip : "")+1,user)+1),db); @@ -983,7 +984,8 @@ ulong acl_get(const char *host, const char *ip, { db_access=entry->access; VOID(pthread_mutex_unlock(&acl_cache->lock)); - return db_access; + DBUG_PRINT("exit", ("access: 0x%lx", db_access)); + DBUG_RETURN(db_access); } /* @@ -1035,7 +1037,8 @@ exit: acl_cache->add(entry); } VOID(pthread_mutex_unlock(&acl_cache->lock)); - return (db_access & host_access); + DBUG_PRINT("exit", ("access: 0x%lx", db_access & host_access)); + DBUG_RETURN(db_access & host_access); } /* From 379b46128f5203a8260334e9170998f1a8c36f8b Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Fri, 12 Nov 2004 18:30:30 +0200 Subject: [PATCH 81/94] Added possibility to run only certain tests by giving the test name(s) as argument(s) after options. Added option -T to display all current test names. --- tests/client_test.c | 405 ++++++++++++++++++++++++-------------------- 1 file changed, 217 insertions(+), 188 deletions(-) diff --git a/tests/client_test.c b/tests/client_test.c index 3c5598ee75a..aa9e62fa588 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -27,7 +27,7 @@ #include #include -#define VER "2.0" +#define VER "2.1" #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ /* set default options */ @@ -52,6 +52,12 @@ static double total_time; const char *default_dbug_option= "d:t:o,/tmp/client_test.trace"; +struct my_tests_st +{ + const char *name; + void (*function)(); +}; + #define myheader(str) \ if (opt_silent < 2) \ { \ @@ -11239,31 +11245,35 @@ static char **defaults_argv; static struct my_option client_test_long_options[] = { - {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, - 0, 0, 0, 0, 0}, + {"count", 't', "Number of times test to be executed", (char **) &opt_count, + (char **) &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, {"database", 'D', "Database to use", (char **) &opt_db, (char **) &opt_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"debug", '#', "Output debug log", (gptr*) &default_dbug_option, (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"host", 'h', "Connect to host", (char **) &opt_host, (char **) &opt_host, 0, GET_STR_ALLOC, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, + 0, 0, 0, 0, 0}, + {"host", 'h', "Connect to host", (char **) &opt_host, (char **) &opt_host, + 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"password", 'p', "Password to use when connecting to server. If password is not given it's asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection", (char **) &opt_port, + (char **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"show-tests", 'T', "Show all tests' names", 0, 0, 0, GET_NO_ARG, NO_ARG, + 0, 0, 0, 0, 0, 0}, + {"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, + 0}, + {"socket", 'S', "Socket file to use for connection", + (char **) &opt_unix_socket, (char **) &opt_unix_socket, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"testcase", 'c', + "May disable some code when runs as mysql-test-run testcase.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DONT_ALLOW_USER_CHANGE {"user", 'u', "User for login if not current user", (char **) &opt_user, (char **) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"port", 'P', "Port number to use for connection", (char **) &opt_port, - (char **) &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, - 0}, - {"socket", 'S', "Socket file to use for connection", (char **) &opt_unix_socket, - (char **) &opt_unix_socket, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"testcase", 'c', "May disable some code when runs as mysql-test-run testcase.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"count", 't', "Number of times test to be executed", (char **) &opt_count, - (char **) &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -11279,13 +11289,160 @@ static void usage(void) Copyright (C) 2002-2004 MySQL AB\n\ This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ and you are welcome to modify and redistribute it under the GPL license\n"); - printf("Usage: %s [OPTIONS]\n", my_progname); + printf("Usage: %s [OPTIONS] [TESTNAME1 TESTNAME2...]\n", my_progname); my_print_help(client_test_long_options); print_defaults("my", client_test_load_default_groups); my_print_variables(client_test_long_options); } +static struct my_tests_st my_tests[]= { + { "client_query", client_query }, +#if NOT_YET_WORKING + { "test_drop_temp", test_drop_temp }, +#endif + { "test_fetch_seek", test_fetch_seek }, + { "test_fetch_nobuffs", test_fetch_nobuffs }, + { "test_open_direct", test_open_direct }, + { "test_fetch_null", test_fetch_null }, + { "test_ps_null_param", test_ps_null_param }, + { "test_fetch_date", test_fetch_date }, + { "test_fetch_str", test_fetch_str }, + { "test_fetch_long", test_fetch_long }, + { "test_fetch_short", test_fetch_short }, + { "test_fetch_tiny", test_fetch_tiny }, + { "test_fetch_bigint", test_fetch_bigint }, + { "test_fetch_float", test_fetch_float }, + { "test_fetch_double", test_fetch_double }, + { "test_bind_result_ext", test_bind_result_ext }, + { "test_bind_result_ext1", test_bind_result_ext1 }, + { "test_select_direct", test_select_direct }, + { "test_select_prepare", test_select_prepare }, + { "test_select", test_select }, + { "test_select_version", test_select_version }, + { "test_ps_conj_select", test_ps_conj_select }, + { "test_select_show_table", test_select_show_table }, + { "test_func_fields", test_func_fields }, + { "test_long_data", test_long_data }, + { "test_insert", test_insert }, + { "test_set_variable", test_set_variable }, + { "test_select_show", test_select_show }, + { "test_prepare_noparam", test_prepare_noparam }, + { "test_bind_result", test_bind_result }, + { "test_prepare_simple", test_prepare_simple }, + { "test_prepare", test_prepare }, + { "test_null", test_null }, + { "test_debug_example", test_debug_example }, + { "test_update", test_update }, + { "test_simple_update", test_simple_update }, + { "test_simple_delete", test_simple_delete }, + { "test_double_compare", test_double_compare }, + { "client_store_result", client_store_result }, + { "client_use_result", client_use_result }, + { "test_tran_bdb", test_tran_bdb }, + { "test_tran_innodb", test_tran_innodb }, + { "test_prepare_ext", test_prepare_ext }, + { "test_prepare_syntax", test_prepare_syntax }, + { "test_field_names", test_field_names }, + { "test_field_flags", test_field_flags }, + { "test_long_data_str", test_long_data_str }, + { "test_long_data_str1", test_long_data_str1 }, + { "test_long_data_bin", test_long_data_bin }, + { "test_warnings", test_warnings }, + { "test_errors", test_errors }, + { "test_prepare_resultset", test_prepare_resultset }, + { "test_stmt_close", test_stmt_close }, + { "test_prepare_field_result", test_prepare_field_result }, + { "test_multi_stmt", test_multi_stmt }, + { "test_multi_statements", test_multi_statements }, + { "test_prepare_multi_statements", test_prepare_multi_statements }, + { "test_store_result", test_store_result }, + { "test_store_result1", test_store_result1 }, + { "test_store_result2", test_store_result2 }, + { "test_subselect", test_subselect }, + { "test_date", test_date }, + { "test_date_date", test_date_date }, + { "test_date_time", test_date_time }, + { "test_date_ts", test_date_ts }, + { "test_date_dt", test_date_dt }, + { "test_prepare_alter", test_prepare_alter }, + { "test_manual_sample", test_manual_sample }, + { "test_pure_coverage", test_pure_coverage }, + { "test_buffers", test_buffers }, + { "test_ushort_bug", test_ushort_bug }, + { "test_sshort_bug", test_sshort_bug }, + { "test_stiny_bug", test_stiny_bug }, + { "test_field_misc", test_field_misc }, + { "test_set_option", test_set_option }, +#ifndef EMBEDDED_LIBRARY + { "test_prepare_grant", test_prepare_grant }, +#endif + { "test_frm_bug", test_frm_bug }, + { "test_explain_bug", test_explain_bug }, + { "test_decimal_bug", test_decimal_bug }, + { "test_nstmts", test_nstmts }, + { "test_logs;", test_logs }, + { "test_cuted_rows", test_cuted_rows }, + { "test_fetch_offset", test_fetch_offset }, + { "test_fetch_column", test_fetch_column }, + { "test_mem_overun", test_mem_overun }, + { "test_list_fields", test_list_fields }, + { "test_free_result", test_free_result }, + { "test_free_store_result", test_free_store_result }, + { "test_sqlmode", test_sqlmode }, + { "test_ts", test_ts }, + { "test_bug1115", test_bug1115 }, + { "test_bug1180", test_bug1180 }, + { "test_bug1500", test_bug1500 }, + { "test_bug1644", test_bug1644 }, + { "test_bug1946", test_bug1946 }, + { "test_bug2248", test_bug2248 }, + { "test_parse_error_and_bad_length", test_parse_error_and_bad_length }, + { "test_bug2247", test_bug2247 }, + { "test_subqueries", test_subqueries }, + { "test_bad_union", test_bad_union }, + { "test_distinct", test_distinct }, + { "test_subqueries_ref", test_subqueries_ref }, + { "test_union", test_union }, + { "test_bug3117", test_bug3117 }, + { "test_join", test_join }, + { "test_selecttmp", test_selecttmp }, + { "test_create_drop", test_create_drop }, + { "test_rename", test_rename }, + { "test_do_set", test_do_set }, + { "test_multi", test_multi }, + { "test_insert_select", test_insert_select }, + { "test_bind_nagative", test_bind_nagative }, + { "test_derived", test_derived }, + { "test_xjoin", test_xjoin }, + { "test_bug3035", test_bug3035 }, + { "test_union2", test_union2 }, + { "test_bug1664", test_bug1664 }, + { "test_union_param", test_union_param }, + { "test_order_param", test_order_param }, + { "test_ps_i18n", test_ps_i18n }, + { "test_bug3796", test_bug3796 }, + { "test_bug4026", test_bug4026 }, + { "test_bug4079", test_bug4079 }, + { "test_bug4236", test_bug4236 }, + { "test_bug4030", test_bug4030 }, + { "test_bug5126", test_bug5126 }, + { "test_bug4231", test_bug4231 }, + { "test_bug5399", test_bug5399 }, + { "test_bug5194", test_bug5194 }, + { "test_bug5315", test_bug5315 }, + { "test_bug6049", test_bug6049 }, + { "test_bug6058", test_bug6058 }, + { "test_bug6059", test_bug6059 }, + { "test_bug6046", test_bug6046 }, + { "test_bug6081", test_bug6081 }, + { "test_bug6096", test_bug6096 }, + { "test_bug4172", test_bug4172 }, + { "test_conversion", test_conversion }, + { 0, 0 } +}; + + static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) @@ -11316,6 +11473,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else opt_silent++; break; + case 'T': + { + struct my_tests_st *fptr; + + printf("All possible test names:\n\n"); + for (fptr= my_tests; fptr->name; fptr++) + printf("%s\n", fptr->name); + exit(0); + break; + } case '?': case 'I': /* Info */ usage(); @@ -11362,11 +11529,14 @@ static void print_test_output() main routine ***************************************************************************/ + int main(int argc, char **argv) { + struct my_tests_st *fptr; + DEBUGGER_OFF; MY_INIT(argv[0]); - + load_defaults("my", client_test_load_default_groups, &argc, &argv); defaults_argv= argv; get_options(argc, argv); @@ -11378,180 +11548,39 @@ int main(int argc, char **argv) { /* Start of tests */ test_count= 1; - start_time= time((time_t *)0); - client_query(); /* simple client query test */ -#if NOT_YET_WORKING - /* Used for internal new development debugging */ - test_drop_temp(); /* Test DROP TEMPORARY TABLE Access checks */ -#endif - test_fetch_seek(); /* Test stmt seek() functions */ - test_fetch_nobuffs(); /* to fecth without prior bound buffers */ - test_open_direct(); /* direct execution in the middle of open stmts */ - test_fetch_null(); /* to fetch null data */ - test_ps_null_param(); /* Fetch value of null parameter */ - test_fetch_date(); /* to fetch date, time and timestamp */ - test_fetch_str(); /* to fetch string to all types */ - test_fetch_long(); /* to fetch long to all types */ - test_fetch_short(); /* to fetch short to all types */ - test_fetch_tiny(); /* to fetch tiny to all types */ - test_fetch_bigint(); /* to fetch bigint to all types */ - test_fetch_float(); /* to fetch float to all types */ - test_fetch_double(); /* to fetch double to all types */ - test_bind_result_ext(); /* result bind test - extension */ - test_bind_result_ext1(); /* result bind test - extension */ - test_select_direct(); /* direct select - protocol_simple debug */ - test_select_prepare(); /* prepare select - protocol_prep debug */ - test_select(); /* simple select test */ - test_select_version(); /* select with variables */ - test_ps_conj_select(); /* prepare select with "where a=? or b=?" */ - test_select_show_table();/* simple show prepare */ -#if NOT_USED - /* - Enable this tests from 4.1.1 when mysql_param_result() is - supported - */ - test_select_meta(); /* select param meta information */ - test_update_meta(); /* update param meta information */ - test_insert_meta(); /* insert param meta information */ -#endif - test_func_fields(); /* test for new 4.1 MYSQL_FIELD members */ - test_long_data(); /* test for sending text data in chunks */ - test_insert(); /* simple insert test - prepare */ - test_set_variable(); /* prepare with set variables */ - test_select_show(); /* prepare - show test */ - test_prepare_noparam(); /* prepare without parameters */ - test_bind_result(); /* result bind test */ - test_prepare_simple(); /* simple prepare */ - test_prepare(); /* prepare test */ - test_null(); /* test null data handling */ - test_debug_example(); /* some debugging case */ - test_update(); /* prepare-update test */ - test_simple_update(); /* simple prepare with update */ - test_simple_delete(); /* prepare with delete */ - test_double_compare(); /* float comparision */ - client_store_result(); /* usage of mysql_store_result() */ - client_use_result(); /* usage of mysql_use_result() */ - test_tran_bdb(); /* transaction test on BDB table type */ - test_tran_innodb(); /* transaction test on InnoDB table type */ - test_prepare_ext(); /* test prepare with all types - conversion -- TODO */ - test_prepare_syntax(); /* syntax check for prepares */ - test_field_names(); /* test for field names */ - test_field_flags(); /* test to help .NET provider team */ - test_long_data_str(); /* long data handling */ - test_long_data_str1(); /* yet another long data handling */ - test_long_data_bin(); /* long binary insertion */ - test_warnings(); /* show warnings test */ - test_errors(); /* show errors test */ - test_prepare_resultset();/* prepare meta info test */ - test_stmt_close(); /* mysql_stmt_close() test -- hangs */ - test_prepare_field_result(); /* prepare meta info */ - test_multi_stmt(); /* multi stmt test */ - test_multi_statements();/* test multi statement execution */ - test_prepare_multi_statements(); /* check that multi statements are - disabled in PS */ - test_store_result(); /* test the store_result */ - test_store_result1(); /* test store result without buffers */ - test_store_result2(); /* test store result for misc case */ - test_subselect(); /* test subselect prepare -TODO*/ - test_date(); /* test the MYSQL_TIME conversion */ - test_date_date(); /* test conversion from DATE to all */ - test_date_time(); /* test conversion from TIME to all */ - test_date_ts() ; /* test conversion from TIMESTAMP to all */ - test_date_dt() ; /* test conversion from DATETIME to all */ - test_prepare_alter(); /* change table schema in middle of prepare */ - test_manual_sample(); /* sample in the manual */ - test_pure_coverage(); /* keep pure coverage happy */ - test_buffers(); /* misc buffer handling */ - test_ushort_bug(); /* test a simple conv bug from php */ - test_sshort_bug(); /* test a simple conv bug from php */ - test_stiny_bug(); /* test a simple conv bug from php */ - test_field_misc(); /* check the field info for misc case, bug: #74 */ - test_set_option(); /* test the SET OPTION feature, bug #85 */ - /*TODO HF: here should be NO_EMBEDDED_ACCESS_CHECKS*/ -#ifndef EMBEDDED_LIBRARY - test_prepare_grant(); /* Test the GRANT command, bug #89 */ -#endif - test_frm_bug(); /* test the crash when .frm is invalid, bug #93 */ - test_explain_bug(); /* test for the EXPLAIN, bug #115 */ - test_decimal_bug(); /* test for the decimal bug */ - test_nstmts(); /* test n statements */ - test_logs(); ; /* Test logs */ - test_cuted_rows(); /* Test for WARNINGS from cuted rows */ - test_fetch_offset(); /* Test mysql_stmt_fetch_column with offset */ - test_fetch_column(); /* Test mysql_stmt_fetch_column */ - test_mem_overun(); /* test DBD ovverun bug */ - test_list_fields(); /* test COM_LIST_FIELDS for DEFAULT */ - test_free_result(); /* test mysql_stmt_free_result() */ - test_free_store_result(); /* test to make sure stmt results are cleared - during stmt_free_result() */ - test_sqlmode(); /* test for SQL_MODE */ - test_ts(); /* test for timestamp BR#819 */ - test_bug1115(); /* BUG#1115 */ - test_bug1180(); /* BUG#1180 */ - test_bug1500(); /* BUG#1500 */ - test_bug1644(); /* BUG#1644 */ - test_bug1946(); /* test that placeholders are allowed only in - prepared queries */ - test_bug2248(); /* BUG#2248 */ - test_parse_error_and_bad_length(); /* test if bad length param in - mysql_stmt_prepare() triggers error */ - test_bug2247(); /* test that mysql_stmt_affected_rows() returns - number of rows affected by last prepared - statement execution */ - test_subqueries(); /* repeatable subqueries */ - test_bad_union(); /* correct setup of UNION */ - test_distinct(); /* distinct aggregate functions */ - test_subqueries_ref(); /* outer reference in subqueries converted - Item_field -> Item_ref */ - test_union(); /* test union with prepared statements */ - test_bug3117(); /* BUG#3117: LAST_INSERT_ID() */ - test_join(); /* different kinds of join, BUG#2794 */ - test_selecttmp(); /* temporary table used in select execution */ - test_create_drop(); /* some table manipulation BUG#2811 */ - test_rename(); /* rename test */ - test_do_set(); /* DO & SET commands test BUG#3393 */ - test_multi(); /* test of multi delete & update */ - test_insert_select(); /* test INSERT ... SELECT */ - test_bind_nagative(); /* bind negative to unsigned BUG#3223 */ - test_derived(); /* derived table with parameter BUG#3020 */ - test_xjoin(); /* complex join test */ - test_bug3035(); /* inserts of INT32_MAX/UINT32_MAX */ - test_union2(); /* repeatable execution of union (Bug #3577) */ - test_bug1664(); /* test for bugs in mysql_stmt_send_long_data() - call (Bug #1664) */ - test_union_param(); - test_order_param(); /* ORDER BY with parameters in select list - (Bug #3686 */ - test_ps_i18n(); /* test for i18n support in binary protocol */ - test_bug3796(); /* test for select concat(?, ) */ - test_bug4026(); /* test microseconds precision of time types */ - test_bug4079(); /* erroneous subquery in prepared statement */ - test_bug4236(); /* init -> execute */ - test_bug4030(); /* test conversion string -> time types in - libmysql */ - test_bug5126(); /* support for mediumint type in libmysql */ - test_bug4231(); /* proper handling of all-zero times and - dates in the server */ - test_bug5399(); /* check that statement id uniquely identifies - statement */ - test_bug5194(); /* bulk inserts in prepared mode */ - test_bug5315(); /* check that mysql_change_user closes all - prepared statements */ - test_bug6049(); /* check support for negative TIME values */ - test_bug6058(); /* check support for 0000-00-00 dates */ - test_bug6059(); /* correct metadata for SELECT ... INTO OUTFILE */ - test_bug6046(); /* NATURAL JOIN transformation works in PS */ - test_bug6081(); /* test of mysql_create_db()/mysql_rm_db() */ - test_bug6096(); /* max_length for numeric columns */ - test_bug4172(); /* floating point conversions in libmysql */ + int i, name_ok; + if (!argv[1]) + { + for (fptr= my_tests; fptr->name; fptr++) + (*fptr->function)(); + } + else + { + for (i= 1; argv[i]; i++) + { + name_ok= 0; + for (fptr= my_tests; fptr->name; fptr++) + { + if (!strcmp(fptr->name, argv[i])) + { + name_ok= 1; + (*fptr->function)(); + } + } + if (!name_ok) + { + printf("\n\nGiven test not found: '%s'\n", argv[i]); + printf("See legal test names with %s -T\n\nAborting!\n", + my_progname); + client_disconnect(); + free_defaults(defaults_argv); + exit(1); + } + } + } - test_conversion(); /* placeholder value is not converted to - character set of column if character set - of connection equals to character set of - client */ /* XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH. From c724163e141feff488c9db52b930f5411fa09d37 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 12 Nov 2004 19:01:49 +0200 Subject: [PATCH 82/94] Fix to allow usage of 4.0 tables with 4.1 --- sql/field.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/field.cc b/sql/field.cc index f70a23e889a..bbd21247b8e 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5943,6 +5943,7 @@ Field *make_field(char *ptr, uint32 field_length, if (!f_is_packed(pack_flag)) { if (field_type == FIELD_TYPE_STRING || + field_type == FIELD_TYPE_DECIMAL || // 3.23 or 4.0 string field_type == FIELD_TYPE_VAR_STRING) return new Field_string(ptr,field_length,null_pos,null_bit, unireg_check, field_name, table, From 81d7fc68ff149c386d11e278a5492254c75b4eee Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Fri, 12 Nov 2004 19:04:35 +0200 Subject: [PATCH 83/94] Changed some unneccessary calls to current_thd() into table->in_use --- sql/ha_heap.cc | 33 ++++++++++++++++++++------------- sql/ha_isam.cc | 27 +++++++++++++++------------ sql/ha_isammrg.cc | 9 +++++---- sql/ha_myisam.cc | 38 +++++++++++++++++++++++--------------- sql/ha_myisammrg.cc | 34 +++++++++++++++++++++------------- 5 files changed, 84 insertions(+), 57 deletions(-) diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 3bb8383e488..1c8967c1a34 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -86,7 +86,7 @@ void ha_heap::set_keys_for_scanning(void) int ha_heap::write_row(byte * buf) { - statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) table->timestamp_field->set_time(); if (table->next_number_field && buf == table->record[0]) @@ -96,7 +96,7 @@ int ha_heap::write_row(byte * buf) int ha_heap::update_row(const byte * old_data, byte * new_data) { - statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); return heap_update(file,old_data,new_data); @@ -104,7 +104,7 @@ int ha_heap::update_row(const byte * old_data, byte * new_data) int ha_heap::delete_row(const byte * buf) { - statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status); return heap_delete(file,buf); } @@ -112,7 +112,8 @@ int ha_heap::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error = heap_rkey(file,buf,active_index, key, key_len, find_flag); table->status = error ? STATUS_NOT_FOUND : 0; return error; @@ -121,7 +122,8 @@ int ha_heap::index_read(byte * buf, const byte * key, uint key_len, int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error= heap_rkey(file, buf, active_index, key, key_len, HA_READ_PREFIX_LAST); table->status= error ? STATUS_NOT_FOUND : 0; @@ -131,7 +133,8 @@ int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len) int ha_heap::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error = heap_rkey(file, buf, index, key, key_len, find_flag); table->status = error ? STATUS_NOT_FOUND : 0; return error; @@ -140,7 +143,8 @@ int ha_heap::index_read_idx(byte * buf, uint index, const byte * key, int ha_heap::index_next(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_next_count, + &LOCK_status); int error=heap_rnext(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -149,7 +153,8 @@ int ha_heap::index_next(byte * buf) int ha_heap::index_prev(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_prev_count, + &LOCK_status); int error=heap_rprev(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -158,7 +163,7 @@ int ha_heap::index_prev(byte * buf) int ha_heap::index_first(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_first_count, + statistic_increment(table->in_use->status_var.ha_read_first_count, &LOCK_status); int error=heap_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -168,7 +173,8 @@ int ha_heap::index_first(byte * buf) int ha_heap::index_last(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_last_count, + &LOCK_status); int error=heap_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -181,7 +187,7 @@ int ha_heap::rnd_init(bool scan) int ha_heap::rnd_next(byte *buf) { - statistic_increment(current_thd->status_var.ha_read_rnd_next_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_next_count, &LOCK_status); int error=heap_scan(file, buf); table->status=error ? STATUS_NOT_FOUND: 0; @@ -192,7 +198,8 @@ int ha_heap::rnd_pos(byte * buf, byte *pos) { int error; HEAP_PTR position; - statistic_increment(current_thd->status_var.ha_read_rnd_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_rnd_count, + &LOCK_status); memcpy_fixed((char*) &position,pos,sizeof(HEAP_PTR)); error=heap_rrnd(file, buf, position); table->status=error ? STATUS_NOT_FOUND: 0; @@ -456,7 +463,7 @@ int ha_heap::create(const char *name, TABLE *table_arg, } } mem_per_row+= MY_ALIGN(table_arg->reclength + 1, sizeof(char*)); - max_rows = (ha_rows) (current_thd->variables.max_heap_table_size / + max_rows = (ha_rows) (table->in_use->variables.max_heap_table_size / mem_per_row); HP_CREATE_INFO hp_create_info; hp_create_info.auto_key= auto_key; diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc index d703df7d2e3..7b4e88c8601 100644 --- a/sql/ha_isam.cc +++ b/sql/ha_isam.cc @@ -69,7 +69,7 @@ uint ha_isam::min_record_length(uint options) const int ha_isam::write_row(byte * buf) { - statistic_increment(current_thd->status_var.ha_write_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) table->timestamp_field->set_time(); if (table->next_number_field && buf == table->record[0]) @@ -79,7 +79,7 @@ int ha_isam::write_row(byte * buf) int ha_isam::update_row(const byte * old_data, byte * new_data) { - statistic_increment(current_thd->status_var.ha_update_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_update_count, &LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); return !nisam_update(file,old_data,new_data) ? 0 : my_errno ? my_errno : -1; @@ -87,14 +87,15 @@ int ha_isam::update_row(const byte * old_data, byte * new_data) int ha_isam::delete_row(const byte * buf) { - statistic_increment(current_thd->status_var.ha_delete_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_delete_count, &LOCK_status); return !nisam_delete(file,buf) ? 0 : my_errno ? my_errno : -1; } int ha_isam::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=nisam_rkey(file, buf, active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return !error ? 0 : my_errno ? my_errno : -1; @@ -103,7 +104,8 @@ int ha_isam::index_read(byte * buf, const byte * key, int ha_isam::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=nisam_rkey(file, buf, index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return !error ? 0 : my_errno ? my_errno : -1; @@ -111,7 +113,8 @@ int ha_isam::index_read_idx(byte * buf, uint index, const byte * key, int ha_isam::index_read_last(byte * buf, const byte * key, uint key_len) { - statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=nisam_rkey(file, buf, active_index, key, key_len, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; @@ -120,7 +123,7 @@ int ha_isam::index_read_last(byte * buf, const byte * key, uint key_len) int ha_isam::index_next(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_next_count, + statistic_increment(table->in_use->status_var.ha_read_next_count, &LOCK_status); int error=nisam_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -129,7 +132,7 @@ int ha_isam::index_next(byte * buf) int ha_isam::index_prev(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_prev_count, + statistic_increment(table->in_use->status_var.ha_read_prev_count, &LOCK_status); int error=nisam_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -138,7 +141,7 @@ int ha_isam::index_prev(byte * buf) int ha_isam::index_first(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_first_count, + statistic_increment(table->in_use->status_var.ha_read_first_count, &LOCK_status); int error=nisam_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -147,7 +150,7 @@ int ha_isam::index_first(byte * buf) int ha_isam::index_last(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_last_count, + statistic_increment(table->in_use->status_var.ha_read_last_count, &LOCK_status); int error=nisam_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -161,7 +164,7 @@ int ha_isam::rnd_init(bool scan) int ha_isam::rnd_next(byte *buf) { - statistic_increment(current_thd->status_var.ha_read_rnd_next_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_next_count, &LOCK_status); int error=nisam_rrnd(file, buf, NI_POS_ERROR); table->status=error ? STATUS_NOT_FOUND: 0; @@ -170,7 +173,7 @@ int ha_isam::rnd_next(byte *buf) int ha_isam::rnd_pos(byte * buf, byte *pos) { - statistic_increment(current_thd->status_var.ha_read_rnd_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_count, &LOCK_status); int error=nisam_rrnd(file, buf, (ulong) ha_get_ptr(pos,ref_length)); table->status=error ? STATUS_NOT_FOUND: 0; diff --git a/sql/ha_isammrg.cc b/sql/ha_isammrg.cc index 5a070087724..f9ed3af8f61 100644 --- a/sql/ha_isammrg.cc +++ b/sql/ha_isammrg.cc @@ -77,7 +77,7 @@ int ha_isammrg::write_row(byte * buf) int ha_isammrg::update_row(const byte * old_data, byte * new_data) { - statistic_increment(current_thd->status_var.ha_update_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_update_count, &LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); return !mrg_update(file,old_data,new_data) ? 0 : my_errno ? my_errno : -1; @@ -85,7 +85,7 @@ int ha_isammrg::update_row(const byte * old_data, byte * new_data) int ha_isammrg::delete_row(const byte * buf) { - statistic_increment(current_thd->status_var.ha_delete_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_delete_count, &LOCK_status); return !mrg_delete(file,buf) ? 0 : my_errno ? my_errno : -1; } @@ -128,7 +128,7 @@ int ha_isammrg::rnd_init(bool scan) int ha_isammrg::rnd_next(byte *buf) { - statistic_increment(current_thd->status_var.ha_read_rnd_next_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_next_count, &LOCK_status); int error=mrg_rrnd(file, buf, ~(mrg_off_t) 0); table->status=error ? STATUS_NOT_FOUND: 0; @@ -137,7 +137,8 @@ int ha_isammrg::rnd_next(byte *buf) int ha_isammrg::rnd_pos(byte * buf, byte *pos) { - statistic_increment(current_thd->status_var.ha_read_rnd_count, &LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_rnd_count, + &LOCK_status); int error=mrg_rrnd(file, buf, (ulong) ha_get_ptr(pos,ref_length)); table->status=error ? STATUS_NOT_FOUND: 0; return !error ? 0 : my_errno ? my_errno : -1; diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 7482c6d5fa8..58f10f67341 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -249,7 +249,7 @@ int ha_myisam::close(void) int ha_myisam::write_row(byte * buf) { - statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status); /* If we have a timestamp column, update it to the current time */ if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) @@ -602,7 +602,7 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) local_testflag|= T_STATISTICS; param.testflag|= T_STATISTICS; // We get this for free statistics_done=1; - if (current_thd->variables.myisam_repair_threads>1) + if (thd->variables.myisam_repair_threads>1) { char buf[40]; /* TODO: respect myisam_repair_threads variable */ @@ -1084,7 +1084,7 @@ bool ha_myisam::is_crashed() const int ha_myisam::update_row(const byte * old_data, byte * new_data) { - statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); return mi_update(file,old_data,new_data); @@ -1092,7 +1092,7 @@ int ha_myisam::update_row(const byte * old_data, byte * new_data) int ha_myisam::delete_row(const byte * buf) { - statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status); return mi_delete(file,buf); } @@ -1100,7 +1100,8 @@ int ha_myisam::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=mi_rkey(file,buf,active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1109,7 +1110,8 @@ int ha_myisam::index_read(byte * buf, const byte * key, int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=mi_rkey(file,buf,index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1118,7 +1120,8 @@ int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key, int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1127,7 +1130,8 @@ int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len) int ha_myisam::index_next(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_next_count, + &LOCK_status); int error=mi_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1136,7 +1140,8 @@ int ha_myisam::index_next(byte * buf) int ha_myisam::index_prev(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_prev_count, + &LOCK_status); int error=mi_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1145,7 +1150,7 @@ int ha_myisam::index_prev(byte * buf) int ha_myisam::index_first(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_first_count, + statistic_increment(table->in_use->status_var.ha_read_first_count, &LOCK_status); int error=mi_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1155,7 +1160,8 @@ int ha_myisam::index_first(byte * buf) int ha_myisam::index_last(byte * buf) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_last_count, + &LOCK_status); int error=mi_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1166,7 +1172,8 @@ int ha_myisam::index_next_same(byte * buf, uint length __attribute__((unused))) { DBUG_ASSERT(inited==INDEX); - statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_next_count, + &LOCK_status); int error=mi_rnext_same(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1182,7 +1189,7 @@ int ha_myisam::rnd_init(bool scan) int ha_myisam::rnd_next(byte *buf) { - statistic_increment(current_thd->status_var.ha_read_rnd_next_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_next_count, &LOCK_status); int error=mi_scan(file, buf); table->status=error ? STATUS_NOT_FOUND: 0; @@ -1196,7 +1203,8 @@ int ha_myisam::restart_rnd_next(byte *buf, byte *pos) int ha_myisam::rnd_pos(byte * buf, byte *pos) { - statistic_increment(current_thd->status_var.ha_read_rnd_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_rnd_count, + &LOCK_status); int error=mi_rrnd(file, buf, ha_get_ptr(pos,ref_length)); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -1606,7 +1614,7 @@ int ha_myisam::ft_read(byte * buf) if (!ft_handler) return -1; - thread_safe_increment(current_thd->status_var.ha_read_next_count, + thread_safe_increment(table->in_use->status_var.ha_read_next_count, &LOCK_status); // why ? error=ft_handler->please->read_next(ft_handler,(char*) buf); diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 903dd9dec2f..8cff61859b1 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -81,7 +81,7 @@ int ha_myisammrg::close(void) int ha_myisammrg::write_row(byte * buf) { - statistic_increment(current_thd->status_var.ha_write_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) table->timestamp_field->set_time(); if (table->next_number_field && buf == table->record[0]) @@ -91,7 +91,7 @@ int ha_myisammrg::write_row(byte * buf) int ha_myisammrg::update_row(const byte * old_data, byte * new_data) { - statistic_increment(current_thd->status_var.ha_update_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status); if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); return myrg_update(file,old_data,new_data); @@ -99,14 +99,15 @@ int ha_myisammrg::update_row(const byte * old_data, byte * new_data) int ha_myisammrg::delete_row(const byte * buf) { - statistic_increment(current_thd->status_var.ha_delete_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status); return myrg_delete(file,buf); } int ha_myisammrg::index_read(byte * buf, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -115,7 +116,8 @@ int ha_myisammrg::index_read(byte * buf, const byte * key, int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, uint key_len, enum ha_rkey_function find_flag) { - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=myrg_rkey(file,buf,index, key, key_len, find_flag); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -123,7 +125,8 @@ int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key, int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len) { - statistic_increment(current_thd->status_var.ha_read_key_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_key_count, + &LOCK_status); int error=myrg_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST); table->status=error ? STATUS_NOT_FOUND: 0; @@ -132,7 +135,8 @@ int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len) int ha_myisammrg::index_next(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_next_count, + &LOCK_status); int error=myrg_rnext(file,buf,active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -140,7 +144,8 @@ int ha_myisammrg::index_next(byte * buf) int ha_myisammrg::index_prev(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_prev_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_prev_count, + &LOCK_status); int error=myrg_rprev(file,buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -148,7 +153,7 @@ int ha_myisammrg::index_prev(byte * buf) int ha_myisammrg::index_first(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_first_count, + statistic_increment(table->in_use->status_var.ha_read_first_count, &LOCK_status); int error=myrg_rfirst(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; @@ -157,7 +162,8 @@ int ha_myisammrg::index_first(byte * buf) int ha_myisammrg::index_last(byte * buf) { - statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_last_count, + &LOCK_status); int error=myrg_rlast(file, buf, active_index); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -167,7 +173,8 @@ int ha_myisammrg::index_next_same(byte * buf, const byte *key __attribute__((unused)), uint length __attribute__((unused))) { - statistic_increment(current_thd->status_var.ha_read_next_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_next_count, + &LOCK_status); int error=myrg_rnext_same(file,buf); table->status=error ? STATUS_NOT_FOUND: 0; return error; @@ -180,7 +187,7 @@ int ha_myisammrg::rnd_init(bool scan) int ha_myisammrg::rnd_next(byte *buf) { - statistic_increment(current_thd->status_var.ha_read_rnd_next_count, + statistic_increment(table->in_use->status_var.ha_read_rnd_next_count, &LOCK_status); int error=myrg_rrnd(file, buf, HA_OFFSET_ERROR); table->status=error ? STATUS_NOT_FOUND: 0; @@ -189,7 +196,8 @@ int ha_myisammrg::rnd_next(byte *buf) int ha_myisammrg::rnd_pos(byte * buf, byte *pos) { - statistic_increment(current_thd->status_var.ha_read_rnd_count,&LOCK_status); + statistic_increment(table->in_use->status_var.ha_read_rnd_count, + &LOCK_status); int error=myrg_rrnd(file, buf, ha_get_ptr(pos,ref_length)); table->status=error ? STATUS_NOT_FOUND: 0; return error; From 76b8c8747dd175ccd4706ccc209ebdb478c1c1d5 Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Fri, 12 Nov 2004 19:22:58 +0200 Subject: [PATCH 84/94] Removed an unneccessary for() and variable. --- mysys/default.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mysys/default.c b/mysys/default.c index 16e166a3ca5..364b2037f67 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -120,7 +120,7 @@ int load_defaults(const char *conf_file, const char **groups, uint args_used=0; int error= 0; MEM_ROOT alloc; - char *ptr, **res, **ext; + char *ptr, **res; DBUG_ENTER("load_defaults"); @@ -176,10 +176,9 @@ int load_defaults(const char *conf_file, const char **groups, } else if (dirname_length(conf_file)) { - for (ext= (char**) f_extensions; *ext; *ext++) - if ((error= search_default_file(&args, &alloc, NullS, conf_file, - &group)) < 0) - goto err; + if ((error= search_default_file(&args, &alloc, NullS, conf_file, + &group)) < 0) + goto err; } else { From dc6452a4d4d96aca832ace93cb8a2115052b6786 Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Fri, 12 Nov 2004 19:54:25 +0200 Subject: [PATCH 85/94] Code cleanup and some optimizations. --- tests/client_test.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/client_test.c b/tests/client_test.c index 89034012d5b..2f28da6d00d 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -11494,11 +11494,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), return 0; } -static void get_options(int argc, char **argv) +static void get_options(int *argc, char ***argv) { int ho_error; - if ((ho_error= handle_options(&argc, &argv, client_test_long_options, + if ((ho_error= handle_options(argc, argv, client_test_long_options, get_one_option))) exit(ho_error); @@ -11541,7 +11541,7 @@ int main(int argc, char **argv) load_defaults("my", client_test_load_default_groups, &argc, &argv); defaults_argv= argv; - get_options(argc, argv); + get_options(&argc, &argv); client_connect(); /* connect to server */ @@ -11552,30 +11552,28 @@ int main(int argc, char **argv) test_count= 1; start_time= time((time_t *)0); - int i, name_ok; - if (!argv[1]) + if (!argc) { for (fptr= my_tests; fptr->name; fptr++) (*fptr->function)(); } else { - for (i= 1; argv[i]; i++) + for ( ; *argv ; argv++) { - name_ok= 0; for (fptr= my_tests; fptr->name; fptr++) { - if (!strcmp(fptr->name, argv[i])) + if (!strcmp(fptr->name, *argv)) { - name_ok= 1; (*fptr->function)(); + break; } } - if (!name_ok) + if (!fptr->name) { - printf("\n\nGiven test not found: '%s'\n", argv[i]); - printf("See legal test names with %s -T\n\nAborting!\n", - my_progname); + fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); + fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", + my_progname); client_disconnect(); free_defaults(defaults_argv); exit(1); From dc667223508fdfb970219c7d931e4f6c35392550 Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Fri, 12 Nov 2004 20:47:41 +0200 Subject: [PATCH 86/94] Fixed a function call. --- sql/item_strfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 3f659964a6c..5a23eec5a1b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2593,7 +2593,7 @@ String *Item_func_quote::val_str(String *str) uint arg_length, new_length; if (!arg) // Null argument { - str->copy("NULL", 4); // Return the string 'NULL' + str->copy("NULL", 4, collation.collation); // Return the string 'NULL' null_value= 0; return str; } From e0f1e6af365a8983da84c64484199a1226f95508 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 12 Nov 2004 21:24:16 +0200 Subject: [PATCH 87/94] Portability fix for gcc 2.95.3 After merge fixes --- mysql-test/r/mix_innodb_myisam_binlog.result | 10 ++++++---- mysys/default.c | 3 ++- sql/mysql_priv.h | 6 +++--- sql/sql_base.cc | 6 +++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/mix_innodb_myisam_binlog.result b/mysql-test/r/mix_innodb_myisam_binlog.result index 9d6e9bd767a..abcb451df65 100644 --- a/mysql-test/r/mix_innodb_myisam_binlog.result +++ b/mysql-test/r/mix_innodb_myisam_binlog.result @@ -174,10 +174,12 @@ select a from t1 order by a; a 16 18 -master-bin.000001 79 Query 1 79 use `test`; BEGIN -master-bin.000001 119 Query 1 79 use `test`; insert into t1 values(16) -master-bin.000001 179 Query 1 79 use `test`; insert into t1 values(18) -master-bin.000001 239 Query 1 239 use `test`; COMMIT +show binlog events from 95; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 95 Query 1 # use `test`; BEGIN +master-bin.000001 157 Query 1 # use `test`; insert into t1 values(16) +master-bin.000001 239 Query 1 # use `test`; insert into t1 values(18) +master-bin.000001 321 Query 1 # use `test`; COMMIT delete from t1; delete from t2; alter table t2 type=MyISAM; diff --git a/mysys/default.c b/mysys/default.c index 02d4ec250f9..d6d84f65d8b 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -85,7 +85,8 @@ struct handle_option_ctx static int search_default_file(Process_option_func func, void *func_ctx, const char *dir, const char *config_file); -static int search_default_file_with_ext(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, +static int search_default_file_with_ext(Process_option_func func, + void *func_ctx, const char *dir, const char *ext, const char *config_file); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 7d1ffe97e08..62e4f849c67 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -649,8 +649,8 @@ bool drop_locked_tables(THD *thd,const char *db, const char *table_name); void abort_locked_tables(THD *thd,const char *db, const char *table_name); void execute_init_command(THD *thd, sys_var_str *init_command_var, rw_lock_t *var_mutex); -extern const Field *not_found_field; -extern const Field *view_ref_found; +extern Field *not_found_field; +extern Field *view_ref_found; enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND, IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE, @@ -776,7 +776,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find); SQL_SELECT *make_select(TABLE *head, table_map const_tables, table_map read_tables, COND *conds, int *error, bool allow_null_cond= false); -extern const Item **not_found_item; +extern Item **not_found_item; Item ** find_item_in_list(Item *item, List &items, uint *counter, find_item_error_report_type report_error, bool *unaliased); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index eeb34f6b600..e690673c934 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2045,8 +2045,8 @@ bool rm_temporary_table(enum db_type base, char *path) ******************************************************************************/ /* Special Field pointers for find_field_in_tables returning */ -const Field *not_found_field= (Field*) 0x1; -const Field *view_ref_found= (Field*) 0x2; +Field *not_found_field= (Field*) 0x1; +Field *view_ref_found= (Field*) 0x2; #define WRONG_GRANT (Field*) -1 @@ -2447,7 +2447,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, */ /* Special Item pointer to serve as a return value from find_item_in_list(). */ -const Item **not_found_item= (const Item**) 0x1; +Item **not_found_item= (Item**) 0x1; Item ** From 6cf9ea2c9a4fe58829b443a5fdfd710b52c9c306 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Fri, 12 Nov 2004 21:42:44 +0200 Subject: [PATCH 88/94] Add back data that bk loosed during automatic merge --- mysql-test/r/func_str.result | 279 +++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 763f7f1b8bf..98d9c332ab3 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -406,3 +406,282 @@ abcdabc select SUBSTRING_INDEX(_latin1'abcdabcdabcd',_latin2'd',2); ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin2_general_ci,COERCIBLE) for operation 'substring_index' select SUBSTRING_INDEX(_latin1'abcdabcdabcd' COLLATE latin1_general_ci,_latin1'd' COLLATE latin1_bin,2); +ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT) and (latin1_bin,EXPLICIT) for operation 'substring_index' +select _latin1'B' between _latin1'a' and _latin1'c'; +_latin1'B' between _latin1'a' and _latin1'c' +1 +select _latin1'B' collate latin1_bin between _latin1'a' and _latin1'c'; +_latin1'B' collate latin1_bin between _latin1'a' and _latin1'c' +0 +select _latin1'B' between _latin1'a' collate latin1_bin and _latin1'c'; +_latin1'B' between _latin1'a' collate latin1_bin and _latin1'c' +0 +select _latin1'B' between _latin1'a' and _latin1'c' collate latin1_bin; +_latin1'B' between _latin1'a' and _latin1'c' collate latin1_bin +0 +select _latin2'B' between _latin1'a' and _latin1'b'; +ERROR HY000: Illegal mix of collations (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation 'between' +select _latin1'B' between _latin2'a' and _latin1'b'; +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation 'between' +select _latin1'B' between _latin1'a' and _latin2'b'; +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE) for operation 'between' +select _latin1'B' collate latin1_general_ci between _latin1'a' collate latin1_bin and _latin1'b'; +ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_bin,EXPLICIT), (latin1_swedish_ci,COERCIBLE) for operation 'between' +select _latin1'B' in (_latin1'a',_latin1'b'); +_latin1'B' in (_latin1'a',_latin1'b') +1 +select _latin1'B' collate latin1_bin in (_latin1'a',_latin1'b'); +_latin1'B' collate latin1_bin in (_latin1'a',_latin1'b') +0 +select _latin1'B' in (_latin1'a' collate latin1_bin,_latin1'b'); +_latin1'B' in (_latin1'a' collate latin1_bin,_latin1'b') +0 +select _latin1'B' in (_latin1'a',_latin1'b' collate latin1_bin); +_latin1'B' in (_latin1'a',_latin1'b' collate latin1_bin) +0 +select _latin2'B' in (_latin1'a',_latin1'b'); +ERROR HY000: Illegal mix of collations (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation ' IN ' +select _latin1'B' in (_latin2'a',_latin1'b'); +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE) for operation ' IN ' +select _latin1'B' in (_latin1'a',_latin2'b'); +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE), (latin1_swedish_ci,COERCIBLE), (latin2_general_ci,COERCIBLE) for operation ' IN ' +select _latin1'B' COLLATE latin1_general_ci in (_latin1'a' COLLATE latin1_bin,_latin1'b'); +ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_bin,EXPLICIT), (latin1_swedish_ci,COERCIBLE) for operation ' IN ' +select _latin1'B' COLLATE latin1_general_ci in (_latin1'a',_latin1'b' COLLATE latin1_bin); +ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT), (latin1_swedish_ci,COERCIBLE), (latin1_bin,EXPLICIT) for operation ' IN ' +select collation(bin(130)), coercibility(bin(130)); +collation(bin(130)) coercibility(bin(130)) +latin1_swedish_ci 3 +select collation(oct(130)), coercibility(oct(130)); +collation(oct(130)) coercibility(oct(130)) +latin1_swedish_ci 3 +select collation(conv(130,16,10)), coercibility(conv(130,16,10)); +collation(conv(130,16,10)) coercibility(conv(130,16,10)) +latin1_swedish_ci 3 +select collation(hex(130)), coercibility(hex(130)); +collation(hex(130)) coercibility(hex(130)) +latin1_swedish_ci 3 +select collation(char(130)), coercibility(hex(130)); +collation(char(130)) coercibility(hex(130)) +binary 3 +select collation(format(130,10)), coercibility(format(130,10)); +collation(format(130,10)) coercibility(format(130,10)) +latin1_swedish_ci 3 +select collation(lcase(_latin2'a')), coercibility(lcase(_latin2'a')); +collation(lcase(_latin2'a')) coercibility(lcase(_latin2'a')) +latin2_general_ci 3 +select collation(ucase(_latin2'a')), coercibility(ucase(_latin2'a')); +collation(ucase(_latin2'a')) coercibility(ucase(_latin2'a')) +latin2_general_ci 3 +select collation(left(_latin2'a',1)), coercibility(left(_latin2'a',1)); +collation(left(_latin2'a',1)) coercibility(left(_latin2'a',1)) +latin2_general_ci 3 +select collation(right(_latin2'a',1)), coercibility(right(_latin2'a',1)); +collation(right(_latin2'a',1)) coercibility(right(_latin2'a',1)) +latin2_general_ci 3 +select collation(substring(_latin2'a',1,1)), coercibility(substring(_latin2'a',1,1)); +collation(substring(_latin2'a',1,1)) coercibility(substring(_latin2'a',1,1)) +latin2_general_ci 3 +select collation(concat(_latin2'a',_latin2'b')), coercibility(concat(_latin2'a',_latin2'b')); +collation(concat(_latin2'a',_latin2'b')) coercibility(concat(_latin2'a',_latin2'b')) +latin2_general_ci 3 +select collation(lpad(_latin2'a',4,_latin2'b')), coercibility(lpad(_latin2'a',4,_latin2'b')); +collation(lpad(_latin2'a',4,_latin2'b')) coercibility(lpad(_latin2'a',4,_latin2'b')) +latin2_general_ci 3 +select collation(rpad(_latin2'a',4,_latin2'b')), coercibility(rpad(_latin2'a',4,_latin2'b')); +collation(rpad(_latin2'a',4,_latin2'b')) coercibility(rpad(_latin2'a',4,_latin2'b')) +latin2_general_ci 3 +select collation(concat_ws(_latin2'a',_latin2'b')), coercibility(concat_ws(_latin2'a',_latin2'b')); +collation(concat_ws(_latin2'a',_latin2'b')) coercibility(concat_ws(_latin2'a',_latin2'b')) +latin2_general_ci 3 +select collation(make_set(255,_latin2'a',_latin2'b',_latin2'c')), coercibility(make_set(255,_latin2'a',_latin2'b',_latin2'c')); +collation(make_set(255,_latin2'a',_latin2'b',_latin2'c')) coercibility(make_set(255,_latin2'a',_latin2'b',_latin2'c')) +latin2_general_ci 3 +select collation(export_set(255,_latin2'y',_latin2'n',_latin2' ')), coercibility(export_set(255,_latin2'y',_latin2'n',_latin2' ')); +collation(export_set(255,_latin2'y',_latin2'n',_latin2' ')) coercibility(export_set(255,_latin2'y',_latin2'n',_latin2' ')) +binary 3 +select collation(trim(_latin2' a ')), coercibility(trim(_latin2' a ')); +collation(trim(_latin2' a ')) coercibility(trim(_latin2' a ')) +latin2_general_ci 3 +select collation(ltrim(_latin2' a ')), coercibility(ltrim(_latin2' a ')); +collation(ltrim(_latin2' a ')) coercibility(ltrim(_latin2' a ')) +latin2_general_ci 3 +select collation(rtrim(_latin2' a ')), coercibility(rtrim(_latin2' a ')); +collation(rtrim(_latin2' a ')) coercibility(rtrim(_latin2' a ')) +latin2_general_ci 3 +select collation(trim(LEADING _latin2' ' FROM _latin2'a')), coercibility(trim(LEADING _latin2'a' FROM _latin2'a')); +collation(trim(LEADING _latin2' ' FROM _latin2'a')) coercibility(trim(LEADING _latin2'a' FROM _latin2'a')) +latin2_general_ci 3 +select collation(trim(TRAILING _latin2' ' FROM _latin2'a')), coercibility(trim(TRAILING _latin2'a' FROM _latin2'a')); +collation(trim(TRAILING _latin2' ' FROM _latin2'a')) coercibility(trim(TRAILING _latin2'a' FROM _latin2'a')) +latin2_general_ci 3 +select collation(trim(BOTH _latin2' ' FROM _latin2'a')), coercibility(trim(BOTH _latin2'a' FROM _latin2'a')); +collation(trim(BOTH _latin2' ' FROM _latin2'a')) coercibility(trim(BOTH _latin2'a' FROM _latin2'a')) +latin2_general_ci 3 +select collation(repeat(_latin2'a',10)), coercibility(repeat(_latin2'a',10)); +collation(repeat(_latin2'a',10)) coercibility(repeat(_latin2'a',10)) +latin2_general_ci 3 +select collation(reverse(_latin2'ab')), coercibility(reverse(_latin2'ab')); +collation(reverse(_latin2'ab')) coercibility(reverse(_latin2'ab')) +latin2_general_ci 3 +select collation(quote(_latin2'ab')), coercibility(quote(_latin2'ab')); +collation(quote(_latin2'ab')) coercibility(quote(_latin2'ab')) +latin2_general_ci 3 +select collation(soundex(_latin2'ab')), coercibility(soundex(_latin2'ab')); +collation(soundex(_latin2'ab')) coercibility(soundex(_latin2'ab')) +latin2_general_ci 3 +select collation(substring(_latin2'ab',1)), coercibility(substring(_latin2'ab',1)); +collation(substring(_latin2'ab',1)) coercibility(substring(_latin2'ab',1)) +latin2_general_ci 3 +select collation(insert(_latin2'abcd',2,3,_latin2'ef')), coercibility(insert(_latin2'abcd',2,3,_latin2'ef')); +collation(insert(_latin2'abcd',2,3,_latin2'ef')) coercibility(insert(_latin2'abcd',2,3,_latin2'ef')) +latin2_general_ci 3 +select collation(replace(_latin2'abcd',_latin2'b',_latin2'B')), coercibility(replace(_latin2'abcd',_latin2'b',_latin2'B')); +collation(replace(_latin2'abcd',_latin2'b',_latin2'B')) coercibility(replace(_latin2'abcd',_latin2'b',_latin2'B')) +latin2_general_ci 3 +select collation(encode('abcd','ab')), coercibility(encode('abcd','ab')); +collation(encode('abcd','ab')) coercibility(encode('abcd','ab')) +binary 3 +create table t1 +select +bin(130), +oct(130), +conv(130,16,10), +hex(130), +char(130), +format(130,10), +left(_latin2'a',1), +right(_latin2'a',1), +lcase(_latin2'a'), +ucase(_latin2'a'), +substring(_latin2'a',1,1), +concat(_latin2'a',_latin2'b'), +lpad(_latin2'a',4,_latin2'b'), +rpad(_latin2'a',4,_latin2'b'), +concat_ws(_latin2'a',_latin2'b'), +make_set(255,_latin2'a',_latin2'b',_latin2'c'), +export_set(255,_latin2'y',_latin2'n',_latin2' '), +trim(_latin2' a '), +ltrim(_latin2' a '), +rtrim(_latin2' a '), +trim(LEADING _latin2' ' FROM _latin2' a '), +trim(TRAILING _latin2' ' FROM _latin2' a '), +trim(BOTH _latin2' ' FROM _latin2' a '), +repeat(_latin2'a',10), +reverse(_latin2'ab'), +quote(_latin2'ab'), +soundex(_latin2'ab'), +substring(_latin2'ab',1), +insert(_latin2'abcd',2,3,_latin2'ef'), +replace(_latin2'abcd',_latin2'b',_latin2'B'), +encode('abcd','ab') +; +Warnings: +Warning 1265 Data truncated for column 'format(130,10)' at row 1 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `bin(130)` char(64) NOT NULL default '', + `oct(130)` char(64) NOT NULL default '', + `conv(130,16,10)` char(64) NOT NULL default '', + `hex(130)` char(6) NOT NULL default '', + `char(130)` char(1) NOT NULL default '', + `format(130,10)` char(4) NOT NULL default '', + `left(_latin2'a',1)` char(1) character set latin2 NOT NULL default '', + `right(_latin2'a',1)` char(1) character set latin2 NOT NULL default '', + `lcase(_latin2'a')` char(1) character set latin2 NOT NULL default '', + `ucase(_latin2'a')` char(1) character set latin2 NOT NULL default '', + `substring(_latin2'a',1,1)` char(1) character set latin2 NOT NULL default '', + `concat(_latin2'a',_latin2'b')` char(2) character set latin2 NOT NULL default '', + `lpad(_latin2'a',4,_latin2'b')` char(4) character set latin2 NOT NULL default '', + `rpad(_latin2'a',4,_latin2'b')` char(4) character set latin2 NOT NULL default '', + `concat_ws(_latin2'a',_latin2'b')` char(1) character set latin2 NOT NULL default '', + `make_set(255,_latin2'a',_latin2'b',_latin2'c')` char(5) character set latin2 NOT NULL default '', + `export_set(255,_latin2'y',_latin2'n',_latin2' ')` char(127) character set latin2 NOT NULL default '', + `trim(_latin2' a ')` char(3) character set latin2 NOT NULL default '', + `ltrim(_latin2' a ')` char(3) character set latin2 NOT NULL default '', + `rtrim(_latin2' a ')` char(3) character set latin2 NOT NULL default '', + `trim(LEADING _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '', + `trim(TRAILING _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '', + `trim(BOTH _latin2' ' FROM _latin2' a ')` char(3) character set latin2 NOT NULL default '', + `repeat(_latin2'a',10)` char(10) character set latin2 NOT NULL default '', + `reverse(_latin2'ab')` char(2) character set latin2 NOT NULL default '', + `quote(_latin2'ab')` char(6) character set latin2 NOT NULL default '', + `soundex(_latin2'ab')` char(4) character set latin2 NOT NULL default '', + `substring(_latin2'ab',1)` char(2) character set latin2 NOT NULL default '', + `insert(_latin2'abcd',2,3,_latin2'ef')` char(6) character set latin2 NOT NULL default '', + `replace(_latin2'abcd',_latin2'b',_latin2'B')` char(4) character set latin2 NOT NULL default '', + `encode('abcd','ab')` binary(4) NOT NULL default '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +select SUBSTR('abcdefg',3,2); +SUBSTR('abcdefg',3,2) +cd +select SUBSTRING('abcdefg',3,2); +SUBSTRING('abcdefg',3,2) +cd +select SUBSTR('abcdefg',-3,2) FROM DUAL; +SUBSTR('abcdefg',-3,2) +ef +select SUBSTR('abcdefg',-1,5) FROM DUAL; +SUBSTR('abcdefg',-1,5) +g +select SUBSTR('abcdefg',0,0) FROM DUAL; +SUBSTR('abcdefg',0,0) + +select SUBSTR('abcdefg',-1,-1) FROM DUAL; +SUBSTR('abcdefg',-1,-1) + +select SUBSTR('abcdefg',1,-1) FROM DUAL; +SUBSTR('abcdefg',1,-1) + +create table t7 (s1 char); +select * from t7 +where concat(s1 collate latin1_general_ci,s1 collate latin1_swedish_ci) = 'AA'; +ERROR HY000: Illegal mix of collations (latin1_general_ci,EXPLICIT) and (latin1_swedish_ci,EXPLICIT) for operation 'concat' +drop table t7; +select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2); +substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2) substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2) +1abcd;2abcd 3abcd;4abcd +explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"),replace('aaaa','a','b'),insert('txs',2,1,'hi'),left(_latin2'a',1),right(_latin2'a',1),lcase(_latin2'a'),ucase(_latin2'a'),SUBSTR('abcdefg',3,2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),trim(_latin2' a '),ltrim(_latin2' a '),rtrim(_latin2' a '), decode(encode(repeat("a",100000),"monty"),"monty"); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,cast(_latin1'HE' as char charset binary) AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate latin1_bin),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n \r\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n \r\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")`,replace(_latin1'aaaa',_latin1'a',_latin1'b') AS `replace('aaaa','a','b')`,insert(_latin1'txs',2,1,_latin1'hi') AS `insert('txs',2,1,'hi')`,left(_latin2'a',1) AS `left(_latin2'a',1)`,right(_latin2'a',1) AS `right(_latin2'a',1)`,lcase(_latin2'a') AS `lcase(_latin2'a')`,ucase(_latin2'a') AS `ucase(_latin2'a')`,substr(_latin1'abcdefg',3,2) AS `SUBSTR('abcdefg',3,2)`,substring_index(_latin1'1abcd;2abcd;3abcd;4abcd',_latin1';',2) AS `substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2)`,trim(_latin2' a ') AS `trim(_latin2' a ')`,ltrim(_latin2' a ') AS `ltrim(_latin2' a ')`,rtrim(_latin2' a ') AS `rtrim(_latin2' a ')`,decode(encode(repeat(_latin1'a',100000))) AS `decode(encode(repeat("a",100000),"monty"),"monty")` +SELECT lpad(12345, 5, "#"); +lpad(12345, 5, "#") +12345 +SELECT conv(71, 10, 36), conv('1Z', 36, 10); +conv(71, 10, 36) conv('1Z', 36, 10) +1Z 71 +create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb'); +create table t2 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8; +insert into t2 values (1,'cccccccccc'), (2,'dddddddddd'); +select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 +where t2.id=t1.id order by name; +name +aaaaaaaaaaccccc +bbbbbbbbbbddddd +drop table t1, t2; +create table t1 (c1 INT, c2 INT UNSIGNED); +insert into t1 values ('21474836461','21474836461'); +Warnings: +Warning 1264 Out of range value adjusted for column 'c1' at row 1 +Warning 1264 Out of range value adjusted for column 'c2' at row 1 +insert into t1 values ('-21474836461','-21474836461'); +Warnings: +Warning 1264 Out of range value adjusted for column 'c1' at row 1 +Warning 1264 Out of range value adjusted for column 'c2' at row 1 +show warnings; +Level Code Message +Warning 1264 Out of range value adjusted for column 'c1' at row 1 +Warning 1264 Out of range value adjusted for column 'c2' at row 1 +select * from t1; +c1 c2 +2147483647 4294967295 +-2147483648 0 +drop table t1; +select left(1234, 3) + 0; +left(1234, 3) + 0 +123 From 79d8bde11ee6da9474a5b122c1739316f5adb120 Mon Sep 17 00:00:00 2001 From: "paul@kite-hub.kitebird.com" <> Date: Fri, 12 Nov 2004 14:15:06 -0600 Subject: [PATCH 89/94] Makefile.am: Add -acc flag for texi2html to handle accented characters. --- Docs/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/Makefile.am b/Docs/Makefile.am index e53ea195d94..2f32dfca1b4 100644 --- a/Docs/Makefile.am +++ b/Docs/Makefile.am @@ -9,7 +9,7 @@ # If you know how to fix any of this more elegantly please mail # docs@mysql.com -TEXI2HTML_FLAGS = -iso -number +TEXI2HTML_FLAGS = -iso -number -acc DVIPS = dvips MAKEINFO = @MAKEINFO@ TEXINFO_TEX = Support/texinfo.tex From 7df412160ad9fe8c350656cd9ed6dc01e9d565df Mon Sep 17 00:00:00 2001 From: "patg@patrick-galbraiths-computer.local" <> Date: Fri, 12 Nov 2004 15:56:25 -0800 Subject: [PATCH 90/94] Needed for WL# 2094, MySQL Federated Storage Handler sql_string.h: simple string method to drop last character of a string (also decrements str_length) --- BitKeeper/etc/logging_ok | 1 + sql/sql_string.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index c35853e3258..84f6b60f4d9 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -156,6 +156,7 @@ nick@mysql.com nick@nick.leippe.com papa@gbichot.local patg@krsna.patg.net +patg@patrick-galbraiths-computer.local paul@central.snake.net paul@ice.local paul@ice.snake.net diff --git a/sql/sql_string.h b/sql/sql_string.h index cb5b1fb25fd..2101db40f92 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -141,6 +141,34 @@ public: bool set(longlong num, CHARSET_INFO *cs); bool set(ulonglong num, CHARSET_INFO *cs); bool set(double num,uint decimals, CHARSET_INFO *cs); + + /* + PMG 2004.11.12 + This is a method that works the same as perl's "chop". It simply + drops the last character of a string. This is useful in the case + of the federated storage handler where I'm building a unknown + number, list of values and fields to be used in a sql insert + statement to be run on the remote server, and have a comma after each. + When the list is complete, I "chop" off the trailing comma + + ex. + String stringobj; + stringobj.append("VALUES ('foo', 'fi', 'fo',"); + stringobj.chop(); + stringobj.append(")"); + + In this case, the value of string was: + + VALUES ('foo', 'fi', 'fo', + VALUES ('foo', 'fi', 'fo' + VALUES ('foo', 'fi', 'fo') + + */ + inline void chop() + { + Ptr[str_length--]= '\0'; + } + inline void free() { if (alloced) From 321f803784c6a64489a77cf3ebb65a6ba6ebe5b6 Mon Sep 17 00:00:00 2001 From: "gluh@gluh.mysql.r18.ru" <> Date: Sat, 13 Nov 2004 13:56:39 +0300 Subject: [PATCH 91/94] WL#1629: SHOW with WHERE(partially) & WL#173: Create Data Dictionary Tables for SHOW Commands --- mysql-test/r/information_schema.result | 402 +++++ mysql-test/t/information_schema.test | 188 ++ sql/ha_innodb.cc | 98 ++ sql/ha_innodb.h | 1 + sql/handler.h | 4 + sql/mysql_priv.h | 33 +- sql/opt_sum.cc | 2 +- sql/sql_acl.cc | 218 ++- sql/sql_base.cc | 16 +- sql/sql_lex.cc | 1 + sql/sql_lex.h | 4 +- sql/sql_parse.cc | 216 +-- sql/sql_select.cc | 29 +- sql/sql_show.cc | 2178 ++++++++++++++++++------ sql/sql_view.cc | 5 +- sql/sql_yacc.yy | 142 +- sql/table.cc | 1 + sql/table.h | 54 + tests/client_test.c | 40 +- 19 files changed, 2932 insertions(+), 700 deletions(-) create mode 100644 mysql-test/r/information_schema.result create mode 100644 mysql-test/t/information_schema.test diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result new file mode 100644 index 00000000000..6267fd204c4 --- /dev/null +++ b/mysql-test/r/information_schema.result @@ -0,0 +1,402 @@ +grant all privileges on test.* to mysqltest_1@localhost; +select * from information_schema.SCHEMATA where schema_name > 'm'; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME +NULL mysql latin1_swedish_ci +NULL test latin1_swedish_ci +select schema_name from information_schema.schemata; +schema_name +mysql +test +show databases *; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME +NULL mysql latin1_swedish_ci +NULL test latin1_swedish_ci +show databases like 't%'; +Database (t%) +test +show databases; +Database +mysql +test +show databases * where schema_name like 't%'; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME +NULL test latin1_swedish_ci +show databases * where schema_name = 't%'; +CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME +create database testtets; +create table testtets.t1(a int, b VARCHAR(30), KEY string_data (b)); +create table test.t2(a int); +create table t3(a int, KEY a_data (a)); +create table testtets.t4(a int); +create view v1 (c) as select table_name from information_schema.TABLES; +select * from v1; +c +columns_priv +db +func +help_category +help_keyword +help_relation +help_topic +host +proc +tables_priv +time_zone +time_zone_leap_second +time_zone_name +time_zone_transition +time_zone_transition_type +user +t2 +t3 +v1 +t1 +t4 +select c,table_name from v1 +left join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; +c table_name +tables_priv tables_priv +time_zone time_zone +time_zone_leap_second time_zone_leap_second +time_zone_name time_zone_name +time_zone_transition time_zone_transition +time_zone_transition_type time_zone_transition_type +t2 t2 +t3 t3 +t1 t1 +t4 t4 +select c, v2.table_name from v1 +right join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; +c table_name +tables_priv tables_priv +time_zone time_zone +time_zone_leap_second time_zone_leap_second +time_zone_name time_zone_name +time_zone_transition time_zone_transition +time_zone_transition_type time_zone_transition_type +t2 t2 +t3 t3 +t1 t1 +t4 t4 +select table_name from information_schema.TABLES +where table_schema = "testtets" and table_name like "t%"; +table_name +t1 +t4 +select * from information_schema.STATISTICS where TABLE_SCHEMA = "testtets"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT +NULL testtets t1 1 testtets string_data 1 b A NULL NULL NULL YES BTREE +show keys * where TABLE_SCHEMA Like "test%"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT +NULL test t3 1 test a_data 1 a A NULL NULL NULL YES BTREE +NULL testtets t1 1 testtets string_data 1 b A NULL NULL NULL YES BTREE +show keys where INDEX_NAME = "a_data"; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t3 1 a_data 1 a A NULL NULL NULL YES BTREE +show tables like 't%'; +Tables_in_test (t%) +t2 +t3 +show tables * from test where table_name like 't%'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE +NULL test t2 +NULL test t3 +show table status; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t2 MyISAM 9 Fixed 0 0 0 21474836479 1024 0 NULL # # NULL latin1_swedish_ci NULL +t3 MyISAM 9 Fixed 0 0 0 21474836479 1024 0 NULL # # NULL latin1_swedish_ci NULL +v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view +show full columns from t3 like "a%"; +Field Type Collation Null Key Default Extra Privileges Comment +a int(11) NULL YES MUL NULL select,insert,update,references +show full columns from mysql.db like "Insert%"; +Field Type Collation Null Key Default Extra Privileges Comment +Insert_priv enum('N','Y') utf8_bin N select,insert,update,references +show full columns from v1; +Field Type Collation Null Key Default Extra Privileges Comment +c char(64) latin1_swedish_ci select,insert,update,references +select * from information_schema.COLUMNS where table_name="t1" +and column_name= "a"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME TYPE COLLATION_NAME IS_NULLABLE KEY COLUMN_DEFAULT EXTRA PRIVILIGES COMMENT +NULL testtets t1 a 1 int 0 11 4 0 NULL int(11) NULL YES NULL select,insert,update,references +show columns * where table_name = "t1"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME TYPE COLLATION_NAME IS_NULLABLE KEY COLUMN_DEFAULT EXTRA PRIVILIGES COMMENT +NULL testtets t1 a 1 int 0 11 4 0 NULL int(11) NULL YES NULL +NULL testtets t1 b 2 varchar 30 30 30 31 latin1 varchar(30) latin1_swedish_ci YES MUL NULL +drop view v1; +drop tables testtets.t4, testtets.t1, t2, t3; +drop database testtets; +select * from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like 'latin1%'; +CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +latin1 ISO 8859-1 West European latin1_swedish_ci 1 +SHOW CHARACTER SET LIKE 'latin1%'; +Charset Description Default collation Maxlen +latin1 ISO 8859-1 West European latin1_swedish_ci 1 +SHOW CHARACTER SET * LIKE 'latin1%'; +CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +latin1 ISO 8859-1 West European latin1_swedish_ci 1 +SHOW CHARACTER SET WHERE CHARACTER_SET_NAME like 'latin1%'; +Charset Description Default collation Maxlen +latin1 ISO 8859-1 West European latin1_swedish_ci 1 +SHOW CHARACTER SET CHARACTER_SET_NAME WHERE CHARACTER_SET_NAME like 'latin1%'; +CHARACTER_SET_NAME +latin1 +SHOW CHARACTER SET * WHERE CHARACTER_SET_NAME like 'latin1%'; +CHARACTER_SET_NAME Description DEFAULT_COLLATE_NAME Maxlen +latin1 ISO 8859-1 West European latin1_swedish_ci 1 +select * from information_schema.COLLATIONS +where COLLATION_NAME like 'latin1%'; +COLLATION_NAME Charset Id Default Compiled Sortlen +latin1_german1_ci latin1 5 0 +latin1_swedish_ci latin1 8 Yes Yes 1 +latin1_danish_ci latin1 15 0 +latin1_german2_ci latin1 31 Yes 2 +latin1_bin latin1 47 Yes 1 +latin1_general_ci latin1 48 0 +latin1_general_cs latin1 49 0 +latin1_spanish_ci latin1 94 0 +SHOW COLLATION LIKE 'latin1%'; +Collation Charset Id Default Compiled Sortlen +latin1_german1_ci latin1 5 0 +latin1_swedish_ci latin1 8 Yes Yes 1 +latin1_danish_ci latin1 15 0 +latin1_german2_ci latin1 31 Yes 2 +latin1_bin latin1 47 Yes 1 +latin1_general_ci latin1 48 0 +latin1_general_cs latin1 49 0 +latin1_spanish_ci latin1 94 0 +SHOW COLLATION * LIKE 'latin1%'; +COLLATION_NAME Charset Id Default Compiled Sortlen +latin1_german1_ci latin1 5 0 +latin1_swedish_ci latin1 8 Yes Yes 1 +latin1_danish_ci latin1 15 0 +latin1_german2_ci latin1 31 Yes 2 +latin1_bin latin1 47 Yes 1 +latin1_general_ci latin1 48 0 +latin1_general_cs latin1 49 0 +latin1_spanish_ci latin1 94 0 +SHOW COLLATION WHERE COLLATION_NAME like 'latin1%'; +Collation Charset Id Default Compiled Sortlen +latin1_german1_ci latin1 5 0 +latin1_swedish_ci latin1 8 Yes Yes 1 +latin1_danish_ci latin1 15 0 +latin1_german2_ci latin1 31 Yes 2 +latin1_bin latin1 47 Yes 1 +latin1_general_ci latin1 48 0 +latin1_general_cs latin1 49 0 +latin1_spanish_ci latin1 94 0 +SHOW COLLATION COLLATION_NAME WHERE COLLATION_NAME like 'latin1%'; +COLLATION_NAME +latin1_german1_ci +latin1_swedish_ci +latin1_danish_ci +latin1_german2_ci +latin1_bin +latin1_general_ci +latin1_general_cs +latin1_spanish_ci +SHOW COLLATION * WHERE COLLATION_NAME like 'latin1%'; +COLLATION_NAME Charset Id Default Compiled Sortlen +latin1_german1_ci latin1 5 0 +latin1_swedish_ci latin1 8 Yes Yes 1 +latin1_danish_ci latin1 15 0 +latin1_german2_ci latin1 31 Yes 2 +latin1_bin latin1 47 Yes 1 +latin1_general_ci latin1 48 0 +latin1_general_cs latin1 49 0 +latin1_spanish_ci latin1 94 0 +select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY +where COLLATION_NAME like 'latin1%'; +COLLATION_NAME CHARACTER_SET_NAME +latin1_german1_ci latin1 +latin1_swedish_ci latin1 +latin1_danish_ci latin1 +latin1_german2_ci latin1 +latin1_bin latin1 +latin1_general_ci latin1 +latin1_general_cs latin1 +latin1_spanish_ci latin1 +create function sub1(i int) returns int +return i+1; +create procedure sel2() +begin +select * from t1; +select * from t2; +end| +show procedure status; +Db Name Type Definer Modified Created Security_type Comment +test sel2 PROCEDURE root@localhost # # DEFINER +show function status; +Db Name Type Definer Modified Created Security_type Comment +test sub1 FUNCTION root@localhost # # DEFINER +select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; +ROUTINE_NAME +sel2 +sub1 +explain select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE # ALL NULL NULL NULL NULL 2 +1 SIMPLE # ALL NULL NULL NULL NULL 2 Using where +select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a, +mysql.proc b where a.ROUTINE_NAME = b.name; +ROUTINE_NAME name +sub1 sub1 +sel2 sel2 +select count(*) from information_schema.ROUTINES; +count(*) +2 +create view v0 (c) as select schema_name from information_schema.SCHEMATA; +select * from v0; +c +mysql +test +explain select * from v0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY # ALL NULL NULL NULL NULL 2 +create view v1 (c) as select table_name from information_schema.TABLES +where table_name="v1"; +select * from v1; +c +v1 +create view v2 (c) as select column_name from information_schema.COLUMNS +where table_name="v2"; +select * from v2; +c +c +create view v3 (c) as select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like "latin1%"; +select * from v3; +c +latin1 +create view v4 (c) as select COLLATION_NAME from information_schema.COLLATIONS +where COLLATION_NAME like "latin1%"; +select * from v4; +c +latin1_german1_ci +latin1_swedish_ci +latin1_danish_ci +latin1_german2_ci +latin1_bin +latin1_general_ci +latin1_general_cs +latin1_spanish_ci +show keys from v4; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +select * from information_schema.VIEWS where TABLE_NAME like "v%"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE +NULL test v0 select `SCHEMATA`.`SCHEMA_NAME` AS `c` from `information_schema`.`SCHEMATA` NONE NO +NULL test v1 select `TABLES`.`TABLE_NAME` AS `c` from `information_schema`.`TABLES` where (`TABLES`.`TABLE_NAME` = _latin1'v1') NONE NO +NULL test v2 select `COLUMNS`.`COLUMN_NAME` AS `c` from `information_schema`.`COLUMNS` where (`COLUMNS`.`TABLE_NAME` = _latin1'v2') NONE NO +NULL test v3 select `CHARACTER_SETS`.`CHARACTER_SET_NAME` AS `c` from `information_schema`.`CHARACTER_SETS` where (`CHARACTER_SETS`.`CHARACTER_SET_NAME` like _latin1'latin1%') NONE NO +NULL test v4 select `COLLATIONS`.`COLLATION_NAME` AS `c` from `information_schema`.`COLLATIONS` where (`COLLATIONS`.`COLLATION_NAME` like _latin1'latin1%') NONE NO +drop view v0, v1, v2, v3, v4; +create table t1 (a int); +grant select,update,insert on t1 to mysqltest_1@localhost; +grant select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost; +grant all on test.* to mysqltest_1@localhost with grant option; +select * from information_schema.USER_PRIVILEGES where grantee like '%mysqltest_1%'; +GRANTEE TABLE_CATALOG PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_1'@'localhost' NULL USAGE NO +select * from information_schema.SCHEMA_PRIVILEGES where grantee like '%mysqltest_1%'; +GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_1'@'localhost' NULL test SELECT YES +'mysqltest_1'@'localhost' NULL test INSERT YES +'mysqltest_1'@'localhost' NULL test UPDATE YES +'mysqltest_1'@'localhost' NULL test DELETE YES +'mysqltest_1'@'localhost' NULL test CREATE YES +'mysqltest_1'@'localhost' NULL test DROP YES +'mysqltest_1'@'localhost' NULL test REFERENCES YES +'mysqltest_1'@'localhost' NULL test INDEX YES +'mysqltest_1'@'localhost' NULL test ALTER YES +'mysqltest_1'@'localhost' NULL test CREATE TEMPORARY TABLES YES +'mysqltest_1'@'localhost' NULL test LOCK TABLES YES +'mysqltest_1'@'localhost' NULL test CREATE VIEW YES +'mysqltest_1'@'localhost' NULL test SHOW VIEW YES +select * from information_schema.TABLE_PRIVILEGES where grantee like '%mysqltest_1%'; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_1'@'localhost' NULL test t1 SELECT NO +'mysqltest_1'@'localhost' NULL test t1 INSERT NO +'mysqltest_1'@'localhost' NULL test t1 UPDATE NO +select * from information_schema.COLUMN_PRIVILEGES where grantee like '%mysqltest_1%'; +GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE +'mysqltest_1'@'localhost' NULL test t1 a SELECT NO +'mysqltest_1'@'localhost' NULL test t1 a INSERT NO +'mysqltest_1'@'localhost' NULL test t1 a UPDATE NO +'mysqltest_1'@'localhost' NULL test t1 a REFERENCES NO +delete from mysql.user where user='mysqltest_1'; +delete from mysql.db where user='mysqltest_1'; +delete from mysql.tables_priv where user='mysqltest_1'; +delete from mysql.columns_priv where user='mysqltest_1'; +flush privileges; +drop table t1; +create table t1 (a int null, primary key(a)); +alter table t1 add constraint constraint_1 unique (a); +alter table t1 add constraint unique key_1(a); +alter table t1 add constraint constraint_2 unique key_2(a); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL default '0', + PRIMARY KEY (`a`), + UNIQUE KEY `constraint_1` (`a`), + UNIQUE KEY `key_1` (`a`), + UNIQUE KEY `key_2` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_METHOD +NULL test PRIMARY test t1 PRIMARY NULL +NULL test constraint_1 test t1 UNIQUE NULL +NULL test key_1 test t1 UNIQUE NULL +NULL test key_2 test t1 UNIQUE NULL +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +NULL test PRIMARY test t1 a 1 NULL NULL NULL +NULL test constraint_1 test t1 a 1 NULL NULL NULL +NULL test key_1 test t1 a 1 NULL NULL NULL +NULL test key_2 test t1 a 1 NULL NULL NULL +drop table t1; +CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), +FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE, +FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB; +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_METHOD +NULL test PRIMARY test t1 PRIMARY NULL +NULL test PRIMARY test t2 PRIMARY NULL +NULL test t2_ibfk_1 test t2 FOREIGN ON DELETE CASCADE +NULL test t2_ibfk_2 test t2 FOREIGN ON UPDATE CASCADE +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +NULL test PRIMARY test t1 id 1 NULL NULL NULL +NULL test PRIMARY test t2 id 1 NULL NULL NULL +NULL test t2_ibfk_1 test t2 t1_id 1 test t1 id +NULL test t2_ibfk_2 test t2 t1_id 1 test t1 id +select table_name from information_schema.TABLES where table_schema like "test%"; +table_name +t1 +t2 +select table_name,column_name from information_schema.COLUMNS where table_schema like "test%"; +table_name column_name +t1 id +t2 id +t2 t1_id +select ROUTINE_NAME from information_schema.ROUTINES; +ROUTINE_NAME +sel2 +sub1 +delete from mysql.user where user='mysqltest_1'; +drop table t2; +drop table t1; +drop procedure sel2; +drop function sub1; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test new file mode 100644 index 00000000000..017bf465d53 --- /dev/null +++ b/mysql-test/t/information_schema.test @@ -0,0 +1,188 @@ + +# Test for information_schema.schemata & +# show databases + +grant all privileges on test.* to mysqltest_1@localhost; + +select * from information_schema.SCHEMATA where schema_name > 'm'; +select schema_name from information_schema.schemata; +show databases *; +show databases like 't%'; +show databases; +show databases * where schema_name like 't%'; +show databases * where schema_name = 't%'; + +# Test for information_schema.tables & +# show tables + +create database testtets; +create table testtets.t1(a int, b VARCHAR(30), KEY string_data (b)); +create table test.t2(a int); +create table t3(a int, KEY a_data (a)); +create table testtets.t4(a int); +create view v1 (c) as select table_name from information_schema.TABLES; +select * from v1; +select c,table_name from v1 +left join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; + +select c, v2.table_name from v1 +right join information_schema.TABLES v2 on (v1.c=v2.table_name) +where v1.c like "t%"; + +select table_name from information_schema.TABLES +where table_schema = "testtets" and table_name like "t%"; + +select * from information_schema.STATISTICS where TABLE_SCHEMA = "testtets"; +show keys * where TABLE_SCHEMA Like "test%"; +show keys where INDEX_NAME = "a_data"; + +show tables like 't%'; +--replace_column 15 # 16 # +show tables * from test where table_name like 't%'; +--replace_column 12 # 13 # +show table status; +show full columns from t3 like "a%"; +show full columns from mysql.db like "Insert%"; +show full columns from v1; +select * from information_schema.COLUMNS where table_name="t1" +and column_name= "a"; +show columns * where table_name = "t1"; + +drop view v1; +drop tables testtets.t4, testtets.t1, t2, t3; +drop database testtets; + +# Test for information_schema.CHARACTER_SETS & +# SHOW CHARACTER SET + +select * from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like 'latin1%'; +SHOW CHARACTER SET LIKE 'latin1%'; +SHOW CHARACTER SET * LIKE 'latin1%'; +SHOW CHARACTER SET WHERE CHARACTER_SET_NAME like 'latin1%'; +SHOW CHARACTER SET CHARACTER_SET_NAME WHERE CHARACTER_SET_NAME like 'latin1%'; +SHOW CHARACTER SET * WHERE CHARACTER_SET_NAME like 'latin1%'; + +# Test for information_schema.COLLATIONS & +# SHOW COLLATION + +select * from information_schema.COLLATIONS +where COLLATION_NAME like 'latin1%'; +SHOW COLLATION LIKE 'latin1%'; +SHOW COLLATION * LIKE 'latin1%'; +SHOW COLLATION WHERE COLLATION_NAME like 'latin1%'; +SHOW COLLATION COLLATION_NAME WHERE COLLATION_NAME like 'latin1%'; +SHOW COLLATION * WHERE COLLATION_NAME like 'latin1%'; + +select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY +where COLLATION_NAME like 'latin1%'; + +# Test for information_schema.ROUTINES & +# + +create function sub1(i int) returns int + return i+1; +delimiter |; +create procedure sel2() +begin + select * from t1; + select * from t2; +end| +delimiter ;| + +--replace_column 5 # 6 # +show procedure status; +--replace_column 5 # 6 # +show function status; +select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; +--replace_column 3 # +explain select a.ROUTINE_NAME from information_schema.ROUTINES a, +information_schema.SCHEMATA b where +a.ROUTINE_SCHEMA = b.SCHEMA_NAME; + +select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a, +mysql.proc b where a.ROUTINE_NAME = b.name; +select count(*) from information_schema.ROUTINES; + +# +# Test for views +# +create view v0 (c) as select schema_name from information_schema.SCHEMATA; +select * from v0; +--replace_column 3 # +explain select * from v0; +create view v1 (c) as select table_name from information_schema.TABLES +where table_name="v1"; +select * from v1; +create view v2 (c) as select column_name from information_schema.COLUMNS +where table_name="v2"; +select * from v2; +create view v3 (c) as select CHARACTER_SET_NAME from information_schema.CHARACTER_SETS +where CHARACTER_SET_NAME like "latin1%"; +select * from v3; +create view v4 (c) as select COLLATION_NAME from information_schema.COLLATIONS +where COLLATION_NAME like "latin1%"; +select * from v4; +show keys from v4; +select * from information_schema.VIEWS where TABLE_NAME like "v%"; +drop view v0, v1, v2, v3, v4; + +# +# Test for privileges tables +# +create table t1 (a int); +grant select,update,insert on t1 to mysqltest_1@localhost; +grant select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost; +grant all on test.* to mysqltest_1@localhost with grant option; +select * from information_schema.USER_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.SCHEMA_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.TABLE_PRIVILEGES where grantee like '%mysqltest_1%'; +select * from information_schema.COLUMN_PRIVILEGES where grantee like '%mysqltest_1%'; +delete from mysql.user where user='mysqltest_1'; +delete from mysql.db where user='mysqltest_1'; +delete from mysql.tables_priv where user='mysqltest_1'; +delete from mysql.columns_priv where user='mysqltest_1'; +flush privileges; +drop table t1; + + +# +# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables +# + +create table t1 (a int null, primary key(a)); +alter table t1 add constraint constraint_1 unique (a); +alter table t1 add constraint unique key_1(a); +alter table t1 add constraint constraint_2 unique key_2(a); +show create table t1; +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; +drop table t1; + +CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), +FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE, +FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB; +select * from information_schema.TABLE_CONSTRAINTS where +TABLE_SCHEMA= "test"; +select * from information_schema.KEY_COLUMN_USAGE where +TABLE_SCHEMA= "test"; + +connect (user1,localhost,mysqltest_1,,); +connection user1; +select table_name from information_schema.TABLES where table_schema like "test%"; +select table_name,column_name from information_schema.COLUMNS where table_schema like "test%"; +select ROUTINE_NAME from information_schema.ROUTINES; +disconnect user1; +connection default; +delete from mysql.user where user='mysqltest_1'; +drop table t2; +drop table t1; +drop procedure sel2; +drop function sub1; + \ No newline at end of file diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 370458c6e01..7f92f9fd899 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -4674,6 +4674,104 @@ ha_innobase::get_foreign_key_create_info(void) return(str); } + +int +ha_innobase::get_foreign_key_list(THD *thd, List *f_key_list) +{ + dict_foreign_t* foreign; + + DBUG_ENTER("get_foreign_key_list"); + row_prebuilt_t* prebuilt = (row_prebuilt_t*)innobase_prebuilt; + ut_a(prebuilt != NULL); + update_thd(current_thd); + prebuilt->trx->op_info = (char*)"getting list of foreign keys"; + trx_search_latch_release_if_reserved(prebuilt->trx); + mutex_enter(&(dict_sys->mutex)); + foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list); + + while (foreign != NULL) + { + uint i; + FOREIGN_KEY_INFO f_key_info; + LEX_STRING *name= 0; + const char *tmp_buff; + + tmp_buff= foreign->id; + i= 0; + while (tmp_buff[i] != '/') + i++; + tmp_buff+= i + 1; + f_key_info.forein_id= make_lex_string(thd, f_key_info.forein_id, + tmp_buff, strlen(tmp_buff), 1); + tmp_buff= foreign->referenced_table_name; + i= 0; + while (tmp_buff[i] != '/') + i++; + f_key_info.referenced_db= make_lex_string(thd, f_key_info.referenced_db, + tmp_buff, i, 1); + tmp_buff+= i + 1; + f_key_info.referenced_table= make_lex_string(thd, + f_key_info.referenced_table, + tmp_buff, strlen(tmp_buff), 1); + + for (i= 0;;) + { + tmp_buff= foreign->foreign_col_names[i]; + name= make_lex_string(thd, name, tmp_buff, strlen(tmp_buff), 1); + f_key_info.foreign_fields.push_back(name); + tmp_buff= foreign->referenced_col_names[i]; + name= make_lex_string(thd, name, tmp_buff, strlen(tmp_buff), 1); + f_key_info.referenced_fields.push_back(name); + if (++i >= foreign->n_fields) + break; + } + + ulong length= 0; + if (foreign->type == DICT_FOREIGN_ON_DELETE_CASCADE) + { + length=17; + tmp_buff= "ON DELETE CASCADE"; + } + else if (foreign->type == DICT_FOREIGN_ON_DELETE_SET_NULL) + { + length=18; + tmp_buff= "ON DELETE SET NULL"; + } + else if (foreign->type == DICT_FOREIGN_ON_DELETE_NO_ACTION) + { + length=19; + tmp_buff= "ON DELETE NO ACTION"; + } + else if (foreign->type == DICT_FOREIGN_ON_UPDATE_CASCADE) + { + length=17; + tmp_buff= "ON UPDATE CASCADE"; + } + else if (foreign->type == DICT_FOREIGN_ON_UPDATE_SET_NULL) + { + length=18; + tmp_buff= "ON UPDATE SET NULL"; + } + else if (foreign->type == DICT_FOREIGN_ON_UPDATE_NO_ACTION) + { + length=19; + tmp_buff= "ON UPDATE NO ACTION"; + } + f_key_info.constraint_method= make_lex_string(thd, + f_key_info.constraint_method, + tmp_buff, length, 1); + + FOREIGN_KEY_INFO *pf_key_info= ((FOREIGN_KEY_INFO *) + thd->memdup((gptr) &f_key_info, + sizeof(FOREIGN_KEY_INFO))); + f_key_list->push_back(pf_key_info); + foreign = UT_LIST_GET_NEXT(foreign_list, foreign); + } + mutex_exit(&(dict_sys->mutex)); + prebuilt->trx->op_info = (char*)""; + DBUG_RETURN(0); +} + /*********************************************************************** Checks if a table is referenced by a foreign key. The MySQL manual states that a REPLACE is either equivalent to an INSERT, or DELETE(s) + INSERT. Only a diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index 7e337afed0e..f9588bee055 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -162,6 +162,7 @@ class ha_innobase: public handler int check(THD* thd, HA_CHECK_OPT* check_opt); char* update_table_comment(const char* comment); char* get_foreign_key_create_info(); + int get_foreign_key_list(THD *thd, List *f_key_list); uint referenced_by_foreign_key(); void free_foreign_key_create_info(char* str); THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, diff --git a/sql/handler.h b/sql/handler.h index 858a7861dba..31c6e2f902b 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -223,6 +223,8 @@ typedef struct st_ha_create_information struct st_table; typedef struct st_table TABLE; +struct st_foreign_key_info; +typedef struct st_foreign_key_info FOREIGN_KEY_INFO; typedef struct st_ha_check_opt { @@ -465,6 +467,8 @@ public: virtual char* get_foreign_key_create_info() { return(NULL);} /* gets foreign key create string from InnoDB */ /* used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */ + virtual int get_foreign_key_list(THD *thd, List *f_key_list) + { return 0; } virtual uint referenced_by_foreign_key() { return 0;} virtual void init_table_handle_for_HANDLER() { return; } /* prepare InnoDB for HANDLER */ diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 62e4f849c67..5af64604cbd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -247,6 +247,7 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset; key checks in some cases */ #define OPTION_RELAXED_UNIQUE_CHECKS (1L << 27) #define SELECT_NO_UNLOCK (1L << 28) +#define OPTION_SCHEMA_TABLE (1L << 29) /* The rest of the file is included in the server only */ #ifndef MYSQL_CLIENT @@ -405,7 +406,8 @@ typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); void free_items(Item *item); void cleanup_items(Item *item); class THD; -void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0); +void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0, + TABLE *stopper= 0); bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); @@ -692,14 +694,7 @@ void free_des_key_file(); int mysql_do(THD *thd, List &values); /* sql_show.cc */ -int mysqld_show_dbs(THD *thd,const char *wild); int mysqld_show_open_tables(THD *thd,const char *wild); -int mysqld_show_tables(THD *thd, const char *db, const char *wild, - bool verbose); -int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild); -int mysqld_show_fields(THD *thd,TABLE_LIST *table, const char *wild, - bool verbose); -int mysqld_show_keys(THD *thd, TABLE_LIST *table); int mysqld_show_logs(THD *thd); void append_identifier(THD *thd, String *packet, const char *name, uint length); @@ -718,14 +713,32 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, struct system_status_var *status_var); int mysql_find_files(THD *thd,List *files, const char *db, const char *path, const char *wild, bool dir); -int mysqld_show_charsets(THD *thd,const char *wild); -int mysqld_show_collations(THD *thd,const char *wild); int mysqld_show_storage_engines(THD *thd); int mysqld_show_privileges(THD *thd); int mysqld_show_column_types(THD *thd); int mysqld_help (THD *thd, const char *text); void calc_sum_of_all_status(STATUS_VAR *to); + + +/* information schema */ +extern LEX_STRING information_schema_name; +LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str, + const char* str, uint length, + bool allocate_lex_string= 0); +ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name); +ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx); +int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, + enum enum_schema_tables schema_table_idx); +int make_schema_select(THD *thd, SELECT_LEX *sel, + enum enum_schema_tables schema_table_idx); +int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list); +int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond); +int get_schema_tables_result(JOIN *join); + /* sql_prepare.cc */ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, LEX_STRING *name=NULL); diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 30033bc39eb..f9a51a8348f 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -131,7 +131,7 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) for (table= tables; table; table= table->next_local) { if (outer_tables || (table->table->file->table_flags() & - HA_NOT_EXACT_COUNT)) + HA_NOT_EXACT_COUNT) || table->schema_table) { const_result= 0; // Can't optimize left join break; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 59456c0eb2c..e796f275509 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2851,7 +2851,8 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, for (table= tables; table && number--; table= table->next_global) { GRANT_TABLE *grant_table; - if (!(~table->grant.privilege & want_access) || table->derived) + if (!(~table->grant.privilege & want_access) || + table->derived || table->schema_table) { /* It is subquery in the FROM clause. VIEW set table->derived after @@ -3928,6 +3929,221 @@ int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr) DBUG_RETURN (*str != '\0'); } + +void update_schema_privilege(TABLE *table, char *buff, const char* db, + const char* t_name, const char* column, + uint col_length, const char *priv, + uint priv_length, const char* is_grantable) +{ + int i= 2; + CHARSET_INFO *cs= system_charset_info; + restore_record(table, default_values); + table->field[0]->store(buff, strlen(buff), cs); + if (db) + table->field[i++]->store(db, strlen(db), cs); + if (t_name) + table->field[i++]->store(t_name, strlen(t_name), cs); + if (column) + table->field[i++]->store(column, col_length, cs); + table->field[i++]->store(priv, priv_length, cs); + table->field[i]->store(is_grantable, strlen(is_grantable), cs); + table->file->write_row(table->record[0]); +} + + +int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) +{ +#ifndef NO_EMBEDDED_ACCESS_CHECKS + uint counter; + ACL_USER *acl_user; + ulong want_access; + + char buff[100]; + TABLE *table= tables->table; + DBUG_ENTER("fill_schema_user_privileges"); + for (counter=0 ; counter < acl_users.elements ; counter++) + { + const char *user,*host, *is_grantable="YES"; + acl_user=dynamic_element(&acl_users,counter,ACL_USER*); + if (!(user=acl_user->user)) + user= ""; + if (!(host=acl_user->host.hostname)) + host= ""; + want_access= acl_user->access; + if (!(want_access & GRANT_ACL)) + is_grantable= "NO"; + + strxmov(buff,"'",user,"'@'",host,"'",NullS); + if (!(want_access & ~GRANT_ACL)) + update_schema_privilege(table, buff, 0, 0, 0, 0, "USAGE", 5, is_grantable); + else + { + uint priv_id; + ulong j,test_access= want_access & ~GRANT_ACL; + for (priv_id=0, j = SELECT_ACL;j <= GLOBAL_ACLS; priv_id++,j <<= 1) + { + if (test_access & j) + update_schema_privilege(table, buff, 0, 0, 0, 0, + command_array[priv_id], + command_lengths[priv_id], is_grantable); + } + } + } +#endif + DBUG_RETURN(0); +} + + +int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) +{ +#ifndef NO_EMBEDDED_ACCESS_CHECKS + uint counter; + ACL_DB *acl_db; + ulong want_access; + char buff[100]; + TABLE *table= tables->table; + DBUG_ENTER("fill_schema_schema_privileges"); + + for (counter=0 ; counter < acl_dbs.elements ; counter++) + { + const char *user, *host, *is_grantable="YES"; + + acl_db=dynamic_element(&acl_dbs,counter,ACL_DB*); + if (!(user=acl_db->user)) + user= ""; + if (!(host=acl_db->host.hostname)) + host= ""; + + want_access=acl_db->access; + if (want_access) + { + if (!(want_access & GRANT_ACL)) + { + is_grantable= "NO"; + } + strxmov(buff,"'",user,"'@'",host,"'",NullS); + if (!(want_access & ~GRANT_ACL)) + update_schema_privilege(table, buff, acl_db->db, 0, 0, + 0, "USAGE", 5, is_grantable); + else + { + int cnt; + ulong j,test_access= want_access & ~GRANT_ACL; + for (cnt=0, j = SELECT_ACL; j <= DB_ACLS; cnt++,j <<= 1) + if (test_access & j) + update_schema_privilege(table, buff, acl_db->db, 0, 0, 0, + command_array[cnt], command_lengths[cnt], + is_grantable); + } + } + } +#endif + DBUG_RETURN(0); +} + + +int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) +{ +#ifndef NO_EMBEDDED_ACCESS_CHECKS + uint index; + char buff[100]; + TABLE *table= tables->table; + DBUG_ENTER("fill_schema_table_privileges"); + + for (index=0 ; index < column_priv_hash.records ; index++) + { + const char *user, *is_grantable= "YES"; + GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash, + index); + if (!(user=grant_table->user)) + user= ""; + ulong table_access= grant_table->privs; + if (table_access != 0) + { + ulong test_access= table_access & ~GRANT_ACL; + if (!(table_access & GRANT_ACL)) + is_grantable= "NO"; + + strxmov(buff,"'",user,"'@'",grant_table->orig_host,"'",NullS); + if (!test_access) + update_schema_privilege(table, buff, grant_table->db, grant_table->tname, + 0, 0, "USAGE", 5, is_grantable); + else + { + ulong j; + int cnt; + for (cnt= 0, j= SELECT_ACL; j <= TABLE_ACLS; cnt++, j<<= 1) + { + if (test_access & j) + update_schema_privilege(table, buff, grant_table->db, + grant_table->tname, 0, 0, command_array[cnt], + command_lengths[cnt], is_grantable); + } + } + } + } +#endif + DBUG_RETURN(0); +} + + +int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) +{ +#ifndef NO_EMBEDDED_ACCESS_CHECKS + uint index; + char buff[100]; + TABLE *table= tables->table; + DBUG_ENTER("fill_schema_table_privileges"); + + for (index=0 ; index < column_priv_hash.records ; index++) + { + const char *user, *is_grantable= "YES"; + GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash, + index); + if (!(user=grant_table->user)) + user= ""; + ulong table_access= grant_table->cols; + if (table_access != 0) + { + ulong test_access= grant_table->cols & ~GRANT_ACL; + if (!(table_access & GRANT_ACL)) + is_grantable= "NO"; + + strxmov(buff,"'",user,"'@'",grant_table->orig_host,"'",NullS); + if (!test_access) + continue; + else + { + ulong j; + int cnt; + for (cnt= 0, j= SELECT_ACL; j <= TABLE_ACLS; cnt++, j<<= 1) + { + if (test_access & j) + { + for (uint col_index=0 ; + col_index < grant_table->hash_columns.records ; + col_index++) + { + GRANT_COLUMN *grant_column = (GRANT_COLUMN*) + hash_element(&grant_table->hash_columns,col_index); + if ((grant_column->rights & j) && (table_access & j)) + update_schema_privilege(table, buff, grant_table->db, + grant_table->tname, + grant_column->column, + grant_column->key_length, + command_array[cnt], + command_lengths[cnt], is_grantable); + } + } + } + } + } + } +#endif + DBUG_RETURN(0); +} + + #ifndef NO_EMBEDDED_ACCESS_CHECKS /* fill effective privileges for table diff --git a/sql/sql_base.cc b/sql/sql_base.cc index e690673c934..9dc66f46afa 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -370,7 +370,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, Put all normal tables used by thread in free list. */ -void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) +void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived, + TABLE *stopper) { bool found_old_table; DBUG_ENTER("close_thread_tables"); @@ -408,7 +409,7 @@ void close_thread_tables(THD *thd, bool lock_in_use, bool skip_derived) DBUG_PRINT("info", ("thd->open_tables: %p", thd->open_tables)); found_old_table= 0; - while (thd->open_tables) + while (thd->open_tables != stopper) found_old_table|=close_thread_table(thd, &thd->open_tables); thd->some_tables_deleted=0; @@ -1656,6 +1657,12 @@ int open_tables(THD *thd, TABLE_LIST *start, uint *counter) */ if (tables->derived) continue; + if (tables->schema_table) + { + if (!mysql_schema_table(thd, thd->lex, tables)) + continue; + DBUG_RETURN(-1); + } (*counter)++; if (!tables->table && !(tables->table= open_table(thd, tables, &new_frm_mem, &refresh))) @@ -2904,7 +2911,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, &view_iter)) goto err; } - else + else if (!tables->schema_table) { table_iter.set(tables); if (check_grant_all_columns(thd, SELECT_ACL, &table->grant, @@ -2984,7 +2991,8 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, db= tables->db; tab= tables->real_name; } - if (!(fld->have_privileges= (get_column_grant(thd, + if (!tables->schema_table && + !(fld->have_privileges= (get_column_grant(thd, &table->grant, db, tab, diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 86219abc632..68203d8ba20 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1057,6 +1057,7 @@ void st_select_lex::init_query() first_cond_optimization= 1; parsing_place= NO_MATTER; no_wrap_view_item= 0; + link_next= 0; } void st_select_lex::init_select() diff --git a/sql/sql_lex.h b/sql/sql_lex.h index fd1c1dee0b7..18c13efc528 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -56,7 +56,7 @@ enum enum_sql_command { SQLCOM_SHOW_INNODB_STATUS, SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT, SQLCOM_SHOW_GRANTS, SQLCOM_SHOW_CREATE, SQLCOM_SHOW_CHARSETS, - SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, + SQLCOM_SHOW_COLLATIONS, SQLCOM_SHOW_CREATE_DB, SQLCOM_SHOW_TABLE_STATUS, SQLCOM_LOAD,SQLCOM_SET_OPTION,SQLCOM_LOCK_TABLES,SQLCOM_UNLOCK_TABLES, SQLCOM_GRANT, @@ -692,7 +692,7 @@ typedef struct st_lex LEX_MASTER_INFO mi; // used by CHANGE MASTER USER_RESOURCES mqh; ulong thread_id,type; - enum_sql_command sql_command; + enum_sql_command sql_command, orig_sql_command; thr_lock_type lock_option, multi_lock_option; enum SSL_type ssl_type; /* defined in violite.h */ enum my_lex_states next_state; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 726c4faa7bc..91f8defb2a7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1868,6 +1868,109 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } +int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, + enum enum_schema_tables schema_table_idx) +{ + DBUG_ENTER("prepare_schema_table"); + SELECT_LEX *sel= 0; + switch(schema_table_idx) { + case SCH_SCHEMATA: +#if defined(DONT_ALLOW_SHOW_COMMANDS) + send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + DBUG_RETURN(1); +#else + if ((specialflag & SPECIAL_SKIP_SHOW_DB) && + check_global_access(thd, SHOW_DB_ACL)) + DBUG_RETURN(1); + break; +#endif + case SCH_TABLE_NAMES: + case SCH_TABLES: + case SCH_VIEWS: +#ifdef DONT_ALLOW_SHOW_COMMANDS + send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + DBUG_RETURN(1); +#else + { + char *db= lex->select_lex.db ? lex->select_lex.db : thd->db; + if (!db) + { + send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + DBUG_RETURN(1); /* purecov: inspected */ + } + remove_escape(db); // Fix escaped '_' + if (check_db_name(db)) + { + net_printf(thd,ER_WRONG_DB_NAME, db); + DBUG_RETURN(1); + } + if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) + DBUG_RETURN(1); /* purecov: inspected */ + if (!thd->col_access && check_grant_db(thd,db)) + { + net_printf(thd, ER_DBACCESS_DENIED_ERROR, + thd->priv_user, + thd->priv_host, + db); + DBUG_RETURN(1); + } + lex->select_lex.db= db; + break; + } +#endif + case SCH_COLUMNS: + case SCH_STATISTICS: +#ifdef DONT_ALLOW_SHOW_COMMANDS + send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + DBUG_RETURN(1); +#else + if (table_ident) + { + TABLE_LIST **query_tables_last= lex->query_tables_last; + sel= new SELECT_LEX(); + sel->init_query(); + if(!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ, + (List *) 0, (List *) 0)) + DBUG_RETURN(1); + lex->query_tables_last= query_tables_last; + TABLE_LIST *table_list= (TABLE_LIST*) sel->table_list.first; + char *db= table_list->db; + remove_escape(db); // Fix escaped '_' + remove_escape(table_list->real_name); + if (check_access(thd,SELECT_ACL | EXTRA_ACL,db, + &table_list->grant.privilege, 0, 0)) + DBUG_RETURN(1); /* purecov: inspected */ + if (grant_option && check_grant(thd, SELECT_ACL, table_list, 2, + UINT_MAX, 0)) + DBUG_RETURN(1); + break; + } +#endif + case SCH_PROCEDURES: + case SCH_CHARSETS: + case SCH_COLLATIONS: + case SCH_COLLATION_CHARACTER_SET_APPLICABILITY: + case SCH_USER_PRIVILEGES: + case SCH_SCHEMA_PRIVILEGES: + case SCH_TABLE_PRIVILEGES: + case SCH_COLUMN_PRIVILEGES: + case SCH_TABLE_CONSTRAINTS: + case SCH_KEY_COLUMN_USAGE: + default: + break; + } + + SELECT_LEX *select_lex= lex->current_select; + if (make_schema_select(thd, select_lex, schema_table_idx)) + { + DBUG_RETURN(1); + } + TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first; + table_list->schema_select_lex= sel; + DBUG_RETURN(0); +} + + /* Read query from packet and store in thd->query Used in COM_QUERY and COM_PREPARE @@ -3004,17 +3107,6 @@ unsent_create_error: else res = mysql_drop_index(thd, first_table, &lex->alter_info); break; - case SQLCOM_SHOW_DATABASES: -#if defined(DONT_ALLOW_SHOW_COMMANDS) - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - goto error; -#else - if ((specialflag & SPECIAL_SKIP_SHOW_DB) && - check_global_access(thd, SHOW_DB_ACL)) - goto error; - res= mysqld_show_dbs(thd, (lex->wild ? lex->wild->ptr() : NullS)); - break; -#endif case SQLCOM_SHOW_PROCESSLIST: if (!thd->priv_user[0] && check_global_access(thd,PROCESS_ACL)) break; @@ -3061,96 +3153,10 @@ unsent_create_error: res= mysqld_show_logs(thd); break; } -#endif - case SQLCOM_SHOW_TABLES: - /* FALL THROUGH */ -#ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - goto error; -#else - { - char *db=select_lex->db ? select_lex->db : thd->db; - if (!db) - { - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ - goto error; /* purecov: inspected */ - } - remove_escape(db); // Fix escaped '_' - if (check_db_name(db)) - { - net_printf(thd,ER_WRONG_DB_NAME, db); - goto error; - } - if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) - goto error; /* purecov: inspected */ - if (!thd->col_access && check_grant_db(thd,db)) - { - net_printf(thd, ER_DBACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - db); - goto error; - } - /* grant is checked in mysqld_show_tables */ - if (lex->describe) - res= mysqld_extend_show_tables(thd,db, - (lex->wild ? lex->wild->ptr() : NullS)); - else - res= mysqld_show_tables(thd, db, - (lex->wild ? lex->wild->ptr() : NullS), - lex->verbose); - break; - } #endif case SQLCOM_SHOW_OPEN_TABLES: res= mysqld_show_open_tables(thd,(lex->wild ? lex->wild->ptr() : NullS)); break; - case SQLCOM_SHOW_CHARSETS: - res= mysqld_show_charsets(thd,(lex->wild ? lex->wild->ptr() : NullS)); - break; - case SQLCOM_SHOW_COLLATIONS: - res= mysqld_show_collations(thd,(lex->wild ? lex->wild->ptr() : NullS)); - break; - case SQLCOM_SHOW_FIELDS: - DBUG_ASSERT(first_table == all_tables && first_table != 0); -#ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - goto error; -#else - { - char *db= first_table->db; - remove_escape(db); // Fix escaped '_' - remove_escape(first_table->real_name); - if (check_access(thd,SELECT_ACL | EXTRA_ACL,db, - &first_table->grant.privilege, 0, 0)) - goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd, SELECT_ACL, first_table, 2, UINT_MAX, 0)) - goto error; - res= mysqld_show_fields(thd, first_table, - (lex->wild ? lex->wild->ptr() : NullS), - lex->verbose); - break; - } -#endif - case SQLCOM_SHOW_KEYS: - DBUG_ASSERT(first_table == all_tables && first_table != 0); -#ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ - goto error; -#else - { - char *db= first_table->db; - remove_escape(db); // Fix escaped '_' - remove_escape(first_table->real_name); - if (check_access(thd,SELECT_ACL | EXTRA_ACL,db, - &first_table->grant.privilege, 0, 0)) - goto error; /* purecov: inspected */ - if (grant_option && check_grant(thd, SELECT_ACL, all_tables, 2, UINT_MAX, 0)) - goto error; - res= mysqld_show_keys(thd, first_table); - break; - } -#endif case SQLCOM_CHANGE_DB: mysql_change_db(thd,select_lex->db); break; @@ -4234,7 +4240,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, TABLE_LIST *org_tables=tables; for (; tables; tables= tables->next_global) { - if (tables->derived || + if (tables->derived || tables->schema_table || (tables->table && (int)tables->table->tmp_table) || my_tz_check_n_skip_implicit_tables(&tables, thd->lex->time_zone_tables_used)) @@ -4490,6 +4496,8 @@ mysql_init_select(LEX *lex) SELECT_LEX *select_lex= lex->current_select; select_lex->init_select(); select_lex->select_limit= HA_POS_ERROR; + lex->orig_sql_command= SQLCOM_END; + lex->wild= 0; if (select_lex == &lex->select_lex) { DBUG_ASSERT(lex->result == 0); @@ -5286,6 +5294,18 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX); ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES); ptr->derived= table->sel; + if (!my_strcasecmp(system_charset_info, ptr->db, + information_schema_name.str)) + { + ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->real_name); + if (!schema_table) + { + net_printf(thd, ER_UNKNOWN_TABLE, ptr->real_name, + information_schema_name.str); + DBUG_RETURN(0); + } + ptr->schema_table= schema_table; + } ptr->select_lex= lex->current_select; ptr->cacheable_table= 1; if (use_index_arg) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d07e274b0b7..3c7f1032f51 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1221,6 +1221,12 @@ JOIN::exec() List *curr_fields_list= &fields_list; TABLE *curr_tmp_table= 0; + if ((curr_join->select_lex->options & OPTION_SCHEMA_TABLE) && + get_schema_tables_result(curr_join)) + { + DBUG_VOID_RETURN; + } + /* Create a tmp table if distinct or if the sort is too complicated */ if (need_tmp) { @@ -2129,6 +2135,8 @@ make_join_statistics(JOIN *join,TABLE_LIST *tables,COND *conds, s->dependent= tables->dep_tables; s->key_dependent= 0; + if (tables->schema_table) + table->file->records= 2; s->on_expr_ref= &tables->on_expr; if (*s->on_expr_ref) @@ -7724,7 +7732,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, blob_count,group_null_items; bool using_unique_constraint=0; bool not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS); - char *tmpname,path[FN_REFLEN]; + char *tmpname,path[FN_REFLEN], filename[FN_REFLEN]; byte *pos,*group_buff; uchar *null_flags; Field **reg_field, **from_field, **blob_field; @@ -7746,14 +7754,15 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, temp_pool_slot = bitmap_set_next(&temp_pool); if (temp_pool_slot != MY_BIT_NONE) // we got a slot - sprintf(path, "%s%s_%lx_%i", mysql_tmpdir, tmp_file_prefix, - current_pid, temp_pool_slot); + sprintf(filename, "%s_%lx_%i", tmp_file_prefix, + current_pid, temp_pool_slot); else // if we run out of slots or we are not using tempool - sprintf(path,"%s%s%lx_%lx_%x",mysql_tmpdir,tmp_file_prefix,current_pid, + sprintf(filename,"%s%lx_%lx_%x",tmp_file_prefix,current_pid, thd->thread_id, thd->tmp_table++); if (lower_case_table_names) my_casedn_str(files_charset_info, path); + sprintf(path, "%s%s", mysql_tmpdir, filename); if (group) { @@ -12879,8 +12888,16 @@ void st_table_list::print(THD *thd, String *str) { append_identifier(thd, str, db, db_length); str->append('.'); - append_identifier(thd, str, real_name, real_name_length); - cmp_name= real_name; + if (schema_table) + { + append_identifier(thd, str, alias, strlen(alias)); + cmp_name= alias; + } + else + { + append_identifier(thd, str, real_name, real_name_length); + cmp_name= real_name; + } } if (my_strcasecmp(table_alias_charset, cmp_name, alias)) { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 7043379bf8f..2d27faa0e9c 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -21,6 +21,7 @@ #include "sql_select.h" // For select_describe #include "sql_acl.h" #include "repl_failsafe.h" +#include "sp_head.h" #include #ifdef HAVE_BERKELEY_DB @@ -43,55 +44,6 @@ static int view_store_create_info(THD *thd, TABLE_LIST *table, String *packet); -/* - Report list of databases - A database is a directory in the mysql_data_home directory -*/ - -int -mysqld_show_dbs(THD *thd,const char *wild) -{ - Item_string *field=new Item_string("",0,thd->charset()); - List field_list; - char *end; - List files; - char *file_name; - Protocol *protocol= thd->protocol; - DBUG_ENTER("mysqld_show_dbs"); - - field->name=(char*) thd->alloc(20+ (wild ? (uint) strlen(wild)+4: 0)); - field->max_length=NAME_LEN; - end=strmov(field->name,"Database"); - if (wild && wild[0]) - strxmov(end," (",wild,")",NullS); - field_list.push_back(field); - - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - if (mysql_find_files(thd,&files,NullS,mysql_data_home,wild,1)) - DBUG_RETURN(1); - List_iterator_fast it(files); - - while ((file_name=it++)) - { -#ifndef NO_EMBEDDED_ACCESS_CHECKS - if (thd->master_access & (DB_ACLS | SHOW_DB_ACL) || - acl_get(thd->host, thd->ip, thd->priv_user, file_name,0) || - (grant_option && !check_grant_db(thd, file_name))) -#endif - { - protocol->prepare_for_resend(); - protocol->store(file_name, system_charset_info); - if (protocol->write()) - DBUG_RETURN(-1); - } - } - send_eof(thd); - DBUG_RETURN(0); -} - - /*************************************************************************** List all open tables in a database ***************************************************************************/ @@ -132,70 +84,6 @@ int mysqld_show_open_tables(THD *thd,const char *wild) } -/*************************************************************************** -** List all tables in a database (fast version) -** A table is a .frm file in the current databasedir -***************************************************************************/ - -int mysqld_show_tables(THD *thd, const char *db, const char *wild, - bool show_type) -{ - Item_string *field=new Item_string("",0,thd->charset()); - List field_list; - char path[FN_LEN],*end; - List files; - char *file_name; - Protocol *protocol= thd->protocol; - uint len; - DBUG_ENTER("mysqld_show_tables"); - - field->name=(char*) thd->alloc(20+(uint) strlen(db)+ - (wild ? (uint) strlen(wild)+4:0)); - end=strxmov(field->name,"Tables_in_",db,NullS); - if (wild && wild[0]) - strxmov(end," (",wild,")",NullS); - field->max_length=NAME_LEN; - (void) my_snprintf(path, FN_LEN, "%s/%s", mysql_data_home, db); - end= path + (len= unpack_dirname(path,path)); - len= FN_LEN - len; - field_list.push_back(field); - if (show_type) - field_list.push_back(new Item_empty_string("Table_type", 10)); - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - if (mysql_find_files(thd,&files,db,path,wild,0)) - DBUG_RETURN(-1); - List_iterator_fast it(files); - while ((file_name=it++)) - { - protocol->prepare_for_resend(); - protocol->store(file_name, system_charset_info); - if (show_type) - { - my_snprintf(end, len, "/%s%s", file_name, reg_ext); - switch (mysql_frm_type(path)) - { - case FRMTYPE_ERROR: - protocol->store("ERROR", system_charset_info); - break; - case FRMTYPE_TABLE: - protocol->store("BASE TABLE", system_charset_info); - break; - case FRMTYPE_VIEW: - protocol->store("VIEW", system_charset_info); - break; - default: - DBUG_ASSERT(0); // this should be impossible - } - } - if (protocol->write()) - DBUG_RETURN(-1); - } - send_eof(thd); - DBUG_RETURN(0); -} - /*************************************************************************** ** List all table types supported ***************************************************************************/ @@ -482,211 +370,6 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, } -/*************************************************************************** - Extended version of mysqld_show_tables -***************************************************************************/ - -int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) -{ - Item *item; - List files; - List field_list; - char path[FN_LEN]; - char *file_name; - TABLE *table; - Protocol *protocol= thd->protocol; - TIME time; - int res; - DBUG_ENTER("mysqld_extend_show_tables"); - - (void) sprintf(path,"%s/%s",mysql_data_home,db); - (void) unpack_dirname(path,path); - field_list.push_back(item=new Item_empty_string("Name",NAME_LEN)); - field_list.push_back(item=new Item_empty_string("Engine",10)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Version", (longlong) 0, 21)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("Row_format",10)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Rows",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Avg_row_length",(int32) 0,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Data_length",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Max_data_length",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Index_length",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Data_free",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Auto_increment",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_datetime("Create_time")); - item->maybe_null=1; - field_list.push_back(item=new Item_datetime("Update_time")); - item->maybe_null=1; - field_list.push_back(item=new Item_datetime("Check_time")); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("Collation",32)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("Create_options",255)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("Comment",80)); - item->maybe_null=1; - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - - if (mysql_find_files(thd,&files,db,path,wild,0)) - DBUG_RETURN(-1); - List_iterator_fast it(files); - while ((file_name=it++)) - { - TABLE_LIST table_list; - bzero((char*) &table_list,sizeof(table_list)); - protocol->prepare_for_resend(); - protocol->store(file_name, system_charset_info); - table_list.db=(char*) db; - table_list.real_name= table_list.alias= file_name; - table_list.select_lex= &thd->lex->select_lex; - if (lower_case_table_names) - my_casedn_str(files_charset_info, file_name); - if ((res= open_and_lock_tables(thd, &table_list))) - { - for (uint i=2 ; i < field_list.elements ; i++) - protocol->store_null(); - // Send error to Comment field if possible - if (res < 0) - { - protocol->store(thd->net.last_error, system_charset_info); - thd->clear_error(); - } - else - DBUG_RETURN(1); - } - else if (table_list.view) - { - for (uint i= 2; i < field_list.elements; i++) - protocol->store_null(); - protocol->store("view", system_charset_info); - } - else - { - const char *str; - handler *file= (table= table_list.table)->file; - file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK); - protocol->store(file->table_type(), system_charset_info); - protocol->store((ulonglong) table->frm_version); - str= ((table->db_options_in_use & HA_OPTION_COMPRESS_RECORD) ? - "Compressed" : - (table->db_options_in_use & HA_OPTION_PACK_RECORD) ? - "Dynamic" : "Fixed"); - protocol->store(str, system_charset_info); - protocol->store((ulonglong) file->records); - protocol->store((ulonglong) file->mean_rec_length); - protocol->store((ulonglong) file->data_file_length); - if (file->max_data_file_length) - protocol->store((ulonglong) file->max_data_file_length); - else - protocol->store_null(); - protocol->store((ulonglong) file->index_file_length); - protocol->store((ulonglong) file->delete_length); - if (table->found_next_number_field) - { - table->next_number_field=table->found_next_number_field; - table->next_number_field->reset(); - file->update_auto_increment(); - protocol->store(table->next_number_field->val_int()); - table->next_number_field=0; - } - else - protocol->store_null(); - if (!file->create_time) - protocol->store_null(); - else - { - thd->variables.time_zone->gmt_sec_to_TIME(&time, file->create_time); - protocol->store(&time); - } - if (!file->update_time) - protocol->store_null(); - else - { - thd->variables.time_zone->gmt_sec_to_TIME(&time, file->update_time); - protocol->store(&time); - } - if (!file->check_time) - protocol->store_null(); - else - { - thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time); - protocol->store(&time); - } - str= (table->table_charset ? table->table_charset->name : "default"); - protocol->store(str, system_charset_info); - if (file->table_flags() & HA_HAS_CHECKSUM) - protocol->store((ulonglong)file->checksum()); - else - protocol->store_null(); // Checksum - { - char option_buff[350],*ptr; - ptr=option_buff; - if (table->min_rows) - { - ptr=strmov(ptr," min_rows="); - ptr=longlong10_to_str(table->min_rows,ptr,10); - } - if (table->max_rows) - { - ptr=strmov(ptr," max_rows="); - ptr=longlong10_to_str(table->max_rows,ptr,10); - } - if (table->avg_row_length) - { - ptr=strmov(ptr," avg_row_length="); - ptr=longlong10_to_str(table->avg_row_length,ptr,10); - } - if (table->db_create_options & HA_OPTION_PACK_KEYS) - ptr=strmov(ptr," pack_keys=1"); - if (table->db_create_options & HA_OPTION_NO_PACK_KEYS) - ptr=strmov(ptr," pack_keys=0"); - if (table->db_create_options & HA_OPTION_CHECKSUM) - ptr=strmov(ptr," checksum=1"); - if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE) - ptr=strmov(ptr," delay_key_write=1"); - if (table->row_type != ROW_TYPE_DEFAULT) - ptr=strxmov(ptr, " row_format=", ha_row_type[(uint) table->row_type], - NullS); - if (file->raid_type) - { - char buff[100]; - sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld", - my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE); - ptr=strmov(ptr,buff); - } - protocol->store(option_buff+1, - (ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1) - , system_charset_info); - } - { - char *comment=table->file->update_table_comment(table->comment); - protocol->store(comment, system_charset_info); - if (comment != table->comment) - my_free(comment,MYF(0)); - } - } - close_thread_tables(thd, 0); - if (protocol->write()) - DBUG_RETURN(-1); - } - send_eof(thd); - DBUG_RETURN(0); -} - - /*************************************************************************** ** List all columns in a table_list->real_name ***************************************************************************/ @@ -1046,103 +729,6 @@ mysqld_show_logs(THD *thd) } -int -mysqld_show_keys(THD *thd, TABLE_LIST *table_list) -{ - TABLE *table; - Protocol *protocol= thd->protocol; - DBUG_ENTER("mysqld_show_keys"); - DBUG_PRINT("enter",("db: %s table: %s",table_list->db, - table_list->real_name)); - - if (!(table = open_ltable(thd, table_list, TL_UNLOCK))) - { - send_error(thd); - DBUG_RETURN(1); - } - - List field_list; - Item *item; - field_list.push_back(new Item_empty_string("Table",NAME_LEN)); - field_list.push_back(new Item_return_int("Non_unique",1, MYSQL_TYPE_TINY)); - field_list.push_back(new Item_empty_string("Key_name",NAME_LEN)); - field_list.push_back(new Item_return_int("Seq_in_index",2, MYSQL_TYPE_TINY)); - field_list.push_back(new Item_empty_string("Column_name",NAME_LEN)); - field_list.push_back(item=new Item_empty_string("Collation",1)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("Cardinality",0,21)); - item->maybe_null=1; - field_list.push_back(item=new Item_return_int("Sub_part",3, - MYSQL_TYPE_TINY)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("Packed",10)); - item->maybe_null=1; - field_list.push_back(new Item_empty_string("Null",3)); - field_list.push_back(new Item_empty_string("Index_type",16)); - field_list.push_back(new Item_empty_string("Comment",255)); - item->maybe_null=1; - - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - - KEY *key_info=table->key_info; - table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME); - for (uint i=0 ; i < table->keys ; i++,key_info++) - { - KEY_PART_INFO *key_part= key_info->key_part; - const char *str; - for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) - { - protocol->prepare_for_resend(); - protocol->store(table->table_name, system_charset_info); - protocol->store_tiny((longlong) ((key_info->flags & HA_NOSAME) ? 0 :1)); - protocol->store(key_info->name, system_charset_info); - protocol->store_tiny((longlong) (j+1)); - str=(key_part->field ? key_part->field->field_name : - "?unknown field?"); - protocol->store(str, system_charset_info); - if (table->file->index_flags(i, j, 0) & HA_READ_ORDER) - protocol->store(((key_part->key_part_flag & HA_REVERSE_SORT) ? - "D" : "A"), 1, system_charset_info); - else - protocol->store_null(); /* purecov: inspected */ - KEY *key=table->key_info+i; - if (key->rec_per_key[j]) - { - ha_rows records=(table->file->records / key->rec_per_key[j]); - protocol->store((ulonglong) records); - } - else - protocol->store_null(); - - /* Check if we have a key part that only uses part of the field */ - if (!(key_info->flags & HA_FULLTEXT) && (!key_part->field || - key_part->length != table->field[key_part->fieldnr-1]->key_length())) - protocol->store_tiny((longlong) key_part->length); - else - protocol->store_null(); - protocol->store_null(); // No pack_information yet - - /* Null flag */ - uint flags= key_part->field ? key_part->field->flags : 0; - char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES"); - protocol->store((const char*) pos, system_charset_info); - protocol->store(table->file->index_type(i), system_charset_info); - /* Comment */ - if (!table->keys_in_use.is_set(i)) - protocol->store("disabled",8, system_charset_info); - else - protocol->store("", 0, system_charset_info); - if (protocol->write()) - DBUG_RETURN(1); /* purecov: inspected */ - } - } - send_eof(thd); - DBUG_RETURN(0); -} - - /**************************************************************************** Return only fields for API mysql_list_fields Use "show table wildcard" in mysql instead of this @@ -1816,112 +1402,6 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) Status functions *****************************************************************************/ -static bool write_collation(Protocol *protocol, CHARSET_INFO *cs) -{ - protocol->prepare_for_resend(); - protocol->store(cs->name, system_charset_info); - protocol->store(cs->csname, system_charset_info); - protocol->store_short((longlong) cs->number); - protocol->store((cs->state & MY_CS_PRIMARY) ? "Yes" : "",system_charset_info); - protocol->store((cs->state & MY_CS_COMPILED)? "Yes" : "",system_charset_info); - protocol->store_short((longlong) cs->strxfrm_multiply); - return protocol->write(); -} - -int mysqld_show_collations(THD *thd, const char *wild) -{ - char buff[8192]; - String packet2(buff,sizeof(buff),thd->charset()); - List field_list; - CHARSET_INFO **cs; - Protocol *protocol= thd->protocol; - - DBUG_ENTER("mysqld_show_charsets"); - - field_list.push_back(new Item_empty_string("Collation",30)); - field_list.push_back(new Item_empty_string("Charset",30)); - field_list.push_back(new Item_return_int("Id",11, FIELD_TYPE_SHORT)); - field_list.push_back(new Item_empty_string("Default",30)); - field_list.push_back(new Item_empty_string("Compiled",30)); - field_list.push_back(new Item_return_int("Sortlen",3, FIELD_TYPE_SHORT)); - - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - - for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) - { - CHARSET_INFO **cl; - if (!cs[0] || !(cs[0]->state & MY_CS_AVAILABLE) || - !(cs[0]->state & MY_CS_PRIMARY)) - continue; - for ( cl= all_charsets; cl < all_charsets+255 ;cl ++) - { - if (!cl[0] || !(cl[0]->state & MY_CS_AVAILABLE) || - !my_charset_same(cs[0],cl[0])) - continue; - if (!(wild && wild[0] && - wild_case_compare(system_charset_info,cl[0]->name,wild))) - { - if (write_collation(protocol, cl[0])) - goto err; - } - } - } - send_eof(thd); - DBUG_RETURN(0); -err: - DBUG_RETURN(1); -} - -static bool write_charset(Protocol *protocol, CHARSET_INFO *cs) -{ - protocol->prepare_for_resend(); - protocol->store(cs->csname, system_charset_info); - protocol->store(cs->comment ? cs->comment : "", system_charset_info); - protocol->store(cs->name, system_charset_info); - protocol->store_short((longlong) cs->mbmaxlen); - return protocol->write(); -} - -int mysqld_show_charsets(THD *thd, const char *wild) -{ - char buff[8192]; - String packet2(buff,sizeof(buff),thd->charset()); - List field_list; - CHARSET_INFO **cs; - Protocol *protocol= thd->protocol; - - DBUG_ENTER("mysqld_show_charsets"); - - field_list.push_back(new Item_empty_string("Charset",30)); - field_list.push_back(new Item_empty_string("Description",60)); - field_list.push_back(new Item_empty_string("Default collation",60)); - field_list.push_back(new Item_return_int("Maxlen",3, FIELD_TYPE_SHORT)); - - if (protocol->send_fields(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(1); - - for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) - { - if (cs[0] && (cs[0]->state & MY_CS_PRIMARY) && - (cs[0]->state & MY_CS_AVAILABLE) && - !(wild && wild[0] && - wild_case_compare(system_charset_info,cs[0]->csname,wild))) - { - if (write_charset(protocol, cs[0])) - goto err; - } - } - send_eof(thd); - DBUG_RETURN(0); -err: - DBUG_RETURN(1); -} - - - int mysqld_show(THD *thd, const char *wild, show_var_st *variables, enum enum_var_type value_type, pthread_mutex_t *mutex, @@ -2261,6 +1741,1662 @@ void calc_sum_of_all_status(STATUS_VAR *to) } +LEX_STRING *make_lex_string(THD *thd, LEX_STRING *lex_str, + const char* str, uint length, + bool allocate_lex_string) +{ + MEM_ROOT *mem= thd->mem_root; + if (allocate_lex_string) + lex_str= (LEX_STRING *)thd->alloc(sizeof(LEX_STRING)); + lex_str->str= strmake_root(mem, str, length); + lex_str->length= length; + return lex_str; +} + + +/* INFORMATION_SCHEMA name */ +LEX_STRING information_schema_name= {(char*)"information_schema", 18}; +extern ST_SCHEMA_TABLE schema_tables[]; + +typedef struct st_index_field_values +{ + const char *db_value, *table_value; +} INDEX_FIELD_VALUES; + + +void get_index_field_values(LEX *lex, INDEX_FIELD_VALUES *index_field_values) +{ + const char *wild= lex->wild ? lex->wild->ptr() : NullS; + switch (lex->orig_sql_command) { + case SQLCOM_SHOW_DATABASES: + index_field_values->db_value= wild; + break; + case SQLCOM_SHOW_TABLES: + case SQLCOM_SHOW_TABLE_STATUS: + index_field_values->db_value= lex->current_select->db; + index_field_values->table_value= wild; + break; + default: + index_field_values->db_value= NullS; + index_field_values->table_value= NullS; + break; + } +} + + +int make_table_list(THD *thd, SELECT_LEX *sel, + char *db, char *table) +{ + Table_ident *table_ident; + LEX_STRING ident_db, ident_table; + ident_db.str= db; + ident_db.length= strlen(db); + ident_table.str= table; + ident_table.length= strlen(table); + table_ident= new Table_ident(thd, ident_db, ident_table, 1); + sel->init_query(); + if(!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ, + (List *) 0, (List *) 0)) + return 1; + return 0; +} + + +bool uses_only_table_name_fields(Item *item, TABLE_LIST *table) +{ + if (item->type() == Item::FUNC_ITEM) + { + Item_func *item_func= (Item_func*)item; + Item **child; + Item **item_end= (item_func->arguments()) + item_func->argument_count(); + for (child= item_func->arguments(); child != item_end; child++) + if (!uses_only_table_name_fields(*child, table)) + return 0; + return 1; + } + else if (item->type() == Item::FIELD_ITEM) + { + Item_field *item_field= (Item_field*)item; + CHARSET_INFO *cs= system_charset_info; + ST_SCHEMA_TABLE *schema_table= table->schema_table; + ST_FIELD_INFO *field_info= schema_table->fields_info; + const char *field_name1= field_info[schema_table->idx_field1].field_name; + const char *field_name2= field_info[schema_table->idx_field2].field_name; + if(table->table != item_field->field->table || + (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1), + (uchar *) item_field->field_name, + strlen(item_field->field_name)) && + cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2), + (uchar *) item_field->field_name, + strlen(item_field->field_name)))) + return 0; + else + return 1; + } + else + return 1; +} + + +static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table) +{ + if (!cond) + return (COND*) 0; + if (cond->type() == Item::COND_ITEM) + { + if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC) + { + /* Create new top level AND item */ + Item_cond_and *new_cond=new Item_cond_and; + if (!new_cond) + return (COND*) 0; + List_iterator li(*((Item_cond*) cond)->argument_list()); + Item *item; + while ((item=li++)) + { + Item *fix= make_cond_for_info_schema(item, table); + if (fix) + new_cond->argument_list()->push_back(fix); + } + switch (new_cond->argument_list()->elements) { + case 0: + return (COND*) 0; + case 1: + return new_cond->argument_list()->head(); + default: + new_cond->quick_fix_field(); + return new_cond; + } + } + else + { // Or list + Item_cond_or *new_cond=new Item_cond_or; + if (!new_cond) + return (COND*) 0; + List_iterator li(*((Item_cond*) cond)->argument_list()); + Item *item; + while ((item=li++)) + { + Item *fix=make_cond_for_info_schema(item, table); + if (!fix) + return (COND*) 0; + new_cond->argument_list()->push_back(fix); + } + new_cond->quick_fix_field(); + new_cond->top_level_item(); + return new_cond; + } + } + + if (!uses_only_table_name_fields(cond, table)) + return (COND*) 0; + return cond; +} + + +int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) +{ + LEX *lex= thd->lex; + TABLE *table= tables->table; + SELECT_LEX *select_lex= &lex->select_lex; + ST_SCHEMA_TABLE *schema_table= tables->schema_table; + DBUG_ENTER("fill_schema_tables"); + + SELECT_LEX *lsel= tables->schema_select_lex; + if (lsel) + { + TABLE *old_open_tables= thd->open_tables; + TABLE_LIST *show_table_list= (TABLE_LIST*) lsel->table_list.first; + lex->all_selects_list= lsel; + int res= open_and_lock_tables(thd, show_table_list); + if (schema_table->process_table(thd, show_table_list, + table, res, show_table_list->db, + show_table_list->real_name)) + { + DBUG_RETURN(1); + } + close_thread_tables(thd, 0, 0, old_open_tables); + show_table_list->table= 0; + lex->all_selects_list= select_lex; + DBUG_RETURN(0); + } + + SELECT_LEX sel; + INDEX_FIELD_VALUES idx_field_vals; + char path[FN_REFLEN], *end, *base_name, *file_name; + uint len; + List bases; + lex->all_selects_list= &sel; + enum enum_schema_tables schema_table_idx= + (enum enum_schema_tables) (schema_table - &schema_tables[0]); + thr_lock_type lock_type= TL_UNLOCK; + if (schema_table_idx == SCH_TABLES) + lock_type= TL_READ; + get_index_field_values(lex, &idx_field_vals); + if (mysql_find_files(thd, &bases, NullS, mysql_data_home, + idx_field_vals.db_value, 1)) + return 1; + List_iterator_fast it(bases); + COND *partial_cond= make_cond_for_info_schema(cond, tables); + while ((base_name=it++) || + /* + generate error for non existing database. + (to save old behaviour for SHOW TABLES FROM db) + */ + ((lex->orig_sql_command == SQLCOM_SHOW_TABLES || + lex->orig_sql_command == SQLCOM_SHOW_TABLE_STATUS) && + (base_name= select_lex->db) && !bases.elements)) + { +#ifndef NO_EMBEDDED_ACCESS_CHECKS + if (!check_access(thd,SELECT_ACL, base_name, &thd->col_access,0,1) || + thd->master_access & (DB_ACLS | SHOW_DB_ACL) || + acl_get(thd->host, thd->ip, thd->priv_user, base_name,0) || + (grant_option && !check_grant_db(thd, base_name))) +#endif + { + List files; + (void) sprintf(path,"%s/%s",mysql_data_home,base_name); + end= path + (len= unpack_dirname(path,path)); + len= FN_LEN - len; + if (mysql_find_files(thd, &files, base_name, + path, idx_field_vals.table_value, 0)) + DBUG_RETURN(1); + + List_iterator_fast it(files); + while ((file_name=it++)) + { + restore_record(table, default_values); + table->field[schema_table->idx_field1]-> + store(base_name, strlen(base_name), system_charset_info); + table->field[schema_table->idx_field2]-> + store(file_name, strlen(file_name),system_charset_info); + if (!partial_cond || partial_cond->val_int()) + { + if (schema_table_idx == SCH_TABLE_NAMES) + { + if (lex->verbose || lex->orig_sql_command == SQLCOM_END) + { + my_snprintf(end, len, "/%s%s", file_name, reg_ext); + switch (mysql_frm_type(path)) + { + case FRMTYPE_ERROR: + table->field[3]->store("ERROR", 5, system_charset_info); + break; + case FRMTYPE_TABLE: + table->field[3]->store("BASE TABLE", 10, system_charset_info); + break; + case FRMTYPE_VIEW: + table->field[3]->store("VIEW", 4, system_charset_info); + break; + default: + DBUG_ASSERT(0); + } + } + table->file->write_row(table->record[0]); + } + else + { + int res; + TABLE *old_open_tables= thd->open_tables; + if (make_table_list(thd, &sel, base_name, file_name)) + DBUG_RETURN(1); + TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first; + show_table_list->lock_type= lock_type; + res= open_and_lock_tables(thd, show_table_list); + if (schema_table->process_table(thd, show_table_list, table, + res, base_name, file_name)) + { + DBUG_RETURN(1); + } + close_thread_tables(thd, 0, 0, old_open_tables); + } + } + } + } + } + lex->all_selects_list= select_lex; + DBUG_RETURN(0); +} + + +int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) +{ + char path[FN_REFLEN],*end; + bool found_libchar; + INDEX_FIELD_VALUES idx_field_vals; + List files; + char *file_name; + uint length; + HA_CREATE_INFO create; + TABLE *table= tables->table; + + get_index_field_values(thd->lex, &idx_field_vals); + if (mysql_find_files(thd, &files, NullS, mysql_data_home, + idx_field_vals.db_value, 1)) + return 1; + List_iterator_fast it(files); + while ((file_name=it++)) + { +#ifndef NO_EMBEDDED_ACCESS_CHECKS + if (thd->master_access & (DB_ACLS | SHOW_DB_ACL) || + acl_get(thd->host, thd->ip, thd->priv_user, file_name,0) || + (grant_option && !check_grant_db(thd, file_name))) +#endif + { + (void) sprintf(path,"%s/%s",mysql_data_home, file_name); + length=unpack_dirname(path,path); // Convert if not unix + found_libchar= 0; + if (length && path[length-1] == FN_LIBCHAR) + { + found_libchar= 1; + path[length-1]=0; // remove ending '\' + } + + if (found_libchar) + path[length-1]= FN_LIBCHAR; + strmov(path+length, MY_DB_OPT_FILE); + load_db_opt(thd, path, &create); + restore_record(table, default_values); + table->field[1]->store(file_name, strlen(file_name), system_charset_info); + table->field[2]->store(create.default_table_charset->name, + strlen(create.default_table_charset->name), + system_charset_info); + table->file->write_row(table->record[0]); + } + } + return 0; +} + + +int get_schema_tables_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, const char *file_name) +{ + const char *tmp_buff; + TIME time; + CHARSET_INFO *cs= system_charset_info; + + DBUG_ENTER("get_schema_tables_record"); + restore_record(table, default_values); + if (res > 0) + { + DBUG_RETURN(1); + } + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(file_name, strlen(file_name), cs); + if (res < 0 || tables->view) + { + table->field[3]->store("VIEW", 4, cs); + table->field[20]->store("view", 4, cs); + if (res) + thd->clear_error(); + } + else + { + TABLE *show_table= tables->table; + handler *file= show_table->file; + file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK); + table->field[3]->store("BASE TABLE", 10, cs); + for (int i= 4; i < 20; i++) + { + if ((i > 12 && i < 17) || i == 18) + continue; + table->field[i]->set_notnull(); + } + tmp_buff= file->table_type(); + table->field[4]->store(tmp_buff, strlen(tmp_buff), cs); + table->field[5]->store((longlong) show_table->frm_version); + tmp_buff= ((show_table->db_options_in_use & + HA_OPTION_COMPRESS_RECORD) ? "Compressed" : + (show_table->db_options_in_use & HA_OPTION_PACK_RECORD) ? + "Dynamic" : "Fixed"); + table->field[6]->store(tmp_buff, strlen(tmp_buff), cs); + table->field[7]->store((longlong) file->records); + table->field[8]->store((longlong) file->mean_rec_length); + table->field[9]->store((longlong) file->data_file_length); + if (file->max_data_file_length) + { + table->field[10]->store((longlong) file->max_data_file_length); + } + table->field[11]->store((longlong) file->index_file_length); + table->field[12]->store((longlong) file->delete_length); + if (table->found_next_number_field) + { + show_table->next_number_field=show_table->found_next_number_field; + show_table->next_number_field->reset(); + file->update_auto_increment(); + table->field[13]->store((longlong) show_table-> + next_number_field->val_int()); + table->field[13]->set_notnull(); + show_table->next_number_field=0; + } + if (file->create_time) + { + thd->variables.time_zone->gmt_sec_to_TIME(&time, + file->create_time); + table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + table->field[14]->set_notnull(); + } + if (file->update_time) + { + thd->variables.time_zone->gmt_sec_to_TIME(&time, + file->update_time); + table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + table->field[15]->set_notnull(); + } + if (file->check_time) + { + thd->variables.time_zone->gmt_sec_to_TIME(&time, file->check_time); + table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + table->field[16]->set_notnull(); + } + tmp_buff= (show_table->table_charset ? show_table-> + table_charset->name : "default"); + table->field[17]->store(tmp_buff, strlen(tmp_buff), cs); + if (file->table_flags() & HA_HAS_CHECKSUM) + { + table->field[18]->store((longlong) file->checksum()); + table->field[18]->set_notnull(); + } + + char option_buff[350],*ptr; + ptr=option_buff; + if (show_table->min_rows) + { + ptr=strmov(ptr," min_rows="); + ptr=longlong10_to_str(show_table->min_rows,ptr,10); + } + if (show_table->max_rows) + { + ptr=strmov(ptr," max_rows="); + ptr=longlong10_to_str(show_table->max_rows,ptr,10); + } + if (show_table->avg_row_length) + { + ptr=strmov(ptr," avg_row_length="); + ptr=longlong10_to_str(show_table->avg_row_length,ptr,10); + } + if (show_table->db_create_options & HA_OPTION_PACK_KEYS) + ptr=strmov(ptr," pack_keys=1"); + if (show_table->db_create_options & HA_OPTION_NO_PACK_KEYS) + ptr=strmov(ptr," pack_keys=0"); + if (show_table->db_create_options & HA_OPTION_CHECKSUM) + ptr=strmov(ptr," checksum=1"); + if (show_table->db_create_options & HA_OPTION_DELAY_KEY_WRITE) + ptr=strmov(ptr," delay_key_write=1"); + if (show_table->row_type != ROW_TYPE_DEFAULT) + ptr=strxmov(ptr, " row_format=", + ha_row_type[(uint) show_table->row_type], + NullS); + if (file->raid_type) + { + char buff[100]; + sprintf(buff," raid_type=%s raid_chunks=%d raid_chunksize=%ld", + my_raid_type(file->raid_type), file->raid_chunks, + file->raid_chunksize/RAID_BLOCK_SIZE); + ptr=strmov(ptr,buff); + } + table->field[19]->store(option_buff+1, + (ptr == option_buff ? 0 : + (uint) (ptr-option_buff)-1), cs); + + char *comment= show_table->file-> + update_table_comment(show_table->comment); + table->field[20]->store(comment, strlen(comment), cs); + if (comment != show_table->comment) + my_free(comment,MYF(0)); + } + table->file->write_row(table->record[0]); + DBUG_RETURN(0); +} + + +int get_schema_column_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, const char *file_name) +{ + TIME time; + const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; + CHARSET_INFO *cs= system_charset_info; + DBUG_ENTER("get_schema_column_record"); + if (res) + { + DBUG_RETURN(1); + } + + TABLE *show_table= tables->table; + handler *file= show_table->file; + file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + restore_record(show_table, default_values); + Field **ptr,*field; + int count= 0; + for (ptr=show_table->field; (field= *ptr) ; ptr++) + { + if (!wild || !wild[0] || + !wild_case_compare(system_charset_info, field->field_name,wild)) + { + uint tmp_length; + char *tmp_buff; + byte *pos; + uint flags=field->flags; + char tmp[MAX_FIELD_WIDTH]; + char tmp1[MAX_FIELD_WIDTH]; + String type(tmp,sizeof(tmp), system_charset_info); + char tmp_buffer[128]; + count++; + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(file_name, strlen(file_name), cs); + table->field[3]->store(field->field_name, strlen(field->field_name), + cs); + table->field[4]->store((longlong) count); + field->sql_type(type); + table->field[11]->store(type.ptr(), type.length(), cs); + tmp_buff= strchr(type.ptr(),'('); + table->field[5]->store(type.ptr(), + (tmp_buff ? tmp_buff - type.ptr() : + type.length()), cs); + + if (show_table->timestamp_field == field && + field->unireg_check != Field::TIMESTAMP_UN_FIELD) + { + table->field[15]->store("CURRENT_TIMESTAMP", 17, cs); + table->field[15]->set_notnull(); + } + else if (field->unireg_check != Field::NEXT_NUMBER && + !field->is_null() && + !(field->flags & NO_DEFAULT_VALUE_FLAG)) + { + String def(tmp1,sizeof(tmp1), cs); + type.set(tmp, sizeof(tmp), field->charset()); + field->val_str(&type); + uint dummy_errors; + def.copy(type.ptr(), type.length(), type.charset(), cs, &dummy_errors); + table->field[15]->store(def.ptr(), def.length(), def.charset()); + table->field[15]->set_notnull(); + } + else if (field->unireg_check == Field::NEXT_NUMBER || + field->maybe_null()) + table->field[15]->set_null(); // Null as default + else + { + table->field[15]->store("",0, cs); + table->field[15]->set_notnull(); + } + + pos=(byte*) ((flags & NOT_NULL_FLAG) && + field->type() != FIELD_TYPE_TIMESTAMP ? + "" : "YES"); + table->field[13]->store((const char*) pos, + strlen((const char*) pos), cs); + if (field->has_charset()) + { + table->field[6]->store((longlong) field->field_length/ + field->charset()->mbmaxlen); + } + table->field[7]->store((longlong) field->field_length); + table->field[8]->store((longlong) field->pack_length()); + table->field[9]->store((longlong) field->decimals()); + if (field->has_charset()) + { + pos=(byte*) field->charset()->csname; + table->field[10]->store((const char*) pos, + strlen((const char*) pos), cs); + table->field[10]->set_notnull(); + pos=(byte*) field->charset()->name; + table->field[12]->store((const char*) pos, + strlen((const char*) pos), cs); + table->field[12]->set_notnull(); + } + pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" : + (field->flags & UNIQUE_KEY_FLAG) ? "UNI" : + (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":""); + table->field[14]->store((const char*) pos, + strlen((const char*) pos), cs); + char *end=tmp; + if (field->unireg_check == Field::NEXT_NUMBER) + end=strmov(tmp,"auto_increment"); + table->field[16]->store(tmp, (uint) (end-tmp), cs); + if (thd->lex->verbose) + { + end=tmp; +#ifndef NO_EMBEDDED_ACCESS_CHECKS + uint col_access; + check_access(thd,SELECT_ACL | EXTRA_ACL, base_name, + &tables->grant.privilege, 0, 0); + col_access= get_column_grant(thd, &tables->grant, tables->db, + tables->real_name, + field->field_name) & COL_ACLS; + for (uint bitnr=0; col_access ; col_access>>=1,bitnr++) + { + if (col_access & 1) + { + *end++=','; + end=strmov(end,grant_types.type_names[bitnr]); + } + } +#else + end=strmov(end,""); +#endif + table->field[17]->store(tmp+1,end == tmp ? 0 : (uint) (end-tmp-1), cs); + table->field[18]->store(field->comment.str, field->comment.length, cs); + } + table->file->write_row(table->record[0]); + } + } + DBUG_RETURN(0); +} + + + +int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond) +{ + CHARSET_INFO **cs; + const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; + TABLE *table= tables->table; + CHARSET_INFO *scs= system_charset_info; + for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) + { + CHARSET_INFO *tmp_cs= cs[0]; + if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && + (tmp_cs->state & MY_CS_AVAILABLE) && + !(wild && wild[0] && + wild_case_compare(scs, tmp_cs->csname,wild))) + { + restore_record(table, default_values); + table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs); + table->field[1]->store(tmp_cs->comment ? tmp_cs->comment : "", + strlen(tmp_cs->comment ? tmp_cs->comment : ""), + scs); + table->field[2]->store(tmp_cs->name, strlen(tmp_cs->name), scs); + table->field[3]->store((longlong) tmp_cs->mbmaxlen); + table->file->write_row(table->record[0]); + } + } + return 0; +} + + +int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond) +{ + CHARSET_INFO **cs; + const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; + TABLE *table= tables->table; + CHARSET_INFO *scs= system_charset_info; + for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) + { + CHARSET_INFO **cl; + CHARSET_INFO *tmp_cs= cs[0]; + if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || + !(tmp_cs->state & MY_CS_PRIMARY)) + continue; + for ( cl= all_charsets; cl < all_charsets+255 ;cl ++) + { + CHARSET_INFO *tmp_cl= cl[0]; + if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || + !my_charset_same(tmp_cs, tmp_cl)) + continue; + if (!(wild && wild[0] && + wild_case_compare(scs, tmp_cl->name,wild))) + { + const char *tmp_buff; + restore_record(table, default_values); + table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs); + table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs); + table->field[2]->store((longlong) tmp_cl->number); + tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : ""; + table->field[3]->store(tmp_buff, strlen(tmp_buff), scs); + tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : ""; + table->field[4]->store(tmp_buff, strlen(tmp_buff), scs); + table->field[5]->store((longlong) tmp_cl->strxfrm_multiply); + table->file->write_row(table->record[0]); + } + } + } + return 0; +} + + +int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond) +{ + CHARSET_INFO **cs; + const char *wild= NullS; + TABLE *table= tables->table; + CHARSET_INFO *scs= system_charset_info; + for ( cs= all_charsets ; cs < all_charsets+255 ; cs++ ) + { + CHARSET_INFO **cl; + CHARSET_INFO *tmp_cs= cs[0]; + if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || + !(tmp_cs->state & MY_CS_PRIMARY)) + continue; + for ( cl= all_charsets; cl < all_charsets+255 ;cl ++) + { + CHARSET_INFO *tmp_cl= cl[0]; + if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || + !my_charset_same(tmp_cs,tmp_cl)) + continue; + restore_record(table, default_values); + table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs); + table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs); + table->file->write_row(table->record[0]); + } + } + return 0; +} + + +void store_schema_proc(THD *thd, TABLE *table, + TABLE *proc_table, + const char *wild) +{ + String tmp_string; + TIME time; + LEX *lex= thd->lex; + CHARSET_INFO *cs= system_charset_info; + restore_record(table, default_values); + if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC && + proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE || + lex->orig_sql_command == SQLCOM_SHOW_STATUS_FUNC && + proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION || + lex->orig_sql_command == SQLCOM_END) + { + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[1], &tmp_string); + if (!wild || !wild[0] || !wild_compare(tmp_string.ptr(), wild, 0)) + { + table->field[3]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[0], &tmp_string); + table->field[2]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[2], &tmp_string); + table->field[4]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[3], &tmp_string); + table->field[0]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[5], &tmp_string); + table->field[11]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[6], &tmp_string); + table->field[10]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[7], &tmp_string); + table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[9], &tmp_string); + table->field[6]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[10], &tmp_string); + table->field[8]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[11], &tmp_string); + table->field[5]->store(tmp_string.ptr(), tmp_string.length(), cs); + bzero((char *)&time, sizeof(time)); + ((Field_timestamp *) proc_table->field[12])->get_time(&time); + table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + bzero((char *)&time, sizeof(time)); + ((Field_timestamp *) proc_table->field[13])->get_time(&time); + table->field[13]->store_time(&time, MYSQL_TIMESTAMP_DATETIME); + get_field(thd->mem_root, proc_table->field[14], &tmp_string); + table->field[16]->store(tmp_string.ptr(), tmp_string.length(), cs); + tmp_string.length(0); + get_field(thd->mem_root, proc_table->field[15], &tmp_string); + table->field[17]->store(tmp_string.ptr(), tmp_string.length(), cs); + table->field[7]->store("SQL", 3, cs); + table->field[9]->store("SQL", 3, cs); + table->file->write_row(table->record[0]); + } + } +} + + +int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond) +{ + TABLE *proc_table; + TABLE_LIST proc_tables; + const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; + int res= 0; + TABLE *table= tables->table, *old_open_tables= thd->open_tables; + DBUG_ENTER("fill_schema_proc"); + + bzero((char*) &proc_tables,sizeof(proc_tables)); + proc_tables.db= (char*) "mysql"; + proc_tables.real_name= proc_tables.alias= (char*) "proc"; + proc_tables.lock_type= TL_READ; + if (!(proc_table= open_ltable(thd, &proc_tables, TL_READ))) + { + DBUG_RETURN(1); + } + proc_table->file->ha_index_init(0); + if ((res= proc_table->file->index_first(proc_table->record[0]))) + { + res= (res == HA_ERR_END_OF_FILE) ? 0 : 1; + goto err; + } + store_schema_proc(thd, table, proc_table, wild); + while (!proc_table->file->index_next(proc_table->record[0])) + store_schema_proc(thd, table, proc_table, wild); + +err: + proc_table->file->ha_index_end(); + close_thread_tables(thd, 0, 0, old_open_tables); + DBUG_RETURN(res); +} + + +int get_schema_stat_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, const char *file_name) +{ + CHARSET_INFO *cs= system_charset_info; + DBUG_ENTER("get_schema_stat_record"); + if (!res) + { + TABLE *show_table= tables->table; + KEY *key_info=show_table->key_info; + show_table->file->info(HA_STATUS_VARIABLE | + HA_STATUS_NO_LOCK | + HA_STATUS_TIME); + for (uint i=0 ; i < show_table->keys ; i++,key_info++) + { + KEY_PART_INFO *key_part= key_info->key_part; + const char *str; + for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) + { + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(file_name, strlen(file_name), cs); + table->field[3]->store((longlong) ((key_info->flags & + HA_NOSAME) ? 0 :1)); + table->field[4]->store(base_name, strlen(base_name), cs); + table->field[5]->store(key_info->name, strlen(key_info->name), cs); + table->field[6]->store((longlong) (j+1)); + str=(key_part->field ? key_part->field->field_name : + "?unknown field?"); + table->field[7]->store(str, strlen(str), cs); + if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER) + { + table->field[8]->store(((key_part->key_part_flag & + HA_REVERSE_SORT) ? + "D" : "A"), 1, cs); + table->field[8]->set_notnull(); + } + KEY *key=show_table->key_info+i; + if (key->rec_per_key[j]) + { + ha_rows records=(show_table->file->records / + key->rec_per_key[j]); + table->field[9]->store((longlong) records); + table->field[9]->set_notnull(); + } + if (!(key_info->flags & HA_FULLTEXT) && + (!key_part->field || + key_part->length != + show_table->field[key_part->fieldnr-1]->key_length())) + { + table->field[10]->store((longlong) key_part->length); + table->field[10]->set_notnull(); + } + uint flags= key_part->field ? key_part->field->flags : 0; + const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES"); + table->field[12]->store(pos, strlen(pos), cs); + pos= show_table->file->index_type(i); + table->field[13]->store(pos, strlen(pos), cs); + if (!show_table->keys_in_use.is_set(i)) + table->field[14]->store("disabled", 8, cs); + else + table->field[14]->store("", 0, cs); + table->field[14]->set_notnull(); + table->file->write_row(table->record[0]); + } + } + } + DBUG_RETURN(0); +} + + +int get_schema_views_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, const char *file_name) +{ + CHARSET_INFO *cs= system_charset_info; + DBUG_ENTER("get_schema_views_record"); + if (!res) + { + if (tables->view) + { + restore_record(table, default_values); + table->field[1]->store(tables->view_db.str, tables->view_db.length, cs); + table->field[2]->store(tables->view_name.str,tables->view_name.length,cs); + table->field[3]->store(tables->query.str, tables->query.length, cs); + table->field[4]->store("NONE", 4, cs); + if (tables->updatable_view) + table->field[5]->store("YES", 3, cs); + else + table->field[5]->store("NO", 2, cs); + table->file->write_row(table->record[0]); + } + } + DBUG_RETURN(0); +} + + +int get_schema_constarints_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, const char *file_name) +{ + CHARSET_INFO *cs= system_charset_info; + DBUG_ENTER("get_schema_constarints_record"); + if (!res) + { + List f_key_list; + TABLE *show_table= tables->table; + KEY *key_info=show_table->key_info; + uint primary_key= show_table->primary_key; + show_table->file->info(HA_STATUS_VARIABLE | + HA_STATUS_NO_LOCK | + HA_STATUS_TIME); + for (uint i=0 ; i < show_table->keys ; i++, key_info++) + { + if (i != primary_key && !(key_info->flags & HA_NOSAME)) + continue; + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(key_info->name, strlen(key_info->name), cs); + table->field[3]->store(base_name, strlen(base_name), cs); + table->field[4]->store(file_name, strlen(file_name), cs); + if (i == primary_key && !strcmp(key_info->name, primary_key_name)) + table->field[5]->store("PRIMARY", 7, cs); + else if (key_info->flags & HA_NOSAME) + table->field[5]->store("UNIQUE", 6, cs); + table->file->write_row(table->record[0]); + } + + show_table->file->get_foreign_key_list(thd, &f_key_list); + FOREIGN_KEY_INFO *f_key_info; + List_iterator_fast it(f_key_list); + while ((f_key_info=it++)) + { + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(f_key_info->forein_id->str, + f_key_info->forein_id->length, cs); + table->field[3]->store(base_name, strlen(base_name), cs); + table->field[4]->store(file_name, strlen(file_name), cs); + table->field[5]->store("FOREIGN", 7, system_charset_info); + table->field[6]->store(f_key_info->constraint_method->str, + f_key_info->constraint_method->length, cs); + table->field[6]->set_notnull(); + table->file->write_row(table->record[0]); + } + } + DBUG_RETURN(0); +} + + +int get_schema_key_column_usage_record(THD *thd, struct st_table_list *tables, + TABLE *table, int res, + const char *base_name, + const char *file_name) +{ + DBUG_ENTER("get_schema_key_column_usage_record"); + CHARSET_INFO *cs= system_charset_info; + if (!res) + { + List f_key_list; + TABLE *show_table= tables->table; + KEY *key_info=show_table->key_info; + uint primary_key= show_table->primary_key; + show_table->file->info(HA_STATUS_VARIABLE | + HA_STATUS_NO_LOCK | + HA_STATUS_TIME); + for (uint i=0 ; i < show_table->keys ; i++, key_info++) + { + if (i != primary_key && !(key_info->flags & HA_NOSAME)) + continue; + uint f_idx= 0; + KEY_PART_INFO *key_part= key_info->key_part; + for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) + { + uint f_idx= 0; + if (key_part->field) + { + f_idx++; + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(key_info->name, strlen(key_info->name), cs); + table->field[3]->store(base_name, strlen(base_name), cs); + table->field[4]->store(file_name, strlen(file_name), cs); + table->field[5]->store(key_part->field->field_name, + strlen(key_part->field->field_name), cs); + table->field[6]->store((longlong) f_idx); + table->file->write_row(table->record[0]); + } + } + } + + show_table->file->get_foreign_key_list(thd, &f_key_list); + FOREIGN_KEY_INFO *f_key_info; + List_iterator_fast it(f_key_list); + while ((f_key_info= it++)) + { + LEX_STRING *f_info, *r_info; + List_iterator_fast it(f_key_info->foreign_fields), + it1(f_key_info->referenced_fields); + uint f_idx= 0; + while ((f_info= it++)) + { + r_info= it1++; + f_idx++; + restore_record(table, default_values); + table->field[1]->store(base_name, strlen(base_name), cs); + table->field[2]->store(f_key_info->forein_id->str, + f_key_info->forein_id->length, cs); + table->field[3]->store(base_name, strlen(base_name), cs); + table->field[4]->store(file_name, strlen(file_name), cs); + table->field[5]->store(f_info->str, f_info->length, cs); + table->field[6]->store((longlong) f_idx); + table->field[7]->store(f_key_info->referenced_db->str, + f_key_info->referenced_db->length, cs); + table->field[7]->set_notnull(); + table->field[8]->store(f_key_info->referenced_table->str, + f_key_info->referenced_table->length, cs); + table->field[8]->set_notnull(); + table->field[9]->store(r_info->str, r_info->length, cs); + table->field[9]->set_notnull(); + table->file->write_row(table->record[0]); + } + } + } + DBUG_RETURN(0); +} + + +/* + Find schema_tables elment by name + + SYNOPSIS + find_schema_table() + thd thread handler + table_name table name + + RETURN + 0 table not found + # pointer to 'shema_tables' element +*/ + +ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name) +{ + ST_SCHEMA_TABLE *schema_table= schema_tables; + for ( ; schema_table->table_name; schema_table++) + { + if (!my_strcasecmp(system_charset_info, + schema_table->table_name, + table_name)) + return schema_table; + } + return 0; +} + + +ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx) +{ + return &schema_tables[schema_table_idx]; +} + + +/* + Create information_schema table using schema_table data + + SYNOPSIS + create_schema_table() + thd thread handler + schema_table pointer to 'shema_tables' element + + RETURN + # Pointer to created table + 0 Can't create table +*/ + +TABLE *create_schema_table(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + int field_count= 0; + Item *item; + TABLE *table; + List field_list; + ST_FIELD_INFO *fields_info= schema_table->fields_info; + DBUG_ENTER("create_schema_table"); + + for ( ; fields_info->field_name; fields_info++) + { + switch (fields_info->field_type) { + case MYSQL_TYPE_LONG: + if (!(item= new Item_int(fields_info->field_name, + fields_info->value, + fields_info->field_length))) + { + DBUG_RETURN(0); + } + break; + case MYSQL_TYPE_TIMESTAMP: + if (!(item=new Item_datetime(fields_info->field_name))) + { + DBUG_RETURN(0); + } + break; + default: + CHARSET_INFO *cs= system_charset_info; + if (fields_info->utf8) + cs= thd->charset(); + if (!(item= new Item_string("", fields_info->field_length, cs))) + { + DBUG_RETURN(0); + } + item->set_name(fields_info->field_name, + strlen(fields_info->field_name), cs); + break; + } + field_list.push_back(item); + item->maybe_null= fields_info->maybe_null; + field_count++; + } + TMP_TABLE_PARAM *tmp_table_param = + (TMP_TABLE_PARAM*) (thd->calloc(sizeof(TMP_TABLE_PARAM))); + tmp_table_param->init(); + tmp_table_param->field_count= field_count; + SELECT_LEX *select_lex= thd->lex->current_select; + if (!(table= create_tmp_table(thd, tmp_table_param, + field_list, (ORDER*) 0, 0, 0, + (select_lex->options | thd->options | + TMP_TABLE_ALL_COLUMNS), + HA_POS_ERROR, + (char *) schema_table->table_name))) + DBUG_RETURN(0); + DBUG_RETURN(table); +} + + +/* + For old SHOW compatibility. It is used when + old SHOW doesn't have generated column names + Make list of fields for SHOW + + SYNOPSIS + make_old_format() + thd thread handler + schema_table pointer to 'schema_tables' element + + RETURN + -1 errror + 0 success +*/ + +int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + ST_FIELD_INFO *field_info= schema_table->fields_info; + for ( ; field_info->field_name; field_info++) + { + if (field_info->old_name) + { + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (field) + { + field->set_name(field_info->old_name, + strlen(field_info->old_name), + system_charset_info); + if (add_item_to_list(thd, field)) + return 1; + } + } + } + return 0; +} + + +int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + char tmp[128]; + LEX *lex= thd->lex; + SELECT_LEX *sel= lex->current_select; + + if (!sel->item_list.elements) + { + ST_FIELD_INFO *field_info= &schema_table->fields_info[1]; + String buffer(tmp,sizeof(tmp), system_charset_info); + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (!field || add_item_to_list(thd, field)) + return 1; + buffer.length(0); + buffer.append(field_info->old_name); + if (lex->wild && lex->wild->ptr()) + { + buffer.append(" ("); + buffer.append(lex->wild->ptr()); + buffer.append(")"); + } + field->set_name(buffer.ptr(), buffer.length(), system_charset_info); + } + return 0; +} + + +int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + char tmp[128]; + String buffer(tmp,sizeof(tmp), thd->charset()); + LEX *lex= thd->lex; + + ST_FIELD_INFO *field_info= &schema_table->fields_info[2]; + buffer.length(0); + buffer.append(field_info->old_name); + buffer.append(lex->select_lex.db); + if (lex->wild && lex->wild->ptr()) + { + buffer.append(" ("); + buffer.append(lex->wild->ptr()); + buffer.append(")"); + } + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (add_item_to_list(thd, field)) + return 1; + field->set_name(buffer.ptr(), buffer.length(), system_charset_info); + if (thd->lex->verbose) + { + field->set_name(buffer.ptr(), buffer.length(), system_charset_info); + field_info= &schema_table->fields_info[3]; + field= new Item_field(NullS, NullS, field_info->field_name); + if (add_item_to_list(thd, field)) + return 1; + field->set_name(field_info->old_name, strlen(field_info->old_name), + system_charset_info); + } + return 0; +} + + +int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) +{ + ST_FIELD_INFO *field_info= &schema_table->fields_info[3]; + int count= 2; + for ( ; field_info->field_name; field_info++) + { + count++; + if (field_info->old_name) + { + if (!thd->lex->verbose && (count == 12 ||count == 17 || count == 18)) + continue; + Item_field *field= new Item_field(NullS, NullS, field_info->field_name); + if (field) + { + field->set_name(field_info->old_name, + strlen(field_info->old_name), + system_charset_info); + if (add_item_to_list(thd, field)) + return 1; + } + } + } + return 0; +} + + +/* + Create information_schema table + + SYNOPSIS + mysql_schema_table() + thd thread handler + lex pointer to LEX + table_list pointer to table_list + + RETURN + 0 success + 1 error +*/ + +int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list) +{ + TABLE *table; + DBUG_ENTER("mysql_schema_table"); + if (!(table= table_list->schema_table-> + create_table(thd, table_list->schema_table))) + { + DBUG_RETURN(1); + } + table->tmp_table= TMP_TABLE; + table->grant.privilege= SELECT_ACL; + table_list->real_name= table->real_name; + table_list->table= table; + table->next= thd->derived_tables; + thd->derived_tables= table; + table_list->select_lex->options |= OPTION_SCHEMA_TABLE; + DBUG_RETURN(0); +} + + +/* + Generate select from information_schema table + + SYNOPSIS + make_schema_select() + thd thread handler + sel pointer to SELECT_LEX + schema_table_idx index of 'schema_tables' element + + RETURN + 0 success + 1 error +*/ + +int make_schema_select(THD *thd, SELECT_LEX *sel, + enum enum_schema_tables schema_table_idx) +{ + ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx); + LEX_STRING db, table; + DBUG_ENTER("mysql_schema_select"); + /* + We have to make non const db_name & table_name + because of lower_case_table_names + */ + make_lex_string(thd, &db, information_schema_name.str, + information_schema_name.length, 0); + make_lex_string(thd, &table, schema_table->table_name, + strlen(schema_table->table_name), 0); + if (!sel->item_list.elements && /* Handle old syntax */ + schema_table->old_format(thd, schema_table) || + !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0), + 0, 0, TL_READ, (List *) 0, + (List *) 0)) + { + DBUG_RETURN(1); + } + DBUG_RETURN(0); +} + + +/* + Fill temporaty schema tables before SELECT + + SYNOPSIS + get_schema_tables_result() + join join which use schema tables + + RETURN + 0 success + 1 error +*/ + +int get_schema_tables_result(JOIN *join) +{ + DBUG_ENTER("get_schema_tables_result"); + JOIN_TAB *tmp_join_tab= join->join_tab+join->tables; + THD *thd= join->thd; + for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++) + { + if (!tab->table || !tab->table->pos_in_table_list) + break; + TABLE_LIST *table_list= tab->table->pos_in_table_list; + if (table_list->schema_table && !thd->only_prepare()) + { + TABLE *old_derived_tables= thd->derived_tables; + thd->derived_tables= 0; + thd->lex->sql_command= SQLCOM_SHOW_FIELDS; + table_list->table->file->records= 0; + MYSQL_LOCK *sql_lock= thd->lock; + thd->lock=0; + if (table_list->schema_table->fill_table(thd, table_list, + tab->select_cond)) + { + thd->derived_tables= old_derived_tables; + thd->lock= sql_lock; + DBUG_RETURN(-1); + } + thd->lock= sql_lock; + thd->lex->sql_command= SQLCOM_SELECT; + thd->derived_tables= old_derived_tables; + } + } + DBUG_RETURN(0); +} + + +ST_FIELD_INFO schema_fields_info[]= +{ + {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"SCHEMA_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Database"}, + {"DEFAULT_CHARACTER_SET_NAME", 60, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO tables_fields_info[]= +{ + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA",NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Name"}, + {"TABLE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ENGINE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, "Engine"}, + {"VERSION", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Version"}, + {"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, 1, "Row_format"}, + {"ROWS", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Rows"}, + {"AVG_ROW_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Avg_row_length"}, + {"DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Data_length"}, + {"MAX_DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Max_data_length"}, + {"INDEX_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Index_length"}, + {"DATA_FREE", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Data_free"}, + {"AUTO_INCREMENT", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Auto_increment"}, + {"CREATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Create_time"}, + {"UPDATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Update_time"}, + {"CHECK_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, 0, "Check_time"}, + {"COLLATION", 60, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"}, + {"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, 0, "Checksum"}, + {"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, 1, "Create_options"}, + {"COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO columns_fields_info[]= +{ + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Field"}, + {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"DATA_TYPE", 40, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"CHARACTER_SET_NAME", 40, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TYPE", 40, MYSQL_TYPE_STRING, 0, 0, 1, "Type"}, + {"COLLATION_NAME", 40, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"}, + {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Null"}, + {"KEY", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Key"}, + {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, "Default"}, + {"EXTRA", 20, MYSQL_TYPE_STRING, 0, 0, 1, "Extra"}, + {"PRIVILIGES", 80, MYSQL_TYPE_STRING, 0, 0, 1, "Privileges"}, + {"COMMENT", 255, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO charsets_fields_info[]= +{ + {"CHARACTER_SET_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Charset"}, + {"Description", 60, MYSQL_TYPE_STRING, 0, 0, 1, "Description"}, + {"DEFAULT_COLLATE_NAME", 60, MYSQL_TYPE_STRING, 0, 0, 1, "Default collation"}, + {"Maxlen", 3 ,MYSQL_TYPE_LONG, 0, 0, 0, "Maxlen"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO collation_fields_info[]= +{ + {"COLLATION_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Collation"}, + {"Charset", 30, MYSQL_TYPE_STRING, 0, 0, 1, "Charset"}, + {"Id", 11, MYSQL_TYPE_LONG, 0, 0, 0, "Id"}, + {"Default", 30 ,MYSQL_TYPE_STRING, 0, 0, 1, "Default"}, + {"Compiled", 30 ,MYSQL_TYPE_STRING, 0, 0, 1, "Compiled"}, + {"Sortlen", 3 ,MYSQL_TYPE_LONG, 0, 0, 0, "Sortlen"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO coll_charset_app_fields_info[]= +{ + {"COLLATION_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CHARACTER_SET_NAME", 30, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO proc_fields_info[]= +{ + {"SPECIFIC_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ROUTINE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"ROUTINE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Db"}, + {"ROUTINE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Name"}, + {"ROUTINE_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, 1, "Type"}, + {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, 1, "Definer"}, + {"DTD_IDENTIFIER", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ROUTINE_BODY", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ROUTINE_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"PARAMETER_STYLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_DETERMINISTIC", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"SQL_DATA_ACCESS", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"SQL_PATH", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"LAST_ALTERED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, 0, "Modified"}, + {"CREATED", 0, MYSQL_TYPE_TIMESTAMP, 0, 0, 1, "Created"}, + {"SECURITY_TYPE", 7, MYSQL_TYPE_STRING, 0, 0, 1, "Security_type"}, + {"SQL_MODE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ROUTINE_COMMENT", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Comment"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO stat_fields_info[]= +{ + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Table"}, + {"NON_UNIQUE", 1, MYSQL_TYPE_LONG, 0, 0, 0, "Non_unique"}, + {"INDEX_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Key_name"}, + {"SEQ_IN_INDEX", 2, MYSQL_TYPE_LONG, 0, 0, 0, "Seq_in_index"}, + {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Column_name"}, + {"COLLATION", 1, MYSQL_TYPE_STRING, 0, 1, 1, "Collation"}, + {"CARDINALITY", 21, MYSQL_TYPE_LONG, 0, 1, 0, "Cardinality"}, + {"SUB_PART", 3, MYSQL_TYPE_LONG, 0, 1, 0, "Sub_part"}, + {"PACKED", 10, MYSQL_TYPE_STRING, 0, 1, 1, "Packed"}, + {"NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, "Null"}, + {"INDEX_TYPE", 16, MYSQL_TYPE_STRING, 0, 0, 1, "Index_type"}, + {"COMMENT", 16, MYSQL_TYPE_STRING, 0, 1, 1, "Comment"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO view_fields_info[]= +{ + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"VIEW_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CHECK_OPTION", 4, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_UPDATABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO user_privileges_fields_info[]= +{ + {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO schema_privileges_fields_info[]= +{ + {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO table_privileges_fields_info[]= +{ + {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO column_privileges_fields_info[]= +{ + {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"PRIVILEGE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO table_constraints_fields_info[]= +{ + {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CONSTRAINT_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CONSTRAINT_METHOD", 20, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO key_column_usage_fields_info[]= +{ + {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"ORDINAL_POSITION", 10 ,MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"REFERENCED_TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"REFERENCED_TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"REFERENCED_COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +ST_FIELD_INFO table_names_fields_info[]= +{ + {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 1, 0}, + {"TABLE_SCHEMA",NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, 0}, + {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Tables_in_"}, + {"TABLE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 1, "Table_type"}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} +}; + + +/* + Description of ST_FIELD_INFO in table.h +*/ + +ST_SCHEMA_TABLE schema_tables[]= +{ + {"SCHEMATA", schema_fields_info, create_schema_table, + fill_schema_shemata, make_schemata_old_format, 0, 1, -1}, + {"TABLES", tables_fields_info, create_schema_table, + get_all_tables, make_old_format, get_schema_tables_record, 1, 2}, + {"COLUMNS", columns_fields_info, create_schema_table, + get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2}, + {"CHARACTER_SETS", charsets_fields_info, create_schema_table, + fill_schema_charsets, make_old_format, 0, -1, -1}, + {"COLLATIONS", collation_fields_info, create_schema_table, + fill_schema_collation, make_old_format, 0, -1, -1}, + {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info, + create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1}, + {"ROUTINES", proc_fields_info, create_schema_table, + fill_schema_proc, make_old_format, 0, -1, -1}, + {"STATISTICS", stat_fields_info, create_schema_table, + get_all_tables, make_old_format, get_schema_stat_record, 1, 2}, + {"VIEWS", view_fields_info, create_schema_table, + get_all_tables, 0, get_schema_views_record, 1, 2}, + {"USER_PRIVILEGES", user_privileges_fields_info, create_schema_table, + fill_schema_user_privileges, 0, 0, -1, -1}, + {"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table, + fill_schema_schema_privileges, 0, 0, -1, -1}, + {"TABLE_PRIVILEGES", table_privileges_fields_info, create_schema_table, + fill_schema_table_privileges, 0, 0, -1, -1}, + {"COLUMN_PRIVILEGES", column_privileges_fields_info, create_schema_table, + fill_schema_column_privileges, 0, 0, -1, -1}, + {"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table, + get_all_tables, 0, get_schema_constarints_record, 3, 4}, + {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table, + get_all_tables, 0, get_schema_key_column_usage_record, 3, 4}, + {"TABLE_NAMES", table_names_fields_info, create_schema_table, + get_all_tables, make_table_names_old_format, 0, 1, 2}, + {0, 0, 0, 0, 0, 0, 0, 0} +}; + + #ifdef __GNUC__ template class List_iterator_fast; template class List; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 760ada9cdbd..941f08094b5 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -188,7 +188,8 @@ int mysql_create_view(THD *thd, for (tbl= tables; tbl; tbl= tbl->next_global) { /* is this table temporary and is not view? */ - if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view) + if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view && + !tbl->schema_table) { my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); res= -1; @@ -494,7 +495,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, tbl; tbl= tbl->next_local) { - if (tbl->view && !tbl->updatable_view) + if ((tbl->view && !tbl->updatable_view) || tbl->schema_table) { view->updatable_view= 0; break; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index fe5ce7640ea..2f6cb53fc04 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -663,7 +663,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); opt_table_alias %type - table_ident table_ident_nodb references + table_ident table_ident_nodb references from_table_ident %type remember_name remember_end opt_ident opt_db text_or_password @@ -5904,21 +5904,32 @@ show: SHOW ; show_param: - DATABASES wild - { Lex->sql_command= SQLCOM_SHOW_DATABASES; } - | opt_full TABLES opt_db wild - { - LEX *lex= Lex; - lex->sql_command= SQLCOM_SHOW_TABLES; - lex->select_lex.db= $3; - } - | TABLE_SYM STATUS_SYM opt_db wild - { - LEX *lex= Lex; - lex->sql_command= SQLCOM_SHOW_TABLES; - lex->describe= DESCRIBE_EXTENDED; - lex->select_lex.db= $3; - } + DATABASES ext_select_item_list wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_DATABASES; + if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA)) + YYABORT; + } + | opt_full TABLES ext_select_item_list opt_db wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_TABLES; + lex->select_lex.db= $4; + if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES)) + YYABORT; + } + | TABLE_SYM STATUS_SYM ext_select_item_list opt_db wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_TABLE_STATUS; + lex->select_lex.db= $4; + if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES)) + YYABORT; + } | OPEN_SYM TABLES opt_db wild { LEX *lex= Lex; @@ -5928,12 +5939,14 @@ show_param: | ENGINE_SYM storage_engines { Lex->create_info.db_type= $2; } show_engine_param - | opt_full COLUMNS from_or_in table_ident opt_db wild + | opt_full COLUMNS ext_select_item_list from_table_ident opt_db wild_and_where { - Lex->sql_command= SQLCOM_SHOW_FIELDS; + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_FIELDS; if ($5) $4->change_db($5); - if (!Select->add_table_to_list(YYTHD, $4, NULL, 0)) + if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS)) YYABORT; } | NEW_SYM MASTER_SYM FOR_SYM SLAVE WITH MASTER_LOG_FILE_SYM EQ @@ -5959,13 +5972,15 @@ show_param: LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS; } opt_limit_clause_init - | keys_or_index from_or_in table_ident opt_db - { - Lex->sql_command= SQLCOM_SHOW_KEYS; + | keys_or_index ext_select_item_list from_table_ident opt_db where_clause + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_KEYS; if ($4) $3->change_db($4); - if (!Select->add_table_to_list(YYTHD, $3, NULL, 0)) - YYABORT; + if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS)) + YYABORT; } | COLUMN_SYM TYPES_SYM { @@ -6012,10 +6027,22 @@ show_param: thd->lex->sql_command= SQLCOM_SHOW_VARIABLES; thd->lex->option_type= (enum_var_type) $1; } - | charset wild - { Lex->sql_command= SQLCOM_SHOW_CHARSETS; } - | COLLATION_SYM wild - { Lex->sql_command= SQLCOM_SHOW_COLLATIONS; } + | charset ext_select_item_list wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_CHARSETS; + if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS)) + YYABORT; + } + | COLLATION_SYM ext_select_item_list wild_and_where + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_COLLATIONS; + if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS)) + YYABORT; + } | BERKELEY_DB_SYM LOGS_SYM { Lex->sql_command= SQLCOM_SHOW_LOGS; WARN_DEPRECATED("SHOW BDB LOGS", "SHOW ENGINE BDB LOGS"); } | LOGS_SYM @@ -6094,13 +6121,21 @@ show_param: lex->sql_command = SQLCOM_SHOW_CREATE_FUNC; lex->spname= $3; } - | PROCEDURE STATUS_SYM wild + | PROCEDURE STATUS_SYM ext_select_item_list wild_and_where { - Lex->sql_command = SQLCOM_SHOW_STATUS_PROC; + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_STATUS_PROC; + if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES)) + YYABORT; } - | FUNCTION_SYM STATUS_SYM wild + | FUNCTION_SYM STATUS_SYM ext_select_item_list wild_and_where { - Lex->sql_command = SQLCOM_SHOW_STATUS_FUNC; + LEX *lex= Lex; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_STATUS_FUNC; + if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES)) + YYABORT; }; show_engine_param: @@ -6161,16 +6196,49 @@ binlog_from: /* empty */ { Lex->mi.pos = 4; /* skip magic number */ } | FROM ulonglong_num { Lex->mi.pos = $2; }; +from_table_ident: + /* empty */ { $$= 0; } + | from_or_in table_ident { $$= $2; } + ; + +wild_and_where: + /* empty */ + | LIKE TEXT_STRING_sys + { Lex->wild= new (YYTHD->mem_root) String($2.str, $2.length, + system_charset_info); } + | WHERE expr + { + Select->where= $2; + if ($2) + $2->top_level_item(); + } + ; + +ext_select_item_list: + { + LEX *lex=Lex; + SELECT_LEX *sel= lex->current_select; + lex->lock_option= TL_READ; + mysql_init_select(lex); + lex->current_select->parsing_place= SELECT_LIST; + } + /* empty */ + | select_item_list {}; + /* A Oracle compatible synonym for show */ describe: describe_command table_ident { - LEX *lex=Lex; - lex->wild=0; - lex->verbose=0; - lex->sql_command=SQLCOM_SHOW_FIELDS; - if (!Select->add_table_to_list(lex->thd, $2, NULL,0)) + LEX *lex= Lex; + lex->lock_option= TL_READ; + mysql_init_select(lex); + lex->current_select->parsing_place= SELECT_LIST; + lex->sql_command= SQLCOM_SELECT; + lex->orig_sql_command= SQLCOM_SHOW_FIELDS; + lex->select_lex.db= 0; + lex->verbose= 0; + if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS)) YYABORT; } opt_describe_column {} diff --git a/sql/table.cc b/sql/table.cc index 0e8045abacf..68293335155 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1520,6 +1520,7 @@ void st_table_list::set_ancestor() if (ancestor->ancestor) ancestor->set_ancestor(); table= ancestor->table; + schema_table= ancestor->schema_table; ancestor->table->grant= grant; } diff --git a/sql/table.h b/sql/table.h index f95be1fcccb..86dd30dff68 100644 --- a/sql/table.h +++ b/sql/table.h @@ -204,6 +204,58 @@ struct st_table { }; +typedef struct st_foreign_key_info +{ + LEX_STRING *forein_id; + LEX_STRING *referenced_db; + LEX_STRING *referenced_table; + LEX_STRING *constraint_method; + List foreign_fields; + List referenced_fields; +} FOREIGN_KEY_INFO; + + +enum enum_schema_tables +{ + SCH_SCHEMATA= 0, SCH_TABLES, SCH_COLUMNS, SCH_CHARSETS, SCH_COLLATIONS, + SCH_COLLATION_CHARACTER_SET_APPLICABILITY, SCH_PROCEDURES, SCH_STATISTICS, + SCH_VIEWS, SCH_USER_PRIVILEGES, SCH_SCHEMA_PRIVILEGES, SCH_TABLE_PRIVILEGES, + SCH_COLUMN_PRIVILEGES, SCH_TABLE_CONSTRAINTS, SCH_KEY_COLUMN_USAGE, + SCH_TABLE_NAMES +}; + + +typedef struct st_field_info +{ + const char* field_name; + uint field_length; + enum enum_field_types field_type; + int value; + bool maybe_null; + bool utf8; + const char* old_name; +} ST_FIELD_INFO; + +struct st_table_list; +typedef class Item COND; + +typedef struct st_schema_table +{ + const char* table_name; + ST_FIELD_INFO *fields_info; + /* Create information_schema table */ + TABLE *(*create_table) (THD *thd, struct st_schema_table *schema_table); + /* Fill table with data */ + int (*fill_table) (THD *thd, struct st_table_list *tables, COND *cond); + /* Handle fileds for old SHOW */ + int (*old_format) (THD *thd, struct st_schema_table *schema_table); + int (*process_table) (THD *thd, struct st_table_list *tables, + TABLE *table, int res, const char *base_name, + const char *file_name); + int idx_field1, idx_field2; +} ST_SCHEMA_TABLE; + + #define JOIN_TYPE_LEFT 1 #define JOIN_TYPE_RIGHT 2 @@ -252,6 +304,8 @@ typedef struct st_table_list */ st_table_list *correspondent_table; st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */ + ST_SCHEMA_TABLE *schema_table; /* Information_schema table */ + st_select_lex *schema_select_lex; /* link to select_lex where this table was used */ st_select_lex *select_lex; st_lex *view; /* link on VIEW lex for merging */ diff --git a/tests/client_test.c b/tests/client_test.c index 39969120608..034d846017a 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -655,10 +655,12 @@ static void verify_prepare_field(MYSQL_RES *result, fprintf(stdout, "\n org_name :`%s`\t(expected: `%s`)", field->org_name, org_name); fprintf(stdout, "\n type :`%d`\t(expected: `%d`)", field->type, type); - fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", - field->table, table); - fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", - field->org_table, org_table); + if (table) + fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", + field->table, table); + if (org_table) + fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", + field->org_table, org_table); fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); fprintf(stdout, "\n length :`%ld`\t(expected: `%ld`)", field->length, length); @@ -671,8 +673,10 @@ static void verify_prepare_field(MYSQL_RES *result, DIE_UNLESS(strcmp(field->name, name) == 0); DIE_UNLESS(strcmp(field->org_name, org_name) == 0); DIE_UNLESS(field->type == type); - DIE_UNLESS(strcmp(field->table, table) == 0); - DIE_UNLESS(strcmp(field->org_table, org_table) == 0); + if (table) + DIE_UNLESS(strcmp(field->table, table) == 0); + if (org_table) + DIE_UNLESS(strcmp(field->org_table, org_table) == 0); DIE_UNLESS(strcmp(field->db, db) == 0); DIE_UNLESS(field->length == length); if (def) @@ -7256,23 +7260,23 @@ static void test_explain_bug() mysql_num_fields(result)); DIE_UNLESS(6 == mysql_num_fields(result)); - verify_prepare_field(result, 0, "Field", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN, 0); + verify_prepare_field(result, 0, "Field", "COLUMN_NAME", + MYSQL_TYPE_STRING, 0, 0, "", NAME_LEN, 0); - verify_prepare_field(result, 1, "Type", "", MYSQL_TYPE_VAR_STRING, - "", "", "", 40, 0); + verify_prepare_field(result, 1, "Type", "TYPE", + MYSQL_TYPE_STRING, 0, 0, "", 40, 0); - verify_prepare_field(result, 2, "Null", "", MYSQL_TYPE_VAR_STRING, - "", "", "", 1, 0); + verify_prepare_field(result, 2, "Null", "IS_NULLABLE", + MYSQL_TYPE_STRING, 0, 0, "", 3, 0); - verify_prepare_field(result, 3, "Key", "", MYSQL_TYPE_VAR_STRING, - "", "", "", 3, 0); + verify_prepare_field(result, 3, "Key", "KEY", + MYSQL_TYPE_STRING, 0, 0, "", 3, 0); - verify_prepare_field(result, 4, "Default", "", MYSQL_TYPE_VAR_STRING, - "", "", "", NAME_LEN, 0); + verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", + MYSQL_TYPE_STRING, 0, 0, "", NAME_LEN, 0); - verify_prepare_field(result, 5, "Extra", "", MYSQL_TYPE_VAR_STRING, - "", "", "", 20, 0); + verify_prepare_field(result, 5, "Extra", "EXTRA", + MYSQL_TYPE_STRING, 0, 0, "", 20, 0); mysql_free_result(result); mysql_stmt_close(stmt); From 7210195f1e8b482db0a102b921a859604a1f9522 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Sat, 13 Nov 2004 19:35:51 +0200 Subject: [PATCH 92/94] now my_printf_error is not better then my_error, but my_error call is shorter used only one implementation of format parser of (printf) fixed multistatement --- include/mysqld_error.h | 4 +- mysql-test/t/key.test | 2 +- mysys/my_error.c | 117 +++--------------- sql/field_conv.cc | 6 +- sql/ha_innodb.cc | 9 +- sql/handler.cc | 19 +-- sql/item.cc | 58 ++++----- sql/item_cmpfunc.cc | 11 +- sql/item_func.cc | 49 +++----- sql/item_strfunc.cc | 17 ++- sql/lock.cc | 3 +- sql/log.cc | 3 +- sql/parse_file.cc | 38 +++--- sql/procedure.cc | 3 +- sql/protocol.cc | 1 - sql/repl_failsafe.cc | 22 ++-- sql/set_var.cc | 57 ++++----- sql/share/czech/errmsg.txt | 2 + sql/share/danish/errmsg.txt | 2 + sql/share/dutch/errmsg.txt | 2 + sql/share/english/errmsg.txt | 2 + sql/share/estonian/errmsg.txt | 2 + sql/share/french/errmsg.txt | 2 + sql/share/german/errmsg.txt | 2 + sql/share/greek/errmsg.txt | 2 + sql/share/hungarian/errmsg.txt | 2 + sql/share/italian/errmsg.txt | 2 + sql/share/japanese/errmsg.txt | 2 + sql/share/korean/errmsg.txt | 2 + sql/share/norwegian-ny/errmsg.txt | 2 + sql/share/norwegian/errmsg.txt | 2 + sql/share/polish/errmsg.txt | 2 + sql/share/portuguese/errmsg.txt | 2 + sql/share/romanian/errmsg.txt | 2 + sql/share/russian/errmsg.txt | 2 + sql/share/serbian/errmsg.txt | 2 + sql/share/slovak/errmsg.txt | 2 + sql/share/spanish/errmsg.txt | 2 + sql/share/swedish/errmsg.txt | 2 + sql/share/ukrainian/errmsg.txt | 2 + sql/slave.cc | 8 +- sql/sp.cc | 16 ++- sql/sp_head.cc | 14 +-- sql/sql_acl.cc | 87 ++++++------- sql/sql_analyse.cc | 15 +-- sql/sql_base.cc | 81 +++++------- sql/sql_class.cc | 10 +- sql/sql_db.cc | 29 ++--- sql/sql_delete.cc | 18 ++- sql/sql_handler.cc | 30 ++--- sql/sql_insert.cc | 37 ++---- sql/sql_load.cc | 9 +- sql/sql_map.cc | 8 +- sql/sql_parse.cc | 198 ++++++++++++------------------ sql/sql_prepare.cc | 32 ++--- sql/sql_rename.cc | 6 +- sql/sql_repl.cc | 12 +- sql/sql_select.cc | 13 +- sql/sql_show.cc | 13 +- sql/sql_table.cc | 144 ++++++++-------------- sql/sql_trigger.cc | 7 +- sql/sql_udf.cc | 16 +-- sql/sql_update.cc | 44 +++---- sql/sql_view.cc | 49 +++----- sql/sql_yacc.yy | 186 ++++++++++------------------ sql/table.cc | 22 ++-- strings/my_vsnprintf.c | 27 +++- 67 files changed, 620 insertions(+), 976 deletions(-) diff --git a/include/mysqld_error.h b/include/mysqld_error.h index f98bb4cb75c..4ef23f446c9 100644 --- a/include/mysqld_error.h +++ b/include/mysqld_error.h @@ -406,4 +406,6 @@ #define ER_LOGING_PROHIBIT_CHANGING_OF 1387 #define ER_NO_FILE_MAPPING 1388 #define ER_WRONG_MAGIC 1389 -#define ER_ERROR_MESSAGES 390 +#define ER_PS_MANY_PARAM 1390 +#define ER_KEY_PART_0 1391 +#define ER_ERROR_MESSAGES 392 diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 8885f69e60c..0a86c1cd145 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -299,5 +299,5 @@ drop table t1; # create dedicated error code for this and # and change my_printf_error() to my_error ---error 1105 +--error 1391 create table t1 (c char(10), index (c(0))); diff --git a/mysys/my_error.c b/mysys/my_error.c index 75aa84efca0..175f8cf516b 100644 --- a/mysys/my_error.c +++ b/mysys/my_error.c @@ -26,12 +26,9 @@ WARNING! my_error family functions have to be used according following rules: - if message have not parameters use my_message(ER_CODE, ER(ER_CODE), MYF(N)) - - if message have only integer parameters, string constants (created - inside program) or string put (and cut if it is need) in some limited - length buffer before passing it as parameter then you can use - my_error(ER_CODE, MYF(N), ...). Never pass string get from user to - my_error. - - in all other cases use my_printf_error(ER_CODE, ER(ER_CODE), MYF(N), ...) + - if message registered use my_error(ER_CODE, MYF(N), ...). + - With some special text of errror message use: + my_printf_error(ER_CODE, format, MYF(N), ...) */ const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; @@ -53,107 +50,22 @@ char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; the length value is ignored. */ -int my_error(int nr,myf MyFlags, ...) +int my_error(int nr, myf MyFlags, ...) { - va_list ap; - uint olen, plen; - reg1 const char *tpos; - reg2 char *endpos; - char * par; - char ebuff[ERRMSGSIZE+20]; - int prec_chars; /* output precision */ - my_bool prec_supplied; + const char *format; + va_list args; + char ebuff[ERRMSGSIZE + 20]; DBUG_ENTER("my_error"); - LINT_INIT(prec_chars); /* protected by prec_supplied */ - va_start(ap,MyFlags); DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); if (nr / ERRMOD == GLOB && my_errmsg[GLOB] == 0) init_glob_errs(); + format= my_errmsg[nr / ERRMOD][nr % ERRMOD]; - olen=(uint) strlen(tpos=my_errmsg[nr / ERRMOD][nr % ERRMOD]); - endpos=ebuff; - - while (*tpos) - { - if (tpos[0] != '%') - { - *endpos++= *tpos++; /* Copy ordinary char */ - continue; - } - if (*++tpos == '%') /* test if %% */ - { - olen--; - } - else - { - /* - Skip size/precision flags to be compatible with printf. - The only size/precision flag supported is "%.*s". - If "%.*u" or "%.*d" are encountered, the precision number is read - from the variable argument list but its value is ignored. - */ - prec_supplied= 0; - if (*tpos== '.') - { - tpos++; - olen--; - if (*tpos == '*') - { - tpos++; - olen--; - prec_chars= va_arg(ap, int); /* get length parameter */ - prec_supplied= 1; - } - } - - if (!prec_supplied) - { - while (my_isdigit(&my_charset_latin1, *tpos) || *tpos == '.' || - *tpos == '-') - tpos++; - - if (*tpos == 'l') /* Skip 'l' argument */ - tpos++; - } - - if (*tpos == 's') /* String parameter */ - { - par= va_arg(ap, char *); - plen= (uint) strlen(par); - if (prec_supplied && prec_chars > 0) - plen= min((uint)prec_chars, plen); - if (olen + plen < ERRMSGSIZE+2) /* Replace if possible */ - { - strmake(endpos, par, plen); - endpos+= plen; - tpos++; - olen+= plen-2; - continue; - } - } - else if (*tpos == 'd' || *tpos == 'u') /* Integer parameter */ - { - register int iarg; - iarg= va_arg(ap, int); - if (*tpos == 'd') - plen= (uint) (int10_to_str((long) iarg, endpos, -10) - endpos); - else - plen= (uint) (int10_to_str((long) (uint) iarg, endpos, 10) - endpos); - if (olen + plen < ERRMSGSIZE+2) /* Replace parameter if possible */ - { - endpos+= plen; - tpos++; - olen+= plen-2; - continue; - } - } - } - *endpos++= '%'; /* % used as % or unknown code */ - } - *endpos= '\0'; /* End of errmessage */ - va_end(ap); + va_start(args,MyFlags); + (void) my_vsnprintf (ebuff, sizeof(ebuff), format, args); + va_end(args); DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags)); } @@ -172,11 +84,14 @@ int my_printf_error(uint error, const char *format, myf MyFlags, ...) { va_list args; char ebuff[ERRMSGSIZE+20]; + DBUG_ENTER("my_printf_error"); + DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d Format: %s", + error, MyFlags, errno, format)); va_start(args,MyFlags); - (void) vsprintf (ebuff,format,args); + (void) my_vsnprintf (ebuff, sizeof(ebuff), format, args); va_end(args); - return (*error_handler_hook)(error, ebuff, MyFlags); + DBUG_RETURN((*error_handler_hook)(error, ebuff, MyFlags)); } /* diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 61a5a28f47b..336408c5aa9 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -126,8 +126,7 @@ set_field_to_null(Field *field) return 0; } if (!current_thd->no_errors) - my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0), - field->field_name); + my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name); return -1; } @@ -185,8 +184,7 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions) return 0; } if (!current_thd->no_errors) - my_printf_error(ER_BAD_NULL_ERROR,ER(ER_BAD_NULL_ERROR),MYF(0), - field->field_name); + my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name); return -1; } diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 34fc4873d43..88af43f8410 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -495,11 +495,10 @@ innobase_mysql_tmpfile(void) if (fd2 < 0) { DBUG_PRINT("error",("Got error %d on dup",fd2)); my_errno=errno; - my_printf_error(EE_OUT_OF_FILERESOURCES, - ER(EE_OUT_OF_FILERESOURCES), - MYF(ME_BELL+ME_WAITTANG), - filename, my_errno); - } + my_error(EE_OUT_OF_FILERESOURCES, + MYF(ME_BELL+ME_WAITTANG), + filename, my_errno); + } my_close(fd, MYF(MY_WME)); } return(fd2); diff --git a/sql/handler.cc b/sql/handler.cc index 8b6458d3662..e65fd6d097d 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1200,8 +1200,7 @@ void handler::print_error(int error, myf errflag) str.length(max_length-4); str.append("..."); } - my_printf_error(ER_DUP_ENTRY, ER(ER_DUP_ENTRY), MYF(0), - str.c_ptr(), key_nr+1); + my_error(ER_DUP_ENTRY, MYF(0), str.c_ptr(), key_nr+1); DBUG_VOID_RETURN; } textno=ER_DUP_KEY; @@ -1270,7 +1269,7 @@ void handler::print_error(int error, myf errflag) uint length=dirname_part(buff,table->path); buff[length-1]=0; db=buff+dirname_length(buff); - my_error(ER_NO_SUCH_TABLE,MYF(0),db,table->table_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), db, table->table_name); break; } default: @@ -1284,20 +1283,16 @@ void handler::print_error(int error, myf errflag) { const char* engine= table_type(); if (temporary) - my_printf_error(ER_GET_TEMPORARY_ERRMSG, - ER(ER_GET_TEMPORARY_ERRMSG), MYF(0), - error, str.ptr(), engine); + my_error(ER_GET_TEMPORARY_ERRMSG, MYF(0), error, str.ptr(), engine); else - my_printf_error(ER_GET_ERRMSG, - ER(ER_GET_ERRMSG), MYF(0), - error, str.ptr(), engine); + my_error(ER_GET_ERRMSG, MYF(0), error, str.ptr(), engine); } else my_error(ER_GET_ERRNO,errflag,error); DBUG_VOID_RETURN; } } - my_error(textno,errflag,table->table_name,error); + my_error(textno, errflag, table->table_name, error); DBUG_VOID_RETURN; } @@ -1419,9 +1414,7 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, error=table.file->create(name,&table,create_info); VOID(closefrm(&table)); if (error) - my_printf_error(ER_CANT_CREATE_TABLE, ER(ER_CANT_CREATE_TABLE), - MYF(ME_BELL+ME_WAITTANG), - name,error); + my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name,error); DBUG_RETURN(error != 0); } diff --git a/sql/item.cc b/sql/item.cc index f37224c6bf5..42e1f23babd 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1621,8 +1621,8 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) best match, they must reference the same column, otherwise the field is ambiguous. */ - my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), - MYF(0), find_item->full_name(), current_thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), + find_item->full_name(), current_thd->where); return NULL; } } @@ -1713,8 +1713,8 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) DBUG_ASSERT(*select_ref); if (! (*select_ref)->fixed) { - my_error(ER_ILLEGAL_REFERENCE, MYF(0), ref->name, - "forward reference in item list"); + my_error(ER_ILLEGAL_REFERENCE, MYF(0), + ref->name, "forward reference in item list"); return NULL; } return (select->ref_pointer_array + counter); @@ -1895,8 +1895,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) if (upward_lookup) { // We can't say exactly what absent table or field - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - full_name(), thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where); } else { @@ -1988,14 +1987,9 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) db, tab, field_name) & VIEW_ANY_ACL))) { - my_printf_error(ER_COLUMNACCESS_DENIED_ERROR, - ER(ER_COLUMNACCESS_DENIED_ERROR), - MYF(0), - "ANY", - thd->priv_user, - thd->host_or_ip, - field_name, - tab); + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + "ANY", thd->priv_user, thd->host_or_ip, + field_name, tab); return TRUE; } } @@ -2455,8 +2449,7 @@ Item_real::Item_real(const char *str_arg, uint length) when we are in the parser */ DBUG_ASSERT(str_arg[length] == 0); - my_printf_error(ER_ILLEGAL_VALUE_FOR_TYPE, ER(ER_ILLEGAL_VALUE_FOR_TYPE), - MYF(0), "double", (char*) str_arg); + my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "double", (char*) str_arg); } presentation= name=(char*) str_arg; decimals=(uint8) nr_of_decimals(str_arg); @@ -2846,8 +2839,8 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) return TRUE; if (ref == not_found_item && from_field == not_found_field) { - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - this->full_name(), current_thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + this->full_name(), current_thd->where); ref= 0; // Safety return TRUE; } @@ -2889,8 +2882,8 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) else { /* The current reference cannot be resolved in this query. */ - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - this->full_name(), current_thd->where); + my_error(ER_BAD_FIELD_ERROR,MYF(0), + this->full_name(), current_thd->where); return TRUE; } } @@ -2907,11 +2900,10 @@ bool Item_ref::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) current_sel->having_fix_field))) || !(*ref)->fixed) { - my_printf_error(ER_ILLEGAL_REFERENCE, ER(ER_ILLEGAL_REFERENCE), MYF(0), - name, - ((*ref)->with_sum_func? - "reference to group function": - "forward reference in item list")); + my_error(ER_ILLEGAL_REFERENCE, MYF(0), + name, ((*ref)->with_sum_func? + "reference to group function": + "forward reference in item list")); return TRUE; } max_length= (*ref)->max_length; @@ -2932,8 +2924,6 @@ void Item_ref::cleanup() DBUG_ENTER("Item_ref::cleanup"); Item_ident::cleanup(); result_field= 0; - if (hook_ptr) - *hook_ptr= orig_item; DBUG_VOID_RETURN; } @@ -3046,8 +3036,7 @@ bool Item_default_value::fix_fields(THD *thd, field_arg= (Item_field *)arg; if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG) { - my_printf_error(ER_NO_DEFAULT_FOR_FIELD, ER(ER_NO_DEFAULT_FOR_FIELD), - MYF(0), field_arg->field->field_name); + my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name); return TRUE; } if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of()))) @@ -3603,12 +3592,11 @@ bool Item_type_holder::join_types(THD *thd, Item *item) old_derivation= collation.derivation_name(); if (item_type == STRING_RESULT && collation.aggregate(item->collation)) { - my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, - ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), - old_cs, old_derivation, - item->collation.collation->name, - item->collation.derivation_name(), - "UNION"); + my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), + old_cs, old_derivation, + item->collation.collation->name, + item->collation.derivation_name(), + "UNION"); return 1; } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 63d20b2dab3..4a4485ba2da 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -53,11 +53,10 @@ static void agg_cmp_type(Item_result *type, Item **items, uint nitems) static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, - ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), - c1.collation->name,c1.derivation_name(), - c2.collation->name,c2.derivation_name(), - fname); + my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), + c1.collation->name,c1.derivation_name(), + c2.collation->name,c2.derivation_name(), + fname); } @@ -2437,7 +2436,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) cmp_collation.collation))) { (void) regerror(error,&preg,buff,sizeof(buff)); - my_printf_error(ER_REGEXP_ERROR,ER(ER_REGEXP_ERROR),MYF(0),buff); + my_error(ER_REGEXP_ERROR, MYF(0), buff); return TRUE; } regex_compiled=regex_is_const=1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 65e1cceb5bb..8d4ad54b511 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -45,11 +45,10 @@ bool check_reserved_words(LEX_STRING *name) static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, - ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), - c1.collation->name, c1.derivation_name(), - c2.collation->name, c2.derivation_name(), - fname); + my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + fname); } static void my_coll_agg_error(DTCollation &c1, @@ -57,12 +56,11 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c3, const char *fname) { - my_printf_error(ER_CANT_AGGREGATE_3COLLATIONS, - ER(ER_CANT_AGGREGATE_3COLLATIONS), MYF(0), - c1.collation->name, c1.derivation_name(), - c2.collation->name, c2.derivation_name(), - c3.collation->name, c3.derivation_name(), - fname); + my_error(ER_CANT_AGGREGATE_3COLLATIONS, MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + c3.collation->name, c3.derivation_name(), + fname); } @@ -76,8 +74,7 @@ static void my_coll_agg_error(Item** args, uint count, const char *fname) args[2]->collation, fname); else - my_printf_error(ER_CANT_AGGREGATE_NCOLLATIONS, - ER(ER_CANT_AGGREGATE_NCOLLATIONS), MYF(0),fname); + my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), fname); } @@ -1717,8 +1714,7 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, if (!tmp_udf) { - my_printf_error(ER_CANT_FIND_UDF,ER(ER_CANT_FIND_UDF),MYF(0),u_d->name.str, - errno); + my_error(ER_CANT_FIND_UDF, MYF(0), u_d->name.str, errno); DBUG_RETURN(TRUE); } u_d=tmp_udf; @@ -1838,8 +1834,8 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, u_d->func_init; if ((error=(uchar) init(&initid, &f_args, thd->net.last_error))) { - my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0), - u_d->name.str, thd->net.last_error); + my_error(ER_CANT_INITIALIZE_UDF, MYF(0), + u_d->name.str, thd->net.last_error); free_udf(u_d); DBUG_RETURN(TRUE); } @@ -1851,8 +1847,8 @@ udf_handler::fix_fields(THD *thd, TABLE_LIST *tables, Item_result_field *func, initialized=1; if (error) { - my_printf_error(ER_CANT_INITIALIZE_UDF,ER(ER_CANT_INITIALIZE_UDF),MYF(0), - u_d->name.str, ER(ER_UNKNOWN_ERROR)); + my_error(ER_CANT_INITIALIZE_UDF, MYF(0), + u_d->name.str, ER(ER_UNKNOWN_ERROR)); DBUG_RETURN(TRUE); } DBUG_RETURN(FALSE); @@ -3378,8 +3374,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, { if (!var->is_struct()) { - my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, ER(ER_VARIABLE_IS_NOT_STRUCT), - MYF(0), base_name->str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), base_name->str); return 0; } } @@ -3544,8 +3539,7 @@ Item_func_sp::execute(Item **itp) m_sp= sp_find_function(thd, m_name); if (! m_sp) { - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - "FUNCTION", m_name->m_qname); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname); DBUG_RETURN(-1); } @@ -3579,8 +3573,7 @@ Item_func_sp::field_type() const DBUG_PRINT("info", ("m_returns = %d", m_sp->m_returns)); DBUG_RETURN(m_sp->m_returns); } - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - "FUNCTION", m_name->m_qname); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname); DBUG_RETURN(MYSQL_TYPE_STRING); } @@ -3596,8 +3589,7 @@ Item_func_sp::result_type() const { DBUG_RETURN(m_sp->result()); } - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - "FUNCTION", m_name->m_qname); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname); DBUG_RETURN(STRING_RESULT); } @@ -3610,8 +3602,7 @@ Item_func_sp::fix_length_and_dec() m_sp= sp_find_function(current_thd, m_name); if (! m_sp) { - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - "FUNCTION", m_name->m_qname); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", m_name->m_qname); } else { diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b3ba0b4a4f3..891cf48f7ca 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -42,11 +42,10 @@ String my_empty_string("",default_charset_info); static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { - my_printf_error(ER_CANT_AGGREGATE_2COLLATIONS, - ER(ER_CANT_AGGREGATE_2COLLATIONS), MYF(0), - c1.collation->name, c1.derivation_name(), - c2.collation->name, c2.derivation_name(), - fname); + my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), + c1.collation->name, c1.derivation_name(), + c2.collation->name, c2.derivation_name(), + fname); } uint nr_of_decimals(const char *str) @@ -2219,8 +2218,7 @@ void Item_func_set_collation::fix_length_and_dec() { if (!(set_collation= get_charset_by_name(colname,MYF(0)))) { - my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), - colname); + my_error(ER_UNKNOWN_COLLATION, MYF(0), colname); return; } } @@ -2228,9 +2226,8 @@ void Item_func_set_collation::fix_length_and_dec() if (!set_collation || !my_charset_same(args[0]->collation.collation,set_collation)) { - my_printf_error(ER_COLLATION_CHARSET_MISMATCH, - ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), - colname, args[0]->collation.collation->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + colname, args[0]->collation.collation->csname); return; } collation.set(set_collation, DERIVATION_EXPLICIT); diff --git a/sql/lock.cc b/sql/lock.cc index 76b85946a4a..c4f1d681b76 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -430,8 +430,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, *write_lock_used=table; if (table->db_stat & HA_READ_ONLY) { - my_printf_error(ER_OPEN_AS_READONLY, ER(ER_OPEN_AS_READONLY), MYF(0), - table->table_name); + my_error(ER_OPEN_AS_READONLY, MYF(0), table->table_name); my_free((gptr) sql_lock,MYF(0)); return 0; } diff --git a/sql/log.cc b/sql/log.cc index 7f273247c6f..8f7e15d0db8 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1517,8 +1517,7 @@ err: if (my_errno == EFBIG) my_message(ER_TRANS_CACHE_FULL, ER(ER_TRANS_CACHE_FULL), MYF(0)); else - my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), - name, errno); + my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno); write_error=1; } if (file == &log_file) diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 91b29ce9b61..6c3a81384a6 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -350,8 +350,7 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, if (stat_info.st_size > INT_MAX-1) { - my_printf_error(ER_FPARSER_TOO_BIG_FILE, - ER(ER_FPARSER_TOO_BIG_FILE), MYF(0), file_name->str); + my_error(ER_FPARSER_TOO_BIG_FILE, MYF(0), file_name->str); DBUG_RETURN(0); } @@ -413,8 +412,7 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root, frm_error: if (bad_format_errors) { - my_printf_error(ER_FPARSER_BAD_HEADER, ER(ER_FPARSER_BAD_HEADER), MYF(0), - file_name->str); + my_error(ER_FPARSER_BAD_HEADER, MYF(0), file_name->str); DBUG_RETURN(0); } else @@ -627,8 +625,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, // it is comment if (!(ptr= strchr(ptr, '\n'))) { - my_printf_error(ER_FPARSER_EOF_IN_COMMENT, - ER(ER_FPARSER_EOF_IN_COMMENT), MYF(0), line); + my_error(ER_FPARSER_EOF_IN_COMMENT, MYF(0), line); DBUG_RETURN(TRUE); } ptr++; @@ -670,9 +667,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, (LEX_STRING *)(base + parameter->offset)))) { - my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, - ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), - parameter->name.str, line); + my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } break; @@ -683,9 +679,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, (LEX_STRING *) (base + parameter->offset)))) { - my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, - ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), - parameter->name.str, line); + my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } break; @@ -694,9 +689,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, case FILE_OPTIONS_REV: if (!(eol= strchr(ptr, '\n'))) { - my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, - ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), - parameter->name.str, line); + my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } { @@ -713,9 +707,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, /* yyyy-mm-dd HH:MM:SS = 19(PARSE_FILE_TIMESTAMPLENGTH) characters */ if (ptr[PARSE_FILE_TIMESTAMPLENGTH] != '\n') { - my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, - ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), - parameter->name.str, line); + my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), + parameter->name.str, line); DBUG_RETURN(TRUE); } memcpy(val->str, ptr, PARSE_FILE_TIMESTAMPLENGTH); @@ -754,9 +747,8 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, break; list_err_w_message: - my_printf_error(ER_FPARSER_ERROR_IN_PARAMETER, - ER(ER_FPARSER_ERROR_IN_PARAMETER), MYF(0), - parameter->name.str, line); + my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), + parameter->name.str, line); list_err: DBUG_RETURN(TRUE); } @@ -769,9 +761,7 @@ File_parser::parse(gptr base, MEM_ROOT *mem_root, // skip unknown parameter if (!(ptr= strchr(ptr, '\n'))) { - my_printf_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, - ER(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER), MYF(0), - line); + my_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, MYF(0), line); DBUG_RETURN(TRUE); } ptr++; diff --git a/sql/procedure.cc b/sql/procedure.cc index 7779f5ce085..420a4f6262b 100644 --- a/sql/procedure.cc +++ b/sql/procedure.cc @@ -65,8 +65,7 @@ setup_procedure(THD *thd,ORDER *param,select_result *result, DBUG_RETURN(proc); } } - my_printf_error(ER_UNKNOWN_PROCEDURE,ER(ER_UNKNOWN_PROCEDURE),MYF(0), - (*param->item)->name); + my_error(ER_UNKNOWN_PROCEDURE, MYF(0), (*param->item)->name); *error=1; DBUG_RETURN(0); } diff --git a/sql/protocol.cc b/sql/protocol.cc index e0d256fbe87..88be2710422 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -127,7 +127,6 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) thd->net.report_error= 0; /* Abort multi-result sets */ - thd->lex->found_colon= 0; thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS; DBUG_VOID_RETURN; } diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index d49afb5f59d..5f67143065b 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -449,9 +449,8 @@ bool show_new_master(THD* thd) if (translate_master(thd, lex_mi, errmsg)) { if (errmsg[0]) - my_printf_error(ER_ERROR_WHEN_EXECUTING_COMMAND, - ER(ER_ERROR_WHEN_EXECUTING_COMMAND), MYF(0), - "SHOW NEW MASTER", errmsg); + my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), + "SHOW NEW MASTER", errmsg); DBUG_RETURN(TRUE); } else @@ -790,8 +789,7 @@ bool load_master_data(THD* thd) if (connect_to_master(thd, &mysql, active_mi)) { - my_printf_error(error= ER_CONNECT_TO_MASTER, - ER(ER_CONNECT_TO_MASTER), MYF(0), mysql_error(&mysql)); + my_error(error= ER_CONNECT_TO_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -803,8 +801,7 @@ bool load_master_data(THD* thd) if (mysql_real_query(&mysql, "SHOW DATABASES", 14) || !(db_res = mysql_store_result(&mysql))) { - my_printf_error(error = ER_QUERY_ON_MASTER, - ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); + my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -831,8 +828,7 @@ bool load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW MASTER STATUS",18) || !(master_status_res = mysql_store_result(&mysql))) { - my_printf_error(error = ER_QUERY_ON_MASTER, - ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); + my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } @@ -885,8 +881,7 @@ bool load_master_data(THD* thd) mysql_real_query(&mysql, "SHOW TABLES", 11) || !(*cur_table_res = mysql_store_result(&mysql))) { - my_printf_error(error = ER_QUERY_ON_MASTER, - ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); + my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); cleanup_mysql_results(db_res, cur_table_res - 1, table_res); goto err; } @@ -943,8 +938,7 @@ bool load_master_data(THD* thd) if (mysql_real_query(&mysql, "UNLOCK TABLES", 13)) { - my_printf_error(error = ER_QUERY_ON_MASTER, - ER(ER_QUERY_ON_MASTER), MYF(0), mysql_error(&mysql)); + my_error(error= ER_QUERY_ON_MASTER, MYF(0), mysql_error(&mysql)); goto err; } } @@ -953,7 +947,7 @@ bool load_master_data(THD* thd) 0 /* not only reset, but also reinit */, &errmsg)) { - my_printf_error(ER_RELAY_LOG_FAIL, ER(ER_RELAY_LOG_FAIL), MYF(0), errmsg); + my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); unlock_slave_threads(active_mi); pthread_mutex_unlock(&LOCK_active_mi); return TRUE; diff --git a/sql/set_var.cc b/sql/set_var.cc index a183f815a59..e5f3e17d17d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -899,8 +899,8 @@ bool sys_var_str::check(THD *thd, set_var *var) return 0; if ((res=(*check_func)(thd, var)) < 0) - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), - name, var->value->str_value.ptr()); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), + name, var->value->str_value.ptr()); return res; } @@ -1174,8 +1174,7 @@ static int check_max_delayed_threads(THD *thd, set_var *var) val != (longlong) global_system_variables.max_insert_delayed_threads) { char buf[64]; - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), - MYF(0), var->var->name, llstr(val, buf)); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf)); return 1; } return 0; @@ -1473,8 +1472,7 @@ bool sys_var::check_enum(THD *thd, set_var *var, TYPELIB *enum_names) return 0; err: - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), - name, value); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value); return 1; } @@ -1515,8 +1513,7 @@ bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) return 0; err: - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), - MYF(0), name, buff); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff); return 1; } @@ -1540,9 +1537,8 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) { if (var_type != OPT_DEFAULT) { - my_printf_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, - ER(ER_INCORRECT_GLOBAL_LOCAL_VAR), MYF(0), - name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); + my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), + name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); return 0; } /* As there was no local variable, return the global value */ @@ -1585,8 +1581,7 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) return tmp; } default: - my_printf_error(ER_VAR_CANT_BE_READ, ER(ER_VAR_CANT_BE_READ), MYF(0), - name); + my_error(ER_VAR_CANT_BE_READ, MYF(0), name); } return 0; } @@ -1698,8 +1693,7 @@ bool sys_var_thd_date_time_format::check(THD *thd, set_var *var) if (!(format= date_time_format_make(date_time_type, res->ptr(), res->length()))) { - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), - name, res->c_ptr()); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr()); return 1; } @@ -1797,14 +1791,12 @@ bool sys_var_collation::check(THD *thd, set_var *var) String str(buff,sizeof(buff), system_charset_info), *res; if (!(res=var->value->val_str(&str))) { - my_printf_error(ER_WRONG_VALUE_FOR_VAR, ER(ER_WRONG_VALUE_FOR_VAR), - MYF(0), name, "NULL"); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); return 1; } if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) { - my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), - res->c_ptr()); + my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr()); return 1; } } @@ -1814,8 +1806,7 @@ bool sys_var_collation::check(THD *thd, set_var *var) { char buf[20]; int10_to_str((int) var->value->val_int(), buf, -10); - my_printf_error(ER_UNKNOWN_COLLATION, ER(ER_UNKNOWN_COLLATION), MYF(0), - buf); + my_error(ER_UNKNOWN_COLLATION, MYF(0), buf); return 1; } } @@ -1836,8 +1827,7 @@ bool sys_var_character_set::check(THD *thd, set_var *var) { if (!nullable) { - my_printf_error(ER_WRONG_VALUE_FOR_VAR, - ER(ER_WRONG_VALUE_FOR_VAR), MYF(0), name, "NULL"); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); return 1; } tmp= NULL; @@ -1845,8 +1835,7 @@ bool sys_var_character_set::check(THD *thd, set_var *var) else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && !(tmp=get_old_charset_by_name(res->c_ptr()))) { - my_printf_error(ER_UNKNOWN_CHARACTER_SET, ER(ER_UNKNOWN_CHARACTER_SET), - MYF(0), res->c_ptr()); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); return 1; } } @@ -2443,8 +2432,7 @@ bool sys_var_thd_time_zone::check(THD *thd, set_var *var) if (!(var->save_result.time_zone= my_tz_find(res, thd->lex->time_zone_tables_used))) { - my_printf_error(ER_UNKNOWN_TIME_ZONE, ER(ER_UNKNOWN_TIME_ZONE), MYF(0), - res ? res->c_ptr() : "NULL"); + my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL"); return 1; } return 0; @@ -2726,8 +2714,7 @@ sys_var *find_sys_var(const char *str, uint length) length ? length : strlen(str)); if (!var) - my_printf_error(ER_UNKNOWN_SYSTEM_VARIABLE, ER(ER_UNKNOWN_SYSTEM_VARIABLE), - MYF(0), (char*) str); + my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); return var; } @@ -2814,7 +2801,7 @@ int set_var::check(THD *thd) if (var->check_type(type)) { int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; - my_printf_error(err, ER(err), MYF(0), var->name); + my_error(err, MYF(0), var->name); return -1; } if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL))) @@ -2824,7 +2811,7 @@ int set_var::check(THD *thd) { if (var->check_default(type)) { - my_printf_error(ER_NO_DEFAULT, ER(ER_NO_DEFAULT), MYF(0), var->name); + my_error(ER_NO_DEFAULT, MYF(0), var->name); return -1; } return 0; @@ -2834,8 +2821,7 @@ int set_var::check(THD *thd) return -1; if (var->check_update_type(value->result_type())) { - my_printf_error(ER_WRONG_TYPE_FOR_VAR, ER(ER_WRONG_TYPE_FOR_VAR), MYF(0), - var->name); + my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name); return -1; } return var->check(thd, this) ? -1 : 0; @@ -2859,7 +2845,7 @@ int set_var::light_check(THD *thd) if (var->check_type(type)) { int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; - my_printf_error(err, ER(err), MYF(0), var->name); + my_error(err, MYF(0), var->name); return -1; } if (type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)) @@ -2986,8 +2972,7 @@ bool sys_var_thd_storage_engine::check(THD *thd, set_var *var) value= "unknown"; err: - my_printf_error(ER_UNKNOWN_STORAGE_ENGINE, ER(ER_UNKNOWN_STORAGE_ENGINE), - MYF(0), value); + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value); return 1; } diff --git a/sql/share/czech/errmsg.txt b/sql/share/czech/errmsg.txt index 68816534d3a..c6ee78ffbb2 100644 --- a/sql/share/czech/errmsg.txt +++ b/sql/share/czech/errmsg.txt @@ -418,3 +418,5 @@ character-set=latin2 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/danish/errmsg.txt b/sql/share/danish/errmsg.txt index f475c9cd371..37b523526ce 100644 --- a/sql/share/danish/errmsg.txt +++ b/sql/share/danish/errmsg.txt @@ -409,3 +409,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/dutch/errmsg.txt b/sql/share/dutch/errmsg.txt index 471997e8a22..7cf441e899d 100644 --- a/sql/share/dutch/errmsg.txt +++ b/sql/share/dutch/errmsg.txt @@ -418,3 +418,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/english/errmsg.txt b/sql/share/english/errmsg.txt index 293227e64b9..990e3819053 100644 --- a/sql/share/english/errmsg.txt +++ b/sql/share/english/errmsg.txt @@ -406,3 +406,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/estonian/errmsg.txt b/sql/share/estonian/errmsg.txt index 59e55207946..ff2f2a922ce 100644 --- a/sql/share/estonian/errmsg.txt +++ b/sql/share/estonian/errmsg.txt @@ -411,3 +411,5 @@ character-set=latin7 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/french/errmsg.txt b/sql/share/french/errmsg.txt index be6c440b509..2403eec4b60 100644 --- a/sql/share/french/errmsg.txt +++ b/sql/share/french/errmsg.txt @@ -406,3 +406,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/german/errmsg.txt b/sql/share/german/errmsg.txt index 3afdd3ab496..757274bf1d5 100644 --- a/sql/share/german/errmsg.txt +++ b/sql/share/german/errmsg.txt @@ -419,3 +419,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/greek/errmsg.txt b/sql/share/greek/errmsg.txt index b0b158f5851..ce8fece95e7 100644 --- a/sql/share/greek/errmsg.txt +++ b/sql/share/greek/errmsg.txt @@ -406,3 +406,5 @@ character-set=greek "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/hungarian/errmsg.txt b/sql/share/hungarian/errmsg.txt index ba5f662a196..e93970e7eb8 100644 --- a/sql/share/hungarian/errmsg.txt +++ b/sql/share/hungarian/errmsg.txt @@ -411,3 +411,5 @@ character-set=latin2 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/italian/errmsg.txt b/sql/share/italian/errmsg.txt index d7ce95f8ed3..1745c31f114 100644 --- a/sql/share/italian/errmsg.txt +++ b/sql/share/italian/errmsg.txt @@ -406,3 +406,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/japanese/errmsg.txt b/sql/share/japanese/errmsg.txt index 56df55f3db4..969bacc8d8f 100644 --- a/sql/share/japanese/errmsg.txt +++ b/sql/share/japanese/errmsg.txt @@ -410,3 +410,5 @@ character-set=ujis "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/korean/errmsg.txt b/sql/share/korean/errmsg.txt index 1672dcb7dc6..cdb67ba004c 100644 --- a/sql/share/korean/errmsg.txt +++ b/sql/share/korean/errmsg.txt @@ -406,3 +406,5 @@ character-set=euckr "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/norwegian-ny/errmsg.txt b/sql/share/norwegian-ny/errmsg.txt index 187bab28cf1..35b5a3d464b 100644 --- a/sql/share/norwegian-ny/errmsg.txt +++ b/sql/share/norwegian-ny/errmsg.txt @@ -408,3 +408,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/norwegian/errmsg.txt b/sql/share/norwegian/errmsg.txt index ba1d11aa158..bb34b3d653c 100644 --- a/sql/share/norwegian/errmsg.txt +++ b/sql/share/norwegian/errmsg.txt @@ -408,3 +408,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/polish/errmsg.txt b/sql/share/polish/errmsg.txt index 9d9940ca69d..e4dfb9442dd 100644 --- a/sql/share/polish/errmsg.txt +++ b/sql/share/polish/errmsg.txt @@ -411,3 +411,5 @@ character-set=latin2 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/portuguese/errmsg.txt b/sql/share/portuguese/errmsg.txt index 214b4753f1c..9b229613936 100644 --- a/sql/share/portuguese/errmsg.txt +++ b/sql/share/portuguese/errmsg.txt @@ -408,3 +408,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/romanian/errmsg.txt b/sql/share/romanian/errmsg.txt index 2019bcc98f5..422143ea706 100644 --- a/sql/share/romanian/errmsg.txt +++ b/sql/share/romanian/errmsg.txt @@ -411,3 +411,5 @@ character-set=latin2 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/russian/errmsg.txt b/sql/share/russian/errmsg.txt index 3354d6a7ee5..2da6cbdfc1a 100644 --- a/sql/share/russian/errmsg.txt +++ b/sql/share/russian/errmsg.txt @@ -411,3 +411,5 @@ character-set=koi8r "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/serbian/errmsg.txt b/sql/share/serbian/errmsg.txt index 385f6f2044c..0abc324dfc8 100644 --- a/sql/share/serbian/errmsg.txt +++ b/sql/share/serbian/errmsg.txt @@ -399,3 +399,5 @@ character-set=cp1250 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/slovak/errmsg.txt b/sql/share/slovak/errmsg.txt index 8ee06be1128..862ca741640 100644 --- a/sql/share/slovak/errmsg.txt +++ b/sql/share/slovak/errmsg.txt @@ -414,3 +414,5 @@ character-set=latin2 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/spanish/errmsg.txt b/sql/share/spanish/errmsg.txt index 2215da6d57e..d3a4a029768 100644 --- a/sql/share/spanish/errmsg.txt +++ b/sql/share/spanish/errmsg.txt @@ -410,3 +410,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/swedish/errmsg.txt b/sql/share/swedish/errmsg.txt index 92ef9e1659b..1b445e509c1 100644 --- a/sql/share/swedish/errmsg.txt +++ b/sql/share/swedish/errmsg.txt @@ -406,3 +406,5 @@ character-set=latin1 "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/share/ukrainian/errmsg.txt b/sql/share/ukrainian/errmsg.txt index c1f86886870..a7b139bc2c3 100644 --- a/sql/share/ukrainian/errmsg.txt +++ b/sql/share/ukrainian/errmsg.txt @@ -412,3 +412,5 @@ character-set=koi8u "Binary logging and replication forbid changing the global server %s" "Can't map file: %-.64s, errno: %d" "Wrong magic in %-.64s" +"Prepared statement contains too many placeholders" +"Key part '%-.64s' length cannot be 0" diff --git a/sql/slave.cc b/sql/slave.cc index d14e9784834..34785f1a18f 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1502,7 +1502,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, err_msg= (char*) net->read_pos + ((mysql->server_capabilities & CLIENT_PROTOCOL_41) ? 3+SQLSTATE_LENGTH+1 : 3); - my_printf_error(ER_MASTER, ER(ER_MASTER), MYF(0), err_msg); + my_error(ER_MASTER, MYF(0), err_msg); DBUG_RETURN(1); } thd->command = COM_TABLE_DUMP; @@ -1580,8 +1580,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db, error=file->repair(thd,&check_opt) != 0; thd->net.vio = save_vio; if (error) - my_printf_error(ER_INDEX_REBUILD, ER(ER_INDEX_REBUILD), MYF(0), - tables.table->real_name); + my_error(ER_INDEX_REBUILD, MYF(0), tables.table->real_name); err: close_thread_tables(thd); @@ -1608,8 +1607,7 @@ int fetch_master_table(THD *thd, const char *db_name, const char *table_name, } if (connect_to_master(thd, mysql, mi)) { - my_printf_error(ER_CONNECT_TO_MASTER, ER(ER_CONNECT_TO_MASTER), MYF(0), - mysql_error(mysql)); + my_error(ER_CONNECT_TO_MASTER, MYF(0), mysql_error(mysql)); mysql_close(mysql); DBUG_RETURN(1); } diff --git a/sql/sp.cc b/sql/sp.cc index bf1ad5d5fcf..5798eedbad9 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -1001,8 +1001,7 @@ sp_cache_functions(THD *thd, LEX *lex) { delete newlex; thd->lex= oldlex; - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - "FUNCTION", ls->str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION", ls->str); ret= 1; break; } @@ -1164,7 +1163,7 @@ sp_change_db(THD *thd, char *name, bool no_access_check) { if ((db_length > NAME_LEN) || check_db_name(dbname)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname); + my_error(ER_WRONG_DB_NAME, MYF(0), dbname); x_free(dbname); DBUG_RETURN(1); } @@ -1183,11 +1182,10 @@ sp_change_db(THD *thd, char *name, bool no_access_check) if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - my_printf_error(ER_DBACCESS_DENIED_ERROR, ER(ER_DBACCESS_DENIED_ERROR), - MYF(0), - thd->priv_user, - thd->priv_host, - dbname); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->priv_host, @@ -1203,7 +1201,7 @@ sp_change_db(THD *thd, char *name, bool no_access_check) path[length-1]=0; // remove ending '\' if (access(path,F_OK)) { - my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname); + my_error(ER_BAD_DB_ERROR, MYF(0), dbname); my_free(dbname,MYF(0)); DBUG_RETURN(1); } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index f07bb89e154..7db79128bb8 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -544,8 +544,8 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp) { // Need to use my_printf_error here, or it will not terminate the // invoking query properly. - my_printf_error(ER_SP_WRONG_NO_OF_ARGS, ER(ER_SP_WRONG_NO_OF_ARGS), MYF(0), - "FUNCTION", m_name.str, params, argcount); + my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), + "FUNCTION", m_name.str, params, argcount); DBUG_RETURN(-1); } @@ -596,8 +596,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, Item **resp) *resp= it; else { - my_printf_error(ER_SP_NORETURNEND, ER(ER_SP_NORETURNEND), MYF(0), - m_name.str); + my_error(ER_SP_NORETURNEND, MYF(0), m_name.str); ret= -1; } } @@ -623,8 +622,8 @@ sp_head::execute_procedure(THD *thd, List *args) if (args->elements != params) { - my_printf_error(ER_SP_WRONG_NO_OF_ARGS, ER(ER_SP_WRONG_NO_OF_ARGS), MYF(0), - "PROCEDURE", m_name.str, params, args->elements); + my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), "PROCEDURE", + m_name.str, params, args->elements); DBUG_RETURN(-1); } @@ -893,8 +892,7 @@ sp_head::check_backpatch(THD *thd) { if (bp->lab->type == SP_LAB_REF) { - my_printf_error(ER_SP_LILABEL_MISMATCH, ER(ER_SP_LILABEL_MISMATCH), - MYF(0), "GOTO", bp->lab->name); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "GOTO", bp->lab->name); return -1; } } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index cd20888cb98..1ad125beb0e 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1534,9 +1534,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, if (combo.password.length != SCRAMBLED_PASSWORD_CHAR_LENGTH && combo.password.length != SCRAMBLED_PASSWORD_CHAR_LENGTH_323) { - my_printf_error(ER_UNKNOWN_ERROR, - "Password hash should be a %d-digit hexadecimal number", - MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH); + my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH); DBUG_RETURN(-1); } password_len= combo.password.length; @@ -1552,8 +1550,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, /* what == 'N' means revoke */ if (what == 'N') { - my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRAN), MYF(0), - combo.user.str, combo.host.str); + my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); goto end; } /* @@ -1570,9 +1567,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, else if (((thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER) && !password_len) || !create_user) { - my_printf_error(ER_NO_PERMISSION_TO_CREATE_USER, - ER(ER_NO_PERMISSION_TO_CREATE_USER), MYF(0), - thd->user, thd->host_or_ip); + my_error(ER_NO_PERMISSION_TO_CREATE_USER, MYF(0), + thd->user, thd->host_or_ip); goto end; } old_row_exists = 0; @@ -1760,8 +1756,7 @@ static int replace_db_table(TABLE *table, const char *db, { if (what == 'N') { // no row, no revoke - my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRANT), MYF(0), - combo.user.str, combo.host.str); + my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); goto abort; } old_row_exists = 0; @@ -2068,10 +2063,9 @@ static int replace_column_table(GRANT_TABLE *g_t, { if (revoke_grant) { - my_printf_error(ER_NONEXISTING_TABLE_GRANT, - ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), - combo.user.str, combo.host.str, - table_name); /* purecov: inspected */ + my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: inspected */ result= -1; /* purecov: inspected */ continue; /* purecov: inspected */ } @@ -2237,10 +2231,9 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, */ if (revoke_grant) { // no row, no revoke - my_printf_error(ER_NONEXISTING_TABLE_GRANT, - ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), - combo.user.str, combo.host.str, - table_name); /* purecov: deadcode */ + my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } old_row_exists = 0; @@ -2369,8 +2362,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, column->column.length(), 0, 0, 0, 0, &unused_field_idx)) { - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - column->column.c_ptr(), table_list->alias); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + column->column.c_ptr(), table_list->alias); DBUG_RETURN(TRUE); } column_priv|= column->rights; @@ -2385,8 +2378,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, fn_format(buf,buf,"","",4+16+32); if (access(buf,F_OK)) { - my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), - table_list->db, table_list->alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); DBUG_RETURN(TRUE); } } @@ -2474,9 +2466,8 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (revoke_grant) { - my_printf_error(ER_NONEXISTING_TABLE_GRANT, - ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), - Str->user.str, Str->host.str, table_list->real_name); + my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), + Str->user.str, Str->host.str, table_list->real_name); result= TRUE; continue; } @@ -2920,12 +2911,11 @@ err: command= "create view"; else if (want_access & SHOW_VIEW_ACL) command= "show create view"; - my_printf_error(ER_TABLEACCESS_DENIED_ERROR, - ER(ER_TABLEACCESS_DENIED_ERROR), MYF(0), - command, - thd->priv_user, - thd->host_or_ip, - table ? table->real_name : "unknown"); + my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + table ? table->real_name : "unknown"); } DBUG_RETURN(1); } @@ -2971,21 +2961,18 @@ bool check_grant_column(THD *thd, GRANT_INFO *grant, } #endif - /* We must use my_printf_error() here! */ err: rw_unlock(&LOCK_grant); if (!show_tables) { char command[128]; get_privilege_desc(command, sizeof(command), want_access); - my_printf_error(ER_COLUMNACCESS_DENIED_ERROR, - ER(ER_COLUMNACCESS_DENIED_ERROR), - MYF(0), - command, - thd->priv_user, - thd->host_or_ip, - name, - table_name); + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + name, + table_name); } return 1; } @@ -3032,7 +3019,6 @@ bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant, rw_unlock(&LOCK_grant); return 0; - /* We must use my_printf_error() here! */ err: rw_unlock(&LOCK_grant); err2: @@ -3041,14 +3027,12 @@ err2: command= "select"; else if (want_access & INSERT_ACL) command= "insert"; - my_printf_error(ER_COLUMNACCESS_DENIED_ERROR, - ER(ER_COLUMNACCESS_DENIED_ERROR), - MYF(0), - command, - thd->priv_user, - thd->host_or_ip, - fields->name(), - table_name); + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + fields->name(), + table_name); return 1; } @@ -3232,9 +3216,8 @@ bool mysql_show_grants(THD *thd,LEX_USER *lex_user) } if (counter == acl_users.elements) { - my_printf_error(ER_NONEXISTING_GRANT, - ER(ER_NONEXISTING_GRANT), MYF(0), - lex_user->user.str, lex_user->host.str); + my_error(ER_NONEXISTING_GRANT, MYF(0), + lex_user->user.str, lex_user->host.str); DBUG_RETURN(TRUE); } diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 69b7b987152..2259d3bead8 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -81,18 +81,14 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val_real() < 0) { delete pc; - my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, - ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), - proc_name); + my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); DBUG_RETURN(0); } pc->max_tree_elements = (uint) (*param->item)->val_int(); param = param->next; if (param->next) // no third parameter possible { - my_printf_error(ER_WRONG_PARAMCOUNT_TO_PROCEDURE, - ER(ER_WRONG_PARAMCOUNT_TO_PROCEDURE), MYF(0), - proc_name); + my_error(ER_WRONG_PARAMCOUNT_TO_PROCEDURE, MYF(0), proc_name); DBUG_RETURN(0); } // second parameter @@ -100,9 +96,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val_real() < 0) { delete pc; - my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, - ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), - proc_name); + my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); DBUG_RETURN(0); } pc->max_treemem = (uint) (*param->item)->val_int(); @@ -111,8 +105,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, (*param->item)->val_real() < 0) { delete pc; - my_printf_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, - ER(ER_WRONG_PARAMETERS_TO_PROCEDURE), MYF(0), proc_name); + my_error(ER_WRONG_PARAMETERS_TO_PROCEDURE, MYF(0), proc_name); DBUG_RETURN(0); } // if only one parameter was given, it will be the value of max_tree_elements diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b32aa033209..5c9beb44e4c 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -891,8 +891,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, { if (table->query_id == thd->query_id) { - my_printf_error(ER_CANT_REOPEN_TABLE, - ER(ER_CANT_REOPEN_TABLE), MYF(0), table->table_name); + my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name); DBUG_RETURN(0); } table->query_id= thd->query_id; @@ -949,7 +948,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, VOID(pthread_mutex_unlock(&LOCK_open)); } } - my_printf_error(ER_TABLE_NOT_LOCKED,ER(ER_TABLE_NOT_LOCKED),MYF(0),alias); + my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias); DBUG_RETURN(0); } @@ -1262,8 +1261,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh) next=table->next; if (!tables || (!db_stat && reopen_table(table,1))) { - my_printf_error(ER_CANT_REOPEN_TABLE, ER(ER_CANT_REOPEN_TABLE), - MYF(0),table->table_name); + my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name); VOID(hash_delete(&open_cache,(byte*) table)); error=1; } @@ -1548,8 +1546,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db, { /* Give right error message */ thd->clear_error(); - my_printf_error(ER_NOT_KEYFILE, ER(ER_NOT_KEYFILE), MYF(0), - name, my_errno); + my_error(ER_NOT_KEYFILE, MYF(0), name, my_errno); sql_print_error("Couldn't repair table: %s.%s",db,name); if (entry->file) closefrm(entry); @@ -1614,8 +1611,7 @@ err: { TABLE_LIST * view= table_desc->belong_to_view; thd->clear_error(); - my_printf_error(ER_VIEW_INVALID, ER(ER_VIEW_INVALID), MYF(0), - view->view_db.str, view->view_name.str); + my_error(ER_VIEW_INVALID, MYF(0), view->view_db.str, view->view_name.str); } DBUG_RETURN(1); } @@ -1743,9 +1739,7 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table, if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ && (int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ) { - my_printf_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, - ER(ER_TABLE_NOT_LOCKED_FOR_WRITE), - MYF(0),table->table_name); + my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->table_name); DBUG_RETURN(1); } if ((error=table->file->start_stmt(thd))) @@ -2330,8 +2324,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, { if (report_error == REPORT_ALL_ERRORS || report_error == IGNORE_EXCEPT_NON_UNIQUE) - my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), - item->full_name(),thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), + item->full_name(),thd->where); return (Field*) 0; } found=find; @@ -2351,16 +2345,14 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, } if (report_error == REPORT_ALL_ERRORS || report_error == REPORT_EXCEPT_NON_UNIQUE) - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - table_name, thd->where); + my_error(ER_UNKNOWN_TABLE, MYF(0), table_name, thd->where); else return (Field*) not_found_field; } else if (report_error == REPORT_ALL_ERRORS || report_error == REPORT_EXCEPT_NON_UNIQUE) - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), - item->full_name(),thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(),thd->where); else return (Field*) not_found_field; return (Field*) 0; @@ -2373,8 +2365,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, { if (report_error == REPORT_ALL_ERRORS || report_error == REPORT_EXCEPT_NON_UNIQUE) - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), - item->full_name(),thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(),thd->where); return (Field*) not_found_field; } @@ -2399,8 +2390,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, break; if (report_error == REPORT_ALL_ERRORS || report_error == IGNORE_EXCEPT_NON_UNIQUE) - my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), - name,thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), name, thd->where); return (Field*) 0; } found=field; @@ -2410,8 +2400,7 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, return found; if (report_error == REPORT_ALL_ERRORS || report_error == REPORT_EXCEPT_NON_UNIQUE) - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), - MYF(0), item->full_name(), thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), item->full_name(), thd->where); else return (Field*) not_found_field; return (Field*) 0; @@ -2523,8 +2512,8 @@ find_item_in_list(Item *find, List &items, uint *counter, unaliased names only and will have duplicate error anyway. */ if (report_error != IGNORE_ERRORS) - my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), - MYF(0), find->full_name(), current_thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), + find->full_name(), current_thd->where); return (Item**) 0; } found_unaliased= li.ref(); @@ -2548,8 +2537,8 @@ find_item_in_list(Item *find, List &items, uint *counter, if ((*found)->eq(item, 0)) continue; // Same field twice if (report_error != IGNORE_ERRORS) - my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), - MYF(0), find->full_name(), current_thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), + find->full_name(), current_thd->where); return (Item**) 0; } found= li.ref(); @@ -2592,8 +2581,8 @@ find_item_in_list(Item *find, List &items, uint *counter, if (found_unaliased_non_uniq) { if (report_error != IGNORE_ERRORS) - my_printf_error(ER_NON_UNIQ_ERROR, ER(ER_NON_UNIQ_ERROR), MYF(0), - find->full_name(), current_thd->where); + my_error(ER_NON_UNIQ_ERROR, MYF(0), + find->full_name(), current_thd->where); return (Item **) 0; } if (found_unaliased) @@ -2608,8 +2597,8 @@ find_item_in_list(Item *find, List &items, uint *counter, if (report_error != REPORT_EXCEPT_NOT_FOUND) { if (report_error == REPORT_ALL_ERRORS) - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - find->full_name(), current_thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + find->full_name(), current_thd->where); return (Item **) 0; } else @@ -2822,9 +2811,8 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, (pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <= 0) { - my_printf_error(ER_KEY_COLUMN_DOES_NOT_EXITS, - ER(ER_KEY_COLUMN_DOES_NOT_EXITS), MYF(0), - name->c_ptr(), table->real_name); + my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), + name->c_ptr(), table->real_name); map->set_all(); return 1; } @@ -2994,14 +2982,12 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, fld->field_name) & VIEW_ANY_ACL))) { - my_printf_error(ER_COLUMNACCESS_DENIED_ERROR, - ER(ER_COLUMNACCESS_DENIED_ERROR), - MYF(0), - "ANY", - thd->priv_user, - thd->host_or_ip, - fld->field_name, - tab); + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + "ANY", + thd->priv_user, + thd->host_or_ip, + fld->field_name, + tab); goto err; } } @@ -3042,8 +3028,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, if (!table_name) my_message(ER_NO_TABLES_USED, ER(ER_NO_TABLES_USED), MYF(0)); else - my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), - table_name); + my_error(ER_BAD_TABLE_ERROR, MYF(0), table_name); err: DBUG_RETURN(1); @@ -3573,8 +3558,7 @@ open_new_frm(const char *path, const char *alias, { if (table_desc == 0 || table_desc->required_type == FRMTYPE_TABLE) { - my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), - db, table_name, "BASE TABLE"); + my_error(ER_WRONG_OBJECT, MYF(0), db, table_name, "BASE TABLE"); goto err; } if (mysql_make_view(parser, table_desc)) @@ -3583,8 +3567,7 @@ open_new_frm(const char *path, const char *alias, else { /* only VIEWs are supported now */ - my_printf_error(ER_FRM_UNKNOWN_TYPE, ER(ER_FRM_UNKNOWN_TYPE), MYF(0), - path, parser->type()->str); + my_error(ER_FRM_UNKNOWN_TYPE, MYF(0), path, parser->type()->str); goto err; } DBUG_RETURN(0); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6f236f42df9..e69c0f52c93 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -701,8 +701,8 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length) key_length + 1); if (!new_table) { - my_printf_error(EE_OUTOFMEMORY, ER(EE_OUTOFMEMORY), MYF(ME_BELL), - ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); + my_error(EE_OUTOFMEMORY, MYF(ME_BELL), + ALIGN_SIZE(sizeof(TABLE_LIST)) + key_length + 1); killed= KILL_CONNECTION; return 0; } @@ -1018,8 +1018,7 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange, if (!access(path, F_OK)) { - my_printf_error(ER_FILE_EXISTS_ERROR, ER(ER_FILE_EXISTS_ERROR), MYF(0), - exchange->file_name); + my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); return -1; } /* Create the file world readable */ @@ -1263,8 +1262,7 @@ bool select_dump::send_data(List &items) } else if (my_b_write(&cache,(byte*) res->ptr(),res->length())) { - my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), - path, my_errno); + my_error(ER_ERROR_ON_WRITE, MYF(0), path, my_errno); goto err; } } diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 42d6549f843..ad4887146d8 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -408,8 +408,7 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, { if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS)) { - my_printf_error(ER_DB_CREATE_EXISTS, ER(ER_DB_CREATE_EXISTS), MYF(0), - db); + my_error(ER_DB_CREATE_EXISTS, MYF(0), db); error= -1; goto exit; } @@ -419,13 +418,12 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, { if (my_errno != ENOENT) { - my_printf_error(EE_STAT, ER(EE_STAT), MYF(0), path, my_errno); + my_error(EE_STAT, MYF(0), path, my_errno); goto exit; } if (my_mkdir(path,0777,MYF(0)) < 0) { - my_printf_error(ER_CANT_CREATE_DB, ER(ER_CANT_CREATE_DB), - MYF(0), db, my_errno); + my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno); error= -1; goto exit; } @@ -579,7 +577,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) if (!if_exists) { error= -1; - my_printf_error(ER_DB_DROP_EXISTS, ER(ER_DB_DROP_EXISTS), MYF(0), db); + my_error(ER_DB_DROP_EXISTS, MYF(0), db); goto exit; } else @@ -803,8 +801,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, */ if (found_other_files) { - my_printf_error(ER_DB_DROP_RMDIR, ER(ER_DB_DROP_RMDIR), MYF(0), - org_path, EEXIST); + my_error(ER_DB_DROP_RMDIR, MYF(0), org_path, EEXIST); DBUG_RETURN(-1); } else @@ -867,8 +864,7 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error) *--pos=0; if (rmdir(path) < 0 && send_error) { - my_printf_error(ER_DB_DROP_RMDIR, ER(ER_DB_DROP_RMDIR), MYF(0), - path, errno); + my_error(ER_DB_DROP_RMDIR, MYF(0), path, errno); DBUG_RETURN(-1); } DBUG_RETURN(0); @@ -995,7 +991,7 @@ bool mysql_change_db(THD *thd, const char *name) } if (check_db_name(dbname)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname); + my_error(ER_WRONG_DB_NAME, MYF(0), dbname); x_free(dbname); DBUG_RETURN(1); } @@ -1008,11 +1004,10 @@ bool mysql_change_db(THD *thd, const char *name) thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - my_printf_error(ER_DBACCESS_DENIED_ERROR, - ER(ER_DBACCESS_DENIED_ERROR), MYF(0), - thd->priv_user, - thd->priv_host, - dbname); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->priv_host, @@ -1027,7 +1022,7 @@ bool mysql_change_db(THD *thd, const char *name) path[length-1]=0; // remove ending '\' if (access(path,F_OK)) { - my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname); + my_error(ER_BAD_DB_ERROR, MYF(0), dbname); my_free(dbname,MYF(0)); DBUG_RETURN(1); } diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 31363583806..a1ac6162b82 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -290,14 +290,12 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds) DBUG_RETURN(TRUE); if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), MYF(0), - table_list->alias, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); DBUG_RETURN(TRUE); } if (unique_table(table_list, table_list->next_global)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), MYF(0), - table_list->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, conds); @@ -354,8 +352,8 @@ bool mysql_multi_delete_prepare(THD *thd) if (!target_tbl->correspondent_table->updatable || check_key_in_view(thd, target_tbl->correspondent_table)) { - my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), - MYF(0), target_tbl->real_name, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), + target_tbl->real_name, "DELETE"); DBUG_RETURN(TRUE); } /* @@ -372,8 +370,8 @@ bool mysql_multi_delete_prepare(THD *thd) un->check_updateable(target_tbl->correspondent_table->db, target_tbl->correspondent_table->real_name)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), - MYF(0), target_tbl->correspondent_table->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), + target_tbl->correspondent_table->real_name); DBUG_RETURN(TRUE); } } @@ -736,8 +734,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) db_type table_type; if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN) { - my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), - table_list->db, table_list->real_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), + table_list->db, table_list->real_name); DBUG_RETURN(TRUE); } if (!ha_supports_generate(table_type)) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index e1df25ae724..853b3dd37c6 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -173,8 +173,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) { DBUG_PRINT("info",("duplicate '%s'", tables->alias)); if (! reopen) - my_printf_error(ER_NONUNIQ_TABLE, ER(ER_NONUNIQ_TABLE), - MYF(0), tables->alias); + my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias); goto err; } } @@ -198,7 +197,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) if (! (tables->table->file->table_flags() & HA_CAN_SQL_HANDLER)) { if (! reopen) - my_printf_error(ER_ILLEGAL_HA,ER(ER_ILLEGAL_HA),MYF(0), tables->alias); + my_error(ER_ILLEGAL_HA, MYF(0), tables->alias); mysql_ha_close(thd, tables); goto err; } @@ -257,11 +256,11 @@ err: will be closed. Broadcasts a COND_refresh condition. RETURN - 0 ok - != 0 error + FALSE ok + TRUE error */ -int mysql_ha_close(THD *thd, TABLE_LIST *tables) +bool mysql_ha_close(THD *thd, TABLE_LIST *tables) { TABLE_LIST *hash_tables; TABLE **table_ptr; @@ -299,15 +298,14 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables) } else { - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - tables->alias, "HANDLER"); + my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias, "HANDLER"); DBUG_PRINT("exit",("ERROR")); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } send_ok(thd); DBUG_PRINT("exit", ("OK")); - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } @@ -403,11 +401,9 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, strxnmov(buff, sizeof(buff), tables->db, ".", tables->real_name, NullS); else strncpy(buff, tables->alias, sizeof(buff)); - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - buff, "HANDLER"); + my_error(ER_UNKNOWN_TABLE, MYF(0), buff, "HANDLER"); #else - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - tables->alias, "HANDLER"); + my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias, "HANDLER"); #endif goto err0; } @@ -422,8 +418,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, { if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0) { - my_printf_error(ER_KEY_DOES_NOT_EXITS,ER(ER_KEY_DOES_NOT_EXITS),MYF(0), - keyname,tables->alias); + my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), keyname, tables->alias); goto err0; } table->file->ha_index_or_rnd_end(); @@ -491,8 +486,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, KEY_PART_INFO *key_part=keyinfo->key_part; if (key_expr->elements > keyinfo->key_parts) { - my_printf_error(ER_TOO_MANY_KEY_PARTS,ER(ER_TOO_MANY_KEY_PARTS), - MYF(0),keyinfo->key_parts); + my_error(ER_TOO_MANY_KEY_PARTS, MYF(0), keyinfo->key_parts); goto err; } List_iterator it_ke(*key_expr); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f39753f0e62..2fddaed5f45 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -58,9 +58,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, { if (values.elements != table->fields) { - my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, - ER(ER_WRONG_VALUE_COUNT_ON_ROW), - MYF(0),counter); + my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); return -1; } #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -82,9 +80,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, int res; if (fields.elements != values.elements) { - my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, - ER(ER_WRONG_VALUE_COUNT_ON_ROW), - MYF(0),counter); + my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); return -1; } @@ -100,8 +96,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List &fields, if (check_unique && thd->dupp_field) { - my_printf_error(ER_FIELD_SPECIFIED_TWICE, ER(ER_FIELD_SPECIFIED_TWICE), - MYF(0), thd->dupp_field->field_name); + my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name); return -1; } if (table->timestamp_field && // Don't set timestamp if used @@ -172,9 +167,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, table_list->db ? table_list->db : thd->db, table_list->real_name)) { - my_printf_error(ER_DELAYED_INSERT_TABLE_LOCKED, - ER(ER_DELAYED_INSERT_TABLE_LOCKED), - MYF(0), table_list->real_name); + my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0), + table_list->real_name); DBUG_RETURN(TRUE); } } @@ -228,9 +222,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, counter++; if (values->elements != value_count) { - my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, - ER(ER_WRONG_VALUE_COUNT_ON_ROW), - MYF(0),counter); + my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); goto abort; } if (setup_fields(thd, 0, table_list, *values, 0, 0, 0)) @@ -602,8 +594,7 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, (insert_into_view && check_view_insertability(table_list, thd->query_id))) { - my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), - MYF(0), table_list->alias, "INSERT"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "INSERT"); DBUG_RETURN(1); } DBUG_RETURN(0); @@ -650,8 +641,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table, if (unique_table(table_list, table_list->next_global)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), - MYF(0), table_list->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); DBUG_RETURN(TRUE); } thd->lex->select_lex.first_execution= 0; @@ -831,9 +821,7 @@ int check_that_all_fields_are_given_values(THD *thd, TABLE *entry) if ((*field)->query_id != thd->query_id && ((*field)->flags & NO_DEFAULT_VALUE_FLAG)) { - my_printf_error(ER_NO_DEFAULT_FOR_FIELD, - ER(ER_NO_DEFAULT_FOR_FIELD),MYF(0), - (*field)->field_name); + my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), (*field)->field_name); return 1; } } @@ -1325,8 +1313,7 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) if (!(di->table->file->table_flags() & HA_CAN_INSERT_DELAYED)) { thd->fatal_error(); - my_printf_error(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0), - di->table_list.real_name); + my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.real_name); goto end; } di->table->copy_blobs=1; @@ -1886,9 +1873,7 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) if (table->fields < values.elements) { - my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, - ER(ER_WRONG_VALUE_COUNT_ON_ROW), - MYF(0),1); + my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1); DBUG_RETURN(-1); } diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 4f5cf463fb6..d9e4943f322 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -125,8 +125,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, DBUG_RETURN(-1); if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), - MYF(0), table_list->alias, "LOAD"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD"); DBUG_RETURN(TRUE); } table= table_list->table; @@ -149,8 +148,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, DBUG_RETURN(TRUE); if (thd->dupp_field) { - my_printf_error(ER_FIELD_SPECIFIED_TWICE, ER(ER_FIELD_SPECIFIED_TWICE), - MYF(0), thd->dupp_field->field_name); + my_error(ER_FIELD_SPECIFIED_TWICE, MYF(0), thd->dupp_field->field_name); DBUG_RETURN(TRUE); } if (check_that_all_fields_are_given_values(thd, table)) @@ -223,8 +221,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ((stat_info.st_mode & S_IFREG) == S_IFREG || (stat_info.st_mode & S_IFIFO) == S_IFIFO))) { - my_printf_error(ER_TEXTFILE_NOT_READABLE, - ER(ER_TEXTFILE_NOT_READABLE), MYF(0), name); + my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name); DBUG_RETURN(TRUE); } if ((stat_info.st_mode & S_IFIFO) == S_IFIFO) diff --git a/sql/sql_map.cc b/sql/sql_map.cc index 917a8f2c30f..687e60b7c72 100644 --- a/sql/sql_map.cc +++ b/sql/sql_map.cc @@ -47,13 +47,12 @@ mapped_files::mapped_files(const my_string filename,byte *magic,uint magic_lengt 0L))) { error=errno; - my_printf_error(ER_NO_FILE_MAPPING, ER(ER_NO_FILE_MAPPING), MYF(0), - (my_string) name, error); + my_error(ER_NO_FILE_MAPPING, MYF(0), (my_string) name, error); } } if (map && memcmp(map,magic,magic_length)) { - my_printf_error(ER_WRONG_MAGIC, ER(ER_WRONG_MAGIC), MYF(0), name); + my_error(ER_WRONG_MAGIC, MYF(0), name); VOID(munmap(map,size)); map=0; } @@ -112,8 +111,7 @@ mapped_files *map_file(const my_string name,byte *magic,uint magic_length) { map->use_count++; if (!map->map) - my_printf_error(ER_NO_FILE_MAPPING, ER(ER_NO_FILE_MAPPING), MYF(0), - path, map->error); + my_error(ER_NO_FILE_MAPPING, MYF(0), path, map->error); } VOID(pthread_mutex_unlock(&LOCK_mapped_file)); return map; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 652a0493f6b..9d56ea27130 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1204,8 +1204,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd) if (!db || check_db_name(db)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME ,MYF(0), db ? db : "NULL"); goto err; } if (lower_case_table_names) @@ -1502,7 +1501,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, DBUG_PRINT("query",("%-.4096s",thd->query)); mysql_parse(thd,thd->query, thd->query_length); - while (!thd->killed && !thd->is_fatal_error && thd->lex->found_colon) + while (!thd->killed && thd->lex->found_colon && !thd->net.report_error) { char *packet= thd->lex->found_colon; /* @@ -1620,8 +1619,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, // null test to handle EOM if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); break; } if (check_access(thd,CREATE_ACL,db,0,1,0)) @@ -1630,7 +1628,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, bzero(&create_info, sizeof(create_info)); if (mysql_create_db(thd, (lower_case_table_names == 2 ? alias : db), &create_info, 0) < 0) - send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0); + error= TRUE; break; } case COM_DROP_DB: // QQ: To be removed @@ -1641,8 +1639,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* null test to handle EOM */ if (!db || !(alias= thd->strdup(db)) || check_db_name(db)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), - MYF(0), db ? db : "NULL"); + my_error(ER_WRONG_DB_NAME, MYF(0), db ? db : "NULL"); break; } if (check_access(thd,DROP_ACL,db,0,1,0)) @@ -1656,7 +1653,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, mysql_log.write(thd,command,db); if (mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : db), 0, 0) < 0) - send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0); + error= TRUE; break; } #ifndef EMBEDDED_LIBRARY @@ -2189,11 +2186,10 @@ mysql_execute_command(THD *thd) } else { - my_printf_error(ER_UNKNOWN_STMT_HANDLER, ER(ER_UNKNOWN_STMT_HANDLER), - MYF(0), - lex->prepared_stmt_name.length, - lex->prepared_stmt_name.str, - "DEALLOCATE PREPARE"); + my_error(ER_UNKNOWN_STMT_HANDLER, MYF(0), + lex->prepared_stmt_name.length, + lex->prepared_stmt_name.str, + "DEALLOCATE PREPARE"); goto error; } break; @@ -2386,8 +2382,7 @@ mysql_execute_command(THD *thd) } if (strlen(first_table->real_name) > NAME_LEN) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), - first_table->real_name); + my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->real_name); break; } pthread_mutex_lock(&LOCK_active_mi); @@ -2455,8 +2450,7 @@ mysql_execute_command(THD *thd) if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) && unique_table(create_table, select_tables)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), - MYF(0), create_table->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->real_name); goto create_error; } /* If we create merge table, we have to test tables in merge, too */ @@ -2469,8 +2463,7 @@ mysql_execute_command(THD *thd) { if (unique_table(tab, select_tables)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), - MYF(0), tab->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->real_name); goto create_error; } } @@ -2579,8 +2572,7 @@ create_error: ulong priv=0; if (lex->name && (!lex->name[0] || strlen(lex->name) > NAME_LEN)) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), - lex->name); + my_error(ER_WRONG_TABLE_NAME, MYF(0), lex->name); goto error; } if (!select_lex->db) @@ -3054,18 +3046,17 @@ create_error: remove_escape(db); // Fix escaped '_' if (check_db_name(db)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), db); + my_error(ER_WRONG_DB_NAME, MYF(0), db); goto error; } if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) goto error; /* purecov: inspected */ if (!thd->col_access && check_grant_db(thd,db)) { - my_printf_error(ER_DBACCESS_DENIED_ERROR, - ER(ER_DBACCESS_DENIED_ERROR), MYF(0), - thd->priv_user, - thd->priv_host, - db); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + db); goto error; } /* grant is checked in mysqld_show_tables */ @@ -3231,8 +3222,7 @@ create_error: char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3262,8 +3252,7 @@ create_error: char *alias; if (!(alias=thd->strdup(lex->name)) || check_db_name(lex->name)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3298,8 +3287,7 @@ create_error: { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } /* @@ -3333,8 +3321,7 @@ create_error: { if (!strip_sp(lex->name) || check_db_name(lex->name)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), - lex->name); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->name); break; } if (check_access(thd,SELECT_ACL,lex->name,0,1,0)) @@ -3356,8 +3343,7 @@ create_error: #ifdef HAVE_DLOPEN if ((sph= sp_find_function(thd, lex->spname))) { - my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), - lex->spname->m_name.str); + my_error(ER_UDF_EXISTS, MYF(0), lex->spname->m_name.str); goto error; } if (!(res = mysql_create_function(thd,&lex->udf))) @@ -3642,7 +3628,7 @@ create_error: if (udf) { - my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), name); + my_error(ER_UDF_EXISTS, MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; @@ -3652,7 +3638,7 @@ create_error: if (lex->sphead->m_type == TYPE_ENUM_FUNCTION && !lex->sphead->m_has_return) { - my_printf_error(ER_SP_NORETURN, ER(ER_SP_NORETURN), MYF(0), name); + my_error(ER_SP_NORETURN, MYF(0), name); delete lex->sphead; lex->sphead= 0; goto error; @@ -3667,22 +3653,19 @@ create_error: lex->sphead= 0; break; case SP_WRITE_ROW_FAILED: - my_printf_error(ER_SP_ALREADY_EXISTS, ER(ER_SP_ALREADY_EXISTS), MYF(0), - SP_TYPE_STRING(lex), name); + my_error(ER_SP_ALREADY_EXISTS, MYF(0), SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; case SP_NO_DB_ERROR: - my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), - lex->sphead->m_db.str); + my_error(ER_BAD_DB_ERROR, MYF(0), lex->sphead->m_db.str); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; goto error; default: - my_printf_error(ER_SP_STORE_FAILED, ER(ER_SP_STORE_FAILED), MYF(0), - SP_TYPE_STRING(lex), name); + my_error(ER_SP_STORE_FAILED, MYF(0), SP_TYPE_STRING(lex), name); lex->unit.cleanup(); delete lex->sphead; lex->sphead= 0; @@ -3696,8 +3679,7 @@ create_error: if (!(sp= sp_find_procedure(thd, lex->spname))) { - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), - MYF(0), "PROCEDURE", + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PROCEDURE", lex->spname->m_qname.str); goto error; } @@ -3795,12 +3777,12 @@ create_error: send_ok(thd); break; case SP_KEY_NOT_FOUND: - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - SP_COM_STRING(lex), lex->spname->m_qname.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; default: - my_printf_error(ER_SP_CANT_ALTER, ER(ER_SP_CANT_ALTER), MYF(0), - SP_COM_STRING(lex), lex->spname->m_qname.str); + my_error(ER_SP_CANT_ALTER, MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; } break; @@ -3862,12 +3844,12 @@ create_error: send_ok(thd); break; } - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - SP_COM_STRING(lex), lex->spname->m_qname.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; default: - my_printf_error(ER_SP_DROP_FAILED, ER(ER_SP_DROP_FAILED), MYF(0), - SP_COM_STRING(lex), lex->spname->m_qname.str); + my_error(ER_SP_DROP_FAILED, MYF(0), + SP_COM_STRING(lex), lex->spname->m_qname.str); goto error; } break; @@ -3876,14 +3858,13 @@ create_error: { if (lex->spname->m_name.length > NAME_LEN) { - my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), - lex->spname->m_name.str); + my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); goto error; } if (sp_show_create_procedure(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - SP_COM_STRING(lex), lex->spname->m_name.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } break; @@ -3892,14 +3873,13 @@ create_error: { if (lex->spname->m_name.length > NAME_LEN) { - my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), - lex->spname->m_name.str); + my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str); goto error; } if (sp_show_create_function(thd, lex->spname) != SP_OK) { /* We don't distinguish between errors for now */ - my_printf_error(ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), MYF(0), - SP_COM_STRING(lex), lex->spname->m_name.str); + my_error(ER_SP_DOES_NOT_EXIST, MYF(0), + SP_COM_STRING(lex), lex->spname->m_name.str); goto error; } break; @@ -4103,13 +4083,12 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, { // We can never grant this DBUG_PRINT("error",("No possible access")); if (!no_errors) - my_printf_error(ER_ACCESS_DENIED_ERROR, - ER(ER_ACCESS_DENIED_ERROR), MYF(0), - thd->priv_user, - thd->priv_host, - (thd->password ? - ER(ER_YES) : - ER(ER_NO)));/* purecov: tested */ + my_error(ER_ACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + (thd->password ? + ER(ER_YES) : + ER(ER_NO))); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ } @@ -4136,13 +4115,12 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_PRINT("error",("Access denied")); if (!no_errors) - my_printf_error(ER_DBACCESS_DENIED_ERROR, - ER(ER_DBACCESS_DENIED_ERROR), MYF(0), - thd->priv_user, - thd->priv_host, - (db ? db : (thd->db ? - thd->db : - "unknown"))); /* purecov: tested */ + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, + thd->priv_host, + (db ? db : (thd->db ? + thd->db : + "unknown"))); /* purecov: tested */ DBUG_RETURN(TRUE); /* purecov: tested */ #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4176,8 +4154,7 @@ bool check_global_access(THD *thd, ulong want_access) if ((thd->master_access & want_access)) return 0; get_privilege_desc(command, sizeof(command), want_access); - my_printf_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, - ER(ER_SPECIFIC_ACCESS_DENIED_ERROR), MYF(0), command); + my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); return 1; #endif /* NO_EMBEDDED_ACCESS_CHECKS */ } @@ -4331,8 +4308,7 @@ check_sp_definer_access(THD *thd, sp_head *sp) strncmp(thd->priv_host, hst->str, hst->length) == 0) return FALSE; /* Both user and host must match */ - my_printf_error(ER_SP_ACCESS_DENIED_ERROR, ER(ER_SP_ACCESS_DENIED_ERROR), - MYF(0), sp->m_qname.str); + my_error(ER_SP_ACCESS_DENIED_ERROR, MYF(0), sp->m_qname.str); return TRUE; /* Not definer or root */ } @@ -4710,8 +4686,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if (strlen(field_name) > NAME_LEN) { - my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), - field_name); /* purecov: inspected */ + my_error(ER_TOO_LONG_IDENT, MYF(0), field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } if (type_modifier & PRI_KEY_FLAG) @@ -4742,8 +4717,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC && type == FIELD_TYPE_TIMESTAMP)) { - my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), - field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } else if (default_value->type() == Item::NULL_ITEM) @@ -4752,23 +4726,20 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG) { - my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), - field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } else if (type_modifier & AUTO_INCREMENT_FLAG) { - my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), - field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } if (on_update_value && type != FIELD_TYPE_TIMESTAMP) { - my_printf_error(ER_INVALID_ON_UPDATE, ER(ER_INVALID_ON_UPDATE), MYF(0), - field_name); + my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name); DBUG_RETURN(1); } @@ -4894,9 +4865,8 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res=default_value->val_str(&str); if (res->length()) { - my_printf_error(ER_BLOB_CANT_HAVE_DEFAULT, - ER(ER_BLOB_CANT_HAVE_DEFAULT), MYF(0), - field_name); /* purecov: inspected */ + my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), + field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->def=0; @@ -4916,8 +4886,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, uint tmp_length=new_field->length; if (tmp_length > PRECISION_FOR_DOUBLE) { - my_printf_error(ER_WRONG_FIELD_SPEC, ER(ER_WRONG_FIELD_SPEC), MYF(0), - field_name); + my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); DBUG_RETURN(1); } else if (tmp_length > PRECISION_FOR_FLOAT) @@ -5014,8 +4983,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, { if (interval->count > sizeof(longlong)*8) { - my_printf_error(ER_TOO_BIG_SET, ER(ER_TOO_BIG_SET), MYF(0), - field_name); /* purecov: inspected */ + my_error(ER_TOO_BIG_SET, MYF(0), field_name); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } new_field->pack_length=(interval->count+7)/8; @@ -5041,8 +5009,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, ¬_used, ¬_used2, ¬_used3); if (thd->cuted_fields) { - my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), - field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } @@ -5064,8 +5031,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, res->strip_sp(); if (!find_type(interval, res->ptr(), res->length(), 0)) { - my_printf_error(ER_INVALID_DEFAULT, ER(ER_INVALID_DEFAULT), MYF(0), - field_name); + my_error(ER_INVALID_DEFAULT, MYF(0), field_name); DBUG_RETURN(1); } } @@ -5079,15 +5045,14 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type, type != FIELD_TYPE_STRING && type != FIELD_TYPE_VAR_STRING && type != FIELD_TYPE_GEOMETRY)) { - my_printf_error(ER_TOO_BIG_FIELDLENGTH, ER(ER_TOO_BIG_FIELDLENGTH), MYF(0), + my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), field_name, MAX_FIELD_CHARLENGTH);/* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } type_modifier&= AUTO_INCREMENT_FLAG; if ((~allowed_type_modifier) & type_modifier) { - my_printf_error(ER_WRONG_FIELD_SPEC, ER(ER_WRONG_FIELD_SPEC), MYF(0), - field_name); + my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name); DBUG_RETURN(1); } if (!new_field->pack_length) @@ -5217,8 +5182,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (check_table_name(table->table.str,table->table.length) || table->db.str && check_db_name(table->db.str)) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), - table->table.str); + my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); DBUG_RETURN(0); } @@ -5283,8 +5247,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && !strcmp(ptr->db, tables->db)) { - my_printf_error(ER_NONUNIQ_TABLE, ER(ER_NONUNIQ_TABLE), MYF(0), - alias_str); /* purecov: tested */ + my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */ DBUG_RETURN(0); /* purecov: tested */ } } @@ -5828,8 +5791,7 @@ static bool append_file_to_dir(THD *thd, const char **filename_ptr, if (strlen(*filename_ptr)+strlen(table_name) >= FN_REFLEN-1 || !test_if_hard_path(*filename_ptr)) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), - *filename_ptr); + my_error(ER_WRONG_TABLE_NAME, MYF(0), *filename_ptr); return 1; } /* Fix is using unix filename format on dos */ @@ -5863,8 +5825,7 @@ bool check_simple_select() char command[80]; strmake(command, lex->yylval->symbol.str, min(lex->yylval->symbol.length, sizeof(command)-1)); - my_printf_error(ER_CANT_USE_OPTION_HERE, ER(ER_CANT_USE_OPTION_HERE), - MYF(0), command); + my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command); return 1; } return 0; @@ -6010,7 +5971,7 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) if (select_lex->item_list.elements != lex->value_list.elements) { - my_printf_error(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); + my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0)); DBUG_RETURN(TRUE); } /* @@ -6113,8 +6074,8 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count) } if (!walk) { - my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), - target_tbl->real_name, "MULTI DELETE"); + my_error(ER_UNKNOWN_TABLE, MYF(0), + target_tbl->real_name, "MULTI DELETE"); DBUG_RETURN(TRUE); } walk->lock_type= target_tbl->lock_type; @@ -6288,8 +6249,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, find_table_in_global_list(tables, create_table->db, create_table->real_name)) { - net_printf(thd,ER_UPDATE_TABLE_USED, create_table->real_name); - + error= FALSE; goto err; } } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index e29f6329e58..9e3395cf893 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -926,9 +926,7 @@ static bool mysql_test_insert(Prepared_statement *stmt, counter++; if (values->elements != value_count) { - my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, - ER(ER_WRONG_VALUE_COUNT_ON_ROW), - MYF(0), counter); + my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter); goto error; } if (setup_fields(thd, 0, table_list, *values, 0, 0, 0)) @@ -1062,15 +1060,13 @@ static int mysql_test_select(Prepared_statement *stmt, DBUG_RETURN(TRUE); #endif - if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) - { - send_error(thd); - goto err; - } - - if ((result= open_and_lock_tables(thd, tables))) - goto err; result= TRUE; + if (!lex->result && !(lex->result= new (stmt->mem_root) select_send)) + goto err; + + if (open_and_lock_tables(thd, tables)) + goto err; + thd->used_tables= 0; // Updated by setup_fields @@ -1518,9 +1514,8 @@ static bool init_param_array(Prepared_statement *stmt) if (stmt->param_count > (uint) UINT_MAX16) { /* Error code to be defined in 5.0 */ - send_error(thd, ER_UNKNOWN_ERROR, - "Prepared statement contains too many placeholders."); - return 1; + my_message(ER_PS_MANY_PARAM, ER(ER_PS_MANY_PARAM), MYF(0)); + return TRUE; } Item_param **to; List_iterator param_iterator(lex->param_list); @@ -1529,7 +1524,7 @@ static bool init_param_array(Prepared_statement *stmt) alloc_root(stmt->thd->mem_root, sizeof(Item_param*) * stmt->param_count); if (!stmt->param_array) - return 1; + return TRUE; for (to= stmt->param_array; to < stmt->param_array + stmt->param_count; ++to) @@ -1537,7 +1532,7 @@ static bool init_param_array(Prepared_statement *stmt) *to= param_iterator++; } } - return 0; + return FALSE; } @@ -1659,9 +1654,6 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); stmt= NULL; - if (thd->net.report_error) - send_error(thd); - /* otherwise the error is sent inside yyparse/check_preapred_statement */ } else { @@ -1968,7 +1960,7 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt, alloc_query(thd, (char *)expanded_query->ptr(), expanded_query->length()+1)) { - my_error(ER_OUTOFMEMORY, 0, expanded_query->length()); + my_error(ER_OUTOFMEMORY, MYF(0), expanded_query->length()); DBUG_VOID_RETURN; } /* diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 25874e1335a..9f29a975441 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -157,8 +157,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) unpack_filename(name, name); if (!access(name,F_OK)) { - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); DBUG_RETURN(ren_table); // This can't be skipped } sprintf(name,"%s/%s/%s%s",mysql_data_home, @@ -167,8 +166,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) unpack_filename(name, name); if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN) { - my_printf_error(ER_FILE_NOT_FOUND, ER(ER_FILE_NOT_FOUND), MYF(0), - name, my_errno); + my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); if (!skip_error) DBUG_RETURN(ren_table); } diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 3ef7e01d248..d2e3e72618d 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1002,7 +1002,7 @@ int reset_slave(THD *thd, MASTER_INFO* mi) err: unlock_slave_threads(mi); if (error) - my_printf_error(sql_errno, ER(sql_errno), MYF(0), errmsg); + my_error(sql_errno, MYF(0), errmsg); DBUG_RETURN(error); } @@ -1195,8 +1195,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) 0 /* not only reset, but also reinit */, &errmsg)) { - my_printf_error(ER_RELAY_LOG_FAIL, ER(ER_RELAY_LOG_FAIL), MYF(0), - errmsg); + my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1212,7 +1211,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) 0 /*no data lock*/, &msg, 0)) { - my_printf_error(ER_RELAY_LOG_INIT, ER(ER_RELAY_LOG_INIT), MYF(0), msg); + my_error(ER_RELAY_LOG_INIT, MYF(0), msg); unlock_slave_threads(mi); DBUG_RETURN(TRUE); } @@ -1406,9 +1405,8 @@ err: if (errmsg) { - my_printf_error(ER_ERROR_WHEN_EXECUTING_COMMAND, - ER(ER_ERROR_WHEN_EXECUTING_COMMAND), MYF(0), - "SHOW BINLOG EVENTS", errmsg); + my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0), + "SHOW BINLOG EVENTS", errmsg); DBUG_RETURN(TRUE); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f0584837028..2f3687c28bd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1883,7 +1883,7 @@ Cursor::fetch(ulong num_rows) thd->server_status&= ~SERVER_STATUS_LAST_ROW_SENT; } else - send_error(thd, ER_OUT_OF_RESOURCES); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); /* free cursor memory */ free_items(free_list); free_list= 0; @@ -11220,8 +11220,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, uint count= (uint) order_item->val_int(); if (!count || count > fields.elements) { - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR), - MYF(0), order_item->full_name(), thd->where); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + order_item->full_name(), thd->where); return 1; } order->item= ref_pointer_array + count - 1; @@ -11371,8 +11371,7 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, (*order->item)->marker=1; /* Mark found */ if ((*order->item)->with_sum_func) { - my_printf_error(ER_WRONG_GROUP_FIELD, ER(ER_WRONG_GROUP_FIELD),MYF(0), - (*order->item)->full_name()); + my_error(ER_WRONG_GROUP_FIELD, MYF(0), (*order->item)->full_name()); return 1; } } @@ -11387,9 +11386,7 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, if (item->type() != Item::SUM_FUNC_ITEM && !item->marker && !item->const_item()) { - my_printf_error(ER_WRONG_FIELD_WITH_GROUP, - ER(ER_WRONG_FIELD_WITH_GROUP), - MYF(0),item->full_name()); + my_error(ER_WRONG_FIELD_WITH_GROUP, MYF(0), item->full_name()); return 1; } } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index b46834882c6..7a483086584 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -868,8 +868,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) /* TODO: add environment variables show when it become possible */ if (thd->lex->only_view && !table_list->view) { - my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), - table_list->db, table_list->real_name, "VIEW"); + my_error(ER_WRONG_OBJECT, MYF(0), + table_list->db, table_list->real_name, "VIEW"); DBUG_RETURN(TRUE); } @@ -938,7 +938,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname, if (check_db_name(dbname)) { - my_printf_error(ER_WRONG_DB_NAME, ER(ER_WRONG_DB_NAME), MYF(0), dbname); + my_error(ER_WRONG_DB_NAME, MYF(0), dbname); DBUG_RETURN(TRUE); } @@ -950,9 +950,8 @@ bool mysqld_show_create_db(THD *thd, char *dbname, thd->master_access); if (!(db_access & DB_ACLS) && (!grant_option || check_grant_db(thd,dbname))) { - my_printf_error(ER_DBACCESS_DENIED_ERROR, - ER(ER_DBACCESS_DENIED_ERROR), MYF(0), - thd->priv_user, thd->host_or_ip, dbname); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, thd->host_or_ip, dbname); mysql_log.write(thd,COM_INIT_DB,ER(ER_DBACCESS_DENIED_ERROR), thd->priv_user, thd->host_or_ip, dbname); DBUG_RETURN(TRUE); @@ -969,7 +968,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname, } if (access(path,F_OK)) { - my_printf_error(ER_BAD_DB_ERROR, ER(ER_BAD_DB_ERROR), MYF(0), dbname); + my_error(ER_BAD_DB_ERROR, MYF(0), dbname); DBUG_RETURN(TRUE); } if (found_libchar) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 301130c13ca..cb327990a78 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -84,9 +84,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, { if (thd->global_read_lock) { - my_printf_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, - ER(ER_TABLE_NOT_LOCKED_FOR_WRITE), MYF(0), - tables->real_name); + my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), tables->real_name); error= TRUE; goto err; } @@ -269,8 +267,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, if (wrong_tables.length()) { if (!foreign_key_error) - my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), - wrong_tables.c_ptr()); + my_error(ER_BAD_TABLE_ERROR, MYF(0), wrong_tables.c_ptr()); else my_message(ER_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED), MYF(0)); error= 1; @@ -470,8 +467,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (check_column_name(sql_field->field_name)) { - my_printf_error(ER_WRONG_COLUMN_NAME, ER(ER_WRONG_COLUMN_NAME), MYF(0), - sql_field->field_name); + my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name); DBUG_RETURN(-1); } @@ -488,8 +484,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, */ if (field_no < select_field_pos || dup_no >= select_field_pos) { - my_printf_error(ER_DUP_FIELDNAME, ER(ER_DUP_FIELDNAME), MYF(0), - sql_field->field_name); + my_error(ER_DUP_FIELDNAME, MYF(0), sql_field->field_name); DBUG_RETURN(-1); } else @@ -541,8 +536,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, #ifdef HAVE_SPATIAL if (!(file->table_flags() & HA_CAN_GEOMETRY)) { - my_printf_error(ER_CHECK_NOT_IMPLEMENTED, ER(ER_CHECK_NOT_IMPLEMENTED), - MYF(0), "GEOMETRY"); + my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "GEOMETRY"); DBUG_RETURN(-1); } sql_field->pack_flag=FIELDFLAG_GEOM | @@ -555,8 +549,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, blob_columns++; break; #else - my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED), MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); DBUG_RETURN(-1); #endif /*HAVE_SPATIAL*/ case FIELD_TYPE_VAR_STRING: @@ -676,11 +670,9 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (fk_key->ref_columns.elements && fk_key->ref_columns.elements != fk_key->columns.elements) { - my_printf_error(ER_WRONG_FK_DEF, ER(ER_WRONG_FK_DEF), MYF(0), - (fk_key->name ? - fk_key->name : - "foreign key without name"), - ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); + my_error(ER_WRONG_FK_DEF, MYF(0), + (fk_key->name ? fk_key->name : "foreign key without name"), + ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF)); DBUG_RETURN(-1); } continue; @@ -694,8 +686,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (key->name && strlen(key->name) > NAME_LEN) { - my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), - key->name); + my_error(ER_TOO_LONG_IDENT, MYF(0), key->name); DBUG_RETURN(-1); } key_iterator2.rewind (); @@ -735,8 +726,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, if (key->name && !tmp_table && !my_strcasecmp(system_charset_info,key->name,primary_key_name)) { - my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), - MYF(0), key->name); + my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name); DBUG_RETURN(-1); } } @@ -781,8 +771,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, key_info->flags= HA_SPATIAL; break; #else - my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED),MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); DBUG_RETURN(-1); #endif case Key::FOREIGN_KEY: @@ -822,8 +812,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { if (key_info->key_parts != 1) { - my_printf_error(ER_WRONG_ARGUMENTS, - ER(ER_WRONG_ARGUMENTS),MYF(0),"SPATIAL INDEX"); + my_error(ER_WRONG_ARGUMENTS, MYF(0), "SPATIAL INDEX"); DBUG_RETURN(-1); } } @@ -833,17 +822,15 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, #ifdef HAVE_RTREE_KEYS if ((key_info->key_parts & 1) == 1) { - my_printf_error(ER_WRONG_ARGUMENTS, - ER(ER_WRONG_ARGUMENTS),MYF(0),"RTREE INDEX"); + my_error(ER_WRONG_ARGUMENTS, MYF(0), "RTREE INDEX"); DBUG_RETURN(-1); } /* TODO: To be deleted */ - my_printf_error(ER_NOT_SUPPORTED_YET, ER(ER_NOT_SUPPORTED_YET), - MYF(0), "RTREE INDEX"); + my_error(ER_NOT_SUPPORTED_YET, MYF(0), "RTREE INDEX"); DBUG_RETURN(-1); #else - my_printf_error(ER_FEATURE_DISABLED,ER(ER_FEATURE_DISABLED),MYF(0), - sym_group_rtree.name, sym_group_rtree.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_rtree.name, sym_group_rtree.needed_define); DBUG_RETURN(-1); #endif } @@ -861,9 +848,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, field++; if (!sql_field) { - my_printf_error(ER_KEY_COLUMN_DOES_NOT_EXITS, - ER(ER_KEY_COLUMN_DOES_NOT_EXITS),MYF(0), - column->field_name); + my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name); DBUG_RETURN(-1); } /* for fulltext keys keyseg length is 1 for blobs (it's ignored in @@ -881,8 +866,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, sql_field->charset->mbminlen > 1 || // ucs2 doesn't work yet (ft_key_charset && sql_field->charset != ft_key_charset)) { - my_printf_error(ER_BAD_FT_COLUMN,ER(ER_BAD_FT_COLUMN),MYF(0), - column->field_name); + my_error(ER_BAD_FT_COLUMN, MYF(0), column->field_name); DBUG_RETURN(-1); } ft_key_charset=sql_field->charset; @@ -903,15 +887,12 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, { if (!(file->table_flags() & HA_CAN_INDEX_BLOBS)) { - my_printf_error(ER_BLOB_USED_AS_KEY,ER(ER_BLOB_USED_AS_KEY),MYF(0), - column->field_name); + my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name); DBUG_RETURN(-1); } if (!column->length) { - my_printf_error(ER_BLOB_KEY_WITHOUT_LENGTH, - ER(ER_BLOB_KEY_WITHOUT_LENGTH),MYF(0), - column->field_name); + my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name); DBUG_RETURN(-1); } } @@ -940,8 +921,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, key_info->flags|= HA_NULL_PART_KEY; if (!(file->table_flags() & HA_NULL_IN_KEY)) { - my_printf_error(ER_NULL_COLUMN_IN_INDEX,ER(ER_NULL_COLUMN_IN_INDEX), - MYF(0),column->field_name); + my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name); DBUG_RETURN(-1); } if (key->type == Key::SPATIAL) @@ -1001,8 +981,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } else if (length == 0) { - my_printf_error(ER_WRONG_KEY_COLUMN, ER(ER_WRONG_KEY_COLUMN), MYF(0), - column->field_name); + my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name); DBUG_RETURN(-1); } if (length > file->max_key_part_length()) @@ -1058,8 +1037,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, key_info_buffer,key_info); if (check_if_keyname_exists(key_name,key_info_buffer,key_info)) { - my_printf_error(ER_DUP_KEYNAME, ER(ER_DUP_KEYNAME), MYF(0), - key_name); + my_error(ER_DUP_KEYNAME, MYF(0), key_name); DBUG_RETURN(-1); } key_info->name=(char*) key_name; @@ -1067,8 +1045,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (!key_info->name || check_column_name(key_info->name)) { - my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), - MYF(0), key_info->name); + my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name); DBUG_RETURN(-1); } if (!(key_info->flags & HA_NULL_PART_KEY)) @@ -1177,7 +1154,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, if ((create_info->options & HA_LEX_CREATE_TMP_TABLE) && (file->table_flags() & HA_NO_TEMP_TABLES)) { - my_printf_error(ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), MYF(0), table_name); + my_error(ER_ILLEGAL_HA, MYF(0), table_name); DBUG_RETURN(TRUE); } #endif @@ -1228,8 +1205,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, create_info->table_existed= 1; // Mark that table existed DBUG_RETURN(FALSE); } - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), MYF(0), - alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); DBUG_RETURN(TRUE); } if (wait_if_global_read_lock(thd, 0, 1)) @@ -1245,8 +1221,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, error= FALSE; } else - my_printf_error(ER_TABLE_EXISTS_ERROR, - ER(ER_TABLE_EXISTS_ERROR), MYF(0), table_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); goto end; } } @@ -1275,8 +1250,7 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name, error= FALSE; } else - my_printf_error(ER_TABLE_EXISTS_ERROR, - ER(ER_TABLE_EXISTS_ERROR), MYF(0), table_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); goto end; } } @@ -1495,8 +1469,7 @@ mysql_rename_table(enum db_type base, } delete file; if (error) - my_printf_error(ER_ERROR_ON_RENAME, ER(ER_ERROR_ON_RENAME), - MYF(0), from, to, error); + my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error); DBUG_RETURN(error != 0); } @@ -2048,8 +2021,7 @@ bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables, if (!(key_cache= get_key_cache(key_cache_name))) { pthread_mutex_unlock(&LOCK_global_system_variables); - my_printf_error(ER_UNKNOWN_KEY_CACHE, ER(ER_UNKNOWN_KEY_CACHE), MYF(0), - key_cache_name->str); + my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str); DBUG_RETURN(TRUE); } pthread_mutex_unlock(&LOCK_global_system_variables); @@ -2159,8 +2131,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, check_table_name(src_table,table_ident->table.length)) || table_ident->db.str && check_db_name((src_db= table_ident->db.str))) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), MYF(0), - src_table); + my_error(ER_WRONG_TABLE_NAME, MYF(0), src_table); DBUG_RETURN(TRUE); } @@ -2179,8 +2150,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, reg_ext, NullS); if (access(src_path, F_OK)) { - my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), - src_table); + my_error(ER_BAD_TABLE_ERROR, MYF(0), src_table); goto err; } } @@ -2263,8 +2233,7 @@ table_exists: res= FALSE; } else - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), MYF(0), - table_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); err: pthread_mutex_lock(&LOCK_open); @@ -2523,8 +2492,7 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list, } if (idx>= table->keys) { - my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, ER(ER_CANT_DROP_FIELD_OR_KEY), - MYF(0), drop_key->name); + my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), drop_key->name); /*don't need to free((gptr) key_numbers);*/ DBUG_RETURN(-1); } @@ -2647,8 +2615,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (find_temporary_table(thd,new_db,new_name_buff)) { - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), new_name_buff); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff); DBUG_RETURN(TRUE); } } @@ -2660,8 +2627,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, F_OK)) { /* Table will be closed in do_command() */ - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); DBUG_RETURN(TRUE); } } @@ -2702,8 +2668,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, error=0; if (!access(new_name_buff,F_OK)) { - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), new_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name); error= -1; } else @@ -2847,8 +2812,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (def->sql_type == FIELD_TYPE_BLOB) { - my_printf_error(ER_BLOB_CANT_HAVE_DEFAULT, - ER(ER_BLOB_CANT_HAVE_DEFAULT), MYF(0), def->change); + my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change); DBUG_RETURN(TRUE); } def->def=alter->def; // Use new default @@ -2862,8 +2826,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, { if (def->change && ! def->field) { - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - def->change, table_name); + my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table_name); DBUG_RETURN(TRUE); } if (!def->after) @@ -2881,8 +2844,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } if (!find) { - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), - MYF(0), def->after, table_name); + my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table_name); DBUG_RETURN(TRUE); } find_it.after(def); // Put element after this @@ -2890,8 +2852,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } if (alter_info->alter_list.elements) { - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), - alter_info->alter_list.head()->name, table_name); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + alter_info->alter_list.head()->name, table_name); DBUG_RETURN(TRUE); } if (!create_list.elements) @@ -2986,8 +2948,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (key->name && !my_strcasecmp(system_charset_info,key->name,primary_key_name)) { - my_printf_error(ER_WRONG_NAME_FOR_INDEX, ER(ER_WRONG_NAME_FOR_INDEX), - MYF(0), key->name); + my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name); DBUG_RETURN(TRUE); } } @@ -2995,16 +2956,14 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (alter_info->drop_list.elements) { - my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, - ER(ER_CANT_DROP_FIELD_OR_KEY), MYF(0), - alter_info->drop_list.head()->name); + my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), + alter_info->drop_list.head()->name); goto err; } if (alter_info->alter_list.elements) { - my_printf_error(ER_CANT_DROP_FIELD_OR_KEY, - ER(ER_CANT_DROP_FIELD_OR_KEY), MYF(0), - alter_info->alter_list.head()->name); + my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), + alter_info->alter_list.head()->name); goto err; } @@ -3207,8 +3166,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (!access(new_name_buff,F_OK)) { error=1; - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), new_name_buff); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff); VOID(quick_rm_table(new_db_type,new_db,tmp_name)); VOID(pthread_mutex_unlock(&LOCK_open)); goto err; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 4a99296a7a5..7637679430f 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -74,8 +74,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) */ if (tables->view || table->tmp_table != NO_TMP_TABLE) { - my_printf_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, - ER(ER_TRG_ON_VIEW_OR_TEMP_TABLE), MYF(0), tables->alias); + my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias); DBUG_RETURN(TRUE); } @@ -418,8 +417,8 @@ err_with_lex_cleanup: We don't care about this error message much because .TRG files will be merged into .FRM anyway. */ - my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), - table_name, triggers_file_ext, "TRIGGER"); + my_error(ER_WRONG_OBJECT, MYF(0), + table_name, triggers_file_ext, "TRIGGER"); DBUG_RETURN(1); } diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 964021ce7fa..7fd81f22e66 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -384,15 +384,14 @@ int mysql_create_function(THD *thd,udf_func *udf) } if (udf->name.length > NAME_LEN) { - my_printf_error(ER_TOO_LONG_IDENT, ER(ER_TOO_LONG_IDENT), MYF(0), - udf->name); + my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name); DBUG_RETURN(1); } rw_wrlock(&THR_LOCK_udf); if ((hash_search(&udf_hash,(byte*) udf->name.str, udf->name.length))) { - my_printf_error(ER_UDF_EXISTS, ER(ER_UDF_EXISTS), MYF(0), udf->name); + my_error(ER_UDF_EXISTS, MYF(0), udf->name); goto err; } if (!(dl = find_udf_dl(udf->dl))) @@ -401,7 +400,7 @@ int mysql_create_function(THD *thd,udf_func *udf) { DBUG_PRINT("error",("dlopen of %s failed, error: %d (%s)", udf->dl,errno,dlerror())); - my_printf_error(ER_CANT_OPEN_LIBRARY, ER(ER_CANT_OPEN_LIBRARY), MYF(0), + my_error(ER_CANT_OPEN_LIBRARY, MYF(0), udf->dl, errno, dlerror()); goto err; } @@ -412,8 +411,7 @@ int mysql_create_function(THD *thd,udf_func *udf) if (udf->func == NULL) { - my_printf_error(ER_CANT_FIND_DL_ENTRY, ER(ER_CANT_FIND_DL_ENTRY), MYF(0), - udf->name); + my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), udf->name); goto err; } udf->name.str=strdup_root(&mem,udf->name.str); @@ -447,8 +445,7 @@ int mysql_create_function(THD *thd,udf_func *udf) close_thread_tables(thd); if (error) { - my_printf_error(ER_ERROR_ON_WRITE, ER(ER_ERROR_ON_WRITE), MYF(0), - "func@mysql", error); + my_error(ER_ERROR_ON_WRITE, MYF(0), "func@mysql", error); del_udf(u_d); goto err; } @@ -478,8 +475,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) if (!(udf=(udf_func*) hash_search(&udf_hash,(byte*) udf_name->str, (uint) udf_name->length))) { - my_printf_error(ER_FUNCTION_NOT_DEFINED, ER(ER_FUNCTION_NOT_DEFINED), - MYF(0), udf_name->str); + my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), udf_name->str); goto err; } del_udf(udf); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index dfc46150847..c5167018701 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -38,15 +38,15 @@ static bool compare_record(TABLE *table, ulong query_id) if (memcmp(table->null_flags, table->null_flags+table->rec_buff_length, table->null_bytes)) - return 1; // Diff in NULL value + return TRUE; // Diff in NULL value /* Compare updated fields */ for (Field **ptr=table->field ; *ptr ; ptr++) { if ((*ptr)->query_id == query_id && (*ptr)->cmp_binary_offset(table->rec_buff_length)) - return 1; + return TRUE; } - return 0; + return FALSE; } @@ -73,8 +73,7 @@ static bool check_fields(THD *thd, List &items) if (!(field= item->filed_for_view_update())) { /* item has name, because it comes from VIEW SELECT list */ - my_printf_error(ER_NONUPDATEABLE_COLUMN, ER(ER_NONUPDATEABLE_COLUMN), - MYF(0), item->name); + my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name); return TRUE; } /* @@ -134,8 +133,8 @@ bool mysql_update(THD *thd, table_list->grant.want_privilege : table->grant.want_privilege); #endif - if ((error= mysql_prepare_update(thd, table_list, &conds, order_num, order))) - DBUG_RETURN(error); + if (mysql_prepare_update(thd, table_list, &conds, order_num, order)) + DBUG_RETURN(TRUE); old_used_keys= table->used_keys; // Keys used in WHERE /* @@ -165,8 +164,7 @@ bool mysql_update(THD *thd, } if (!table_list->updatable || check_key_in_view(thd, table_list)) { - my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE), - MYF(0), table_list->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); DBUG_RETURN(TRUE); } if (table->timestamp_field) @@ -532,8 +530,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, /* Check that we are not using table that we are updating in a sub select */ if (unique_table(table_list, table_list->next_global)) { - my_printf_error(ER_UPDATE_TABLE_USED, ER(ER_UPDATE_TABLE_USED), MYF(0), - table_list->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name); DBUG_RETURN(TRUE); } select_lex->fix_prepare_information(thd, conds); @@ -591,7 +588,7 @@ bool mysql_multi_update_prepare(THD *thd) /* open tables and create derived ones, but do not lock and fill them */ if (open_tables(thd, table_list, & table_count) || mysql_handle_derived(lex, &mysql_derived_prepare)) - DBUG_RETURN(thd->net.report_error ? -1 : 1); + DBUG_RETURN(TRUE); /* Ensure that we have update privilege for all tables and columns in the SET part @@ -658,9 +655,7 @@ bool mysql_multi_update_prepare(THD *thd) { if (!tl->updatable || check_key_in_view(thd, tl)) { - my_printf_error(ER_NON_UPDATABLE_TABLE, - ER(ER_NON_UPDATABLE_TABLE), MYF(0), - tl->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), tl->alias, "UPDATE"); DBUG_RETURN(TRUE); } @@ -671,8 +666,7 @@ bool mysql_multi_update_prepare(THD *thd) if (lex->select_lex.check_updateable_in_subqueries(tl->db, tl->real_name)) { - my_printf_error(ER_UPDATE_TABLE_USED, - ER(ER_UPDATE_TABLE_USED), MYF(0), tl->real_name); + my_error(ER_UPDATE_TABLE_USED, MYF(0), tl->real_name); DBUG_RETURN(TRUE); } DBUG_PRINT("info",("setting table `%s` for update", tl->alias)); @@ -727,7 +721,7 @@ bool mysql_multi_update_prepare(THD *thd) } if (thd->fill_derived_tables() && mysql_handle_derived(lex, &mysql_derived_filling)) - DBUG_RETURN(thd->net.report_error ? -1 : 1); + DBUG_RETURN(TRUE); DBUG_RETURN (FALSE); } @@ -749,8 +743,8 @@ bool mysql_multi_update(THD *thd, multi_update *result; DBUG_ENTER("mysql_multi_update"); - if ((res= mysql_multi_update_prepare(thd))) - DBUG_RETURN(res); + if (mysql_multi_update_prepare(thd)) + DBUG_RETURN(TRUE); if (!(result= new multi_update(thd, table_list, fields, values, handle_duplicates))) @@ -1021,7 +1015,7 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List *fields) case JT_SYSTEM: case JT_CONST: case JT_EQ_REF: - return 1; // At most one matching row + return TRUE; // At most one matching row case JT_REF: return !check_if_key_used(table, join_tab->ref.key, *fields); case JT_ALL: @@ -1032,11 +1026,11 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List *fields) if ((table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) && table->primary_key < MAX_KEY) return !check_if_key_used(table, table->primary_key, *fields); - return 1; + return TRUE; default: break; // Avoid compler warning } - return 0; + return FALSE; } @@ -1360,7 +1354,7 @@ bool multi_update::send_eof() /* Safety: If we haven't got an error before (should not happen) */ my_message(ER_UNKNOWN_ERROR, "An error occured in multi-table update", MYF(0)); - return 1; + return TRUE; } @@ -1370,5 +1364,5 @@ bool multi_update::send_eof() (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated; ::send_ok(thd, (ulong) thd->row_count_func, thd->insert_id_used ? thd->insert_id() : 0L,buff); - return 0; + return FALSE; } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index cd739071d7b..f7f3a362696 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -113,13 +113,8 @@ bool mysql_create_view(THD *thd, */ if (check_some_access(thd, VIEW_ANY_ACL, tbl)) { - my_printf_error(ER_TABLEACCESS_DENIED_ERROR, - ER(ER_TABLEACCESS_DENIED_ERROR), - MYF(0), - "ANY", - thd->priv_user, - thd->host_or_ip, - tbl->real_name); + my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), + "ANY", thd->priv_user, thd->host_or_ip, tbl->real_name); DBUG_RETURN(TRUE); } /* @@ -190,8 +185,7 @@ bool mysql_create_view(THD *thd, /* is this table temporary and is not view? */ if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view) { - my_printf_error(ER_VIEW_SELECT_TMPTABLE, - ER(ER_VIEW_SELECT_TMPTABLE), MYF(0), tbl->alias); + my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); res= TRUE; goto err; } @@ -201,8 +195,7 @@ bool mysql_create_view(THD *thd, strcmp(tbl->view_db.str, view->db) == 0 && strcmp(tbl->view_name.str, view->real_name) == 0) { - my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), - tbl->view_db.str, tbl->view_name.str); + my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str); res= TRUE; goto err; } @@ -257,8 +250,7 @@ bool mysql_create_view(THD *thd, { if (strcmp(item->name, check->name) == 0) { - my_printf_error(ER_DUP_FIELDNAME, ER(ER_DUP_FIELDNAME), - MYF(0), item->name); + my_error(ER_DUP_FIELDNAME, MYF(0), item->name); DBUG_RETURN(TRUE); } } @@ -290,14 +282,9 @@ bool mysql_create_view(THD *thd, if ((~fld->have_privileges & priv)) { /* VIEW column has more privileges */ - my_printf_error(ER_COLUMNACCESS_DENIED_ERROR, - ER(ER_COLUMNACCESS_DENIED_ERROR), - MYF(0), - "create view", - thd->priv_user, - thd->host_or_ip, - item->name, - view->real_name); + my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), + "create view", thd->priv_user, thd->host_or_ip, item->name, + view->real_name); DBUG_RETURN(TRUE); } } @@ -432,8 +419,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, { if (mode == VIEW_CREATE_NEW) { - my_printf_error(ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR), - MYF(0), view->alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), view->alias); DBUG_RETURN(-1); } @@ -443,9 +429,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, if (!parser->ok() || strncmp("VIEW", parser->type()->str, parser->type()->length)) { - my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), - (view->db ? view->db : thd->db), - view->real_name, "VIEW"); + my_error(ER_WRONG_OBJECT, MYF(0), + (view->db ? view->db : thd->db), view->real_name, "VIEW"); DBUG_RETURN(-1); } @@ -465,8 +450,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, { if (mode == VIEW_ALTER) { - my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), - view->db, view->alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), view->db, view->alias); DBUG_RETURN(-1); } } @@ -529,8 +513,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, if (view->with_check != VIEW_CHECK_NONE && !view->updatable_view) { - my_printf_error(ER_VIEW_NONUPD_CHECK, ER(ER_VIEW_NONUPD_CHECK), MYF(0), - view->db, view->real_name); + my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->real_name); DBUG_RETURN(-1); } @@ -880,11 +863,9 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) continue; } if (type) - my_printf_error(ER_WRONG_OBJECT, ER(ER_WRONG_OBJECT), MYF(0), - view->db, view->real_name, "VIEW"); + my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->real_name, "VIEW"); else - my_printf_error(ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), MYF(0), - name); + my_error(ER_BAD_TABLE_ERROR, MYF(0), name); goto err; } if (my_delete(path, MYF(MY_WME))) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9974c7934dd..11c38a244a2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1467,8 +1467,7 @@ sp_fdparam: if (spc->find_pvar(&$1, TRUE)) { - my_printf_error(ER_SP_DUP_PARAM, ER(ER_SP_DUP_PARAM), MYF(0), - $1.str); + my_error(ER_SP_DUP_PARAM, MYF(0), $1.str); YYABORT; } spc->push_pvar(&$1, (enum enum_field_types)$2, sp_param_in); @@ -1494,8 +1493,7 @@ sp_pdparam: if (spc->find_pvar(&$2, TRUE)) { - my_printf_error(ER_SP_DUP_PARAM, ER(ER_SP_DUP_PARAM), MYF(0), - $2.str); + my_error(ER_SP_DUP_PARAM, MYF(0), $2.str); YYABORT; } spc->push_pvar(&$2, (enum enum_field_types)$3, @@ -1588,8 +1586,7 @@ sp_decl: if (spc->find_cond(&$2, TRUE)) { - my_printf_error(ER_SP_DUP_COND, ER(ER_SP_DUP_COND), MYF(0), - $2.str); + my_error(ER_SP_DUP_COND, MYF(0), $2.str); YYABORT; } YYTHD->lex->spcont->push_cond(&$2, $5); @@ -1646,8 +1643,7 @@ sp_decl: if (ctx->find_cursor(&$2, &offp, TRUE)) { - my_printf_error(ER_SP_DUP_CURS, ER(ER_SP_DUP_CURS), MYF(0), - $2.str); + my_error(ER_SP_DUP_CURS, MYF(0), $2.str); delete $5; YYABORT; } @@ -1751,8 +1747,7 @@ sp_hcond: $$= Lex->spcont->find_cond(&$1); if ($$ == NULL) { - my_printf_error(ER_SP_COND_MISMATCH, ER(ER_SP_COND_MISMATCH), - MYF(0), $1.str); + my_error(ER_SP_COND_MISMATCH, MYF(0), $1.str); YYABORT; } } @@ -1781,8 +1776,7 @@ sp_decl_idents: if (spc->find_pvar(&$1, TRUE)) { - my_printf_error(ER_SP_DUP_VAR, ER(ER_SP_DUP_VAR), MYF(0), - $1.str); + my_error(ER_SP_DUP_VAR, MYF(0), $1.str); YYABORT; } spc->push_pvar(&$1, (enum_field_types)0, sp_param_in); @@ -1795,8 +1789,7 @@ sp_decl_idents: if (spc->find_pvar(&$3, TRUE)) { - my_printf_error(ER_SP_DUP_VAR, ER(ER_SP_DUP_VAR), MYF(0), - $3.str); + my_error(ER_SP_DUP_VAR, MYF(0), $3.str); YYABORT; } spc->push_pvar(&$3, (enum_field_types)0, sp_param_in); @@ -1950,9 +1943,7 @@ sp_proc_stmt: if (! lab) { - my_printf_error(ER_SP_LILABEL_MISMATCH, - ER(ER_SP_LILABEL_MISMATCH), MYF(0), - "LEAVE", $2.str); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "LEAVE", $2.str); YYABORT; } else @@ -1982,9 +1973,7 @@ sp_proc_stmt: if (! lab || lab->type != SP_LAB_ITER) { - my_printf_error(ER_SP_LILABEL_MISMATCH, - ER(ER_SP_LILABEL_MISMATCH), MYF(0), - "ITERATE", $2.str); + my_error(ER_SP_LILABEL_MISMATCH, MYF(0), "ITERATE", $2.str); YYABORT; } else @@ -2012,8 +2001,7 @@ sp_proc_stmt: if (lab) { - my_printf_error(ER_SP_LABEL_REDEFINE, - ER(ER_SP_LABEL_REDEFINE), MYF(0), $2.str); + my_error(ER_SP_LABEL_REDEFINE, MYF(0), $2.str); YYABORT; } else @@ -2088,8 +2076,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - my_printf_error(ER_SP_CURSOR_MISMATCH, - ER(ER_SP_CURSOR_MISMATCH), MYF(0), $2.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); YYABORT; } i= new sp_instr_copen(sp->instructions(), lex->spcont, offset); @@ -2104,8 +2091,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$3, &offset)) { - my_printf_error(ER_SP_CURSOR_MISMATCH, - ER(ER_SP_CURSOR_MISMATCH), MYF(0), $3.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $3.str); YYABORT; } i= new sp_instr_cfetch(sp->instructions(), lex->spcont, offset); @@ -2122,8 +2108,7 @@ sp_proc_stmt: if (! lex->spcont->find_cursor(&$2, &offset)) { - my_printf_error(ER_SP_CURSOR_MISMATCH, - ER(ER_SP_CURSOR_MISMATCH), MYF(0), $2.str); + my_error(ER_SP_CURSOR_MISMATCH, MYF(0), $2.str); YYABORT; } i= new sp_instr_cclose(sp->instructions(), lex->spcont, offset); @@ -2147,8 +2132,7 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$1))) { - my_printf_error(ER_SP_UNDECLARED_VAR, - ER(ER_SP_UNDECLARED_VAR), MYF(0), $1.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); YYABORT; } else @@ -2170,8 +2154,7 @@ sp_fetch_list: if (!spc || !(spv = spc->find_pvar(&$3))) { - my_printf_error(ER_SP_UNDECLARED_VAR, - ER(ER_SP_UNDECLARED_VAR), MYF(0), $3.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str); YYABORT; } else @@ -2295,8 +2278,7 @@ sp_labeled_control: if (lab) { - my_printf_error(ER_SP_LABEL_REDEFINE, - ER(ER_SP_LABEL_REDEFINE), MYF(0), $1.str); + my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str); YYABORT; } else @@ -2317,8 +2299,7 @@ sp_labeled_control: if (!lab || my_strcasecmp(system_charset_info, $5.str, lab->name) != 0) { - my_printf_error(ER_SP_LABEL_MISMATCH, - ER(ER_SP_LABEL_MISMATCH), MYF(0), $5.str); + my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str); YYABORT; } } @@ -2576,11 +2557,9 @@ default_charset: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - my_printf_error(ER_CONFLICTING_DECLARATIONS, - ER(ER_CONFLICTING_DECLARATIONS), MYF(0), - "CHARACTER SET ", - cinfo->default_table_charset->csname, - "CHARACTER SET ", $4->csname); + my_error(ER_CONFLICTING_DECLARATIONS, MYF(0), + "CHARACTER SET ", cinfo->default_table_charset->csname, + "CHARACTER SET ", $4->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2595,9 +2574,8 @@ default_collation: cinfo->default_table_charset && $4 && !my_charset_same(cinfo->default_table_charset,$4)) { - my_printf_error(ER_COLLATION_CHARSET_MISMATCH, - ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), - $4->name, cinfo->default_table_charset->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $4->name, cinfo->default_table_charset->csname); YYABORT; } Lex->create_info.default_table_charset= $4; @@ -2609,8 +2587,7 @@ storage_engines: { $$ = ha_resolve_by_name($1.str,$1.length); if ($$ == DB_TYPE_UNKNOWN) { - my_printf_error(ER_UNKNOWN_STORAGE_ENGINE, - ER(ER_UNKNOWN_STORAGE_ENGINE), MYF(0), $1.str); + my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), $1.str); YYABORT; } }; @@ -2807,10 +2784,8 @@ type: Lex->uint_geom_type= (uint)$1; $$=FIELD_TYPE_GEOMETRY; #else - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0) - sym_group_geom.name, - sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0) + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif } @@ -2977,9 +2952,8 @@ attribute: { if (Lex->charset && !my_charset_same(Lex->charset,$2)) { - my_printf_error(ER_COLLATION_CHARSET_MISMATCH, - ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), - $2->name,Lex->charset->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $2->name,Lex->charset->csname); YYABORT; } else @@ -3004,8 +2978,7 @@ charset_name: { if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0)))) { - my_printf_error(ER_UNKNOWN_CHARACTER_SET, - ER(ER_UNKNOWN_CHARACTER_SET), MYF(0), $1.str); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); YYABORT; } } @@ -3023,8 +2996,7 @@ old_or_new_charset_name: if (!($$=get_charset_by_csname($1.str,MY_CS_PRIMARY,MYF(0))) && !($$=get_old_charset_by_name($1.str))) { - my_printf_error(ER_UNKNOWN_CHARACTER_SET, - ER(ER_UNKNOWN_CHARACTER_SET), MYF(0), $1.str); + my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), $1.str); YYABORT; } } @@ -3040,8 +3012,7 @@ collation_name: { if (!($$=get_charset_by_name($1.str,MYF(0)))) { - my_printf_error(ER_UNKNOWN_COLLATION, - ER(ER_UNKNOWN_COLLATION), MYF(0), $1.str); + my_error(ER_UNKNOWN_COLLATION, MYF(0), $1.str); YYABORT; } }; @@ -3130,9 +3101,8 @@ key_type: #ifdef HAVE_SPATIAL $$= Key::SPATIAL; #else - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif }; @@ -3195,9 +3165,7 @@ key_part: int key_part_len= atoi($3.str); if (!key_part_len) { - my_printf_error(ER_UNKNOWN_ERROR, - "Key part '%s' length cannot be 0", - MYF(0), $1.str); + my_error(ER_KEY_PART_0, MYF(0), $1.str); } $$=new key_part_spec($1.str,(uint) key_part_len); }; @@ -3406,8 +3374,7 @@ alter_list_item: if (check_table_name($3->table.str,$3->table.length) || $3->db.str && check_db_name($3->db.str)) { - my_printf_error(ER_WRONG_TABLE_NAME, ER(ER_WRONG_TABLE_NAME), - MYF(0), $3->table.str); + my_error(ER_WRONG_TABLE_NAME, MYF(0), $3->table.str); YYABORT; } lex->alter_info.flags|= ALTER_RENAME; @@ -3422,9 +3389,8 @@ alter_list_item: $5= $5 ? $5 : $4; if (!my_charset_same($4,$5)) { - my_printf_error(ER_COLLATION_CHARSET_MISMATCH, - ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), - $5->name, $4->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $5->name, $4->csname); YYABORT; } LEX *lex= Lex; @@ -4269,10 +4235,9 @@ simple_expr: { if (!$1.symbol->create_func) { - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(void))($1.symbol->create_func))(); @@ -4281,10 +4246,9 @@ simple_expr: { if (!$1.symbol->create_func) { - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*))($1.symbol->create_func))($3); @@ -4293,10 +4257,9 @@ simple_expr: { if (!$1.symbol->create_func) { - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5); @@ -4305,10 +4268,9 @@ simple_expr: { if (!$1.symbol->create_func) { - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - $1.symbol->group->name, - $1.symbol->group->needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + $1.symbol->group->name, + $1.symbol->group->needed_define); YYABORT; } $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7); @@ -4411,9 +4373,8 @@ simple_expr: #ifdef HAVE_SPATIAL $$= $1; #else - my_printf_error(ER_FEATURE_DISABLED, - ER(ER_FEATURE_DISABLED), MYF(0), - sym_group_geom.name, sym_group_geom.needed_define); + my_error(ER_FEATURE_DISABLED, MYF(0), + sym_group_geom.name, sym_group_geom.needed_define); YYABORT; #endif } @@ -5469,8 +5430,7 @@ select_var_ident: if (!lex->spcont || !(t=lex->spcont->find_pvar(&$1))) { - my_printf_error(ER_SP_UNDECLARED_VAR, - ER(ER_SP_UNDECLARED_VAR), MYF(0), $1.str); + my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str); YYABORT; } if (! lex->result) @@ -5826,9 +5786,8 @@ update: else if (lex->select_lex.get_table_list()->derived) { /* it is single table update and it is update of derived table */ - my_printf_error(ER_NON_UPDATABLE_TABLE, - ER(ER_NON_UPDATABLE_TABLE), MYF(0), - lex->select_lex.get_table_list()->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), + lex->select_lex.get_table_list()->alias, "UPDATE"); YYABORT; } else @@ -6686,9 +6645,8 @@ simple_ident_q: FIXME. Far from perfect solution. See comment for "SET NEW.field_name:=..." for more info. */ - my_printf_error(ER_BAD_FIELD_ERROR, - ER(ER_BAD_FIELD_ERROR), MYF(0), - $3.str, new_row ? "NEW": "OLD"); + my_error(ER_BAD_FIELD_ERROR, MYF(0), + $3.str, new_row ? "NEW": "OLD"); YYABORT; } @@ -6699,9 +6657,8 @@ simple_ident_q: SELECT_LEX *sel= lex->current_select; if (sel->no_table_names_allowed) { - my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, - ER(ER_TABLENAME_NOT_ALLOWED_HERE), - MYF(0), $1.str, thd->where); + my_error(ER_TABLENAME_NOT_ALLOWED_HERE, + MYF(0), $1.str, thd->where); } $$= (sel->parsing_place != IN_HAVING || sel->get_in_sum_expr() > 0) ? @@ -6716,9 +6673,8 @@ simple_ident_q: SELECT_LEX *sel= lex->current_select; if (sel->no_table_names_allowed) { - my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, - ER(ER_TABLENAME_NOT_ALLOWED_HERE), - MYF(0), $2.str, thd->where); + my_error(ER_TABLENAME_NOT_ALLOWED_HERE, + MYF(0), $2.str, thd->where); } $$= (sel->parsing_place != IN_HAVING || sel->get_in_sum_expr() > 0) ? @@ -6732,9 +6688,8 @@ simple_ident_q: SELECT_LEX *sel= lex->current_select; if (sel->no_table_names_allowed) { - my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, - ER(ER_TABLENAME_NOT_ALLOWED_HERE), - MYF(0), $3.str, thd->where); + my_error(ER_TABLENAME_NOT_ALLOWED_HERE, + MYF(0), $3.str, thd->where); } $$= (sel->parsing_place != IN_HAVING || sel->get_in_sum_expr() > 0) ? @@ -6775,9 +6730,8 @@ IDENT_sys: $1.length); if (wlen < $1.length) { - my_printf_error(ER_INVALID_CHARACTER_STRING, - ER(ER_INVALID_CHARACTER_STRING), MYF(0), - cs->csname, $1.str + wlen); + my_error(ER_INVALID_CHARACTER_STRING, MYF(0), + cs->csname, $1.str + wlen); YYABORT; } $$= $1; @@ -7214,8 +7168,7 @@ option_value: Error message also should be improved. */ - my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), - MYF(0), $1.base_name, "NEW"); + my_error(ER_BAD_FIELD_ERROR, MYF(0), $1.base_name, "NEW"); YYABORT; } lex->sphead->add_instr(i); @@ -7281,9 +7234,8 @@ option_value: $3= $3 ? $3 : $2; if (!my_charset_same($2,$3)) { - my_printf_error(ER_COLLATION_CHARSET_MISMATCH, - ER(ER_COLLATION_CHARSET_MISMATCH), MYF(0), - $3->name, $2->csname); + my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), + $3->name, $2->csname); YYABORT; } lex->var_list.push_back(new set_var_collation_client($3,$3,$3)); @@ -7373,8 +7325,7 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, - ER(ER_VARIABLE_IS_NOT_STRUCT), MYF(0), $3.str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); $$.var= tmp; $$.base_name= $1; } @@ -7385,8 +7336,7 @@ internal_variable_name: if (!tmp) YYABORT; if (!tmp->is_struct()) - my_printf_error(ER_VARIABLE_IS_NOT_STRUCT, - ER(ER_VARIABLE_IS_NOT_STRUCT), MYF(0), $3.str); + my_error(ER_VARIABLE_IS_NOT_STRUCT, MYF(0), $3.str); $$.var= tmp; $$.base_name.str= (char*) "default"; $$.base_name.length= 7; diff --git a/sql/table.cc b/sql/table.cc index 095c3f037d5..e9ce118183f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -984,12 +984,11 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype) uint length=dirname_part(buff,name); buff[length-1]=0; db=buff+dirname_length(buff); - my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), - db, form->real_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), db, form->real_name); } else - my_printf_error(ER_FILE_NOT_FOUND, ER(ER_FILE_NOT_FOUND), errortype, - fn_format(buff, name, form_dev, reg_ext, 0), my_errno); + my_error(ER_FILE_NOT_FOUND, errortype, + fn_format(buff, name, form_dev, reg_ext, 0), my_errno); break; case 2: { @@ -997,15 +996,14 @@ static void frm_error(int error, TABLE *form, const char *name, myf errortype) datext= datext==NullS ? "" : datext; err_no= (my_errno == ENOENT) ? ER_FILE_NOT_FOUND : (my_errno == EAGAIN) ? ER_FILE_USED : ER_CANT_OPEN_FILE; - my_printf_error(err_no, ER(err_no), errortype, - fn_format(buff, form->real_name, form_dev, datext, 2), - my_errno); + my_error(err_no, errortype, + fn_format(buff, form->real_name, form_dev, datext, 2), my_errno); break; } default: /* Better wrong error than none */ case 4: - my_printf_error(ER_NOT_FORM_FILE, ER(ER_NOT_FORM_FILE), errortype, - fn_format(buff, name, form_dev, reg_ext, 0)); + my_error(ER_NOT_FORM_FILE, errortype, + fn_format(buff, name, form_dev, reg_ext, 0)); break; } DBUG_VOID_RETURN; @@ -1728,8 +1726,7 @@ err: if (thd->net.last_errno == ER_BAD_FIELD_ERROR) { thd->clear_error(); - my_printf_error(ER_VIEW_INVALID, ER(ER_VIEW_INVALID), MYF(0), - view_db.str, view_name.str); + my_error(ER_VIEW_INVALID, MYF(0), view_db.str, view_name.str); } thd->lex->select_lex.no_wrap_view_item= save_wrapper; thd->lex->current_select= current_select_save; @@ -1783,8 +1780,7 @@ int st_table_list::view_check_option(THD *thd, bool ignore_failure) } else { - my_printf_error(ER_VIEW_CHECK_FAILED, ER(ER_VIEW_CHECK_FAILED), MYF(0), - view_db.str, view_name.str); + my_error(ER_VIEW_CHECK_FAILED, MYF(0), view_db.str, view_name.str); return(VIEW_CHECK_ERROR); } } diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c index 268f7d18f2a..4d7c17e977c 100644 --- a/strings/my_vsnprintf.c +++ b/strings/my_vsnprintf.c @@ -52,15 +52,30 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) if (*fmt == '-') fmt++; length= width= pre_zero= have_long= 0; - for (;my_isdigit(&my_charset_latin1,*fmt); fmt++) + if (*fmt == '*') { - length=length*10+ (uint) (*fmt-'0'); - if (!length) - pre_zero= 1; /* first digit was 0 */ + fmt++; + length= va_arg(ap, int); } + else + for (; my_isdigit(&my_charset_latin1, *fmt); fmt++) + { + length= length * 10 + (uint)(*fmt - '0'); + if (!length) + pre_zero= 1; /* first digit was 0 */ + } if (*fmt == '.') - for (fmt++;my_isdigit(&my_charset_latin1,*fmt); fmt++) - width=width*10+ (uint) (*fmt-'0'); + { + fmt++; + if (*fmt == '*') + { + fmt++; + width= va_arg(ap, int); + } + else + for (; my_isdigit(&my_charset_latin1, *fmt); fmt++) + width= width * 10 + (uint)(*fmt - '0'); + } else width= ~0; if (*fmt == 'l') From 25d0f827ce983a9f95ff17717e3f60649e985c69 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Sat, 13 Nov 2004 23:26:15 +0200 Subject: [PATCH 93/94] posmerge fixes --- mysql-test/r/view.result | 4 +- sql/item.cc | 3 -- sql/mysql_priv.h | 2 +- sql/sql_parse.cc | 24 ++++++------ sql/sql_select.cc | 3 -- sql/sql_show.cc | 85 ++++++++++++++++++++++------------------ sql/table.h | 2 +- 7 files changed, 64 insertions(+), 59 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 18fa7c2e374..f41e6c7e165 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1221,11 +1221,11 @@ ERROR 42000: FUNCTION test.x1 does not exist show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment t1 MyISAM 9 Fixed 0 0 0 21474836479 1024 0 NULL # # NULL latin1_swedish_ci NULL -v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view +v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL FUNCTION test.x1 does not exist show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment t1 MyISAM 9 Fixed 0 0 0 21474836479 1024 0 NULL # # NULL latin1_swedish_ci NULL -v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view +v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL FUNCTION test.x1 does not exist drop view v1; drop table t1; create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1; diff --git a/sql/item.cc b/sql/item.cc index 42e1f23babd..ea721eea831 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1793,9 +1793,6 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference) !any_privileges)) == not_found_field) { -#ifdef EMBEDDED_LIBRARY - thd->net.last_errno= 0; -#endif SELECT_LEX *last= 0; TABLE_LIST *table_list; Item **ref= (Item **) not_found_item; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index d3ff1a0ab0a..7a49799c7cd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -737,7 +737,7 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond); int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond); int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond); int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond); -int get_schema_tables_result(JOIN *join); +bool get_schema_tables_result(JOIN *join); /* sql_prepare.cc */ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index dfd82f2750e..11c02dacdad 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1877,7 +1877,8 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, switch(schema_table_idx) { case SCH_SCHEMATA: #if defined(DONT_ALLOW_SHOW_COMMANDS) - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, + ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); #else if ((specialflag & SPECIAL_SKIP_SHOW_DB) && @@ -1889,30 +1890,30 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, case SCH_TABLES: case SCH_VIEWS: #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, + ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); #else { char *db= lex->select_lex.db ? lex->select_lex.db : thd->db; if (!db) { - send_error(thd,ER_NO_DB_ERROR); /* purecov: inspected */ + my_message(ER_NO_DB_ERROR, + ER(ER_NO_DB_ERROR), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); /* purecov: inspected */ } remove_escape(db); // Fix escaped '_' if (check_db_name(db)) { - net_printf(thd,ER_WRONG_DB_NAME, db); + my_error(ER_WRONG_DB_NAME, MYF(0), db); DBUG_RETURN(1); } if (check_access(thd,SELECT_ACL,db,&thd->col_access,0,0)) DBUG_RETURN(1); /* purecov: inspected */ if (!thd->col_access && check_grant_db(thd,db)) { - net_printf(thd, ER_DBACCESS_DENIED_ERROR, - thd->priv_user, - thd->priv_host, - db); + my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), + thd->priv_user, thd->priv_host, db); DBUG_RETURN(1); } lex->select_lex.db= db; @@ -1922,7 +1923,8 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, case SCH_COLUMNS: case SCH_STATISTICS: #ifdef DONT_ALLOW_SHOW_COMMANDS - send_error(thd,ER_NOT_ALLOWED_COMMAND); /* purecov: inspected */ + my_message(ER_NOT_ALLOWED_COMMAND, + ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */ DBUG_RETURN(1); #else if (table_ident) @@ -5238,8 +5240,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->real_name); if (!schema_table) { - net_printf(thd, ER_UNKNOWN_TABLE, ptr->real_name, - information_schema_name.str); + my_error(ER_UNKNOWN_TABLE, MYF(0), + ptr->real_name, information_schema_name.str); DBUG_RETURN(0); } ptr->schema_table= schema_table; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 977e8c5c9ca..bb620617db3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9770,9 +9770,6 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), { Item *item= *group->item; item->save_org_in_field(group->field); -#ifdef EMBEDDED_LIBRARY - join->thd->net.last_errno= 0; -#endif /* Store in the used key if the field was 0 */ if (item->maybe_null) group->buff[-1]=item->null_value ? 1 : 0; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 4af041d1a95..c92369685ea 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1900,7 +1900,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) TABLE *old_open_tables= thd->open_tables; TABLE_LIST *show_table_list= (TABLE_LIST*) lsel->table_list.first; lex->all_selects_list= lsel; - int res= open_and_lock_tables(thd, show_table_list); + bool res= open_and_lock_tables(thd, show_table_list); if (schema_table->process_table(thd, show_table_list, table, res, show_table_list->db, show_table_list->real_name)) @@ -2060,9 +2060,10 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) } -int get_schema_tables_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, const char *file_name) +static int get_schema_tables_record(THD *thd, struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { const char *tmp_buff; TIME time; @@ -2070,18 +2071,21 @@ int get_schema_tables_record(THD *thd, struct st_table_list *tables, DBUG_ENTER("get_schema_tables_record"); restore_record(table, default_values); - if (res > 0) - { - DBUG_RETURN(1); - } table->field[1]->store(base_name, strlen(base_name), cs); table->field[2]->store(file_name, strlen(file_name), cs); - if (res < 0 || tables->view) + if (res) + { + /* + there was errors during opening tables + */ + const char *error= thd->net.last_error; + table->field[20]->store(error, strlen(error), cs); + thd->clear_error(); + } + else if (tables->view) { table->field[3]->store("VIEW", 4, cs); table->field[20]->store("view", 4, cs); - if (res) - thd->clear_error(); } else { @@ -2203,9 +2207,10 @@ int get_schema_tables_record(THD *thd, struct st_table_list *tables, } -int get_schema_column_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, const char *file_name) +static int get_schema_column_record(THD *thd, struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { TIME time; const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; @@ -2538,9 +2543,10 @@ err: } -int get_schema_stat_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, const char *file_name) +static int get_schema_stat_record(THD *thd, struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { CHARSET_INFO *cs= system_charset_info; DBUG_ENTER("get_schema_stat_record"); @@ -2605,13 +2611,14 @@ int get_schema_stat_record(THD *thd, struct st_table_list *tables, } } } - DBUG_RETURN(0); + DBUG_RETURN(res); } -int get_schema_views_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, const char *file_name) +static int get_schema_views_record(THD *thd, struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { CHARSET_INFO *cs= system_charset_info; DBUG_ENTER("get_schema_views_record"); @@ -2631,13 +2638,14 @@ int get_schema_views_record(THD *thd, struct st_table_list *tables, table->file->write_row(table->record[0]); } } - DBUG_RETURN(0); + DBUG_RETURN(res); } -int get_schema_constarints_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, const char *file_name) +static int get_schema_constarints_record(THD *thd, struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { CHARSET_INFO *cs= system_charset_info; DBUG_ENTER("get_schema_constarints_record"); @@ -2684,14 +2692,15 @@ int get_schema_constarints_record(THD *thd, struct st_table_list *tables, table->file->write_row(table->record[0]); } } - DBUG_RETURN(0); + DBUG_RETURN(res); } -int get_schema_key_column_usage_record(THD *thd, struct st_table_list *tables, - TABLE *table, int res, - const char *base_name, - const char *file_name) +static int get_schema_key_column_usage_record(THD *thd, + struct st_table_list *tables, + TABLE *table, bool res, + const char *base_name, + const char *file_name) { DBUG_ENTER("get_schema_key_column_usage_record"); CHARSET_INFO *cs= system_charset_info; @@ -2707,7 +2716,7 @@ int get_schema_key_column_usage_record(THD *thd, struct st_table_list *tables, for (uint i=0 ; i < show_table->keys ; i++, key_info++) { if (i != primary_key && !(key_info->flags & HA_NOSAME)) - continue; + continue; uint f_idx= 0; KEY_PART_INFO *key_part= key_info->key_part; for (uint j=0 ; j < key_info->key_parts ; j++,key_part++) @@ -2762,7 +2771,7 @@ int get_schema_key_column_usage_record(THD *thd, struct st_table_list *tables, } } } - DBUG_RETURN(0); + DBUG_RETURN(res); } @@ -3076,11 +3085,11 @@ int make_schema_select(THD *thd, SELECT_LEX *sel, join join which use schema tables RETURN - 0 success - 1 error + FALSE success + TRUE error */ -int get_schema_tables_result(JOIN *join) +bool get_schema_tables_result(JOIN *join) { DBUG_ENTER("get_schema_tables_result"); JOIN_TAB *tmp_join_tab= join->join_tab+join->tables; @@ -3090,7 +3099,7 @@ int get_schema_tables_result(JOIN *join) if (!tab->table || !tab->table->pos_in_table_list) break; TABLE_LIST *table_list= tab->table->pos_in_table_list; - if (table_list->schema_table && !thd->only_prepare()) + if (table_list->schema_table && thd->fill_derived_tables()) { TABLE *old_derived_tables= thd->derived_tables; thd->derived_tables= 0; @@ -3103,14 +3112,14 @@ int get_schema_tables_result(JOIN *join) { thd->derived_tables= old_derived_tables; thd->lock= sql_lock; - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } thd->lock= sql_lock; thd->lex->sql_command= SQLCOM_SELECT; thd->derived_tables= old_derived_tables; } } - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } diff --git a/sql/table.h b/sql/table.h index 86dd30dff68..db3ce638842 100644 --- a/sql/table.h +++ b/sql/table.h @@ -250,7 +250,7 @@ typedef struct st_schema_table /* Handle fileds for old SHOW */ int (*old_format) (THD *thd, struct st_schema_table *schema_table); int (*process_table) (THD *thd, struct st_table_list *tables, - TABLE *table, int res, const char *base_name, + TABLE *table, bool res, const char *base_name, const char *file_name); int idx_field1, idx_field2; } ST_SCHEMA_TABLE; From bb529506256502d03c7f78f2fc9b4f0ba672ae6b Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Sun, 14 Nov 2004 00:28:44 +0200 Subject: [PATCH 94/94] make information schema libmysqld compatible fixed typo --- sql/handler.cc | 4 ++-- sql/sql_acl.cc | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index e65fd6d097d..12820a66cb9 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -517,8 +517,8 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) if ((error=ndbcluster_commit(thd,trans->ndb_tid))) { if (error == -1) - my_message_(ER_ERROR_DURING_COMMIT, ER(ER_ERROR_DURING_COMMIT), - MYF(0)); + my_message(ER_ERROR_DURING_COMMIT, ER(ER_ERROR_DURING_COMMIT), + MYF(0)); error=1; } if (trans == &thd->transaction.all) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 4c6ba829793..036ccb91260 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3985,8 +3985,10 @@ int fill_schema_user_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } -#endif DBUG_RETURN(0); +#else + return(0); +#endif } @@ -4033,8 +4035,10 @@ int fill_schema_schema_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } -#endif DBUG_RETURN(0); +#else + return (0); +#endif } @@ -4078,8 +4082,10 @@ int fill_schema_table_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } -#endif DBUG_RETURN(0); +#else + return (0); +#endif } @@ -4135,8 +4141,10 @@ int fill_schema_column_privileges(THD *thd, TABLE_LIST *tables, COND *cond) } } } -#endif DBUG_RETURN(0); +#else + return (0); +#endif }