bitExplicit registers all explicit casts. This comprises only the source types.
(builtInCasts map[id.Cast]casts.Cast)
| 33 | |
| 34 | // bitExplicit registers all explicit casts. This comprises only the source types. |
| 35 | func bitExplicit(builtInCasts map[id.Cast]casts.Cast) { |
| 36 | bitToInt32 := id.NewCast(pgtypes.Bit.ID, pgtypes.Int32.ID) |
| 37 | builtInCasts[bitToInt32] = casts.Cast{ |
| 38 | ID: bitToInt32, |
| 39 | CastType: casts.CastType_Explicit, |
| 40 | Function: id.NullFunction, |
| 41 | BuiltIn: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) { |
| 42 | array, err := tree.ParseDBitArray(val.(string)) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | if array.BitLen() > 32 { |
| 47 | return nil, errors.Wrap(pgtypes.ErrCastOutOfRange, "integer out of range") |
| 48 | } |
| 49 | return int32(array.AsInt64(32)), nil |
| 50 | }, |
| 51 | UseInOut: false, |
| 52 | } |
| 53 | bitToInt64 := id.NewCast(pgtypes.Bit.ID, pgtypes.Int64.ID) |
| 54 | builtInCasts[bitToInt64] = casts.Cast{ |
| 55 | ID: bitToInt64, |
| 56 | CastType: casts.CastType_Explicit, |
| 57 | Function: id.NullFunction, |
| 58 | BuiltIn: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) { |
| 59 | array, err := tree.ParseDBitArray(val.(string)) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | if array.BitLen() > 64 { |
| 64 | return nil, errors.Wrap(pgtypes.ErrCastOutOfRange, "bigint out of range") |
| 65 | } |
| 66 | return array.AsInt64(64), nil |
| 67 | }, |
| 68 | UseInOut: false, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // bitImplicit registers all implicit casts. This comprises only the source types. |
| 73 | func bitImplicit(builtInCasts map[id.Cast]casts.Cast) { |
no test coverage detected