view_random.go 610 B

1234567891011121314151617181920212223242526272829303132
  1. package route
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "fmt"
  6. "opennamu/route/tool"
  7. )
  8. func View_random(call_arg []string) {
  9. db_set := map[string]string{}
  10. json.Unmarshal([]byte(call_arg[0]), &db_set)
  11. db := tool.DB_connect(db_set)
  12. if db == nil {
  13. return
  14. }
  15. defer db.Close()
  16. var title string
  17. err := db.QueryRow(tool.DB_change(db_set, "select title from data where title not like 'user:%' and title not like 'category:%' and title not like 'file:%' order by random() limit 1")).Scan(&title)
  18. if err != nil {
  19. if err == sql.ErrNoRows {
  20. title = ""
  21. } else {
  22. return
  23. }
  24. }
  25. fmt.Print(title)
  26. }