Changeset 207 in code for trunk/db.go


Ignore:
Timestamp:
Apr 1, 2020, 3:34:22 PM (5 years ago)
Author:
contact
Message:

Fix SQL error logged on JOIN

Closes: https://todo.sr.ht/~emersion/soju/40

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/db.go

    r202 r207  
    4646        Key  string
    4747}
     48
     49var ErrNoSuchChannel = fmt.Errorf("soju: no such channel")
    4850
    4951type DB struct {
     
    266268}
    267269
     270func (db *DB) GetChannel(networkID int64, name string) (*Channel, error) {
     271        db.lock.RLock()
     272        defer db.lock.RUnlock()
     273
     274        ch := &Channel{Name: name}
     275
     276        var key *string
     277        row := db.db.QueryRow("SELECT id, key FROM Channel WHERE network = ? AND name = ?", networkID, name)
     278        if err := row.Scan(&ch.ID, &key); err == sql.ErrNoRows {
     279                return nil, ErrNoSuchChannel
     280        } else if err != nil {
     281                return nil, err
     282        }
     283        ch.Key = fromStringPtr(key)
     284        return ch, nil
     285}
     286
    268287func (db *DB) StoreChannel(networkID int64, ch *Channel) error {
    269288        db.lock.Lock()
Note: See TracChangeset for help on using the changeset viewer.