summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <vva@eagle.mysql.r18.ru>2003-05-20 17:03:18 -0400
committerunknown <vva@eagle.mysql.r18.ru>2003-05-20 17:03:18 -0400
commit8d4db91a788413c34af1eb24a0136155bbcc7da8 (patch)
tree3e0997cde6f2b2d3ea4a49befbecd595c4730290
parent471df17c91db9424dbc28ffbe076f612394dd56f (diff)
downloadmariadb-git-8d4db91a788413c34af1eb24a0136155bbcc7da8.tar.gz
changed processing of LOAD DATA in mysqlbinlog
client/Makefile.am: added ../mysys/mf_tempdir.c to mysqlbinlog_SOURCES client/mysqlbinlog.cc: changed processing of LOAD DATA mysql-test/r/rpl_loaddata.result: added LINE STARTING BY '>' mysql-test/std_data/rpl_loaddata2.dat: added LINE STARTING BY '>' mysql-test/t/rpl_loaddata.test: added LINE STARTING BY '>' sql/log_event.cc: fixed some bugs in processing of LOAD DATA
-rw-r--r--client/Makefile.am2
-rw-r--r--client/mysqlbinlog.cc87
-rw-r--r--mysql-test/r/rpl_loaddata.result2
-rw-r--r--mysql-test/std_data/rpl_loaddata2.dat8
-rw-r--r--mysql-test/t/rpl_loaddata.test3
-rw-r--r--sql/log_event.cc16
6 files changed, 64 insertions, 54 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 2922b1fc6a2..2c54ec45989 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -35,7 +35,7 @@ mysqldump_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
mysqlimport_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
mysqltest_SOURCES= mysqltest.c
mysqltest_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-mysqlbinlog_SOURCES = mysqlbinlog.cc
+mysqlbinlog_SOURCES = mysqlbinlog.cc ../mysys/mf_tempdir.c
mysqlbinlog_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
mysqlmanagerc_SOURCES = mysqlmanagerc.c
mysqlmanagerc_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 3f85f0be008..a5f769c0782 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -20,6 +20,7 @@
#include <time.h>
#include <assert.h>
#include "log_event.h"
+#include "include/my_sys.h"
#define BIN_LOG_HEADER_SIZE 4
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
@@ -57,7 +58,6 @@ static short binlog_flags = 0;
static MYSQL* mysql = NULL;
static const char* table = 0;
-static bool use_local_load= 0;
static const char* dirname_for_local_load= 0;
static void dump_local_log_entries(const char* logname);
@@ -106,7 +106,7 @@ class Load_log_processor
gptr data, uint size)
{
File file;
- if ((file= my_open(fname,flags,MYF(MY_WME)) < 0) ||
+ if (((file= my_open(fname,flags,MYF(MY_WME))) < 0) ||
my_write(file,(byte*) data,size,MYF(MY_WME|MY_NABP)) ||
my_close(file,MYF(MY_WME)))
exit(1);
@@ -149,7 +149,9 @@ public:
}
void init_by_cur_dir()
{
- target_dir_name_len= 0;
+ if (my_getwd(target_dir_name,sizeof(target_dir_name),MYF(MY_WME)))
+ exit(1);
+ target_dir_name_len= strlen(target_dir_name);
}
void destroy()
{
@@ -176,7 +178,7 @@ public:
void process(Create_file_log_event *ce)
{
const char *fname= create_file(ce);
- append_to_file(fname,O_CREAT|O_BINARY,ce->block,ce->block_len);
+ append_to_file(fname,O_CREAT|O_EXCL|O_BINARY|O_WRONLY,ce->block,ce->block_len);
}
void process(Append_block_log_event *ae)
{
@@ -184,7 +186,7 @@ public:
die("Skiped CreateFile event for file_id: %u",ae->file_id);
Create_file_log_event* ce=
*((Create_file_log_event**)file_names.buffer + ae->file_id);
- append_to_file(ce->fname,O_APPEND|O_BINARY,ae->block,ae->block_len);
+ append_to_file(ce->fname,O_APPEND|O_BINARY|O_WRONLY,ae->block,ae->block_len);
}
};
@@ -309,7 +311,7 @@ extern "C" my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{
- switch(optid) {
+ switch (optid) {
#ifndef DBUG_OFF
case '#':
DBUG_PUSH(argument ? argument : default_dbug_option);
@@ -338,9 +340,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'V':
print_version();
exit(0);
- case 'l':
- use_local_load= 1;
- break;
case '?':
usage();
exit(0);
@@ -552,8 +551,6 @@ static void dump_local_log_entries(const char* logname)
MYF(MY_WME | MY_NABP)))
exit(1);
old_format = check_header(file);
- if (use_local_load && !dirname_for_local_load)
- load_processor.init_by_file_name(logname);
}
else
{
@@ -575,8 +572,6 @@ static void dump_local_log_entries(const char* logname)
}
file->pos_in_file=position;
file->seek_not_done=0;
- if (use_local_load && !dirname_for_local_load)
- load_processor.init_by_cur_dir();
}
if (!position)
@@ -632,37 +627,31 @@ Could not read entry at offset %s : Error in log format or read error",
if (!short_form)
fprintf(result_file, "# at %s\n",llstr(old_off,llbuff));
- if (!use_local_load)
+ switch (ev->get_type_code()) {
+ case CREATE_FILE_EVENT:
+ {
+ Create_file_log_event* ce= (Create_file_log_event*)ev;
+ ce->print(result_file, short_form, last_db,true);
+ load_processor.process(ce);
+ ev= 0;
+ break;
+ }
+ case APPEND_BLOCK_EVENT:
ev->print(result_file, short_form, last_db);
- else
+ load_processor.process((Append_block_log_event*)ev);
+ break;
+ case EXEC_LOAD_EVENT:
{
- switch(ev->get_type_code())
- {
- case CREATE_FILE_EVENT:
- {
- Create_file_log_event* ce= (Create_file_log_event*)ev;
- ce->print(result_file, short_form, last_db,true);
- load_processor.process(ce);
- ev= 0;
- break;
- }
- case APPEND_BLOCK_EVENT:
- ev->print(result_file, short_form, last_db);
- load_processor.process((Append_block_log_event*)ev);
- break;
- case EXEC_LOAD_EVENT:
- {
- 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;
- break;
- }
- default:
- ev->print(result_file, short_form, last_db);
- }
+ 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;
+ break;
+ }
+ default:
+ ev->print(result_file, short_form, last_db);
}
}
rec_count++;
@@ -688,8 +677,20 @@ int main(int argc, char** argv)
if (use_remote)
mysql = safe_connect();
+
+ MY_TMPDIR tmpdir;
+ tmpdir.list= 0;
+ if (!dirname_for_local_load)
+ {
+ if (init_tmpdir(&tmpdir, 0))
+ exit(1);
+ dirname_for_local_load= my_tmpdir(&tmpdir);
+ }
+
if (dirname_for_local_load)
load_processor.init_by_dir_name(dirname_for_local_load);
+ else
+ load_processor.init_by_cur_dir();
if (table)
{
@@ -707,6 +708,8 @@ int main(int argc, char** argv)
while (--argc >= 0)
dump_log_entries(*(argv++));
}
+ if (tmpdir.list)
+ free_tmpdir(&tmpdir);
if (result_file != stdout)
my_fclose(result_file, MYF(0));
if (use_remote)
diff --git a/mysql-test/r/rpl_loaddata.result b/mysql-test/r/rpl_loaddata.result
index 305868b04fd..5b7aab3df74 100644
--- a/mysql-test/r/rpl_loaddata.result
+++ b/mysql-test/r/rpl_loaddata.result
@@ -7,7 +7,7 @@ start slave;
create table t1(a int not null auto_increment, b int, primary key(a) );
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
-load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' ignore 1 lines;
+load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;
select * from t1;
diff --git a/mysql-test/std_data/rpl_loaddata2.dat b/mysql-test/std_data/rpl_loaddata2.dat
index 7a3d4ea7695..b883d9dcd58 100644
--- a/mysql-test/std_data/rpl_loaddata2.dat
+++ b/mysql-test/std_data/rpl_loaddata2.dat
@@ -1,8 +1,8 @@
-2003-01-21,6328,%a%,%aaaaa%
+>2003-01-21,6328,%a%,%aaaaa%
##
-2003-02-22,2461,b,%a a a @@ @% @b ' " a%
+>2003-02-22,2461,b,%a a a @@ @% @b ' " a%
##
-2003-03-22,2161,%c%,%asdf%
+>2003-03-22,2161,%c%,%asdf%
##
-2003-04-22,2416,%a%,%bbbbb%
+>2003-04-22,2416,%a%,%bbbbb%
##
diff --git a/mysql-test/t/rpl_loaddata.test b/mysql-test/t/rpl_loaddata.test
index 2acb67dfce2..1f34aa9d3f9 100644
--- a/mysql-test/t/rpl_loaddata.test
+++ b/mysql-test/t/rpl_loaddata.test
@@ -10,8 +10,7 @@ create table t1(a int not null auto_increment, b int, primary key(a) );
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
-#load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionaly enclosed by '%' escaped by '@' lines terminated by '\n%%\n' ignore 1 lines;
- load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' ignore 1 lines;
+load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 39db264d898..530e878b458 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1182,15 +1182,19 @@ void Load_log_event::pack_info(Protocol *protocol)
pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
}
+ bool line_lexem_added= false;
if (sql_ex.line_term_len)
{
pos= strmov(pos, " LINES TERMINATED BY ");
pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
+ line_lexem_added= true;
}
if (sql_ex.line_start_len)
{
- pos= strmov(pos, " LINES STARTING BY ");
+ if (!line_lexem_added)
+ pos= strmov(pos," LINES");
+ pos= strmov(pos, " STARTING BY ");
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
}
@@ -1438,10 +1442,10 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db)
if (db && db[0] && !same_db)
fprintf(file, "use %s;\n", db);
- fprintf(file, "LOAD ");
+ fprintf(file, "LOAD DATA ");
if (check_fname_outside_temp_buf())
fprintf(file, "LOCAL ");
- fprintf(file, "DATA INFILE '%-*s' ", fname_len, fname);
+ fprintf(file, "INFILE '%-*s' ", fname_len, fname);
if (sql_ex.opt_flags & REPLACE_FLAG)
fprintf(file," REPLACE ");
@@ -1469,15 +1473,19 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db)
pretty_print_str(file, sql_ex.escaped, sql_ex.escaped_len);
}
+ bool line_lexem_added= false;
if (sql_ex.line_term)
{
fprintf(file," LINES TERMINATED BY ");
pretty_print_str(file, sql_ex.line_term, sql_ex.line_term_len);
+ line_lexem_added= true;
}
if (sql_ex.line_start)
{
- fprintf(file," LINES STARTING BY ");
+ if (!line_lexem_added)
+ fprintf(file," LINES");
+ fprintf(file," STARTING BY ");
pretty_print_str(file, sql_ex.line_start, sql_ex.line_start_len);
}