diff --git a/NuoDb.Data.Client/NuoDbDataReader.cs b/NuoDb.Data.Client/NuoDbDataReader.cs index b5ec371..f94ecb5 100644 --- a/NuoDb.Data.Client/NuoDbDataReader.cs +++ b/NuoDb.Data.Client/NuoDbDataReader.cs @@ -76,7 +76,7 @@ private void InitResultSet(int handle, EncodedDataStream dataStream, bool readCo this.values = new Value[numberColumns]; this.closed = false; this.currentRow = 0; - this.afterLast = false; + // this.afterLast = false; this.declaredColumnTypes = null; this.declaredColumnTypeNames = null; @@ -93,6 +93,9 @@ private void InitResultSet(int handle, EncodedDataStream dataStream, bool readCo //RemPreparedStatement ps = (RemPreparedStatement)statement; //columnNames = ps.columnNames; } + + // Set afterLast to true if the ResultSet is empty. + this.afterLast = (this.pendingRows == null || this.pendingRows.getInt() == 0); } protected override void Dispose(bool disposing) @@ -307,14 +310,17 @@ public override bool NextResult() public override bool Read() { - if (this.pendingRows == null) + // Currently, afterLast can only be false if pendingRows was non-null in InitResultSet(); + // - but InitResultSet could be changed in the future. + if (afterLast || pendingRows == null) return false; //int maxRows = statement == null ? 0 : statement.MaxRows; - int maxRows = 0; + int maxRows = 0; // this local maxRows HIDES this.maxRows for (; ; ) { + // NOTE: this is a LOCAL maxRows which is hiding this.maxRows. if (maxRows > 0 && currentRow >= maxRows) { afterLast = true; @@ -324,7 +330,8 @@ public override bool Read() if (!pendingRows.EndOfMessage) { - int result = pendingRows.getInt(); + // InitResultSet() performs the pendingRows.getInt() for currentRow == 0 + int result = currentRow > 0 ? pendingRows.getInt() : -1; if (result == 0) { @@ -653,7 +660,7 @@ public override System.Collections.IEnumerator GetEnumerator() public override bool HasRows { - get { throw new NotImplementedException(); } + get { return (!afterLast); } } } }