WIP: looking into double-charset problems

This commit is contained in:
Shlomi Noach 2016-11-02 12:15:36 +01:00
parent 8b4a32cedd
commit c6df7aa016
3 changed files with 24 additions and 0 deletions

View File

@ -152,6 +152,10 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) {
if column.Name == mappedColumn.Name && column.Type == sql.DateTimeColumnType && mappedColumn.Type == sql.TimestampColumnType { if column.Name == mappedColumn.Name && column.Type == sql.DateTimeColumnType && mappedColumn.Type == sql.TimestampColumnType {
this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.migrationContext.ApplierTimeZone) this.migrationContext.MappedSharedColumns.SetConvertDatetimeToTimestamp(column.Name, this.migrationContext.ApplierTimeZone)
} }
if column.Name == mappedColumn.Name && column.Charset != "" && column.Charset == mappedColumn.Charset {
this.migrationContext.SharedColumns.SetCharsetUnchanged(column.Name)
this.migrationContext.MappedSharedColumns.SetCharsetUnchanged(column.Name)
}
} }
for _, column := range this.migrationContext.UniqueKey.Columns.Columns() { for _, column := range this.migrationContext.UniqueKey.Columns.Columns() {

View File

@ -38,6 +38,12 @@ func buildColumnsPreparedValues(columns *ColumnList) []string {
var token string var token string
if column.timezoneConversion != nil { if column.timezoneConversion != nil {
token = fmt.Sprintf("convert_tz(?, '%s', '%s')", column.timezoneConversion.ToTimezone, "+00:00") token = fmt.Sprintf("convert_tz(?, '%s', '%s')", column.timezoneConversion.ToTimezone, "+00:00")
} else if column.CharsetUnchanged {
token = "?"
// token = fmt.Sprintf("BINARY ?")
//token = fmt.Sprintf("_%s ?", column.Charset)
// token = fmt.Sprintf("convert(? using %s)", column.Charset)
// token = fmt.Sprintf("convert(?, char character set %s)", column.Charset)
} else { } else {
token = "?" token = "?"
} }

View File

@ -10,6 +10,8 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"github.com/outbrain/golib/log"
) )
type ColumnType int type ColumnType int
@ -29,15 +31,23 @@ type Column struct {
Name string Name string
IsUnsigned bool IsUnsigned bool
Charset string Charset string
CharsetUnchanged bool
Type ColumnType Type ColumnType
timezoneConversion *TimezoneConvertion timezoneConversion *TimezoneConvertion
} }
func (this *Column) convertArg(arg interface{}) interface{} { func (this *Column) convertArg(arg interface{}) interface{} {
if s, ok := arg.(string); ok { if s, ok := arg.(string); ok {
if this.CharsetUnchanged {
log.Errorf("============== charset unchanged for %+v: %+v, <%+v>", this.Name, this.Charset, arg)
// return []byte(s)
//return s
}
log.Errorf("============== charset for %+v: %+v, <%+v>", this.Name, this.Charset, arg)
// string, charset conversion // string, charset conversion
if encoding, ok := charsetEncodingMap[this.Charset]; ok { if encoding, ok := charsetEncodingMap[this.Charset]; ok {
arg, _ = encoding.NewDecoder().String(s) arg, _ = encoding.NewDecoder().String(s)
log.Errorf("============== charset converted for %+v: %+v, <%+v>", this.Name, this.Charset, arg)
} }
return arg return arg
} }
@ -142,6 +152,10 @@ func (this *ColumnList) IsUnsigned(columnName string) bool {
return this.GetColumn(columnName).IsUnsigned return this.GetColumn(columnName).IsUnsigned
} }
func (this *ColumnList) SetCharsetUnchanged(columnName string) {
this.GetColumn(columnName).CharsetUnchanged = true
}
func (this *ColumnList) SetCharset(columnName string, charset string) { func (this *ColumnList) SetCharset(columnName string, charset string) {
this.GetColumn(columnName).Charset = charset this.GetColumn(columnName).Charset = charset
} }