Skip to content

Commit

Permalink
[internal/database] GetCorrID needs to accept multiple rows as result
Browse files Browse the repository at this point in the history
QueryRow selects the first result returned, but the file_event_log always will return multiple rows. This is due to the `register_file` function  in our DB schema that stores the first log event without any correlation ID.
  • Loading branch information
jbygdell committed Dec 30, 2024
1 parent dac21cf commit fab9558
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions sda/internal/database/db_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,29 @@ func (dbs *SDAdb) getCorrID(user, path, accession string) (string, error) {
dbs.checkAndReconnectIfNeeded()
db := dbs.DB
const query = "SELECT DISTINCT correlation_id FROM sda.file_event_log e " +
"RIGHT JOIN sda.files f ON e.file_id = f.id WHERE f.submission_file_path = $1 AND f.submission_user = $2 AND COALESCE(f.stable_id, '')= $3;"

var corrID string
err := db.QueryRow(query, path, user, accession).Scan(&corrID)
"RIGHT JOIN sda.files f ON e.file_id = f.id " +
"WHERE f.submission_file_path = $1 AND f.submission_user = $2 AND COALESCE(f.stable_id, '') = $3;"
rows, err := db.Query(query, path, user, accession)
if err != nil {
return "", err
}
if rows.Err() != nil {
return "", rows.Err()
}
defer rows.Close()

var corrID sql.NullString
for rows.Next() {
err := rows.Scan(&corrID)
if err != nil {
return "", err
}
if corrID.Valid {
break
}
}

return corrID, nil
return corrID.String, nil
}

// list all users with files not yet assigned to a dataset
Expand Down

0 comments on commit fab9558

Please sign in to comment.