List:Commits« Previous MessageNext Message »
From:rburnett Date:September 12 2008 4:13pm
Subject:Connector/NET commit: r1417 - in branches/5.2: . MySql.Web/Providers/Source MySql.Web/Tests
View as plain text  
Modified:
   branches/5.2/CHANGES
   branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs
   branches/5.2/MySql.Web/Tests/ProfileTests.cs
Log:
fixed problem with profile provider where INSERT .. ON DUPLICATE UPDATE syntax would not
work correctly with some older server versions (bug #39330).  We fixed this by using a
data adapter which will use a standard insert or update statement.


Modified: branches/5.2/CHANGES
===================================================================
--- branches/5.2/CHANGES	2008-09-12 12:22:06 UTC (rev 1416)
+++ branches/5.2/CHANGES	2008-09-12 14:13:23 UTC (rev 1417)
@@ -11,6 +11,8 @@
   values (bug #39294)  
 - fixed problem where using a stored procedure with parameters with a table adapter
   was no longer working after our parameter schema changes (bug #39252)  
+- fixed problem with profile provider where INSERT .. ON DUPLICATE UPDATE syntax would
not
+  work correctly with some older server versions (bug #39330)  
   
 Version 5.2.3 - 8/14/08
 - Increased the speed of MySqlDataReader.GetOrdinal dramatically by using a couple

Modified: branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs
===================================================================
--- branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs	2008-09-12 12:22:06 UTC
(rev 1416)
+++ branches/5.2/MySql.Web/Providers/Source/ProfileProvider.cs	2008-09-12 14:13:23 UTC
(rev 1417)
@@ -502,17 +502,28 @@
                         int userId = SchemaManager.CreateOrFetchUserId(connection,
username, 
                             applicationId, isAuthenticated);
 
-                        MySqlCommand cmd = new MySqlCommand(
-                            @"INSERT INTO my_aspnet_Profiles  
-                            VALUES (@userId, @index, @stringData, @binaryData, NULL) ON
DUPLICATE KEY UPDATE
-                            valueindex=VALUES(valueindex), stringdata=VALUES(stringdata),
-                            binarydata=VALUES(binarydata)", connection);
-                        cmd.Parameters.Clear();
-                        cmd.Parameters.AddWithValue("@userId", userId);
-                        cmd.Parameters.AddWithValue("@index", index);
-                        cmd.Parameters.AddWithValue("@stringData", stringData);
-                        cmd.Parameters.AddWithValue("@binaryData", binaryData);
-                        count = cmd.ExecuteNonQuery();
+                        MySqlDataAdapter da = new MySqlDataAdapter(
+                            "SELECT * FROM my_aspnet_Profiles WHERE userId=@id",
connection);
+                        da.SelectCommand.Parameters.AddWithValue("@id", userId);
+                        MySqlCommandBuilder cb =new MySqlCommandBuilder(da);
+                        DataTable dt = new DataTable();
+                        da.Fill(dt);
+
+                        DataRow row;
+                        if (dt.Rows.Count == 0)
+                        {
+                            row = dt.NewRow();
+                            dt.Rows.Add(row);
+                        }
+                        else
+                            row = dt.Rows[0];
+
+                        row["userId"] = userId;
+                        row["valueIndex"] = index;
+                        row["stringdata"] = stringData;
+                        row["binarydata"] = binaryData;
+
+                        count = da.Update(dt);
                         if (count == 0)
                             throw new Exception(Resources.ProfileUpdateFailed);
                         ts.Complete();

Modified: branches/5.2/MySql.Web/Tests/ProfileTests.cs
===================================================================
--- branches/5.2/MySql.Web/Tests/ProfileTests.cs	2008-09-12 12:22:06 UTC (rev 1416)
+++ branches/5.2/MySql.Web/Tests/ProfileTests.cs	2008-09-12 14:13:23 UTC (rev 1417)
@@ -110,7 +110,41 @@
             Assert.AreEqual(0, dt.Rows.Count);
         }
 
+        /// <summary>
+        /// Bug #39330	Attempt to update a previously saved Profile property failed
+        /// </summary>
         [Test]
+        public void AnonymousUserSettingAndUpdatingAnonymousProperty()
+        {
+            MySQLProfileProvider provider = InitProfileProvider();
+            SettingsContext ctx = new SettingsContext();
+            ctx.Add("IsAuthenticated", false);
+            ctx.Add("UserName", "user1");
+
+            SettingsPropertyValueCollection values = new
SettingsPropertyValueCollection();
+            SettingsProperty property1 = new SettingsProperty("color");
+            property1.PropertyType = typeof(string);
+            property1.Attributes["AllowAnonymous"] = true;
+            SettingsPropertyValue value = new SettingsPropertyValue(property1);
+            value.PropertyValue = "blue";
+            values.Add(value);
+
+            provider.SetPropertyValues(ctx, values);
+
+            SettingsPropertyCollection props = new SettingsPropertyCollection();
+            props.Add(property1);
+            values = provider.GetPropertyValues(ctx, props);
+            Assert.AreEqual(1, values.Count);
+            Assert.AreEqual("blue", values["color"].PropertyValue);
+
+            values["color"].PropertyValue = "red";
+            provider.SetPropertyValues(ctx, values);
+            values = provider.GetPropertyValues(ctx, props);
+            Assert.AreEqual(1, values.Count);
+            Assert.AreEqual("red", values["color"].PropertyValue);
+        }
+
+        [Test]
         public void StringCollectionAsProperty()
         {
             ProfileBase profile = ProfileBase.Create("foo", true);

Thread
Connector/NET commit: r1417 - in branches/5.2: . MySql.Web/Providers/Source MySql.Web/Testsrburnett12 Sep