[hyena] Log ArrayDataReaders disposed without being fully read
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena] Log ArrayDataReaders disposed without being fully read
- Date: Tue, 4 Jan 2011 21:25:34 +0000 (UTC)
commit 0056e2eb83ef6abaf6c60e588e4f69b2610eb9b5
Author: Gabriel Burt <gabriel burt gmail com>
Date: Tue Jan 4 12:54:05 2011 -0600
Log ArrayDataReaders disposed without being fully read
Only logs them when in debug mode. Useful for identifying queries that
are missing a "LIMIT 1" or similar.
.../Hyena.Data.Sqlite/ArrayDataReader.cs | 16 ++++++++++++++--
.../Hyena.Data.Sqlite/HyenaSqliteCommand.cs | 2 +-
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/Hyena.Data.Sqlite/Hyena.Data.Sqlite/ArrayDataReader.cs b/Hyena.Data.Sqlite/Hyena.Data.Sqlite/ArrayDataReader.cs
index 16dbd2b..8ff23ce 100644
--- a/Hyena.Data.Sqlite/Hyena.Data.Sqlite/ArrayDataReader.cs
+++ b/Hyena.Data.Sqlite/Hyena.Data.Sqlite/ArrayDataReader.cs
@@ -39,11 +39,13 @@ namespace Hyena.Data.Sqlite
{
internal class ArrayDataReader : IDataReader
{
+ string sql;
int rows;
int row = -1;
+ int max_got_row = -1;
List<object[]> data = new List<object[]> ();
- internal ArrayDataReader (IDataReader reader)
+ internal ArrayDataReader (IDataReader reader, string sql)
{
if (!reader.Read ())
return;
@@ -60,11 +62,17 @@ namespace Hyena.Data.Sqlite
data.Add (vals);
rows++;
} while (reader.Read ());
+
+ this.sql = sql;
}
public void Dispose ()
{
+ if (rows > 1 && max_got_row < (rows - 1) && Log.Debugging) {
+ Log.WarningFormat ("Disposing ArrayDataReader that has {0} rows but we only read {1} of them\n{2}", rows, row, sql);
+ }
row = -1;
+ max_got_row = -1;
}
public int FieldCount { get; private set; }
@@ -73,11 +81,15 @@ namespace Hyena.Data.Sqlite
public bool Read ()
{
row++;
+ max_got_row++;
return row < rows;
}
public object this[int i] {
- get { return data[row][i]; }
+ get {
+ max_got_row = Math.Max (i, max_got_row);
+ return data[row][i];
+ }
}
public object this[string columnName] {
diff --git a/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs b/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
index 712baff..f7a1ba9 100644
--- a/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
+++ b/Hyena.Data.Sqlite/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
@@ -96,7 +96,7 @@ namespace Hyena.Data.Sqlite
switch (CommandType) {
case HyenaCommandType.Reader:
using (var reader = connection.Query (command_text)) {
- result = new ArrayDataReader (reader);
+ result = new ArrayDataReader (reader, command_text);
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]