db: lift execQuery error handling to parent
This commit is contained in:
parent
aad92d27e9
commit
2f65ffdd70
@ -103,8 +103,8 @@ func (ld *badgerLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
vcl.ShowMessage("Badger doesn't support querying")
|
||||
func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return errors.New("Badger doesn't support querying")
|
||||
}
|
||||
|
||||
func (ld *badgerLoadedDatabase) Close() {
|
||||
|
@ -185,8 +185,8 @@ func (ld *boltLoadedDatabase) DeleteBucket(ndata *navData) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
vcl.ShowMessage("Bolt doesn't support querying")
|
||||
func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return errors.New("Bolt doesn't support querying")
|
||||
}
|
||||
|
||||
func (ld *boltLoadedDatabase) Close() {
|
||||
|
@ -89,8 +89,8 @@ func (ld *debconfLoadedDatabase) NavContext(ndata *navData) ([]contextAction, er
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *debconfLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
vcl.ShowMessage("debconf doesn't support querying")
|
||||
func (ld *debconfLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return errors.New("debconf doesn't support querying")
|
||||
}
|
||||
|
||||
func (ld *debconfLoadedDatabase) Close() {
|
||||
|
@ -28,7 +28,8 @@ func (n *noLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error {
|
||||
return errors.New("Editing is not supported")
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
func (n *noLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
|
@ -94,8 +94,8 @@ func (ld *pebbleLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
vcl.ShowMessage("pebble doesn't support querying")
|
||||
func (ld *pebbleLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
return errors.New("pebble doesn't support querying")
|
||||
}
|
||||
|
||||
func (ld *pebbleLoadedDatabase) Close() {
|
||||
|
10
db_redis.go
10
db_redis.go
@ -168,22 +168,20 @@ func (ld *redisLoadedDatabase) NavContext(ndata *navData) ([]contextAction, erro
|
||||
return nil, nil // No special actions are supported
|
||||
}
|
||||
|
||||
func (ld *redisLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
func (ld *redisLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
ctx := context.Background()
|
||||
|
||||
// Need to parse the query into separate string+args fields for the protocol
|
||||
fields, err := lexer.Fields(query)
|
||||
if err != nil {
|
||||
vcl.ShowMessage(fmt.Sprintf("Parsing the query: %v", err))
|
||||
return
|
||||
return fmt.Errorf("Parsing the query: %w", err)
|
||||
}
|
||||
|
||||
fields_boxed := box_interface(fields)
|
||||
|
||||
ret, err := ld.db.Do(ctx, fields_boxed...).Result()
|
||||
if err != nil {
|
||||
vcl.ShowMessage(fmt.Sprintf("The redis query returned an error: %v", err))
|
||||
return
|
||||
return fmt.Errorf("The redis query returned an error: %w", err)
|
||||
}
|
||||
|
||||
vcl_stringgrid_clear(resultArea)
|
||||
@ -212,6 +210,8 @@ func (ld *redisLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGr
|
||||
|
||||
vcl_stringgrid_columnwidths(resultArea)
|
||||
resultArea.SetEnabled(true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ld *redisLoadedDatabase) Close() {
|
||||
|
@ -164,11 +164,10 @@ func populateRows(rr *sql.Rows, dest *vcl.TStringGrid) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) {
|
||||
func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error {
|
||||
rr, err := ld.db.Query(query)
|
||||
if err != nil {
|
||||
vcl.ShowMessage(err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
defer rr.Close()
|
||||
@ -177,8 +176,7 @@ func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringG
|
||||
|
||||
columns, err := rr.Columns()
|
||||
if err != nil {
|
||||
vcl.ShowMessage(err.Error())
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
populateColumns(columns, resultArea)
|
||||
@ -187,6 +185,7 @@ func (ld *sqliteLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringG
|
||||
|
||||
vcl_stringgrid_columnwidths(resultArea)
|
||||
resultArea.SetEnabled(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ld *sqliteLoadedDatabase) NavChildren(ndata *navData) ([]string, error) {
|
||||
|
@ -20,7 +20,7 @@ type loadedDatabase interface {
|
||||
RootElement() *vcl.TTreeNode
|
||||
RenderForNav(f *TMainForm, ndata *navData)
|
||||
ApplyChanges(f *TMainForm, ndata *navData) error
|
||||
ExecQuery(query string, resultArea *vcl.TStringGrid)
|
||||
ExecQuery(query string, resultArea *vcl.TStringGrid) error
|
||||
NavChildren(ndata *navData) ([]string, error)
|
||||
NavContext(ndata *navData) ([]contextAction, error)
|
||||
Keepalive(ndata *navData)
|
||||
|
6
main.go
6
main.go
@ -712,7 +712,11 @@ func (f *TMainForm) OnQueryExecute(sender vcl.IObject) {
|
||||
}
|
||||
|
||||
ndata := (*navData)(node.Data())
|
||||
ndata.ld.ExecQuery(queryString, f.queryResult)
|
||||
err := ndata.ld.ExecQuery(queryString, f.queryResult)
|
||||
if err != nil {
|
||||
vcl.ShowMessage(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (f *TMainForm) OnNavChange(sender vcl.IObject, node *vcl.TTreeNode) {
|
||||
|
Loading…
Reference in New Issue
Block a user