mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-05-04 19:11:27 +08:00
@@ -6,12 +6,7 @@ const logTableName = "device_log"
|
||||
|
||||
// CreateLogStable 添加LOG超级表
|
||||
func (s *TdEngine) CreateLogStable() (err error) {
|
||||
var name string
|
||||
err = s.db.QueryRow("SELECT stable_name FROM information_schema.ins_stables WHERE stable_name = 'device_log' LIMIT 1").Scan(&name)
|
||||
if name != "" {
|
||||
return
|
||||
}
|
||||
sql := "CREATE STABLE device_log (ts TIMESTAMP, type VARCHAR(20), content VARCHAR(1000)) TAGS (device VARCHAR(255))"
|
||||
sql := "CREATE STABLE IF NOT EXISTS device_log (ts TIMESTAMP, type VARCHAR(20), content VARCHAR(1000)) TAGS (device VARCHAR(255))"
|
||||
_, err = s.db.Exec(sql)
|
||||
return
|
||||
}
|
||||
@@ -28,8 +23,8 @@ func (s *TdEngine) InsertLog(log *TdLog) (err error) {
|
||||
func (s *TdEngine) ClearLog() (err error) {
|
||||
ts := time.Now().Add(-7 * 24 * time.Hour).Format("2006-01-02")
|
||||
|
||||
sql := "DELETE FROM device_log WHERE ts < '" + ts + "'"
|
||||
_, err = s.db.Exec(sql)
|
||||
sql := "DELETE FROM device_log WHERE ts < ?"
|
||||
_, err = s.db.Exec(sql, ts)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user