diff options
author | unknown <msvensson@neptunus.(none)> | 2006-11-28 20:59:57 +0100 |
---|---|---|
committer | unknown <msvensson@neptunus.(none)> | 2006-11-28 20:59:57 +0100 |
commit | c789301fcd3877a21d328b8e3c4ab97148d879f3 (patch) | |
tree | abd103946cab0eae83e36388b799bb0e86227ee3 /client | |
parent | db875c0c070d34c525f650b15912273d74d4f8aa (diff) | |
parent | 5be953f896d0c28395605b103a60182b648e78c7 (diff) | |
download | mariadb-git-c789301fcd3877a21d328b8e3c4ab97148d879f3.tar.gz |
Merge neptunus.(none):/home/msvensson/mysql/mysql-5.0
into neptunus.(none):/home/msvensson/mysql/mysql-5.0-maint
BitKeeper/etc/collapsed:
auto-union
BitKeeper/etc/ignore:
auto-union
Makefile.am:
Auto merged
client/mysqltest.c:
Auto merged
mysql-test/lib/mtr_report.pl:
Auto merged
mysql-test/mysql-test-run.pl:
Auto merged
mysql-test/r/rpl_deadlock.result:
Auto merged
mysql-test/r/udf.result:
Auto merged
mysql-test/t/limit.test:
Auto merged
mysql-test/t/mysql.test:
Auto merged
mysql-test/t/rpl_deadlock.test:
Auto merged
mysql-test/t/udf.test:
Auto merged
mysql-test/mysql-test-run-shell.sh:
Auto merged
mysql-test/t/view_grant.test:
Auto merged
sql/item.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/item_func.h:
Auto merged
sql/item_timefunc.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql-common/my_time.c:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_table.cc:
Auto merged
include/my_sys.h:
Manual merge, my_getpagesize broken out of "#ifdef HAVE_SYS_MMAN_H"
Diffstat (limited to 'client')
-rw-r--r-- | client/client_priv.h | 3 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 2 | ||||
-rw-r--r-- | client/mysqldump.c | 147 | ||||
-rw-r--r-- | client/mysqltest.c | 88 |
4 files changed, 166 insertions, 74 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index 9e011144836..7ebbade4ef6 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -51,5 +51,6 @@ enum options_client #endif OPT_TRIGGERS, OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, - OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_SSL_VERIFY_SERVER_CERT + OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_SSL_VERIFY_SERVER_CERT, + OPT_DEBUG_INFO }; diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index c04c2ecabd6..ff4e0b5a5cf 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1088,7 +1088,7 @@ could be out of memory"); } if (len < 8 && net->read_pos[0] == 254) break; // end of data - DBUG_PRINT("info",( "len= %u, net->read_pos[5] = %d\n", + DBUG_PRINT("info",( "len: %lu, net->read_pos[5]: %d\n", len, net->read_pos[5])); if (!(ev= Log_event::read_log_event((const char*) net->read_pos + 1 , len - 1, &error_msg, diff --git a/client/mysqldump.c b/client/mysqldump.c index 757bec09b50..2be60b2df9a 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -30,14 +30,14 @@ ** master/autocommit code by Brian Aker <brian@tangent.org> ** SSL by ** Andrei Errapart <andreie@no.spam.ee> -** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee> +** Tõnu Samuel <tonu@please.do.not.remove.this.spam.ee> ** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up ** and adapted to mysqldump 05/11/01 by Jani Tolonen ** Added --single-transaction option 06/06/2002 by Peter Zaitsev ** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov */ -#define DUMP_VERSION "10.10" +#define DUMP_VERSION "10.11" #include <my_global.h> #include <my_sys.h> @@ -99,7 +99,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*mysql=0; -static my_bool insert_pat_inited=0; +static my_bool insert_pat_inited= 0, info_flag; static DYNAMIC_STRING insert_pat; static char *opt_password=0,*current_user=0, *current_host=0,*path=0,*fields_terminated=0, @@ -107,6 +107,7 @@ static char *opt_password=0,*current_user=0, *where=0, *order_by=0, *opt_compatible_mode_str= 0, *err_ptr= 0; +static char **defaults_argv= 0; static char compatible_mode_normal_str[255]; static ulong opt_compatible_mode= 0; #define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1 @@ -116,7 +117,7 @@ static my_string opt_mysql_unix_port=0; static int first_error=0; static DYNAMIC_STRING extended_row; #include <sslopt-vars.h> -FILE *md_result_file; +FILE *md_result_file= 0; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; #endif @@ -215,6 +216,8 @@ static struct my_option my_long_options[] = {"debug", '#', "Output debug log", (gptr*) &default_dbug_option, (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.", (gptr*) &info_flag, + (gptr*) &info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"default-character-set", OPT_DEFAULT_CHARSET, "Set the default character set.", (gptr*) &default_charset, (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -628,14 +631,6 @@ byte* get_table_key(const char *entry, uint *length, } -void init_table_rule_hash(HASH* h) -{ - if (hash_init(h, charset_info, 16, 0, 0, - (hash_get_key) get_table_key, - (hash_free_key) free_table_ent, 0)) - exit(EX_EOM); -} - static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) @@ -678,6 +673,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; case '#': DBUG_PUSH(argument ? argument : default_dbug_option); + info_flag= 1; break; #include <sslopt-case.h> case 'V': print_version(); exit(0); @@ -718,9 +714,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n"); exit(1); } - if (!hash_inited(&ignore_table)) - init_table_rule_hash(&ignore_table); - if (my_hash_insert(&ignore_table, (byte*)my_strdup(argument, MYF(0)))) exit(EX_EOM); break; @@ -796,9 +789,21 @@ static int get_options(int *argc, char ***argv) md_result_file= stdout; load_defaults("my",load_default_groups,argc,argv); + defaults_argv= *argv; - if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) - exit(ho_error); + if (hash_init(&ignore_table, charset_info, 16, 0, 0, + (hash_get_key) get_table_key, + (hash_free_key) free_table_ent, 0)) + return(EX_EOM); + /* Don't copy cluster internal log tables */ + if (my_hash_insert(&ignore_table, + (byte*) my_strdup("mysql.apply_status", MYF(MY_WME))) || + my_hash_insert(&ignore_table, + (byte*) my_strdup("mysql.schema", MYF(MY_WME)))) + return(EX_EOM); + + if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option))) + return(ho_error); *mysql_params->p_max_allowed_packet= opt_max_allowed_packet; *mysql_params->p_net_buffer_length= opt_net_buffer_length; @@ -810,7 +815,7 @@ static int get_options(int *argc, char ***argv) { fprintf(stderr, "%s: You must use option --tab with --fields-...\n", my_progname); - return(1); + return(EX_USAGE); } /* Ensure consistency of the set of binlog & locking options */ @@ -820,7 +825,7 @@ static int get_options(int *argc, char ***argv) { fprintf(stderr, "%s: You can't use --single-transaction and " "--lock-all-tables at the same time.\n", my_progname); - return(1); + return(EX_USAGE); } if (opt_master_data) opt_lock_all_tables= !opt_single_transaction; @@ -829,14 +834,14 @@ static int get_options(int *argc, char ***argv) if (enclosed && opt_enclosed) { fprintf(stderr, "%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n", my_progname); - return(1); + return(EX_USAGE); } if ((opt_databases || opt_alldbs) && path) { fprintf(stderr, "%s: --databases or --all-databases can't be used with --tab.\n", my_progname); - return(1); + return(EX_USAGE); } if (strcmp(default_charset, charset_info->csname) && !(charset_info= get_charset_by_csname(default_charset, @@ -845,7 +850,7 @@ static int get_options(int *argc, char ***argv) if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) { short_usage(); - return 1; + return EX_USAGE; } if (tty_password) opt_password=get_tty_password(NullS); @@ -920,6 +925,23 @@ static FILE* open_sql_file_for_table(const char* table) } +static void free_resources() +{ + if (md_result_file && md_result_file != stdout) + my_fclose(md_result_file, MYF(0)); + my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); + if (hash_inited(&ignore_table)) + hash_free(&ignore_table); + if (extended_insert) + dynstr_free(&extended_row); + if (insert_pat_inited) + dynstr_free(&insert_pat); + if (defaults_argv) + free_defaults(defaults_argv); + my_end(info_flag ? MY_CHECK_ERROR : 0); +} + + static void safe_exit(int error) { if (!first_error) @@ -928,18 +950,19 @@ static void safe_exit(int error) return; if (mysql) mysql_close(mysql); + free_resources(); exit(error); } -/* safe_exit */ /* -** dbConnect -- connects to the host and selects DB. + db_connect -- connects to the host and selects DB. */ -static int dbConnect(char *host, char *user,char *passwd) + +static int connect_to_db(char *host, char *user,char *passwd) { char buff[20+FN_REFLEN]; - DBUG_ENTER("dbConnect"); + DBUG_ENTER("connect_to_db"); verbose_msg("-- Connecting to %s...\n", host ? host : "localhost"); mysql_init(&mysql_connection); @@ -960,11 +983,11 @@ static int dbConnect(char *host, char *user,char *passwd) #endif mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset); if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd, - NULL,opt_mysql_port,opt_mysql_unix_port, - 0))) + NULL,opt_mysql_port,opt_mysql_unix_port, + 0))) { DB_error(&mysql_connection, "when trying to connect"); - return 1; + DBUG_RETURN(1); } /* Don't dump SET NAMES with a pre-4.1 server (bug#7997). @@ -981,7 +1004,7 @@ static int dbConnect(char *host, char *user,char *passwd) if (mysql_query_with_error_report(mysql, 0, buff)) { safe_exit(EX_MYSQLERR); - return 1; + DBUG_RETURN(1); } /* set time_zone to UTC to allow dumping date types between servers with @@ -993,11 +1016,11 @@ static int dbConnect(char *host, char *user,char *passwd) if (mysql_query_with_error_report(mysql, 0, buff)) { safe_exit(EX_MYSQLERR); - return 1; + DBUG_RETURN(1); } } - return 0; -} /* dbConnect */ + DBUG_RETURN(0); +} /* connect_to_db */ /* @@ -1519,7 +1542,11 @@ static uint get_table_structure(char *table, char *db, char *table_type, { complete_insert= opt_complete_insert; if (!insert_pat_inited) - insert_pat_inited= init_dynamic_string(&insert_pat, "", 1024, 1024); + { + insert_pat_inited= 1; + if (init_dynamic_string(&insert_pat, "", 1024, 1024)) + safe_exit(EX_MYSQLERR); + } else dynstr_set(&insert_pat, ""); } @@ -1988,7 +2015,7 @@ continue_xml: */ -static void dump_triggers_for_table (char *table, char *db) +static void dump_triggers_for_table(char *table, char *db) { char *result_table; char name_buff[NAME_LEN*4+3], table_buff[NAME_LEN*2+3]; @@ -2176,7 +2203,7 @@ static void dump_table(char *table, char *db) The "table" could be a view. If so, we don't do anything here. */ if (strcmp (table_type, "VIEW") == 0) - return; + DBUG_VOID_RETURN; /* Check --no-data flag */ if (opt_no_data) @@ -2693,6 +2720,8 @@ static int dump_databases(char **db_names) { int result=0; char **db; + DBUG_ENTER("dump_databases"); + for (db= db_names ; *db ; db++) { if (dump_all_tables_in_db(*db)) @@ -2706,7 +2735,7 @@ static int dump_databases(char **db_names) result=1; } } - return result; + DBUG_RETURN(result); } /* dump_databases */ @@ -2721,7 +2750,7 @@ RETURN VALUES 0 Success. 1 Failure. */ -int init_dumping_views(char *qdatabase) +int init_dumping_views(char *qdatabase __attribute__((unused))) { return 0; } /* init_dumping_views */ @@ -2818,12 +2847,11 @@ static int init_dumping(char *database, int init_func(char*)) } /* init_dumping */ +/* Return 1 if we should copy the table */ + my_bool include_table(byte* hash_key, uint len) { - if (hash_search(&ignore_table, (byte*) hash_key, len)) - return FALSE; - - return TRUE; + return !hash_search(&ignore_table, (byte*) hash_key, len); } @@ -2832,16 +2860,16 @@ static int dump_all_tables_in_db(char *database) char *table; uint numrows; char table_buff[NAME_LEN*2+3]; - char hash_key[2*NAME_LEN+2]; /* "db.tablename" */ char *afterdot; int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql"); + DBUG_ENTER("dump_all_tables_in_db"); afterdot= strmov(hash_key, database); *afterdot++= '.'; if (init_dumping(database, init_dumping_tables)) - return 1; + DBUG_RETURN(1); if (opt_xml) print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); if (lock_tables) @@ -2895,7 +2923,7 @@ static int dump_all_tables_in_db(char *database) fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n"); fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n"); } - return 0; + DBUG_RETURN(0); } /* dump_all_tables_in_db */ @@ -3257,7 +3285,6 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, /* - SYNOPSIS Check if we the table is one of the table types that should be ignored: @@ -3297,8 +3324,8 @@ char check_if_ignore_table(const char *table_name, char *table_type) { if (mysql_errno(mysql) != ER_PARSE_ERROR) { /* If old MySQL version */ - verbose_msg("-- Warning: Couldn't get status information for " \ - "table %s (%s)\n", table_name,mysql_error(mysql)); + verbose_msg("-- Warning: Couldn't get status information for " + "table %s (%s)\n", table_name, mysql_error(mysql)); DBUG_RETURN(result); /* assume table is ok */ } } @@ -3653,19 +3680,24 @@ static my_bool get_view_structure(char *table, char* db) int main(int argc, char **argv) { + int exit_code; MY_INIT("mysqldump"); compatible_mode_normal_str[0]= 0; default_charset= (char *)mysql_universal_client_charset; bzero((char*) &ignore_table, sizeof(ignore_table)); - if (get_options(&argc, &argv)) + exit_code= get_options(&argc, &argv); + if (exit_code) { - my_end(0); - exit(EX_USAGE); + free_resources(0); + exit(exit_code); } - if (dbConnect(current_host, current_user, opt_password)) + if (connect_to_db(current_host, current_user, opt_password)) + { + free_resources(0); exit(EX_MYSQLERR); + } if (!path) write_header(md_result_file, *argv); @@ -3712,15 +3744,6 @@ err: dbDisconnect(current_host); if (!path) write_footer(md_result_file); - if (md_result_file != stdout) - my_fclose(md_result_file, MYF(0)); - my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); - if (hash_inited(&ignore_table)) - hash_free(&ignore_table); - if (extended_insert) - dynstr_free(&extended_row); - if (insert_pat_inited) - dynstr_free(&insert_pat); - my_end(0); + free_resources(); return(first_error); } /* main */ diff --git a/client/mysqltest.c b/client/mysqltest.c index 6871701e691..005f204d571 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -29,6 +29,7 @@ Matt Wagner <matt@mysql.com> Monty Jani + Holyfoot */ #define MTEST_VERSION "3.0" @@ -220,6 +221,12 @@ struct st_connection MYSQL* util_mysql; char *name; MYSQL_STMT* stmt; + + const char *cur_query; + int cur_query_len; + pthread_mutex_t mutex; + pthread_cond_t cond; + int query_done; }; struct st_connection connections[128]; struct st_connection* cur_con, *next_con, *connections_end; @@ -458,7 +465,6 @@ void mysql_disable_rpl_parse(MYSQL* mysql __attribute__((unused))) {} int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; } my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; } #endif - void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, int len); void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val); @@ -469,7 +475,56 @@ void handle_error(struct st_command*, const char *err_sqlstate, DYNAMIC_STRING *ds); void handle_no_error(struct st_command*); +#ifdef EMBEDDED_LIBRARY +/* + send_one_query executes query in separate thread what is + necessary in embedded library to run 'send' in proper way. + This implementation doesn't handle errors returned + by mysql_send_query. It's technically possible, though + i don't see where it is needed. +*/ +pthread_handler_t send_one_query(void *arg) +{ + struct st_connection *cn= (struct st_connection*)arg; + + mysql_thread_init(); + VOID(mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len)); + + mysql_thread_end(); + pthread_mutex_lock(&cn->mutex); + cn->query_done= 1; + VOID(pthread_cond_signal(&cn->cond)); + pthread_mutex_unlock(&cn->mutex); + pthread_exit(0); + return 0; +} + +static int do_send_query(struct st_connection *cn, const char *q, int q_len, + int flags) +{ + pthread_t tid; + + if (flags & QUERY_REAP_FLAG) + return mysql_send_query(&cn->mysql, q, q_len); + + if (pthread_mutex_init(&cn->mutex, NULL) || + pthread_cond_init(&cn->cond, NULL)) + die("Error in the thread library"); + cn->cur_query= q; + cn->cur_query_len= q_len; + cn->query_done= 0; + if (pthread_create(&tid, NULL, send_one_query, (void*)cn)) + die("Cannot start new thread for query"); + + return 0; +} + +#else /*EMBEDDED_LIBRARY*/ + +#define do_send_query(cn,q,q_len,flags) mysql_send_query(&cn->mysql, q, q_len) + +#endif /*EMBEDDED_LIBRARY*/ void do_eval(DYNAMIC_STRING *query_eval, const char *query, const char *query_end, my_bool pass_through_escape_chars) @@ -4506,7 +4561,6 @@ int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) } - /* Run query using MySQL C API @@ -4523,11 +4577,12 @@ int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) error - function will not return */ -void run_query_normal(MYSQL *mysql, struct st_command *command, +void run_query_normal(struct st_connection *cn, struct st_command *command, int flags, char *query, int query_len, DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= 0; + MYSQL *mysql= &cn->mysql; int err= 0, counter= 0; DBUG_ENTER("run_query_normal"); DBUG_PRINT("enter",("flags: %d", flags)); @@ -4538,14 +4593,26 @@ void run_query_normal(MYSQL *mysql, struct st_command *command, /* Send the query */ - if (mysql_send_query(mysql, query, query_len)) + if (do_send_query(cn, query, query_len, flags)) { handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; } } - +#ifdef EMBEDDED_LIBRARY + /* + Here we handle 'reap' command, so we need to check if the + query's thread was finished and probably wait + */ + else if (flags & QUERY_REAP_FLAG) + { + pthread_mutex_lock(&cn->mutex); + while (!cn->query_done) + pthread_cond_wait(&cn->cond, &cn->mutex); + pthread_mutex_unlock(&cn->mutex); + } +#endif /*EMBEDDED_LIBRARY*/ if (!(flags & QUERY_REAP_FLAG)) DBUG_VOID_RETURN; @@ -5036,8 +5103,9 @@ int util_query(MYSQL* org_mysql, const char* query){ */ -void run_query(MYSQL *mysql, struct st_command *command, int flags) +void run_query(struct st_connection *cn, struct st_command *command, int flags) { + MYSQL *mysql= &cn->mysql; DYNAMIC_STRING *ds; DYNAMIC_STRING ds_result; DYNAMIC_STRING ds_warnings; @@ -5194,7 +5262,7 @@ void run_query(MYSQL *mysql, struct st_command *command, int flags) match_re(&ps_re, query)) run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings); else - run_query_normal(mysql, command, flags, query, query_len, + run_query_normal(cn, command, flags, query, query_len, ds, &ds_warnings); if (sp_created) @@ -5659,7 +5727,7 @@ int main(int argc, char **argv) strmake(command->require_file, save_file, sizeof(save_file)); save_file[0]= 0; } - run_query(&cur_con->mysql, command, QUERY_REAP_FLAG|QUERY_SEND_FLAG); + run_query(cur_con, command, QUERY_REAP_FLAG|QUERY_SEND_FLAG); display_result_vertically= old_display_result_vertically; command->last_argument= command->end; command_executed++; @@ -5690,7 +5758,7 @@ int main(int argc, char **argv) strmake(command->require_file, save_file, sizeof(save_file)); save_file[0]= 0; } - run_query(&cur_con->mysql, command, flags); + run_query(cur_con, command, flags); command_executed++; command->last_argument= command->end; break; @@ -5716,7 +5784,7 @@ int main(int argc, char **argv) the query and read the result some time later when reap instruction is given on this connection. */ - run_query(&cur_con->mysql, command, QUERY_SEND_FLAG); + run_query(cur_con, command, QUERY_SEND_FLAG); command_executed++; command->last_argument= command->end; break; |