ConvertSerialized implements the val.TupleTypeHandler interface.
(ctx context.Context, other val.TupleTypeHandler, val []byte)
| 1185 | |
| 1186 | // ConvertSerialized implements the val.TupleTypeHandler interface. |
| 1187 | func (t *DoltgresType) ConvertSerialized(ctx context.Context, other val.TupleTypeHandler, val []byte) ([]byte, error) { |
| 1188 | ot, ok := other.(*DoltgresType) |
| 1189 | if !ok { |
| 1190 | if other == nil { |
| 1191 | // TODO: replace this with something much better than this hack |
| 1192 | // `other` will be nil in cases where the parent and child are mismatched (AdaptiveEncoding vs StringEnc for example) |
| 1193 | // Since we do restrict foreign keys to similar types, if the calling type is a string type, we can fairly |
| 1194 | // safely assume that the other type is also a string type. This is implemented specifically for a customer |
| 1195 | // issue, as should be replaced as soon as a real fix is found. |
| 1196 | switch t.ID.TypeName() { |
| 1197 | case "bpchar", "text", "varchar": |
| 1198 | var str string |
| 1199 | if len(val) > 0 { |
| 1200 | if val[len(val)-1] == 0 { |
| 1201 | str = string(val[:len(val)-1]) |
| 1202 | } else { |
| 1203 | str = string(val) |
| 1204 | } |
| 1205 | } |
| 1206 | return t.SerializeValue(ctx, str) |
| 1207 | } |
| 1208 | } |
| 1209 | return nil, errors.Errorf("expected DoltgresType, got %T", other) |
| 1210 | } |
| 1211 | |
| 1212 | value, err := ot.DeserializeValue(ctx, val) |
| 1213 | if err != nil { |
| 1214 | return nil, err |
| 1215 | } |
| 1216 | |
| 1217 | sqlCtx, _ := ctx.(*sql.Context) |
| 1218 | toValue, _, err := t.ConvertToType(sqlCtx, ot, value) |
| 1219 | if err != nil { |
| 1220 | return nil, err |
| 1221 | } |
| 1222 | |
| 1223 | return t.SerializeValue(ctx, toValue) |
| 1224 | } |
| 1225 | |
| 1226 | // TypeInfo implements the typeinfo.ExtendedType interface. |
| 1227 | func (t *DoltgresType) TypeInfo() typeinfo.TypeInfo { |
nothing calls this directly
no test coverage detected