summaryrefslogtreecommitdiff
path: root/option.go
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-07-21 11:51:34 +0100
committerJoe Robinson <joe@mumsnet.com>2014-07-21 11:51:34 +0100
commit5b1d414ba23937e7fe1eba74547a7acf33e9c5a6 (patch)
treef8fd9b1c9860201a10408c82855ac4a4f8cde1ce /option.go
parentc4c2aee4aa4ce2b726f14cb8f91f20801d2e6784 (diff)
Added some error checking
Diffstat (limited to 'option.go')
-rw-r--r--option.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/option.go b/option.go
index d8cb697..e3d246f 100644
--- a/option.go
+++ b/option.go
@@ -1,6 +1,7 @@
package main
import "github.com/mxk/go-sqlite/sqlite3"
+import "errors"
type Option struct {
id int
@@ -8,7 +9,7 @@ type Option struct {
pollId int64
}
-func getOptionFromText(db*sqlite3.Conn, text string) Option {
+func getOptionFromText(db*sqlite3.Conn, text string) (Option, error) {
args := sqlite3.NamedArgs{"$a": text}
sql := "SELECT * FROM options WHERE text = $a"
@@ -20,10 +21,10 @@ func getOptionFromText(db*sqlite3.Conn, text string) Option {
s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row
option := Option{id:rowid, text:row["text"].(string), pollId:row["poll_id"].(int64)}
- return option
+ return option, nil
}
- //If we get here there are no matching users
- return Option{id:0, text:"", pollId:0}
+ //If we get here there are no matching options
+ return Option{id:0, text:"", pollId:0}, errors.New("No option found matching '" + text + "'")
} \ No newline at end of file