internal SqlChars(SqlStreamChars s)
 {
     this.m_rgchBuf = null;
     this.m_lCurLen = -1L;
     this.m_stream = s;
     this.m_state = (s == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Stream;
     this.m_rgchWorkBuf = null;
 }
 public SqlBytes(System.IO.Stream s)
 {
     this.m_rgbBuf = null;
     this.m_lCurLen = -1L;
     this.m_stream = s;
     this.m_state = (s == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Stream;
     this.m_rgbWorkBuf = null;
 }
 private SqlChars(SerializationInfo info, StreamingContext context)
 {
     this.m_stream = null;
     this.m_rgchWorkBuf = null;
     if (info.GetBoolean("IsNull"))
     {
         this.m_state = SqlBytesCharsState.Null;
         this.m_rgchBuf = null;
     }
     else
     {
         this.m_state = SqlBytesCharsState.Buffer;
         this.m_rgchBuf = (char[]) info.GetValue("data", typeof(char[]));
         this.m_lCurLen = this.m_rgchBuf.Length;
     }
 }
 public SqlChars(char[] buffer)
 {
     this.m_rgchBuf = buffer;
     this.m_stream = null;
     if (this.m_rgchBuf == null)
     {
         this.m_state = SqlBytesCharsState.Null;
         this.m_lCurLen = -1L;
     }
     else
     {
         this.m_state = SqlBytesCharsState.Buffer;
         this.m_lCurLen = this.m_rgchBuf.Length;
     }
     this.m_rgchWorkBuf = null;
 }
Esempio n. 5
0
        // Create a SqlChars with an in-memory buffer
        public SqlChars(char[] buffer)
        {
            m_rgchBuf = buffer;
            m_stream = null;
            if (m_rgchBuf == null)
            {
                _state = SqlBytesCharsState.Null;
                _lCurLen = x_lNull;
            }
            else
            {
                _state = SqlBytesCharsState.Buffer;
                _lCurLen = (long)m_rgchBuf.Length;
            }

            _rgchWorkBuf = null;

            AssertValid();
        }
Esempio n. 6
0
        // Create a SqlBytes with an in-memory buffer
        public SqlBytes(byte[] buffer)
        {
            _rgbBuf = buffer;
            _stream = null;
            if (_rgbBuf == null)
            {
                _state = SqlBytesCharsState.Null;
                _lCurLen = x_lNull;
            }
            else
            {
                _state = SqlBytesCharsState.Buffer;
                _lCurLen = _rgbBuf.Length;
            }

            _rgbWorkBuf = null;

            AssertValid();
        }
Esempio n. 7
0
        // Set the current length of the data
        // If the SqlBytes is Null, setLength will make it non-Null.
        public void SetLength(long value)
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            if (FStream())
            {
                m_stream.SetLength(value);
            }
            else
            {
                // If there is a buffer, even the value of SqlBytes is Null,
                // still allow setting length to zero, which will make it not Null.
                // If the buffer is null, raise exception
                //
                if (null == m_rgbBuf)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));
                }

                if (value > (long)m_rgbBuf.Length)
                {
                    throw new ArgumentOutOfRangeException("value");
                }

                else if (IsNull)
                {
                    // At this point we know that value is small enough
                    // Go back in buffer mode
                    m_state = SqlBytesCharsState.Buffer;
                }

                m_lCurLen = value;
            }

            AssertValid();
        }
 private void CopyStreamToBuffer()
 {
     long length = this.m_stream.Length;
     if (length >= 0x7fffffffL)
     {
         throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_BufferInsufficientMessage"));
     }
     if ((this.m_rgchBuf == null) || (this.m_rgchBuf.Length < length))
     {
         this.m_rgchBuf = new char[length];
     }
     if (this.m_stream.Position != 0L)
     {
         this.m_stream.Seek(0L, SeekOrigin.Begin);
     }
     this.m_stream.Read(this.m_rgchBuf, 0, (int) length);
     this.m_stream = null;
     this.m_lCurLen = length;
     this.m_state = SqlBytesCharsState.Buffer;
 }
