From 7449ce02683fc26395cf0ffeed08086a13c41c18 Mon Sep 17 00:00:00 2001 From: Nik Trevallyn-Jones Date: Mon, 6 May 2024 18:47:09 -0400 Subject: [PATCH 1/3] Implement NuoDbDataReader.HasRows() --- NuoDb.Data.Client/NuoDbDataReader.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/NuoDb.Data.Client/NuoDbDataReader.cs b/NuoDb.Data.Client/NuoDbDataReader.cs index b5ec371..d2bf96c 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,7 +310,8 @@ public override bool NextResult() public override bool Read() { - if (this.pendingRows == null) + //afterLast can only be false if pendingRows was non-null in InitResultSet(). + if (afterLast) return false; //int maxRows = statement == null ? 0 : statement.MaxRows; @@ -315,6 +319,7 @@ public override bool Read() for (; ; ) { + // NOTE: this is a LOCAL maxRows which is hiding this.maxRows. if (maxRows > 0 && currentRow >= maxRows) { afterLast = true; @@ -324,7 +329,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 +659,7 @@ public override System.Collections.IEnumerator GetEnumerator() public override bool HasRows { - get { throw new NotImplementedException(); } + get { return (!afterLast); } } } } From f44ae50e1bea2a61b25092c1dc96a72d0273c289 Mon Sep 17 00:00:00 2001 From: Nik Trevallyn-Jones Date: Tue, 21 May 2024 15:23:50 -0400 Subject: [PATCH 2/3] Add further safety check in Read(). dd further explanatory comments. --- NuoDb.Data.Client/NuoDbDataReader.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/NuoDb.Data.Client/NuoDbDataReader.cs b/NuoDb.Data.Client/NuoDbDataReader.cs index d2bf96c..cb653cf 100644 --- a/NuoDb.Data.Client/NuoDbDataReader.cs +++ b/NuoDb.Data.Client/NuoDbDataReader.cs @@ -310,12 +310,13 @@ public override bool NextResult() public override bool Read() { - //afterLast can only be false if pendingRows was non-null in InitResultSet(). - if (afterLast) + // 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 (; ; ) { From 7841f916b5978af01bec81848d8551c9693a1ca4 Mon Sep 17 00:00:00 2001 From: Nik Trevallyn-Jones Date: Tue, 21 May 2024 15:26:06 -0400 Subject: [PATCH 3/3] Fix typo in comment. --- NuoDb.Data.Client/NuoDbDataReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NuoDb.Data.Client/NuoDbDataReader.cs b/NuoDb.Data.Client/NuoDbDataReader.cs index cb653cf..f94ecb5 100644 --- a/NuoDb.Data.Client/NuoDbDataReader.cs +++ b/NuoDb.Data.Client/NuoDbDataReader.cs @@ -310,7 +310,7 @@ public override bool NextResult() public override bool Read() { - // CUrrently, afterLast can only be false if pendingRows was non-null in InitResultSet(); + // 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;