From 8d2e60dcb97570307cd41bb07c73f7d13f182c44 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Tue, 2 Dec 2014 00:28:05 +0100 Subject: [PATCH] Add missing check --- lib/check_table_access.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/check_table_access.go diff --git a/lib/check_table_access.go b/lib/check_table_access.go new file mode 100644 index 0000000..3e4e8c3 --- /dev/null +++ b/lib/check_table_access.go @@ -0,0 +1,24 @@ +package lib + +import ( + "database/sql" + "log" +) + +// check that select to a table exists. Return an error if we get a failure. +func CheckTableAccess(dbh *sql.DB, table_name string) error { + sql_select := "SELECT 1 FROM " + table_name + " LIMIT 1" + + var one int + err := dbh.QueryRow(sql_select).Scan(&one) + switch { + case err == sql.ErrNoRows: + log.Println("No setting with that variable_name", one) + case err != nil: + log.Fatal(err) + default: + // we don't care if there's no error + } + + return err +} -- 2.7.4