internal SmiQueryMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList<SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, bool allowsDBNull, string serverName, string catalogName, string schemaName, string tableName, string columnName, SqlBoolean isKey, bool isIdentity, bool isColumnSet, bool isReadOnly, SqlBoolean isExpression, SqlBoolean isAliased, SqlBoolean isHidden) : base(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, allowsDBNull, serverName, catalogName, schemaName, tableName, columnName, isKey, isIdentity, isColumnSet)
 {
     this._isReadOnly = isReadOnly;
     this._isExpression = isExpression;
     this._isAliased = isAliased;
     this._isHidden = isHidden;
 }
 internal SmiExtendedMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList<SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : base(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties)
 {
     this._name = name;
     this._typeSpecificNamePart1 = typeSpecificNamePart1;
     this._typeSpecificNamePart2 = typeSpecificNamePart2;
     this._typeSpecificNamePart3 = typeSpecificNamePart3;
 }
 internal SmiStorageMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList<SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, bool allowsDBNull, string serverName, string catalogName, string schemaName, string tableName, string columnName, SqlBoolean isKey, bool isIdentity, bool isColumnSet) : base(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3)
 {
     this._allowsDBNull = allowsDBNull;
     this._serverName = serverName;
     this._catalogName = catalogName;
     this._schemaName = schemaName;
     this._tableName = tableName;
     this._columnName = columnName;
     this._isKey = isKey;
     this._isIdentity = isIdentity;
     this._isColumnSet = isColumnSet;
 }
        // Most general constructor, should be able to intialize all SqlMetaData fields.(Used by SqlParameter)
        internal SqlMetaData (String            name,
                              SqlDbType         sqlDBType,
                              long              maxLength,
                              byte              precision,
                              byte              scale,
                              long              localeId,
                              SqlCompareOptions compareOptions,
                              string            xmlSchemaCollectionDatabase,
                              string            xmlSchemaCollectionOwningSchema,
                              string            xmlSchemaCollectionName,
                              bool              partialLength,
                              Type              udtType) {
            AssertNameIsValid(name);

            m_strName                         = name;
            m_sqlDbType                       = sqlDBType;
            m_lMaxLength                      = maxLength;
            m_bPrecision                      = precision;
            m_bScale                          = scale;
            m_lLocale                         = localeId;
            m_eCompareOptions                 = compareOptions;
            m_XmlSchemaCollectionDatabase     = xmlSchemaCollectionDatabase;
            m_XmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema;
            m_XmlSchemaCollectionName         = xmlSchemaCollectionName;
            m_bPartialLength                  = partialLength;

            m_udttype                         = udtType;
        }
Example #5
0
 // string type constructor with locale and compare options, no tvp extended properties
 public SqlMetaData(String name, SqlDbType dbType, long maxLength, long locale,
                    SqlCompareOptions compareOptions)
 {
     Construct(name, dbType, maxLength, locale, compareOptions, x_defaultUseServerDefault,
             x_defaultIsUniqueKey, x_defaultColumnSortOrder, x_defaultSortOrdinal);
 }
Example #6
0
        private static SortedList <SqlString, SqlString> CreateSortedSqlStringList(int numberOfItems, SqlCompareOptions compareOption, CultureInfo cInfo, int localeID)
        {
            SortedList <SqlString, SqlString> items = new SortedList <SqlString, SqlString>(numberOfItems);

            //
            // Generate list of SqlString
            //

            Random rand = new Random(500);
            int    numberOfWords;

            StringBuilder builder = new StringBuilder();
            SqlString     word;

            for (int i = 0; i < numberOfItems; ++i)
            {
                do
                {
                    builder.Clear();
                    numberOfWords = rand.Next(10) + 1;

                    for (int j = 0; j < numberOfWords; ++j)
                    {
                        builder.Append(s_sampleString[rand.Next(s_sampleStringCount)]);
                        builder.Append(" ");
                    }

                    if (numberOfWords % 2 == 1)
                    {
                        for (int k = 0; k < rand.Next(100); ++k)
                        {
                            builder.Append(' ');
                        }
                    }
                    word = new SqlString(builder.ToString(), localeID, compareOption);
                } while (items.ContainsKey(word));

                items.Add(word, word);
            }

            return(items);
        }
