Skip to content

Commit f634f1f

Browse files
Peter Wilhelmsson2hdddg
authored andcommitted
Use system database when retrieving routing table
fix #137
1 parent cc98e38 commit f634f1f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

neo4j/internal/bolt/bolt4.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,19 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
618618
return nil, err
619619
}
620620

621+
// The query should run in system database, preserve current setting and restore it when
622+
// done.
623+
originalDatabaseName := b.databaseName
624+
b.databaseName = "system"
625+
defer func() { b.databaseName = originalDatabaseName }()
626+
627+
// Query for the users default database or a specific database
621628
const (
622629
queryDefault = "CALL dbms.routing.getRoutingTable($context)"
623630
queryDatabase = "CALL dbms.routing.getRoutingTable($context, $db)"
624631
)
625632
query := queryDefault
626633
params := map[string]interface{}{"context": context}
627-
628634
if database != db.DefaultDatabase {
629635
query = queryDatabase
630636
params["db"] = database
@@ -634,7 +640,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
634640
if err != nil {
635641
return nil, err
636642
}
637-
638643
rec, _, err := b.Next(stream.Handle)
639644
if err != nil {
640645
return nil, err
@@ -649,7 +654,6 @@ func (b *bolt4) GetRoutingTable(database string, context map[string]string) (*db
649654
if table == nil {
650655
return nil, errors.New("Unable to parse routing table")
651656
}
652-
653657
return table, nil
654658
}
655659

0 commit comments

Comments
 (0)