| 1226 | } |
| 1227 | |
| 1228 | void RenderRow(PrintStream &out, ResultMetadata &result, RowData &row) override { |
| 1229 | if (row.row_index > 0) { |
| 1230 | if (json_array) { |
| 1231 | // wrap all JSON objects in an array |
| 1232 | out.Print(","); |
| 1233 | } |
| 1234 | out.Print("\n"); |
| 1235 | } |
| 1236 | out.Print("{"); |
| 1237 | auto &data = row.data; |
| 1238 | auto &is_null = row.is_null; |
| 1239 | auto &types = result.types; |
| 1240 | auto &col_names = result.column_names; |
| 1241 | for (idx_t i = 0; i < col_names.size(); i++) { |
| 1242 | if (i > 0) { |
| 1243 | out.Print(","); |
| 1244 | } |
| 1245 | out.Print(EscapeJSONString(col_names[i])); |
| 1246 | out.Print(":"); |
| 1247 | if (is_null[i]) { |
| 1248 | out.Print("null"); |
| 1249 | } else if (types[i].IsNested() || types[i].IsJSONType()) { |
| 1250 | // nested types have already been converted to the correct JSON format |
| 1251 | out.Print(data[i]); |
| 1252 | } else if (!RequiresQuotes(types[i])) { |
| 1253 | // for numeric types emit the data directly without quoting |
| 1254 | out.Print(data[i]); |
| 1255 | } else { |
| 1256 | // not a nested type - escape here |
| 1257 | out.Print(EscapeJSONString(data[i].GetString())); |
| 1258 | } |
| 1259 | } |
| 1260 | out.Print("}"); |
| 1261 | } |
| 1262 | |
| 1263 | string EscapeJSONString(const string &str) { |
| 1264 | string result = "\""; |
nothing calls this directly
no test coverage detected