MCPcopy Create free account
hub / github.com/duckdb/duckdb / RenderRow

Method RenderRow

tools/shell/shell_renderer.cpp:1228–1261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 = "\"";

Callers

nothing calls this directly

Calls 5

IsNestedMethod · 0.80
IsJSONTypeMethod · 0.80
PrintMethod · 0.45
sizeMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected