summaryrefslogtreecommitdiff
path: root/option.go
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-07-18 18:27:00 +0100
committerJoe Robinson <joe@mumsnet.com>2014-07-18 18:27:00 +0100
commit70b4b1dc65bfd493088443c20c4670a62c06f317 (patch)
treeec44625cc577f197b7c98edc0de8eb4d30bc4b2c /option.go
parent0913485975baf0a5db4939ab3112ed7b8883d0f1 (diff)
Added initial voting functionality
Diffstat (limited to 'option.go')
-rw-r--r--option.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/option.go b/option.go
new file mode 100644
index 0000000..d8cb697
--- /dev/null
+++ b/option.go
@@ -0,0 +1,29 @@
+package main
+
+import "github.com/mxk/go-sqlite/sqlite3"
+
+type Option struct {
+ id int
+ text string
+ pollId int64
+}
+
+func getOptionFromText(db*sqlite3.Conn, text string) Option {
+
+ args := sqlite3.NamedArgs{"$a": text}
+ sql := "SELECT * FROM options WHERE text = $a"
+ s, err := db.Query(sql, args)
+ row := make(sqlite3.RowMap)
+
+ for ; err == nil ; err = s.Next() {
+ var rowid int
+ 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
+ }
+
+ //If we get here there are no matching users
+ return Option{id:0, text:"", pollId:0}
+
+} \ No newline at end of file