summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.local>2006-12-01 13:25:06 +0300
committerunknown <kostja@bodhi.local>2006-12-01 13:25:06 +0300
commitfe84b016e1fd62d92c9f13a1e21784ea8cb200cd (patch)
treef5e6ea500cc0b8162cc8b977ac2c888fceea2f6d /sql
parent4ec847218dca3fa31d6b7d61fffdf71c444c1c74 (diff)
downloadmariadb-git-fe84b016e1fd62d92c9f13a1e21784ea8cb200cd.tar.gz
A fix and a test case for Bug#24179 "select b into $var" fails with
--cursor_protocol": fix a misleading error message in case of SELECT .. INTO. sql/sql_class.cc: Implement select_result::check_simple_select hierarchy to support correct error messages in case of SELECT .. INTO and C API cursors. sql/sql_class.h: Set the error message inside the function that checks for the error condition (simple_select, renamed to check_simple_select). sql/sql_prepare.cc: Use a new method that now sets the error. tests/mysql_client_test.c: Add a test case for Bug#24179 "select b into $var" fails with --cursor_protocol" (check for the right error message and error code).
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_class.cc14
-rw-r--r--sql/sql_class.h12
-rw-r--r--sql/sql_prepare.cc3
3 files changed, 25 insertions, 4 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index d2f1e9ed0d9..f46cd2353eb 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -885,6 +885,13 @@ void select_result::cleanup()
/* do nothing */
}
+bool select_result::check_simple_select() const
+{
+ my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0));
+ return TRUE;
+}
+
+
static String default_line_term("\n",default_charset_info);
static String default_escaped("\\",default_charset_info);
static String default_field_term("\t",default_charset_info);
@@ -1553,6 +1560,13 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
}
+bool select_dumpvar::check_simple_select() const
+{
+ my_error(ER_SP_BAD_CURSOR_SELECT, MYF(0));
+ return TRUE;
+}
+
+
void select_dumpvar::cleanup()
{
vars.empty();
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 41845dc5c76..ec03b9cb4a6 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1724,7 +1724,14 @@ public:
virtual bool initialize_tables (JOIN *join=0) { return 0; }
virtual void send_error(uint errcode,const char *err);
virtual bool send_eof()=0;
- virtual bool simple_select() { return 0; }
+ /**
+ Check if this query returns a result set and therefore is allowed in
+ cursors and set an error message if it is not the case.
+
+ @retval FALSE success
+ @retval TRUE error, an error message is set
+ */
+ virtual bool check_simple_select() const;
virtual void abort() {}
/*
Cleanup instance of this class for next execution of a prepared
@@ -1762,7 +1769,7 @@ public:
bool send_fields(List<Item> &list, uint flags);
bool send_data(List<Item> &items);
bool send_eof();
- bool simple_select() { return 1; }
+ virtual bool check_simple_select() const { return FALSE; }
void abort();
};
@@ -2202,6 +2209,7 @@ public:
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
bool send_data(List<Item> &items);
bool send_eof();
+ virtual bool check_simple_select() const;
void cleanup();
};
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 1e7601c0951..8b2c2cd3674 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2906,10 +2906,9 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
in INSERT ... SELECT and similar commands.
*/
- if (open_cursor && lex->result && !lex->result->simple_select())
+ if (open_cursor && lex->result && lex->result->check_simple_select())
{
DBUG_PRINT("info",("Cursor asked for not SELECT stmt"));
- my_error(ER_SP_BAD_CURSOR_QUERY, MYF(0));
return TRUE;
}