Quellcode durchsuchen

2002-04-20 Daniel Morgan <[email protected]>

* System.Data.OleDb: added directory - for OleDb database
provider classes

* System.Data.SqlClient/SqlClientPermission.cs
* System.Data.SqlClient/SqlClientPermissionAttribute.cs
* System.Data.SqlClient/SqlCommandBuilder.cs
* System.Data.SqlClient/SqlInfoMessageEventHandler.cs
* System.Data.SqlClient/SqlRowUpdatedEventArgs.cs
* System.Data.SqlClient/SqlRowUpdatedEventHandler.cs
* System.Data.SqlClient/SqlRowUpdatingEventArgs.cs
* System.Data.SqlClient/SqlRowUpdatingEventHandler.cs
* Test/TestSqlException.cs
* Test/TestSqlIsolationLevel.cs: added - more tests

* System.Data.build: modified - added new files - excludes these too

* System.Data.SqlClient/PostgresLibrary.cs - modified - comment

* System.Data.SqlClient/SqlConnection.cs
* System.Data.SqlClient/SqlCommand.cs
* System.Data.SqlClient/SqlTransaction.cs
* System.Data.SqlClient/SqlException.cs
* System.Data.SqlClient/SqlErrorCollection.cs
* System.Data.SqlClient/SqlError.cs: modified - transaction and
  exception/error handling. SqlConnection(connectionString)
  constructor should not automatically connect.

* System.Data.SqlClient/SqlDataReader.cs
* System.Data.SqlClient/SqlDataAdapter.cs
* System.Data.SqlClient/SqlParameter.cs
* System.Data.SqlClient/SqlParameterCollection.cs: modified -
added using System.ComponentModel;

* Test/TestSqlInsert.cs: modified - to use transaction

svn path=/trunk/mcs/; revision=3933
Daniel Morgan vor 24 Jahren
Ursprung
Commit
a9c683d500
65 geänderte Dateien mit 2804 neuen und 736 gelöschten Zeilen
  1. 76 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlClientPermission.cs
  2. 51 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlClientPermissionAttribute.cs
  3. 33 34
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs
  4. 103 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommandBuilder.cs
  5. 59 46
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlConnection.cs
  6. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataAdapter.cs
  7. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs
  8. 68 19
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlError.cs
  9. 39 62
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlErrorCollection.cs
  10. 103 18
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlException.cs
  11. 9 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventArgs.cs
  12. 19 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventHandler.cs
  13. 64 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameter.cs
  14. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs
  15. 38 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventArgs.cs
  16. 18 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventHandler.cs
  17. 42 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventArgs.cs
  18. 18 0
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventHandler.cs
  19. 99 65
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlTransaction.cs
  20. 0 1
      mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs
  21. 76 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlClientPermission.cs
  22. 51 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlClientPermissionAttribute.cs
  23. 33 34
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs
  24. 103 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommandBuilder.cs
  25. 59 46
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlConnection.cs
  26. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataAdapter.cs
  27. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs
  28. 68 19
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlError.cs
  29. 39 62
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlErrorCollection.cs
  30. 103 18
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlException.cs
  31. 9 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventArgs.cs
  32. 19 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventHandler.cs
  33. 64 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameter.cs
  34. 1 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs
  35. 38 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventArgs.cs
  36. 18 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventHandler.cs
  37. 42 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventArgs.cs
  38. 18 0
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventHandler.cs
  39. 99 65
      mcs/class/Mono.Data.PostgreSqlClient/PgSqlTransaction.cs
  40. 0 1
      mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs
  41. 37 0
      mcs/class/System.Data/ChangeLog
  42. 0 1
      mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs
  43. 76 0
      mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs
  44. 51 0
      mcs/class/System.Data/System.Data.SqlClient/SqlClientPermissionAttribute.cs
  45. 33 34
      mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
  46. 103 0
      mcs/class/System.Data/System.Data.SqlClient/SqlCommandBuilder.cs
  47. 59 46
      mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
  48. 1 0
      mcs/class/System.Data/System.Data.SqlClient/SqlDataAdapter.cs
  49. 1 0
      mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs
  50. 68 19
      mcs/class/System.Data/System.Data.SqlClient/SqlError.cs
  51. 39 62
      mcs/class/System.Data/System.Data.SqlClient/SqlErrorCollection.cs
  52. 103 18
      mcs/class/System.Data/System.Data.SqlClient/SqlException.cs
  53. 9 0
      mcs/class/System.Data/System.Data.SqlClient/SqlInfoMessageEventArgs.cs
  54. 19 0
      mcs/class/System.Data/System.Data.SqlClient/SqlInfoMessageEventHandler.cs
  55. 64 0
      mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs
  56. 1 0
      mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs
  57. 38 0
      mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatedEventArgs.cs
  58. 18 0
      mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatedEventHandler.cs
  59. 42 0
      mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatingEventArgs.cs
  60. 18 0
      mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatingEventHandler.cs
  61. 99 65
      mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs
  62. 8 0
      mcs/class/System.Data/System.Data.build
  63. 117 0
      mcs/class/System.Data/Test/TestSqlException.cs
  64. 12 1
      mcs/class/System.Data/Test/TestSqlInsert.cs
  65. 104 0
      mcs/class/System.Data/Test/TestSqlIsolationLevel.cs

+ 76 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlClientPermission.cs

