Remove duplicated code (#1588)
Remove duplicated code Reviewed-on: https://gitea.com/xorm/xorm/pulls/1588
This commit is contained in:
parent
188da20272
commit
67cf42799c
|
@ -137,7 +137,6 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
|
|||
}
|
||||
// --
|
||||
|
||||
if i == 0 {
|
||||
for _, col := range table.Columns() {
|
||||
ptrFieldValue, err := col.ValueOfV(&vv)
|
||||
if err != nil {
|
||||
|
@ -183,60 +182,13 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
|
|||
args = append(args, arg)
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
colNames = append(colNames, col.Name)
|
||||
cols = append(cols, col)
|
||||
}
|
||||
colPlaces = append(colPlaces, "?")
|
||||
}
|
||||
} else {
|
||||
for _, col := range cols {
|
||||
ptrFieldValue, err := col.ValueOfV(&vv)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
fieldValue := *ptrFieldValue
|
||||
|
||||
if col.IsAutoIncrement && utils.IsZero(fieldValue.Interface()) {
|
||||
continue
|
||||
}
|
||||
if col.MapType == schemas.ONLYFROMDB {
|
||||
continue
|
||||
}
|
||||
if col.IsDeleted {
|
||||
continue
|
||||
}
|
||||
if session.statement.OmitColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
if len(session.statement.ColumnMap) > 0 && !session.statement.ColumnMap.Contain(col.Name) {
|
||||
continue
|
||||
}
|
||||
if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime {
|
||||
val, t := session.engine.nowTime(col)
|
||||
args = append(args, val)
|
||||
|
||||
var colName = col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnTime(bean, col, t)
|
||||
})
|
||||
} else if col.IsVersion && session.statement.CheckVersion {
|
||||
args = append(args, 1)
|
||||
var colName = col.Name
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
col := table.GetColumn(colName)
|
||||
setColumnInt(bean, col, 1)
|
||||
})
|
||||
} else {
|
||||
arg, err := session.statement.Value2Interface(col, fieldValue)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
|
||||
colPlaces = append(colPlaces, "?")
|
||||
}
|
||||
}
|
||||
colMultiPlaces = append(colMultiPlaces, strings.Join(colPlaces, ", "))
|
||||
}
|
||||
cleanupProcessorsClosures(&session.beforeClosures)
|
||||
|
|
Loading…
Reference in New Issue