Example #7
0
        private static SortedList<SqlString, SqlString> CreateSortedSqlStringList(int numberOfItems, SqlCompareOptions compareOption, CultureInfo cInfo, int localeID)
        {
            SortedList<SqlString, SqlString> items = new SortedList<SqlString, SqlString>(numberOfItems);

            //
            // Generate list of SqlString
            //

            Random rand = new Random(500);
            int numberOfWords;

            StringBuilder builder = new StringBuilder();
            SqlString word;

            for (int i = 0; i < numberOfItems; ++i)
            {
                do
                {
                    builder.Clear();
                    numberOfWords = rand.Next(10) + 1;

                    for (int j = 0; j < numberOfWords; ++j)
                    {
                        builder.Append(s_sampleString[rand.Next(s_sampleStringCount)]);
                        builder.Append(" ");
                    }

                    if (numberOfWords % 2 == 1)
                    {
                        for (int k = 0; k < rand.Next(100); ++k)
                        {
                            builder.Append(' ');
                        }
                    }
                    word = new SqlString(builder.ToString(), localeID, compareOption);
                } while (items.ContainsKey(word));

                items.Add(word, word);
            }

            return items;
        }
 // SMI V200 ctor.
 internal SmiMetaData(
                         SqlDbType dbType,
                         long maxLength,
                         byte precision,
                         byte scale,
                         long localeId,
                         SqlCompareOptions compareOptions,
                         Type userDefinedType,
                         bool isMultiValued,
                         IList<SmiExtendedMetaData> fieldTypes,
                         SmiMetaDataPropertyCollection extendedProperties)
     :
                 this(dbType,
                         maxLength,
                         precision,
                         scale,
                         localeId,
                         compareOptions,
                         userDefinedType,
                         null,
                         isMultiValued,
                         fieldTypes,
                         extendedProperties) {
 }
        // Private constructor used only to initialize default instance array elements.
        // DO NOT EXPOSE OUTSIDE THIS CLASS!
        private SmiMetaData (
                                SqlDbType         sqlDbType,
                                long              maxLength,
                                byte              precision,
                                byte              scale,
                                SqlCompareOptions compareOptions) {
            _databaseType      = sqlDbType;
            _maxLength         = maxLength;
            _precision         = precision;
            _scale             = scale;
            _compareOptions    = compareOptions;

            // defaults are the same for all types for the following attributes.
            _localeId           = 0; 
            _clrType            = null;
            _isMultiValued      = false;
            _fieldMetaData      = __emptyFieldList;
            _extendedProperties = SmiMetaDataPropertyCollection.EmptyInstance;
        }
Example #10
0
 internal SmiExtendedMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : base(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties)
 {
     this._name = name;
     this._typeSpecificNamePart1 = typeSpecificNamePart1;
     this._typeSpecificNamePart2 = typeSpecificNamePart2;
     this._typeSpecificNamePart3 = typeSpecificNamePart3;
 }
Example #11
0
        // Private constructor used to initialize default instance array elements.
        // DO NOT EXPOSE OUTSIDE THIS CLASS!  It performs no validation.
        private SqlMetaData(String name,
                             SqlDbType sqlDbType,
                             long maxLength,
                             byte precision,
                             byte scale,
                             long localeId,
                             SqlCompareOptions compareOptions,
                             bool partialLength)
        {
            AssertNameIsValid(name);

            _strName = name;
            _sqlDbType = sqlDbType;
            _lMaxLength = maxLength;
            _bPrecision = precision;
            _bScale = scale;
            _lLocale = localeId;
            _eCompareOptions = compareOptions;
            _bPartialLength = partialLength;
            ThrowIfUdt(sqlDbType);
        }
Example #12
0
 internal SmiExtendedMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, SmiMetaData[] columns, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : this(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3)
 {
 }
Example #13
0
 internal SmiExtendedMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : this(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, null, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3)
 {
 }
Example #14
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.Data.SqlTypes.SqlString'/> class.
 ///    </para>
 /// </devdoc>
 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data)
     : this(lcid, compareOptions, data, 0, data.Length, true)
 {
 }
Example #15
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.Data.SqlTypes.SqlString'/> class.
 ///    </para>
 /// </devdoc>
 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data, int index, int count)
     : this(lcid, compareOptions, data, index, count, true)
 {
 }
Example #16
0
        private static void VerifySortedSqlStringList(SortedList <SqlString, SqlString> items, SqlCompareOptions compareOption, CultureInfo cInfo)
        {
            //
            // Verify the list is in order
            //

            IList <SqlString> keyList = items.Keys;

            for (int i = 0; i < items.Count - 1; ++i)
            {
                SqlString currentString = keyList[i];
                SqlString nextString    = keyList[i + 1];

                Assert.True((bool)((currentString < nextString) && (nextString >= currentString)), "FAILED: (SqlString Operator Comparison): SqlStrings are out of order");
                Assert.True((currentString.CompareTo(nextString) < 0) && (nextString.CompareTo(currentString) > 0), "FAILED: (SqlString.CompareTo): SqlStrings are out of order");

                switch (compareOption)
                {
                case SqlCompareOptions.BinarySort:
                    Assert.True(CompareBinary(currentString.Value, nextString.Value) < 0, "FAILED: (SqlString BinarySort Comparison): SqlStrings are out of order");
                    break;

                case SqlCompareOptions.BinarySort2:
                    Assert.True(string.CompareOrdinal(currentString.Value.TrimEnd(), nextString.Value.TrimEnd()) < 0, "FAILED: (SqlString BinarySort2 Comparison): SqlStrings are out of order");

                    break;

                default:
                    CompareInfo    cmpInfo    = cInfo.CompareInfo;
                    CompareOptions cmpOptions = SqlString.CompareOptionsFromSqlCompareOptions(nextString.SqlCompareOptions);

                    Assert.True(cmpInfo.Compare(currentString.Value.TrimEnd(), nextString.Value.TrimEnd(), cmpOptions) < 0, "FAILED: (SqlString Comparison): SqlStrings are out of order");
                    break;
                }
            }
        }
Example #17
0
 // everything except xml schema and tvp properties ctor
 public SqlMetaData(String name, SqlDbType dbType, long maxLength, byte precision,
                    byte scale, long locale, SqlCompareOptions compareOptions,
                    Type userDefinedType) :
                    this(name, dbType, maxLength, precision, scale, locale, compareOptions,
                         userDefinedType, x_defaultUseServerDefault, x_defaultIsUniqueKey,
                         x_defaultColumnSortOrder, x_defaultSortOrdinal)
 {
 }
