(ctx *FmtCtx)
| 32 | ) |
| 33 | |
| 34 | func (d *DTuple) pgwireFormat(ctx *FmtCtx) { |
| 35 | // When converting a tuple to text in "postgres mode" there is |
| 36 | // special behavior: values are printed in "postgres mode" then the |
| 37 | // result string itself is rendered in "postgres mode". |
| 38 | // Immediate NULL tuple elements are printed as the empty string. |
| 39 | // |
| 40 | // In this last conversion, for *tuples* the special double quote |
| 41 | // and backslash characters are *doubled* (not escaped). Other |
| 42 | // special characters from C like \t \n etc are not escaped and |
| 43 | // instead printed as-is. Only non-valid characters get escaped to |
| 44 | // hex. So we delegate this formatting to a tuple-specific |
| 45 | // string printer called pgwireFormatStringInTuple(). |
| 46 | ctx.WriteByte('(') |
| 47 | comma := "" |
| 48 | for _, v := range d.D { |
| 49 | ctx.WriteString(comma) |
| 50 | switch dv := UnwrapDatum(v).(type) { |
| 51 | case NullLiteral: |
| 52 | case *DString: |
| 53 | pgwireFormatStringInTuple(&ctx.Buffer, string(*dv)) |
| 54 | case *DCollatedString: |
| 55 | pgwireFormatStringInTuple(&ctx.Buffer, dv.Contents) |
| 56 | // Bytes cannot use the default case because they will be incorrectly |
| 57 | // double escaped. |
| 58 | case *DBytes: |
| 59 | ctx.FormatNode(dv) |
| 60 | case *DJSON: |
| 61 | var buf bytes.Buffer |
| 62 | dv.JSON.Format(&buf) |
| 63 | pgwireFormatStringInTuple(&ctx.Buffer, buf.String()) |
| 64 | default: |
| 65 | s := AsStringWithFlags(v, ctx.flags) |
| 66 | pgwireFormatStringInTuple(&ctx.Buffer, s) |
| 67 | } |
| 68 | comma = "," |
| 69 | } |
| 70 | ctx.WriteByte(')') |
| 71 | } |
| 72 | |
| 73 | func pgwireFormatStringInTuple(buf *bytes.Buffer, in string) { |
| 74 | quote := pgwireQuoteStringInTuple(in) |
no test coverage detected