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