Example #18
0
 // Constructor: Construct from both Unicode and NonUnicode data, according to fUnicode
 /// <summary>
 /// Initializes a new instance of the <see cref='System.Data.SqlTypes.SqlString'/> class.
 /// </summary>
 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data, bool fUnicode)
     : this(lcid, compareOptions, data, 0, data.Length, fUnicode)
 {
 }
Example #19
0
 private void SetDefaultsForType(SqlDbType dbType)
 {
     if (SqlDbType.BigInt <= dbType && SqlDbType.DateTimeOffset >= dbType)
     {
         SqlMetaData smdDflt = sxm_rgDefaults[(int)dbType];
         _sqlDbType = dbType;
         _lMaxLength = smdDflt.MaxLength;
         _bPrecision = smdDflt.Precision;
         _bScale = smdDflt.Scale;
         _lLocale = smdDflt.LocaleId;
         _eCompareOptions = smdDflt.CompareOptions;
     }
 }
Example #20
0
        // SMI V220 ctor.
        internal SmiMetaData(
            SqlDbType dbType,
            long maxLength,
            byte precision,
            byte scale,
            long localeId,
            SqlCompareOptions compareOptions,
            string udtAssemblyQualifiedName,
            bool isMultiValued,
            IList <SmiExtendedMetaData> fieldTypes,
            SmiMetaDataPropertyCollection extendedProperties)
        {
            Debug.Assert(IsSupportedDbType(dbType), "Invalid SqlDbType: " + dbType);

            SetDefaultsForType(dbType);

            switch (dbType)
            {
            case SqlDbType.BigInt:
            case SqlDbType.Bit:
            case SqlDbType.DateTime:
            case SqlDbType.Float:
            case SqlDbType.Image:
            case SqlDbType.Int:
            case SqlDbType.Money:
            case SqlDbType.Real:
            case SqlDbType.SmallDateTime:
            case SqlDbType.SmallInt:
            case SqlDbType.SmallMoney:
            case SqlDbType.Timestamp:
            case SqlDbType.TinyInt:
            case SqlDbType.UniqueIdentifier:
            case SqlDbType.Variant:
            case SqlDbType.Xml:
            case SqlDbType.Date:
                break;

            case SqlDbType.Binary:
            case SqlDbType.VarBinary:
                _maxLength = maxLength;
                break;

            case SqlDbType.Char:
            case SqlDbType.NChar:
            case SqlDbType.NVarChar:
            case SqlDbType.VarChar:
                // locale and compare options are not validated until they get to the server
                _maxLength      = maxLength;
                _localeId       = localeId;
                _compareOptions = compareOptions;
                break;

            case SqlDbType.NText:
            case SqlDbType.Text:
                _localeId       = localeId;
                _compareOptions = compareOptions;
                break;

            case SqlDbType.Decimal:
                Debug.Assert(MinPrecision <= precision && SqlDecimal.MaxPrecision >= precision, "Invalid precision: " + precision);
                Debug.Assert(MinScale <= scale && SqlDecimal.MaxScale >= scale, "Invalid scale: " + scale);
                Debug.Assert(scale <= precision, "Precision: " + precision + " greater than scale: " + scale);
                _precision = precision;
                _scale     = scale;
                _maxLength = s_maxLenFromPrecision[precision - 1];
                break;

            case SqlDbType.Udt:
                throw System.Data.Common.ADP.DbTypeNotSupported(SqlDbType.Udt.ToString());

            case SqlDbType.Structured:
                if (null != fieldTypes)
                {
                    _fieldMetaData = new System.Collections.ObjectModel.ReadOnlyCollection <SmiExtendedMetaData>(fieldTypes);
                }
                _isMultiValued = isMultiValued;
                _maxLength     = _fieldMetaData.Count;
                break;

            case SqlDbType.Time:
                Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                _scale     = scale;
                _maxLength = 5 - s_maxVarTimeLenOffsetFromScale[scale];
                break;

            case SqlDbType.DateTime2:
                Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                _scale     = scale;
                _maxLength = 8 - s_maxVarTimeLenOffsetFromScale[scale];
                break;

            case SqlDbType.DateTimeOffset:
                Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                _scale     = scale;
                _maxLength = 10 - s_maxVarTimeLenOffsetFromScale[scale];
                break;

            default:
                Debug.Assert(false, "How in the world did we get here? :" + dbType);
                break;
            }

            if (null != extendedProperties)
            {
                extendedProperties.SetReadOnly();
                _extendedProperties = extendedProperties;
            }

            // properties and fields must meet the following conditions at this point:
            //  1) not null
            //  2) read only
            //  3) same number of columns in each list (0 count acceptable for properties that are "unused")
            Debug.Assert(null != _extendedProperties && _extendedProperties.IsReadOnly, "SmiMetaData.ctor: _extendedProperties is " + (null != _extendedProperties ? "writeable" : "null"));
            Debug.Assert(null != _fieldMetaData && _fieldMetaData.IsReadOnly, "SmiMetaData.ctor: _fieldMetaData is " + (null != _fieldMetaData ? "writeable" : "null"));
#if DEBUG
            ((SmiDefaultFieldsProperty)_extendedProperties[SmiPropertySelector.DefaultFields]).CheckCount(_fieldMetaData.Count);
            ((SmiUniqueKeyProperty)_extendedProperties[SmiPropertySelector.UniqueKey]).CheckCount(_fieldMetaData.Count);
#endif
        }
