+2002-11-01 Daniel Morgan <danmorg@sc.rr.com>\r
+\r
+ * PgSqlCommand.cs: get rid of warning\r
+ \r
+ * PgSqlDataReader.cs: implemented GetEnumerator(),\r
+ and Dispose()\r
+\r
2002-10-16 Daniel Morgan <danmorg@sc.rr.com>\r
\r
* ParmUtil.cs\r
private void GetKeyInfo(string columnName, out bool isUnique, out bool isKey) {
isUnique = false;
isKey = false;
-
+/*
string sql;
sql =
"FROM pg_class c, pg_class c2, pg_index i " +
"WHERE c.relname = ':tableName' AND c.oid = i.indrelid " +
"AND i.indexrelid = c2.oid ";
+*/
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
+using System.Data.Common;
namespace Mono.Data.PostgreSqlClient {
/// <summary>
/// of result sets obtained by executing a command
/// at a SQL database.
/// </summary>
- //public sealed class PgSqlDataReader : MarshalByRefObject,
- // IEnumerable, IDataReader, IDisposable, IDataRecord
- public sealed class PgSqlDataReader : IEnumerable,
- IDataReader, IDataRecord {
+ public sealed class PgSqlDataReader : MarshalByRefObject,
+ IEnumerable, IDataReader, IDisposable, IDataRecord {
+
#region Fields
private PgSqlCommand cmd;
private int currentRow = -1; // no Read() has been done yet
+ private bool disposed = false;
+
#endregion // Fields
#region Constructors
public void Close() {
open = false;
- // free SqlDataReader resources in SqlCommand
- // and allow SqlConnection to be used again
+ // free PgSqlDataReader resources in PgSqlCommand
+ // and allow PgSqlConnection to be used again
cmd.CloseReader();
// TODO: get parameters from result
- // clear unmanaged PostgreSQL result set
- PostgresLibrary.PQclear (pgResult);
- pgResult = IntPtr.Zero;
+ Dispose (true);
}
[MonoTODO]
}
[MonoTODO]
- public IEnumerator GetEnumerator() {
- throw new NotImplementedException ();
+ IEnumerator IEnumerable.GetEnumerator () {
+ return new DbEnumerator (this);
}
#endregion // Public Methods
#region Destructors
- [MonoTODO]
- public void Dispose () {
+ private void Dispose(bool disposing) {
+ if(!this.disposed) {
+ if(disposing) {
+ // release any managed resources
+ cmd = null;
+ table = null;
+ fields = null;
+ types = null;
+ isNull = null;
+ actualLength = null;
+ dbTypes = null;
+ }
+ // release any unmanaged resources
+
+ // clear unmanaged PostgreSQL result set
+ if (pgResult != IntPtr.Zero) {
+ PostgresLibrary.PQclear (pgResult);
+ pgResult = IntPtr.Zero;
+ }
+
+ // close any handles
+ this.disposed = true;
+ }
}
- //[MonoTODO]
- //~PgSqlDataReader() {
- //}
+ void IDisposable.Dispose() {
+ Dispose(true);
+ }
+
+ ~PgSqlDataReader() {
+ Dispose(false);
+ }
#endregion // Destructors
private void GetKeyInfo(string columnName, out bool isUnique, out bool isKey) {
isUnique = false;
isKey = false;
-
+/*
string sql;
sql =
"FROM pg_class c, pg_class c2, pg_index i " +
"WHERE c.relname = ':tableName' AND c.oid = i.indrelid " +
"AND i.indexrelid = c2.oid ";
+*/
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
+using System.Data.Common;
namespace Mono.Data.PostgreSqlClient {
/// <summary>
/// of result sets obtained by executing a command
/// at a SQL database.
/// </summary>
- //public sealed class PgSqlDataReader : MarshalByRefObject,
- // IEnumerable, IDataReader, IDisposable, IDataRecord
- public sealed class PgSqlDataReader : IEnumerable,
- IDataReader, IDataRecord {
+ public sealed class PgSqlDataReader : MarshalByRefObject,
+ IEnumerable, IDataReader, IDisposable, IDataRecord {
+
#region Fields
private PgSqlCommand cmd;
private int currentRow = -1; // no Read() has been done yet
+ private bool disposed = false;
+
#endregion // Fields
#region Constructors
public void Close() {
open = false;
- // free SqlDataReader resources in SqlCommand
- // and allow SqlConnection to be used again
+ // free PgSqlDataReader resources in PgSqlCommand
+ // and allow PgSqlConnection to be used again
cmd.CloseReader();
// TODO: get parameters from result
- // clear unmanaged PostgreSQL result set
- PostgresLibrary.PQclear (pgResult);
- pgResult = IntPtr.Zero;
+ Dispose (true);
}
[MonoTODO]
}
[MonoTODO]
- public IEnumerator GetEnumerator() {
- throw new NotImplementedException ();
+ IEnumerator IEnumerable.GetEnumerator () {
+ return new DbEnumerator (this);
}
#endregion // Public Methods
#region Destructors
- [MonoTODO]
- public void Dispose () {
+ private void Dispose(bool disposing) {
+ if(!this.disposed) {
+ if(disposing) {
+ // release any managed resources
+ cmd = null;
+ table = null;
+ fields = null;
+ types = null;
+ isNull = null;
+ actualLength = null;
+ dbTypes = null;
+ }
+ // release any unmanaged resources
+
+ // clear unmanaged PostgreSQL result set
+ if (pgResult != IntPtr.Zero) {
+ PostgresLibrary.PQclear (pgResult);
+ pgResult = IntPtr.Zero;
+ }
+
+ // close any handles
+ this.disposed = true;
+ }
}
- //[MonoTODO]
- //~PgSqlDataReader() {
- //}
+ void IDisposable.Dispose() {
+ Dispose(true);
+ }
+
+ ~PgSqlDataReader() {
+ Dispose(false);
+ }
#endregion // Destructors