List:Commits« Previous MessageNext Message »
From:rburnett Date:January 23 2007 10:33pm
Subject:Connector/NET commit: r566 - in branches/5.0: . Driver/Source TestSuite
View as plain text  
Modified:
   branches/5.0/CHANGES
   branches/5.0/Driver/Source/Statement.cs
   branches/5.0/Driver/Source/command.cs
   branches/5.0/TestSuite/StoredProcedure.cs
Log:
Bug #25609 MySqlDataAdapter.FillSchema 

Fixed this by moving the modification to SQL_SELECT_LIMIT past the sproc resolution.

Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES	2007-01-23 17:13:31 UTC (rev 565)
+++ branches/5.0/CHANGES	2007-01-23 21:33:39 UTC (rev 566)
@@ -9,6 +9,7 @@
   Bug #25458 Opening connection hangs 
   Bug #25651 SELECT does not work properly when WHERE contains UTF-8 characters   
   Bug #25726 MySqlConnection throws NullReferenceException and ArgumentNullException 
+  Bug #25609 MySqlDataAdapter.FillSchema 
   
   Other changes
   -------------

Modified: branches/5.0/Driver/Source/Statement.cs
===================================================================
--- branches/5.0/Driver/Source/Statement.cs	2007-01-23 17:13:31 UTC (rev 565)
+++ branches/5.0/Driver/Source/Statement.cs	2007-01-23 21:33:39 UTC (rev 566)
@@ -32,6 +32,8 @@
         protected string commandText;
         private ArrayList buffers;
         protected MySqlParameterCollection parameters;
+        protected string preCommand;
+        protected string postCommand;
 
         private Statement(MySqlConnection connection)
         {
@@ -45,15 +47,45 @@
             commandText = text;
         }
 
+        #region Properties
+
         public virtual string ProcessedCommandText
         {
             get { return commandText; }
         }
 
+        public string PreCommand
+        {
+            get { return preCommand; }
+            set { preCommand = value; }
+        }
+
+        public string PostCommand
+        {
+            get { return postCommand; }
+            set { postCommand = value; }
+        }
+
+        #endregion
+
         public virtual void Close()
         {
         }
 
+        private string GetCommandText()
+        {
+            StringBuilder sb = new StringBuilder(PreCommand);
+            if (sb.Length > 0)
+                sb.Append(";");
+            sb.Append(ProcessedCommandText);
+            if (PostCommand != null)
+            {
+                sb.Append(";");
+                sb.Append(PostCommand);
+            }
+            return sb.ToString();
+        }
+
         public virtual void Execute(MySqlParameterCollection parameters)
         {
             this.parameters = parameters;
@@ -77,7 +109,7 @@
         protected virtual void BindParameters()
         {
             // tokenize the sql
-            ArrayList tokenArray = TokenizeSql(ProcessedCommandText);
+            ArrayList tokenArray = TokenizeSql(GetCommandText());
 
             MySqlStream stream = new MySqlStream(driver.Encoding);
             stream.Version = driver.Version;

Modified: branches/5.0/Driver/Source/command.cs
===================================================================
--- branches/5.0/Driver/Source/command.cs	2007-01-23 17:13:31 UTC (rev 565)
+++ branches/5.0/Driver/Source/command.cs	2007-01-23 21:33:39 UTC (rev 566)
@@ -309,7 +309,7 @@
 		{
 			if (statement != null)
 				statement.Close();
-		}
+        }
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/ExecuteReader/*'/>
 		public new MySqlDataReader ExecuteReader()
@@ -342,17 +342,6 @@
 
 			string sql = TrimSemicolons(cmdText);
 
-			//TODO: make these work with prepared statements and stored procedures
-			if (0 != (behavior & CommandBehavior.SchemaOnly))
-			{
-				sql = String.Format("SET SQL_SELECT_LIMIT=0;{0};SET sql_select_limit=-1;", sql);
-			}
-
-			if (0 != (behavior & CommandBehavior.SingleRow))
-			{
-				sql = String.Format("SET SQL_SELECT_LIMIT=1;{0};SET sql_select_limit=-1;", sql);
-			}
-
 			if (statement == null || !statement.IsPrepared)
 			{
 				if (CommandType == CommandType.StoredProcedure)
@@ -361,6 +350,19 @@
 					statement = new PreparableStatement(this.Connection, sql);
 			}
 
+            // if we are asked to provide only schema or single row resultsets, then
+            // set SQL_SELECT_LIMIT to optimize the process
+            if (0 != (behavior & CommandBehavior.SchemaOnly))
+            {
+                statement.PreCommand = "SET SQL_SELECT_LIMIT=0";
+                statement.PostCommand = "SET SQL_SELECT_LIMIT=-1";
+            }
+            else if (0 != (behavior & CommandBehavior.SingleRow))
+            {
+                statement.PreCommand = "SET SQL_SELECT_LIMIT=1";
+                statement.PostCommand = "SET SQL_SELECT_LIMIT=-1";
+            }
+
 			updatedRowCount = -1;
 
             try

Modified: branches/5.0/TestSuite/StoredProcedure.cs
===================================================================
--- branches/5.0/TestSuite/StoredProcedure.cs	2007-01-23 17:13:31 UTC (rev 565)
+++ branches/5.0/TestSuite/StoredProcedure.cs	2007-01-23 21:33:39 UTC (rev 566)
@@ -1074,5 +1074,30 @@
                 Assert.Fail(ex.Message);
             }
         }
+
+        /// <summary>
+        /// Bug #25609 MySqlDataAdapter.FillSchema 
+        /// </summary>
+        [Test]
+        public void GetSchema()
+        {
+            try
+            {
+                execSQL("CREATE PROCEDURE spTest() BEGIN SELECT * FROM test; END");
+
+                MySqlCommand cmd = new MySqlCommand("spTest", conn);
+                cmd.CommandType = CommandType.StoredProcedure;
+                cmd.CommandTimeout = 0;
+                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
+                DataTable schema = new DataTable();
+                da.FillSchema(schema, SchemaType.Source);
+                Assert.AreEqual(2, schema.Columns.Count);
+            }
+            catch (Exception ex)
+            {
+                Assert.Fail(ex.Message);
+            }
+        }
+
 	}
 }

Thread
Connector/NET commit: r566 - in branches/5.0: . Driver/Source TestSuiterburnett23 Jan