Example #21
0
 internal SmiQueryMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, bool allowsDBNull, string serverName, string catalogName, string schemaName, string tableName, string columnName, SqlBoolean isKey, bool isIdentity, bool isColumnSet, bool isReadOnly, SqlBoolean isExpression, SqlBoolean isAliased, SqlBoolean isHidden) : base(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, allowsDBNull, serverName, catalogName, schemaName, tableName, columnName, isKey, isIdentity, isColumnSet)
 {
     this._isReadOnly   = isReadOnly;
     this._isExpression = isExpression;
     this._isAliased    = isAliased;
     this._isHidden     = isHidden;
 }
 internal SmiExtendedMetaData(
                                 SqlDbType dbType, 
                                 long maxLength,
                                 byte precision, 
                                 byte scale, 
                                 long localeId, 
                                 SqlCompareOptions compareOptions, 
                                 Type userDefinedType, 
                                 string name, 
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3) :
                             this(
                                 dbType,
                                 maxLength,
                                 precision,
                                 scale,
                                 localeId,
                                 compareOptions,
                                 userDefinedType,
                                 false,
                                 null,
                                 null,
                                 name,
                                 typeSpecificNamePart1,
                                 typeSpecificNamePart2,
                                 typeSpecificNamePart3) {
 }
        // SMI V220 ctor.
        internal SmiMetaData(
                                SqlDbType dbType, 
                                long maxLength,
                                byte precision, 
                                byte scale, 
                                long localeId, 
                                SqlCompareOptions compareOptions, 
                                Type userDefinedType,
                                string udtAssemblyQualifiedName,
                                bool isMultiValued,
                                IList<SmiExtendedMetaData> fieldTypes,
                                SmiMetaDataPropertyCollection extendedProperties) {

            
            Debug.Assert( IsSupportedDbType(dbType), "Invalid SqlDbType: " + dbType );

            SetDefaultsForType( dbType );
            
            // 

            
            switch ( dbType ) {
                case SqlDbType.BigInt:
                case SqlDbType.Bit:
                case SqlDbType.DateTime:
                case SqlDbType.Float:
                case SqlDbType.Image:
                case SqlDbType.Int:
                case SqlDbType.Money:
                case SqlDbType.Real:
                case SqlDbType.SmallDateTime:
                case SqlDbType.SmallInt:
                case SqlDbType.SmallMoney:
                case SqlDbType.Timestamp:
                case SqlDbType.TinyInt:
                case SqlDbType.UniqueIdentifier:
                case SqlDbType.Variant:
                case SqlDbType.Xml:
                case SqlDbType.Date:
                    break;
                case SqlDbType.Binary:
                case SqlDbType.VarBinary:
                    _maxLength = maxLength;
                    break;
                case SqlDbType.Char:
                case SqlDbType.NChar:
                case SqlDbType.NVarChar:
                case SqlDbType.VarChar:
                    // locale and compare options are not validated until they get to the server
                    _maxLength = maxLength;
                    _localeId = localeId;
                    _compareOptions = compareOptions;
                    break;
                case SqlDbType.NText:
                case SqlDbType.Text:
                    _localeId = localeId;
                    _compareOptions = compareOptions;
                    break;
                case SqlDbType.Decimal:
                    Debug.Assert( MinPrecision <= precision && SqlDecimal.MaxPrecision >= precision, "Invalid precision: " + precision );
                    Debug.Assert( MinScale <= scale && SqlDecimal.MaxScale >= scale, "Invalid scale: " + scale );
                    Debug.Assert( scale <= precision, "Precision: " + precision + " greater than scale: " + scale );
                    _precision = precision;
                    _scale = scale;
                    _maxLength = __maxLenFromPrecision[precision - 1];
                    break;
                case SqlDbType.Udt:
                    // Assert modified for VSFTDEVDIV479492 - for SqlParameter both userDefinedType and udtAssemblyQualifiedName
                    // can be NULL, we are checking only maxLength if it will be used (i.e. userDefinedType is NULL)
                    Debug.Assert((null != userDefinedType) || (0 <= maxLength || UnlimitedMaxLengthIndicator == maxLength),
                            String.Format((IFormatProvider)null, "SmiMetaData.ctor: Udt name={0}, maxLength={1}", udtAssemblyQualifiedName, maxLength));
                    // Type not validated until matched to a server.  Could be null if extended metadata supplies three-part name!
                    _clrType = userDefinedType;
                    if (null != userDefinedType) {
                        _maxLength = SerializationHelperSql9.GetUdtMaxLength(userDefinedType);
                    }
                    else {
                        _maxLength = maxLength;
                    }
                    _udtAssemblyQualifiedName = udtAssemblyQualifiedName;
                    break;
                case SqlDbType.Structured:
                    if (null != fieldTypes) {
                        _fieldMetaData = (new List<SmiExtendedMetaData>(fieldTypes)).AsReadOnly();
                    }
                    _isMultiValued = isMultiValued;
                    _maxLength = _fieldMetaData.Count;
                    break;
                case SqlDbType.Time:
                    Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                    _scale = scale;
                    _maxLength = 5 - __maxVarTimeLenOffsetFromScale[scale];
                    break;
                case SqlDbType.DateTime2:
                    Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                    _scale = scale;
                    _maxLength = 8 - __maxVarTimeLenOffsetFromScale[scale];
                    break;
                case SqlDbType.DateTimeOffset:
                    Debug.Assert(MinScale <= scale && scale <= MaxTimeScale, "Invalid time scale: " + scale);
                    _scale = scale;
                    _maxLength = 10 - __maxVarTimeLenOffsetFromScale[scale];
                    break;
                default:
                    Debug.Assert( false, "How in the world did we get here? :" + dbType );
                    break;
            }

            if (null != extendedProperties) {
                extendedProperties.SetReadOnly();
                _extendedProperties = extendedProperties;
            }

            // properties and fields must meet the following conditions at this point:
            //  1) not null
            //  2) read only
            //  3) same number of columns in each list (0 count acceptable for properties that are "unused")
            Debug.Assert(null != _extendedProperties && _extendedProperties.IsReadOnly, "SmiMetaData.ctor: _extendedProperties is " + (null!=_extendedProperties?"writeable":"null"));
            Debug.Assert(null != _fieldMetaData && _fieldMetaData.IsReadOnly, "SmiMetaData.ctor: _fieldMetaData is " + (null!=_fieldMetaData?"writeable":"null"));
#if DEBUG
            ((SmiDefaultFieldsProperty)_extendedProperties[SmiPropertySelector.DefaultFields]).CheckCount(_fieldMetaData.Count);
            ((SmiOrderProperty)_extendedProperties[SmiPropertySelector.SortOrder]).CheckCount(_fieldMetaData.Count);
            ((SmiUniqueKeyProperty)_extendedProperties[SmiPropertySelector.UniqueKey]).CheckCount(_fieldMetaData.Count);
#endif
        }
 internal SmiParameterMetaData( 
                                 SqlDbType dbType, 
                                 long maxLength, 
                                 byte precision, 
                                 byte scale, 
                                 long  localeId, 
                                 SqlCompareOptions compareOptions, 
                                 Type userDefinedType, 
                                 SmiMetaData[] columns, 
                                 string name, 
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3,
                                 ParameterDirection direction) :
                         // Implement as calling the new ctor
                         this ( 
                                 dbType, 
                                 maxLength, 
                                 precision, 
                                 scale, 
                                 localeId, 
                                 compareOptions, 
                                 userDefinedType, 
                                 name, 
                                 typeSpecificNamePart1, 
                                 typeSpecificNamePart2, 
                                 typeSpecificNamePart3,
                                 direction ) {
     Debug.Assert( null == columns, "Row types not supported" );
 }
 // Internal setter to be used by constructors only!  Modifies state!
 private void SetDefaultsForType( SqlDbType dbType )
     {
         SmiMetaData smdDflt = GetDefaultForType( dbType );
         _databaseType = dbType;
         _maxLength = smdDflt.MaxLength;
         _precision = smdDflt.Precision;
         _scale = smdDflt.Scale;
         _localeId = smdDflt.LocaleId;
         _compareOptions = smdDflt.CompareOptions;
         _clrType = null;
         _isMultiValued = smdDflt._isMultiValued;
         _fieldMetaData = smdDflt._fieldMetaData;            // This is ok due to immutability
         _extendedProperties = smdDflt._extendedProperties;  // This is ok due to immutability
     }