Esempio n. 9
0
 public void Write(long offset, char[] buffer, int offsetInBuffer, int count)
 {
     if (this.FStream())
     {
         if (this.m_stream.Position != offset)
         {
             this.m_stream.Seek(offset, SeekOrigin.Begin);
         }
         this.m_stream.Write(buffer, offsetInBuffer, count);
     }
     else
     {
         if (buffer == null)
         {
             throw new ArgumentNullException("buffer");
         }
         if (this.m_rgchBuf == null)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_NoBufferMessage"));
         }
         if (offset < 0L)
         {
             throw new ArgumentOutOfRangeException("offset");
         }
         if (offset > this.m_rgchBuf.Length)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_BufferInsufficientMessage"));
         }
         if ((offsetInBuffer < 0) || (offsetInBuffer > buffer.Length))
         {
             throw new ArgumentOutOfRangeException("offsetInBuffer");
         }
         if ((count < 0) || (count > (buffer.Length - offsetInBuffer)))
         {
             throw new ArgumentOutOfRangeException("count");
         }
         if (count > (this.m_rgchBuf.Length - offset))
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_BufferInsufficientMessage"));
         }
         if (this.IsNull)
         {
             if (offset != 0L)
             {
                 throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_WriteNonZeroOffsetOnNullMessage"));
             }
             this.m_lCurLen = 0L;
             this.m_state   = SqlBytesCharsState.Buffer;
         }
         else if (offset > this.m_lCurLen)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_WriteOffsetLargerThanLenMessage"));
         }
         if (count != 0)
         {
             Array.Copy(buffer, (long)offsetInBuffer, this.m_rgchBuf, offset, (long)count);
             if (this.m_lCurLen < (offset + count))
             {
                 this.m_lCurLen = offset + count;
             }
         }
     }
 }
Esempio n. 10
0
		// Create a SqlBytes with an in-memory buffer
		public SqlBytes(byte[] buffer) {
			m_rgbBuf = buffer;
			m_stream = null;
			if (m_rgbBuf == null) {
				m_state = SqlBytesCharsState.Null;
				m_lCurLen = x_lNull;
            }
			else {
				m_state = SqlBytesCharsState.Buffer;
				m_lCurLen = (long)m_rgbBuf.Length;
            }

			m_rgbWorkBuf = null;

			AssertValid();
		}
Esempio n. 11
0
        // Constructor required for serialization. Deserializes as a Buffer. If the bits have been tampered with
        // then this will throw a SerializationException or a InvalidCastException.
        private SqlBytes(SerializationInfo info, StreamingContext context)
        {
            _stream = null;
            _rgbWorkBuf = null;

            if (info.GetBoolean("IsNull"))
            {
                _state = SqlBytesCharsState.Null;
                _rgbBuf = null;
            }
            else
            {
                _state = SqlBytesCharsState.Buffer;
                _rgbBuf = (byte[])info.GetValue("data", typeof(byte[]));
                _lCurLen = _rgbBuf.Length;
            }

            AssertValid();
        }
Esempio n. 12
0
 public void SetNull()
 {
     this.m_lCurLen = -1L;
     this.m_stream  = null;
     this.m_state   = SqlBytesCharsState.Null;
 }
Esempio n. 13
0
		// Copy the data from the Stream to the array buffer.
		// If the SqlChars doesn't hold a buffer or the buffer
		// is not big enough, allocate new char array.
		private void CopyStreamToBuffer() {
			Debug.Assert(FStream());

			long lStreamLen = m_stream.Length;
			if (lStreamLen >= x_lMaxLen)
                           throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));

			if (m_rgchBuf == null || m_rgchBuf.Length < lStreamLen)
				m_rgchBuf = new char[lStreamLen];

			if (m_stream.Position != 0)
				m_stream.Seek(0, SeekOrigin.Begin);

			m_stream.Read(m_rgchBuf, 0, (int)lStreamLen);
			m_stream = null;
			m_lCurLen = lStreamLen;
			m_state = SqlBytesCharsState.Buffer;

			AssertValid();
        }
Esempio n. 14
0
		// Set the current length of the data
		// If the SqlChars is Null, setLength will make it non-Null.
		public void SetLength(long value) {
			if (value < 0)
				throw new ArgumentOutOfRangeException("value");

			if (FStream()) {
				m_stream.SetLength(value);
            }
			else {
				// If there is a buffer, even the value of SqlChars is Null,
				// still allow setting length to zero, which will make it not Null.
				// If the buffer is null, raise exception
				//
				if (null == m_rgchBuf)
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));

				if (value > (long)m_rgchBuf.Length)
					throw new ArgumentOutOfRangeException("value");

				else if (IsNull)
					// At this point we know that value is small enough
					// Go back in buffer mode
					m_state = SqlBytesCharsState.Buffer;
                                
				m_lCurLen = value;
				}

			AssertValid();
        }
