List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:November 30 2009 3:25pm
Subject:bzr commit into connector-net-6.0 branch (vvaintroub:778) Bug#48944
View as plain text  
#At file:///H:/connector_net/6.0/ based on revid:vvaintroub@stripped

  778 Vladislav Vaintroub	2009-11-30
      -  When sending file to server (builk loading), open the file for readonly, not for read-write 
        (bug#48944)

    modified:
      CHANGES
      MySql.Data/Provider/Source/NativeDriver.cs
      MySql.Data/Tests/Source/BulkLoading.cs
=== modified file 'CHANGES'
--- a/CHANGES	2009-11-25 16:26:35 +0000
+++ b/CHANGES	2009-11-30 15:25:48 +0000
@@ -1,6 +1,5 @@
-- Always close connection in MySqlConnection.Dispose(), also when it is
-garbage-collected  so underlying driver can be reused in the connection pool (bug#31996)
-
+-  When sending file to server (builk loading), open the file for readonly, not for read-write 
+  (bug#48944)
 Version 6.0.5
 - ensure that MySqlPacket always has a valid encoding. This prevents null reference exceptions in ReadString()
   (bug#46844)

=== modified file 'MySql.Data/Provider/Source/NativeDriver.cs'
--- a/MySql.Data/Provider/Source/NativeDriver.cs	2009-09-01 03:54:56 +0000
+++ b/MySql.Data/Provider/Source/NativeDriver.cs	2009-11-30 15:25:48 +0000
@@ -557,7 +557,8 @@ namespace MySql.Data.MySqlClient
             long len = 0;
             try
             {
-                using (FileStream fs = new FileStream(filename, FileMode.Open))
+                using (FileStream fs = new FileStream(filename, FileMode.Open,
+                    FileAccess.Read))
                 {
                     len = fs.Length;
                     while (len > 0)

=== modified file 'MySql.Data/Tests/Source/BulkLoading.cs'
--- a/MySql.Data/Tests/Source/BulkLoading.cs	2008-05-22 17:41:55 +0000
+++ b/MySql.Data/Tests/Source/BulkLoading.cs	2009-11-30 15:25:48 +0000
@@ -55,6 +55,44 @@ namespace MySql.Data.MySqlClient.Tests
             Assert.AreEqual(200, dt.Rows.Count);
             Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
         }
+        
+        [Test]
+        public void BulkLoadReadOnlyFile()
+        {
+            execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+
+            // first create the external file
+            string path = Path.GetTempFileName();
+            StreamWriter sw = new StreamWriter(path);
+            for (int i = 0; i < 200; i++)
+                sw.WriteLine(i + "\t'Test'");
+            sw.Flush();
+            sw.Close();
+
+            FileInfo fi = new FileInfo(path);
+            FileAttributes oldAttr = fi.Attributes;
+            fi.Attributes = fi.Attributes | FileAttributes.ReadOnly;
+            try
+            {
+                MySqlBulkLoader loader = new MySqlBulkLoader(conn);
+                loader.TableName = "Test";
+                loader.FileName = path;
+                loader.Timeout = 0;
+                int count = loader.Load();
+                Assert.AreEqual(200, count);
+
+                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
+                DataTable dt = new DataTable();
+                da.Fill(dt);
+                Assert.AreEqual(200, dt.Rows.Count);
+                Assert.AreEqual("'Test'", dt.Rows[0][1].ToString().Trim());
+            }
+            finally
+            {
+                fi.Attributes = oldAttr;
+                fi.Delete();
+            }
+        }
 
         [Test]
         public void BulkLoadSimple2()


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20091130152548-8c8b4qp3bmkgj2vc.bundle
Thread
bzr commit into connector-net-6.0 branch (vvaintroub:778) Bug#48944Vladislav Vaintroub30 Nov