Example #26
0
        private static void SqlStringCompareTest(int numberOfItems, SqlCompareOptions compareOption, CultureInfo cInfo, int localeID)
        {
            SortedList <SqlString, SqlString> items = CreateSortedSqlStringList(numberOfItems, compareOption, cInfo, localeID);

            VerifySortedSqlStringList(items, compareOption, cInfo);
        }
 // SMI V200 ctor.
 internal SmiExtendedMetaData(
                                 SqlDbType dbType,
                                 long maxLength,
                                 byte precision,
                                 byte scale,
                                 long localeId,
                                 SqlCompareOptions compareOptions,
                                 Type userDefinedType,
                                 bool isMultiValued,
                                 IList<SmiExtendedMetaData> fieldMetaData,
                                 SmiMetaDataPropertyCollection extendedProperties,
                                 string name,
                                 string typeSpecificNamePart1,
                                 string typeSpecificNamePart2,
                                 string typeSpecificNamePart3) :
                         this(   dbType,
                                 maxLength,
                                 precision,
                                 scale,
                                 localeId,
                                 compareOptions,
                                 userDefinedType,
                                 null,
                                 isMultiValued,
                                 fieldMetaData,
                                 extendedProperties,
                                 name,
                                 typeSpecificNamePart1,
                                 typeSpecificNamePart2,
                                 typeSpecificNamePart3) {
 }
		public SqlMetaData (string name, SqlDbType type, long maxLength, long locale, SqlCompareOptions compareOptions)
		{
			this.compareOptions = compareOptions;
			this.localeId = locale;
			this.maxLength = maxLength;
			this.name = name;
			this.sqlDbType = type;
		}
