Преглед на файлове

Prevent errors from having no rows.

master
Syfaro преди 3 години
родител
ревизия
a8b605b19a
променени са 4 файла, в които са добавени 33 реда и са изтрити 14 реда
  1. +7
    -2
      commands/manage/count_items.go
  2. +4
    -2
      commands/manage/end_selection.go
  3. +12
    -7
      commands/manage/select_item.go
  4. +10
    -3
      commands/manage/selection_list.go

+ 7
- 2
commands/manage/count_items.go Целия файл

@@ -2,6 +2,7 @@ package commands

import (
"bytes"
"database/sql"
"github.com/syfaro/finch"
"github.com/syfaro/selectionsbot/database"
"gopkg.in/telegram-bot-api.v4"
@@ -32,8 +33,10 @@ func (cmd countItems) Execute(message tgbotapi.Message) error {
order by
id desc
`, message.Chat.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No currently active selections")
}

var items []database.SelectionVoteCount
@@ -51,8 +54,10 @@ func (cmd countItems) Execute(message tgbotapi.Message) error {
group by
selection_item_id
`, selection.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No votes were found")
}

b := bytes.Buffer{}


+ 4
- 2
commands/manage/end_selection.go Целия файл

@@ -30,8 +30,10 @@ func (cmd endSelection) Execute(message tgbotapi.Message) error {
active = 1 and
chat_id = $1
`, message.Chat.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No currently active selections")
}

u := database.User{}
@@ -48,7 +50,7 @@ func (cmd endSelection) Execute(message tgbotapi.Message) error {
where
chat_id = $1
`, message.Chat.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
}



+ 12
- 7
commands/manage/select_item.go Целия файл

@@ -30,11 +30,10 @@ func (cmd selectItem) Execute(message tgbotapi.Message) error {
chat_id = $1 and
active = 1
`, message.Chat.ID)
if err == sql.ErrNoRows {
cmd.QuickReply(message, "There are no active selections")
return nil
} else if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No currently active selections")
}

var items []database.SelectionItem
@@ -46,8 +45,10 @@ func (cmd selectItem) Execute(message tgbotapi.Message) error {
where
selection_id = $1
`, selection.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No selection items were found")
}

var itemList [][]tgbotapi.KeyboardButton
@@ -100,8 +101,10 @@ func (cmd selectItem) ExecuteWaiting(message tgbotapi.Message) error {
chat_id = $1 and
active = 1
`, message.Chat.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No currently active selections")
}

var item database.SelectionItem
@@ -114,8 +117,10 @@ func (cmd selectItem) ExecuteWaiting(message tgbotapi.Message) error {
item = $1 and
selection_id = $2
`, message.Text, selection.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No selection items were found")
}

_, err = database.DB.Exec(`


+ 10
- 3
commands/manage/selection_list.go Целия файл

@@ -2,6 +2,7 @@ package commands

import (
"bytes"
"database/sql"
"github.com/syfaro/finch"
"github.com/syfaro/selectionsbot/database"
"gopkg.in/telegram-bot-api.v4"
@@ -32,8 +33,10 @@ func (cmd selectionList) Execute(message tgbotapi.Message) error {
order by
id desc
`, message.Chat.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No currently active selections")
}

var items []database.SelectionItem
@@ -45,8 +48,10 @@ func (cmd selectionList) Execute(message tgbotapi.Message) error {
where
selection_id = $1
`, selection.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No items were found")
}

b := bytes.Buffer{}
@@ -68,8 +73,10 @@ func (cmd selectionList) Execute(message tgbotapi.Message) error {
selection_id = $1 and
selection_item_id = $2
`, selection.ID, item.ID)
if err != nil {
if err != nil && err != sql.ErrNoRows {
return err
} else if err == sql.ErrNoRows {
return cmd.QuickReply(message, "No votes were found")
}

var users []string


Loading…
Отказ
Запис