subsql:=fmt.Sprintf("select last_row(ts) from %s.%s group by tbname",d.srcdbname,stbname)
subRows,err:=d.db.Query(subsql)
iferr!=nil{
checkErr(err,subsql)
}
forsubRows.Next(){
vartbnamestring
subRows.Scan(&lastTime,&tbname)
}
subRows.Close()
lastTime,ok:=lastRowDict[tbname]
if!ok{
lastTime=time.Now()
}
fori,f:=rangefields{
col:=fmt.Sprintf("%s %s %s",stbname,tbname,f)
count:=0
{
var(
tstime.Time
dbnamestring
tablenamestring
colnamestring
checkintervalint
thresholdint
)
checkSql:=fmt.Sprintf("select * from %s.%s where dbname = \"%s\" and tablename = \"%s\" and colname = \"%s\"",d.dbname,d.metaTable,d.srcdbname,tbname,f)
checkSql:=fmt.Sprintf("select * from %s.%s where dbname = \"%s\" and tablename = \"%s\" and colname = \"%s\"",d.dbname,d.metaTable,d.srcdbname,tbname,f)
checkRow,err:=d.db.Query(checkSql)
iferr!=nil{
checkErr(err,checkSql)
}
ifcount==0{
sql:=fmt.Sprintf("insert into %s.%s values(%v, \"%s\", \"%s\", \"%s\", %d, %d)",d.dbname,d.metaTable,fieldTs.UnixMilli(),d.dbname,tbname,f,d.dInterval,d.dThreshold)