Example #29
0
 private static void SqlStringCompareTest(int numberOfItems, SqlCompareOptions compareOption, CultureInfo cInfo, int localeID)
 {
     SortedList<SqlString, SqlString> items = CreateSortedSqlStringList(numberOfItems, compareOption, cInfo, localeID);
     VerifySortedSqlStringList(items, compareOption, cInfo);
 }
 // SMI V220 ctor.
 internal SmiParameterMetaData( 
                                 SqlDbType dbType, 
                                 long maxLength, 
                                 byte precision, 
                                 byte scale, 
                                 long  localeId, 
                                 SqlCompareOptions compareOptions, 
                                 Type userDefinedType,
                                 string udtAssemblyQualifiedName,
                                 bool isMultiValued,
                                 IList<SmiExtendedMetaData> fieldMetaData,
                                 SmiMetaDataPropertyCollection extendedProperties,
                                 string name, 
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3,
                                 ParameterDirection direction) :
                             base( dbType, 
                                 maxLength, 
                                 precision, 
                                 scale, 
                                 localeId, 
                                 compareOptions, 
                                 userDefinedType, 
                                 udtAssemblyQualifiedName,
                                 isMultiValued,
                                 fieldMetaData,
                                 extendedProperties,
                                 name, 
                                 typeSpecificNamePart1, 
                                 typeSpecificNamePart2,
                                 typeSpecificNamePart3) {
     Debug.Assert( ParameterDirection.Input == direction
                || ParameterDirection.Output == direction 
                || ParameterDirection.InputOutput == direction 
                || ParameterDirection.ReturnValue == direction, "Invalid direction: " + direction );
     _direction = direction;
 }
Example #31
0
        private static void VerifySortedSqlStringList(SortedList<SqlString, SqlString> items, SqlCompareOptions compareOption, CultureInfo cInfo)
        {
            //
            // Verify the list is in order
            //

            IList<SqlString> keyList = items.Keys;
            for (int i = 0; i < items.Count - 1; ++i)
            {
                SqlString currentString = keyList[i];
                SqlString nextString = keyList[i + 1];

                Assert.True((bool)((currentString < nextString) && (nextString >= currentString)), "FAILED: (SqlString Operator Comparison): SqlStrings are out of order");
                Assert.True((currentString.CompareTo(nextString) < 0) && (nextString.CompareTo(currentString) > 0), "FAILED: (SqlString.CompareTo): SqlStrings are out of order");

                switch (compareOption)
                {
                    case SqlCompareOptions.BinarySort:
                        Assert.True(CompareBinary(currentString.Value, nextString.Value) < 0, "FAILED: (SqlString BinarySort Comparison): SqlStrings are out of order");
                        break;
                    case SqlCompareOptions.BinarySort2:
                        Assert.True(string.CompareOrdinal(currentString.Value.TrimEnd(), nextString.Value.TrimEnd()) < 0, "FAILED: (SqlString BinarySort2 Comparison): SqlStrings are out of order");

                        break;
                    default:
                        CompareInfo cmpInfo = cInfo.CompareInfo;
                        CompareOptions cmpOptions = SqlString.CompareOptionsFromSqlCompareOptions(nextString.SqlCompareOptions);

                        Assert.True(cmpInfo.Compare(currentString.Value.TrimEnd(), nextString.Value.TrimEnd(), cmpOptions) < 0, "FAILED: (SqlString Comparison): SqlStrings are out of order");
                        break;
                }
            }
        }
 // SMI V200 ctor.
 internal SmiStorageMetaData(
                                 SqlDbType dbType, 
                                 long maxLength, 
                                 byte precision, 
                                 byte scale, 
                                 long localeId, 
                                 SqlCompareOptions compareOptions,
                                 Type userDefinedType, 
                                 bool isMultiValued,
                                 IList<SmiExtendedMetaData> fieldMetaData,
                                 SmiMetaDataPropertyCollection extendedProperties,
                                 string name, 
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3,
                                 bool allowsDBNull, 
                                 string serverName, 
                                 string catalogName, 
                                 string schemaName, 
                                 string tableName, 
                                 string columnName, 
                                 SqlBoolean isKey, 
                                 bool isIdentity) :
                         this(   dbType, 
                                 maxLength, 
                                 precision, 
                                 scale, 
                                 localeId, 
                                 compareOptions, 
                                 userDefinedType, 
                                 null,
                                 isMultiValued,
                                 fieldMetaData,
                                 extendedProperties,
                                 name, 
                                 typeSpecificNamePart1, 
                                 typeSpecificNamePart2,
                                 typeSpecificNamePart3,
                                 allowsDBNull,
                                 serverName,
                                 catalogName,
                                 schemaName,
                                 tableName,
                                 columnName,
                                 isKey,
                                 isIdentity,
                                 false) {
 }
        // Private constructor used to initialize default instance array elements.
        // DO NOT EXPOSE OUTSIDE THIS CLASS!  It performs no validation.
        private SqlMetaData (String            name,
                             SqlDbType         sqlDbType,
                             long              maxLength,
                             byte              precision,
                             byte              scale,
                             long              localeId,
                             SqlCompareOptions compareOptions,
                             bool              partialLength) {

            AssertNameIsValid(name);

            m_strName                         = name;
            m_sqlDbType                       = sqlDbType;
            m_lMaxLength                      = maxLength;
            m_bPrecision                      = precision;
            m_bScale                          = scale;
            m_lLocale                         = localeId; 
            m_eCompareOptions                 = compareOptions;
            m_bPartialLength                  = partialLength;
            m_udttype                         = null;
        }
 internal SmiQueryMetaData(
                                 SqlDbType dbType, 
                                 long maxLength, 
                                 byte precision, 
                                 byte scale, 
                                 long localeId, 
                                 SqlCompareOptions compareOptions,
                                 Type userDefinedType, 
                                 SmiMetaData[] columns, 
                                 string name, 
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3,
                                 bool allowsDBNull, 
                                 string serverName, 
                                 string catalogName, 
                                 string schemaName, 
                                 string tableName, 
                                 string columnName, 
                                 SqlBoolean isKey, 
                                 bool isIdentity, 
                                 bool isReadOnly, 
                                 SqlBoolean isExpression, 
                                 SqlBoolean isAliased, 
                                 SqlBoolean isHidden ) :
                         // Implement as calling the new ctor
                         this ( 
                                 dbType, 
                                 maxLength, 
                                 precision, 
                                 scale, 
                                 localeId, 
                                 compareOptions, 
                                 userDefinedType, 
                                 name, 
                                 typeSpecificNamePart1, 
                                 typeSpecificNamePart2, 
                                 typeSpecificNamePart3,
                                 allowsDBNull,
                                 serverName,
                                 catalogName,
                                 schemaName,
                                 tableName,
                                 columnName,
                                 isKey,
                                 isIdentity,
                                 isReadOnly,
                                 isExpression,
                                 isAliased,
                                 isHidden ) {
     Debug.Assert( null == columns, "Row types not supported" );
 }
