From 9c63b18f9770fe1ffc95f1fa0d7524b1473ec992 Mon Sep 17 00:00:00 2001
From: "bell@sanja.is.com.ua" <>
Date: Fri, 3 Jan 2003 17:08:00 +0200
Subject: [PATCH] fixed do with subselects

---
 mysql-test/r/subselect.result | 11 ++++++++++-
 mysql-test/t/subselect.test   | 10 +++++++++-
 sql/sql_parse.cc              |  9 ++++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 7dc03a3187..38a8e0368c 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -841,4 +841,13 @@ ROW(1, 1, 'a') IN (select b,a,c from t where c='b' or c='a')
 1
 select ROW(1, 1, 'a') IN (select b,a,c from t limit 2);
 This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
-drop table if exists t;
+drop table t;
+create table t (a int);
+insert into t values (1);
+do @a:=(SELECT a from t);
+select @a;
+@a
+1
+drop table t;
+do (SELECT a from t);
+Table 'test.t' doesn't exist
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index ba9491125a..de07df1905 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -462,4 +462,12 @@ select ROW(1, 2, 'a') IN (select a,b,c from t where c='b' or c='a');
 select ROW(1, 1, 'a') IN (select b,a,c from t where c='b' or c='a');
 -- error 1235
 select ROW(1, 1, 'a') IN (select b,a,c from t limit 2);
-drop table if exists t;
+drop table t;
+
+create table t (a int);
+insert into t values (1);
+do @a:=(SELECT a from t);
+select @a;
+drop table t;
+-- error 1146
+do (SELECT a from t);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c0b33153da..ac18b65e8c 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1598,7 +1598,14 @@ mysql_execute_command(THD *thd)
     break;
   }
   case SQLCOM_DO:
-    res=mysql_do(thd, *lex->insert_list);
+    if (tables && ((res= check_table_access(thd, SELECT_ACL, tables)) ||
+		   (res= open_and_lock_tables(thd,tables))))
+	break;
+
+    fix_tables_pointers(lex->all_selects_list);
+    res= mysql_do(thd, *lex->insert_list);
+    if (thd->net.report_error)
+      res= -1;
     break;
 
   case SQLCOM_EMPTY_QUERY:
-- 
2.30.9