From f6caefef2d9e237d636d2de017eed98b4bd436db Mon Sep 17 00:00:00 2001 From: "mats@mysql.com" <> Date: Fri, 4 Feb 2005 14:29:54 +0100 Subject: [PATCH] Bug#7853 (mysqlbinlog does not accept input from stdin) The utility 'mysqlbinlog' now accepts input from stdin. It can now be used to read the output from, e.g., 'zcat' or other utility. --- client/mysqlbinlog.cc | 8 +++----- mysql-test/r/mysqlbinlog.result | 10 ++++++++++ mysql-test/t/mysqlbinlog.test | 10 ++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index caf126f2830..3b107c80cfc 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1121,15 +1121,15 @@ static int dump_local_log_entries(const char* logname) } check_header(file, &description_event); } - else // reading from stdin; TODO: check that it works + else // reading from stdin; { - if (init_io_cache(file, fileno(result_file), 0, READ_CACHE, (my_off_t) 0, + if (init_io_cache(file, fileno(stdin), 0, READ_CACHE, (my_off_t) 0, 0, MYF(MY_WME | MY_NABP | MY_DONT_CHECK_FILESIZE))) return 1; check_header(file, &description_event); if (start_position) { - /* skip 'start_position' characters from stdout */ + /* skip 'start_position' characters from stdin */ byte buff[IO_SIZE]; my_off_t length,tmp; for (length= start_position_mot ; length > 0 ; length-=tmp) @@ -1142,8 +1142,6 @@ static int dump_local_log_entries(const char* logname) } } } - file->pos_in_file= start_position_mot; - file->seek_not_done=0; } if (!description_event || !description_event->is_valid()) diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index c18588d90a7..1828bb7663a 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -96,4 +96,14 @@ SET TIMESTAMP=1000000000; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1; SET @@session.sql_mode=0; insert into t1 values ("Alas"); + +--- reading stdin -- +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +use test; +SET TIMESTAMP=1065204671; +BEGIN; +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +use test; +SET TIMESTAMP=1065204671; +BEGIN; drop table t1, t2; diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index a8bbe60d58e..7f0a963adde 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -95,5 +95,15 @@ select "--- --position --" as ""; --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR --exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --position=118 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002 +# Bug#7853 (mysqlbinlog does not accept input from stdin) +--disable_query_log +select "--- reading stdin --" as ""; +--enable_query_log +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec cat $MYSQL_TEST_DIR/std_data/trunc_binlog.000001 | $MYSQL_BINLOG --short-form - + +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR +--exec cat $MYSQL_TEST_DIR/std_data/trunc_binlog.000001 | $MYSQL_BINLOG --short-form --position=79 - + # clean up drop table t1, t2;