(ctx *sql.Context, s sql.Schema, formatCodes []int16)
| 496 | } |
| 497 | |
| 498 | func schemaToFieldDescriptions(ctx *sql.Context, s sql.Schema, formatCodes []int16) ([]pgproto3.FieldDescription, error) { |
| 499 | var err error |
| 500 | formatCodes, err = extendFormatCodes(len(s), formatCodes) |
| 501 | if err != nil { |
| 502 | return nil, err |
| 503 | } |
| 504 | |
| 505 | fields := make([]pgproto3.FieldDescription, len(s)) |
| 506 | for i, c := range s { |
| 507 | var oid uint32 |
| 508 | var typmod = int32(-1) |
| 509 | |
| 510 | var err error |
| 511 | colName := c.Name |
| 512 | // Translate the internal sentinel aliases set by nodeSelectExprs for unaliased string |
| 513 | // literals back to Postgres's ?column? placeholder. |
| 514 | if strings.HasPrefix(colName, ast.UnknownColSentinelPrefix) { |
| 515 | colName = "?column?" |
| 516 | } |
| 517 | dataTypeSize := int16(c.Type.MaxTextResponseByteLength(ctx)) |
| 518 | tableAttributeNumber := uint16(i + 1) // TODO: this should be based on the actual table field index, not the return schema |
| 519 | if doltgresType, ok := c.Type.(*pgtypes.DoltgresType); ok { |
| 520 | if doltgresType.ID == pgtypes.Unknown.ID { |
| 521 | // The `unknown` type is always converted to `text` on output since they're binary coercible. |
| 522 | // No function or column returns `unknown`, so this is always a raw string literal from the query. |
| 523 | // Column naming (alias vs ?column?) is handled in nodeSelectExprs; preserve whatever name |
| 524 | // was set there. |
| 525 | doltgresType = pgtypes.Text |
| 526 | dataTypeSize = int16(doltgresType.MaxTextResponseByteLength(ctx)) |
| 527 | tableAttributeNumber = 0 |
| 528 | } |
| 529 | if doltgresType.TypType == pgtypes.TypeType_Domain { |
| 530 | oid = id.Cache().ToOID(doltgresType.BaseTypeType.ID.AsId()) |
| 531 | } else { |
| 532 | oid = id.Cache().ToOID(doltgresType.ID.AsId()) |
| 533 | } |
| 534 | typmod = doltgresType.GetAttTypMod() // pg_attribute.atttypmod |
| 535 | } else { |
| 536 | oid, err = VitessTypeToObjectID(c.Type) |
| 537 | if err != nil { |
| 538 | panic(err) |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | fields[i] = pgproto3.FieldDescription{ |
| 543 | Name: []byte(colName), |
| 544 | TableOID: uint32(0), |
| 545 | TableAttributeNumber: tableAttributeNumber, |
| 546 | DataTypeOID: oid, |
| 547 | DataTypeSize: dataTypeSize, |
| 548 | TypeModifier: typmod, |
| 549 | Format: formatCodes[i], |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | return fields, nil |
| 554 | } |
| 555 |
no test coverage detected