array_recv_callable is the function definition of array_recv.
(ctx *sql.Context, t [4]*pgtypes.DoltgresType, val1, val2, val3 any)
| 177 | |
| 178 | // array_recv_callable is the function definition of array_recv. |
| 179 | func array_recv_callable(ctx *sql.Context, t [4]*pgtypes.DoltgresType, val1, val2, val3 any) (any, error) { |
| 180 | data := val1.([]byte) |
| 181 | if data == nil { |
| 182 | return nil, nil |
| 183 | } |
| 184 | typeColl, err := core.GetTypesCollectionFromContext(ctx, "") |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | reader := utils.NewWireReader(data) |
| 189 | dimensions := reader.ReadInt32() |
| 190 | _ = reader.ReadInt32() // Whether the array has a null, doesn't seem useful |
| 191 | baseTypeID := id.Type(id.Cache().ToInternal(reader.ReadUint32())) |
| 192 | baseType, err := typeColl.GetType(ctx, baseTypeID) |
| 193 | if err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | if baseType == nil { |
| 197 | return nil, pgtypes.ErrTypeDoesNotExist.New(baseTypeID.TypeName()) |
| 198 | } |
| 199 | // TODO: handle more than 1 dimension |
| 200 | if dimensions > 1 { |
| 201 | return nil, errors.Errorf("array dimensions greater than 1 are not yet supported") |
| 202 | } |
| 203 | var vals []any |
| 204 | for dimensionIdx := int32(0); dimensionIdx < dimensions; dimensionIdx++ { |
| 205 | elementsCount := reader.ReadInt32() |
| 206 | _ = reader.ReadInt32() // Lower bound, not sure what to do with this |
| 207 | for i := int32(0); i < elementsCount; i++ { |
| 208 | elementLen := reader.ReadInt32() |
| 209 | if elementLen != -1 { |
| 210 | valBytes := reader.ReadBytes(uint32(elementLen)) |
| 211 | val, err := baseType.CallReceive(ctx, valBytes) |
| 212 | if err != nil { |
| 213 | return nil, err |
| 214 | } |
| 215 | vals = append(vals, val) |
| 216 | } else { |
| 217 | vals = append(vals, nil) |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | return vals, nil |
| 222 | } |
| 223 | |
| 224 | // array_send represents the PostgreSQL function of array type IO send. |
| 225 | var array_send = framework.Function1{ |
nothing calls this directly
no test coverage detected