ArrToString is used for array_out function. |trimBool| parameter allows replacing boolean result of "true" to "t" if the function is `Type.SQL()`.
(ctx *sql.Context, arr []any, baseType *DoltgresType, trimBool bool)
| 162 | // ArrToString is used for array_out function. |trimBool| parameter allows replacing |
| 163 | // boolean result of "true" to "t" if the function is `Type.SQL()`. |
| 164 | func ArrToString(ctx *sql.Context, arr []any, baseType *DoltgresType, trimBool bool) (string, error) { |
| 165 | sb := strings.Builder{} |
| 166 | sb.WriteRune('{') |
| 167 | for i, v := range arr { |
| 168 | if i > 0 { |
| 169 | sb.WriteString(",") |
| 170 | } |
| 171 | if v != nil { |
| 172 | str, err := baseType.IoOutput(ctx, v) |
| 173 | if err != nil { |
| 174 | return "", err |
| 175 | } |
| 176 | if baseType.ID == Bool.ID && trimBool { |
| 177 | str = string(str[0]) |
| 178 | } |
| 179 | sb.WriteString(quoteString(str)) |
| 180 | } else { |
| 181 | sb.WriteString("NULL") |
| 182 | } |
| 183 | } |
| 184 | sb.WriteRune('}') |
| 185 | return sb.String(), nil |
| 186 | } |
| 187 | |
| 188 | // RecordToString is used for the record_out function, to serialize record values for wire transfer. |
| 189 | // |fields| contains the values to serialize. |
no test coverage detected