@@ -0,0 +1,76 @@
+//
+// System.Data.SqlClient.SqlClientPermission.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	public sealed class SqlClientPermission : DBDataPermission {
+		
+		[MonoTODO]
+		public SqlClientPermission() {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state) {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state,
+			bool allowBlankPassword) { 
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Copy() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override void FromXml(SecurityElement 
+					securityElement) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Intersect(IPermission target)  {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override bool IsSubsetOf(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override SecurityElement ToXml() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Union(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermission() {
+			// FIXME: destructor to release resources
+		}
+	}
+}

+ 51 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlClientPermissionAttribute.cs

@@ -0,0 +1,51 @@
+//
+// System.Data.SqlClient.SqlClientPermissionAttribute.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	[AttributeUsage(AttributeTargets.Assembly    | 
+			AttributeTargets.Class 	     | 
+			AttributeTargets.Struct      | 
+			AttributeTargets.Constructor |
+			AttributeTargets.Method)]
+	[Serializable]
+	public sealed class SqlClientPermissionAttribute :
+		DBDataPermissionAttribute {
+
+		[MonoTODO]
+		[AttributeUsage(AttributeTargets.Assembly    | 
+			 AttributeTargets.Class       | 
+			 AttributeTargets.Struct      | 
+			 AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public SqlClientPermissionAttribute(SecurityAction action) {
+			// FIXME: do constructor
+		}
+
+		[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
+			 | AttributeTargets.Struct | AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public override IPermission CreatePermission() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermissionAttribute() {
+			// FIXME: destructor to release resources
+		}
+	}
+
+}

+ 33 - 34
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs

@@ -8,6 +8,9 @@
 // (C) Ximian, Inc 2002
 //
 
+// use #define DEBUG_SqlCommand if you want to spew debug messages
+// #define DEBUG_SqlCommand
+
 using System;
 using System.ComponentModel;
 using System.Data;
@@ -99,10 +102,8 @@ namespace System.Data.SqlClient
 			ExecStatusType execStatus;
 			String rowsAffectedString;
 
-			// FIXME: throw an 
-			// InvalidOperationException
-			// exception if the the connection
-			// does not exist or is not open
+			if(conn.State != ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is not Open");
 
 			// FIXME: PQexec blocks 
 			// while PQsendQuery is non-blocking
@@ -115,52 +116,43 @@ namespace System.Data.SqlClient
 			pgResult = PostgresLibrary.
 				PQexec (conn.PostgresConnection, sql);
 
-			/* FIXME: throw an SqlException exception
-			 * if there is a SQL Error
-			 */
-
-			/*
-			 * FIXME: get status
-			 */
                         execStatus = PostgresLibrary.
 					PQresultStatus (pgResult);
 			
 			if(execStatus == ExecStatusType.PGRES_COMMAND_OK)
 			{
-				Console.WriteLine("*** SqlCommand Execute " +
-					"got PGRES_COMMAND_OK");
 				rowsAffectedString = PostgresLibrary.
 					PQcmdTuples (pgResult);
-				Console.WriteLine("*** Rows Affected: " + 
-					rowsAffectedString);
-				// FIXME: convert string to number
+#if DEBUG_SqlCommand
+				Console.WriteLine("rowsAffectedString: " + 
+						rowsAffectedString);
+#endif // DEBUG_SqlCommand
+				if(rowsAffectedString != null)
+					if(rowsAffectedString.Equals("") == false)
+						rowsAffected = int.Parse(rowsAffectedString);
 			}
 			else
 			{
-				Console.WriteLine("*** Error: SqlCommand " +
-					"did not get PGRES_COMMAND_OK");
-				String statusString;
+				String errorMessage = "ExecuteNonQuery execution failure";
 				
-				statusString = PostgresLibrary.
+				errorMessage = PostgresLibrary.
 					PQresStatus(execStatus);
-				Console.WriteLine("*** Command Status: " +
-					statusString);
 
-				String errorMessage;
-				errorMessage = PostgresLibrary.
+				errorMessage += " " + PostgresLibrary.
 					PQresultErrorMessage(pgResult);
-
-				Console.WriteLine("*** Error message: " +
-					statusString);				
+				
+				throw new SqlException(0, 0,
+						  errorMessage, 0, "",
+						  conn.DataSource, "SqlCommand", 0);
 			}
-			
+#if DEBUG_SqlCommand			
 			String cmdStatus;
 			cmdStatus = PostgresLibrary.
 				PQcmdStatus(pgResult);
 
 			Console.WriteLine("*** Command Status: " +
 				cmdStatus);
-
+#endif // DEBUG_SqlCommand
 			PostgresLibrary.PQclear (pgResult);
 			
 			// FIXME: get number of rows
@@ -214,6 +206,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Prepare ()
 		{
+			// FIXME: parameters have to be implemented for this
 			throw new NotImplementedException ();
 		}
 
@@ -354,15 +347,21 @@ namespace System.Data.SqlClient
 
 		#endregion // Properties
 
-		#region Desctructors
-/*		
+		#region Destructors
+
+		[MonoTODO]
+		public void Dispose() {
+			// FIXME: need proper way to release resources
+			// Dispose(true);
+		}
+
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
 		~SqlCommand()
 		{
-			FIXME: need proper way to release resources
+			// FIXME: need proper way to release resources
+			// Dispose(false);
 		}
-*/
+
 		#endregion //Destructors
 	}
 }

+ 103 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommandBuilder.cs

@@ -0,0 +1,103 @@
+//
+// System.Data.SqlClient.SqlCommandBuilder.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.ComponentModel;
+
+namespace System.Data.SqlClient {
+
+	/// <summary>
+	/// Builder of one command
+	/// that will be used in manipulating a table for
+	/// a DataSet that is assoicated with a database.
+	/// </summary>
+	public sealed class SqlCommandBuilder : Component {
+		
+		[MonoTODO]
+		public SqlCommandBuilder() {
+
+		}
+
+		[MonoTODO]
+		public SqlCommandBuilder(SqlDataAdapter adapter) {
+		
+		}
+
+		[MonoTODO]
+		public SqlDataAdapter DataAdapter {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set{
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuotePrefix {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuoteSuffix {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public static void DeriveParameters(SqlCommand command) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetDeleteCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetInsertCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetUpdateCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public void RefreshSchema() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		protected override void Dispose(bool disposing) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlCommandBuilder() {
+			// FIXME: create destructor - release resources
+		}
+	}
+}
+

+ 59 - 46
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlConnection.cs

@@ -8,9 +8,8 @@
 // (C) Ximian, Inc 2002
 //
 
-// FIXME: what is the proper way to debug messages?
-// use #define DEBUG_SqlConnection if you want to spew debug messages for 
-#define DEBUG_SqlConnection
+// use #define DEBUG_SqlConnection if you want to spew debug messages
+// #define DEBUG_SqlConnection
 
 using System;
 using System.ComponentModel;
@@ -34,6 +33,9 @@ namespace System.Data.SqlClient
 	//	ICloneable
 	public sealed class SqlConnection : IDbConnection
 	{
+		// FIXME: Need to implement class Component, 
+		// and interfaces: ICloneable and IDisposable	
+
 		#region Fields
 
 		private PGconn pgConn = IntPtr.Zero;    
@@ -106,24 +108,31 @@ namespace System.Data.SqlClient
 		public SqlConnection (String connectionString)
 		{
 			SetConnectionString (connectionString);
-			OpenDataSource ();
 		}
 
-		#endregion
+		#endregion // Constructors
 
-		#region Deconstructors
+		#region Destructors
 
+		[MonoTODO]
+		public void Dispose () {	
+			// FIXME: release resources properly
+			Close ();
+			// Dispose (true);
+		}
+	
 		// aka Finalize
-
-
-		/*
-		[ClassInterface(ClassInterfaceType.AutoDual)]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		[MonoTODO]
 		~SqlConnection()
 		{
-
+			// FIXME: this class need 
+			//        a destructor to release resources
+			//        Also, take a look at Dispose
+			// Dispose (false);
 		}
-		*/
-		#endregion // Deconstructors
+		
+		#endregion // Destructors
 
 		#region Public Methods
 
@@ -148,6 +157,19 @@ namespace System.Data.SqlClient
 			return TransactionBegin (il); // call private method
 		}
 
+		// PostgreSQL does not support named transactions/savepoint
+		//            nor nested transactions
+		[Obsolete]
+		public SqlTransaction BeginTransaction(	string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
+		[Obsolete]
+		public SqlTransaction BeginTransaction(IsolationLevel iso,
+						string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
 		[MonoTODO]
 		public void ChangeDatabase (string databaseName)
 		{
@@ -178,15 +200,7 @@ namespace System.Data.SqlClient
 			OpenDataSource ();
 		}
 
-		[MonoTODO]
-		public void Dispose ()
-		{	
-			// FIXME: quick hack
-			Close ();
-			// Dispose (true);
-		}
-	
-		#endregion
+		#endregion // Public Methods
 
 		#region Internal Methods
 
@@ -218,6 +232,11 @@ namespace System.Data.SqlClient
 
 		private void OpenDataSource ()
 		{
+			if(dbname.Equals(""))
+				throw new InvalidOperationException("dbname missing");
+			else if(conState == ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is already Open");
+
 			ConnStatusType connStatus;
 
 			// FIXME: check to make sure we have 
@@ -242,24 +261,12 @@ namespace System.Data.SqlClient
 			{
 				String errorMessage = PostgresLibrary.
 					PQerrorMessage (pgConn);
-				// FIXME: use thie WriteLine's until
-				// exceptions have been implemented
-				Console.WriteLine("*** Error: " + 
-					"could not connect to database.");			
-				Console.WriteLine ("Error Message: " + 
-					errorMessage);
-
-				// FIXME: do error checking, 
-				// if could not connect, 
-				// throw an exception:
-				//  InvalidOperationException - attempt 
-				//    to connect to without specifying 
-				//    database or server
-				//  SqlException - error while 
-				//    connecting to database
-				
+				errorMessage += ": Could not connect to database.";
+
+				throw new SqlException(0, 0,
+					errorMessage, 0, "",
+					host, "SqlConnection", 0);
 			}
-			
 		}
 
 		private void CloseDataSource ()
@@ -297,12 +304,12 @@ namespace System.Data.SqlClient
 				connectionString);
 
 #if DEBUG_SqlConnection
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.pgConnectionString: " +
+			Console.WriteLine(
+				"OLE-DB Connection String    [in]: " +
+				this.ConnectionString);
+			Console.WriteLine(
+				"Postgres Connection String [out]: " +
 				pgConnectionString);
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.connectionString: " +
-				this.connectionString);
 #endif // DEBUG_SqlConnection
 		}
 
@@ -381,7 +388,7 @@ namespace System.Data.SqlClient
 
 				case "password":
 					password = parmValue;
-					addParm = false;
+				//	addParm = false;
 					break;
 
 				case "options":
@@ -429,7 +436,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public ConnectionState State 		{
 			get { 
-				throw new NotImplementedException (); 
+				return conState;
 			}
 		}
 
@@ -481,6 +488,12 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal SqlTransaction Transaction {
+			get {
+				return trans;
+			}
+		}
+
 		#endregion
 
 		#region Events and Delegates

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataAdapter.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Collections;
+using System.ComponentModel;
 using System.Data;
 
 namespace System.Data.SqlClient

+ 68 - 19
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlError.cs

@@ -19,86 +19,135 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlError
 	{
+		byte theClass = 0;
+		int lineNumber = 0;
+		string message = "";
+		int number = 0;
+		string procedure = "";
+		string server = "";
+		string source = "";
+		byte state = 0;
+
+		internal SqlError(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			this.theClass = theClass;
+			this.lineNumber = lineNumber;
+			this.message = message;
+			this.number = number;
+			this.procedure = procedure;
+			this.server = server;
+			this.source = source;
+			this.state = state;
+		}
+		
 		#region Properties
 
 		[MonoTODO]
+		/// <summary>
+		/// severity level of the error
+		/// </summary>
 		public byte Class {
 			get { 
-				throw new NotImplementedException ();
+				return theClass;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-			   throw new NotImplementedException ();
+			   return lineNumber;
 		   }
 		}
 
 		[MonoTODO]
 		public string Message {
 			get { 
-				throw new NotImplementedException ();
+				return message;
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException ();
+				return number;
 			}
 		}
 
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException ();
+				return procedure;
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException ();
+				return server;
 			}
 		}
 
 		[MonoTODO]
 		public string Source {
 			get { 
-				throw new NotImplementedException ();
+				return source;
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException ();
+				return state;
 			}
 		}
 
 		#endregion
 
 		#region Methods
-		
+
 		[MonoTODO]
 		public override string ToString ()
 		{
-			throw new NotImplementedException ();
+			String toStr;
+			String stackTrace = 
+			stackTrace = " <Stack Trace>";
+			// FIXME: generate the correct SQL error string
+			toStr = "SqlError:" + message + stackTrace;
+			return toStr;
 		}
-		#endregion
 
-		#region Destructors
+		internal void SetClass(byte theClass) {
+			this.theClass = theClass;
+		}
 
-		// FIXME: do the destructor
-/*
-		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
-		{
+		internal void SetLineNumber(int lineNumber) {
+			this.lineNumber = lineNumber;
+		}
+
+		internal void SetMessage(string message) {
+			this.message = message;
+		}
+
+		internal void SetNumber(int number) {
+			this.number = number;
+		}
+
+		internal void SetProcedure(string procedure) {
+			this.procedure = procedure;
+		}
+
+		internal void SetServer(string server) {
+			this.server = server;
+		}
+
+		internal void SetSource(string source) {
+			this.source = source;
+		}
 
+		internal void SetState(byte state) {
+			this.state = state;
 		}
-*/
 
 		#endregion
 		

+ 39 - 62
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlErrorCollection.cs

@@ -20,68 +20,27 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlErrorCollection : ICollection, IEnumerable
 	{
-		#region Properties
+		private int count = 0;
+		ArrayList errorList = new ArrayList();
 
-		[MonoTODO]
-		public byte Class {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection() {
 		}
 
-		[MonoTODO]
-		public int LineNumber {
-			get { 
-			   throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Message {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-		
-		[MonoTODO]
-		public int Number {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Procedure {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Server {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Source {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public byte State {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
 		}
 
+		#region Properties
+                
 		[MonoTODO]
 		public int Count {
 			get {	
-				throw new NotImplementedException ();
+				return errorList.Count;
 			}			  
 		}
 
@@ -109,6 +68,14 @@ namespace System.Data.SqlClient
 			throw new NotImplementedException ();
 		}
 
+		[MonoTODO]
+		// Index property (indexer)
+		public SqlError this[int index] {
+			get {
+				return (SqlError) errorList[index];
+			}
+		}
+
 		#endregion
 
 		#region Methods
@@ -120,19 +87,29 @@ namespace System.Data.SqlClient
 		}
 		#endregion
 
+		internal void Add(SqlError error) {
+			errorList.Add(error);
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			SqlError error = new SqlError(theClass,
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+			Add(error);
+		}
+
 		#region Destructors
 
-		// FIXME: do the destructor
-/*
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
+		~SqlErrorCollection()
 		{
-
+			// FIXME: do the destructor - release resources
 		}
-*/
 
-		#endregion
-		
+		#endregion		
 	}
 }

+ 103 - 18
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlException.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Data;
+using System.Runtime.Serialization;
 
 namespace System.Data.SqlClient
 {
@@ -17,101 +18,185 @@ namespace System.Data.SqlClient
 	/// </summary>
 	public sealed class SqlException : SystemException
 	{
+		private SqlErrorCollection errors = new SqlErrorCollection();
+
+		internal SqlException() {
+			
+		}
+
+		internal SqlException(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+						
+			errors = new SqlErrorCollection (theClass, 
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
 		#region Properties
-		
+
 		[MonoTODO]
 		public byte Class {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				else
+					return errors[0].Class;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetClass(value);
 			}
 		}
 
 		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
-				throw new NotImplementedException (); 
+				return errors;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors = value;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				return errors[0].LineNumber;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetLineNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Message 	{
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else {
+					String msg = "";
+					int i = 0;
+					
+					for(i = 0; i < errors.Count - 1; i++) {
+						msg = msg + errors[i].Message + "\n";
+                                        }
+					msg = msg + errors[i];
+
+					return msg;
+				}
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].Number;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Procedure;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetProcedure(value);
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Server;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetServer(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Source {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Source;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetSource(value);
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].State;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetState(value);
 			}
 		}
 
 		#endregion // Properties
+
+		#region Methods
+
+		[MonoTODO]
+		public override void GetObjectData(SerializationInfo si,
+			StreamingContext context) {
+			// FIXME: to do
+		}
+
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		public override string ToString() {
+			String toStr = "";
+			for (int i = 0; i < errors.Count; i++) {
+				toStr = toStr + errors[i].ToString() + "\n";
+			}
+			return toStr;
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			errors.Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
+		[MonoTODO]
+		~SqlException() {
+			// FIXME: destructor to release resources
+		}
+
+		#endregion // Methods
 	}
 }

+ 9 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventArgs.cs

@@ -15,12 +15,14 @@ namespace System.Data.SqlClient
 {
 	public sealed class SqlInfoMessageEventArgs : EventArgs
 	{
+		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}	
 
+		[MonoTODO]
 		public string Message 
 		{
 			get { 
@@ -28,14 +30,21 @@ namespace System.Data.SqlClient
 			}
 		}	
 
+		[MonoTODO]
 		public string Source {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}
 
+		[MonoTODO]
 		public override string ToString() {
 			// representation of InfoMessage event
 		}
+
+		[MonoTODO]
+		~SqlInfoMessageEventArgs() {
+			// FIXME: destructor needs to release resources
+		}
 	}
 }

+ 19 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventHandler.cs

@@ -0,0 +1,19 @@
+//
+// System.Data.SqlClient.SqlInfoMessageEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void 
+	SqlInfoMessageEventHandler (object sender,
+				SqlInfoMessageEventArgs e);
+}

+ 64 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameter.cs

@@ -8,6 +8,7 @@
 // (C) Ximian, Inc. 2002
 //
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 using System.Runtime.InteropServices;
@@ -23,6 +24,43 @@ namespace System.Data.SqlClient
 	//	IDbDataParameter, IDataParameter, ICloneable
 	public sealed class SqlParameter : IDbDataParameter, IDataParameter
 	{
+		[MonoTODO]
+		public SqlParameter () {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter (string parameterName, object value) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType) {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, string sourceColumn) {
+			// FIXME: do this
+		}
+			 
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, ParameterDirection direction, 
+			bool isNullable, byte precision,
+			byte scale, string sourceColumn,
+			DataRowVersion sourceVersion, object value) {
+			// FIXME: do this
+		}
+
+
 		[MonoTODO]
 		public DbType DbType {
 			get { 
@@ -50,6 +88,17 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public int Offset {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
+
 		[MonoTODO]
 		public string ParameterName {
 			get { 
@@ -82,6 +131,17 @@ namespace System.Data.SqlClient
 				throw new NotImplementedException (); 
 			}
 		}
+		
+		[MonoTODO]
+		public SqlDbType SqlDbType {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
 
 		[MonoTODO]
 		public object Value {
@@ -128,5 +188,9 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException (); 
+		}
 	}
 }

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Collections;
 

+ 38 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventArgs.cs

@@ -0,0 +1,38 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+	public sealed class SqlRowUpdatedEventArgs : RowUpdatedEventArgs {	
+		
+		[MonoTODO]
+		public SqlRowUpdatedEventArgs (DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+		
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatedEventArgs () {
+			// FIXME: need destructor to release resources
+		}
+
+	}
+}

+ 18 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatedEventHandler(object sender,
+					SqlRowUpdatedEventArgs e);
+}

+ 42 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventArgs.cs

@@ -0,0 +1,42 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient
+{
+	public sealed class SqlRowUpdatingEventArgs : RowUpdatingEventArgs
+	{
+		[MonoTODO]
+		public SqlRowUpdatingEventArgs(	DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatingEventArgs() {
+			// FIXME: create destructor to release resources
+		}
+	}
+}

+ 18 - 0
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatingEventHandler(object sender,
+			SqlRowUpdatingEventArgs e);
+}

+ 99 - 65
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlTransaction.cs

@@ -3,9 +3,15 @@
 //
 // Author:
 //   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
 //
 // (C) Ximian, Inc. 2002
 //
+
+// use #define DEBUG_SqlTransaction if you want to spew debug messages
+// #define DEBUG_SqlTransaction
+
+
 using System;
 using System.Data;
 using System.Data.Common;
@@ -21,12 +27,11 @@ namespace System.Data.SqlClient
 	{
 		#region Fields
 
+		private bool doingTransaction = false;
 		private SqlConnection conn = null;
-		//        How do you get/set the 
-		//        IsolationLevel in PostgreSQL?
 		private IsolationLevel isolationLevel =	
 			IsolationLevel.ReadCommitted;
-		// There are two IsolationLevel's for PostgreSQL:
+		// There are only two IsolationLevel's for PostgreSQL:
 		//    ReadCommitted and Serializable, 
 		// but ReadCommitted is the default 
 		
@@ -37,51 +42,48 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Commit ()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"COMMIT");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Commit transaction.");
+			
+			SqlCommand cmd = new SqlCommand("COMMIT", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
 		}		
 
 		[MonoTODO]
 		public void Rollback()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"ROLLBACK");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Rollback transaction.");
+			
+			SqlCommand cmd = new SqlCommand("ROLLBACK", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
+		}
+
+		// For PostgreSQL, Rollback(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Rollback(string transactionName) {
+			// throw new NotImplementedException ();
+			Rollback();
+		}
+
+		// For PostgreSQL, Save(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Save (string savePointName) {
+			// throw new NotImplementedException ();
 		}
 
 		#endregion // Public Methods
@@ -90,30 +92,40 @@ namespace System.Data.SqlClient
 
 		internal void Begin()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"BEGIN");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == true)
+				throw new InvalidOperationException(
+					"Transaction has begun " +
+					"and PostgreSQL does not " +
+					"support nested transactions.");
+			
+			SqlCommand cmd = new SqlCommand("BEGIN", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = true;
 		}
 
 		internal void SetIsolationLevel(IsolationLevel isoLevel)
 		{
+			String sSql = "SET TRANSACTION ISOLATION LEVEL ";
+ 
+			switch (isoLevel) 
+			{
+				case IsolationLevel.ReadCommitted:
+					sSql += "READ COMMITTED";
+					break;
+
+				case IsolationLevel.Serializable:
+					sSql += "SERIALIZABLE";
+					break;
+				default:
+					// FIXME: generate exception here
+					// PostgreSQL only supports:
+					//   ReadCommitted or Serializable
+					break;
+			}
+			SqlCommand cmd = new SqlCommand(sSql, conn);
+			cmd.ExecuteNonQuery();
+
 			this.isolationLevel = isoLevel;
 		}
 
@@ -144,13 +156,35 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal bool DoingTransaction {
+			get {
+				return doingTransaction;
+			}
+		}
+
+		#endregion Properties
+
+		#region Destructors
+
+		// Destructors aka Finalize and Dispose
+
 		[MonoTODO]
 		public void Dispose()
 		{
 			// FIXME: need to properly release resources
+			// Dispose(true);
 		}
-	
-		#endregion // Properties
+
+		// Destructor 
+		[MonoTODO]
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		~SqlTransaction() {
+			// FIXME: need to properly release resources
+			// Dispose(false);
+		}
+
+		#endregion // Destructors
 
 	}
 }

+ 0 - 1
mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs

@@ -55,7 +55,6 @@ namespace System.Data.SqlClient
 		PGRES_FATAL_ERROR
 	}
 
-	// FIXME: should be sealed internal class
 	sealed internal class PostgresLibrary
 	{
 		#region PInvoke Functions

+ 76 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlClientPermission.cs

@@ -0,0 +1,76 @@
+//
+// System.Data.SqlClient.SqlClientPermission.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	public sealed class SqlClientPermission : DBDataPermission {
+		
+		[MonoTODO]
+		public SqlClientPermission() {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state) {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state,
+			bool allowBlankPassword) { 
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Copy() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override void FromXml(SecurityElement 
+					securityElement) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Intersect(IPermission target)  {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override bool IsSubsetOf(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override SecurityElement ToXml() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Union(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermission() {
+			// FIXME: destructor to release resources
+		}
+	}
+}

+ 51 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlClientPermissionAttribute.cs

@@ -0,0 +1,51 @@
+//
+// System.Data.SqlClient.SqlClientPermissionAttribute.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	[AttributeUsage(AttributeTargets.Assembly    | 
+			AttributeTargets.Class 	     | 
+			AttributeTargets.Struct      | 
+			AttributeTargets.Constructor |
+			AttributeTargets.Method)]
+	[Serializable]
+	public sealed class SqlClientPermissionAttribute :
+		DBDataPermissionAttribute {
+
+		[MonoTODO]
+		[AttributeUsage(AttributeTargets.Assembly    | 
+			 AttributeTargets.Class       | 
+			 AttributeTargets.Struct      | 
+			 AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public SqlClientPermissionAttribute(SecurityAction action) {
+			// FIXME: do constructor
+		}
+
+		[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
+			 | AttributeTargets.Struct | AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public override IPermission CreatePermission() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermissionAttribute() {
+			// FIXME: destructor to release resources
+		}
+	}
+
+}

+ 33 - 34
mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs

@@ -8,6 +8,9 @@
 // (C) Ximian, Inc 2002
 //
 
+// use #define DEBUG_SqlCommand if you want to spew debug messages
+// #define DEBUG_SqlCommand
+
 using System;
 using System.ComponentModel;
 using System.Data;
@@ -99,10 +102,8 @@ namespace System.Data.SqlClient
 			ExecStatusType execStatus;
 			String rowsAffectedString;
 
-			// FIXME: throw an 
-			// InvalidOperationException
-			// exception if the the connection
-			// does not exist or is not open
+			if(conn.State != ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is not Open");
 
 			// FIXME: PQexec blocks 
 			// while PQsendQuery is non-blocking
@@ -115,52 +116,43 @@ namespace System.Data.SqlClient
 			pgResult = PostgresLibrary.
 				PQexec (conn.PostgresConnection, sql);
 
-			/* FIXME: throw an SqlException exception
-			 * if there is a SQL Error
-			 */
-
-			/*
-			 * FIXME: get status
-			 */
                         execStatus = PostgresLibrary.
 					PQresultStatus (pgResult);
 			
 			if(execStatus == ExecStatusType.PGRES_COMMAND_OK)
 			{
-				Console.WriteLine("*** SqlCommand Execute " +
-					"got PGRES_COMMAND_OK");
 				rowsAffectedString = PostgresLibrary.
 					PQcmdTuples (pgResult);
-				Console.WriteLine("*** Rows Affected: " + 
-					rowsAffectedString);
-				// FIXME: convert string to number
+#if DEBUG_SqlCommand
+				Console.WriteLine("rowsAffectedString: " + 
+						rowsAffectedString);
+#endif // DEBUG_SqlCommand
+				if(rowsAffectedString != null)
+					if(rowsAffectedString.Equals("") == false)
+						rowsAffected = int.Parse(rowsAffectedString);
 			}
 			else
 			{
-				Console.WriteLine("*** Error: SqlCommand " +
-					"did not get PGRES_COMMAND_OK");
-				String statusString;
+				String errorMessage = "ExecuteNonQuery execution failure";
 				
-				statusString = PostgresLibrary.
+				errorMessage = PostgresLibrary.
 					PQresStatus(execStatus);
-				Console.WriteLine("*** Command Status: " +
-					statusString);
 
-				String errorMessage;
-				errorMessage = PostgresLibrary.
+				errorMessage += " " + PostgresLibrary.
 					PQresultErrorMessage(pgResult);
-
-				Console.WriteLine("*** Error message: " +
-					statusString);				
+				
+				throw new SqlException(0, 0,
+						  errorMessage, 0, "",
+						  conn.DataSource, "SqlCommand", 0);
 			}
-			
+#if DEBUG_SqlCommand			
 			String cmdStatus;
 			cmdStatus = PostgresLibrary.
 				PQcmdStatus(pgResult);
 
 			Console.WriteLine("*** Command Status: " +
 				cmdStatus);
-
+#endif // DEBUG_SqlCommand
 			PostgresLibrary.PQclear (pgResult);
 			
 			// FIXME: get number of rows
@@ -214,6 +206,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Prepare ()
 		{
+			// FIXME: parameters have to be implemented for this
 			throw new NotImplementedException ();
 		}
 
@@ -354,15 +347,21 @@ namespace System.Data.SqlClient
 
 		#endregion // Properties
 
-		#region Desctructors
-/*		
+		#region Destructors
+
+		[MonoTODO]
+		public void Dispose() {
+			// FIXME: need proper way to release resources
+			// Dispose(true);
+		}
+
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
 		~SqlCommand()
 		{
-			FIXME: need proper way to release resources
+			// FIXME: need proper way to release resources
+			// Dispose(false);
 		}
-*/
+
 		#endregion //Destructors
 	}
 }

+ 103 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommandBuilder.cs

@@ -0,0 +1,103 @@
+//
+// System.Data.SqlClient.SqlCommandBuilder.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.ComponentModel;
+
+namespace System.Data.SqlClient {
+
+	/// <summary>
+	/// Builder of one command
+	/// that will be used in manipulating a table for
+	/// a DataSet that is assoicated with a database.
+	/// </summary>
+	public sealed class SqlCommandBuilder : Component {
+		
+		[MonoTODO]
+		public SqlCommandBuilder() {
+
+		}
+
+		[MonoTODO]
+		public SqlCommandBuilder(SqlDataAdapter adapter) {
+		
+		}
+
+		[MonoTODO]
+		public SqlDataAdapter DataAdapter {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set{
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuotePrefix {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuoteSuffix {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public static void DeriveParameters(SqlCommand command) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetDeleteCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetInsertCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetUpdateCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public void RefreshSchema() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		protected override void Dispose(bool disposing) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlCommandBuilder() {
+			// FIXME: create destructor - release resources
+		}
+	}
+}
+

+ 59 - 46
mcs/class/Mono.Data.PostgreSqlClient/PgSqlConnection.cs

@@ -8,9 +8,8 @@
 // (C) Ximian, Inc 2002
 //
 
-// FIXME: what is the proper way to debug messages?
-// use #define DEBUG_SqlConnection if you want to spew debug messages for 
-#define DEBUG_SqlConnection
+// use #define DEBUG_SqlConnection if you want to spew debug messages
+// #define DEBUG_SqlConnection
 
 using System;
 using System.ComponentModel;
@@ -34,6 +33,9 @@ namespace System.Data.SqlClient
 	//	ICloneable
 	public sealed class SqlConnection : IDbConnection
 	{
+		// FIXME: Need to implement class Component, 
+		// and interfaces: ICloneable and IDisposable	
+
 		#region Fields
 
 		private PGconn pgConn = IntPtr.Zero;    
@@ -106,24 +108,31 @@ namespace System.Data.SqlClient
 		public SqlConnection (String connectionString)
 		{
 			SetConnectionString (connectionString);
-			OpenDataSource ();
 		}
 
-		#endregion
+		#endregion // Constructors
 
-		#region Deconstructors
+		#region Destructors
 
+		[MonoTODO]
+		public void Dispose () {	
+			// FIXME: release resources properly
+			Close ();
+			// Dispose (true);
+		}
+	
 		// aka Finalize
-
-
-		/*
-		[ClassInterface(ClassInterfaceType.AutoDual)]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		[MonoTODO]
 		~SqlConnection()
 		{
-
+			// FIXME: this class need 
+			//        a destructor to release resources
+			//        Also, take a look at Dispose
+			// Dispose (false);
 		}
-		*/
-		#endregion // Deconstructors
+		
+		#endregion // Destructors
 
 		#region Public Methods
 
@@ -148,6 +157,19 @@ namespace System.Data.SqlClient
 			return TransactionBegin (il); // call private method
 		}
 
+		// PostgreSQL does not support named transactions/savepoint
+		//            nor nested transactions
+		[Obsolete]
+		public SqlTransaction BeginTransaction(	string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
+		[Obsolete]
+		public SqlTransaction BeginTransaction(IsolationLevel iso,
+						string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
 		[MonoTODO]
 		public void ChangeDatabase (string databaseName)
 		{
@@ -178,15 +200,7 @@ namespace System.Data.SqlClient
 			OpenDataSource ();
 		}
 
-		[MonoTODO]
-		public void Dispose ()
-		{	
-			// FIXME: quick hack
-			Close ();
-			// Dispose (true);
-		}
-	
-		#endregion
+		#endregion // Public Methods
 
 		#region Internal Methods
 
@@ -218,6 +232,11 @@ namespace System.Data.SqlClient
 
 		private void OpenDataSource ()
 		{
+			if(dbname.Equals(""))
+				throw new InvalidOperationException("dbname missing");
+			else if(conState == ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is already Open");
+
 			ConnStatusType connStatus;
 
 			// FIXME: check to make sure we have 
@@ -242,24 +261,12 @@ namespace System.Data.SqlClient
 			{
 				String errorMessage = PostgresLibrary.
 					PQerrorMessage (pgConn);
-				// FIXME: use thie WriteLine's until
-				// exceptions have been implemented
-				Console.WriteLine("*** Error: " + 
-					"could not connect to database.");			
-				Console.WriteLine ("Error Message: " + 
-					errorMessage);
-
-				// FIXME: do error checking, 
-				// if could not connect, 
-				// throw an exception:
-				//  InvalidOperationException - attempt 
-				//    to connect to without specifying 
-				//    database or server
-				//  SqlException - error while 
-				//    connecting to database
-				
+				errorMessage += ": Could not connect to database.";
+
+				throw new SqlException(0, 0,
+					errorMessage, 0, "",
+					host, "SqlConnection", 0);
 			}
-			
 		}
 
 		private void CloseDataSource ()
@@ -297,12 +304,12 @@ namespace System.Data.SqlClient
 				connectionString);
 
 #if DEBUG_SqlConnection
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.pgConnectionString: " +
+			Console.WriteLine(
+				"OLE-DB Connection String    [in]: " +
+				this.ConnectionString);
+			Console.WriteLine(
+				"Postgres Connection String [out]: " +
 				pgConnectionString);
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.connectionString: " +
-				this.connectionString);
 #endif // DEBUG_SqlConnection
 		}
 
@@ -381,7 +388,7 @@ namespace System.Data.SqlClient
 
 				case "password":
 					password = parmValue;
-					addParm = false;
+				//	addParm = false;
 					break;
 
 				case "options":
@@ -429,7 +436,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public ConnectionState State 		{
 			get { 
-				throw new NotImplementedException (); 
+				return conState;
 			}
 		}
 
@@ -481,6 +488,12 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal SqlTransaction Transaction {
+			get {
+				return trans;
+			}
+		}
+
 		#endregion
 
 		#region Events and Delegates

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataAdapter.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Collections;
+using System.ComponentModel;
 using System.Data;
 
 namespace System.Data.SqlClient

+ 68 - 19
mcs/class/Mono.Data.PostgreSqlClient/PgSqlError.cs

@@ -19,86 +19,135 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlError
 	{
+		byte theClass = 0;
+		int lineNumber = 0;
+		string message = "";
+		int number = 0;
+		string procedure = "";
+		string server = "";
+		string source = "";
+		byte state = 0;
+
+		internal SqlError(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			this.theClass = theClass;
+			this.lineNumber = lineNumber;
+			this.message = message;
+			this.number = number;
+			this.procedure = procedure;
+			this.server = server;
+			this.source = source;
+			this.state = state;
+		}
+		
 		#region Properties
 
 		[MonoTODO]
+		/// <summary>
+		/// severity level of the error
+		/// </summary>
 		public byte Class {
 			get { 
-				throw new NotImplementedException ();
+				return theClass;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-			   throw new NotImplementedException ();
+			   return lineNumber;
 		   }
 		}
 
 		[MonoTODO]
 		public string Message {
 			get { 
-				throw new NotImplementedException ();
+				return message;
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException ();
+				return number;
 			}
 		}
 
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException ();
+				return procedure;
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException ();
+				return server;
 			}
 		}
 
 		[MonoTODO]
 		public string Source {
 			get { 
-				throw new NotImplementedException ();
+				return source;
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException ();
+				return state;
 			}
 		}
 
 		#endregion
 
 		#region Methods
-		
+
 		[MonoTODO]
 		public override string ToString ()
 		{
-			throw new NotImplementedException ();
+			String toStr;
+			String stackTrace = 
+			stackTrace = " <Stack Trace>";
+			// FIXME: generate the correct SQL error string
+			toStr = "SqlError:" + message + stackTrace;
+			return toStr;
 		}
-		#endregion
 
-		#region Destructors
+		internal void SetClass(byte theClass) {
+			this.theClass = theClass;
+		}
 
-		// FIXME: do the destructor
-/*
-		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
-		{
+		internal void SetLineNumber(int lineNumber) {
+			this.lineNumber = lineNumber;
+		}
+
+		internal void SetMessage(string message) {
+			this.message = message;
+		}
+
+		internal void SetNumber(int number) {
+			this.number = number;
+		}
+
+		internal void SetProcedure(string procedure) {
+			this.procedure = procedure;
+		}
+
+		internal void SetServer(string server) {
+			this.server = server;
+		}
+
+		internal void SetSource(string source) {
+			this.source = source;
+		}
 
+		internal void SetState(byte state) {
+			this.state = state;
 		}
-*/
 
 		#endregion
 		

+ 39 - 62
mcs/class/Mono.Data.PostgreSqlClient/PgSqlErrorCollection.cs

@@ -20,68 +20,27 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlErrorCollection : ICollection, IEnumerable
 	{
-		#region Properties
+		private int count = 0;
+		ArrayList errorList = new ArrayList();
 
-		[MonoTODO]
-		public byte Class {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection() {
 		}
 
-		[MonoTODO]
-		public int LineNumber {
-			get { 
-			   throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Message {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-		
-		[MonoTODO]
-		public int Number {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Procedure {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Server {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Source {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public byte State {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
 		}
 
+		#region Properties
+                
 		[MonoTODO]
 		public int Count {
 			get {	
-				throw new NotImplementedException ();
+				return errorList.Count;
 			}			  
 		}
 
@@ -109,6 +68,14 @@ namespace System.Data.SqlClient
 			throw new NotImplementedException ();
 		}
 
+		[MonoTODO]
+		// Index property (indexer)
+		public SqlError this[int index] {
+			get {
+				return (SqlError) errorList[index];
+			}
+		}
+
 		#endregion
 
 		#region Methods
@@ -120,19 +87,29 @@ namespace System.Data.SqlClient
 		}
 		#endregion
 
+		internal void Add(SqlError error) {
+			errorList.Add(error);
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			SqlError error = new SqlError(theClass,
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+			Add(error);
+		}
+
 		#region Destructors
 
-		// FIXME: do the destructor
-/*
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
+		~SqlErrorCollection()
 		{
-
+			// FIXME: do the destructor - release resources
 		}
-*/
 
-		#endregion
-		
+		#endregion		
 	}
 }

+ 103 - 18
mcs/class/Mono.Data.PostgreSqlClient/PgSqlException.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Data;
+using System.Runtime.Serialization;
 
 namespace System.Data.SqlClient
 {
@@ -17,101 +18,185 @@ namespace System.Data.SqlClient
 	/// </summary>
 	public sealed class SqlException : SystemException
 	{
+		private SqlErrorCollection errors = new SqlErrorCollection();
+
+		internal SqlException() {
+			
+		}
+
+		internal SqlException(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+						
+			errors = new SqlErrorCollection (theClass, 
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
 		#region Properties
-		
+
 		[MonoTODO]
 		public byte Class {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				else
+					return errors[0].Class;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetClass(value);
 			}
 		}
 
 		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
-				throw new NotImplementedException (); 
+				return errors;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors = value;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				return errors[0].LineNumber;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetLineNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Message 	{
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else {
+					String msg = "";
+					int i = 0;
+					
+					for(i = 0; i < errors.Count - 1; i++) {
+						msg = msg + errors[i].Message + "\n";
+                                        }
+					msg = msg + errors[i];
+
+					return msg;
+				}
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].Number;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Procedure;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetProcedure(value);
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Server;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetServer(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Source {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Source;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetSource(value);
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].State;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetState(value);
 			}
 		}
 
 		#endregion // Properties
+
+		#region Methods
+
+		[MonoTODO]
+		public override void GetObjectData(SerializationInfo si,
+			StreamingContext context) {
+			// FIXME: to do
+		}
+
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		public override string ToString() {
+			String toStr = "";
+			for (int i = 0; i < errors.Count; i++) {
+				toStr = toStr + errors[i].ToString() + "\n";
+			}
+			return toStr;
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			errors.Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
+		[MonoTODO]
+		~SqlException() {
+			// FIXME: destructor to release resources
+		}
+
+		#endregion // Methods
 	}
 }

+ 9 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventArgs.cs

@@ -15,12 +15,14 @@ namespace System.Data.SqlClient
 {
 	public sealed class SqlInfoMessageEventArgs : EventArgs
 	{
+		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}	
 
+		[MonoTODO]
 		public string Message 
 		{
 			get { 
@@ -28,14 +30,21 @@ namespace System.Data.SqlClient
 			}
 		}	
 
+		[MonoTODO]
 		public string Source {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}
 
+		[MonoTODO]
 		public override string ToString() {
 			// representation of InfoMessage event
 		}
+
+		[MonoTODO]
+		~SqlInfoMessageEventArgs() {
+			// FIXME: destructor needs to release resources
+		}
 	}
 }

+ 19 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlInfoMessageEventHandler.cs

@@ -0,0 +1,19 @@
+//
+// System.Data.SqlClient.SqlInfoMessageEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void 
+	SqlInfoMessageEventHandler (object sender,
+				SqlInfoMessageEventArgs e);
+}

+ 64 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameter.cs

@@ -8,6 +8,7 @@
 // (C) Ximian, Inc. 2002
 //
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 using System.Runtime.InteropServices;
@@ -23,6 +24,43 @@ namespace System.Data.SqlClient
 	//	IDbDataParameter, IDataParameter, ICloneable
 	public sealed class SqlParameter : IDbDataParameter, IDataParameter
 	{
+		[MonoTODO]
+		public SqlParameter () {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter (string parameterName, object value) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType) {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, string sourceColumn) {
+			// FIXME: do this
+		}
+			 
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, ParameterDirection direction, 
+			bool isNullable, byte precision,
+			byte scale, string sourceColumn,
+			DataRowVersion sourceVersion, object value) {
+			// FIXME: do this
+		}
+
+
 		[MonoTODO]
 		public DbType DbType {
 			get { 
@@ -50,6 +88,17 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public int Offset {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
+
 		[MonoTODO]
 		public string ParameterName {
 			get { 
@@ -82,6 +131,17 @@ namespace System.Data.SqlClient
 				throw new NotImplementedException (); 
 			}
 		}
+		
+		[MonoTODO]
+		public SqlDbType SqlDbType {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
 
 		[MonoTODO]
 		public object Value {
@@ -128,5 +188,9 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException (); 
+		}
 	}
 }

+ 1 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlParameterCollection.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Collections;
 

+ 38 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventArgs.cs

@@ -0,0 +1,38 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+	public sealed class SqlRowUpdatedEventArgs : RowUpdatedEventArgs {	
+		
+		[MonoTODO]
+		public SqlRowUpdatedEventArgs (DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+		
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatedEventArgs () {
+			// FIXME: need destructor to release resources
+		}
+
+	}
+}

+ 18 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatedEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatedEventHandler(object sender,
+					SqlRowUpdatedEventArgs e);
+}

+ 42 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventArgs.cs

@@ -0,0 +1,42 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient
+{
+	public sealed class SqlRowUpdatingEventArgs : RowUpdatingEventArgs
+	{
+		[MonoTODO]
+		public SqlRowUpdatingEventArgs(	DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatingEventArgs() {
+			// FIXME: create destructor to release resources
+		}
+	}
+}

+ 18 - 0
mcs/class/Mono.Data.PostgreSqlClient/PgSqlRowUpdatingEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatingEventHandler(object sender,
+			SqlRowUpdatingEventArgs e);
+}

+ 99 - 65
mcs/class/Mono.Data.PostgreSqlClient/PgSqlTransaction.cs

@@ -3,9 +3,15 @@
 //
 // Author:
 //   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
 //
 // (C) Ximian, Inc. 2002
 //
+
+// use #define DEBUG_SqlTransaction if you want to spew debug messages
+// #define DEBUG_SqlTransaction
+
+
 using System;
 using System.Data;
 using System.Data.Common;
@@ -21,12 +27,11 @@ namespace System.Data.SqlClient
 	{
 		#region Fields
 
+		private bool doingTransaction = false;
 		private SqlConnection conn = null;
-		//        How do you get/set the 
-		//        IsolationLevel in PostgreSQL?
 		private IsolationLevel isolationLevel =	
 			IsolationLevel.ReadCommitted;
-		// There are two IsolationLevel's for PostgreSQL:
+		// There are only two IsolationLevel's for PostgreSQL:
 		//    ReadCommitted and Serializable, 
 		// but ReadCommitted is the default 
 		
@@ -37,51 +42,48 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Commit ()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"COMMIT");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Commit transaction.");
+			
+			SqlCommand cmd = new SqlCommand("COMMIT", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
 		}		
 
 		[MonoTODO]
 		public void Rollback()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"ROLLBACK");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Rollback transaction.");
+			
+			SqlCommand cmd = new SqlCommand("ROLLBACK", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
+		}
+
+		// For PostgreSQL, Rollback(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Rollback(string transactionName) {
+			// throw new NotImplementedException ();
+			Rollback();
+		}
+
+		// For PostgreSQL, Save(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Save (string savePointName) {
+			// throw new NotImplementedException ();
 		}
 
 		#endregion // Public Methods
@@ -90,30 +92,40 @@ namespace System.Data.SqlClient
 
 		internal void Begin()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"BEGIN");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == true)
+				throw new InvalidOperationException(
+					"Transaction has begun " +
+					"and PostgreSQL does not " +
+					"support nested transactions.");
+			
+			SqlCommand cmd = new SqlCommand("BEGIN", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = true;
 		}
 
 		internal void SetIsolationLevel(IsolationLevel isoLevel)
 		{
+			String sSql = "SET TRANSACTION ISOLATION LEVEL ";
+ 
+			switch (isoLevel) 
+			{
+				case IsolationLevel.ReadCommitted:
+					sSql += "READ COMMITTED";
+					break;
+
+				case IsolationLevel.Serializable:
+					sSql += "SERIALIZABLE";
+					break;
+				default:
+					// FIXME: generate exception here
+					// PostgreSQL only supports:
+					//   ReadCommitted or Serializable
+					break;
+			}
+			SqlCommand cmd = new SqlCommand(sSql, conn);
+			cmd.ExecuteNonQuery();
+
 			this.isolationLevel = isoLevel;
 		}
 
@@ -144,13 +156,35 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal bool DoingTransaction {
+			get {
+				return doingTransaction;
+			}
+		}
+
+		#endregion Properties
+
+		#region Destructors
+
+		// Destructors aka Finalize and Dispose
+
 		[MonoTODO]
 		public void Dispose()
 		{
 			// FIXME: need to properly release resources
+			// Dispose(true);
 		}
-	
-		#endregion // Properties
+
+		// Destructor 
+		[MonoTODO]
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		~SqlTransaction() {
+			// FIXME: need to properly release resources
+			// Dispose(false);
+		}
+
+		#endregion // Destructors
 
 	}
 }

+ 0 - 1
mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs

@@ -55,7 +55,6 @@ namespace System.Data.SqlClient
 		PGRES_FATAL_ERROR
 	}
 
-	// FIXME: should be sealed internal class
 	sealed internal class PostgresLibrary
 	{
 		#region PInvoke Functions

+ 37 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,40 @@
+2002-04-20  Daniel Morgan <[email protected]>
+
+* System.Data.OleDb: added directory - for OleDb database 
+provider classes
+
+* System.Data.SqlClient/SqlClientPermission.cs
+* System.Data.SqlClient/SqlClientPermissionAttribute.cs
+* System.Data.SqlClient/SqlCommandBuilder.cs
+* System.Data.SqlClient/SqlInfoMessageEventHandler.cs
+* System.Data.SqlClient/SqlRowUpdatedEventArgs.cs
+* System.Data.SqlClient/SqlRowUpdatedEventHandler.cs
+* System.Data.SqlClient/SqlRowUpdatingEventArgs.cs
+* System.Data.SqlClient/SqlRowUpdatingEventHandler.cs
+* Test/TestSqlException.cs
+* Test/TestSqlIsolationLevel.cs: added - more tests
+
+* System.Data.build: modified - added new files - excludes these too
+
+* System.Data.SqlClient/PostgresLibrary.cs - modified - comment
+
+* System.Data.SqlClient/SqlConnection.cs 
+* System.Data.SqlClient/SqlCommand.cs
+* System.Data.SqlClient/SqlTransaction.cs
+* System.Data.SqlClient/SqlException.cs
+* System.Data.SqlClient/SqlErrorCollection.cs
+* System.Data.SqlClient/SqlError.cs: modified - transaction and
+  exception/error handling. SqlConnection(connectionString) 
+  constructor should not automatically connect.
+  
+* System.Data.SqlClient/SqlDataReader.cs
+* System.Data.SqlClient/SqlDataAdapter.cs
+* System.Data.SqlClient/SqlParameter.cs
+* System.Data.SqlClient/SqlParameterCollection.cs: modified - 
+added using System.ComponentModel;
+  
+* Test/TestSqlInsert.cs: modified - to use transaction
+
 2002-04-17  Rodrigo Moya <[email protected]>
 
 	* System.Data/DataRow.cs: new skeletons.

+ 0 - 1
mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs

@@ -55,7 +55,6 @@ namespace System.Data.SqlClient
 		PGRES_FATAL_ERROR
 	}
 
-	// FIXME: should be sealed internal class
 	sealed internal class PostgresLibrary
 	{
 		#region PInvoke Functions

+ 76 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlClientPermission.cs

@@ -0,0 +1,76 @@
+//
+// System.Data.SqlClient.SqlClientPermission.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	public sealed class SqlClientPermission : DBDataPermission {
+		
+		[MonoTODO]
+		public SqlClientPermission() {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state) {
+			// FIXME: do constructor
+		}
+
+		[MonoTODO]
+		public SqlClientPermission(PermissionState state,
+			bool allowBlankPassword) { 
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Copy() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override void FromXml(SecurityElement 
+					securityElement) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Intersect(IPermission target)  {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override bool IsSubsetOf(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override SecurityElement ToXml() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public override IPermission Union(IPermission target) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermission() {
+			// FIXME: destructor to release resources
+		}
+	}
+}

+ 51 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlClientPermissionAttribute.cs

@@ -0,0 +1,51 @@
+//
+// System.Data.SqlClient.SqlClientPermissionAttribute.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+
+	[AttributeUsage(AttributeTargets.Assembly    | 
+			AttributeTargets.Class 	     | 
+			AttributeTargets.Struct      | 
+			AttributeTargets.Constructor |
+			AttributeTargets.Method)]
+	[Serializable]
+	public sealed class SqlClientPermissionAttribute :
+		DBDataPermissionAttribute {
+
+		[MonoTODO]
+		[AttributeUsage(AttributeTargets.Assembly    | 
+			 AttributeTargets.Class       | 
+			 AttributeTargets.Struct      | 
+			 AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public SqlClientPermissionAttribute(SecurityAction action) {
+			// FIXME: do constructor
+		}
+
+		[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
+			 | AttributeTargets.Struct | AttributeTargets.Constructor |
+			 AttributeTargets.Method)]
+		[Serializable]
+		public override IPermission CreatePermission() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlClientPermissionAttribute() {
+			// FIXME: destructor to release resources
+		}
+	}
+
+}

+ 33 - 34
mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs

@@ -8,6 +8,9 @@
 // (C) Ximian, Inc 2002
 //
 
+// use #define DEBUG_SqlCommand if you want to spew debug messages
+// #define DEBUG_SqlCommand
+
 using System;
 using System.ComponentModel;
 using System.Data;
@@ -99,10 +102,8 @@ namespace System.Data.SqlClient
 			ExecStatusType execStatus;
 			String rowsAffectedString;
 
-			// FIXME: throw an 
-			// InvalidOperationException
-			// exception if the the connection
-			// does not exist or is not open
+			if(conn.State != ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is not Open");
 
 			// FIXME: PQexec blocks 
 			// while PQsendQuery is non-blocking
@@ -115,52 +116,43 @@ namespace System.Data.SqlClient
 			pgResult = PostgresLibrary.
 				PQexec (conn.PostgresConnection, sql);
 
-			/* FIXME: throw an SqlException exception
-			 * if there is a SQL Error
-			 */
-
-			/*
-			 * FIXME: get status
-			 */
                         execStatus = PostgresLibrary.
 					PQresultStatus (pgResult);
 			
 			if(execStatus == ExecStatusType.PGRES_COMMAND_OK)
 			{
-				Console.WriteLine("*** SqlCommand Execute " +
-					"got PGRES_COMMAND_OK");
 				rowsAffectedString = PostgresLibrary.
 					PQcmdTuples (pgResult);
-				Console.WriteLine("*** Rows Affected: " + 
-					rowsAffectedString);
-				// FIXME: convert string to number
+#if DEBUG_SqlCommand
+				Console.WriteLine("rowsAffectedString: " + 
+						rowsAffectedString);
+#endif // DEBUG_SqlCommand
+				if(rowsAffectedString != null)
+					if(rowsAffectedString.Equals("") == false)
+						rowsAffected = int.Parse(rowsAffectedString);
 			}
 			else
 			{
-				Console.WriteLine("*** Error: SqlCommand " +
-					"did not get PGRES_COMMAND_OK");
-				String statusString;
+				String errorMessage = "ExecuteNonQuery execution failure";
 				
-				statusString = PostgresLibrary.
+				errorMessage = PostgresLibrary.
 					PQresStatus(execStatus);
-				Console.WriteLine("*** Command Status: " +
-					statusString);
 
-				String errorMessage;
-				errorMessage = PostgresLibrary.
+				errorMessage += " " + PostgresLibrary.
 					PQresultErrorMessage(pgResult);
-
-				Console.WriteLine("*** Error message: " +
-					statusString);				
+				
+				throw new SqlException(0, 0,
+						  errorMessage, 0, "",
+						  conn.DataSource, "SqlCommand", 0);
 			}
-			
+#if DEBUG_SqlCommand			
 			String cmdStatus;
 			cmdStatus = PostgresLibrary.
 				PQcmdStatus(pgResult);
 
 			Console.WriteLine("*** Command Status: " +
 				cmdStatus);
-
+#endif // DEBUG_SqlCommand
 			PostgresLibrary.PQclear (pgResult);
 			
 			// FIXME: get number of rows
@@ -214,6 +206,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Prepare ()
 		{
+			// FIXME: parameters have to be implemented for this
 			throw new NotImplementedException ();
 		}
 
@@ -354,15 +347,21 @@ namespace System.Data.SqlClient
 
 		#endregion // Properties
 
-		#region Desctructors
-/*		
+		#region Destructors
+
+		[MonoTODO]
+		public void Dispose() {
+			// FIXME: need proper way to release resources
+			// Dispose(true);
+		}
+
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
 		~SqlCommand()
 		{
-			FIXME: need proper way to release resources
+			// FIXME: need proper way to release resources
+			// Dispose(false);
 		}
-*/
+
 		#endregion //Destructors
 	}
 }

+ 103 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlCommandBuilder.cs

@@ -0,0 +1,103 @@
+//
+// System.Data.SqlClient.SqlCommandBuilder.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.ComponentModel;
+
+namespace System.Data.SqlClient {
+
+	/// <summary>
+	/// Builder of one command
+	/// that will be used in manipulating a table for
+	/// a DataSet that is assoicated with a database.
+	/// </summary>
+	public sealed class SqlCommandBuilder : Component {
+		
+		[MonoTODO]
+		public SqlCommandBuilder() {
+
+		}
+
+		[MonoTODO]
+		public SqlCommandBuilder(SqlDataAdapter adapter) {
+		
+		}
+
+		[MonoTODO]
+		public SqlDataAdapter DataAdapter {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set{
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuotePrefix {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public string QuoteSuffix {
+			get {
+				throw new NotImplementedException ();
+			}
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		public static void DeriveParameters(SqlCommand command) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetDeleteCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetInsertCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public SqlCommand GetUpdateCommand() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public void RefreshSchema() {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		protected override void Dispose(bool disposing) {
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		~SqlCommandBuilder() {
+			// FIXME: create destructor - release resources
+		}
+	}
+}
+

+ 59 - 46
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -8,9 +8,8 @@
 // (C) Ximian, Inc 2002
 //
 
-// FIXME: what is the proper way to debug messages?
-// use #define DEBUG_SqlConnection if you want to spew debug messages for 
-#define DEBUG_SqlConnection
+// use #define DEBUG_SqlConnection if you want to spew debug messages
+// #define DEBUG_SqlConnection
 
 using System;
 using System.ComponentModel;
@@ -34,6 +33,9 @@ namespace System.Data.SqlClient
 	//	ICloneable
 	public sealed class SqlConnection : IDbConnection
 	{
+		// FIXME: Need to implement class Component, 
+		// and interfaces: ICloneable and IDisposable	
+
 		#region Fields
 
 		private PGconn pgConn = IntPtr.Zero;    
@@ -106,24 +108,31 @@ namespace System.Data.SqlClient
 		public SqlConnection (String connectionString)
 		{
 			SetConnectionString (connectionString);
-			OpenDataSource ();
 		}
 
-		#endregion
+		#endregion // Constructors
 
-		#region Deconstructors
+		#region Destructors
 
+		[MonoTODO]
+		public void Dispose () {	
+			// FIXME: release resources properly
+			Close ();
+			// Dispose (true);
+		}
+	
 		// aka Finalize
-
-
-		/*
-		[ClassInterface(ClassInterfaceType.AutoDual)]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		[MonoTODO]
 		~SqlConnection()
 		{
-
+			// FIXME: this class need 
+			//        a destructor to release resources
+			//        Also, take a look at Dispose
+			// Dispose (false);
 		}
-		*/
-		#endregion // Deconstructors
+		
+		#endregion // Destructors
 
 		#region Public Methods
 
@@ -148,6 +157,19 @@ namespace System.Data.SqlClient
 			return TransactionBegin (il); // call private method
 		}
 
+		// PostgreSQL does not support named transactions/savepoint
+		//            nor nested transactions
+		[Obsolete]
+		public SqlTransaction BeginTransaction(	string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
+		[Obsolete]
+		public SqlTransaction BeginTransaction(IsolationLevel iso,
+						string transactionName) {
+			return TransactionBegin (); // call private method
+		}
+
 		[MonoTODO]
 		public void ChangeDatabase (string databaseName)
 		{
@@ -178,15 +200,7 @@ namespace System.Data.SqlClient
 			OpenDataSource ();
 		}
 
-		[MonoTODO]
-		public void Dispose ()
-		{	
-			// FIXME: quick hack
-			Close ();
-			// Dispose (true);
-		}
-	
-		#endregion
+		#endregion // Public Methods
 
 		#region Internal Methods
 
@@ -218,6 +232,11 @@ namespace System.Data.SqlClient
 
 		private void OpenDataSource ()
 		{
+			if(dbname.Equals(""))
+				throw new InvalidOperationException("dbname missing");
+			else if(conState == ConnectionState.Open)
+				throw new InvalidOperationException("ConnnectionState is already Open");
+
 			ConnStatusType connStatus;
 
 			// FIXME: check to make sure we have 
@@ -242,24 +261,12 @@ namespace System.Data.SqlClient
 			{
 				String errorMessage = PostgresLibrary.
 					PQerrorMessage (pgConn);
-				// FIXME: use thie WriteLine's until
-				// exceptions have been implemented
-				Console.WriteLine("*** Error: " + 
-					"could not connect to database.");			
-				Console.WriteLine ("Error Message: " + 
-					errorMessage);
-
-				// FIXME: do error checking, 
-				// if could not connect, 
-				// throw an exception:
-				//  InvalidOperationException - attempt 
-				//    to connect to without specifying 
-				//    database or server
-				//  SqlException - error while 
-				//    connecting to database
-				
+				errorMessage += ": Could not connect to database.";
+
+				throw new SqlException(0, 0,
+					errorMessage, 0, "",
+					host, "SqlConnection", 0);
 			}
-			
 		}
 
 		private void CloseDataSource ()
@@ -297,12 +304,12 @@ namespace System.Data.SqlClient
 				connectionString);
 
 #if DEBUG_SqlConnection
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.pgConnectionString: " +
+			Console.WriteLine(
+				"OLE-DB Connection String    [in]: " +
+				this.ConnectionString);
+			Console.WriteLine(
+				"Postgres Connection String [out]: " +
 				pgConnectionString);
-			Console.WriteLine("DEBUG_SqlConnection: " +
-				"SqlConnection.connectionString: " +
-				this.connectionString);
 #endif // DEBUG_SqlConnection
 		}
 
@@ -381,7 +388,7 @@ namespace System.Data.SqlClient
 
 				case "password":
 					password = parmValue;
-					addParm = false;
+				//	addParm = false;
 					break;
 
 				case "options":
@@ -429,7 +436,7 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public ConnectionState State 		{
 			get { 
-				throw new NotImplementedException (); 
+				return conState;
 			}
 		}
 
@@ -481,6 +488,12 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal SqlTransaction Transaction {
+			get {
+				return trans;
+			}
+		}
+
 		#endregion
 
 		#region Events and Delegates

+ 1 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlDataAdapter.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 

+ 1 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Collections;
+using System.ComponentModel;
 using System.Data;
 
 namespace System.Data.SqlClient

+ 68 - 19
mcs/class/System.Data/System.Data.SqlClient/SqlError.cs

@@ -19,86 +19,135 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlError
 	{
+		byte theClass = 0;
+		int lineNumber = 0;
+		string message = "";
+		int number = 0;
+		string procedure = "";
+		string server = "";
+		string source = "";
+		byte state = 0;
+
+		internal SqlError(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			this.theClass = theClass;
+			this.lineNumber = lineNumber;
+			this.message = message;
+			this.number = number;
+			this.procedure = procedure;
+			this.server = server;
+			this.source = source;
+			this.state = state;
+		}
+		
 		#region Properties
 
 		[MonoTODO]
+		/// <summary>
+		/// severity level of the error
+		/// </summary>
 		public byte Class {
 			get { 
-				throw new NotImplementedException ();
+				return theClass;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-			   throw new NotImplementedException ();
+			   return lineNumber;
 		   }
 		}
 
 		[MonoTODO]
 		public string Message {
 			get { 
-				throw new NotImplementedException ();
+				return message;
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException ();
+				return number;
 			}
 		}
 
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException ();
+				return procedure;
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException ();
+				return server;
 			}
 		}
 
 		[MonoTODO]
 		public string Source {
 			get { 
-				throw new NotImplementedException ();
+				return source;
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException ();
+				return state;
 			}
 		}
 
 		#endregion
 
 		#region Methods
-		
+
 		[MonoTODO]
 		public override string ToString ()
 		{
-			throw new NotImplementedException ();
+			String toStr;
+			String stackTrace = 
+			stackTrace = " <Stack Trace>";
+			// FIXME: generate the correct SQL error string
+			toStr = "SqlError:" + message + stackTrace;
+			return toStr;
 		}
-		#endregion
 
-		#region Destructors
+		internal void SetClass(byte theClass) {
+			this.theClass = theClass;
+		}
 
-		// FIXME: do the destructor
-/*
-		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
-		{
+		internal void SetLineNumber(int lineNumber) {
+			this.lineNumber = lineNumber;
+		}
+
+		internal void SetMessage(string message) {
+			this.message = message;
+		}
+
+		internal void SetNumber(int number) {
+			this.number = number;
+		}
+
+		internal void SetProcedure(string procedure) {
+			this.procedure = procedure;
+		}
+
+		internal void SetServer(string server) {
+			this.server = server;
+		}
+
+		internal void SetSource(string source) {
+			this.source = source;
+		}
 
+		internal void SetState(byte state) {
+			this.state = state;
 		}
-*/
 
 		#endregion
 		

+ 39 - 62
mcs/class/System.Data/System.Data.SqlClient/SqlErrorCollection.cs

@@ -20,68 +20,27 @@ namespace System.Data.SqlClient
 	[MonoTODO]
 	public sealed class SqlErrorCollection : ICollection, IEnumerable
 	{
-		#region Properties
+		private int count = 0;
+		ArrayList errorList = new ArrayList();
 
-		[MonoTODO]
-		public byte Class {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection() {
 		}
 
-		[MonoTODO]
-		public int LineNumber {
-			get { 
-			   throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Message {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-		
-		[MonoTODO]
-		public int Number {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Procedure {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Server {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public string Source {
-			get { 
-				throw new NotImplementedException ();
-			}
-		}
-
-		[MonoTODO]
-		public byte State {
-			get { 
-				throw new NotImplementedException ();
-			}
+		internal SqlErrorCollection(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
 		}
 
+		#region Properties
+                
 		[MonoTODO]
 		public int Count {
 			get {	
-				throw new NotImplementedException ();
+				return errorList.Count;
 			}			  
 		}
 
@@ -109,6 +68,14 @@ namespace System.Data.SqlClient
 			throw new NotImplementedException ();
 		}
 
+		[MonoTODO]
+		// Index property (indexer)
+		public SqlError this[int index] {
+			get {
+				return (SqlError) errorList[index];
+			}
+		}
+
 		#endregion
 
 		#region Methods
@@ -120,19 +87,29 @@ namespace System.Data.SqlClient
 		}
 		#endregion
 
+		internal void Add(SqlError error) {
+			errorList.Add(error);
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			SqlError error = new SqlError(theClass,
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+			Add(error);
+		}
+
 		#region Destructors
 
-		// FIXME: do the destructor
-/*
 		[MonoTODO]
-		[ClassInterface(ClassInterfaceType.AutoDual)]
-		~SqlError()
+		~SqlErrorCollection()
 		{
-
+			// FIXME: do the destructor - release resources
 		}
-*/
 
-		#endregion
-		
+		#endregion		
 	}
 }

+ 103 - 18
mcs/class/System.Data/System.Data.SqlClient/SqlException.cs

@@ -9,6 +9,7 @@
 //
 using System;
 using System.Data;
+using System.Runtime.Serialization;
 
 namespace System.Data.SqlClient
 {
@@ -17,101 +18,185 @@ namespace System.Data.SqlClient
 	/// </summary>
 	public sealed class SqlException : SystemException
 	{
+		private SqlErrorCollection errors = new SqlErrorCollection();
+
+		internal SqlException() {
+			
+		}
+
+		internal SqlException(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+						
+			errors = new SqlErrorCollection (theClass, 
+				lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
 		#region Properties
-		
+
 		[MonoTODO]
 		public byte Class {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				else
+					return errors[0].Class;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetClass(value);
 			}
 		}
 
 		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
-				throw new NotImplementedException (); 
+				return errors;
 			}
+
 			set { 
-				throw new NotImplementedException (); 
+				errors = value;
 			}
 		}
 
 		[MonoTODO]
 		public int LineNumber {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception here?
+				return errors[0].LineNumber;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetLineNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Message 	{
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else {
+					String msg = "";
+					int i = 0;
+					
+					for(i = 0; i < errors.Count - 1; i++) {
+						msg = msg + errors[i].Message + "\n";
+                                        }
+					msg = msg + errors[i];
+
+					return msg;
+				}
 			}
 		}
 		
 		[MonoTODO]
 		public int Number {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].Number;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetNumber(value);
 			}
 		}
 		
 		[MonoTODO]
 		public string Procedure {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Procedure;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetProcedure(value);
 			}
 		}
 
 		[MonoTODO]
 		public string Server {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Server;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetServer(value);
 			}
 		}
 		
 		[MonoTODO]
 		public override string Source {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return ""; // FIXME: throw exception?
+				else
+					return errors[0].Source;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetSource(value);
 			}
 		}
 
 		[MonoTODO]
 		public byte State {
 			get { 
-				throw new NotImplementedException (); 
+				if(errors.Count == 0)
+					return 0; // FIXME: throw exception?
+				else
+					return errors[0].State;
 			}
 
 			set { 
-				throw new NotImplementedException (); 
+				errors[0].SetState(value);
 			}
 		}
 
 		#endregion // Properties
+
+		#region Methods
+
+		[MonoTODO]
+		public override void GetObjectData(SerializationInfo si,
+			StreamingContext context) {
+			// FIXME: to do
+		}
+
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		public override string ToString() {
+			String toStr = "";
+			for (int i = 0; i < errors.Count; i++) {
+				toStr = toStr + errors[i].ToString() + "\n";
+			}
+			return toStr;
+		}
+
+		internal void Add(byte theClass, int lineNumber,
+			string message,	int number, string procedure,
+			string server, string source, byte state) {
+			
+			errors.Add (theClass, lineNumber, message,
+				number, procedure,
+				server, source, state);
+		}
+
+		[MonoTODO]
+		~SqlException() {
+			// FIXME: destructor to release resources
+		}
+
+		#endregion // Methods
 	}
 }

+ 9 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlInfoMessageEventArgs.cs

@@ -15,12 +15,14 @@ namespace System.Data.SqlClient
 {
 	public sealed class SqlInfoMessageEventArgs : EventArgs
 	{
+		[MonoTODO]
 		public SqlErrorCollection Errors {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}	
 
+		[MonoTODO]
 		public string Message 
 		{
 			get { 
@@ -28,14 +30,21 @@ namespace System.Data.SqlClient
 			}
 		}	
 
+		[MonoTODO]
 		public string Source {
 			get { 
 				throw new NotImplementedException (); 
 			}
 		}
 
+		[MonoTODO]
 		public override string ToString() {
 			// representation of InfoMessage event
 		}
+
+		[MonoTODO]
+		~SqlInfoMessageEventArgs() {
+			// FIXME: destructor needs to release resources
+		}
 	}
 }

+ 19 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlInfoMessageEventHandler.cs

@@ -0,0 +1,19 @@
+//
+// System.Data.SqlClient.SqlInfoMessageEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void 
+	SqlInfoMessageEventHandler (object sender,
+				SqlInfoMessageEventArgs e);
+}

+ 64 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlParameter.cs

@@ -8,6 +8,7 @@
 // (C) Ximian, Inc. 2002
 //
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
 using System.Runtime.InteropServices;
@@ -23,6 +24,43 @@ namespace System.Data.SqlClient
 	//	IDbDataParameter, IDataParameter, ICloneable
 	public sealed class SqlParameter : IDbDataParameter, IDataParameter
 	{
+		[MonoTODO]
+		public SqlParameter () {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter (string parameterName, object value) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType) {
+			// FIXME: do this
+		}
+
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size) {
+			// FIXME: do this
+		}
+		
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, string sourceColumn) {
+			// FIXME: do this
+		}
+			 
+		[MonoTODO]
+		public SqlParameter(string parameterName, SqlDbType dbType,
+			int size, ParameterDirection direction, 
+			bool isNullable, byte precision,
+			byte scale, string sourceColumn,
+			DataRowVersion sourceVersion, object value) {
+			// FIXME: do this
+		}
+
+
 		[MonoTODO]
 		public DbType DbType {
 			get { 
@@ -50,6 +88,17 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public int Offset {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
+
 		[MonoTODO]
 		public string ParameterName {
 			get { 
@@ -82,6 +131,17 @@ namespace System.Data.SqlClient
 				throw new NotImplementedException (); 
 			}
 		}
+		
+		[MonoTODO]
+		public SqlDbType SqlDbType {
+			get {
+				throw new NotImplementedException (); 
+			}
+			
+			set {
+				throw new NotImplementedException (); 
+			}
+		}
 
 		[MonoTODO]
 		public object Value {
@@ -128,5 +188,9 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		[MonoTODO]
+		public override string ToString() {
+			throw new NotImplementedException (); 
+		}
 	}
 }

+ 1 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs

@@ -9,6 +9,7 @@
 //
 
 using System;
+using System.ComponentModel;
 using System.Data;
 using System.Collections;
 

+ 38 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatedEventArgs.cs

@@ -0,0 +1,38 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient {
+	public sealed class SqlRowUpdatedEventArgs : RowUpdatedEventArgs {	
+		
+		[MonoTODO]
+		public SqlRowUpdatedEventArgs (DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+		
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatedEventArgs () {
+			// FIXME: need destructor to release resources
+		}
+
+	}
+}

+ 18 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatedEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatedEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatedEventHandler(object sender,
+					SqlRowUpdatedEventArgs e);
+}

+ 42 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatingEventArgs.cs

@@ -0,0 +1,42 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventArgs.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+namespace System.Data.SqlClient
+{
+	public sealed class SqlRowUpdatingEventArgs : RowUpdatingEventArgs
+	{
+		[MonoTODO]
+		public SqlRowUpdatingEventArgs(	DataRow row,
+			IDbCommand command, StatementType statementType,
+			DataTableMapping tableMapping) {
+			// FIXME: do the constructor
+		}
+
+		[MonoTODO]
+		public new SqlCommand Command {
+			get {
+				throw new NotImplementedException ();
+			} 
+			
+			set {
+				throw new NotImplementedException ();
+			}
+		}
+
+		[MonoTODO]
+		~SqlRowUpdatingEventArgs() {
+			// FIXME: create destructor to release resources
+		}
+	}
+}

+ 18 - 0
mcs/class/System.Data/System.Data.SqlClient/SqlRowUpdatingEventHandler.cs

@@ -0,0 +1,18 @@
+//
+// System.Data.SqlClient.SqlRowUpdatingEventHandler.cs
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+
+namespace System.Data.SqlClient
+{
+	public delegate void SqlRowUpdatingEventHandler(object sender,
+			SqlRowUpdatingEventArgs e);
+}

+ 99 - 65
mcs/class/System.Data/System.Data.SqlClient/SqlTransaction.cs

@@ -3,9 +3,15 @@
 //
 // Author:
 //   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
 //
 // (C) Ximian, Inc. 2002
 //
+
+// use #define DEBUG_SqlTransaction if you want to spew debug messages
+// #define DEBUG_SqlTransaction
+
+
 using System;
 using System.Data;
 using System.Data.Common;
@@ -21,12 +27,11 @@ namespace System.Data.SqlClient
 	{
 		#region Fields
 
+		private bool doingTransaction = false;
 		private SqlConnection conn = null;
-		//        How do you get/set the 
-		//        IsolationLevel in PostgreSQL?
 		private IsolationLevel isolationLevel =	
 			IsolationLevel.ReadCommitted;
-		// There are two IsolationLevel's for PostgreSQL:
+		// There are only two IsolationLevel's for PostgreSQL:
 		//    ReadCommitted and Serializable, 
 		// but ReadCommitted is the default 
 		
@@ -37,51 +42,48 @@ namespace System.Data.SqlClient
 		[MonoTODO]
 		public void Commit ()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"COMMIT");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Commit transaction.");
+			
+			SqlCommand cmd = new SqlCommand("COMMIT", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
 		}		
 
 		[MonoTODO]
 		public void Rollback()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"ROLLBACK");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == false)
+				throw new InvalidOperationException(
+					"Begin transaction was not " +
+					"done earlier " +
+					"thus PostgreSQL can not " +
+					"Rollback transaction.");
+			
+			SqlCommand cmd = new SqlCommand("ROLLBACK", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = false;
+		}
+
+		// For PostgreSQL, Rollback(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Rollback(string transactionName) {
+			// throw new NotImplementedException ();
+			Rollback();
+		}
+
+		// For PostgreSQL, Save(string) will not be implemented
+		// because PostgreSQL does not support Savepoints
+		[Obsolete]
+		public void Save (string savePointName) {
+			// throw new NotImplementedException ();
 		}
 
 		#endregion // Public Methods
@@ -90,30 +92,40 @@ namespace System.Data.SqlClient
 
 		internal void Begin()
 		{
-			IntPtr pgResult;
-			ExecStatusType execStatus;
-
-			pgResult = PostgresLibrary.
-				PQexec (conn.PostgresConnection, 
-					"BEGIN");
-			/* FIXME: check result and emit 
-			 * exceptions on errors 
-			 */
-			execStatus = PostgresLibrary.
-				PQresultStatus (pgResult);
-
-			String cmdStatus;
-			cmdStatus = PostgresLibrary.
-				PQcmdStatus(pgResult);
-
-			Console.WriteLine("*** Command Status: " +
-				cmdStatus);
-
-			PostgresLibrary.PQclear (pgResult);
+			if(doingTransaction == true)
+				throw new InvalidOperationException(
+					"Transaction has begun " +
+					"and PostgreSQL does not " +
+					"support nested transactions.");
+			
+			SqlCommand cmd = new SqlCommand("BEGIN", conn);
+			cmd.ExecuteNonQuery();
+						
+			doingTransaction = true;
 		}
 
 		internal void SetIsolationLevel(IsolationLevel isoLevel)
 		{
+			String sSql = "SET TRANSACTION ISOLATION LEVEL ";
+ 
+			switch (isoLevel) 
+			{
+				case IsolationLevel.ReadCommitted:
+					sSql += "READ COMMITTED";
+					break;
+
+				case IsolationLevel.Serializable:
+					sSql += "SERIALIZABLE";
+					break;
+				default:
+					// FIXME: generate exception here
+					// PostgreSQL only supports:
+					//   ReadCommitted or Serializable
+					break;
+			}
+			SqlCommand cmd = new SqlCommand(sSql, conn);
+			cmd.ExecuteNonQuery();
+
 			this.isolationLevel = isoLevel;
 		}
 
@@ -144,13 +156,35 @@ namespace System.Data.SqlClient
 			}
 		}
 
+		internal bool DoingTransaction {
+			get {
+				return doingTransaction;
+			}
+		}
+
+		#endregion Properties
+
+		#region Destructors
+
+		// Destructors aka Finalize and Dispose
+
 		[MonoTODO]
 		public void Dispose()
 		{
 			// FIXME: need to properly release resources
+			// Dispose(true);
 		}
-	
-		#endregion // Properties
+
+		// Destructor 
+		[MonoTODO]
+		// [Serializable]
+		// [ClassInterface(ClassInterfaceType.AutoDual)]
+		~SqlTransaction() {
+			// FIXME: need to properly release resources
+			// Dispose(false);
+		}
+
+		#endregion // Destructors
 
 	}
 }

+ 8 - 0
mcs/class/System.Data/System.Data.build

@@ -22,6 +22,14 @@
 				<excludes name="System.Data.SqlClient/SqlDataAdapter.cs"/>
 				<excludes name="System.Data.SqlClient/SqlDataReader.cs"/>
 				<excludes name="System.Data.SqlClient/SqlInfoMessageEventArgs.cs"/>
+				<excludes name="System.Data.SqlClient/SqlRowUpdatingEventArgs.cs"/>
+				<excludes name="System.Data.SqlClient/SqlRowUpdatedEventArgs.cs"/>
+				<excludes name="System.Data.SqlClient/SqlInfoMessageEventHandler.cs"/>
+				<excludes name="System.Data.SqlClient/SqlRowUpdatingEventHandler.cs"/>
+				<excludes name="System.Data.SqlClient/SqlRowUpdatedEventHandler.cs"/>
+				<excludes name="System.Data.SqlClient/SqlClientPermission.cs"/>
+				<excludes name="System.Data.SqlClient/SqlClientPermissionAttribute.cs"/>
+				<excludes name="System.Data.SqlClient/SqlCommandBuilder.cs"/>
 				<excludes name="System.Data.SqlTypes/*"/>
 			</sources>
 			<references>

+ 117 - 0
mcs/class/System.Data/Test/TestSqlException.cs

@@ -0,0 +1,117 @@
+//
+// TestSqlInsert.cs
+//
+// To Test SqlConnection and SqlCommand by connecting
+// to a PostgreSQL database 
+// and then executing an INSERT SQL statement
+//
+// To use:
+//   change strings to your database, userid, tables, etc...:
+//        connectionString
+//        insertStatement
+//
+// To test:
+//   mcs TestSqlInsert.cs -r System.Data
+//   mint TestSqlInsert.exe
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.SqlClient;
+
+namespace TestSystemDataSqlClient
+{
+	class TestSqlInsert
+	{
+		[STAThread]
+		static void Main(string[] args) {
+			SqlConnection conn;
+			SqlCommand cmd;
+			SqlTransaction trans;
+
+			int rowsAffected;
+
+			String connectionString;
+			String insertStatement;
+			String deleteStatement;
+	
+			connectionString = 
+				"host=localhost;" +
+				"dbname=test;" +
+				"user=danmorg;" +
+				"password=viewsonic";
+
+			insertStatement = 
+				"insert into sometable " +
+				"(tid, tdesc) " +
+				"values ('beer', 'Beer for All!') ";
+
+			deleteStatement = 
+				"delete from NoSuchTable " +
+				"where tid = 'beer' ";
+
+			try {
+				// Connect to a PostgreSQL database
+				Console.WriteLine ("Connect to database...");
+				conn = new SqlConnection(connectionString);
+				conn.Open();
+			
+				// begin transaction
+				Console.WriteLine ("Begin Transaction...");
+				trans = conn.BeginTransaction();
+
+				// create SQL DELETE command
+				Console.WriteLine ("Create Command initializing " +
+					"with an DELETE statement...");
+				cmd = new SqlCommand (deleteStatement, conn);
+
+				// execute the DELETE SQL command
+				Console.WriteLine ("Execute DELETE SQL Command...");
+				cmd.ExecuteNonQuery();
+				rowsAffected = cmd.ExecuteNonQuery();
+				Console.WriteLine ("Rows Affected: " + rowsAffected);
+
+				// change the SQL command to an SQL INSERT Command
+				Console.WriteLine ("Now use INSERT SQL Command...");
+				cmd.CommandText = insertStatement;
+
+				// execute the INSERT SQL command
+				Console.WriteLine ("Execute INSERT SQL Command...");
+				rowsAffected = cmd.ExecuteNonQuery();
+				Console.WriteLine ("Rows Affected: " + rowsAffected);
+
+				// if successfull at INSERT, commit the transaction,
+				// otherwise, do a rollback the transaction using
+				// trans.Rollback();
+				Console.WriteLine ("Commit transaction...");
+				trans.Commit();
+
+				// Close connection to database
+				Console.WriteLine ("Close database connection...");
+				conn.Close();
+
+				Console.WriteLine ("Assuming everything " +
+					"was successful.");
+				Console.WriteLine ("Verify data in database to " +
+					"see if row is there.");
+			}
+			catch(SqlException e) {
+				// Display the SQL Errors and Rollback the database
+				Console.WriteLine("SqlException caught: " +
+					e.ToString());
+				trans.Rollback();
+				Console.WriteLine("Database has been Rolled back!");
+			}
+			finally {
+				if(conn.State == ConnectionState.Open)
+					conn.Close();
+			}
+		}
+	}
+}

+ 12 - 1
mcs/class/System.Data/Test/TestSqlInsert.cs

@@ -1,5 +1,5 @@
 //
-// System.Data.SqlClient.SqlError.cs
+// TestSqlInsert.cs
 //
 // To Test SqlConnection and SqlCommand by connecting
 // to a PostgreSQL database 
@@ -10,6 +10,10 @@
 //        connectionString
 //        insertStatement
 //
+// To test:
+//   mcs TestSqlInsert.cs -r System.Data
+//   mint TestSqlInsert.exe
+//
 // Author:
 //   Rodrigo Moya ([email protected])
 //   Daniel Morgan ([email protected])
@@ -32,6 +36,8 @@ namespace TestSystemDataSqlClient
 			SqlCommand cmd;
 			SqlTransaction trans;
 
+			int rowsAffected;
+
 			String connectionString;
 			String insertStatement;
 			String deleteStatement;
@@ -54,6 +60,7 @@ namespace TestSystemDataSqlClient
 			// Connect to a PostgreSQL database
 			Console.WriteLine ("Connect to database...");
 			conn = new SqlConnection(connectionString);
+			conn.Open();
 
 			// begin transaction
 			Console.WriteLine ("Begin Transaction...");
@@ -67,6 +74,8 @@ namespace TestSystemDataSqlClient
 			// execute the DELETE SQL command
 			Console.WriteLine ("Execute DELETE SQL Command...");
 			cmd.ExecuteNonQuery();
+			rowsAffected = cmd.ExecuteNonQuery();
+			Console.WriteLine ("Rows Affected: " + rowsAffected);
 
 			// change the SQL command to an SQL INSERT Command
 			Console.WriteLine ("Now use INSERT SQL Command...");
@@ -75,6 +84,8 @@ namespace TestSystemDataSqlClient
 			// execute the INSERT SQL command
 			Console.WriteLine ("Execute INSERT SQL Command...");
 			cmd.ExecuteNonQuery();
+			rowsAffected = cmd.ExecuteNonQuery();
+			Console.WriteLine ("Rows Affected: " + rowsAffected);
 
 			// if successfull at INSERT, commit the transaction,
 			// otherwise, do a rollback the transaction using

+ 104 - 0
mcs/class/System.Data/Test/TestSqlIsolationLevel.cs

@@ -0,0 +1,104 @@
+//
+// TestSqlIsolationLevel.
+//
+// To Test Setting Isolation Level of SqlTransaction
+// to a PostgreSQL database 
+//
+// To use:
+//   change strings to your database, userid, tables, etc...:
+//        connectionString
+//        insertStatement
+// 
+// To test:
+//   mcs TestSqlIsolationLevel.cs -r System.Data
+//   mint TestSqlIsolationLevel.exe
+//
+// Author:
+//   Rodrigo Moya ([email protected])
+//   Daniel Morgan ([email protected])
+//
+// (C) Ximian, Inc 2002
+//
+
+using System;
+using System.Data;
+using System.Data.SqlClient;
+
+namespace TestSystemDataSqlClient
+{
+	class TestSqlInsert
+	{
+		[STAThread]
+		static void Main(string[] args)
+		{
+			SqlConnection conn;
+			SqlCommand cmd;
+			SqlTransaction trans;
+			
+			int rowsAffected;
+
+			String connectionString;
+			String insertStatement;
+			String deleteStatement;
+	
+			connectionString = 
+				"host=localhost;" +
+				"dbname=test;" +
+				"user=danmorg;" +
+				"password=viewsonic";
+
+			insertStatement = 
+				"insert into sometable " +
+				"(tid, tdesc) " +
+				"values ('beer', 'Beer for All!') ";
+
+			deleteStatement = 
+				"delete from sometable " +
+				"where tid = 'beer' ";
+
+			// Connect to a PostgreSQL database
+			Console.WriteLine ("Connect to database...");
+			conn = new SqlConnection(connectionString);
+			conn.Open();
+
+			// begin transaction
+			Console.WriteLine ("Begin Transaction...");
+			trans = conn.BeginTransaction(IsolationLevel.Serializable);
+
+			// create SQL DELETE command
+			Console.WriteLine ("Create Command initializing " +
+				"with an DELETE statement...");
+			cmd = new SqlCommand (deleteStatement, conn);
+
+			// execute the DELETE SQL command
+			Console.WriteLine ("Execute DELETE SQL Command...");
+			cmd.ExecuteNonQuery();
+
+			// change the SQL command to an SQL INSERT Command
+			Console.WriteLine ("Now use INSERT SQL Command...");
+			cmd.CommandText = insertStatement;
+
+			// execute the INSERT SQL command
+			Console.WriteLine ("Execute INSERT SQL Command...");
+			rowsAffected = cmd.ExecuteNonQuery();
+			Console.WriteLine ("Rows Affected: " + rowsAffected);
+
+			// if successfull at INSERT, commit the transaction,
+			// otherwise, do a rollback the transaction using
+			// trans.Rollback();
+			// FIXME: need to have exceptions working in
+			//        SqlClient classes before you can do rollback
+			Console.WriteLine ("Commit transaction...");
+			trans.Commit();
+
+			// Close connection to database
+			Console.WriteLine ("Close database connection...");
+			conn.Close();
+
+			Console.WriteLine ("Assuming everything " +
+				"was successful.");
+			Console.WriteLine ("Verify data in database to " +
+				"see if row is there.");
+		}
+	}
+}