X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Fcheck_table_access.go;fp=lib%2Fcheck_table_access.go;h=3e4e8c3dcb8bd08c36371838c75022d8755cd7e8;hb=8d2e60dcb97570307cd41bb07c73f7d13f182c44;hp=0000000000000000000000000000000000000000;hpb=a99b1b63f399a1c66a480debcb00f5a5a46ededf;p=pstop.git 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 +}