+2008-12-30 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * Tds.cs (LoadData): Improve exception message when attempting to
+ read before the current position. Update the remaining length of the
+ stream when skipping bytes.
2008-12-05 Gonzalo Paniagua Javier <gonzalo@novell.com>
return StreamLength;
if (fieldIndex < StreamIndex)
- throw new InvalidOperationException ("field index less than stream pos");
+ throw new InvalidOperationException (string.Format (
+ "Attempting to read at index '{0}' is not " +
+ "allowed as this is less than the current " +
+ "position. You must read from index '{1}' " +
+ "or greater.", fieldIndex, StreamIndex));
if (fieldIndex >= (StreamLength + StreamIndex))
return 0;
- // Skip to the index
- Comm.Skip ((int) (fieldIndex - StreamIndex));
+ // determine number of bytes to skip
+ int skip = (int) (fieldIndex - StreamIndex);
+ // skip bytes
+ Comm.Skip (skip);
+ // update the current position
StreamIndex += (fieldIndex - StreamIndex);
+ // update the remaining length
+ StreamLength -= skip;
- // Load the reqd amt of bytes
+ // Load the reqd amt of bytes
int loadlen = (int) ((size > StreamLength) ? StreamLength : size);
byte[] arr = Comm.GetBytes (loadlen, true);