Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ enum ss_comment_type { SSC_NONE= 0, SSC_CONDITIONAL, SSC_HINT };
static MYSQL mysql; /* The connection */
static my_bool ignore_errors=0,wait_flag=0,quick=0,
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
output_plain=0,
opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
opt_compress=0, using_opt_local_infile=0,
vertical=0, line_numbers=1, column_names=1,opt_html=0,
Expand Down Expand Up @@ -324,7 +325,7 @@ extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
const char *argument);
static int com_quit(String *str,char*),
com_go(String *str,char*), com_ego(String *str,char*),
com_print(String *str,char*),
com_silent(String *str,char*), com_print(String *str,char*),
com_help(String *str,char*), com_clear(String *str,char*),
com_connect(String *str,char*), com_status(String *str,char*),
com_use(String *str,char*), com_source(String *str, char*),
Expand Down Expand Up @@ -414,6 +415,8 @@ static COMMANDS commands[] = {
{ "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
{ "sandbox", '-', com_sandbox, 0,
"Disallow commands that access the file system (except \\P without an argument and \\e)." },
{ "silent", 'S', com_silent, 0,
"Send command to MariaDB server, display result without column names or borders."},
{ "source", '.', com_source, 1,
"Execute an SQL script file. Takes a file name as an argument."},
{ "status", 's', com_status, 0, "Get status information from the server."},
Expand Down Expand Up @@ -3739,6 +3742,8 @@ static int com_go(String *buffer, char *)
print_table_data_html(result);
else if (opt_xml)
print_table_data_xml(result);
else if (output_plain)
print_tab_data(result);
else if (vertical || (auto_vertical_output &&
(terminal_width < get_result_width(result))))
print_table_data_vertically(result);
Expand Down Expand Up @@ -3879,6 +3884,24 @@ com_ego(String *buffer,char *line)
}


static int
com_silent(String *buffer,char *line)
{
int result;
uint old_opt_silent=opt_silent;
bool old_output_plain=output_plain;
bool old_column_names=column_names;
opt_silent=1;
output_plain=1;
column_names=0;
result=com_go(buffer,line);
opt_silent=old_opt_silent;
output_plain=old_output_plain;
column_names=old_column_names;
return result;
}


static const char *fieldtype2str(enum enum_field_types type)
{
switch (type) {
Expand Down
35 changes: 35 additions & 0 deletions mysql-test/main/mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,41 @@ _
Test 'go' command g
a
1
_
Test 'silent' command(no column names) S
a b
1 x
1 x
_
Test 'silent' command(overrides --table) S
1 x
_
Test 'silent' command(overrides --vertical) S
1 x
_
Test 'silent' command(already silent) S
1 x
_
Test 'silent' command(next statement unaffected) S
1
+---+
| a |
+---+
| 1 |
+---+
1
*************************** 1. row ***************************
a: 1
_
Test 'silent' command(G unaffected) S
1
*************************** 1. row ***************************
a: 1
_
Test 'silent' command(statement with a quoted delimiter) S
analyze table t1;
_
Test 'silent' command(empty result and error) S
drop table t1;
create table t1(a int);
lock tables t1 write;
Expand Down
29 changes: 29 additions & 0 deletions mysql-test/main/mysql.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@ select "Test 'go' command(vertical output) \G" as "_";
# Test 'go' command \g
select "Test 'go' command \g" as "_";
--exec $MYSQL test -e "select * from t1\g"
#
# MDEV-40551 Copy/Paste friendly output format for MariaDB Command Line Client
#
# Test 'silent' command \S
select "Test 'silent' command(no column names) \S" as "_";
--exec $MYSQL test -e "select 1 as a, 'x' as b;"
--exec $MYSQL test -e "select 1 as a, 'x' as b\S"
# \S overrides the session output format, whatever it was started with
select "Test 'silent' command(overrides --table) \S" as "_";
--exec $MYSQL test --table -e "select 1 as a, 'x' as b\S"
select "Test 'silent' command(overrides --vertical) \S" as "_";
--exec $MYSQL test --vertical -e "select 1 as a, 'x' as b\S"
select "Test 'silent' command(already silent) \S" as "_";
--exec $MYSQL test -s -s -e "select 1 as a, 'x' as b\S"
# \S applies to its own statement only
select "Test 'silent' command(next statement unaffected) \S" as "_";
--exec $MYSQL test --table -e "select 1 as a\S select 1 as a;"
--exec $MYSQL test --vertical -e "select 1 as a\S select 1 as a;"
# \G after \S is still vertical
select "Test 'silent' command(\G unaffected) \S" as "_";
--exec $MYSQL test --table -e "select 1 as a\S select 1 as a\G"
# The statement from the feature request
select "Test 'silent' command(statement with a quoted delimiter) \S" as "_";
--exec $MYSQL test --table -e "select concat('analyze table ', table_name, ';') from information_schema.tables where table_schema='test'\S"
# \S on a statement that returns no rows, and on one that fails
select "Test 'silent' command(empty result and error) \S" as "_";
--exec $MYSQL test --table -e "select 1 as a from t1 where 1=0\S"
--error 1
--exec $MYSQL test --table -e "select nosuchcolumn from t1\S"
--enable_query_log
drop table t1;

Expand Down