2010-07-03 Veerapuram Varadhan <vvaradhan@novell.com>
authorVeerapuram Varadhan <v.varadhan@gmail.com>
Sat, 3 Jul 2010 15:37:35 +0000 (15:37 -0000)
committerVeerapuram Varadhan <v.varadhan@gmail.com>
Sat, 3 Jul 2010 15:37:35 +0000 (15:37 -0000)
** Fixes #609935
* TdsMetaParameter.cs (Prepare): Use GetActualSize() instead of
Size property to calculate the length of a nvarchar param.

svn path=/trunk/mcs/; revision=159851

mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
mcs/class/Mono.Data.Tds/Mono.Data.Tds/ChangeLog
mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs

index 04e6919fec9a808e2caf27c5021b81e79e28d6f5..4b783869034fb6ced5182785ad02e86a15eb1a33 100644 (file)
@@ -1,3 +1,9 @@
+2010-07-03  Veerapuram Varadhan  <vvaradhan@novell.com>
+
+       ** Fixes #609935
+       * TdsComm.cs (Append[string]): Fix boundary calculations of bytes 
+       to be written and available free buffer.
+       
 2010-06-15 Jonathan Chambers  <joncham@gmail.com>
 
        * Tds.cs: Add {} around default switch case.
index 65e362e74ce4da39fb8ea5f83abebc122e33b6b5..757610daa71c99097a328fcbbf274c0e6019a50e 100644 (file)
@@ -374,23 +374,28 @@ namespace Mono.Data.Tds.Protocol {
                        if (tdsVersion < TdsVersion.tds70) { 
                                Append (encoder.GetBytes (s));
                        } else {
-                               int lenToWrite = s.Length * 2;
-                               int count = lenToWrite/outBufferLength;
                                int cindex = 0, index;
-                               int remBufLen = 0;
+                               int ssize = sizeof (short);
+                               int lenToWrite = s.Length * ssize;
+                               // if nextOutBufferLength points to the last buffer in outBuffer, 
+                               // we would get a DivisionByZero while calculating remBufLen
+                               if (outBufferLength - nextOutBufferIndex < 1)
+                                       SendIfFull (ssize);
                                
-                               if (lenToWrite % outBufferLength > 0)
+                               int remBufLen = outBufferLength - nextOutBufferIndex;
+                               int count = lenToWrite/remBufLen;
+                               
+                               if (lenToWrite % remBufLen > 0)
                                        count++;
                        
-                               remBufLen = outBufferLength - nextOutBufferIndex;
                                for (int i = 0; i < count; i++) {
-                                       index = System.Math.Min (remBufLen, lenToWrite);
-                                       for (int j = 0; j < index; j+=2, cindex++)
+                                       index = System.Math.Min (remBufLen/ssize, lenToWrite/ssize);
+                                       for (int j = 0; j < index*ssize; j+=2, cindex++)
                                                AppendInternal ((short)s[cindex]);
                                        
-                                       lenToWrite -= System.Math.Min (remBufLen, lenToWrite);
+                                       lenToWrite -= index*ssize;
                                        // Just make sure to flush the buffer
-                                       SendIfFull (lenToWrite+2);
+                                       SendIfFull ((lenToWrite+1)*ssize);
                                }
                        }
                }       
index f023697990c91d7b6e4e6b18f072da3c76bf0f07..e298d93919115ab89f9ec6be02a718f38d653e02 100644 (file)
@@ -1,3 +1,9 @@
+2010-07-03  Veerapuram Varadhan  <vvaradhan@novell.com>
+
+       ** Fixes #609935
+       * TdsMetaParameter.cs (Prepare): Use GetActualSize() instead of Size 
+       property to calculate the length of a nvarchar param.
+       
 2009-05-26  Veerapuram Varadhan  <vvaradhan@novell.com>
 
        * TdsComm.cs (Append):  When appending strings of length bigger than 
index 2c89dfe2a889f5fcf37fb13ae03b7c007d404f3f..e722106f1a6192dbbb7153db29c68336f4325d54 100644 (file)
@@ -246,7 +246,8 @@ namespace Mono.Data.Tds {
                                break;
                        case "nvarchar":
                        case "xml":
-                               result.Append (Size > 0 ? (Size > 8000 ? "(max)" : String.Format ("({0})", Size)) : "(4000)");
+                               int paramSize = GetActualSize ();
+                               result.Append (paramSize > 0 ? (paramSize > 8000 ? "(max)" : String.Format ("({0})", paramSize)) : "(4000)");
                                break;
                        case "char":
                        case "nchar":