List:Internals« Previous MessageNext Message »
From:rburnett Date:November 16 2005 4:38pm
Subject:Connector/NET commit: r198 - in branches/1.0: . TestSuite mysqlclient
View as plain text  
Modified:
   branches/1.0/CHANGES
   branches/1.0/TestSuite/CommandBuilderTests.cs
   branches/1.0/mysqlclient/command.cs
   branches/1.0/mysqlclient/parameter.cs
Log:
Bug #14631 "#42000Query was empty" [fixed]. 
This was fixed by trimming semicolons from the beginning and end of all queries when they are issued.

This patch also contains some refactoring of the PS code.


Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES	2005-11-16 14:59:51 UTC (rev 197)
+++ branches/1.0/CHANGES	2005-11-16 16:38:39 UTC (rev 198)
@@ -12,6 +12,7 @@
 	Bug #11386 Numeric parameters with Precision and Scale not taken into account by Connector [added test case]
 	Bug #6902  Errors in parsing stored procedure parameters [fixed before, refixed]
 	Bug #13927 Multiple Records to same Table in Transaction Problem [fixed]
+	Bug #14631 "#42000Query was empty" [fixed]
 	
 	Other changes
 	-------------------------    

Modified: branches/1.0/TestSuite/CommandBuilderTests.cs
===================================================================
--- branches/1.0/TestSuite/CommandBuilderTests.cs	2005-11-16 14:59:51 UTC (rev 197)
+++ branches/1.0/TestSuite/CommandBuilderTests.cs	2005-11-16 16:38:39 UTC (rev 198)
@@ -207,5 +207,27 @@
 			da.Update(dt);
 		}
 
+		/// <summary>
+		/// Bug #14631  	"#42000Query was empty"
+		/// </summary>
+		[Test]
+		public void SemicolonAtEndOfSQL()
+		{
+			execSQL("DROP TABLE IF EXISTS test");
+			execSQL("CREATE TABLE test (id INT NOT NULL, name VARCHAR(100), PRIMARY KEY(id))");
+			execSQL("INSERT INTO test VALUES(1, 'Data')");
+
+			MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test;", conn);
+			MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
+			DataTable dt = new DataTable();
+			da.Fill(dt);
+			dt.Rows[0]["id"] = 2;
+			da.Update(dt);
+
+			dt.Clear();
+			da.Fill(dt);
+			Assert.AreEqual(1, dt.Rows.Count);
+			Assert.AreEqual(2, dt.Rows[0]["id"]);
+		}
 	}
 }

Modified: branches/1.0/mysqlclient/command.cs
===================================================================
--- branches/1.0/mysqlclient/command.cs	2005-11-16 14:59:51 UTC (rev 197)
+++ branches/1.0/mysqlclient/command.cs	2005-11-16 16:38:39 UTC (rev 198)
@@ -382,16 +382,16 @@
 		{
 			CheckState();
 
-			string sql = cmdText;
+			string sql = TrimSemicolons(cmdText);
 
 			if (0 != (behavior & CommandBehavior.SchemaOnly))
 			{
-				sql = "SET SQL_SELECT_LIMIT=0;" + cmdText + ";SET sql_select_limit=-1";
+				sql = "SET SQL_SELECT_LIMIT=0;" + sql + ";SET sql_select_limit=-1";
 			}
 
 			if (0 != (behavior & CommandBehavior.SingleRow))
 			{
-				sql = "SET SQL_SELECT_LIMIT=1;" + cmdText + ";SET sql_select_limit=-1";
+				sql = "SET SQL_SELECT_LIMIT=1;" + sql + ";SET sql_select_limit=-1";
 			}
 
 			updateCount = -1;
@@ -435,16 +435,37 @@
 				return;
 
 			// strip out names from parameter markers
-			string strippedSQL = PrepareCommandText();
+			string psSQL = CommandText;
 
+			if (CommandType == CommandType.StoredProcedure)
+			{
+				if (storedProcedure == null)
+					storedProcedure = new StoredProcedure(connection);
+				psSQL = storedProcedure.Prepare(this);
+			}
+			psSQL = PrepareCommandText(psSQL);
+
 			// ask our connection to send the prepare command
-			preparedStatement = connection.driver.Prepare( strippedSQL, (string[])parameterMap.ToArray(typeof(string)) );
+			preparedStatement = connection.driver.Prepare(psSQL, (string[])parameterMap.ToArray(typeof(string)));
 		}
 		#endregion
 
 
 		#region Private Methods
 
+		private string TrimSemicolons(string sql)
+		{
+			System.Text.StringBuilder sb = new System.Text.StringBuilder(sql);
+			int start = 0;
+			while (sb[start] == ';')
+				start++;
+
+			int end = sb.Length-1;
+			while (sb[end] == ';')
+				end--;
+			return sb.ToString(start, end-start+1);
+		}
+
 		/// <summary>
 		/// Serializes the given parameter to the given memory stream
 		/// </summary>
@@ -545,12 +566,12 @@
 		/// the parameterMap array list that includes all the paramter names in the
 		/// order they appeared in the SQL
 		/// </remarks>
-		private string PrepareCommandText()
+		private string PrepareCommandText(string text)
 		{
 			StringBuilder	newSQL = new StringBuilder();
 
 			// tokenize the sql first
-			ArrayList tokens = TokenizeSql( CommandText );
+			ArrayList tokens = TokenizeSql(text);
 			parameterMap.Clear();
 
 			foreach (string token in tokens)

Modified: branches/1.0/mysqlclient/parameter.cs
===================================================================
--- branches/1.0/mysqlclient/parameter.cs	2005-11-16 14:59:51 UTC (rev 197)
+++ branches/1.0/mysqlclient/parameter.cs	2005-11-16 16:38:39 UTC (rev 198)
@@ -315,6 +315,14 @@
 			return valueObject;
 		}
 
+		internal MySqlDbType GetPSType()
+		{
+			if (this.mySqlDbType == MySqlDbType.Bit)
+				return MySqlDbType.Byte;//UInt64;
+			else
+				return this.mySqlDbType;
+		}
+
 		internal void Serialize( PacketWriter writer, bool binary ) 
 		{
 			GetValueObject();

Thread
Connector/NET commit: r198 - in branches/1.0: . TestSuite mysqlclientrburnett16 Nov