// SMI V200 ctor. internal SmiParameterMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, ParameterDirection direction) : this(dbType, maxLength, precision, scale, localeId, compareOptions, null, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, direction) { }
private static SmiMetaDataPropertyCollection CreateEmptyInstance() { var emptyInstance = new SmiMetaDataPropertyCollection(); emptyInstance.SetReadOnly(); return(emptyInstance); }
// SMI V220 ctor. internal SmiQueryMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, SqlBoolean isKey ) : base(dbType, maxLength, precision, scale, localeId, compareOptions, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, isKey ) { }
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; }
// SMI V220 ctor. internal SmiExtendedMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : base(dbType, maxLength, precision, scale, localeId, compareOptions, isMultiValued, fieldMetaData, extendedProperties) { Debug.Assert(null == name || MaxNameLength >= name.Length, "Name is too long"); _name = name; _typeSpecificNamePart1 = typeSpecificNamePart1; _typeSpecificNamePart2 = typeSpecificNamePart2; _typeSpecificNamePart3 = typeSpecificNamePart3; }
// SMI V220 ctor. internal SmiParameterMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList <SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, ParameterDirection direction) : base(dbType, maxLength, precision, scale, localeId, compareOptions, 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; }
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; }
// SMI V220 ctor. internal SmiQueryMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, 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, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, allowsDBNull, serverName, catalogName, schemaName, tableName, columnName, isKey, isIdentity, isColumnSet) { _isReadOnly = isReadOnly; _isExpression = isExpression; _isAliased = isAliased; _isHidden = isHidden; }
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; }
private SmiMetaData(System.Data.SqlDbType sqlDbType, long maxLength, byte precision, byte scale, SqlCompareOptions compareOptions) { this._databaseType = sqlDbType; this._maxLength = maxLength; this._precision = precision; this._scale = scale; this._compareOptions = compareOptions; this._localeId = 0L; this._clrType = null; this._isMultiValued = false; this._fieldMetaData = __emptyFieldList; this._extendedProperties = SmiMetaDataPropertyCollection.EmptyInstance; }
// 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; _isMultiValued = smdDflt._isMultiValued; _fieldMetaData = smdDflt._fieldMetaData; // This is ok due to immutability _extendedProperties = smdDflt._extendedProperties; // This is ok due to immutability }
private void SetDefaultsForType(System.Data.SqlDbType dbType) { SmiMetaData defaultForType = GetDefaultForType(dbType); this._databaseType = dbType; this._maxLength = defaultForType.MaxLength; this._precision = defaultForType.Precision; this._scale = defaultForType.Scale; this._localeId = defaultForType.LocaleId; this._compareOptions = defaultForType.CompareOptions; this._clrType = null; this._isMultiValued = defaultForType._isMultiValued; this._fieldMetaData = defaultForType._fieldMetaData; this._extendedProperties = defaultForType._extendedProperties; }
private bool _isColumnSet; // Is this column the XML representation of a columnset? // SMI V220 ctor. internal SmiStorageMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, 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, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3) { _allowsDBNull = allowsDBNull; _serverName = serverName; _catalogName = catalogName; _schemaName = schemaName; _tableName = tableName; _columnName = columnName; _isKey = isKey; _isIdentity = isIdentity; _isColumnSet = isColumnSet; }
// 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; _isMultiValued = false; _fieldMetaData = s_emptyFieldList; _extendedProperties = SmiMetaDataPropertyCollection.EmptyInstance; }
// SMI V200 ctor. internal SmiMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList <SmiExtendedMetaData> fieldTypes, SmiMetaDataPropertyCollection extendedProperties) : this(dbType, maxLength, precision, scale, localeId, compareOptions, null, isMultiValued, fieldTypes, extendedProperties) { }
private void GetActualFieldsAndProperties(out List<SmiExtendedMetaData> fields, out SmiMetaDataPropertyCollection props, out ParameterPeekAheadValue peekAhead) { fields = null; props = null; peekAhead = null; object coercedValue = this.GetCoercedValue(); if (coercedValue is DataTable) { DataTable parent = coercedValue as DataTable; if (parent.Columns.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } fields = new List<SmiExtendedMetaData>(parent.Columns.Count); bool[] collection = new bool[parent.Columns.Count]; bool flag = false; if ((parent.PrimaryKey != null) && (0 < parent.PrimaryKey.Length)) { foreach (DataColumn column in parent.PrimaryKey) { collection[column.Ordinal] = true; flag = true; } } for (int i = 0; i < parent.Columns.Count; i++) { fields.Add(MetaDataUtilsSmi.SmiMetaDataFromDataColumn(parent.Columns[i], parent)); if (!flag && parent.Columns[i].Unique) { collection[i] = true; flag = true; } } if (flag) { props = new SmiMetaDataPropertyCollection(); props[SmiPropertySelector.UniqueKey] = new SmiUniqueKeyProperty(new List<bool>(collection)); } } else if (coercedValue is SqlDataReader) { fields = new List<SmiExtendedMetaData>(((SqlDataReader) coercedValue).GetInternalSmiMetaData()); if (fields.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } bool[] flagArray6 = new bool[fields.Count]; bool flag5 = false; for (int j = 0; j < fields.Count; j++) { SmiQueryMetaData data2 = fields[j] as SmiQueryMetaData; if (((data2 != null) && !data2.IsKey.IsNull) && data2.IsKey.Value) { flagArray6[j] = true; flag5 = true; } } if (flag5) { props = new SmiMetaDataPropertyCollection(); props[SmiPropertySelector.UniqueKey] = new SmiUniqueKeyProperty(new List<bool>(flagArray6)); } } else { if (coercedValue is IEnumerable<SqlDataRecord>) { IEnumerator<SqlDataRecord> enumerator = ((IEnumerable<SqlDataRecord>) coercedValue).GetEnumerator(); SqlDataRecord current = null; try { if (!enumerator.MoveNext()) { throw SQL.IEnumerableOfSqlDataRecordHasNoRows(); } current = enumerator.Current; int fieldCount = current.FieldCount; if (0 >= fieldCount) { throw SQL.NotEnoughColumnsInStructuredType(); } bool[] flagArray5 = new bool[fieldCount]; bool[] flagArray4 = new bool[fieldCount]; bool[] flagArray = new bool[fieldCount]; int sortOrdinal = -1; bool flag4 = false; bool flag3 = false; int num7 = 0; SmiOrderProperty.SmiColumnOrder[] orderArray = new SmiOrderProperty.SmiColumnOrder[fieldCount]; fields = new List<SmiExtendedMetaData>(fieldCount); for (int k = 0; k < fieldCount; k++) { SqlMetaData sqlMetaData = current.GetSqlMetaData(k); fields.Add(MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(sqlMetaData)); if (sqlMetaData.IsUniqueKey) { flagArray5[k] = true; flag4 = true; } if (sqlMetaData.UseServerDefault) { flagArray4[k] = true; flag3 = true; } orderArray[k].Order = sqlMetaData.SortOrder; if (SortOrder.Unspecified != sqlMetaData.SortOrder) { if (fieldCount <= sqlMetaData.SortOrdinal) { throw SQL.SortOrdinalGreaterThanFieldCount(k, sqlMetaData.SortOrdinal); } if (flagArray[sqlMetaData.SortOrdinal]) { throw SQL.DuplicateSortOrdinal(sqlMetaData.SortOrdinal); } orderArray[k].SortOrdinal = sqlMetaData.SortOrdinal; flagArray[sqlMetaData.SortOrdinal] = true; if (sqlMetaData.SortOrdinal > sortOrdinal) { sortOrdinal = sqlMetaData.SortOrdinal; } num7++; } } if (flag4) { props = new SmiMetaDataPropertyCollection(); props[SmiPropertySelector.UniqueKey] = new SmiUniqueKeyProperty(new List<bool>(flagArray5)); } if (flag3) { if (props == null) { props = new SmiMetaDataPropertyCollection(); } props[SmiPropertySelector.DefaultFields] = new SmiDefaultFieldsProperty(new List<bool>(flagArray4)); } if (0 < num7) { if (sortOrdinal >= num7) { int index = 0; while (index < num7) { if (!flagArray[index]) { break; } index++; } throw SQL.MissingSortOrdinal(index); } if (props == null) { props = new SmiMetaDataPropertyCollection(); } props[SmiPropertySelector.SortOrder] = new SmiOrderProperty(new List<SmiOrderProperty.SmiColumnOrder>(orderArray)); } peekAhead = new ParameterPeekAheadValue(); peekAhead.Enumerator = enumerator; peekAhead.FirstRecord = current; enumerator = null; return; } finally { if (enumerator != null) { enumerator.Dispose(); } } } if (coercedValue is DbDataReader) { DataTable schemaTable = ((DbDataReader) coercedValue).GetSchemaTable(); if (schemaTable.Rows.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } int count = schemaTable.Rows.Count; fields = new List<SmiExtendedMetaData>(count); bool[] flagArray3 = new bool[count]; bool flag2 = false; int ordinal = schemaTable.Columns[SchemaTableColumn.IsKey].Ordinal; int columnIndex = schemaTable.Columns[SchemaTableColumn.ColumnOrdinal].Ordinal; for (int m = 0; m < count; m++) { DataRow schemaRow = schemaTable.Rows[m]; SmiExtendedMetaData item = MetaDataUtilsSmi.SmiMetaDataFromSchemaTableRow(schemaRow); int num2 = m; if (!schemaRow.IsNull(columnIndex)) { num2 = (int) schemaRow[columnIndex]; } if ((num2 < count) && (num2 >= 0)) { goto Label_04B7; } throw SQL.InvalidSchemaTableOrdinals(); Label_04AF: fields.Add(null); Label_04B7: if (num2 > fields.Count) { goto Label_04AF; } if (fields.Count == num2) { fields.Add(item); } else { if (fields[num2] != null) { throw SQL.InvalidSchemaTableOrdinals(); } fields[num2] = item; } if (!schemaRow.IsNull(ordinal) && ((bool) schemaRow[ordinal])) { flagArray3[num2] = true; flag2 = true; } } if (flag2) { props = new SmiMetaDataPropertyCollection(); props[SmiPropertySelector.UniqueKey] = new SmiUniqueKeyProperty(new List<bool>(flagArray3)); } } } }
private static SmiMetaDataPropertyCollection CreateEmptyInstance() { var emptyInstance = new SmiMetaDataPropertyCollection(); emptyInstance.SetReadOnly(); return emptyInstance; }
// SMI V220 ctor. internal SmiExtendedMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, string udtAssemblyQualifiedName, bool isMultiValued, IList<SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3) : base(dbType, maxLength, precision, scale, localeId, compareOptions, udtAssemblyQualifiedName, isMultiValued, fieldMetaData, extendedProperties) { Debug.Assert(null == name || MaxNameLength >= name.Length, "Name is too long"); _name = name; _typeSpecificNamePart1 = typeSpecificNamePart1; _typeSpecificNamePart2 = typeSpecificNamePart2; _typeSpecificNamePart3 = typeSpecificNamePart3; }
// 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; }
// 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) { }
// 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; }
private void GetActualFieldsAndProperties(out List<MSS.SmiExtendedMetaData> fields, out SmiMetaDataPropertyCollection props, out ParameterPeekAheadValue peekAhead) { fields = null; props = null; peekAhead = null; object value = GetCoercedValue(); if (value is SqlDataReader) { fields = new List<MSS.SmiExtendedMetaData>(((SqlDataReader)value).GetInternalSmiMetaData()); if (fields.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } bool[] keyCols = new bool[fields.Count]; bool hasKey = false; for (int i = 0; i < fields.Count; i++) { MSS.SmiQueryMetaData qmd = fields[i] as MSS.SmiQueryMetaData; if (null != qmd && !qmd.IsKey.IsNull && qmd.IsKey.Value) { keyCols[i] = true; hasKey = true; } } // Add unique key property, if any found. if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } } else if (value is IEnumerable<SqlDataRecord>) { // must grab the first record of the enumerator to get the metadata IEnumerator<MSS.SqlDataRecord> enumerator = ((IEnumerable<MSS.SqlDataRecord>)value).GetEnumerator(); MSS.SqlDataRecord firstRecord = null; try { // no need for fields if there's no rows or no columns -- we'll be sending a null instance anyway. if (enumerator.MoveNext()) { firstRecord = enumerator.Current; int fieldCount = firstRecord.FieldCount; if (0 < fieldCount) { // It's valid! Grab those fields. bool[] keyCols = new bool[fieldCount]; bool[] defaultFields = new bool[fieldCount]; bool[] sortOrdinalSpecified = new bool[fieldCount]; int maxSortOrdinal = -1; // largest sort ordinal seen, used to optimize locating holes in the list bool hasKey = false; bool hasDefault = false; int sortCount = 0; SmiOrderProperty.SmiColumnOrder[] sort = new SmiOrderProperty.SmiColumnOrder[fieldCount]; fields = new List<MSS.SmiExtendedMetaData>(fieldCount); for (int i = 0; i < fieldCount; i++) { SqlMetaData colMeta = firstRecord.GetSqlMetaData(i); fields.Add(MSS.MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(colMeta)); if (colMeta.IsUniqueKey) { keyCols[i] = true; hasKey = true; } if (colMeta.UseServerDefault) { defaultFields[i] = true; hasDefault = true; } sort[i].Order = colMeta.SortOrder; if (SortOrder.Unspecified != colMeta.SortOrder) { // SqlMetaData takes care of checking for negative sort ordinals with specified sort order // bail early if there's no way sort order could be monotonically increasing if (fieldCount <= colMeta.SortOrdinal) { throw SQL.SortOrdinalGreaterThanFieldCount(i, colMeta.SortOrdinal); } // Check to make sure we haven't seen this ordinal before if (sortOrdinalSpecified[colMeta.SortOrdinal]) { throw SQL.DuplicateSortOrdinal(colMeta.SortOrdinal); } sort[i].SortOrdinal = colMeta.SortOrdinal; sortOrdinalSpecified[colMeta.SortOrdinal] = true; if (colMeta.SortOrdinal > maxSortOrdinal) { maxSortOrdinal = colMeta.SortOrdinal; } sortCount++; } } if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } if (hasDefault) { // May have already created props list in unique key handling if (null == props) { props = new SmiMetaDataPropertyCollection(); } props[MSS.SmiPropertySelector.DefaultFields] = new MSS.SmiDefaultFieldsProperty(new List<bool>(defaultFields)); } if (0 < sortCount) { // validate monotonically increasing sort order. // Since we already checked for duplicates, we just need // to watch for values outside of the sortCount range. if (maxSortOrdinal >= sortCount) { // there is at least one hole, find the first one int i; for (i = 0; i < sortCount; i++) { if (!sortOrdinalSpecified[i]) { break; } } Debug.Assert(i < sortCount, "SqlParameter.GetActualFieldsAndProperties: SortOrdinal hole-finding algorithm failed!"); throw SQL.MissingSortOrdinal(i); } // May have already created props list if (null == props) { props = new SmiMetaDataPropertyCollection(); } props[MSS.SmiPropertySelector.SortOrder] = new MSS.SmiOrderProperty( new List<SmiOrderProperty.SmiColumnOrder>(sort)); } // pack it up so we don't have to rewind to send the first value peekAhead = new ParameterPeekAheadValue(); peekAhead.Enumerator = enumerator; peekAhead.FirstRecord = firstRecord; // now that it's all packaged, make sure we don't dispose it. enumerator = null; } else { throw SQL.NotEnoughColumnsInStructuredType(); } } else { throw SQL.IEnumerableOfSqlDataRecordHasNoRows(); } } finally { if (enumerator != null) { enumerator.Dispose(); } } } else if (value is DbDataReader) { // For ProjectK\CoreCLR, DbDataReader no longer supports GetSchema // So instead we will attempt to generate the metadata from the Field Type alone var reader = (DbDataReader)value; if (reader.FieldCount <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } fields = new List<MSS.SmiExtendedMetaData>(reader.FieldCount); for (int i = 0; i < reader.FieldCount; i++) { fields.Add(MSS.MetaDataUtilsSmi.SmiMetaDataFromType(reader.GetName(i), reader.GetFieldType(i))); } } }
internal SmiMetaData(System.Data.SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, System.Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList<SmiExtendedMetaData> fieldTypes, SmiMetaDataPropertyCollection extendedProperties) { this.SetDefaultsForType(dbType); switch (dbType) { case System.Data.SqlDbType.Binary: case System.Data.SqlDbType.VarBinary: this._maxLength = maxLength; goto Label_01BF; case System.Data.SqlDbType.Char: case System.Data.SqlDbType.NChar: case System.Data.SqlDbType.NVarChar: case System.Data.SqlDbType.VarChar: this._maxLength = maxLength; this._localeId = localeId; this._compareOptions = compareOptions; goto Label_01BF; case System.Data.SqlDbType.Decimal: this._precision = precision; this._scale = scale; this._maxLength = __maxLenFromPrecision[precision - 1]; goto Label_01BF; case System.Data.SqlDbType.NText: case System.Data.SqlDbType.Text: this._localeId = localeId; this._compareOptions = compareOptions; goto Label_01BF; case System.Data.SqlDbType.Udt: this._clrType = userDefinedType; if (null == userDefinedType) { this._maxLength = maxLength; break; } this._maxLength = SerializationHelperSql9.GetUdtMaxLength(userDefinedType); break; case System.Data.SqlDbType.Structured: if (fieldTypes != null) { this._fieldMetaData = new List<SmiExtendedMetaData>(fieldTypes).AsReadOnly(); } this._isMultiValued = isMultiValued; this._maxLength = this._fieldMetaData.Count; goto Label_01BF; case System.Data.SqlDbType.Time: this._scale = scale; this._maxLength = 5 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; case System.Data.SqlDbType.DateTime2: this._scale = scale; this._maxLength = 8 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; case System.Data.SqlDbType.DateTimeOffset: this._scale = scale; this._maxLength = 10 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; default: goto Label_01BF; } this._udtAssemblyQualifiedName = udtAssemblyQualifiedName; Label_01BF: if (extendedProperties != null) { extendedProperties.SetReadOnly(); this._extendedProperties = extendedProperties; } }
// 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) { }
internal SmiMetaData(System.Data.SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, System.Type userDefinedType, string udtAssemblyQualifiedName, bool isMultiValued, IList <SmiExtendedMetaData> fieldTypes, SmiMetaDataPropertyCollection extendedProperties) { this.SetDefaultsForType(dbType); switch (dbType) { case System.Data.SqlDbType.Binary: case System.Data.SqlDbType.VarBinary: this._maxLength = maxLength; goto Label_01BF; case System.Data.SqlDbType.Char: case System.Data.SqlDbType.NChar: case System.Data.SqlDbType.NVarChar: case System.Data.SqlDbType.VarChar: this._maxLength = maxLength; this._localeId = localeId; this._compareOptions = compareOptions; goto Label_01BF; case System.Data.SqlDbType.Decimal: this._precision = precision; this._scale = scale; this._maxLength = __maxLenFromPrecision[precision - 1]; goto Label_01BF; case System.Data.SqlDbType.NText: case System.Data.SqlDbType.Text: this._localeId = localeId; this._compareOptions = compareOptions; goto Label_01BF; case System.Data.SqlDbType.Udt: this._clrType = userDefinedType; if (null == userDefinedType) { this._maxLength = maxLength; break; } this._maxLength = SerializationHelperSql9.GetUdtMaxLength(userDefinedType); break; case System.Data.SqlDbType.Structured: if (fieldTypes != null) { this._fieldMetaData = new List <SmiExtendedMetaData>(fieldTypes).AsReadOnly(); } this._isMultiValued = isMultiValued; this._maxLength = this._fieldMetaData.Count; goto Label_01BF; case System.Data.SqlDbType.Time: this._scale = scale; this._maxLength = 5 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; case System.Data.SqlDbType.DateTime2: this._scale = scale; this._maxLength = 8 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; case System.Data.SqlDbType.DateTimeOffset: this._scale = scale; this._maxLength = 10 - __maxVarTimeLenOffsetFromScale[scale]; goto Label_01BF; default: goto Label_01BF; } this._udtAssemblyQualifiedName = udtAssemblyQualifiedName; Label_01BF: if (extendedProperties != null) { extendedProperties.SetReadOnly(); this._extendedProperties = extendedProperties; } }
static SmiMetaDataPropertyCollection() { EmptyInstance = new SmiMetaDataPropertyCollection(); EmptyInstance.SetReadOnly(); }
private void GetActualFieldsAndProperties(out List<MSS.SmiExtendedMetaData> fields, out SmiMetaDataPropertyCollection props, out ParameterPeekAheadValue peekAhead) { fields = null; props = null; peekAhead = null; object value = GetCoercedValue(); if (value is DataTable) { DataTable dt = value as DataTable; if (dt.Columns.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } fields = new List<MSS.SmiExtendedMetaData>(dt.Columns.Count); bool[] keyCols = new bool[dt.Columns.Count]; bool hasKey = false; // set up primary key as unique key list // do this prior to general metadata loop to favor the primary key if (null != dt.PrimaryKey && 0 < dt.PrimaryKey.Length) { foreach(DataColumn col in dt.PrimaryKey) { keyCols[col.Ordinal] = true; hasKey = true; } } for(int i=0; i<dt.Columns.Count; i++) { fields.Add(MSS.MetaDataUtilsSmi.SmiMetaDataFromDataColumn(dt.Columns[i], dt)); // DataColumn uniqueness is only for a single column, so don't add // more than one. (keyCols.Count first for assumed minimal perf benefit) if (!hasKey && dt.Columns[i].Unique) { keyCols[i] = true; hasKey = true; } } // Add unique key property, if any found. if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } } else if (value is SqlDataReader) { fields = new List<MSS.SmiExtendedMetaData>(((SqlDataReader)value).GetInternalSmiMetaData()); if (fields.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } bool[] keyCols = new bool[fields.Count]; bool hasKey = false; for(int i=0; i<fields.Count; i++) { MSS.SmiQueryMetaData qmd = fields[i] as MSS.SmiQueryMetaData; if (null != qmd && !qmd.IsKey.IsNull && qmd.IsKey.Value) { keyCols[i] = true; hasKey = true; } } // Add unique key property, if any found. if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } } else if (value is IEnumerable<SqlDataRecord>) { // must grab the first record of the enumerator to get the metadata IEnumerator<MSS.SqlDataRecord> enumerator = ((IEnumerable<MSS.SqlDataRecord>) value).GetEnumerator(); MSS.SqlDataRecord firstRecord = null; try { // no need for fields if there's no rows or no columns -- we'll be sending a null instance anyway. if (enumerator.MoveNext()) { firstRecord = enumerator.Current; int fieldCount = firstRecord.FieldCount; if (0 < fieldCount) { // It's valid! Grab those fields. bool[] keyCols = new bool[fieldCount]; bool[] defaultFields = new bool[fieldCount]; bool[] sortOrdinalSpecified = new bool[fieldCount]; int maxSortOrdinal = -1; // largest sort ordinal seen, used to optimize locating holes in the list bool hasKey = false; bool hasDefault = false; int sortCount = 0; SmiOrderProperty.SmiColumnOrder[] sort = new SmiOrderProperty.SmiColumnOrder[fieldCount]; fields = new List<MSS.SmiExtendedMetaData>(fieldCount); for (int i = 0; i < fieldCount; i++) { SqlMetaData colMeta = firstRecord.GetSqlMetaData(i); fields.Add(MSS.MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(colMeta)); if (colMeta.IsUniqueKey) { keyCols[i] = true; hasKey = true; } if (colMeta.UseServerDefault) { defaultFields[i] = true; hasDefault = true; } sort[i].Order = colMeta.SortOrder; if (SortOrder.Unspecified != colMeta.SortOrder) { // SqlMetaData takes care of checking for negative sort ordinals with specified sort order // bail early if there's no way sort order could be monotonically increasing if (fieldCount <= colMeta.SortOrdinal) { throw SQL.SortOrdinalGreaterThanFieldCount(i, colMeta.SortOrdinal); } // Check to make sure we haven't seen this ordinal before if (sortOrdinalSpecified[colMeta.SortOrdinal]) { throw SQL.DuplicateSortOrdinal(colMeta.SortOrdinal); } sort[i].SortOrdinal = colMeta.SortOrdinal; sortOrdinalSpecified[colMeta.SortOrdinal] = true; if (colMeta.SortOrdinal > maxSortOrdinal) { maxSortOrdinal = colMeta.SortOrdinal; } sortCount++; } } if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } if (hasDefault) { // May have already created props list in unique key handling if (null == props) { props = new SmiMetaDataPropertyCollection(); } props[MSS.SmiPropertySelector.DefaultFields] = new MSS.SmiDefaultFieldsProperty(new List<bool>(defaultFields)); } if (0 < sortCount) { // validate monotonically increasing sort order. // Since we already checked for duplicates, we just need // to watch for values outside of the sortCount range. if (maxSortOrdinal >= sortCount) { // there is at least one hole, find the first one int i; for (i = 0; i < sortCount; i++) { if (!sortOrdinalSpecified[i]) { break; } } Debug.Assert(i < sortCount, "SqlParameter.GetActualFieldsAndProperties: SortOrdinal hole-finding algorithm failed!"); throw SQL.MissingSortOrdinal(i); } // May have already created props list if (null == props) { props = new SmiMetaDataPropertyCollection(); } props[MSS.SmiPropertySelector.SortOrder] = new MSS.SmiOrderProperty( new List<SmiOrderProperty.SmiColumnOrder>(sort)); } // pack it up so we don't have to rewind to send the first value peekAhead = new ParameterPeekAheadValue(); peekAhead.Enumerator = enumerator; peekAhead.FirstRecord = firstRecord; // now that it's all packaged, make sure we don't dispose it. enumerator = null; } else { throw SQL.NotEnoughColumnsInStructuredType(); } } else { throw SQL.IEnumerableOfSqlDataRecordHasNoRows(); } } finally { if (enumerator != null) { enumerator.Dispose(); } } } else if (value is DbDataReader) { DataTable schema = ((DbDataReader)value).GetSchemaTable(); if (schema.Rows.Count <= 0) { throw SQL.NotEnoughColumnsInStructuredType(); } int fieldCount = schema.Rows.Count; fields = new List<MSS.SmiExtendedMetaData>(fieldCount); bool[] keyCols = new bool[fieldCount]; bool hasKey = false; int ordinalForIsKey = schema.Columns[SchemaTableColumn.IsKey].Ordinal; int ordinalForColumnOrdinal = schema.Columns[SchemaTableColumn.ColumnOrdinal].Ordinal; // Extract column metadata for(int rowOrdinal=0; rowOrdinal<fieldCount; rowOrdinal++) { DataRow row = schema.Rows[rowOrdinal]; SmiExtendedMetaData candidateMd = MSS.MetaDataUtilsSmi.SmiMetaDataFromSchemaTableRow(row); // Determine destination ordinal. Allow for ordinal not specified by assuming rowOrdinal *is* columnOrdinal // in that case, but don't worry about mix-and-match of the two techniques int columnOrdinal = rowOrdinal; if (!row.IsNull(ordinalForColumnOrdinal)) { columnOrdinal = (int) row[ordinalForColumnOrdinal]; } // After this point, things we are creating (keyCols, fields) should be accessed by columnOrdinal // while the source should just be accessed via "row". // Watch for out-of-range ordinals if (columnOrdinal >= fieldCount || columnOrdinal < 0) { throw SQL.InvalidSchemaTableOrdinals(); } // extend empty space if out-of-order ordinal while (columnOrdinal > fields.Count) { fields.Add(null); } // Now add the candidate to the list if (fields.Count == columnOrdinal) { fields.Add(candidateMd); } else { // Disallow two columns using the same ordinal (even if due to mixing null and non-null columnOrdinals) if (fields[columnOrdinal] != null) { throw SQL.InvalidSchemaTableOrdinals(); } // Don't use insert, since it shifts all later columns down a notch fields[columnOrdinal] = candidateMd; } // Propogate key information if (!row.IsNull(ordinalForIsKey) && (bool)row[ordinalForIsKey]) { keyCols[columnOrdinal] = true; hasKey = true; } } #if DEBUG // Check for holes // Above loop logic prevents holes since: // 1) loop processes fieldcount # of columns // 2) no ordinals outside continuous range from 0 to fieldcount - 1 are allowed // 3) no duplicate ordinals are allowed // But assert no holes to be sure. foreach (SmiExtendedMetaData md in fields) { Debug.Assert(null != md, "Shouldn't be able to have holes, since original loop algorithm prevents such."); } #endif // Add unique key property, if any defined. if (hasKey) { props = new SmiMetaDataPropertyCollection(); props[MSS.SmiPropertySelector.UniqueKey] = new MSS.SmiUniqueKeyProperty(new List<bool>(keyCols)); } } }
// SMI V220 ctor. internal SmiQueryMetaData(SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, bool isMultiValued, IList<SmiExtendedMetaData> fieldMetaData, SmiMetaDataPropertyCollection extendedProperties, string name, string typeSpecificNamePart1, string typeSpecificNamePart2, string typeSpecificNamePart3, SqlBoolean isKey ) : base(dbType, maxLength, precision, scale, localeId, compareOptions, isMultiValued, fieldMetaData, extendedProperties, name, typeSpecificNamePart1, typeSpecificNamePart2, typeSpecificNamePart3, isKey ) { }
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) { }
// 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) { }
// 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 }
// SMI V220 ctor. internal SmiMetaData( SqlDbType dbType, long maxLength, byte precision, byte scale, long localeId, SqlCompareOptions compareOptions, 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 ? "writable" : "null")); Debug.Assert(null != _fieldMetaData && _fieldMetaData.IsReadOnly, "SmiMetaData.ctor: _fieldMetaData is " + (null != _fieldMetaData ? "writable" : "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 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 }
// 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 }
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) { this._direction = direction; }