Skip to content

Commit

Permalink
中文乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
redHJ committed May 3, 2018
1 parent bc197c2 commit dc875c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion reader/rest_reader_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var (
KeyName: KeyEncoding,
ChooseOnly: true,
ChooseOptions: []interface{}{"UTF-8", "UTF-16", "US-ASCII", "ISO-8859-1",
"GBK", "GB18030", "EUC-JP", "UTF-16BE", "UTF-16LE", "Big5", "Shift_JIS",
"GBK", "latin1", "GB18030", "EUC-JP", "UTF-16BE", "UTF-16LE", "Big5", "Shift_JIS",
"ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7",
"ISO-8859-8", "ISO-8859-9", "ISO-8859-10", "ISO-8859-11", "ISO-8859-12", "ISO-8859-13",
"ISO-8859-14", "ISO-8859-15", "ISO-8859-16", "macos-0_2-10.2", "macos-6_2-10.4",
Expand Down Expand Up @@ -313,6 +313,7 @@ var ModeKeyOptions = map[string][]Option{
Description: "数据查询语句(mysql_sql)",
ToolTip: "填写要执行的sql语句",
},
OptionEncoding,
{
KeyName: KeyMysqlOffsetKey,
ChooseOnly: false,
Expand Down
8 changes: 7 additions & 1 deletion reader/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type SqlReader struct {
readChan chan []byte

meta *Meta // 记录offset的元数据
encoder string // 解码方式
offsets []int64 // 当前处理文件的sql的offset
syncSQLs []string // 当前在查询的sqls
schemas map[string]string
Expand All @@ -69,7 +70,7 @@ const (

func NewSQLReader(meta *Meta, conf conf.MapConf) (ret Reader, err error) {
var readBatch int
var dbtype, dataSource, database, rawSqls, cronSchedule, offsetKey string
var dbtype, dataSource, database, rawSqls, cronSchedule, offsetKey, encoder string
var execOnStart bool
dbtype, _ = conf.GetStringOr(KeyMode, ModeMysql)
logpath, _ := conf.GetStringOr(KeyLogPath, "")
Expand All @@ -96,6 +97,7 @@ func NewSQLReader(meta *Meta, conf conf.MapConf) (ret Reader, err error) {
}
cronSchedule, _ = conf.GetStringOr(KeyMysqlCron, "")
execOnStart, _ = conf.GetBoolOr(KeyMysqlExecOnStart, true)
encoder, _ = conf.GetStringOr(KeyEncoding, "")
case ModeMssql:
readBatch, _ = conf.GetIntOr(KeyMssqlReadBatch, 100)
offsetKey, _ = conf.GetStringOr(KeyMssqlOffsetKey, "")
Expand Down Expand Up @@ -198,6 +200,7 @@ func NewSQLReader(meta *Meta, conf conf.MapConf) (ret Reader, err error) {
magicLagDur: mgld,
schemas: schemas,
statsLock: sync.RWMutex{},
encoder: encoder,
}

// 如果meta初始信息损坏
Expand Down Expand Up @@ -469,6 +472,9 @@ func (mr *SqlReader) run() {
switch mr.dbtype {
case ModeMysql:
connectStr = mr.datasource + "/" + mr.database
if mr.encoder != "" {
connectStr += "?charset=" + mr.encoder
}
case ModeMssql:
connectStr = mr.datasource + ";database=" + mr.database
case ModePG:
Expand Down

0 comments on commit dc875c1

Please sign in to comment.