Example #35
0
 // string type constructor with locale and compare options
 public SqlMetaData(String name, SqlDbType dbType, long maxLength, long locale,
                    SqlCompareOptions compareOptions, bool useServerDefault,
                    bool isUniqueKey, SortOrder columnSortOrder, int sortOrdinal)
 {
     Construct(name, dbType, maxLength, locale, compareOptions, useServerDefault,
             isUniqueKey, columnSortOrder, sortOrdinal);
 }
 internal SmiQueryMetaData( SqlDbType dbType,
                                 long maxLength, 
                                 byte precision, 
                                 byte scale, 
                                 long localeId, 
                                 SqlCompareOptions compareOptions,
                                 Type userDefinedType, 
                                 string name,
                                 string typeSpecificNamePart1, 
                                 string typeSpecificNamePart2, 
                                 string typeSpecificNamePart3,
                                 bool allowsDBNull, 
                                 string serverName, 
                                 string catalogName, 
                                 string schemaName,
                                 string tableName, 
                                 string columnName, 
                                 SqlBoolean isKey,
                                 bool isIdentity, 
                                 bool isReadOnly, 
                                 SqlBoolean isExpression, 
                                 SqlBoolean isAliased, 
                                 SqlBoolean isHidden ) :
                             this( dbType,
                                 maxLength, 
                                 precision, 
                                 scale, 
                                 localeId, 
                                 compareOptions, 
                                 userDefinedType, 
                                 false,
                                 null,
                                 null,
                                 name,
                                 typeSpecificNamePart1, 
                                 typeSpecificNamePart2,
                                 typeSpecificNamePart3,
                                 allowsDBNull, 
                                 serverName, 
                                 catalogName, 
                                 schemaName, 
                                 tableName, 
                                 columnName, 
                                 isKey, 
                                 isIdentity,
                                 isReadOnly,
                                 isExpression,
                                 isAliased,
                                 isHidden) {
 }
