package xorm import ( "reflect" "strings" "time" "github.com/lunny/xorm/core" ) var ( c_EMPTY_STRING string c_BOOL_DEFAULT bool c_BYTE_DEFAULT byte c_COMPLEX64_DEFAULT complex64 c_COMPLEX128_DEFAULT complex128 c_FLOAT32_DEFAULT float32 c_FLOAT64_DEFAULT float64 c_INT64_DEFAULT int64 c_UINT64_DEFAULT uint64 c_INT32_DEFAULT int32 c_UINT32_DEFAULT uint32 c_INT16_DEFAULT int16 c_UINT16_DEFAULT uint16 c_INT8_DEFAULT int8 c_UINT8_DEFAULT uint8 c_INT_DEFAULT int c_UINT_DEFAULT uint c_TIME_DEFAULT time.Time ) func genCols(table *core.Table, session *Session, bean interface{}, useCol bool, includeQuote bool) ([]string, []interface{}, error) { colNames := make([]string, 0) args := make([]interface{}, 0) for _, col := range table.Columns() { lColName := strings.ToLower(col.Name) if useCol && !col.IsVersion && !col.IsCreated && !col.IsUpdated { if _, ok := session.Statement.columnMap[lColName]; !ok { continue } } if col.MapType == core.ONLYFROMDB { continue } fieldValuePtr, err := col.ValueOf(bean) if err != nil { session.Engine.LogError(err) continue } fieldValue := *fieldValuePtr if col.IsAutoIncrement { switch fieldValue.Type().Kind() { case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int, reflect.Int64: if fieldValue.Int() == 0 { continue } case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint, reflect.Uint64: if fieldValue.Uint() == 0 { continue } case reflect.String: if len(fieldValue.String()) == 0 { continue } } } if session.Statement.ColumnStr != "" { if _, ok := session.Statement.columnMap[lColName]; !ok { continue } } if session.Statement.OmitStr != "" { if _, ok := session.Statement.columnMap[lColName]; ok { continue } } if (col.IsCreated || col.IsUpdated) && session.Statement.UseAutoTime { args = append(args, time.Now()) } else if col.IsVersion && session.Statement.checkVersion { args = append(args, 1) } else { arg, err := session.value2Interface(col, fieldValue) if err != nil { return colNames, args, err } args = append(args, arg) } if includeQuote { colNames = append(colNames, session.Engine.Quote(col.Name)+" = ?") } else { colNames = append(colNames, col.Name) } } return colNames, args, nil }