private static void SetStream_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metadata, StreamDataFeed feed) { long len = metadata.MaxLength; byte[] buff = new byte[constBinBufferSize]; int nWritten = 0; do { int nRead = 0; int readSize = constBinBufferSize; if (len > 0 && nWritten + readSize > len) { readSize = (int)(len - nWritten); } Debug.Assert(readSize >= 0); nRead = feed._source.Read(buff, 0, readSize); if (nRead == 0) { break; } setters.SetBytes(sink, ordinal, nWritten, buff, 0, nRead); sink.ProcessMessagesAndThrow(); nWritten += nRead; } while (len <= 0 || nWritten < len); setters.SetBytesLength(sink, ordinal, nWritten); sink.ProcessMessagesAndThrow(); }
// note: length < 0 indicates write everything private static void SetSqlBytes_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBytes value, int offset, long length ) { if ( value.IsNull ) { setters.SetDBNull( sink, ordinal ); sink.ProcessMessagesAndThrow(); } else { int chunkSize; if ( length > __maxByteChunkSize || length < 0 ) { chunkSize = __maxByteChunkSize; } else { chunkSize = checked( (int)length ); } byte[] buffer = new byte[ chunkSize ]; long bytesRead; long bytesWritten = 1; // prime value to get into write loop long currentOffset = offset; long lengthWritten = 0; while ( (length < 0 || lengthWritten < length) && 0 != ( bytesRead = value.Read( currentOffset, buffer, 0, chunkSize ) ) && 0 != bytesWritten ) { bytesWritten = setters.SetBytes( sink, ordinal, currentOffset, buffer, 0, checked( (int) bytesRead ) ); sink.ProcessMessagesAndThrow(); checked{ currentOffset += bytesWritten; } checked{ lengthWritten += bytesWritten; } } // Make sure to trim any left-over data setters.SetBytesLength( sink, ordinal, currentOffset ); sink.ProcessMessagesAndThrow(); } }
private static void SetByteArray_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, byte[] buffer, int bufferOffset, int length ) { if ( length > 0 ) { setters.SetBytes( sink, ordinal, 0, buffer, bufferOffset, length ); sink.ProcessMessagesAndThrow(); } setters.SetBytesLength( sink, ordinal, length ); sink.ProcessMessagesAndThrow(); }
private static void SetBytes_FromRecord( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlDataRecord record, int offset ) { int length = 0; // Deal with large values by sending bufferLength of NoLengthLimit (== assume // CheckXetParameters will ignore requested-length checks in this case long bufferLength = record.GetBytes(ordinal, 0, null, 0, 0); if ( bufferLength > Int32.MaxValue ) { bufferLength = NoLengthLimit; } length = CheckXetParameters( metaData.SqlDbType, metaData.MaxLength, NoLengthLimit /* actual */, 0, checked( (int) bufferLength ), offset, checked( (int) bufferLength ) ); int chunkSize; if ( length > __maxByteChunkSize || length < 0 ) { chunkSize = __maxByteChunkSize; } else { chunkSize = checked( (int)length ); } byte[] buffer = new byte[ chunkSize ]; long bytesRead; long bytesWritten = 1; // prime value to get into write loop long currentOffset = offset; long lengthWritten = 0; while ( (length < 0 || lengthWritten < length) && 0 != ( bytesRead = record.GetBytes( ordinal, currentOffset, buffer, 0, chunkSize ) ) && 0 != bytesWritten ) { bytesWritten = setters.SetBytes( sink, ordinal, currentOffset, buffer, 0, checked( (int) bytesRead ) ); sink.ProcessMessagesAndThrow(); checked{ currentOffset += bytesWritten; } checked{ lengthWritten += bytesWritten; } } // Make sure to trim any left-over data setters.SetBytesLength( sink, ordinal, currentOffset ); sink.ProcessMessagesAndThrow(); }
internal static long SetBytesLength( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, long length ) { ThrowIfInvalidSetterAccess( metaData, ExtendedClrTypeCode.ByteArray ); if ( length < 0 ) { throw ADP.InvalidDataLength( length ); } if ( metaData.MaxLength >= 0 && length > metaData.MaxLength ) { length = metaData.MaxLength; } setters.SetBytesLength( sink, ordinal, length ); sink.ProcessMessagesAndThrow(); return length; }
private static void SetSqlBytes_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBytes value, int offset, long length) { if (value.IsNull) { setters.SetDBNull(sink, ordinal); sink.ProcessMessagesAndThrow(); } else { int num4; long num5; if ((length > 0x1f40L) || (length < 0L)) { num4 = 0x1f40; } else { num4 = (int) length; } byte[] buffer = new byte[num4]; long num2 = 1L; long num = offset; for (long i = 0L; ((length < 0L) || (i < length)) && ((0L != (num5 = value.Read(num, buffer, 0, num4))) && (0L != num2)); i += num2) { num2 = setters.SetBytes(sink, ordinal, num, buffer, 0, (int) num5); sink.ProcessMessagesAndThrow(); num += num2; } setters.SetBytesLength(sink, ordinal, num); sink.ProcessMessagesAndThrow(); } }
private static void SetBytes_FromRecord(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlDataRecord record, int offset) { int num6; long num7; int num = 0; long num4 = record.GetBytes(ordinal, 0L, null, 0, 0); if (num4 > 0x7fffffffL) { num4 = -1L; } num = CheckXetParameters(metaData.SqlDbType, metaData.MaxLength, -1L, 0L, (int) num4, offset, (int) num4); if ((num > 0x1f40) || (num < 0)) { num6 = 0x1f40; } else { num6 = num; } byte[] buffer = new byte[num6]; long num3 = 1L; long fieldOffset = offset; for (long i = 0L; ((num < 0) || (i < num)) && ((0L != (num7 = record.GetBytes(ordinal, fieldOffset, buffer, 0, num6))) && (0L != num3)); i += num3) { num3 = setters.SetBytes(sink, ordinal, fieldOffset, buffer, 0, (int) num7); sink.ProcessMessagesAndThrow(); fieldOffset += num3; } setters.SetBytesLength(sink, ordinal, fieldOffset); sink.ProcessMessagesAndThrow(); }