Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Mono.Data.Tds / Mono.Data.Tds / TdsMetaParameter.cs
index b5c5f86bf171d3732d10df26e0f3d78c24bcf87d..8b704455cb3cb1cd1c77b378c82586f079ebd7a3 100644 (file)
@@ -37,6 +37,11 @@ namespace Mono.Data.Tds {
 
        public class TdsMetaParameter
        {
+               #region Static 
+               public const int maxVarCharCharacters =  2147483647; // According to MS, max size is 2GB, 1 Byte Characters
+               public const int maxNVarCharCharacters = 1073741823; // According to MS, max size is 2GB, 2 Byte Characters
+               #endregion
+
                #region Fields
 
                TdsParameterDirection direction = TdsParameterDirection.Input;
@@ -175,6 +180,78 @@ namespace Mono.Data.Tds {
                        set { isVariableSizeType = value; }
                }
 
+               public bool IsVarNVarCharMax
+               {
+                       get { return (TypeName == "ntext" && size >= maxNVarCharCharacters); }
+               }
+
+               public bool IsVarCharMax
+               {
+                       get { return (TypeName == "text" && size >= maxVarCharCharacters); }
+               }
+
+               public bool IsAnyVarCharMax
+               {
+                       get { return IsVarNVarCharMax || IsVarCharMax; }
+               }
+
+               public bool IsNonUnicodeText
+               {
+                       get {
+                               TdsColumnType colType = GetMetaType();
+                               return (colType == TdsColumnType.VarChar ||
+                                       colType == TdsColumnType.BigVarChar ||
+                                       colType == TdsColumnType.Text ||
+                                       colType == TdsColumnType.Char ||
+                                       colType == TdsColumnType.BigChar);
+                       }
+               }
+
+               public bool IsMoneyType
+               {
+                       get {
+                               TdsColumnType colType = GetMetaType();
+                               return (colType == TdsColumnType.Money ||
+                                       colType == TdsColumnType.MoneyN ||
+                                       colType == TdsColumnType.Money4 ||
+                                       colType == TdsColumnType.SmallMoney);
+                       }
+               }
+
+               public bool IsDateTimeType
+               {
+                       get {
+                               TdsColumnType colType = GetMetaType();
+                               return (colType == TdsColumnType.DateTime ||
+                                       colType == TdsColumnType.DateTime4 ||
+                                       colType == TdsColumnType.DateTimeN);
+                       }
+               }
+
+               public bool IsTextType
+               {
+                       get {
+                               TdsColumnType colType = GetMetaType();
+                               return (colType == TdsColumnType.VarChar ||
+                                       colType == TdsColumnType.BigVarChar ||
+                                       colType == TdsColumnType.BigChar ||
+                                       colType == TdsColumnType.Char ||
+                                       colType == TdsColumnType.BigNVarChar || 
+                                       colType == TdsColumnType.NChar ||
+                                       colType == TdsColumnType.Text ||
+                                       colType == TdsColumnType.NText);
+                       }
+               }
+
+               public bool IsDecimalType
+               {
+                       get {
+                               TdsColumnType colType = GetMetaType();
+                               return (colType == TdsColumnType.Decimal ||
+                                       colType == TdsColumnType.Numeric);
+                       }
+               }
+
                #endregion // Properties
 
                #region Methods
@@ -218,7 +295,7 @@ namespace Mono.Data.Tds {
                                }
                                
                                if (size > 8000) {
-                                       typeName = "image";
+                                       typeName = "varbinary(max)";
                                }
                        }
                        
@@ -231,7 +308,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":
@@ -246,7 +323,8 @@ namespace Mono.Data.Tds {
                                break;
                        case "nvarchar":
                        case "xml":
-                               result.Append (Size > 0 ? (Size > 8000 ? "(max)" : String.Format ("({0})", Size)) : "(4000)");
+                               int paramSize = Size < 0 ? GetActualSize () / 2 : Size;
+                               result.Append (paramSize > 0 ? (paramSize > 4000 ? "(max)" : String.Format ("({0})", paramSize)) : "(4000)");
                                break;
                        case "char":
                        case "nchar":
@@ -341,9 +419,11 @@ namespace Mono.Data.Tds {
                                        return TdsColumnType.BitN;
                                return TdsColumnType.Bit;
                        case "bigint":
+                               if (IsNullable)
+                                       return TdsColumnType.IntN ;
                                return TdsColumnType.BigInt;
                        case "char":
-                               return TdsColumnType.Char;
+                               return TdsColumnType.BigChar;
                        case "money":
                                if (IsNullable)
                                        return TdsColumnType.MoneyN;
@@ -351,7 +431,7 @@ namespace Mono.Data.Tds {
                        case "smallmoney":
                                if (IsNullable)
                                        return TdsColumnType.MoneyN ;
-                               return TdsColumnType.Money4;
+                               return TdsColumnType.SmallMoney;
                        case "decimal":
                                return TdsColumnType.Decimal;
                        case "datetime":
@@ -406,6 +486,34 @@ namespace Mono.Data.Tds {
                        }
                }
 
+               public void CalculateIsVariableType()
+               {
+                       switch (GetMetaType ()) {
+                               case TdsColumnType.UniqueIdentifier:
+                               case TdsColumnType.BigVarChar:
+                               case TdsColumnType.BigVarBinary:
+                               case TdsColumnType.IntN:
+                               case TdsColumnType.Text:
+                               case TdsColumnType.FloatN:
+                               case TdsColumnType.BigNVarChar:
+                               case TdsColumnType.NText:
+                               case TdsColumnType.Image:
+                               case TdsColumnType.Decimal:
+                               case TdsColumnType.BigBinary:
+                               case TdsColumnType.DateTimeN:
+                               case TdsColumnType.MoneyN:
+                               case TdsColumnType.BitN:
+                               case TdsColumnType.Char:
+                               case TdsColumnType.BigChar:
+                               case TdsColumnType.NChar:
+                                       IsVariableSizeType = true;
+                                       break;
+                               default:
+                                       IsVariableSizeType = false;
+                               break;
+                       }
+               }
+
                public void Validate (int index)
                {
                        if ((this.direction == TdsParameterDirection.InputOutput || this.direction == TdsParameterDirection.Output) &&