Skip to content

Commit

Permalink
.*: support help statement radondb#710
Browse files Browse the repository at this point in the history
[summary]
support "help statement" for users to get help online information from mysql.

[test case]
src/proxy/help_test.go
src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/parse_test.go

[patch codecov]
src/proxy/help.go 100%
src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go 96.6%
src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/rewriter.go 64.7%
  • Loading branch information
hustjieke committed Dec 10, 2020
1 parent 988f634 commit 3e4980f
Show file tree
Hide file tree
Showing 12 changed files with 3,509 additions and 3,124 deletions.
125 changes: 125 additions & 0 deletions intergration/radon-test/r/help.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
drop database if exists integrate_test;

create database if not exists integrate_test DEFAULT CHARSET=utf8;


help;
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.

help content;

help 'index';
ALTER TABLE
CACHE INDEX
CREATE INDEX
CREATE TABLE
DROP INDEX
JOIN
LOAD INDEX
SHOW
SHOW INDEX
SPATIAL


help 'insert';
Name: 'INSERT'
Description:
Syntax:
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
[PARTITION (partition_name [, partition_name] ...)]
[(col_name [, col_name] ...)]
{VALUES | VALUE} (value_list) [, (value_list)] ...
[ON DUPLICATE KEY UPDATE assignment_list]

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
[PARTITION (partition_name [, partition_name] ...)]
SET assignment_list
[ON DUPLICATE KEY UPDATE assignment_list]

INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
[PARTITION (partition_name [, partition_name] ...)]
[(col_name [, col_name] ...)]
SELECT ...
[ON DUPLICATE KEY UPDATE assignment_list]

value:
{expr | DEFAULT}

value_list:
value [, value] ...

assignment:
col_name = value

assignment_list:
assignment [, assignment] ...

INSERT inserts new rows into an existing table. The INSERT ... VALUES
and INSERT ... SET forms of the statement insert rows based on
explicitly specified values. The INSERT ... SELECT form inserts rows
selected from another table or tables. INSERT with an ON DUPLICATE KEY
UPDATE clause enables existing rows to be updated if a row to be
inserted would cause a duplicate value in a UNIQUE index or PRIMARY
KEY.

For additional information about INSERT ... SELECT and INSERT ... ON
DUPLICATE KEY UPDATE, see [HELP INSERT SELECT], and
https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html.

In MySQL 5.7, the DELAYED keyword is accepted but ignored by the
server. For the reasons for this, see [HELP INSERT DELAYED],

Inserting into a table requires the INSERT privilege for the table. If
the ON DUPLICATE KEY UPDATE clause is used and a duplicate key causes
an UPDATE to be performed instead, the statement requires the UPDATE
privilege for the columns to be updated. For columns that are read but
not modified you need only the SELECT privilege (such as for a column
referenced only on the right hand side of an col_name=expr assignment
in an ON DUPLICATE KEY UPDATE clause).

When inserting into a partitioned table, you can control which
partitions and subpartitions accept new rows. The PARTITION option
takes a list of the comma-separated names of one or more partitions or
subpartitions (or both) of the table. If any of the rows to be inserted
by a given INSERT statement do not match one of the partitions listed,
the INSERT statement fails with the error Found a row not matching the
given partition set. For more information and examples, see
https://dev.mysql.com/doc/refman/5.7/en/partitioning-selection.html.

URL: https://dev.mysql.com/doc/refman/5.7/en/insert.html



help /*test nothing get*/ xx;

help /*test nothing get*/ create create;


drop database integrate_test;
11 changes: 11 additions & 0 deletions intergration/radon-test/t/help.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
drop database if exists integrate_test;
create database if not exists integrate_test DEFAULT CHARSET=utf8;

help;
help content;
help 'index';
help 'insert';
help /*test nothing get*/ xx;
help /*test nothing get*/ create create;

drop database integrate_test;
20 changes: 20 additions & 0 deletions src/proxy/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/

package proxy

import (
"github.com/xelabs/go-mysqlstack/driver"
"github.com/xelabs/go-mysqlstack/sqlparser"
"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
)

// handleExplain used to handle the EXPLAIN command.
func (spanner *Spanner) handleHelp(session *driver.Session, query string, node sqlparser.Statement) (*sqltypes.Result, error) {
return spanner.ExecuteSingle(query)
}
48 changes: 48 additions & 0 deletions src/proxy/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/

package proxy

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xelabs/go-mysqlstack/driver"
"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
"github.com/xelabs/go-mysqlstack/xlog"
)

func TestHelpStmt(t *testing.T) {
log := xlog.NewStdLog(xlog.Level(xlog.PANIC))
fakedbs, proxy, cleanup := MockProxy(log)
defer cleanup()
address := proxy.Address()

// fakedbs.
{
fakedbs.AddQueryPattern("use .*", &sqltypes.Result{})
fakedbs.AddQueryPattern("help *.*", &sqltypes.Result{})
}

// show databases.
{
client, err := driver.NewConn("mock", "mock", address, "test", "utf8")
assert.Nil(t, err)
defer client.Close()
querys := []string{
"help",
"help index",
"help content",
"help 'any string'",
}
for _, query := range querys {
_, err = client.FetchAll(query, -1)
assert.Nil(t, err)
}
}
}
7 changes: 7 additions & 0 deletions src/proxy/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ func (spanner *Spanner) ComQuery(session *driver.Session, query string, bindVari
}
spanner.auditLog(session, R, xbase.EXPLAIN, query, qr, status)
return returnQuery(qr, callback, err)
case *sqlparser.Help:
if qr, err = spanner.handleHelp(session, query, node); err != nil {
log.Error("proxy.help[%s].from.session[%v].error:%+v", query, session.ID(), err)
status = 1
}
spanner.auditLog(session, R, xbase.HELP, query, qr, status)
return returnQuery(qr, callback, err)
case *sqlparser.Transaction:
// Support for myloader.
// Support Multiple-statement Transaction
Expand Down
14 changes: 14 additions & 0 deletions src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/ast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/vendor/github.com/xelabs/go-mysqlstack/sqlparser/parse_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e4980f

Please sign in to comment.