Skip to content

Commit

Permalink
Use system database when retrieving routing table
Browse files Browse the repository at this point in the history
fix #137
  • Loading branch information
Peter Wilhelmsson authored and 2hdddg committed Aug 28, 2020
1 parent cc98e38 commit f634f1f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions neo4j/internal/bolt/bolt4.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,19 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
return nil, err
}

// The query should run in system database, preserve current setting and restore it when
// done.
originalDatabaseName := b.databaseName
b.databaseName = "system"
defer func() { b.databaseName = originalDatabaseName }()

// Query for the users default database or a specific database
const (
queryDefault = "CALL dbms.routing.getRoutingTable($context)"
queryDatabase = "CALL dbms.routing.getRoutingTable($context, $db)"
)
query := queryDefault
params := map[string]interface{}{"context": context}

if database != db.DefaultDatabase {
query = queryDatabase
params["db"] = database
Expand All @@ -634,7 +640,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
if err != nil {
return nil, err
}

rec, _, err := b.Next(stream.Handle)
if err != nil {
return nil, err
Expand All @@ -649,7 +654,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
if table == nil {
return nil, errors.New("Unable to parse routing table")
}

return table, nil
}

Expand Down

0 comments on commit f634f1f

Please sign in to comment.