diff options
author | Veerapuram Varadhan <v.varadhan@gmail.com> | 2010-07-03 19:56:51 +0400 |
---|---|---|
committer | Veerapuram Varadhan <v.varadhan@gmail.com> | 2010-07-03 19:56:51 +0400 |
commit | 93c6d15d753911b2600748a48c262c784f4a061e (patch) | |
tree | d6ac318e524ffd1474ea8d520d464617075ec3d8 /mcs/class | |
parent | 236c10484af033265e706a0bdcfae60a6dfccf54 (diff) |
backport of r159851
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.
svn path=/branches/mono-2-6/mcs/; revision=159853
Diffstat (limited to 'mcs/class')
4 files changed, 28 insertions, 10 deletions
diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog index 515368df0a4..f5034518a4d 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog @@ -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 Veerapuram Varadhan <vvaradhan@novell.com> ** Fixes #613087 diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs index 65e362e74ce..757610daa71 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs @@ -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); } } } diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/ChangeLog b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/ChangeLog index f023697990c..e298d939191 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/ChangeLog +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/ChangeLog @@ -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 diff --git a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs index 2c89dfe2a88..e722106f1a6 100644 --- a/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs +++ b/mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs @@ -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": |