1 Star 0 Fork 1

yysf / dplog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dplog_test.go 4.13 KB
一键复制 编辑 原始数据 按行查看 历史
yangshaofeng 提交于 2023-04-11 21:19 . 修正次数统计信息
package dplog
import (
"gitee.com/yysf_xin/dplog/pkg/push"
"gitee.com/yysf_xin/go-common/db"
"gitee.com/yysf_xin/go-notifier"
"strings"
"testing"
"text/template"
"time"
)
func TestTpl2(t *testing.T) {
tpl := template.New("aa")
notifier.Init(tpl)
var demoTmpl = "{\"msg\": \"{{ . | SafeTruncate 500 | json}}\"}"
tp, _ := tpl.Parse(demoTmpl)
data := "\norg.springframework.jdbc.BadSqlGrammarException: \n### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\n### The error may exist in class path resource [mybatis/mapper/order/GroupOrderExtendMapper.xml]\n### The error may involve defaultParameterMap\n### The error occurred while setting parameters\n### SQL: select order_id, `account`, extend, sub_order_status, stock_up_time, sync_third_order_status, status_time, sale_type, pre_delivery_date from sf_group_order_extend where and data_flag = 1\n### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\n; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\n\tat org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)\n\tat org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)\n hidden 1 elements\n\tat com.feng1.mybatis.SmartSqlSessionTemplate$SqlSessionInterceptor.invoke(SmartSqlSessionTemplate.java:138)"
buff := strings.Builder{}
err := tp.Execute(&buff, data)
if err != nil {
panic(err)
}
println(buff.String())
println("{\"msg\": \"\\norg.springframework.jdbc.BadSqlGrammarException: \\n### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\\n### The error may exist in class path resource [mybatis/mapper/order/GroupOrderExtendMapper.xml]\\n### The error may involve defaultParameterMap\\n### The error occurred while setting parameters\\n### SQL: select order_id, `account`, extend, sub_order_status, stock_up_time, sync_third_order_status, status_time, sale_type, pre_delivery_date from sf_group_order_extend where and data_flag = 1\\n### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\\n; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and data_flag = 1' at line 6\\n\\tat org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)\\n\\tat org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)\\n hidden 1 elements\\n\\tat com.feng1.mybatis.SmartSqlSessionTemplate$SqlSessionInterceptor.invoke(SmartSqlSessionTemplate.java:138)\",\n")
//println(template.JSEscapeString(data))
}
func TestTplDate(t *testing.T) {
tpl := template.New("aa")
notifier.Init(tpl)
msg := push.Msg{}
msg.Last = db.Time(time.Now())
msg.Msg.Time = time.Now()
tp, _ := tpl.Parse("{{.Msg.Time.Format \"01-02 15:04\"}} ")
buff := strings.Builder{}
err := tp.Execute(&buff, &msg)
if err != nil {
panic(err)
}
println(buff.String())
}
Go
1
https://gitee.com/yysf_xin/dplog.git
git@gitee.com:yysf_xin/dplog.git
yysf_xin
dplog
dplog
master

搜索帮助