Esempio n. 15
0
		// Create a SqlChars from a SqlStreamChars
		internal SqlChars(SqlStreamChars s) {
			m_rgchBuf = null;
			m_lCurLen = x_lNull;
			m_stream = s;
			m_state = (s == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Stream;

			m_rgchWorkBuf = null;

			AssertValid();
        }
Esempio n. 16
0
        public SqlBytes(Stream s)
        {
            // Create a SqlBytes from a Stream
            _rgbBuf = null;
            _lCurLen = x_lNull;
            _stream = s;
            _state = (s == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Stream;

            _rgbWorkBuf = null;

            AssertValid();
        }
Esempio n. 17
0
        private void SetBuffer(byte[] buffer)
        {
            _rgbBuf = buffer;
            _lCurLen = (_rgbBuf == null) ? x_lNull : _rgbBuf.Length;
            _stream = null;
            _state = (_rgbBuf == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Buffer;

            AssertValid();
        }
Esempio n. 18
0
        // Copy the data from the Stream to the array buffer.
        // If the SqlBytes doesn't hold a buffer or the buffer
        // is not big enough, allocate new byte array.
        private void CopyStreamToBuffer()
        {
            Debug.Assert(FStream());

            long lStreamLen = _stream.Length;
            if (lStreamLen >= x_lMaxLen)
                throw new SqlTypeException(SR.SqlMisc_WriteOffsetLargerThanLenMessage);

            if (_rgbBuf == null || _rgbBuf.Length < lStreamLen)
                _rgbBuf = new byte[lStreamLen];

            if (_stream.Position != 0)
                _stream.Seek(0, SeekOrigin.Begin);

            _stream.Read(_rgbBuf, 0, (int)lStreamLen);
            _stream = null;
            _lCurLen = lStreamLen;
            _state = SqlBytesCharsState.Buffer;

            AssertValid();
        }
Esempio n. 19
0
        // Write data of specified length into the SqlBytes from specified offset
        public void Write(long offset, byte[] buffer, int offsetInBuffer, int count)
        {
            if (FStream())
            {
                if (m_stream.Position != offset)
                {
                    m_stream.Seek(offset, SeekOrigin.Begin);
                }
                m_stream.Write(buffer, offsetInBuffer, count);
            }
            else
            {
                // Validate the arguments
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }

                if (m_rgbBuf == null)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));
                }

                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (offset > m_rgbBuf.Length)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (offsetInBuffer < 0 || offsetInBuffer > buffer.Length)
                {
                    throw new ArgumentOutOfRangeException("offsetInBuffer");
                }

                if (count < 0 || count > buffer.Length - offsetInBuffer)
                {
                    throw new ArgumentOutOfRangeException("count");
                }

                if (count > m_rgbBuf.Length - offset)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (IsNull)
                {
                    // If NULL and there is buffer inside, we only allow writing from
                    // offset zero.
                    //
                    if (offset != 0)
                    {
                        throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteNonZeroOffsetOnNullMessage));
                    }

                    // treat as if our current length is zero.
                    // Note this has to be done after all inputs are validated, so that
                    // we won't throw exception after this point.
                    //
                    m_lCurLen = 0;
                    m_state   = SqlBytesCharsState.Buffer;
                }
                else if (offset > m_lCurLen)
                {
                    // Don't allow writing from an offset that this larger than current length.
                    // It would leave uninitialized data in the buffer.
                    //
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteOffsetLargerThanLenMessage));
                }

                if (count != 0)
                {
                    Array.Copy(buffer, offsetInBuffer, m_rgbBuf, offset, count);

                    // If the last position that has been written is after
                    // the current data length, reset the length
                    if (m_lCurLen < offset + count)
                    {
                        m_lCurLen = offset + count;
                    }
                }
            }

            AssertValid();
        }
 private void SetBuffer(char[] buffer)
 {
     this.m_rgchBuf = buffer;
     this.m_lCurLen = (this.m_rgchBuf == null) ? -1L : ((long) this.m_rgchBuf.Length);
     this.m_stream = null;
     this.m_state = (this.m_rgchBuf == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Buffer;
 }
Esempio n. 21
0
		// --------------------------------------------------------------
		//	  Public methods
		// --------------------------------------------------------------

		public void SetNull() {
    		m_lCurLen = x_lNull;
    		m_stream = null;
    		m_state = SqlBytesCharsState.Null;

    		AssertValid();
		}
 public void SetLength(long value)
 {
     if (value < 0L)
     {
         throw new ArgumentOutOfRangeException("value");
     }
     if (this.FStream())
     {
         this.m_stream.SetLength(value);
     }
     else
     {
         if (this.m_rgchBuf == null)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_NoBufferMessage"));
         }
         if (value > this.m_rgchBuf.Length)
         {
             throw new ArgumentOutOfRangeException("value");
         }
         if (this.IsNull)
         {
             this.m_state = SqlBytesCharsState.Buffer;
         }
         this.m_lCurLen = value;
     }
 }
