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