diff --git a/pkg/client/client.go b/pkg/client/client.go index b4b5b10ca3b5d7fcda4263bf0d46c07f1301bed3..7ab53cb33d85c65197fd38841719990f0b15da6f 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -381,6 +381,7 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) Rows: []Row{ Row{affected}, }, + Action: action, } return &result, nil @@ -404,10 +405,19 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) if cols == nil { cols = []string{} } - - result := Result{ - Columns: cols, - Rows: []Row{}, + var result Result + if action == "select" { + result = Result{ + Columns: cols, + Rows: []Row{}, + Action: "select", + } + } else { + result = Result{ + Columns: cols, + Rows: []Row{}, + Action: "dcl", + } } for rows.Next() { @@ -431,18 +441,6 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error) } result.PostProcess() - - if len(result.Rows) == 0 { - result := Result{ - Columns: []string{"Rows Returned"}, - Rows: []Row{ - Row{0}, - }, - } - - return &result, nil - } - return &result, nil } diff --git a/pkg/client/dump.go b/pkg/client/dump.go index 34093b17337806ad5f3814d33a48eaea05436432..f309c4fa00dcadcab284019348a2a08a53666caa 100644 --- a/pkg/client/dump.go +++ b/pkg/client/dump.go @@ -2,10 +2,12 @@ package client import ( "bytes" + "errors" "fmt" "io" "net/url" "os/exec" + "regexp" "strings" ) @@ -33,12 +35,17 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { connstr = str } + username, password, err := parse_user_info(connstr) + if err != nil { + return err + } + errOutput := bytes.NewBuffer(nil) opts := []string{ - "openGauss", // the database of which the table belongs - "-U", "openGauss", // the username gs_dump used to connect - "-W", "openGauss2022", // the password. CAUSION: password is set in initdb.sql + "openGauss", // the database of which the table belongs + "-U", username, // the username gs_dump used to connect + "-W", password, // the password. CAUSION: password is set in initdb.sql "--no-owner", "--clean", // clean (drop) database objects before recreating } @@ -47,8 +54,6 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { opts = append(opts, []string{"--table", d.Table}...) } - opts = append(opts, connstr) - cmd := exec.Command("gs_dump", opts...) cmd.Stdout = writer cmd.Stderr = errOutput @@ -59,6 +64,16 @@ func (d *Dump) Export(connstr string, writer io.Writer) error { return nil } +func parse_user_info(input string) (string, string, error) { + reg := regexp.MustCompile(`(\w+)://(\w+):(\w+)`) + match := reg.FindStringSubmatch(input) + if len(match) < 4 { + return "", "", errors.New("can not parse user name and password") + } + + return match[2], match[3], nil +} + // removeUnsupportedOptions removes any options unsupported for making a db dump func removeUnsupportedOptions(input string) (string, error) { uri, err := url.Parse(input) diff --git a/pkg/client/result.go b/pkg/client/result.go index 5f78c72689b27f6ead03c3f3d093c359df6e0fcf..26aace6af50286ba277d8d98183264654e28b0ff 100644 --- a/pkg/client/result.go +++ b/pkg/client/result.go @@ -25,6 +25,7 @@ type Result struct { Pagination *Pagination `json:"pagination,omitempty"` Columns []string `json:"columns"` Rows []Row `json:"rows"` + Action string `json:"action"` } type Objects struct { diff --git a/pkg/command/version.go b/pkg/command/version.go index 34a1a70708e9066d5690e7a48dac00f2a88f63ba..832ee17781e2bef37b5e466e28323ce6e6774dad 100644 --- a/pkg/command/version.go +++ b/pkg/command/version.go @@ -2,7 +2,7 @@ package command const ( // Version is the current openGauss-webclient application version - Version = "0.8.0" + Version = "0.9.0" ) var ( diff --git a/static/index.html b/static/index.html index ec77e88d07c139aa03023723731be6ba4a9da4a0..7447bbc0169d7156bc25bd1c7577e402fc5e7382 100644 --- a/static/index.html +++ b/static/index.html @@ -32,7 +32,11 @@
  • 操作历史
  • 会话
  • - +