提交 ddd0a90c 编写于 作者: martianzhang's avatar martianzhang

add mymysql.TimeString single function into mysql.go

上级 bf0d01ca
......@@ -23,6 +23,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"github.com/XiaoMi/soar/common"
......@@ -287,3 +288,17 @@ func (db *Connector) dangerousQuery(query string) bool {
return false
}
// Sandard MySQL datetime format
const TimeFormat = "2006-01-02 15:04:05.000000000"
// TimeString returns t as string in MySQL format Converts time.Time zero to MySQL zero.
func TimeString(t time.Time) string {
if t.IsZero() {
return "0000-00-00 00:00:00"
}
if t.Nanosecond() == 0 {
return t.Format(TimeFormat[:19])
}
return t.Format(TimeFormat)
}
......@@ -23,7 +23,6 @@ import (
"time"
"github.com/XiaoMi/soar/common"
"github.com/ziutek/mymysql/mysql"
)
/*--------------------
......@@ -135,7 +134,7 @@ func (db *Connector) startSampling(onlineConn *sql.DB, database, table string, w
case "TIMESTAMP", "DATETIME":
t, err := time.Parse(time.RFC3339, string(val))
common.LogIfWarn(err, "")
values = append(values, fmt.Sprintf(`"%s"`, mysql.TimeString(t)))
values = append(values, fmt.Sprintf(`"%s"`, TimeString(t)))
default:
values = append(values, fmt.Sprintf(`unhex("%s")`, fmt.Sprintf("%x", val)))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册