api_w_raw.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package route
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "fmt"
  6. "opennamu/route/tool"
  7. )
  8. func Api_w_raw(call_arg []string) {
  9. db_set := map[string]string{}
  10. json.Unmarshal([]byte(call_arg[0]), &db_set)
  11. other_set := map[string]string{}
  12. json.Unmarshal([]byte(call_arg[1]), &other_set)
  13. db := tool.DB_connect(db_set)
  14. if db == nil {
  15. return
  16. }
  17. defer db.Close()
  18. if other_set["exist_check"] != "" {
  19. stmt, err := db.Prepare(tool.DB_change(db_set, "select title from data where title = ?"))
  20. if err != nil {
  21. return
  22. }
  23. defer stmt.Close()
  24. new_data := map[string]string{}
  25. var title string
  26. err = stmt.QueryRow(other_set["name"]).Scan(&title)
  27. if err != nil {
  28. if err == sql.ErrNoRows {
  29. } else {
  30. return
  31. }
  32. } else {
  33. new_data["exist"] = "1"
  34. }
  35. json_data, _ := json.Marshal(new_data)
  36. fmt.Print(string(json_data))
  37. } else {
  38. new_data := map[string]string{}
  39. var data string
  40. if other_set["rev"] != "" {
  41. stmt, err := db.Prepare(tool.DB_change(db_set, "select data from history where title = ? and id = ?"))
  42. if err != nil {
  43. return
  44. }
  45. defer stmt.Close()
  46. err = stmt.QueryRow(other_set["name"], other_set["rev"]).Scan(&data)
  47. if err != nil {
  48. if err == sql.ErrNoRows {
  49. } else {
  50. return
  51. }
  52. } else {
  53. new_data["title"] = other_set["name"]
  54. new_data["data"] = data
  55. }
  56. json_data, _ := json.Marshal(new_data)
  57. fmt.Print(string(json_data))
  58. } else {
  59. stmt, err := db.Prepare(tool.DB_change(db_set, "select data from data where title = ?"))
  60. if err != nil {
  61. return
  62. }
  63. defer stmt.Close()
  64. err = stmt.QueryRow(other_set["name"]).Scan(&data)
  65. if err != nil {
  66. if err == sql.ErrNoRows {
  67. } else {
  68. return
  69. }
  70. } else {
  71. new_data["title"] = other_set["name"]
  72. new_data["data"] = data
  73. }
  74. json_data, _ := json.Marshal(new_data)
  75. fmt.Print(string(json_data))
  76. }
  77. }
  78. }