summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rwxr-xr-xclient/CMakeLists.txt3
-rw-r--r--client/Makefile.am3
-rw-r--r--client/mysqlbinlog.cc31
-rw-r--r--client/mysqltest.c137
4 files changed, 171 insertions, 3 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 89675138750..a419da5eabf 100755
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -32,7 +32,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
ADD_EXECUTABLE(mysql completion_hash.cc mysql.cc readline.cc sql_string.cc ../mysys/my_conio.c)
TARGET_LINK_LIBRARIES(mysql mysqlclient_notls wsock32)
-ADD_EXECUTABLE(mysqltest mysqltest.c ../mysys/my_getsystime.c ../mysys/my_copy.c)
+ADD_EXECUTABLE(mysqltest mysqltest.c ../mysys/my_getsystime.c
+ ../mysys/my_copy.c ../mysys/my_mkdir.c)
TARGET_LINK_LIBRARIES(mysqltest mysqlclient_notls regex wsock32)
ADD_EXECUTABLE(mysqlcheck mysqlcheck.c)
diff --git a/client/Makefile.am b/client/Makefile.am
index c7663c7da82..672bb2e0c47 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -34,7 +34,8 @@ mysqladmin_SOURCES = mysqladmin.cc
mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS)
mysqltest_SOURCES= mysqltest.c \
$(top_srcdir)/mysys/my_getsystime.c \
- $(top_srcdir)/mysys/my_copy.c
+ $(top_srcdir)/mysys/my_copy.c \
+ $(top_srcdir)/mysys/my_mkdir.c
mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD)
mysqlbinlog_SOURCES = mysqlbinlog.cc \
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 3d06a21c243..b4086b59c01 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -465,6 +465,31 @@ Create_file event for file_id: %u\n",ae->file_id);
Load_log_processor load_processor;
+/**
+ Replace windows-style backslashes by forward slashes so it can be
+ consumed by the mysql client, which requires Unix path.
+
+ @todo This is only useful under windows, so may be ifdef'ed out on
+ other systems. /Sven
+
+ @todo If a Create_file_log_event contains a filename with a
+ backslash (valid under unix), then we have problems under windows.
+ /Sven
+
+ @param[in,out] fname Filename to modify. The filename is modified
+ in-place.
+*/
+static void convert_path_to_forward_slashes(char *fname)
+{
+ while (*fname)
+ {
+ if (*fname == '\\')
+ *fname= '/';
+ fname++;
+ }
+}
+
+
static bool check_database(const char *log_dbname)
{
return one_database &&
@@ -582,6 +607,11 @@ int process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
*/
if (ce)
{
+ /*
+ We must not convert earlier, since the file is used by
+ my_open() in Load_log_processor::append().
+ */
+ convert_path_to_forward_slashes((char*) ce->fname);
ce->print(result_file, print_event_info, TRUE);
my_free((char*)ce->fname,MYF(MY_WME));
delete ce;
@@ -622,6 +652,7 @@ Create_file event for file_id: %u\n",exv->file_id);
if (fname)
{
+ convert_path_to_forward_slashes(fname);
exlq->print(result_file, print_event_info, fname);
my_free(fname, MYF(MY_WME));
}
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 88575c26bc6..05c9ced3848 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -51,6 +51,10 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
+#ifdef __WIN__
+#include <direct.h>
+#endif
+
#ifndef WEXITSTATUS
# ifdef __WIN__
@@ -277,7 +281,7 @@ enum enum_commands {
Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST,
Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, Q_SKIP,
Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES,
- Q_SEND_QUIT,
+ Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
@@ -366,6 +370,10 @@ const char *command_names[]=
"cat_file",
"diff_files",
"send_quit",
+ "change_user",
+ "mkdir",
+ "rmdir",
+
0
};
@@ -2742,6 +2750,67 @@ void do_file_exist(struct st_command *command)
/*
+ SYNOPSIS
+ do_mkdir
+ command called command
+
+ DESCRIPTION
+ mkdir <dir_name>
+ Create the directory <dir_name>
+*/
+
+void do_mkdir(struct st_command *command)
+{
+ int error;
+ static DYNAMIC_STRING ds_dirname;
+ const struct command_arg mkdir_args[] = {
+ "dirname", ARG_STRING, TRUE, &ds_dirname, "Directory to create"
+ };
+ DBUG_ENTER("do_mkdir");
+
+ check_command_args(command, command->first_argument,
+ mkdir_args, sizeof(mkdir_args)/sizeof(struct command_arg),
+ ' ');
+
+ DBUG_PRINT("info", ("creating directory: %s", ds_dirname.str));
+ error= my_mkdir(ds_dirname.str, 0777, MYF(0)) != 0;
+ handle_command_error(command, error);
+ dynstr_free(&ds_dirname);
+ DBUG_VOID_RETURN;
+}
+
+/*
+ SYNOPSIS
+ do_rmdir
+ command called command
+
+ DESCRIPTION
+ rmdir <dir_name>
+ Remove the empty directory <dir_name>
+*/
+
+void do_rmdir(struct st_command *command)
+{
+ int error;
+ static DYNAMIC_STRING ds_dirname;
+ const struct command_arg rmdir_args[] = {
+ "dirname", ARG_STRING, TRUE, &ds_dirname, "Directory to remove"
+ };
+ DBUG_ENTER("do_rmdir");
+
+ check_command_args(command, command->first_argument,
+ rmdir_args, sizeof(rmdir_args)/sizeof(struct command_arg),
+ ' ');
+
+ DBUG_PRINT("info", ("removing directory: %s", ds_dirname.str));
+ error= rmdir(ds_dirname.str) != 0;
+ handle_command_error(command, error);
+ dynstr_free(&ds_dirname);
+ DBUG_VOID_RETURN;
+}
+
+
+/*
Read characters from line buffer or file. This is needed to allow
my_ungetc() to buffer MAX_DELIMITER_LENGTH characters for a file
@@ -3048,6 +3117,69 @@ void do_send_quit(struct st_command *command)
/*
SYNOPSIS
+ do_change_user
+ command called command
+
+ DESCRIPTION
+ change_user [<user>], [<passwd>], [<db>]
+ <user> - user to change to
+ <passwd> - user password
+ <db> - default database
+
+ Changes the user and causes the database specified by db to become
+ the default (current) database for the the current connection.
+
+*/
+
+void do_change_user(struct st_command *command)
+{
+ MYSQL *mysql = &cur_con->mysql;
+ /* static keyword to make the NetWare compiler happy. */
+ static DYNAMIC_STRING ds_user, ds_passwd, ds_db;
+ const struct command_arg change_user_args[] = {
+ { "user", ARG_STRING, FALSE, &ds_user, "User to connect as" },
+ { "password", ARG_STRING, FALSE, &ds_passwd, "Password used when connecting" },
+ { "database", ARG_STRING, FALSE, &ds_db, "Database to select after connect" },
+ };
+
+ DBUG_ENTER("do_change_user");
+
+ check_command_args(command, command->first_argument,
+ change_user_args,
+ sizeof(change_user_args)/sizeof(struct command_arg),
+ ',');
+
+ if (cur_con->stmt)
+ {
+ mysql_stmt_close(cur_con->stmt);
+ cur_con->stmt= NULL;
+ }
+
+ if (!ds_user.length)
+ dynstr_set(&ds_user, mysql->user);
+
+ if (!ds_passwd.length)
+ dynstr_set(&ds_passwd, mysql->passwd);
+
+ if (!ds_db.length)
+ dynstr_set(&ds_db, mysql->db);
+
+ DBUG_PRINT("info",("connection: '%s' user: '%s' password: '%s' database: '%s'",
+ cur_con->name, ds_user.str, ds_passwd.str, ds_db.str));
+
+ if (mysql_change_user(mysql, ds_user.str, ds_passwd.str, ds_db.str))
+ die("change user failed: %s", mysql_error(mysql));
+
+ dynstr_free(&ds_user);
+ dynstr_free(&ds_passwd);
+ dynstr_free(&ds_db);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ SYNOPSIS
do_perl
command command handle
@@ -6847,11 +6979,14 @@ int main(int argc, char **argv)
case Q_ECHO: do_echo(command); command_executed++; break;
case Q_SYSTEM: do_system(command); break;
case Q_REMOVE_FILE: do_remove_file(command); break;
+ case Q_MKDIR: do_mkdir(command); break;
+ case Q_RMDIR: do_rmdir(command); break;
case Q_FILE_EXIST: do_file_exist(command); break;
case Q_WRITE_FILE: do_write_file(command); break;
case Q_APPEND_FILE: do_append_file(command); break;
case Q_DIFF_FILES: do_diff_files(command); break;
case Q_SEND_QUIT: do_send_quit(command); break;
+ case Q_CHANGE_USER: do_change_user(command); break;
case Q_CAT_FILE: do_cat_file(command); break;
case Q_COPY_FILE: do_copy_file(command); break;
case Q_CHMOD_FILE: do_chmod_file(command); break;