diff options
author | unknown <monty@mysql.com> | 2003-12-19 16:34:48 +0200 |
---|---|---|
committer | unknown <monty@mysql.com> | 2003-12-19 16:34:48 +0200 |
commit | de8b2bbd301a17a7a02ea62cff806950071dfbce (patch) | |
tree | 05b144ca850fc0bb99c1922907bfb2e9ba19fc77 /client | |
parent | 5372bc432d3ecc476c777d24dd393a9f2c51ea4d (diff) | |
parent | c9f5145abb9815220b51a9707c6ede0c77b3e1f0 (diff) | |
download | mariadb-git-de8b2bbd301a17a7a02ea62cff806950071dfbce.tar.gz |
merge
client/mysqldump.c:
Auto merged
client/mysqltest.c:
Auto merged
include/my_global.h:
Auto merged
libmysqld/lib_sql.cc:
Auto merged
mysql-test/r/warnings.result:
Auto merged
mysql-test/t/type_enum.test:
Auto merged
sql/field.cc:
Auto merged
sql/lex.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_show.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/table.cc:
Auto merged
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 10 | ||||
-rw-r--r-- | client/mysqldump.c | 177 |
2 files changed, 142 insertions, 45 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 42088d107ed..df55ebcfab0 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -380,7 +380,7 @@ int main(int argc,char *argv[]) put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.", INFO_INFO); sprintf((char*) glob_buffer.ptr(), - "Your MySQL connection id is %ld to server version: %s\n", + "Your MySQL connection id is %lu to server version: %s\n", mysql_thread_id(&mysql),mysql_get_server_info(&mysql)); put_info((char*) glob_buffer.ptr(),INFO_INFO); @@ -613,8 +613,8 @@ static struct my_option my_long_options[] = 0, 1}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_ULONG, - REQUIRED_ARG, 16 *1024L*1024L, 4096, 512*1024L*1024L, MALLOC_OVERHEAD, - 1024, 0}, + REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L, + MALLOC_OVERHEAD, 1024, 0}, {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_ULONG, REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0}, @@ -2346,7 +2346,7 @@ com_connect(String *buffer, char *line) if (connected) { - sprintf(buff,"Connection id: %ld",mysql_thread_id(&mysql)); + sprintf(buff,"Connection id: %lu",mysql_thread_id(&mysql)); put_info(buff,INFO_INFO); sprintf(buff,"Current database: %s\n", current_db ? current_db : "*** NONE ***"); @@ -2652,7 +2652,7 @@ com_status(String *buffer __attribute__((unused)), { MYSQL_RES *result; LINT_INIT(result); - tee_fprintf(stdout, "\nConnection id:\t\t%ld\n",mysql_thread_id(&mysql)); + tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql)); if (!mysql_query(&mysql,"select DATABASE(),USER()") && (result=mysql_use_result(&mysql))) { diff --git a/client/mysqldump.c b/client/mysqldump.c index af47b7c6955..018cd43ce87 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.3" +#define DUMP_VERSION "10.4" #include <my_global.h> #include <my_sys.h> @@ -81,7 +81,7 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick= 1, extended_insert= 1, opt_alldbs=0,opt_create_db=0,opt_first_slave=0,opt_set_names=0, opt_autocommit=0,opt_master_data,opt_disable_keys=1,opt_xml=0, opt_delete_master_logs=0, tty_password=0, - opt_single_transaction=0; + opt_single_transaction=0, opt_comments= 0; static MYSQL mysql_connection,*sock=0; static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, *current_host=0,*path=0,*fields_terminated=0, @@ -276,12 +276,15 @@ static struct my_option my_long_options[] = NO_ARG, 0, 0, 0, 0, 0, 0}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, - GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, 1024*1024L*1024L, - MALLOC_OVERHEAD, 1024, 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*) &net_buffer_length, (gptr*) &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}, {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -298,6 +301,8 @@ static int init_dumping(char *); 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 void print_version(void) { @@ -341,7 +346,7 @@ static void write_header(FILE *sql_file, char *db_name) fputs("<?xml version=\"1.0\"?>\n", sql_file); fputs("<mysqldump>\n", sql_file); } - else + else if (opt_comments) { fprintf(sql_file, "-- MySQL dump %s\n--\n", DUMP_VERSION); fprintf(sql_file, "-- Host: %s Database: %s\n", @@ -652,6 +657,23 @@ static char *quote_name(const char *name, char *buff, my_bool force) } /* quote_name */ + +static char *quote_for_like(const char *name, char *buff) +{ + char *to= buff; + *to++= '\''; + while (*name) + { + if (*name == '\'' || *name == '_' || *name == '\\' || *name == '%') + *to++= '\\'; + *to++= *name++; + } + to[0]= '\''; + to[1]= 0; + return buff; +} + + /* Quote and print a string. @@ -850,7 +872,8 @@ static uint getTableStructure(char *table, char* db) } write_header(sql_file, db); } - fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", + if (!opt_xml && opt_comments) + fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", result_table); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); @@ -926,7 +949,7 @@ static uint getTableStructure(char *table, char* db) } write_header(sql_file, db); } - if (!opt_xml) + if (!opt_xml && opt_comments) fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", result_table); if (opt_drop) @@ -1063,16 +1086,9 @@ static uint getTableStructure(char *table, char* db) /* Get MySQL specific create options */ if (create_options) { - ulong len= strlen(table); - char *tmp= (char*) my_malloc(len * 2 + 1, MYF(MY_WME)); - if (!tmp) - { - ignore_errors= 0; - safe_exit(EX_MYSQLERR); - } - mysql_real_escape_string(&mysql_connection, tmp, table, len); - sprintf(buff,"show table status like \"%s\"", tmp); - my_free(tmp, MYF(MY_WME)); + 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_errno(sock) != ER_PARSE_ERROR) @@ -1187,11 +1203,23 @@ static void dumpTable(uint numFields, char *table) MYSQL_FIELD *field; MYSQL_ROW row; ulong rownr, row_break, total_length, init_length; + const char *table_type; - if (verbose) - fprintf(stderr, "-- Sending SELECT query...\n"); result_table= quote_name(table,table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); + + /* Check table type */ + if ((table_type= check_if_ignore_table(table))) + { + if (verbose) + fprintf(stderr, + "-- Skipping data for table '%s' because it's of type %s\n", + table, table_type); + return; + } + + if (verbose) + fprintf(stderr, "-- Sending SELECT query...\n"); if (path) { char filename[FN_REFLEN], tmp_path[FN_REFLEN]; @@ -1230,14 +1258,14 @@ static void dumpTable(uint numFields, char *table) } else { - if (!opt_xml) + if (!opt_xml && opt_comments) fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n", result_table); sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", result_table); if (where) { - if (!opt_xml) + if (!opt_xml && opt_comments) fprintf(md_result_file,"-- WHERE: %s\n",where); strxmov(strend(query), " WHERE ",where,NullS); } @@ -1333,11 +1361,23 @@ static void dumpTable(uint numFields, char *table) } else { - /* change any strings ("inf","nan",..) into NULL */ + /* change any strings ("inf", "-inf", "nan") into NULL */ char *ptr = row[i]; - dynstr_append(&extended_row, - (!my_isalpha(charset_info,*ptr)) ? - ptr : "NULL"); + if (my_isalpha(charset_info, *ptr) || (*ptr == '-' && + my_isalpha(charset_info, ptr[1]))) + dynstr_append(&extended_row, "NULL"); + else + { + if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + dynstr_append(&extended_row, "\""); + dynstr_append(&extended_row, ptr); + dynstr_append(&extended_row, "\""); + } + else + dynstr_append(&extended_row, ptr); + } } } else @@ -1369,7 +1409,7 @@ static void dumpTable(uint numFields, char *table) } else { - /* change any strings ("inf","nan",..) into NULL */ + /* change any strings ("inf", "-inf", "nan") into NULL */ char *ptr = row[i]; if (opt_xml) { @@ -1379,19 +1419,20 @@ static void dumpTable(uint numFields, char *table) md_result_file); fputs("</field>\n", md_result_file); } + else if (my_isalpha(charset_info, *ptr) || + (*ptr == '-' && my_isalpha(charset_info, ptr[1]))) + fputs("NULL", md_result_file); + else if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + fputs("\"", md_result_file); + fputs(ptr, md_result_file); + fputs("\"", md_result_file); + } else - fputs((!my_isalpha(charset_info,*ptr)) ? - ptr : "NULL", md_result_file); + fputs(ptr, md_result_file); } } - else - { - if (opt_xml) - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, "NULL</field>\n"); - else - fputs("NULL", md_result_file); - } } } @@ -1529,8 +1570,8 @@ static int init_dumping(char *database) */ char quoted_database_buf[64*2+3]; char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted); - - fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); + if (opt_comments) + fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); if (!opt_create_db) { char qbuf[256]; @@ -1726,6 +1767,61 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, } /* print_value */ +/* + Check if we the table is one of the table types that should be ignored: + MRG_ISAM, MRG_MYISAM + + SYNOPSIS + check_if_ignore_table() + table_name Table name to check + + GLOBAL VARIABLES + sock MySQL socket + verbose Write warning messages + + RETURN + 0 Table should be backuped + # Type of table (that should be skipped) +*/ + +static const char *check_if_ignore_table(const char *table_name) +{ + char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN]; + MYSQL_RES *res; + MYSQL_ROW row; + const char *result= 0; + + sprintf(buff,"show table status like %s", + quote_for_like(table_name, show_name_buff)); + if (mysql_query(sock, buff)) + { + if (mysql_errno(sock) != ER_PARSE_ERROR) + { /* If old MySQL version */ + if (verbose) + fprintf(stderr, + "-- Warning: Couldn't get status information for table %s (%s)\n", + table_name,mysql_error(sock)); + return 0; /* assume table is ok */ + } + } + if (!(res= mysql_store_result(sock)) || + !(row= mysql_fetch_row(res))) + { + fprintf(stderr, + "Error: Couldn't read status information for table %s (%s)\n", + table_name, mysql_error(sock)); + if (res) + 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; + mysql_free_result(res); + return result; +} + + int main(int argc, char **argv) { MYSQL_ROW row; @@ -1795,8 +1891,9 @@ int main(int argc, char **argv) row = mysql_fetch_row(master); if (row && row[0] && row[1]) { - fprintf(md_result_file, - "\n--\n-- Position to start replication from\n--\n\n"); + 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]); |