summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2020-11-30 15:19:25 +0300
committerSergei Petrunia <psergey@askmonty.org>2020-11-30 15:19:25 +0300
commit111963477b5ed57b00d347424d7a4d479c044c64 (patch)
tree7f8ab43c1d817a76d3c62745325e40cde69242aa
parente34e53b554e8c3e05e3bd918204cf7ba494b1ae3 (diff)
downloadmariadb-git-111963477b5ed57b00d347424d7a4d479c044c64.tar.gz
Make LEX::print support single-table DELETE.
-rw-r--r--sql/sql_lex.cc41
1 files changed, 39 insertions, 2 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index ce3bf902931..dc5449d0ab4 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3567,8 +3567,10 @@ void LEX::print(String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN("UPDATE "));
if (ignore)
str->append(STRING_WITH_LEN("IGNORE "));
- // table name
- str->append(query_tables->alias);
+ // table name. If the query was using a view, we need
+ // the underlying table name, not the view name
+ TABLE_LIST *base_tbl= query_tables->table->pos_in_table_list;
+ base_tbl->print(thd, table_map(0), str, query_type);
str->append(STRING_WITH_LEN(" SET "));
// print item assignments
List_iterator<Item> it(sel->item_list);
@@ -3608,6 +3610,41 @@ void LEX::print(String *str, enum_query_type query_type)
sel->select_limit->print(str, query_type);
}
}
+ else if (sql_command == SQLCOM_DELETE)
+ {
+ SELECT_LEX *sel= first_select_lex();
+ str->append(STRING_WITH_LEN("DELETE "));
+ if (ignore)
+ str->append(STRING_WITH_LEN("IGNORE "));
+
+ str->append(STRING_WITH_LEN("FROM "));
+ // table name. If the query was using a view, we need
+ // the underlying table name, not the view name
+ TABLE_LIST *base_tbl= query_tables->table->pos_in_table_list;
+ base_tbl->print(thd, table_map(0), str, query_type);
+
+ if (sel->where)
+ {
+ str->append(STRING_WITH_LEN(" WHERE "));
+ sel->where->print(str, query_type);
+ }
+
+ if (sel->order_list.elements)
+ {
+ str->append(STRING_WITH_LEN(" ORDER BY "));
+ for (ORDER *ord= sel->order_list.first; ord; ord= ord->next)
+ {
+ if (ord != sel->order_list.first)
+ str->append(STRING_WITH_LEN(", "));
+ (*ord->item)->print(str, query_type);
+ }
+ }
+ if (sel->select_limit)
+ {
+ str->append(STRING_WITH_LEN(" LIMIT "));
+ sel->select_limit->print(str, query_type);
+ }
+ }
else
DBUG_ASSERT(0); // Not implemented yet
}