Merge branch 'master' of github.com:go-xorm/xorm
This commit is contained in:
commit
74a165e1fd
10
engine.go
10
engine.go
|
@ -666,6 +666,15 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
|||
continue
|
||||
}
|
||||
col.SQLType = core.SQLType{fs[0], 0, 0}
|
||||
if fs[0] == core.Enum && fs[1][0] == '\'' { //enum
|
||||
options := strings.Split(fs[1][0:len(fs[1])-1], ",")
|
||||
col.EnumOptions = make(map[string]int)
|
||||
for k, v := range options {
|
||||
v = strings.TrimSpace(v)
|
||||
v = strings.Trim(v, "'")
|
||||
col.EnumOptions[v] = k
|
||||
}
|
||||
} else {
|
||||
fs2 := strings.Split(fs[1][0:len(fs[1])-1], ",")
|
||||
if len(fs2) == 2 {
|
||||
col.Length, err = strconv.Atoi(fs2[0])
|
||||
|
@ -682,6 +691,7 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
|||
engine.LogError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _, ok := core.SqlTypes[k]; ok {
|
||||
col.SQLType = core.SQLType{k, 0, 0}
|
||||
|
|
|
@ -53,6 +53,17 @@ func (db *mysql) SqlType(c *core.Column) string {
|
|||
case core.TimeStampz:
|
||||
res = core.Char
|
||||
c.Length = 64
|
||||
case core.Enum: //mysql enum
|
||||
res = core.Enum
|
||||
res += "("
|
||||
for v, k := range c.EnumOptions {
|
||||
if k > 0 {
|
||||
res += fmt.Sprintf(",'%v'", v)
|
||||
} else {
|
||||
res += fmt.Sprintf("'%v'", v)
|
||||
}
|
||||
}
|
||||
res += ")"
|
||||
default:
|
||||
res = t
|
||||
}
|
||||
|
@ -140,12 +151,26 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
|
|||
|
||||
if colDefault != nil {
|
||||
col.Default = *colDefault
|
||||
if col.Default == "" {
|
||||
col.DefaultIsEmpty = true
|
||||
}
|
||||
}
|
||||
|
||||
cts := strings.Split(colType, "(")
|
||||
colName := cts[0]
|
||||
colType = strings.ToUpper(colName)
|
||||
var len1, len2 int
|
||||
if len(cts) == 2 {
|
||||
idx := strings.Index(cts[1], ")")
|
||||
if colType == core.Enum && cts[1][0] == '\'' { //enum
|
||||
options := strings.Split(cts[1][0:idx], ",")
|
||||
col.EnumOptions = make(map[string]int)
|
||||
for k, v := range options {
|
||||
v = strings.TrimSpace(v)
|
||||
v = strings.Trim(v, "'")
|
||||
col.EnumOptions[v] = k
|
||||
}
|
||||
} else {
|
||||
lens := strings.Split(cts[1][0:idx], ",")
|
||||
len1, err = strconv.Atoi(strings.TrimSpace(lens[0]))
|
||||
if err != nil {
|
||||
|
@ -158,8 +183,7 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
|
|||
}
|
||||
}
|
||||
}
|
||||
colName := cts[0]
|
||||
colType = strings.ToUpper(colName)
|
||||
}
|
||||
col.Length = len1
|
||||
col.Length2 = len2
|
||||
if _, ok := core.SqlTypes[colType]; ok {
|
||||
|
@ -182,6 +206,10 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
|
|||
if col.SQLType.IsText() {
|
||||
if col.Default != "" {
|
||||
col.Default = "'" + col.Default + "'"
|
||||
} else {
|
||||
if col.DefaultIsEmpty {
|
||||
col.Default = "''"
|
||||
}
|
||||
}
|
||||
}
|
||||
cols[col.Name] = col
|
||||
|
|
|
@ -718,7 +718,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 查询数目太大,采用缓存将不是一个很好的方式。
|
||||
// 查询数目太大,采用缓å˜å°†ä¸æ˜¯ä¸€ä¸ªå¾ˆå¥½çš„æ–¹å¼ã€
|
||||
if len(resultsSlice) > 500 {
|
||||
session.Engine.LogDebug("[xorm:cacheFind] ids length %v > 500, no cache", len(resultsSlice))
|
||||
return ErrCacheFailed
|
||||
|
@ -2484,15 +2484,15 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
|
|||
return fieldValue.String(), nil
|
||||
case reflect.Struct:
|
||||
if fieldType == core.TimeType {
|
||||
switch fieldValue.Interface().(type) {
|
||||
case time.Time:
|
||||
t := fieldValue.Interface().(time.Time)
|
||||
if session.Engine.dialect.DBType() == core.MSSQL {
|
||||
if t.IsZero() {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
switch fieldValue.Interface().(type) {
|
||||
case time.Time:
|
||||
tf := session.Engine.FormatTime(col.SQLType.Name, fieldValue.Interface().(time.Time))
|
||||
tf := session.Engine.FormatTime(col.SQLType.Name, t)
|
||||
return tf, nil
|
||||
default:
|
||||
return fieldValue.Interface(), nil
|
||||
|
|
Loading…
Reference in New Issue