Example #37
0
 // everything except xml schema ctor
 public SqlMetaData(String name, SqlDbType dbType, long maxLength, byte precision,
                    byte scale, long localeId, SqlCompareOptions compareOptions,
                    Type userDefinedType, bool useServerDefault,
                    bool isUniqueKey, SortOrder columnSortOrder, int sortOrdinal)
 {
     switch (dbType)
     {
         case SqlDbType.BigInt:
         case SqlDbType.Image:
         case SqlDbType.Timestamp:
         case SqlDbType.Bit:
         case SqlDbType.DateTime:
         case SqlDbType.SmallDateTime:
         case SqlDbType.Real:
         case SqlDbType.Int:
         case SqlDbType.Money:
         case SqlDbType.SmallMoney:
         case SqlDbType.Float:
         case SqlDbType.UniqueIdentifier:
         case SqlDbType.SmallInt:
         case SqlDbType.TinyInt:
         case SqlDbType.Xml:
         case SqlDbType.Date:
             Construct(name, dbType, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.Binary:
         case SqlDbType.VarBinary:
             Construct(name, dbType, maxLength, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.Char:
         case SqlDbType.NChar:
         case SqlDbType.NVarChar:
         case SqlDbType.VarChar:
             Construct(name, dbType, maxLength, localeId, compareOptions, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.NText:
         case SqlDbType.Text:
             // We should ignore user's max length and use Max instead to avoid exception
             Construct(name, dbType, Max, localeId, compareOptions, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.Decimal:
         case SqlDbType.Time:
         case SqlDbType.DateTime2:
         case SqlDbType.DateTimeOffset:
             Construct(name, dbType, precision, scale, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.Variant:
             Construct(name, dbType, useServerDefault, isUniqueKey, columnSortOrder, sortOrdinal);
             break;
         case SqlDbType.Udt:
             throw ADP.DbTypeNotSupported(SqlDbType.Udt.ToString());
         default:
             SQL.InvalidSqlDbTypeForConstructor(dbType);
             break;
     }
 }
 internal SmiMetaData(
                         SqlDbType dbType, 
                         long maxLength,
                         byte precision, 
                         byte scale, 
                         long localeId, 
                         SqlCompareOptions compareOptions, 
                         Type userDefinedType, 
                         SmiMetaData[] columns) :
                   // Implement as calling the new ctor
                   this(
                         dbType,
                         maxLength,
                         precision,
                         scale, 
                         localeId, 
                         compareOptions, 
                         userDefinedType ) {
     Debug.Assert( null == columns, "Row types not supported" );
 }
Example #39
0
        // Most general constructor, should be able to initialize all SqlMetaData fields.(Used by SqlParameter)
        internal SqlMetaData(String name,
                              SqlDbType sqlDBType,
                              long maxLength,
                              byte precision,
                              byte scale,
                              long localeId,
                              SqlCompareOptions compareOptions,
                              string xmlSchemaCollectionDatabase,
                              string xmlSchemaCollectionOwningSchema,
                              string xmlSchemaCollectionName,
                              bool partialLength
        )
        {
            AssertNameIsValid(name);

            _strName = name;
            _sqlDbType = sqlDBType;
            _lMaxLength = maxLength;
            _bPrecision = precision;
            _bScale = scale;
            _lLocale = localeId;
            _eCompareOptions = compareOptions;
            _xmlSchemaCollectionDatabase = xmlSchemaCollectionDatabase;
            _xmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema;
            _xmlSchemaCollectionName = xmlSchemaCollectionName;
            _bPartialLength = partialLength;

            ThrowIfUdt(sqlDBType);
        }
 // SMI V100 (aka V3) constructor.  Superceded in V200.
 internal SmiMetaData(
                         SqlDbType dbType, 
                         long maxLength,
                         byte precision, 
                         byte scale, 
                         long localeId, 
                         SqlCompareOptions compareOptions, 
                         Type userDefinedType) :
                 this(   dbType,
                         maxLength,
                         precision,
                         scale,
                         localeId,
                         compareOptions,
                         userDefinedType,
                         false,
                         null, 
                         null ) {
 }
Example #41
0
        // Construction for string types with specified locale/compare options
        private void Construct(String name,
                               SqlDbType dbType,
                               long maxLength,
                               long locale,
                               SqlCompareOptions compareOptions,
                               bool useServerDefault,
                               bool isUniqueKey,
                               SortOrder columnSortOrder,
                               int sortOrdinal)
        {
            AssertNameIsValid(name);

            ValidateSortOrder(columnSortOrder, sortOrdinal);

            // Validate type and max length.
            if (SqlDbType.Char == dbType)
            {
                if (maxLength > x_lServerMaxANSI || maxLength < 0)
                    throw ADP.Argument(Res.GetString(Res.ADP_InvalidDataLength2, maxLength.ToString(CultureInfo.InvariantCulture)), "maxLength");
            }
            else if (SqlDbType.VarChar == dbType)
            {
                if ((maxLength > x_lServerMaxANSI || maxLength < 0) && maxLength != Max)
                    throw ADP.Argument(Res.GetString(Res.ADP_InvalidDataLength2, maxLength.ToString(CultureInfo.InvariantCulture)), "maxLength");
            }
            else if (SqlDbType.NChar == dbType)
            {
                if (maxLength > x_lServerMaxUnicode || maxLength < 0)
                    throw ADP.Argument(Res.GetString(Res.ADP_InvalidDataLength2, maxLength.ToString(CultureInfo.InvariantCulture)), "maxLength");
            }
            else if (SqlDbType.NVarChar == dbType)
            {
                if ((maxLength > x_lServerMaxUnicode || maxLength < 0) && maxLength != Max)
                    throw ADP.Argument(Res.GetString(Res.ADP_InvalidDataLength2, maxLength.ToString(CultureInfo.InvariantCulture)), "maxLength");
            }
            else if (SqlDbType.NText == dbType || SqlDbType.Text == dbType)
            {
                // old-style lobs only allowed with Max length
                if (SqlMetaData.Max != maxLength)
                    throw ADP.Argument(Res.GetString(Res.ADP_InvalidDataLength2, maxLength.ToString(CultureInfo.InvariantCulture)), "maxLength");
            }
            else
                throw SQL.InvalidSqlDbTypeForConstructor(dbType);

            // Validate locale?

            // Validate compare options
            //    Binary sort must be by itself.
            //    Nothing else but the Ignore bits is allowed.
            if (SqlCompareOptions.BinarySort != compareOptions &&
                    0 != (~((int)SqlCompareOptions.IgnoreCase | (int)SqlCompareOptions.IgnoreNonSpace |
                            (int)SqlCompareOptions.IgnoreKanaType | (int)SqlCompareOptions.IgnoreWidth) &
                        (int)compareOptions))
                throw ADP.InvalidEnumerationValue(typeof(SqlCompareOptions), (int)compareOptions);

            SetDefaultsForType(dbType);

            _strName = name;
            _lMaxLength = maxLength;
            _lLocale = locale;
            _eCompareOptions = compareOptions;
            _useServerDefault = useServerDefault;
            _isUniqueKey = isUniqueKey;
            _columnSortOrder = columnSortOrder;
            _sortOrdinal = sortOrdinal;
        }
Example #42
0
 internal SmiQueryMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, Type userDefinedType, SmiMetaData[] columns, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, bool allowsDBNull, string serverName, string catalogName, string schemaName, string tableName, string columnName, SqlBoolean isKey, bool isIdentity, bool isReadOnly, SqlBoolean isExpression, SqlBoolean isAliased, SqlBoolean isHidden) : this(dbType, maxLength, precision, scale, localeId, compareOptions, userDefinedType, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, allowsDBNull, serverName, catalogName, schemaName, tableName, columnName, isKey, isIdentity, isReadOnly, isExpression, isAliased, isHidden)
 {
 }