Esempio n. 23
0
		// Write data of specified length into the SqlChars from specified offset

		public void Write(long offset, char[] buffer, int offsetInBuffer, int count) {
			if (FStream()) {
				if (m_stream.Position != offset)
					m_stream.Seek(offset, SeekOrigin.Begin);
				m_stream.Write(buffer, offsetInBuffer, count);
            }
			else {
				// Validate the arguments
				if (buffer == null)
					throw new ArgumentNullException("buffer");

				if (m_rgchBuf == null)
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));

				if (offset < 0)
					throw new ArgumentOutOfRangeException("offset");
				if (offset > m_rgchBuf.Length)
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));

				if (offsetInBuffer < 0 || offsetInBuffer > buffer.Length)
					throw new ArgumentOutOfRangeException("offsetInBuffer");

				if (count < 0 || count > buffer.Length - offsetInBuffer)
					throw new ArgumentOutOfRangeException("count");

				if (count > m_rgchBuf.Length - offset)
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));

				if (IsNull) {
					// If NULL and there is buffer inside, we only allow writing from 
					// offset zero.
					//
					if (offset != 0)
                        throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteNonZeroOffsetOnNullMessage));

					// treat as if our current length is zero.
					// Note this has to be done after all inputs are validated, so that
					// we won't throw exception after this point.
					//
					m_lCurLen = 0;
                    m_state = SqlBytesCharsState.Buffer;
                }
				else if (offset > m_lCurLen) {
					// Don't allow writing from an offset that this larger than current length.
					// It would leave uninitialized data in the buffer.
					//
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteOffsetLargerThanLenMessage));
				}

				if (count != 0)	{
					Array.Copy(buffer, offsetInBuffer, m_rgchBuf, offset, count);

					// If the last position that has been written is after
					// the current data length, reset the length
					if (m_lCurLen < offset + count)
						m_lCurLen = offset + count;
                }
            }

			AssertValid();
        }
 public void SetNull()
 {
     this.m_lCurLen = -1L;
     this.m_stream = null;
     this.m_state = SqlBytesCharsState.Null;
 }
Esempio n. 25
0
		private void SetBuffer(char[] buffer) {
			m_rgchBuf = buffer;
			m_lCurLen = (m_rgchBuf == null) ? x_lNull : (long)m_rgchBuf.Length;
			m_stream = null;
			m_state = (m_rgchBuf == null) ? SqlBytesCharsState.Null : SqlBytesCharsState.Buffer;

			AssertValid();
		}
 public void Write(long offset, char[] buffer, int offsetInBuffer, int count)
 {
     if (this.FStream())
     {
         if (this.m_stream.Position != offset)
         {
             this.m_stream.Seek(offset, SeekOrigin.Begin);
         }
         this.m_stream.Write(buffer, offsetInBuffer, count);
     }
     else
     {
         if (buffer == null)
         {
             throw new ArgumentNullException("buffer");
         }
         if (this.m_rgchBuf == null)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_NoBufferMessage"));
         }
         if (offset < 0L)
         {
             throw new ArgumentOutOfRangeException("offset");
         }
         if (offset > this.m_rgchBuf.Length)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_BufferInsufficientMessage"));
         }
         if ((offsetInBuffer < 0) || (offsetInBuffer > buffer.Length))
         {
             throw new ArgumentOutOfRangeException("offsetInBuffer");
         }
         if ((count < 0) || (count > (buffer.Length - offsetInBuffer)))
         {
             throw new ArgumentOutOfRangeException("count");
         }
         if (count > (this.m_rgchBuf.Length - offset))
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_BufferInsufficientMessage"));
         }
         if (this.IsNull)
         {
             if (offset != 0L)
             {
                 throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_WriteNonZeroOffsetOnNullMessage"));
             }
             this.m_lCurLen = 0L;
             this.m_state = SqlBytesCharsState.Buffer;
         }
         else if (offset > this.m_lCurLen)
         {
             throw new SqlTypeException(System.Data.Res.GetString("SqlMisc_WriteOffsetLargerThanLenMessage"));
         }
         if (count != 0)
         {
             Array.Copy(buffer, (long) offsetInBuffer, this.m_rgchBuf, offset, (long) count);
             if (this.m_lCurLen < (offset + count))
             {
                 this.m_lCurLen = offset + count;
             }
         }
     }
 }