api_bbs_w_comment.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package route
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "log"
  6. "opennamu/route/tool"
  7. "strconv"
  8. )
  9. func Api_bbs_w_comment(call_arg []string) string {
  10. other_set := map[string]string{}
  11. json.Unmarshal([]byte(call_arg[0]), &other_set)
  12. db := tool.DB_connect()
  13. defer db.Close()
  14. if other_set["tool"] == "length" {
  15. stmt, err := db.Prepare(tool.DB_change("select count(*) from bbs_data where set_name = 'comment_date' and set_id = ? order by set_code + 0 desc"))
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. defer stmt.Close()
  20. var comment_length string
  21. bbs_and_post_num := other_set["bbs_num"] + "-" + other_set["post_num"]
  22. err = stmt.QueryRow(bbs_and_post_num).Scan(&comment_length)
  23. if err != nil {
  24. if err == sql.ErrNoRows {
  25. comment_length = "0"
  26. } else {
  27. log.Fatal(err)
  28. }
  29. }
  30. stmt, err = db.Prepare(tool.DB_change("select count(*) from bbs_data where set_name = 'comment_date' and set_id like ? order by set_code + 0 desc"))
  31. if err != nil {
  32. log.Fatal(err)
  33. }
  34. defer stmt.Close()
  35. var reply_length string
  36. err = stmt.QueryRow(bbs_and_post_num + "-%").Scan(&reply_length)
  37. if err != nil {
  38. if err == sql.ErrNoRows {
  39. reply_length = "0"
  40. } else {
  41. log.Fatal(err)
  42. }
  43. }
  44. comment_length_int, _ := strconv.Atoi(comment_length)
  45. reply_length_int, _ := strconv.Atoi(reply_length)
  46. length_int := comment_length_int + reply_length_int
  47. length_str := strconv.Itoa(length_int)
  48. data_list := map[string]string{
  49. "comment": comment_length,
  50. "reply": reply_length,
  51. "data": length_str,
  52. }
  53. json_data, _ := json.Marshal(data_list)
  54. return string(json_data)
  55. } else {
  56. return ""
  57. }
  58. }