autoincr(start) support

This commit is contained in:
Lunny Xiao 2014-01-23 10:19:18 +08:00
parent 2699e20b7b
commit d71a6af18a
1 changed files with 23 additions and 3 deletions

View File

@ -452,6 +452,7 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
table.Type = t table.Type = t
var idFieldColName string var idFieldColName string
var err error
for i := 0; i < t.NumField(); i++ { for i := 0; i < t.NumField(); i++ {
tag := t.Field(i).Tag tag := t.Field(i).Tag
@ -495,8 +496,18 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
col.Nullable = false col.Nullable = false
case k == "NULL": case k == "NULL":
col.Nullable = (strings.ToUpper(tags[j-1]) != "NOT") col.Nullable = (strings.ToUpper(tags[j-1]) != "NOT")
/*case strings.HasPrefix(k, "AUTOINCR(") && strings.HasSuffix(k, ")"):
col.IsAutoIncrement = true
autoStart := k[len("AUTOINCR")+1 : len(k)-1]
autoStartInt, err := strconv.Atoi(autoStart)
if err != nil {
engine.LogError(err)
}
col.AutoIncrStart = autoStartInt*/
case k == "AUTOINCR": case k == "AUTOINCR":
col.IsAutoIncrement = true col.IsAutoIncrement = true
//col.AutoIncrStart = 1
case k == "DEFAULT": case k == "DEFAULT":
col.Default = tags[j+1] col.Default = tags[j+1]
case k == "CREATED": case k == "CREATED":
@ -533,10 +544,19 @@ func (engine *Engine) mapType(t reflect.Type) *Table {
col.SQLType = SQLType{fs[0], 0, 0} col.SQLType = SQLType{fs[0], 0, 0}
fs2 := strings.Split(fs[1][0:len(fs[1])-1], ",") fs2 := strings.Split(fs[1][0:len(fs[1])-1], ",")
if len(fs2) == 2 { if len(fs2) == 2 {
col.Length, _ = strconv.Atoi(fs2[0]) col.Length, err = strconv.Atoi(fs2[0])
col.Length2, _ = strconv.Atoi(fs2[1]) if err != nil {
engine.LogError(err)
}
col.Length2, err = strconv.Atoi(fs2[1])
if err != nil {
engine.LogError(err)
}
} else if len(fs2) == 1 { } else if len(fs2) == 1 {
col.Length, _ = strconv.Atoi(fs2[0]) col.Length, err = strconv.Atoi(fs2[0])
if err != nil {
engine.LogError(err)
}
} }
} else { } else {
if _, ok := sqlTypes[k]; ok { if _, ok := sqlTypes[k]; ok {