Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mycsv_test.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. "testing"
  6. "git.x2erp.com/qdy/go-base/config"
  7. "git.x2erp.com/qdy/go-db/factory/database"
  8. )
  9. func TestNamedParamsQueryCSV(t *testing.T) {
  10. cfg := config.GetConfig()
  11. factory := database.CreateDBFactory(cfg)
  12. defer factory.Close()
  13. // 简化的SQL,只测试3个参数
  14. sql := `
  15. SELECT * FROM (
  16. SELECT a.*, ROWNUM rn FROM (
  17. SELECT CLOTHING_ID, CLOTHING_NAME
  18. FROM X6_STOCK_DEV.A3_CLOTHING
  19. where clothing_id>:1
  20. ORDER BY CLOTHING_ID
  21. ) a WHERE ROWNUM <= :2
  22. ) WHERE rn > :3
  23. `
  24. // // 3个参数
  25. params := []interface{}{
  26. "A",
  27. 10,
  28. 0,
  29. }
  30. // // 3个参数
  31. // params := map[string]interface{}{
  32. // "end_row": 10,
  33. // "start_row": 0,
  34. // }
  35. // // 3个参数
  36. // params := map[string]interface{}{
  37. // "clothing_id": "`0`",
  38. // "end_row": 10,
  39. // "start_row": 0,
  40. // }
  41. // 执行查询
  42. result := factory.QueryPositionalToJSON(sql, params, nil)
  43. // 将请求参数输出为格式化的 JSON 日志
  44. reqJSON, err := json.MarshalIndent(result, "", " ")
  45. if err != nil {
  46. log.Printf("无法序列化请求参数: %v", err)
  47. } else {
  48. log.Printf("QueryRequest 参数:\n%s", string(reqJSON))
  49. }
  50. // 或者使用 fmt 输出
  51. //fmt.Printf("=== QueryRequest ===\n%s\n====================\n", string(reqJSON))
  52. }