package test import ( "fmt" "testing" ) var unit_test = "ddl" var INS = []string{ "INSERT INTO gotab1 VALUES(1, 0.27, 0.99);", "INSERT INTO gotab1 VALUES(1, NULL, NULL);", "INSERT INTO gotab2 VALUES(1, 'XuguSQL', '2020-01-01 00:00:00');", "INSERT INTO gotab2 VALUES(1, '', NULL);"} var Ins2 = ` INSERT INTO LicenseProcess ( Creator, ApplyDate, RelatedProject, SalesPerson, SalesEmail, TechSupport, TechEmail, ProductName, Version, Processor, OperatingSystem, IP, MAC ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` func TestDbexec(t *testing.T) { for _, sql := range INS { _, err := db.Exec(sql) if err != nil { fmt.Printf("[ERROR] %s\n", err.Error()) continue } fmt.Printf("%s ... ok\n", sql) } err := db.Close() if err != nil { fmt.Printf("[ERROR] %s\n", err.Error()) } } type LicenseProcess struct { Creator string // 创建人 ApplyDate string // 申请日期 RelatedProject string // 关联项目 SalesPerson string // 销售人员 SalesEmail string // 销售邮箱 TechSupport string // 技术人员 TechEmail string // 技术邮箱 ProductName string // 产品名称 Version string // 版本 Processor string // 处理器 OperatingSystem string // 操作系统 IP string // IP MAC string // MAC } func TestDbexec2(t *testing.T) { lp := LicenseProcess{ Creator: "Alice", ApplyDate: "2023-01-01", RelatedProject: "Project A", SalesPerson: "Bob", SalesEmail: "bob@example.com", TechSupport: "Charlie", TechEmail: "charlie@example.com", ProductName: "Product X", Version: "1.0", Processor: "Intel", OperatingSystem: "Linux", IP: "192.168.1.1", MAC: "00:1A:2B:3C:4D:5E", } _, err := db.Exec(Ins2, lp.Creator, lp.ApplyDate, lp.RelatedProject, lp.SalesPerson, lp.SalesEmail, lp.TechSupport, lp.TechEmail, lp.ProductName, lp.Version, lp.Processor, lp.OperatingSystem, lp.IP, lp.MAC, ) if err != nil { fmt.Printf("[ERROR] %s\n", err.Error()) return } fmt.Printf("%s ... ok\n", Ins2) err = db.Close() if err != nil { fmt.Printf("[ERROR] %s\n", err.Error()) } }