diff options
author | unknown <monty@mashka.mysql.fi> | 2003-09-11 20:31:40 +0300 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2003-09-11 20:31:40 +0300 |
commit | 41824a35338012ff8196eb975f961d5e0f0e2a22 (patch) | |
tree | 1475a169c541e6b7aedb36103dd255fe52fc0517 /client | |
parent | 07bc35e1d024e5e3b81b131a47878510f0521609 (diff) | |
parent | d32bdcb1bfc274476cdd945e66e00f3ec31253c3 (diff) | |
download | mariadb-git-41824a35338012ff8196eb975f961d5e0f0e2a22.tar.gz |
merge with 4.1 tree
client/mysqltest.c:
Auto merged
include/mysql.h:
Auto merged
libmysql/errmsg.c:
Auto merged
libmysql/libmysql.c:
Auto merged
mysql-test/mysql-test-run.sh:
Auto merged
sql/field.cc:
Auto merged
sql/item.cc:
Auto merged
sql/item.h:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/item_func.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/share/portuguese/errmsg.txt:
Auto merged
sql/share/spanish/errmsg.txt:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_table.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
tests/client_test.c:
Auto merged
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 11 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 88 | ||||
-rw-r--r-- | client/mysqldump.c | 165 | ||||
-rw-r--r-- | client/mysqlimport.c | 14 | ||||
-rw-r--r-- | client/mysqltest.c | 95 |
5 files changed, 190 insertions, 183 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index b249ccbfbc5..37c83411091 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1811,10 +1811,11 @@ print_field_types(MYSQL_RES *result) MYSQL_FIELD *field; while ((field = mysql_fetch_field(result))) { - tee_fprintf(PAGER,"'%s.%s.%s.%s' %d %d %d %d %d\n", + tee_fprintf(PAGER,"Catalog: '%s'\nDatabase: '%s'\nTable: '%s'\nName: '%s'\nType: %d\nLength: %d\nMax length: %d\nIs_null: %d\nFlags: %d\nDecimals: %d\n\n", field->catalog, field->db, field->table, field->name, (int) field->type, - field->length, field->max_length, + field->length, field->max_length, + !IS_NOT_NULL(field->flags), field->flags, field->decimals); } tee_puts("", PAGER); @@ -2650,10 +2651,10 @@ com_status(String *buffer __attribute__((unused)), (void) mysql_fetch_row(result); // Read eof } #ifdef HAVE_OPENSSL - if (mysql.net.vio && mysql.net.vio->ssl_ && - SSL_get_cipher(mysql.net.vio->ssl_)) + if (mysql.net.vio && mysql.net.vio->ssl_arg && + SSL_get_cipher((SSL*) mysql.net.vio->ssl_arg)) tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n", - SSL_get_cipher(mysql.net.vio->ssl_)); + SSL_get_cipher((SSL*) mysql.net.vio->ssl_arg)); else #endif /* HAVE_OPENSSL */ tee_puts("SSL:\t\t\tNot in use", stdout); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 9fdda0a3853..942c55f3078 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -182,7 +182,16 @@ public: void process(Append_block_log_event *ae) { if (ae->file_id >= file_names.elements) - die("Skiped CreateFile event for file_id: %u",ae->file_id); + { + /* + 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. + */ + fprintf(stderr,"Warning: ignoring Append_block as there is no \ +Create_file event for file_id: %u\n",ae->file_id); + return; + } Create_file_log_event* ce= *((Create_file_log_event**)file_names.buffer + ae->file_id); append_to_file(ce->fname,O_APPEND|O_BINARY|O_WRONLY,ae->block,ae->block_len); @@ -567,45 +576,49 @@ Could not read entry at offset %s : Error in log format or read error", } if (rec_count >= offset) { - // see if we should skip this event (only care about queries for now) - if (one_database) - { - if (ev->get_type_code() == QUERY_EVENT) + if (!short_form) + fprintf(result_file, "# at %s\n",llstr(old_off,llbuff)); + + switch (ev->get_type_code()) { + case QUERY_EVENT: + if (one_database) { - //const char * log_dbname = ev->get_db(); const char * log_dbname = ((Query_log_event*)ev)->db; - //printf("entry: %llu, database: %s\n", rec_count, log_dbname); - if ((log_dbname != NULL) && (strcmp(log_dbname, database))) { - //printf("skipping, %s is not %s\n", log_dbname, database); rec_count++; delete ev; continue; // next } -#ifndef DBUG_OFF - else - { - printf("no skip\n"); - } -#endif - } -#ifndef DBUG_OFF - else - { - const char * query_type = ev->get_type_str(); - printf("not query -- %s\n", query_type); } -#endif - } - if (!short_form) - fprintf(result_file, "# at %s\n",llstr(old_off,llbuff)); - - switch (ev->get_type_code()) { + ev->print(result_file, short_form, last_db); + break; case CREATE_FILE_EVENT: { Create_file_log_event* ce= (Create_file_log_event*)ev; - ce->print(result_file, short_form, last_db,true); + if (one_database) + { + /* + We test if this event has to be ignored. If yes, we don't save this + event; this will have the good side-effect of ignoring all related + Append_block and Exec_load. + Note that Load event from 3.23 is not tested. + */ + const char * log_dbname = ce->db; + if ((log_dbname != NULL) && (strcmp(log_dbname, database))) + { + rec_count++; + delete ev; + continue; // next + } + } + /* + We print the event, but with a leading '#': this is just to inform the + user of the original command; the command we want to execute will be a + derivation of this original command (we will change the filename and + use LOCAL), prepared in the 'case EXEC_LOAD_EVENT' below. + */ + ce->print(result_file, short_form, last_db, true); load_processor.process(ce); ev= 0; break; @@ -619,9 +632,20 @@ Could not read entry at offset %s : Error in log format or read error", ev->print(result_file, short_form, last_db); Execute_load_log_event *exv= (Execute_load_log_event*)ev; Create_file_log_event *ce= load_processor.grab_event(exv->file_id); - ce->print(result_file, short_form, last_db,true); - my_free((char*)ce->fname,MYF(MY_WME)); - delete ce; + /* + 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 + Create_file event). Print a warning comment. + */ + if (ce) + { + ce->print(result_file, short_form, last_db,true); + my_free((char*)ce->fname,MYF(MY_WME)); + delete ce; + } + else + fprintf(stderr,"Warning: ignoring Exec_load as there is no \ +Create_file event for file_id: %u\n",exv->file_id); break; } default: @@ -633,7 +657,7 @@ Could not read entry at offset %s : Error in log format or read error", delete ev; } if (fd >= 0) - my_close(fd, MYF(MY_WME)); + my_close(fd, MYF(MY_WME)); end_io_cache(file); } diff --git a/client/mysqldump.c b/client/mysqldump.c index feaaaccd01d..5e57f6480db 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -297,7 +297,7 @@ static int dump_all_tables_in_db(char *db); static int init_dumping(char *); static int dump_databases(char **); static int dump_all_databases(); -static char *quote_name(char *name, char *buff); +static char *quote_name(const char *name, char *buff, my_bool force); static void print_quoted_xml(FILE *output, char *fname, char *str, uint len); static void print_version(void) @@ -347,7 +347,7 @@ static void write_header(FILE *sql_file, char *db_name) fprintf(sql_file, "-- MySQL dump %s\n--\n", DUMP_VERSION); fprintf(sql_file, "-- Host: %s Database: %s\n", current_host ? current_host : "localhost", db_name ? db_name : ""); - fputs("---------------------------------------------------------\n", + fputs("-- ------------------------------------------------------\n", sql_file); fprintf(sql_file, "-- Server version\t%s\n", mysql_get_server_info(&mysql_connection)); @@ -631,33 +631,43 @@ static my_bool test_if_special_chars(const char *str) return 0; } /* test_if_special_chars */ -static char *quote_name(char *name, char *buff) + +static char *quote_name(const char *name, char *buff, my_bool force) { - char *end; - if (!opt_quoted && !test_if_special_chars(name)) - return name; - buff[0]=QUOTE_CHAR; - end=strmov(buff+1,name); - end[0]=QUOTE_CHAR; - end[1]=0; + char *to= buff; + if (!force && !opt_quoted && !test_if_special_chars(name)) + return (char*) name; + *to++= QUOTE_CHAR; + while (*name) + { + if (*name == QUOTE_CHAR) + *to= QUOTE_CHAR; + *to++= *name++; + } + to[0]=QUOTE_CHAR; + to[1]=0; return buff; } /* quote_name */ /* -** getStructure -- retrievs database structure, prints out corresponding -** CREATE statement and fills out insert_pat. -** Return values: number of fields in table, 0 if error + getStructure -- retrievs database structure, prints out corresponding + CREATE statement and fills out insert_pat. + + RETURN + number of fields in table, 0 if error */ + static uint getTableStructure(char *table, char* db) { MYSQL_RES *tableRes; MYSQL_ROW row; my_bool init=0; uint numFields; - char *strpos, *table_name; + char *strpos, *result_table, *opt_quoted_table; const char *delayed; - char name_buff[NAME_LEN+3],table_buff[NAME_LEN+3]; + char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3]; FILE *sql_file = md_result_file; DBUG_ENTER("getTableStructure"); @@ -667,7 +677,8 @@ static uint getTableStructure(char *table, char* db) fprintf(stderr, "-- Retrieving table structure for table %s...\n", table); sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", (opt_quoted || opt_keywords)); - table_name=quote_name(table,table_buff); + result_table= quote_name(table, table_buff, 1); + opt_quoted_table= quote_name(table, table_buff2, 0); if (!mysql_query(sock,insert_pat)) { /* using SHOW CREATE statement */ @@ -691,7 +702,7 @@ static uint getTableStructure(char *table, char* db) end= strmov(end, ","); } } - end= strmov(--end, "\" */"); + end= strmov(end-1, "\" */"); if (mysql_query(sock, buff)) { fprintf(stderr, "%s: Can't set the compatible mode '%s' (%s)\n", @@ -701,11 +712,11 @@ static uint getTableStructure(char *table, char* db) } } - sprintf(buff,"show create table `%s`",table); + sprintf(buff,"show create table %s", result_table); if (mysql_query(sock, buff)) { - fprintf(stderr, "%s: Can't get CREATE TABLE for table '%s' (%s)\n", - my_progname, table, mysql_error(sock)); + 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); } @@ -724,10 +735,10 @@ static uint getTableStructure(char *table, char* db) write_header(sql_file, db); } if (!opt_xml) - fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n", - table); + 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",table_name); + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); tableRes=mysql_store_result(sock); row=mysql_fetch_row(tableRes); @@ -735,11 +746,11 @@ static uint getTableStructure(char *table, char* db) fprintf(sql_file, "%s;\n", row[1]); mysql_free_result(tableRes); } - sprintf(insert_pat,"show fields from %s",table_name); + sprintf(insert_pat,"show fields from %s", result_table); if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock))) { - fprintf(stderr, "%s: Can't get info about table: '%s'\nerror: %s\n", - my_progname, table, mysql_error(sock)); + 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); @@ -747,10 +758,11 @@ static uint getTableStructure(char *table, char* db) } if (cFlag) - sprintf(insert_pat, "INSERT %sINTO %s (", delayed, table_name); + sprintf(insert_pat, "INSERT %sINTO %s (", delayed, opt_quoted_table); else { - sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, table_name); + sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, + opt_quoted_table); if (!extended_insert) strcat(insert_pat,"("); } @@ -765,7 +777,7 @@ static uint getTableStructure(char *table, char* db) } init=1; if (cFlag) - strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME],name_buff)); + strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME], name_buff, 0)); } numFields = (uint) mysql_num_rows(tableRes); mysql_free_result(tableRes); @@ -775,11 +787,11 @@ static uint getTableStructure(char *table, char* db) /* fprintf(stderr, "%s: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", my_progname, mysql_error(sock)); */ - sprintf(insert_pat,"show fields from %s",table_name); + sprintf(insert_pat,"show fields from %s", result_table); if (mysql_query(sock,insert_pat) || !(tableRes=mysql_store_result(sock))) { - fprintf(stderr, "%s: Can't get info about table: '%s'\nerror: %s\n", - my_progname, table, mysql_error(sock)); + 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); } @@ -801,17 +813,17 @@ static uint getTableStructure(char *table, char* db) write_header(sql_file, db); } if (!opt_xml) - fprintf(sql_file, "\n--\n-- Table structure for table '%s'\n--\n\n", - table); + 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",table_name); - fprintf(sql_file, "CREATE TABLE %s (\n", table_name); + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",result_table); + fprintf(sql_file, "CREATE TABLE %s (\n", result_table); } if (cFlag) - sprintf(insert_pat, "INSERT %sINTO %s (", delayed, table_name); + sprintf(insert_pat, "INSERT %sINTO %s (", delayed, result_table); else { - sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, table_name); + sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, result_table); if (!extended_insert) strcat(insert_pat,"("); } @@ -829,15 +841,17 @@ static uint getTableStructure(char *table, char* db) } init=1; if (cFlag) - strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME],name_buff)); + strpos=strmov(strpos,quote_name(row[SHOW_FIELDNAME], name_buff, 0)); if (!tFlag) { if (opt_keywords) - fprintf(sql_file, " %s.%s %s", table_name, - quote_name(row[SHOW_FIELDNAME],name_buff), row[SHOW_TYPE]); + fprintf(sql_file, " %s.%s %s", result_table, + quote_name(row[SHOW_FIELDNAME],name_buff, 0), + row[SHOW_TYPE]); else fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME], - name_buff), row[SHOW_TYPE]); + name_buff, 0), + row[SHOW_TYPE]); if (row[SHOW_DEFAULT]) { fputs(" DEFAULT ", sql_file); @@ -856,11 +870,11 @@ 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]; uint keynr,primary_key; - sprintf(buff,"show keys from %s",table_name); + sprintf(buff,"show keys from %s", result_table); if (mysql_query(sock, buff)) { - fprintf(stderr, "%s: Can't get keys for table '%s' (%s)\n", - my_progname, table, mysql_error(sock)); + 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); @@ -897,15 +911,15 @@ static uint getTableStructure(char *table, char* db) putc(')', sql_file); if (atoi(row[1])) /* Test if duplicate key */ /* Duplicate allowed */ - fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff)); + fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0)); else if (keynr == primary_key) fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */ else - fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff)); + fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff,0)); } else putc(',', sql_file); - fputs(quote_name(row[4],name_buff), sql_file); + fputs(quote_name(row[4], name_buff, 0), sql_file); if (row[7]) fprintf(sql_file, " (%s)",row[7]); /* Sub key */ } @@ -916,23 +930,23 @@ static uint getTableStructure(char *table, char* db) /* Get MySQL specific create options */ if (create_options) { - sprintf(buff,"show table status like '%s'",table); + sprintf(buff,"show table status like %s",result_table); 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,mysql_error(sock)); + "-- Warning: Couldn't get status information for table %s (%s)\n", + result_table,mysql_error(sock)); } } else if (!(tableRes=mysql_store_result(sock)) || !(row=mysql_fetch_row(tableRes))) { fprintf(stderr, - "Error: Couldn't read status information for table '%s' (%s)\n", - table,mysql_error(sock)); + "Error: Couldn't read status information for table %s (%s)\n", + result_table,mysql_error(sock)); } else { @@ -1016,6 +1030,7 @@ static char *field_escape(char *to,const char *from,uint length) static void dumpTable(uint numFields, char *table) { char query[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3]; + char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table; MYSQL_RES *res; MYSQL_FIELD *field; MYSQL_ROW row; @@ -1023,6 +1038,8 @@ static void dumpTable(uint numFields, char *table) 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); if (path) { char filename[FN_REFLEN], tmp_path[FN_REFLEN]; @@ -1049,7 +1066,7 @@ static void dumpTable(uint numFields, char *table) end= add_load_option(end, lines_terminated, " LINES TERMINATED BY"); *end= '\0'; - sprintf(buff," FROM %s",quote_name(table,table_buff)); + sprintf(buff," FROM %s", result_table); end= strmov(end,buff); if (where) end= strxmov(end, " WHERE ",where,NullS); @@ -1062,10 +1079,10 @@ static void dumpTable(uint numFields, char *table) else { if (!opt_xml) - fprintf(md_result_file,"\n--\n-- Dumping data for table '%s'\n--\n", - table); + fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n", + result_table); sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", - quote_name(table,table_buff)); + result_table); if (where) { if (!opt_xml) @@ -1092,18 +1109,17 @@ static void dumpTable(uint numFields, char *table) fprintf(stderr, "-- Retrieving rows...\n"); if (mysql_num_fields(res) != numFields) { - fprintf(stderr,"%s: Error in field count for table: '%s' ! Aborting.\n", - my_progname,table); + fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", + my_progname, result_table); safe_exit(EX_CONSCHECK); return; } if (opt_disable_keys) - fprintf(md_result_file,"/*!40000 ALTER TABLE %s DISABLE KEYS */;\n", - quote_name(table, table_buff)); + fprintf(md_result_file, "\n/*!40000 ALTER TABLE %s DISABLE KEYS */;\n", + opt_quoted_table); if (opt_lock) - fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", - quote_name(table,table_buff)); + fprintf(md_result_file,"LOCK TABLES %s WRITE;\n", opt_quoted_table); total_length=net_buffer_length; /* Force row break */ row_break=0; @@ -1131,8 +1147,8 @@ static void dumpTable(uint numFields, char *table) { if (!(field = mysql_fetch_field(res))) { - sprintf(query,"%s: Not enough fields from table '%s'! Aborting.\n", - my_progname,table); + sprintf(query,"%s: Not enough fields from table %s! Aborting.\n", + my_progname, result_table); fputs(query,stderr); safe_exit(EX_CONSCHECK); return; @@ -1259,11 +1275,11 @@ static void dumpTable(uint numFields, char *table) fflush(md_result_file); if (mysql_errno(sock)) { - sprintf(query,"%s: Error %d: %s when dumping table '%s' at row: %ld\n", + sprintf(query,"%s: Error %d: %s when dumping table %s at row: %ld\n", my_progname, mysql_errno(sock), mysql_error(sock), - table, + result_table, rownr); fputs(query,stderr); safe_exit(EX_CONSCHECK); @@ -1273,7 +1289,7 @@ static void dumpTable(uint numFields, char *table) fputs("UNLOCK TABLES;\n", md_result_file); if (opt_disable_keys) fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n", - quote_name(table,table_buff)); + opt_quoted_table); if (opt_autocommit) fprintf(md_result_file, "commit;\n"); mysql_free_result(res); @@ -1415,7 +1431,7 @@ static int dump_all_tables_in_db(char *database) { char *table; uint numrows; - char table_buff[NAME_LEN+3]; + char table_buff[NAME_LEN*2+3]; if (init_dumping(database)) return 1; @@ -1427,7 +1443,7 @@ static int dump_all_tables_in_db(char *database) init_dynamic_string(&query, "LOCK TABLES ", 256, 1024); for (numrows=0 ; (table = getTableName(1)) ; numrows++) { - dynstr_append(&query, quote_name(table, table_buff)); + 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)) @@ -1459,7 +1475,7 @@ static int dump_all_tables_in_db(char *database) static int dump_selected_tables(char *db, char **table_names, int tables) { uint numrows; - char table_buff[NAME_LEN+3]; + char table_buff[NAME_LEN*+3]; if (init_dumping(db)) return 1; @@ -1471,7 +1487,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) init_dynamic_string(&query, "LOCK TABLES ", 256, 1024); for (i=0 ; i < tables ; i++) { - dynstr_append(&query, quote_name(table_names[i], table_buff)); + dynstr_append(&query, quote_name(table_names[i], table_buff, 1)); dynstr_append(&query, " READ /*!32311 LOCAL */,"); } if (mysql_real_query(sock, query.str, query.length-1)) @@ -1643,9 +1659,8 @@ int main(int argc, char **argv) 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' ;\n", row[0]); - fprintf(md_result_file, "CHANGE MASTER TO MASTER_LOG_POS=%s ;\n", - row[1]); + "CHANGE MASTER TO MASTER_LOG_FILE='%s', \ +MASTER_LOG_POS=%s ;\n",row[0],row[1]); } mysql_free_result(master); } diff --git a/client/mysqlimport.c b/client/mysqlimport.c index d049d69011b..5ad6d1dc429 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -45,16 +45,15 @@ static char *opt_password=0, *current_user=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, *opt_columns=0, *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; -static uint opt_mysql_port=0; +static uint opt_mysql_port= 0, opt_protocol= 0; static my_string opt_mysql_unix_port=0; -static my_string opt_ignore_lines=0; +static longlong opt_ignore_lines= -1; static CHARSET_INFO *charset_info= &my_charset_latin1; #include <sslopt-vars.h> #ifdef HAVE_SMEM static char *shared_memory_base_name=0; #endif -static uint opt_protocol=0; static struct my_option my_long_options[] = { @@ -97,7 +96,7 @@ static struct my_option my_long_options[] = {"ignore", 'i', "If duplicate unique key was found, keep old row.", (gptr*) &ignore, (gptr*) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.", - (gptr*) &opt_ignore_lines, (gptr*) &opt_ignore_lines, 0, GET_STR, + (gptr*) &opt_ignore_lines, (gptr*) &opt_ignore_lines, 0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", (gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR, @@ -259,7 +258,7 @@ static int get_options(int *argc, char ***argv) static int write_to_table(char *filename, MYSQL *sock) { char tablename[FN_REFLEN], hard_path[FN_REFLEN], - sql_statement[FN_REFLEN*2+256], *end; + sql_statement[FN_REFLEN*16+256], *end; my_bool local_file; DBUG_ENTER("write_to_table"); DBUG_PRINT("enter",("filename: %s",filename)); @@ -311,8 +310,9 @@ static int write_to_table(char *filename, MYSQL *sock) " OPTIONALLY ENCLOSED BY"); end= add_load_option(end, escaped, " ESCAPED BY"); end= add_load_option(end, lines_terminated, " LINES TERMINATED BY"); - if (opt_ignore_lines) - end= strmov(strmov(strmov(end, " IGNORE "), opt_ignore_lines), " LINES"); + if (opt_ignore_lines >= 0) + end= strmov(longlong10_to_str(opt_ignore_lines, + strmov(end, " IGNORE "),10), " LINES"); if (opt_columns) end= strmov(strmov(strmov(end, " ("), opt_columns), ")"); *end= '\0'; diff --git a/client/mysqltest.c b/client/mysqltest.c index 7b5aee49bd5..92ed47221bd 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -42,7 +42,7 @@ **********************************************************************/ -#define MTEST_VERSION "1.29" +#define MTEST_VERSION "1.30" #include <my_global.h> #include <mysql_embed.h> @@ -227,6 +227,13 @@ const char *command_names[]= "connection", "query", "connect", + /* the difference between sleep and real_sleep is that sleep will use + the delay from command line (--sleep) if there is one. + real_sleep always uses delay from it's argument. + the logic is that sometimes delays are cpu-dependent (and --sleep + can be used to set this delay. real_sleep is used for cpu-independent + delays + */ "sleep", "real_sleep", "inc", @@ -503,15 +510,6 @@ void init_parser() memset(&var_reg,0, sizeof(var_reg)); } -int hex_val(int c) -{ - if (my_isdigit(charset_info,c)) - return c - '0'; - else if ((c = my_tolower(charset_info,c)) >= 'a' && c <= 'f') - return c - 'a' + 10; - else - return -1; -} int dyn_string_cmp(DYNAMIC_STRING* ds, const char* fname) { @@ -924,7 +922,28 @@ int var_query_set(VAR* v, const char* p, const char** p_end) } if ((row = mysql_fetch_row(res)) && row[0]) - eval_expr(v, row[0], 0); + { + /* + Concatenate all row results with tab in between to allow us to work + with results from many columns (for example from SHOW VARIABLES) + */ + DYNAMIC_STRING result; + uint i; + ulong *lengths; + char *end; + + init_dynamic_string(&result, "", 16384, 65536); + lengths= mysql_fetch_lengths(res); + for (i=0; i < mysql_num_fields(res); i++) + { + if (row[0]) + dynstr_append_mem(&result, row[i], lengths[i]); + dynstr_append_mem(&result, "\t", 1); + } + end= result.str + result.length-1; + eval_expr(v, result.str, (const char**) &end); + dynstr_free(&result); + } else eval_expr(v, "", 0); @@ -981,8 +1000,6 @@ int eval_expr(VAR* v, const char* p, const char** p_end) return 0; } - if (p_end) - *p_end = 0; die("Invalid expr: %s", p); return 1; } @@ -1279,7 +1296,7 @@ static char *get_string(char **to_ptr, char **from_ptr, VAR *var=var_get(start, &end, 0, 1); if (var && to == (char*) end+1) { - DBUG_PRINT("info",("var: %s -> %s", start, var->str_val)); + DBUG_PRINT("info",("var: '%s' -> '%s'", start, var->str_val)); DBUG_RETURN(var->str_val); /* return found variable value */ } } @@ -1609,56 +1626,6 @@ int do_while(struct st_query* q) } -int safe_copy_unescape(char* dest, char* src, int size) -{ - register char* p_dest = dest, *p_src = src; - register int c, val; - enum { ST_NORMAL, ST_ESCAPED, ST_HEX2} state = ST_NORMAL ; - - size--; /* just to make life easier */ - - for (; p_dest - size < dest && p_src - size < src && - (c = *p_src) != '\n' && c; ++p_src) - { - switch(state) { - case ST_NORMAL: - if (c == '\\') - state = ST_ESCAPED; - else - *p_dest++ = c; - break; - case ST_ESCAPED: - if ((val = hex_val(c)) > 0) - { - *p_dest = val; - state = ST_HEX2; - } - else - { - state = ST_NORMAL; - *p_dest++ = c; - } - break; - case ST_HEX2: - if ((val = hex_val(c)) > 0) - { - *p_dest = (*p_dest << 4) + val; - p_dest++; - } - else - *p_dest++ = c; - - state = ST_NORMAL; - break; - - } - } - - *p_dest = 0; - return (p_dest - dest); -} - - int read_line(char* buf, int size) { int c; |