dbexec_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package test
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. var unit_test = "ddl"
  7. var INS = []string{
  8. "INSERT INTO gotab1 VALUES(1, 0.27, 0.99);",
  9. "INSERT INTO gotab1 VALUES(1, NULL, NULL);",
  10. "INSERT INTO gotab2 VALUES(1, 'XuguSQL', '2020-01-01 00:00:00');",
  11. "INSERT INTO gotab2 VALUES(1, '', NULL);"}
  12. var Ins2 = `
  13. INSERT INTO LicenseProcess (
  14. Creator, ApplyDate, RelatedProject, SalesPerson, SalesEmail, TechSupport, TechEmail,
  15. ProductName, Version, Processor, OperatingSystem, IP, MAC
  16. ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  17. `
  18. func TestDbexec(t *testing.T) {
  19. for _, sql := range INS {
  20. _, err := db.Exec(sql)
  21. if err != nil {
  22. fmt.Printf("[ERROR] %s\n", err.Error())
  23. continue
  24. }
  25. fmt.Printf("%s ... ok\n", sql)
  26. }
  27. err := db.Close()
  28. if err != nil {
  29. fmt.Printf("[ERROR] %s\n", err.Error())
  30. }
  31. }
  32. type LicenseProcess struct {
  33. Creator string // 创建人
  34. ApplyDate string // 申请日期
  35. RelatedProject string // 关联项目
  36. SalesPerson string // 销售人员
  37. SalesEmail string // 销售邮箱
  38. TechSupport string // 技术人员
  39. TechEmail string // 技术邮箱
  40. ProductName string // 产品名称
  41. Version string // 版本
  42. Processor string // 处理器
  43. OperatingSystem string // 操作系统
  44. IP string // IP
  45. MAC string // MAC
  46. }
  47. func TestDbexec2(t *testing.T) {
  48. lp := LicenseProcess{
  49. Creator: "Alice",
  50. ApplyDate: "2023-01-01",
  51. RelatedProject: "Project A",
  52. SalesPerson: "Bob",
  53. SalesEmail: "bob@example.com",
  54. TechSupport: "Charlie",
  55. TechEmail: "charlie@example.com",
  56. ProductName: "Product X",
  57. Version: "1.0",
  58. Processor: "Intel",
  59. OperatingSystem: "Linux",
  60. IP: "192.168.1.1",
  61. MAC: "00:1A:2B:3C:4D:5E",
  62. }
  63. _, err := db.Exec(Ins2,
  64. lp.Creator, lp.ApplyDate, lp.RelatedProject, lp.SalesPerson, lp.SalesEmail, lp.TechSupport, lp.TechEmail,
  65. lp.ProductName, lp.Version, lp.Processor, lp.OperatingSystem, lp.IP, lp.MAC,
  66. )
  67. if err != nil {
  68. fmt.Printf("[ERROR] %s\n", err.Error())
  69. return
  70. }
  71. fmt.Printf("%s ... ok\n", Ins2)
  72. err = db.Close()
  73. if err != nil {
  74. fmt.Printf("[ERROR] %s\n", err.Error())
  75. }
  76. }