Skip to content

Commit 3240c6c

Browse files
committed
Fix printing of ORDER BY for set operations, too
1 parent 9d87f40 commit 3240c6c

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

‎src/util/sqlhelper.cpp‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ namespace hsql {
161161
}
162162
}
163163

164+
void printOrderBy(const std::vector<OrderDescription*>* expr, uintmax_t numIndent) {
165+
if (!expr) return;
166+
for (const auto& order_description : *expr) {
167+
printExpression(order_description->expr, numIndent);
168+
if (order_description->type == kOrderAsc) {
169+
inprint("ascending", numIndent);
170+
}
171+
else {
172+
inprint("descending", numIndent);
173+
}
174+
}
175+
}
176+
164177
void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t numIndent) {
165178
inprint("SelectStatement", numIndent);
166179
inprint("Fields:", numIndent + 1);
@@ -203,9 +216,7 @@ namespace hsql {
203216

204217
if (setOperation->resultOrder != nullptr) {
205218
inprint("SetResultOrderBy:", numIndent + 1);
206-
printExpression(setOperation->resultOrder->at(0)->expr, numIndent + 2);
207-
if (setOperation->resultOrder->at(0)->type == kOrderAsc) inprint("ascending", numIndent + 2);
208-
else inprint("descending", numIndent + 2);
219+
printOrderBy(setOperation->resultOrder, numIndent + 2);
209220
}
210221

211222
if (setOperation->resultLimit != nullptr) {
@@ -224,15 +235,7 @@ namespace hsql {
224235

225236
if (stmt->order != nullptr) {
226237
inprint("OrderBy:", numIndent + 1);
227-
for (size_t idx = 0; idx < stmt->order->size(); idx++) {
228-
printExpression(stmt->order->at(idx)->expr, numIndent + 2);
229-
if (stmt->order->at(idx)->type == kOrderAsc) {
230-
inprint("ascending", numIndent + 2);
231-
}
232-
else {
233-
inprint("descending", numIndent + 2);
234-
}
235-
}
238+
printOrderBy(stmt->order, numIndent + 2);
236239
}
237240

238241
if (stmt->limit != nullptr && stmt->limit->limit != nullptr) {

‎src/util/sqlhelper.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ namespace hsql {
2424
void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t num_indent);
2525

2626
// Prints a summary of the given TransactionStatement with the given indentation.
27-
void printTransactionStatementInfo(const TransactionStatement* stmt, uintmax_t numIndent);
27+
void printTransactionStatementInfo(const TransactionStatement* stmt, uintmax_t num_indent);
2828

2929
// Prints a summary of the given Expression with the given indentation.
3030
void printExpression(Expr* expr, uintmax_t num_indent);
3131

32+
// Prints an ORDER BY clause
33+
void printOrderBy(const std::vector<OrderDescription*>* expr, uintmax_t num_indent);
34+
3235
} // namespace hsql
3336

3437
#endif

0 commit comments

Comments
 (0)