From a5a9fcdfe44ffb093887a255254d128fe3752fd1 Mon Sep 17 00:00:00 2001 From: Monty Date: Fri, 5 Aug 2022 17:57:27 +0300 Subject: MDEV-12325 Unexpected data type and truncation when using CTE When creating a recursive CTE, the column types are taken from the non recursive part of the CTE (this is according to the SQL standard). This patch adds code to abort the CTE if the calculated values in the recursive part does not fit in the fields in the created temporary table. The new code only affects recursive CTE, so it should not cause any notable problems for old applications. Other things: - Fixed that we get correct row numbers for warnings generated with WITH RECURSIVE Reviewer: Alexander Barkov --- sql/sql_error.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sql/sql_error.h') diff --git a/sql/sql_error.h b/sql/sql_error.h index 3b29f7aba06..ec52724b6da 100644 --- a/sql/sql_error.h +++ b/sql/sql_error.h @@ -722,6 +722,13 @@ private: /** Reset the current row counter. Start counting from the first row. */ void reset_current_row_for_warning() { m_current_row_for_warning= 1; } + ulong set_current_row_for_warning(ulong row) + { + ulong old_row= m_current_row_for_warning; + m_current_row_for_warning= row; + return old_row; + } + /** Return the current counter value. */ ulong current_row_for_warning() const { return m_current_row_for_warning; } @@ -1099,6 +1106,9 @@ public: void opt_clear_warning_info(ulonglong query_id) { get_warning_info()->opt_clear(query_id); } + long set_current_row_for_warning(long row) + { return get_warning_info()->set_current_row_for_warning(row); } + ulong current_row_for_warning() const { return get_warning_info()->current_row_for_warning(); } -- cgit v1.2.1