private void SetValueFrameworkSpecific(int ordinal, object value) { SqlMetaData metaData = GetSqlMetaData(ordinal); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, isMultiValued: false, value, metaData.Type, SmiVersion ); if (typeCode == ExtendedClrTypeCode.Invalid) { throw ADP.InvalidCast(); } if (SmiVersion >= SmiContextFactory.Sql2008Version) { ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0, peekAhead: null); } else { ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0); } }
// SqlDataRecord public API /// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/ctor/*' /> public SqlDataRecord(params SqlMetaData[] metaData) { // Initial consistency check if (null == metaData) { throw ADP.ArgumentNull(nameof(metaData)); } _columnMetaData = new SqlMetaData[metaData.Length]; _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; for (int i = 0; i < _columnSmiMetaData.Length; i++) { if (null == metaData[i]) { throw ADP.ArgumentNull($"{nameof(metaData)}[{i}]"); } _columnMetaData[i] = metaData[i]; _columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(_columnMetaData[i]); } _eventSink = new SmiEventSink_Default(); _recordBuffer = new MemoryRecordBuffer(_columnSmiMetaData); _usesStringStorageForXml = true; _eventSink.ProcessMessagesAndThrow(); }
/// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValues/*' /> // ISqlUpdateableRecord Implementation public virtual int SetValues(params object[] values) { EnsureSubclassOverride(); if (null == values) { throw ADP.ArgumentNull(nameof(values)); } // Allow values array longer than FieldCount, just ignore the extra cells. int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length; ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength]; // Verify all data values as acceptable before changing current state. for (int i = 0; i < copyLength; i++) { SqlMetaData metaData = GetSqlMetaData(i); typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, false /* isMultiValued */, values[i], metaData.Type); if (ExtendedClrTypeCode.Invalid == typeCodes[i]) { throw ADP.InvalidCast(); } } // Now move the data (it'll only throw if someone plays with the values array between // the validation loop and here, or if an invalid UDT was sent). for (int i = 0; i < copyLength; i++) { ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], 0, 0, null); } return(copyLength); }
internal SqlDataRecord(SmiRecordBuffer recordBuffer, params SmiExtendedMetaData[] metaData) { Debug.Assert(null != recordBuffer, "invalid attempt to instantiate SqlDataRecord with null SmiRecordBuffer"); Debug.Assert(null != metaData, "invalid attempt to instantiate SqlDataRecord with null SmiExtendedMetaData[]"); _columnMetaData = new SqlMetaData[metaData.Length]; _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; for (int i = 0; i < _columnSmiMetaData.Length; i++) { _columnSmiMetaData[i] = metaData[i]; _columnMetaData[i] = MetaDataUtilsSmi.SmiExtendedMetaDataToSqlMetaData(_columnSmiMetaData[i]); } _eventSink = new SmiEventSink_Default(); if (InOutOfProcHelper.InProc) { _recordContext = SmiContextFactory.Instance.GetCurrentContext(); } else { _recordContext = null; } _recordBuffer = recordBuffer; _eventSink.ProcessMessagesAndThrow(); }
/// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValue/*' /> public virtual void SetValue(int ordinal, object value) { EnsureSubclassOverride(); SqlMetaData metaData = GetSqlMetaData(ordinal); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, isMultiValued: false, value, metaData.Type, SmiVersion ); if (typeCode == ExtendedClrTypeCode.Invalid) { throw ADP.InvalidCast(); } if (SmiVersion >= SmiContextFactory.KatmaiVersion) { ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0, length: 0, peekAhead: null); } else { ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0); } }
/// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValue/*' /> public virtual void SetValue(int ordinal, object value) { EnsureSubclassOverride(); SqlMetaData metaData = GetSqlMetaData(ordinal); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, false /* isMultiValued */, value, metaData.Type); if (ExtendedClrTypeCode.Invalid == typeCode) { throw ADP.InvalidCast(); } ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, 0, 0, null); }
// SqlDataRecord public API /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/ctor/*' /> public SqlDataRecord(params SqlMetaData[] metaData) { // Initial consistency check if (metaData == null) { throw ADP.ArgumentNull(nameof(metaData)); } _columnMetaData = new SqlMetaData[metaData.Length]; _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; #if NETFRAMEWORK ulong smiVersion = SmiVersion; #endif for (int i = 0; i < _columnSmiMetaData.Length; i++) { if (metaData[i] == null) { throw ADP.ArgumentNull($"{nameof(metaData)}[{i}]"); } _columnMetaData[i] = metaData[i]; _columnSmiMetaData[i] = MetaDataUtilsSmi.SqlMetaDataToSmiExtendedMetaData(_columnMetaData[i]); #if NETFRAMEWORK if (!MetaDataUtilsSmi.IsValidForSmiVersion(_columnSmiMetaData[i], smiVersion)) { throw ADP.VersionDoesNotSupportDataType(_columnSmiMetaData[i].TypeName); } #endif } _eventSink = new SmiEventSink_Default(); #if NETFRAMEWORK if (InOutOfProcHelper.InProc) { _recordContext = SmiContextFactory.Instance.GetCurrentContext(); _recordBuffer = _recordContext.CreateRecordBuffer(_columnSmiMetaData, _eventSink); _usesStringStorageForXml = false; } else { _recordContext = null; _recordBuffer = new MemoryRecordBuffer(_columnSmiMetaData); _usesStringStorageForXml = true; } #else _recordBuffer = new MemoryRecordBuffer(_columnSmiMetaData); _eventSink.ProcessMessagesAndThrow(); #endif }
/// <include file='../../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValue/*' /> public virtual void SetValue(int ordinal, object value) { SqlMetaData metaData = GetSqlMetaData(ordinal); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, isMultiValued: false, value, metaData.Type ); if (typeCode == ExtendedClrTypeCode.Invalid) { throw ADP.InvalidCast(); } ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0, length: 0, peekAhead: null); }
internal SqlDataRecord(SmiRecordBuffer recordBuffer, params SmiExtendedMetaData[] metaData) { Debug.Assert(recordBuffer != null, "invalid attempt to instantiate SqlDataRecord with null SmiRecordBuffer"); Debug.Assert(metaData != null, "invalid attempt to instantiate SqlDataRecord with null SmiExtendedMetaData[]"); _columnMetaData = new SqlMetaData[metaData.Length]; _columnSmiMetaData = new SmiExtendedMetaData[metaData.Length]; for (int i = 0; i < _columnSmiMetaData.Length; i++) { _columnSmiMetaData[i] = metaData[i]; _columnMetaData[i] = MetaDataUtilsSmi.SmiExtendedMetaDataToSqlMetaData(_columnSmiMetaData[i]); } _eventSink = new SmiEventSink_Default(); _recordBuffer = recordBuffer; _eventSink.ProcessMessagesAndThrow(); }
private int SetValuesFrameworkSpecific(params object[] values) { if (values == null) { throw ADP.ArgumentNull(nameof(values)); } // Allow values array longer than FieldCount, just ignore the extra cells. int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length; ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength]; // Verify all data values as acceptable before changing current state. for (int i = 0; i < copyLength; i++) { SqlMetaData metaData = GetSqlMetaData(i); typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( metaData.SqlDbType, isMultiValued: false, values[i], metaData.Type, SmiVersion ); if (typeCodes[i] == ExtendedClrTypeCode.Invalid) { throw ADP.InvalidCast(); } } // Now move the data (it'll only throw if someone plays with the values array between // the validation loop and here, or if an invalid UDT was sent). for (int i = 0; i < copyLength; i++) { if (SmiVersion >= SmiContextFactory.Sql2008Version) { ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0, peekAhead: null); } else { ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0); } } return(copyLength); }
internal static void FillCompatibleITypedSettersFromRecord(SmiEventSink_Default sink, ITypedSettersV3 setters, SmiMetaData[] metaData, SqlDataRecord record, SmiDefaultFieldsProperty useDefaultValues) { for (int i = 0; i < metaData.Length; ++i) { if (null != useDefaultValues && useDefaultValues[i]) { continue; } if (record.IsDBNull(i)) { ValueUtilsSmi.SetDBNull_Unchecked(sink, setters, i); } else { switch (metaData[i].SqlDbType) { case SqlDbType.BigInt: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int64)); SetInt64_Unchecked(sink, setters, i, record.GetInt64(i)); break; case SqlDbType.Binary: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlBytes)); SetBytes_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.Bit: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Boolean)); SetBoolean_Unchecked(sink, setters, i, record.GetBoolean(i)); break; case SqlDbType.Char: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlChars)); SetChars_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.DateTime: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTime)); SetDateTime_Checked(sink, setters, i, metaData[i], record.GetDateTime(i)); break; case SqlDbType.Decimal: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlDecimal)); SetSqlDecimal_Unchecked(sink, setters, i, record.GetSqlDecimal(i)); break; case SqlDbType.Float: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Double)); SetDouble_Unchecked(sink, setters, i, record.GetDouble(i)); break; case SqlDbType.Image: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlBytes)); SetBytes_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.Int: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int32)); SetInt32_Unchecked(sink, setters, i, record.GetInt32(i)); break; case SqlDbType.Money: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlMoney)); SetSqlMoney_Unchecked(sink, setters, i, metaData[i], record.GetSqlMoney(i)); break; case SqlDbType.NChar: case SqlDbType.NText: case SqlDbType.NVarChar: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlChars)); SetChars_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.Real: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Single)); SetSingle_Unchecked(sink, setters, i, record.GetFloat(i)); break; case SqlDbType.UniqueIdentifier: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Guid)); SetGuid_Unchecked(sink, setters, i, record.GetGuid(i)); break; case SqlDbType.SmallDateTime: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.DateTime)); SetDateTime_Checked(sink, setters, i, metaData[i], record.GetDateTime(i)); break; case SqlDbType.SmallInt: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Int16)); SetInt16_Unchecked(sink, setters, i, record.GetInt16(i)); break; case SqlDbType.SmallMoney: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlMoney)); SetSqlMoney_Checked(sink, setters, i, metaData[i], record.GetSqlMoney(i)); break; case SqlDbType.Text: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlChars)); SetChars_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.Timestamp: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlBytes)); SetBytes_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.TinyInt: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.Byte)); SetByte_Unchecked(sink, setters, i, record.GetByte(i)); break; case SqlDbType.VarBinary: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlBytes)); SetBytes_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.VarChar: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.String)); SetChars_FromRecord(sink, setters, i, metaData[i], record, 0); break; case SqlDbType.Xml: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlXml)); SetSqlXml_Unchecked(sink, setters, i, record.GetSqlXml(i)); // perf improvement? break; case SqlDbType.Variant: object o = record.GetSqlValue(i); ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCode(o); SetCompatibleValue(sink, setters, i, metaData[i], o, typeCode, 0); break; case SqlDbType.Udt: Debug.Assert(CanAccessSetterDirectly(metaData[i], ExtendedClrTypeCode.SqlBytes)); SetBytes_FromRecord(sink, setters, i, metaData[i], record, 0); break; default: Debug.Assert(false, "unsupported DbType:" + metaData[i].SqlDbType.ToString()); throw ADP.NotSupported(); } } } }