summaryrefslogtreecommitdiff
path: root/poll.go
diff options
context:
space:
mode:
Diffstat (limited to 'poll.go')
-rw-r--r--poll.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/poll.go b/poll.go
index 83d1281..9ca9aeb 100644
--- a/poll.go
+++ b/poll.go
@@ -5,7 +5,7 @@ import "github.com/mxk/go-sqlite/sqlite3"
type Poll struct {
id int
title string
- userId int
+ userId int64
}
func addPoll(db *sqlite3.Conn, title string, options []string, nick string) (int64, error) {
@@ -63,7 +63,7 @@ func getPollFromTitle(db *sqlite3.Conn, title string) Poll {
var rowid int
s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row
- poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int)}
+ poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int64)}
return poll
}
@@ -72,3 +72,36 @@ func getPollFromTitle(db *sqlite3.Conn, title string) Poll {
}
+func getPollFromId(db *sqlite3.Conn, id int) Poll {
+
+ args := sqlite3.NamedArgs{"$a": id}
+ sql := "SELECT * FROM polls WHERE id = $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
+
+ poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int64)}
+ return poll
+ }
+
+ //If we get here there are no matching users
+ return Poll{id:0, title:"", userId:0}
+
+}
+
+func deletePoll(db *sqlite3.Conn, id int) error {
+
+ poll := getPollFromId(db, id)
+
+ if (poll.id == 0) {
+ return nil
+ } else {
+ sql := "DELETE FROM polls WHERE id = $a"
+ args := sqlite3.NamedArgs{"$a": id}
+ db.Exec(sql, args)
+ return nil
+ }
+} \ No newline at end of file