MCPcopy Create free account
hub / github.com/YouChenJun/Keydd / InsertData

Function InsertData

engine_db/sql.go:52–71  ·  view source on GitHub ↗

插入数据-存在true -不存在false

(db *sql.DB, data *consts.Keyinfo)

Source from the content-addressed store, hash-verified

50
51// 插入数据-存在true -不存在false
52func InsertData(db *sql.DB, data *consts.Keyinfo) bool {
53 var count int
54 query := "SELECT COUNT(*) FROM key_info WHERE Host =? AND Req_Path =? AND RuleName =? AND Key_text=?"
55 err = db.QueryRow(query, data.Host, data.Req_Path, data.RuleName, data.Key_text).Scan(&count)
56 if err != nil && err != sql.ErrNoRows {
57 if err != nil {
58 logger.Error.Printf("查询失败:", err)
59 }
60 }
61 if count > 0 {
62 return false
63 } else {
64 stmt := "INSERT INTO key_info (RuleName, Host, Req_Path,Req_Body,Res_Body,Key_text,Content_Type) VALUES (?,?,?,?,?,?,?)"
65 _, err = db.Exec(stmt, data.RuleName, data.Host, data.Req_Path, string(data.Req_Body), string(data.Res_Body), data.Key_text, data.Content_Type)
66 if err != nil {
67 logger.Error.Printf("插入失败:", err)
68 }
69 return true
70 }
71}

Callers 1

WriteDataToDatabaseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected