2010-07-10 Veerapuram Varadhan <vvaradhan@novell.com>
authorVeerapuram Varadhan <v.varadhan@gmail.com>
Sat, 10 Jul 2010 10:35:56 +0000 (10:35 -0000)
committerVeerapuram Varadhan <v.varadhan@gmail.com>
Sat, 10 Jul 2010 10:35:56 +0000 (10:35 -0000)
** Fixes 620860
* Tds70.cs (Precision): New virtual property to handle Precision
values across different Tds versions.
(WriteParameterInfo): Use defined Precision property instead of
constant value.  Also handle Ulong and long max/min values
properly.
* Tds80.cs (Precision): Override property to provide Tds 8
precision value.

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

mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds80.cs
mcs/class/Mono.Data.Tds/Mono.Data.Tds/TdsMetaParameter.cs

index 0671a158e221898c90aa67d21982052b51c112f5..69e3125f8842fa1680f0a84c8a63b3d47d453ec0 100644 (file)
@@ -1,3 +1,12 @@
+2010-07-10  Veerapuram Varadhan  <vvaradhan@novell.com>
+
+       ** Fixes 620860
+       * Tds70.cs (Precision): New virtual property to handle Precision values 
+       across different Tds versions.
+       (WriteParameterInfo): Use defined Precision property instead of 
+       constant value.  Also handle Ulong and long max/min values properly.
+       * Tds80.cs (Precision): Override property to provide Tds 8 precision value.
+       
 2010-07-07  Veerapuram Varadhan  <vvaradhan@novell.com>
 
        * TdsComm.cs (Append[DateTime]): Ugh.. ugh.. final fix for handling MinValue for DateTime.
index a0a64db3ee915d693b1f510fc403fe2b92aec181..e804d143b9763502c0f4d62bfcab38aec657da7b 100644 (file)
@@ -76,6 +76,13 @@ namespace Mono.Data.Tds.Protocol
                protected virtual byte[] ClientVersion {
                        get { return new byte[] {0x00, 0x0, 0x0, 0x70};}
                }
+               
+               // Default precision is 28 for a 7.0 server. Unless and 
+               // otherwise the server is started with /p option - which would be 38
+               protected virtual byte Precision {
+                       get { return 28; }
+               }
+               
                #endregion // Properties
                
                #region Methods
@@ -122,7 +129,7 @@ namespace Mono.Data.Tds.Protocol
                                // Set default precision according to the TdsVersion
                                // Current default is 29 for Tds80 
                                if (p.TypeName == "decimal")
-                                       p.Precision = (p.Precision !=0  ? p.Precision : (byte) 18);
+                                       p.Precision = (p.Precision !=0  ? p.Precision : (byte) Precision);
                                                                                
                                parms.Append (p.Prepare ());
                                if (p.Direction == TdsParameterDirection.Output)
@@ -160,7 +167,7 @@ namespace Mono.Data.Tds.Protocol
                                                select.Append ("@" + parameterName);
                                                
                                                if (p.TypeName == "decimal")
-                                                       p.Precision = (p.Precision !=0 ? p.Precision : (byte) 18);
+                                                       p.Precision = (p.Precision !=0 ? p.Precision : (byte) Precision);
                                                        
                                                declare.Append (String.Format ("declare {0}\n", p.Prepare ()));
 
@@ -570,15 +577,19 @@ namespace Mono.Data.Tds.Protocol
 
                        // Precision and Scale are non-zero for only decimal/numeric
                        if ( param.TypeName == "decimal" || param.TypeName == "numeric") {
-                               Comm.Append ((param.Precision !=0 ) ? param.Precision : (byte) 29);
+                               Comm.Append ((param.Precision !=0 ) ? param.Precision : Precision);
                                Comm.Append (param.Scale);
                                // Convert the decimal value according to Scale
                                if (param.Value != null && param.Value != DBNull.Value &&
                                    ((decimal)param.Value) != Decimal.MaxValue && 
-                                   ((decimal)param.Value) != Decimal.MinValue) {
-                                       decimal expo = new Decimal (System.Math.Pow (10, (double)param.Scale));
+                                   ((decimal)param.Value) != Decimal.MinValue &&
+                                   ((decimal)param.Value) != long.MaxValue &&
+                                   ((decimal)param.Value) != long.MinValue &&
+                                   ((decimal)param.Value) != ulong.MaxValue &&
+                                   ((decimal)param.Value) != ulong.MinValue) {
+                                       long expo = (long)new Decimal (System.Math.Pow (10, (double)param.Scale));
                                        long pVal = (long)(((decimal)param.Value) * expo);
-                                       param.Value = (decimal)pVal;                            
+                                       param.Value = pVal;                             
                                }
                        }
 
index 5b541a026e83fadf28fd13d129c18cc647410fca..b507da39f0ee5b0dd528565aab40a4fe62bdd49f 100644 (file)
@@ -61,6 +61,10 @@ namespace Mono.Data.Tds.Protocol {
                protected override byte[] ClientVersion {
                        get { return new byte[] {0x00, 0x0, 0x0, 0x71};}
                }
+               protected override byte Precision {
+                       get { return 38; }
+               }
+               
                #endregion // Properties
                
                #region Methods
index 8ed81f7a16b5fc1f88e7ee63602af5daef36b281..931afeafd9efe22609c23127aa32d2262785e4b4 100644 (file)
@@ -231,7 +231,7 @@ namespace Mono.Data.Tds {
                        case "numeric":
                                // msdotnet sends a default precision of 29
                                result.Append (String.Format ("({0},{1})",
-                                        (Precision == (byte)0 ? (byte)29 : Precision), Scale));
+                                        (Precision == (byte)0 ? (byte)38 : Precision), Scale));
                                break;
                        case "varchar":
                        case "varbinary":