Skip to content

Commit

Permalink
fix memory leak in bridge database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
daviian committed May 17, 2019
1 parent 321f122 commit 54943d7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/bridge/database/room_assignment.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package database

import (
"database/sql"

"github.com/pagient/pagient-server/internal/bridge/model"

"github.com/pkg/errors"
)

// GetRoomAssignments returns current assignments of patients to surgery rooms
func (t *db) GetRoomAssignments(roomSymbol string, limit ...uint) ([]*model.RoomAssignment, error) {
func (db *db) GetRoomAssignments(roomSymbol string, limit ...uint) ([]*model.RoomAssignment, error) {
top := 0
if len(limit) > 0 {
top = int(limit[0])
}

rows, err := t.Query("SELECT pds6_wz.PID FROM pds6_wz JOIN pds6_stwz ON pds6_wz.wzid = pds6_stwz.wzid WHERE pds6_stwz.code = @p1 ORDER BY pds6_wz.flgnr ASC", roomSymbol)
if top > 0 {
rows, err = t.Query("SELECT TOP(@p1) pds6_wz.PID FROM pds6_wz JOIN pds6_stwz ON pds6_wz.wzid = pds6_stwz.wzid WHERE pds6_stwz.code = @p2 ORDER BY pds6_wz.flgnr ASC", top, roomSymbol)
var rows *sql.Rows
var err error
if top == 0 {
rows, err = db.Query("SELECT pds6_wz.PID FROM pds6_wz JOIN pds6_stwz ON pds6_wz.wzid = pds6_stwz.wzid WHERE pds6_stwz.code = @p1 ORDER BY pds6_wz.flgnr ASC", roomSymbol)
} else {
rows, err = db.Query("SELECT TOP(@p1) pds6_wz.PID FROM pds6_wz JOIN pds6_stwz ON pds6_wz.wzid = pds6_stwz.wzid WHERE pds6_stwz.code = @p2 ORDER BY pds6_wz.flgnr ASC", top, roomSymbol)
}

if err != nil {
return nil, errors.Wrap(err, "could not query database")
}
Expand Down

0 comments on commit 54943d7

Please sign in to comment.