TODO(Ziyi): Move the printing logic under each printer and each printer should expose a unified `print` interface.
| 1076 | // TODO(Ziyi): Move the printing logic under each printer and each printer should expose a unified |
| 1077 | // `print` interface. |
| 1078 | void EmbeddedShell::printExecutionResult(QueryResult& queryResult) const { |
| 1079 | auto querySummary = queryResult.getQuerySummary(); |
| 1080 | if (querySummary->isExplain()) { |
| 1081 | printf("%s", queryResult.getNext()->toString().c_str()); |
| 1082 | return; |
| 1083 | } |
| 1084 | if (PrinterTypeUtils::isTableType(printer->printType)) { |
| 1085 | printTruncatedExecutionResult(queryResult); |
| 1086 | return; |
| 1087 | } |
| 1088 | std::string printString = ""; |
| 1089 | if (printer->printType == PrinterType::JSON || printer->printType == PrinterType::JSONLINES) { |
| 1090 | printString = printJsonExecutionResult(queryResult); |
| 1091 | } else if (printer->printType == PrinterType::HTML) { |
| 1092 | printString = printHtmlExecutionResult(queryResult); |
| 1093 | } else if (printer->printType == PrinterType::LATEX) { |
| 1094 | printString = printLatexExecutionResult(queryResult); |
| 1095 | } else if (printer->printType == PrinterType::LINE) { |
| 1096 | printString = printLineExecutionResult(queryResult); |
| 1097 | } else if (printer->printType != PrinterType::TRASH) { |
| 1098 | for (auto i = 0u; i < queryResult.getNumColumns(); i++) { |
| 1099 | printString += |
| 1100 | escapeCsvString(queryResult.getColumnNames()[i], printer->TupleDelimiter); |
| 1101 | if (i != queryResult.getNumColumns() - 1) { |
| 1102 | printString += printer->TupleDelimiter; |
| 1103 | } |
| 1104 | } |
| 1105 | printString += "\n"; |
| 1106 | while (queryResult.hasNext()) { |
| 1107 | if (printInterrupted) { |
| 1108 | return; |
| 1109 | } |
| 1110 | auto tuple = queryResult.getNext(); |
| 1111 | for (auto i = 0u; i < queryResult.getNumColumns(); i++) { |
| 1112 | std::string field = tuple->getValue(i)->toString(); |
| 1113 | printString += escapeCsvString(field, printer->TupleDelimiter); |
| 1114 | if (i != queryResult.getNumColumns() - 1) { |
| 1115 | printString += printer->TupleDelimiter; |
| 1116 | } |
| 1117 | } |
| 1118 | printString += "\n"; |
| 1119 | } |
| 1120 | } |
| 1121 | if (!printInterrupted) { |
| 1122 | printf("%s", printString.c_str()); |
| 1123 | } |
| 1124 | if (stats && !printInterrupted) { |
| 1125 | if (queryResult.getNumTuples() == 1) { |
| 1126 | printf("(1 tuple)\n"); |
| 1127 | } else { |
| 1128 | printf("(%" PRIu64 " tuples)\n", queryResult.getNumTuples()); |
| 1129 | } |
| 1130 | if (queryResult.getNumColumns() == 1) { |
| 1131 | printf("(1 column)\n"); |
| 1132 | } else { |
| 1133 | printf("(%" PRIu64 " columns)\n", static_cast<uint64_t>(queryResult.getNumColumns())); |
| 1134 | } |
| 1135 | printf("Time: %.2fms (compiling), %.2fms (executing)\n", querySummary->getCompilingTime(), |
nothing calls this directly
no test coverage detected