[MonoDevelop] [PATCH] Mono.Data.Sql - remove refereces to data providers and use Mono.Data.ProviderFactory

Daniel Morgan danielmorgan at verizon.net
Thu Feb 23 00:36:38 EST 2006


The patch is just for research purposes to move Mono.Data.Sql forward.

The filename is diff.txt

I've only tested it with Oracle though.  Can you test the Npsql provider 
please?

Your thoughts on this?

Right now, I'm using the Mono.Data.ProviderFactory within 
Mono.Data.Sql.  Maybe, I should just merge the Mono.Data.ProviderFactory 
stuff into Mono.Data.Sql?

-------------- next part --------------
Index: tests/test-oracle-1.cs
===================================================================
--- tests/test-oracle-1.cs	(revision 57083)
+++ tests/test-oracle-1.cs	(working copy)
@@ -1,38 +1,74 @@
 // test-oracle-1.cs
 //
-// $ mcs test-oracle-1.cs /r:System.Data /r:System.Data.OracleClient /r:Mono.Data.Sql
+// $ mcs test-oracle-1.cs /r:System.Data /r:Mono.Data.Sql /r:Mono.Data
 //
 
 using System;
+using System.Collections;
 using System.Data;
-using System.Data.OracleClient;
+using System.Data.Common;
+using System.Data.SqlTypes;
 using System.Text;
 using Mono.Data.Sql;
+using Mono.Data;
 
 namespace Mono.Data.Sql.Tests
 {
 	public class CreateProviderTest
 	{
-		static OracleDbProvider provider = null;
+		static DbProviderBase provider = null;
 
 		static TableSchema[] tables = null;
 		static ViewSchema[] views = null;
+
+		public static void Main(string[] args) 
+		{
+			Test2();
+			Test1();
+		}
+
+		public static void Test2() 
+		{
+			Console.WriteLine("Test2 Oracle Meta Data Provider using MetaDataProviderFactory...");
+
+			string setting = "OraConnStr";
+			provider = MetaDataProviderFactory.GetDbProviderBaseFromSetting(setting);
+			Console.Error.WriteLine("+++ provider.ConnectionString: " + provider.ConnectionString);
+			Console.Error.WriteLine("+++ provider.Provider.Name: " + provider.Provider.Name);
+			Console.Error.WriteLine("+++ provider.ProviderName: " + provider.ProviderName);
+			Console.Error.WriteLine("+++ Open()...");
+			provider.Open();
+			
+			ListTables ();
+
+			tables = null;
+
+			provider.Close();
+			provider = null;
+
+			Console.WriteLine("Test Done.");
+		}
 		
-		public static void Main(string[] args) 
+		public static void Test1() 
 		{	
-			Console.WriteLine("Test Oracle Meta Data Provider...");
+			Console.WriteLine("Test1 Oracle Meta Data Provider...");
 
-			provider = new OracleDbProvider ();
+			provider = (DbProviderBase) new OracleDbProvider ();
 			provider.ConnectionString = "Data Source=palis;user id=scott;password=tiger";
+			Console.Error.WriteLine("+++ provider.ConnectionString: " + provider.ConnectionString);
+			Console.Error.WriteLine("+++ provider.Provider.Name: " + provider.Provider.Name);
+			Console.Error.WriteLine("+++ provider.ProviderName: " + provider.ProviderName);
+			Console.Error.WriteLine("+++ Open()...");
 			provider.Open ();
 			
 			ListTables ();
-			ListViews ();
+			//ListViews ();
 
 			tables = null;
 			views = null;
 
 			provider.Close();
+			provider = null;
 
 			Console.WriteLine("Test Done.");
 		}
Index: tests/test-oracle-1.exe.config
===================================================================
--- tests/test-oracle-1.exe.config	(revision 0)
+++ tests/test-oracle-1.exe.config	(revision 0)
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+	<configSections>
+		<sectionGroup name="mono.data">
+			<section name="providers" type="Mono.Data.ProviderSectionHandler,Mono.Data" />
+		</sectionGroup>
+		<sectionGroup name="mono.data.sql">
+			<section name="metadataproviders" type="Mono.Data.Sql.MetaDataProviderSectionHandler,Mono.Data.Sql" />
+		</sectionGroup>
+	</configSections>
+	<appSettings>
+		<add key="PubsConnStr" value="factory=System.Data.SqlClient;server=localhost;database=testdb;uid=sa;pwd=mypassword" />
+		<add key="OraConnStr" value="factory=System.Data.OracleClient;data source=palis;user id=scott;password=tiger" />
+		<add key="PgConnStr" value="factory=Npgsql;Server=localhost;Database=monotest;User ID=monotest;Password=monotest" />
+		<!--<add key="MySqlByteFXConnStr" value="factory=ByteFX.Data.MySqlClient;Database=test" />-->
+		<!--<add key="FireConnStr" value="factory=FirebirdSql.Data.Firebird;Database=E:\FIREBIRD\EXAMPLES\EMPLOYEE.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=localhost" />-->
+		<add key="Sqlite2ConnStr" value="factory=Mono.Data.SqliteClient;URI=file:sqlitetest2.db" />
+		<add key="Sqlite3ConnStr" value="factory=Mono.Data.SqliteClient;URI=file:sqlitetest3.db,Version=3" />
+		<add key="SybaseConnStr" value="factory=Mono.Data.SybaseClient;Server=MYSERVER,5000;Database=testdb;User ID=sa;Password=;" />
+		<!--<add key="MySqlConnStr" value="factory=MySql.Data;server=localhost;user id=userl;password=pass;database=mysql;pooling=false" />-->
+	</appSettings>
+	<mono.data>
+		<providers>
+			<provider 
+				name="System.Data.SqlClient" 
+				connection="System.Data.SqlClient.SqlConnection" 
+				adapter="System.Data.SqlClient.SqlDataAdapter" 
+				command="System.Data.SqlClient.SqlCommand" 
+				assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+				description="Microsoft SQL Server 7.0/2000/2005"
+				parameterprefix="at"
+				commandbuilder="System.Data.SqlClient.SqlCommandBuilder"  />
+			<provider 
+				name="System.Data.OleDb" 
+				connection="System.Data.OleDb.OleDbConnection" 
+				adapter="System.Data.OleDb.OleDbDataAdapter" 
+				command="System.Data.OleDb.OleDbCommand" 
+				assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+				description="OLE DB" />
+			<provider 
+				name="System.Data.Odbc" 
+				connection="System.Data.Odbc.OdbcConnection" 
+				adapter="System.Data.Odbc.OdbcDataAdapter" 
+				command="System.Data.Odbc.OdbcCommand" 
+				assembly="System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+				description="ODBC"
+				parameterprefix="questionmark"
+				commandbuilder="System.Data.Odbc.OdbcCommandBuilder" />
+			<provider 
+				name="System.Data.OracleClient" 
+				connection="System.Data.OracleClient.OracleConnection" 
+				adapter="System.Data.OracleClient.OracleDataAdapter" 
+				command="System.Data.OracleClient.OracleCommand" 
+				assembly="System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
+				description="Oracle"
+				parameterprefix="colon"
+				commandbuilder="System.Data.OracleClient.OracleCommandBuilder" />
+			<!--<provider 
+				name="ByteFX.Data.MySqlClient" 
+				connection="ByteFX.Data.MySqlClient.MySqlConnection" 
+				adapter="ByteFX.Data.MySqlClient.MySqlDataAdapter" 
+				command="ByteFX.Data.MySqlClient.MySqlCommand"
+				assembly="ByteFX.Data, Version=0.7.6.1, Culture=neutral, PublicKeyToken=0738eb9f132ed756"
+				description="MySQL (ByteFX)" />-->
+			<provider 
+				name="Npgsql" 
+				connection="Npgsql.NpgsqlConnection" 
+				adapter="Npgsql.NpgsqlDataAdapter" 
+				command="Npgsql.NpgsqlCommand" 
+				assembly="Npgsql, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
+				description="PostgreSQL"
+				parameterprefix="at"
+				commandbuilder="Npgsql.NpgsqlCommandBuilder" />
+			<provider 
+				name="Mono.Data.SqliteClient" 
+				connection="Mono.Data.SqliteClient.SqliteConnection" 
+				adapter="Mono.Data.SqliteClient.SqliteDataAdapter" 
+				command="Mono.Data.SqliteClient.SqliteCommand" 
+				assembly="Mono.Data.SqliteClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"
+				description="SQL Lite"
+				parameterprefix="colon" />
+			<provider 
+				name="Mono.Data.SybaseClient" 
+				connection="Mono.Data.SybaseClient.SybaseConnection" 
+				adapter="Mono.Data.SybaseClient.SybaseDataAdapter" 
+				command="Mono.Data.SybaseClient.SybaseCommand" 
+				assembly="Mono.Data.SybaseClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"
+				description="Sybase"
+				parameterprefix="at" />
+			<!--<provider 
+				name="FirebirdSql.Data.Firebird" 
+				connection="FirebirdSql.Data.Firebird.FbConnection" 
+				adapter="FirebirdSql.Data.Firebird.FbDataAdapter" 
+				command="FirebirdSql.Data.Firebird.FbCommand" 
+				assembly="FirebirdSql.Data.Firebird, Version=1.6.3.0, Culture=neutral, PublicKeyToken=e1b4f92304d7b12f"
+				description="Firebird"
+				parameterprefix="at"
+				commandbuilder="FirebirdSql.Data.Firebird.FbCommandBuilder" />-->
+			<!--<provider 
+				name="IBM.Data.DB2" 
+				connection="IBM.Data.DB2.DB2Connection" 
+				adapter="IBM.Data.DB2.DB2DataAdapter" 
+				command="IBM.Data.DB2.DB2Command" 
+				assembly="IBM.Data.DB2, Version=1.0.1728.9997, Culture=neutral, PublicKeyToken=7c307b91aa13d208"
+				description="IBM DB2 Universal Database" />-->
+			<!--<provider 
+				name="MySql.Data" 
+				connection="MySql.Data.MySqlClient.MySqlConnection" 
+				adapter="MySql.Data.MySqlClient.MySqlDataAdapter" 
+				command="MySql.Data.MySqlClient.MySqlCommand"
+				assembly="MySql.Data, Version=1.0.7.30073, Culture=neutral, PublicKeyToken=8e323390df8d9ed4"
+				description="MySQL (MySQL AB)"
+				parameterprefix="at"
+				commandbuilder="MySql.Data.MySqlClient.MySqlCommandBuilder" />-->
+		</providers>
+	</mono.data>
+	<mono.data.sql>
+		<metadataproviders>
+			<metaprovider 
+				providername="System.Data.SqlClient" 
+				metaprovidername="Mono.Data.Sql.SqlDbProvider" />
+			<metaprovider 
+				providername="System.Data.Odbc" 
+				metaprovidername="Mono.Data.Sql.OdbcDbProvider"  />
+			<metaprovider 
+				providername="System.Data.OracleClient" 
+				metaprovidername="Mono.Data.Sql.OracleDbProvider"  />
+			<metaprovider 
+				providername="Npgsql" 
+				metaprovidername="Mono.Data.Sql.NpgsqlDbProvider"  />
+			<metaprovider 
+				providername="Mono.Data.SqliteClient" 
+				metaprovidername="Mono.Data.Sql.SqliteDbProvider" />
+			<metaprovider 
+				providername="Mono.Data.SybaseClient" 
+				metaprovidername="Mono.Data.Sql.SybaseDbProvider" />
+			<!--<metaprovider 
+				providername="FirebirdSql.Data.Firebird" 
+				metaprovidername="Mono.Data.Sql.FirebirdDbProvider" />-->
+			<!--<metaprovider 
+				providername="MySql.Data" 
+				metaprovidername="Mono.Data.Sql.MySqlDbProvider" />-->
+			<!--<metaprovider 
+				providername="ByteFX.Data.MySqlClient" 
+				metaprovidername="Mono.Data.Sql.MySqlDbProvider"  />-->
+		</metadataproviders>
+	</mono.data.sql>
+</configuration>
+

Property changes on: tests/test-oracle-1.exe.config
___________________________________________________________________
Name: svn:executable
   + *

Index: Mono.Data.Sql/Providers/DbProviderBase.cs
===================================================================
--- Mono.Data.Sql/Providers/DbProviderBase.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/DbProviderBase.cs	(working copy)
@@ -3,8 +3,10 @@
 //
 // Authors:
 // Christian Hergert	<chris at mosaix.net>
+// Daniel Morgan        <danielmorgan at verizon.net>
 //
 // Copyright (C) 2005 Mosaix Communications, Inc.
+// Copyright (C) 2006 Daniel Morgan
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -31,6 +33,8 @@
 using System.Data;
 using System.Threading;
 
+using Mono.Data;
+
 namespace Mono.Data.Sql
 {
 	public delegate void DbProviderChangedEventHandler (object sender, DbProviderChangedArgs args);
@@ -47,13 +51,13 @@
 	}
 	
 	[Serializable]
-	public abstract class DbProviderBase
-	{
+	public abstract class DbProviderBase {
 		public event DbProviderChangedEventHandler NameChanged;
 		public event DbProviderChangedEventHandler StateChanged;
 		public event DbProviderChangedEventHandler Refreshed;
 		
 		protected string name = String.Empty;
+		Provider provider = null;
 
 		#region // Threading objects
 		Object ThreadSync = new Object ();
@@ -64,13 +68,27 @@
 		String ThreadedSQLText = String.Empty;
 		#endregion // End of Threading objects
 		
-		public DbProviderBase ()
+		public DbProviderBase () 
 		{
+			provider = GetMonoDataProvider ();
 		}
+
+		public DbProviderBase (Provider provider) 
+		{
+			this.provider = provider;
+		}
+
+		public Provider Provider {
+			get { 
+				if (provider == null)
+					provider = GetMonoDataProvider ();
+				return provider; 
+			}
+		}
 		
 		public virtual string ProviderName {
 			get {
-				return "Unknown Provider";
+				return provider.Name;
 			}
 		}
 		
@@ -117,30 +135,30 @@
 				return true;
 			}
 		}
-		
-		public virtual bool Open ()
+
+		private Provider GetMonoDataProvider() 
 		{
+			return MetaDataProviderFactory.GetProvider (this);
+		}
+		
+		public virtual bool Open () {
 			return IsOpen;
 		}
 		
-		public virtual void Close ()
-		{
+		public virtual void Close () {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void Refresh ()
-		{
+		public virtual void Refresh () {
 			if (Refreshed != null)
 				Refreshed (this, new DbProviderChangedArgs (this));
 		}
 		
-		public virtual bool SupportsSchemaType (Type type)
-		{
+		public virtual bool SupportsSchemaType (Type type) {
 			return false;
 		}
 		
-		public virtual void ExecuteSQL (string SQLText, SQLCallback Callback)
-		{
+		public virtual void ExecuteSQL (string SQLText, SQLCallback Callback) {
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
 				ThreadedSQLText = SQLText;
@@ -149,13 +167,11 @@
 			}
 		}
 
-		public virtual DataTable ExecuteSQL (string SQLText)
-		{
+		public virtual DataTable ExecuteSQL (string SQLText) {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void ExplainSQL (string SQLText, SQLCallback Callback)
-		{
+		public virtual void ExplainSQL (string SQLText, SQLCallback Callback) {
 			if (CanExplain != true)
 				return;
 			
@@ -167,16 +183,14 @@
 			}
 		}
 		
-		public virtual DataTable ExplainSQL (string SQLText)
-		{
+		public virtual DataTable ExplainSQL (string SQLText) {
 			if (CanExplain == false)
 				return null;
 			
 			return ExecuteSQL (String.Format ("EXPLAIN {0}", SQLText));
 		}
 		
-		public virtual void GetTables (SQLCallback Callback)
-		{
+		public virtual void GetTables (SQLCallback Callback) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -185,13 +199,11 @@
 			}
 		}
 		
-		public virtual TableSchema[] GetTables ()
-		{
+		public virtual TableSchema[] GetTables () {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void GetTableColumns (SQLCallback Callback, TableSchema schema)
-		{
+		public virtual void GetTableColumns (SQLCallback Callback, TableSchema schema) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -201,13 +213,11 @@
 			}
 		}
 
-		public virtual ColumnSchema[] GetTableColumns (TableSchema schema)
-		{
+		public virtual ColumnSchema[] GetTableColumns (TableSchema schema) {
 			throw new NotImplementedException ();
 		}
 
-		public virtual void GetTableConstraints (SQLCallback Callback, TableSchema schema)
-		{
+		public virtual void GetTableConstraints (SQLCallback Callback, TableSchema schema) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -217,13 +227,11 @@
 			}
 		}
 		
-		public virtual ConstraintSchema[] GetTableConstraints (TableSchema schema)
-		{
+		public virtual ConstraintSchema[] GetTableConstraints (TableSchema schema) {
 			throw new NotImplementedException ();
 		}
 
-		public virtual void GetViews (SQLCallback Callback)
-		{
+		public virtual void GetViews (SQLCallback Callback) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -232,13 +240,11 @@
 			}
 		}
 		
-		public virtual ViewSchema[] GetViews ()
-		{
+		public virtual ViewSchema[] GetViews () {
 			throw new NotImplementedException ();
 		}
 
-		public virtual void GetViewColumns (SQLCallback Callback, ViewSchema schema)
-		{
+		public virtual void GetViewColumns (SQLCallback Callback, ViewSchema schema) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -248,13 +254,11 @@
 			}
 		}
 
-		public virtual ColumnSchema[] GetViewColumns (ViewSchema schema)
-		{
+		public virtual ColumnSchema[] GetViewColumns (ViewSchema schema) {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void GetProcedures (SQLCallback Callback)
-		{
+		public virtual void GetProcedures (SQLCallback Callback) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -263,13 +267,11 @@
 			}
 		}
 		
-		public virtual ProcedureSchema[] GetProcedures ()
-		{
+		public virtual ProcedureSchema[] GetProcedures () {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void GetProcedureColumns (SQLCallback Callback, ProcedureSchema schema)
-		{
+		public virtual void GetProcedureColumns (SQLCallback Callback, ProcedureSchema schema) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -280,13 +282,11 @@
 			}
 		}
 		
-		public virtual ColumnSchema[] GetProcedureColumns (ProcedureSchema schema)
-		{
+		public virtual ColumnSchema[] GetProcedureColumns (ProcedureSchema schema) {
 			throw new NotImplementedException ();
 		}
 		
-		public virtual void GetUsers (SQLCallback Callback)
-		{
+		public virtual void GetUsers (SQLCallback Callback) {
 			Thread eThread = null;
 			lock (ThreadSync) {
 				ThreadedSQLCallback = Callback;
@@ -295,87 +295,75 @@
 			}
 		}
 		
-		public virtual UserSchema[] GetUsers ()
-		{
+		public virtual UserSchema[] GetUsers () {
 			throw new NotImplementedException ();
 		}
 		
-		protected virtual void OnOpen ()
-		{
+		protected virtual void OnOpen () {
 			if (StateChanged != null)
 				StateChanged (this, new DbProviderChangedArgs (this));
 		}
 		
-		protected virtual void OnClose ()
-		{
+		protected virtual void OnClose () {
 			if (StateChanged != null)
 				StateChanged (this, new DbProviderChangedArgs (this));
 		}
 		
-		protected virtual void ExecuteSQLThreadStart ()
-		{
+		protected virtual void ExecuteSQLThreadStart () {
 			string SQLText = ThreadedSQLText;
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, ExecuteSQL (SQLText));
 		}
 		
-		protected virtual void ExplainSQLThreadStart ()
-		{
+		protected virtual void ExplainSQLThreadStart () {
 			string SQLText = ThreadedSQLText;
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, ExplainSQL (SQLText));
 		}
 		
-		protected virtual void GetTablesThreadStart ()
-		{
+		protected virtual void GetTablesThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, GetTables ());
 		}
 
-		protected virtual void GetTableColumnsThreadStart ()
-		{
+		protected virtual void GetTableColumnsThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			TableSchema Table = ThreadedTableSchema;
 			Callback (this, GetTableColumns (Table));
 		}
 
-		protected virtual void GetTableConstraintsThreadStart ()
-		{
+		protected virtual void GetTableConstraintsThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			TableSchema Table = ThreadedTableSchema;
 			Callback (this, GetTableConstraints (Table));
 		}
 
-		protected virtual void GetViewsThreadStart ()
-		{
+		protected virtual void GetViewsThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, GetViews ());
 		}
 
-		protected virtual void GetViewColumnsThreadStart ()
-		{
+		protected virtual void GetViewColumnsThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			ViewSchema view = ThreadedViewSchema;
 			Callback (this, GetViewColumns (view));
 		}
 
-		protected virtual void GetProceduresThreadStart ()
-		{
+		protected virtual void GetProceduresThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, GetProcedures ());
 		}
 		
-		protected virtual void GetProcedureColumnsThreadStart ()
-		{
+		protected virtual void GetProcedureColumnsThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			ProcedureSchema schema = ThreadedProcedureSchema;
 			Callback (this, GetProcedureColumns (schema));
 		}
 
-		protected virtual void GetUsersThreadStart ()
-		{
+		protected virtual void GetUsersThreadStart () {
 			SQLCallback Callback = ThreadedSQLCallback;
 			Callback (this, GetUsers ());
 		}
 	}
-}
\ No newline at end of file
+}
+
Index: Mono.Data.Sql/Providers/MetaDataProviderSectionHandler.cs
===================================================================
--- Mono.Data.Sql/Providers/MetaDataProviderSectionHandler.cs	(revision 0)
+++ Mono.Data.Sql/Providers/MetaDataProviderSectionHandler.cs	(revision 0)
@@ -0,0 +1,96 @@
+//
+// Mono.Data.Sql.MeataDataProviderSectionHandler
+//
+// Authors:
+//   Brian Ritchie (brianlritchie at hotmail.com) 
+//   Daniel Morgan <danielmorgan at verizon.net>
+//  
+//
+// Copyright (C) Brian Ritchie, 2002
+// Copyright (C) Daniel Morgan, 2006
+// 
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Xml;
+using System.Configuration;
+using Mono.Data;
+using System.Reflection;
+
+namespace Mono.Data.Sql
+{
+	public class MetaDataProviderSectionHandler : IConfigurationSectionHandler
+	{
+		public virtual object Create (object parent, object configContext, XmlNode section)
+		{
+			if (section == null)
+				throw new System.ArgumentNullException ("section");
+
+			ArrayList providers = new ArrayList();
+			Assembly assembly = Assembly.GetExecutingAssembly();
+
+			XmlNodeList ProviderList = section.SelectNodes ("./metaprovider");
+			foreach (XmlNode ProviderNode in ProviderList) {
+				string providername = GetStringValue (ProviderNode, "providername", true);
+				string metaprovidername = GetStringValue (ProviderNode, "metaprovidername", true);
+
+				// get provider instance
+				Provider provider = null;
+				try {
+					provider = ProviderFactory.Providers[providername];
+				}
+				catch(ArgumentOutOfRangeException ae) {
+					throw new Exception("Can not find a Provider that matches providername in config file.");
+
+				}
+
+				// get meata data provider (dbprovider)
+				Type dbprovidertype = assembly.GetType(metaprovidername);
+				if (dbprovidertype == null)
+					throw new Exception("Can not find a DbProvider that matches metaprovidername in the config file.");
+				object[] parms = new object [] { provider };
+				object obj = Activator.CreateInstance (dbprovidertype, parms);
+				DbProviderBase dbprovider = (DbProviderBase) obj;
+
+				// add dbprovider to collection of dbproviders
+				providers.Add (dbprovider);
+			}
+
+			return (DbProviderBase[]) providers.ToArray(typeof(DbProviderBase));
+		}
+
+		private string GetStringValue(XmlNode _node, string _attribute, bool required)
+		{
+			XmlNode a = _node.Attributes.RemoveNamedItem(_attribute);
+			if (a == null) {
+				if (required)
+					throw new ConfigurationException("Attribute required: " + _attribute);
+				else
+					return null;
+			}
+			return a.Value;		
+		}
+	}
+}
+

Property changes on: Mono.Data.Sql/Providers/MetaDataProviderSectionHandler.cs
___________________________________________________________________
Name: svn:executable
   + *

Index: Mono.Data.Sql/Providers/SqlDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/SqlDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/SqlDbProvider.cs	(working copy)
@@ -7,6 +7,8 @@
 //   Sureshkumar T <tsureshkumar at novell.com>
 //
 // Copyright (C) 2005 Mosaix Communications, Inc.
+// Copyright (C) 2005, 2006 Daniel Morgan
+// Copyright (C) 2005 Novell
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,7 +36,7 @@
 using System.Text;
 using System.Text.RegularExpressions;
 
-using System.Data.SqlClient;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
@@ -44,8 +46,8 @@
 	[Serializable]
 	public class SqlDbProvider : DbProviderBase
 	{
-		protected SqlConnection connection = null;
-		protected SqlDataAdapter adapter = new SqlDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
 		
 		/// <summary>
@@ -53,21 +55,28 @@
 		/// </summary>
 		public SqlDbProvider () : base ()
 		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
-		public override string ProviderName {
-			get {
-				return "SQL Server Database";
-			}
+
+		public SqlDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
+
 		/// <summary>
 		/// Constructor with ADO.NET Sql connection.
 		/// </summary>
-		public SqlDbProvider (SqlConnection conn)
+		public SqlDbProvider (IDbConnection conn) 
 		{
 			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
 		}
+
+		public override string ProviderName {
+			get {
+				return "Microsoft SQL Server Database";
+			}
+		}
 		
 		/// <summary>
 		/// ADO.NET Connection
@@ -75,7 +84,7 @@
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new SqlConnection();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -167,8 +176,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				SqlCommand command = new SqlCommand();
-				command.Connection = connection;
+				IDbCommand command = Connection.CreateCommand ();
 				command.CommandText = SQLText;
 
 				DataSet resultSet = new DataSet ();
@@ -194,8 +202,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			SqlCommand command = new SqlCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				"SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
 				" so.crdate as created_date, so.xtype as table_type " +
@@ -203,7 +210,7 @@
 				"WHERE xtype IN ('S','U') " +
 				"AND su.uid = so.uid " +
 				"ORDER BY 1, 2";
-			SqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				TableSchema table = new TableSchema();
@@ -259,10 +266,10 @@
 				throw new InvalidOperationException ("Invalid connection");
 			
 			ArrayList collection = new ArrayList();
-			SqlConnection con2 = (SqlConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SqlCommand command = con2.CreateCommand ();
+			IDbCommand command = con2.CreateCommand ();
 			
 			command.CommandText = 
 				"SELECT su.name as owner, so.name as table_name, " +
@@ -279,7 +286,7 @@
 				"AND sc.xusertype = st.xusertype " +
 				"AND su.uid = so.uid " +
 				"ORDER BY sc.colid";
-			SqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ColumnSchema column = new ColumnSchema();
@@ -321,10 +328,10 @@
 		private string GetSource (string objectName) 
 		{
 			string sql = String.Format ("EXEC [master].[dbo].[sp_helptext] '{0}', null", objectName);
-			SqlConnection con2 = (SqlConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SqlCommand cmd = con2.CreateCommand ();
+			IDbCommand cmd = con2.CreateCommand ();
 			cmd.CommandText = sql;
 			IDataReader reader = cmd.ExecuteReader ();
 
@@ -352,8 +359,7 @@
 		{
 			ArrayList collection = new ArrayList();
 			
-			SqlCommand command = new SqlCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				"SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
 				" so.crdate as created_date, so.xtype as table_type " +
@@ -361,7 +367,7 @@
 				"WHERE xtype = 'V' " +
 				"AND su.uid = so.uid " +
 				"ORDER BY 1, 2";
-			SqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ViewSchema view = new ViewSchema();
@@ -402,15 +408,15 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			SqlConnection con2 = (SqlConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SqlCommand command = con2.CreateCommand ();
+			IDbCommand command = con2.CreateCommand ();
 			command.CommandText =
 				"SELECT * " +
 				" FROM " + view.Name +
 				" WHERE 1 = 0";
-			SqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 
 			for (int i = 0; i < r.FieldCount; i++) {
 				ColumnSchema column = new ColumnSchema();
@@ -463,14 +469,14 @@
 
 			ArrayList collection = new ArrayList ();
 			
-			using (SqlCommand cmd = connection.CreateCommand ()) {
+			using (IDbCommand cmd = Connection.CreateCommand ()) {
 				cmd.CommandText = "SELECT su.name AS owner, so.name as proc_name, so.id as proc_id, " +
 					" so.crdate as created_date, so.xtype as proc_type " +
 					"FROM dbo.sysobjects so, dbo.sysusers su " +
 					"WHERE xtype = 'P' " +
 					"AND su.uid = so.uid " +
 					"ORDER BY 1, 2";
-				using (SqlDataReader reader = cmd.ExecuteReader ()) {
+				using (IDataReader reader = cmd.ExecuteReader ()) {
 					while (reader.Read ()) {
 						ProcedureSchema proc = new ProcedureSchema ();
 						proc.Provider = this;
@@ -486,10 +492,13 @@
 				// get procedure text
 				cmd.CommandType = CommandType.StoredProcedure;
 				cmd.CommandText = "sp_helptext";
-				SqlParameter param = cmd.Parameters.Add ("@objname", SqlDbType.VarChar);
+				IDataParameter param = cmd.CreateParameter ();
+				param.ParameterName = "@objname";
+				param.DbType = DbType.String;
+				cmd.Parameters.Add (param);
 				foreach (ProcedureSchema proc in collection) {
 					param.Value = proc.Name;
-					using (SqlDataReader reader = cmd.ExecuteReader ()) {
+					using (IDataReader reader = cmd.ExecuteReader ()) {
 						if (reader.Read ())
 							proc.Definition = (string) reader [0];
 					}
@@ -506,14 +515,23 @@
 			
 			ArrayList collection = new ArrayList ();
 
-			using (SqlCommand cmd = connection.CreateCommand ()) {
+			using (IDbCommand cmd = Connection.CreateCommand ()) {
 				cmd.CommandType = CommandType.StoredProcedure;
 				cmd.CommandText = "sp_sproc_columns";
-				SqlParameter owner = cmd.Parameters.Add ("@procedure_owner", SqlDbType.VarChar);
-				SqlParameter name = cmd.Parameters.Add ("@procedure_name", SqlDbType.VarChar);
+
+				IDataParameter owner = cmd.CreateParameter ();
+				owner.ParameterName = "@procedure_owner";
+				owner.DbType = DbType.String;
+				cmd.Parameters.Add (owner);
+
+				IDataParameter name = cmd.CreateParameter ();
+				name.ParameterName = "@procedure_name";
+				name.DbType = DbType.String;
+				cmd.Parameters.Add (name);
+
 				owner.Value = schema.OwnerName;
 				name.Value = schema.Name;
-				using (SqlDataReader reader = cmd.ExecuteReader ()) {
+				using (IDataReader reader = cmd.ExecuteReader ()) {
 					while (reader.Read ()) {
 						ColumnSchema column = new ColumnSchema ();
 						column.Provider = this;
@@ -529,3 +547,4 @@
 		}
 	}
 }
+
Index: Mono.Data.Sql/Providers/SqliteDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/SqliteDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/SqliteDbProvider.cs	(working copy)
@@ -31,27 +31,43 @@
 using System.Collections;
 using System.Data;
 
-using Mono.Data.SqliteClient;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
 	[Serializable]
 	public class SqliteDbProvider : DbProviderBase
 	{
-		protected SqliteConnection connection = null;
-		protected SqliteDataAdapter adapter = new SqliteDataAdapter ();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
+
+		public SqliteDbProvider () : base () 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
 		
+		public SqliteDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
+
+		public SqliteDbProvider (IDbConnection conn) : base () 
+		{
+			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
+		}
+
 		public override string ProviderName {
 			get {
-				return "SQLite Database";
+				return "SQL Lite Database";
 			}
 		}
 		
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new SqliteConnection ();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -115,7 +131,7 @@
 		public override DataTable ExecuteSQL (string SQLText)
 		{
 			try {
-				SqliteCommand command = new SqliteCommand ();
+				IDbCommand command = Connection.CreateCommand ();
 				command.Connection = connection;
 				command.CommandText = SQLText;
 
@@ -144,11 +160,10 @@
 
 			ArrayList collection = new ArrayList ();
 
-			using (SqliteCommand command = new SqliteCommand ()) {
+			using (IDbCommand command = Connection.CreateCommand ()) {
 				command.CommandText = "select * from sqlite_master";
-				command.Connection = this.connection;
 
-				SqliteDataReader r = command.ExecuteReader ();
+				IDataReader r = command.ExecuteReader ();
 
 				while (r.Read ()) {
 					TableSchema table = new TableSchema ();
@@ -171,11 +186,11 @@
 
 			ArrayList collection = new ArrayList ();
 			
-			using (SqliteCommand command = new SqliteCommand()) {
+			using (IDbCommand command = Connection.CreateCommand ()) {
 				command.CommandText = "PRAGMA table_info('" +  table.Name + "')";
 				command.Connection = this.connection;
 				
-				SqliteDataReader r = command.ExecuteReader ();
+				IDataReader r = command.ExecuteReader ();
 
 				while (r.Read ()) {
 					ColumnSchema column = new ColumnSchema ();
@@ -207,3 +222,4 @@
 		}
 	}
 }
+
Index: Mono.Data.Sql/Providers/MetaDataProviderFactory.cs
===================================================================
--- Mono.Data.Sql/Providers/MetaDataProviderFactory.cs	(revision 0)
+++ Mono.Data.Sql/Providers/MetaDataProviderFactory.cs	(revision 0)
@@ -0,0 +1,153 @@
+//
+// Mono.Data.Sql.MetaDataProviderFactory
+//
+// Authors:
+//   Brian Ritchie (brianlritchie at hotmail.com) 
+//   Daniel Morgan <danielmorgan at verizon.net>
+//  
+//
+// Copyright (C) Brian Ritchie, 2002
+// Copyright (C) Daniel Morgan, 2006
+// 
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Reflection;
+using System.Runtime.Remoting;
+using System.Configuration;
+using System.Xml;
+using System.Collections;
+using System.Collections.Specialized;
+using Mono.Data;
+
+namespace Mono.Data.Sql {
+	public class MetaDataProviderFactory {
+		private static DbProviderBase[] dbproviders;
+
+		static MetaDataProviderFactory() 
+		{
+			dbproviders = (DbProviderBase[]) ConfigurationSettings.GetConfig ("mono.data.sql/metadataproviders");
+			if (dbproviders == null) {
+				dbproviders = new DbProviderBase[0];
+				// warn the developer or administrator that the provider list is empty
+				System.Diagnostics.Debug.Listeners.Add (new System.Diagnostics.TextWriterTraceListener (Console.Out));
+				System.Diagnostics.Debug.WriteLine ("No meta data providers found. Did you set up a mono.data.sql/metadataproviders area in your app.config or in machine.config?");
+			}
+		}
+
+		static public DbProviderBase[] MetaDataProviders {
+			get {
+				return dbproviders;
+			}
+		}
+
+		static public DbProviderBase GetMetaDataProvider (Provider provider) 
+		{
+			for (int p = 0; p < MetaDataProviders.Length; p++)
+				if (provider.Name.Equals(MetaDataProviders[p].Provider.Name))
+					return MetaDataProviders[p];
+
+			return null;
+		}
+
+		static public Provider GetProvider (DbProviderBase dbprovider) 
+		{	
+			for (int p = 0; p < MetaDataProviders.Length; p++) {
+				DbProviderBase dbp = MetaDataProviders[p];
+
+				if (dbp.GetType().ToString().Equals(dbprovider.GetType().ToString()))
+					return MetaDataProviders[p].Provider;
+			}
+			return null;
+		}
+
+		static public string GetProviderNameFromSetting (string Setting) 
+		{
+			string ConnectionString = ConfigurationSettings.AppSettings [Setting];
+			string [] ConnectionAttributes = ConnectionString.Split (new Char [1] { ';' }); 
+			string providerName = null;
+
+			foreach (string s in ConnectionAttributes) {
+				string [] AttributeParts = s.Split (new Char [1] { '=' });
+				if (AttributeParts [0].ToLower ().Trim () == "factory")
+					providerName = AttributeParts [1].Trim ();
+			}
+			return providerName;
+		}
+
+		static public Mono.Data.Provider GetProviderFromSetting (string Setting) 
+		{
+			string ConnectionString = ConfigurationSettings.AppSettings [Setting];
+			string [] ConnectionAttributes = ConnectionString.Split (new Char [1] { ';' }); 
+			string providerName = null;
+
+			foreach (string s in ConnectionAttributes) {
+				string [] AttributeParts = s.Split (new Char [1] { '=' });
+				if (AttributeParts [0].ToLower ().Trim () == "factory")
+					providerName = AttributeParts [1].Trim ();
+			}
+			Mono.Data.ProviderCollection pc = Mono.Data.ProviderFactory.Providers;
+			Mono.Data.Provider provider = pc[providerName];
+			return provider;
+		}
+
+		static public string GetConnectionStringFromSetting (string Setting) 
+		{
+			string ConnectionString = ConfigurationSettings.AppSettings [Setting];
+			string [] ConnectionAttributes = ConnectionString.Split (new Char [1] { ';' }); 
+			string NewConnectionString = "";
+			foreach (string s in ConnectionAttributes) {
+				string [] AttributeParts = s.Split (new Char [1] { '=' });
+				if (!AttributeParts [0].ToLower ().Trim ().Equals("factory"))
+					NewConnectionString += ";" + s;
+			}
+			NewConnectionString = NewConnectionString.Remove (0, 1); // remove the initial semicolon
+			return NewConnectionString;
+		}
+
+		static public DbProviderBase GetDbProviderBaseFromSetting (string Setting) 
+		{
+			string ConnectionString = ConfigurationSettings.AppSettings [Setting];
+			string [] ConnectionAttributes = ConnectionString.Split (new Char [1] { ';' }); 
+			string providerName = null;
+			string NewConnectionString = "";
+			foreach (string s in ConnectionAttributes) {
+				string [] AttributeParts = s.Split (new Char [1] { '=' });
+				if (AttributeParts [0].ToLower ().Trim () == "factory")
+					providerName = AttributeParts [1].Trim ();
+				else 
+					NewConnectionString += ";" + s;
+			}
+			NewConnectionString = NewConnectionString.Remove (0, 1); // remove the initial semicolon
+			
+			Mono.Data.ProviderCollection pc = Mono.Data.ProviderFactory.Providers;
+			Mono.Data.Provider provider = pc[providerName];
+
+			DbProviderBase dbprovider = GetMetaDataProvider(provider);
+			dbprovider.ConnectionString = NewConnectionString;
+			return dbprovider;
+		}
+	}
+}
+

Property changes on: Mono.Data.Sql/Providers/MetaDataProviderFactory.cs
___________________________________________________________________
Name: svn:executable
   + *

Index: Mono.Data.Sql/Providers/NpgsqlDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/NpgsqlDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/NpgsqlDbProvider.cs	(working copy)
@@ -31,8 +31,9 @@
 using System.Data;
 using System.Text;
 using System.Text.RegularExpressions;
+using System.Reflection;
 
-using Npgsql;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
@@ -42,8 +43,8 @@
 	[Serializable]
 	public class NpgsqlDbProvider : DbProviderBase
 	{
-		protected NpgsqlConnection connection = null;
-		protected NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
 		
 		/// <summary>
@@ -51,7 +52,19 @@
 		/// </summary>
 		public NpgsqlDbProvider () : base ()
 		{
+			adapter = Provider.CreateDataAdapter ();
 		}
+
+		public NpgsqlDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
+
+		public NpgsqlDbProvider (IDbConnection conn) : base () 
+		{
+			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
+		}
 		
 		public override string ProviderName {
 			get {
@@ -60,20 +73,12 @@
 		}
 		
 		/// <summary>
-		/// Constructor with ADO.NET Npgsql connection.
-		/// </summary>
-		public NpgsqlDbProvider (NpgsqlConnection conn)
-		{
-			connection = conn;
-		}
-		
-		/// <summary>
 		/// ADO.NET Connection
 		/// </summary>
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new NpgsqlConnection();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -119,8 +124,8 @@
 		/// </summary>
 		protected int LastSystemOID {
 			get {
-				int major = connection.ServerVersion.Major;
-				int minor = connection.ServerVersion.Minor;
+				int major = GetServerVersion ().Major;
+				int minor = GetServerVersion ().Minor;
 				
 				if (major == 8)
 					return 17137;
@@ -136,6 +141,12 @@
 					return 17137;
 			}
 		}
+
+		public Version GetServerVersion ()
+		{
+				PropertyInfo conPropertyInfo = Connection.GetType ().GetProperty ("ServerVersion");
+				return (Version) conPropertyInfo.GetValue (Connection, null);
+		}
 		
 		/// <summary>
 		/// Open the connection. Returns true on success.
@@ -205,8 +216,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				NpgsqlCommand command = new NpgsqlCommand();
-				command.Connection = connection;
+				IDbCommand command = Connection.CreateCommand ();
 				command.CommandText = SQLText;
 
 				DataSet resultSet = new DataSet ();
@@ -232,8 +242,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			NpgsqlCommand command = new NpgsqlCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				"SELECT c.relname, n.nspname, u.usename, d.description "
 				+ "FROM pg_class c "
@@ -245,7 +254,7 @@
 				+ "   (SELECT 1 FROM pg_rewrite r "
 				+ "      WHERE r.ev_class = c.oid AND r.ev_type = '1') "
 				+ "ORDER BY relname;";
-			NpgsqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				TableSchema table = new TableSchema();
@@ -304,8 +313,7 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			NpgsqlCommand command = new NpgsqlCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText = "SELECT a.attname, a.attnotnull, a.attlen, "
 				+ "typ.typname, adef.adsrc "
 				+ "FROM "
@@ -321,7 +329,7 @@
 				+ "AND a.attnum > 0 AND NOT a.attisdropped "
 				+ "AND a.atttypid = typ.oid "
 				+ "ORDER BY a.attnum;";
-			NpgsqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ColumnSchema column = new ColumnSchema();
@@ -361,8 +369,7 @@
 		{
 			ArrayList collection = new ArrayList();
 			
-			NpgsqlCommand command = new NpgsqlCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				"SELECT v.schemaname, v.viewname, v.viewowner, v.definition,"
 				+ " (c.oid <= " + LastSystemOID + "), "
@@ -372,7 +379,7 @@
 				+ "FROM pg_views v, pg_class c "
 				+ "WHERE v.viewname = c.relname "
 				+ "ORDER BY viewname";
-			NpgsqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ViewSchema view = new ViewSchema();
@@ -414,7 +421,7 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			NpgsqlCommand command = new NpgsqlCommand ();
+			IDbCommand command = Connection.CreateCommand ();
 			command.Connection = connection;
 			command.CommandText =
 				"SELECT attname, typname, attlen, attnotnull "
@@ -428,7 +435,7 @@
 				+ view.Name + "') "
 				+ "  AND a.attnum > 0 AND NOT a.attisdropped "
 				+ "     ORDER BY a.attnum;";
-			NpgsqlDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ColumnSchema column = new ColumnSchema();
@@ -463,8 +470,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			NpgsqlCommand command = new NpgsqlCommand ();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText = String.Format (
 				"SELECT "
 				+ "pc.conname, "
@@ -493,7 +499,7 @@
 				+ "	WHERE nspname='{1}')) "
 				+ "ORDER BY "
 				+ "1;", table.Name, table.SchemaName);
-			NpgsqlDataReader r = command.ExecuteReader ();
+			IDataReader r = command.ExecuteReader ();
 			
 			while (r.Read ()) {
 				ConstraintSchema constraint = null;
@@ -534,10 +540,9 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			NpgsqlCommand command = new NpgsqlCommand ();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText = "SELECT * FROM pg_user;";
-			NpgsqlDataReader r = command.ExecuteReader ();
+			IDataReader r = command.ExecuteReader ();
 			
 			while (r.Read ()) {
 				UserSchema user = new UserSchema ();
@@ -583,8 +588,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			NpgsqlCommand command = new NpgsqlCommand ();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				  "SELECT pc.proname, pc.oid::integer, pl.lanname, pc.prosrc "
 				+ "FROM "
@@ -605,7 +609,7 @@
 				+ "WHERE pc.proowner = pu.usesysid "
 				+ "AND pc.prorettype = 0 "
 				+ "AND pc.prolang = pl.oid;";
-			NpgsqlDataReader r = command.ExecuteReader ();
+			IDataReader r = command.ExecuteReader ();
 			
 			while (r.Read ()) {
 				ProcedureSchema procedure = new ProcedureSchema ();
@@ -638,14 +642,13 @@
 			// FIXME: Won't work properly with overload functions.
 			// Maybe check the number of columns in the parameters for
 			// proper match.
-			NpgsqlCommand command = new NpgsqlCommand ();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText = String.Format (
 				  "SELECT format_type (prorettype, NULL) "
 				+ "FROM pg_proc pc, pg_language pl "
 				+ "WHERE pc.prolang = pl.oid "
 				+ "AND pc.proname = '{0}';", schema.Name);
-			NpgsqlDataReader r = command.ExecuteReader ();
+			IDataReader r = command.ExecuteReader ();
 			
 			while (r.Read ()) {
 				ColumnSchema column = new ColumnSchema ();
@@ -663,3 +666,4 @@
 		}
 	}
 }
+
Index: Mono.Data.Sql/Providers/MySqlDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/MySqlDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/MySqlDbProvider.cs	(working copy)
@@ -30,17 +30,35 @@
 using System.Collections;
 using System.Data;
 
-using ByteFX.Data.MySqlClient;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
 	[Serializable]
 	public class MySqlDbProvider : DbProviderBase
 	{
-		protected MySqlConnection connection = null;
-		protected MySqlDataAdapter adapter = new MySqlDataAdapter ();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
+
+		public MySqlDbProvider () : base () 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
+
+
+		public MySqlDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
+
+		public MySqlDbProvider (IDbConnection conn) : base () 
+		{
+			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
+		}
 		
+
 		public override string ProviderName {
 			get {
 				return "MySQL Database";
@@ -50,7 +68,7 @@
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new MySqlConnection ();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -115,8 +133,7 @@
 		public override DataTable ExecuteSQL (string SQLText)
 		{
 			try {
-				MySqlCommand command = new MySqlCommand ();
-				command.Connection = Connection;
+				IDbCommand command = Connection.CreateCommand ();
 				command.CommandText = SQLText;
 				
 				DataSet resultSet = null;
@@ -139,11 +156,10 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			using (MySqlCommand command = new MySqlCommand ()) {
-				command.Connection = Connection;
+			using (IDbCommand command = Connection.CreateCommand ()) {
 				command.CommandText =
 					"SHOW TABLES;";
-				MySqlDataReader r = command.ExecuteReader ();
+				IDataReader r = command.ExecuteReader ();
 				
 				while (r.Read ()) {
 					TableSchema table = new TableSchema ();
@@ -167,13 +183,12 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			using (MySqlCommand command = new MySqlCommand ()) {
-				command.Connection = Connection;
+			using (IDbCommand command = Connection.CreateCommand()) {
 
 				// XXX: Use String.Format cause mysql parameters suck assmar.
 				command.CommandText =
 					String.Format ("DESCRIBE {0}", table.Name);
-				MySqlDataReader r = command.ExecuteReader ();
+				IDataReader r = command.ExecuteReader ();
 				
 				while (r.Read ()) {
 					ColumnSchema column = new ColumnSchema ();
@@ -201,11 +216,9 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			using (MySqlCommand command = new MySqlCommand ()) {
-				command.Connection = Connection;
-				command.CommandText =
-					"";
-				MySqlDataReader r = command.ExecuteReader ();
+			using (IDbCommand command = Connection.CreateCommand ()) {
+				command.CommandText = "";
+				IDataReader r = command.ExecuteReader ();
 				
 				while (r.Read ()) {
 					ConstraintSchema constraint = new ConstraintSchema ();
@@ -230,11 +243,10 @@
 
 			ArrayList collection = new ArrayList ();
 
-			using (MySqlCommand command = new MySqlCommand ()) {
-				command.Connection = connection;
+			using (IDbCommand command = Connection.CreateCommand ()) {
 				command.CommandText =
 					"SELECT DISTINCT user from mysql.user where user != '';";
-				MySqlDataReader r = command.ExecuteReader ();
+				IDataReader r = command.ExecuteReader ();
 
 				while (r.Read ()) {
 					UserSchema user = new UserSchema ();
@@ -251,3 +263,4 @@
 		}
 	}
 }
+
Index: Mono.Data.Sql/Providers/OracleDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/OracleDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/OracleDbProvider.cs	(working copy)
@@ -6,7 +6,7 @@
 //   Daniel Morgan <danielmorgan at verizon.net>
 //
 // Copyright (C) 2005 Mosaix Communications, Inc.
-// Copyright (C) 2005 Daniel Morgan
+// Copyright (C) 2005, 2006 Daniel Morgan
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,8 +34,6 @@
 using System.Text;
 using System.Text.RegularExpressions;
 
-using System.Data.OracleClient;
-
 namespace Mono.Data.Sql
 {
 	/// <summary>
@@ -44,29 +42,41 @@
 	[Serializable]
 	public class OracleDbProvider : DbProviderBase
 	{
-		protected OracleConnection connection = null;
-		protected OracleDataAdapter adapter = new OracleDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
 
+		public OracleDbProvider () : base () 
+		{
+			adapter = Provider.CreateDataAdapter();
+		}
+
+		public OracleDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter();
+		}
+
+		public OracleDbProvider (IDbConnection conn) : base () 
+		{
+			connection = conn;
+			adapter = Provider.CreateDataAdapter();
+		}
+
 		public override string ProviderName {
 			get {
-				return "Oracle 8i/9i/10g";
+				return "Oracle";
 			}
 		}
-		
-		/// <summary>
-		/// ADO.NET Connection
-		/// </summary>
+
 		public override IDbConnection Connection {
 			get {
-				if (connection == null) {
-					connection = new OracleConnection();
-				}
+				if (connection == null)
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
 		}
-		
+
 		/// <summary>
 		/// Connection String
 		/// </summary>
@@ -153,8 +163,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				OracleCommand command = new OracleCommand();
-				command.Connection = connection;
+				IDbCommand command = connection.CreateCommand();
 				command.CommandText = SQLText;
 
 				DataSet resultSet = new DataSet ();
@@ -196,13 +205,12 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			OracleCommand command = new OracleCommand();
-			command.Connection = connection;
+			IDbCommand command = connection.CreateCommand();
 			command.CommandText =
 				"SELECT OWNER, TABLE_NAME, TABLESPACE_NAME " +
 				"FROM ALL_TABLES " +
 				"ORDER BY OWNER, TABLE_NAME";
-			OracleDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				TableSchema table = new TableSchema();
@@ -263,9 +271,8 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			OracleCommand command = new OracleCommand();
-			command.Connection = connection;
-			command.CommandText = 
+			IDbCommand command = connection.CreateCommand();
+			command.CommandText =
 				"SELECT OWNER, TABLE_NAME, COLUMN_NAME, " +
 				"       DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, " +
 				"       NULLABLE, COLUMN_ID, DEFAULT_LENGTH, DATA_DEFAULT " +
@@ -273,7 +280,7 @@
 				"WHERE OWNER = '" + table.OwnerName + "' " + 
 				"AND TABLE_NAME = '" + table.Name + "' " +
 				"ORDER BY OWNER, TABLE_NAME, COLUMN_ID";
-			OracleDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ColumnSchema column = new ColumnSchema();
@@ -320,13 +327,12 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			OracleCommand command = new OracleCommand();
-			command.Connection = connection;
+			IDbCommand command = connection.CreateCommand();
 			command.CommandText =
 				"SELECT OWNER, VIEW_NAME, TEXT " +
 				"FROM ALL_VIEWS " +
 				"ORDER BY OWNER, VIEW_NAME";
-			OracleDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ViewSchema view = new ViewSchema();
@@ -358,13 +364,12 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			OracleCommand command = new OracleCommand ();
-			command.Connection = connection;
+			IDbCommand command = connection.CreateCommand();
 			command.CommandText =
 				"SELECT * " +
 				" FROM " + view.Name +
 				" WHERE 1 = 0";
-			OracleDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 
 			for (int i = 0; i < r.FieldCount; i++) {
 				ColumnSchema column = new ColumnSchema();
@@ -392,8 +397,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			OracleCommand command = new OracleCommand ();
-			command.Connection = connection;
+			IDbCommand command = connection.CreateCommand();
 			command.CommandText = 
 				"SELECT k.owner, k.table_name, k.constraint_name, " +
 				"       k.constraint_type, k.status, k.validated " +
@@ -401,7 +405,7 @@
 				"WHERE k.owner = '" + table.OwnerName + "' " +
 				"AND k.table_name = '" + table.Name + "' " +
 				"and k.constraint_type = 'P'";
-			OracleDataReader r = command.ExecuteReader ();
+			IDataReader r = command.ExecuteReader ();
 			
 			while (r.Read ()) {
 				ConstraintSchema constraint = null;
Index: Mono.Data.Sql/Providers/FirebirdDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/FirebirdDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/FirebirdDbProvider.cs	(working copy)
@@ -6,7 +6,7 @@
 //   Daniel Morgan <danielmorgan at verizon.net>
 //
 // Copyright (C) 2005 Mosaix Communications, Inc.
-// Copyright (C) 2005 Daniel Morgan
+// Copyright (C) 2005, 2006 Daniel Morgan
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -33,8 +33,9 @@
 using System.Data;
 using System.Text;
 using System.Text.RegularExpressions;
+using System.Reflection;
 
-using FirebirdSql.Data.Firebird;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
@@ -44,17 +45,31 @@
 	[Serializable]
 	public class FirebirdDbProvider : DbProviderBase
 	{
-		protected FbConnection connection = null;
-		protected FbDataAdapter adapter = new FbDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
+
+		static MethodInfo schemaMethod = null;
 		
 		/// <summary>
 		/// Default Constructor
 		/// </summary>
 		public FirebirdDbProvider () : base ()
 		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
+
+		public FirebirdDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
+		}
+
+		public FirebirdDbProvider (IDbConnection conn) 
+		{
+			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
+		}
+
 		public override string ProviderName {
 			get {
 				return "Firebird Database";
@@ -62,20 +77,12 @@
 		}
 		
 		/// <summary>
-		/// Constructor with ADO.NET Npgsql connection.
-		/// </summary>
-		public FirebirdDbProvider (FbConnection conn)
-		{
-			connection = conn;
-		}
-		
-		/// <summary>
 		/// ADO.NET Connection
 		/// </summary>
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new FbConnection();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -183,8 +190,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				FbCommand command = new FbCommand();
-				command.Connection = connection;
+				IDbCommand command = Connection.CreateCommand ();
 				command.CommandText = SQLText;
 
 				DataSet resultSet = new DataSet ();
@@ -210,7 +216,7 @@
 			
 			ArrayList collection = new ArrayList ();
 
-			DataTable dataTable = connection.GetSchema ("Tables", new string[] {null, null, null, "TABLE"});
+			DataTable dataTable = GetSchema ("Tables", new string[] {null, null, null, "TABLE"});
 
 			for (int r = 0; r < dataTable.Rows.Count; r++) {
 				DataRow row = dataTable.Rows[r];
@@ -268,7 +274,7 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			DataTable table2 = connection.GetSchema ("Columns", new string[] {null, null, table.Name, null});
+			DataTable table2 = GetSchema ("Columns", new string[] {null, null, table.Name, null});
 			for (int r = 0; r < table2.Rows.Count; r++) {
 				DataRow row2 = table2.Rows[r];
 
@@ -336,7 +342,7 @@
 		{
 			ArrayList collection = new ArrayList();
 
-			DataTable table2 = connection.GetSchema ("Views", new string[] {null, null, null});
+			DataTable table2 = GetSchema ("Views", new string[] {null, null, null});
 			for (int r = 0; r < table2.Rows.Count; r++) {
 				DataRow row2 = table2.Rows[r];
 				string viewName = row2["VIEW_NAME"].ToString();
@@ -414,7 +420,7 @@
 
 			DataTable table2 = null;
 			DataRow row2 = null;
-			table2 = connection.GetSchema ("Procedures", new string[] {null, null, null});
+			table2 = GetSchema ("Procedures", new string[] {null, null, null});
 			for (int r = 0; r < table2.Rows.Count; r++) {
 				row2 = table2.Rows[r];
 				ProcedureSchema procedure = new ProcedureSchema ();		
@@ -428,7 +434,7 @@
 			}
 			table2 = null;
 
-			table2 = connection.GetSchema ("Functions", new string[] {null, null, null, null});
+			table2 = GetSchema ("Functions", new string[] {null, null, null, null});
 			for (int r = 0; r < table2.Rows.Count; r++) {
 				row2 = table2.Rows[r];
 				ProcedureSchema procedure = new ProcedureSchema ();		
@@ -456,5 +462,37 @@
 			
 			return (ColumnSchema[]) collection.ToArray (typeof (ColumnSchema));
 		}
+
+		public DataTable GetSchema (string sCollectionName, string[] sRestrictions) 
+		{
+			if (schemaMethod == null) {
+				// get the proper GetSchema method on the FbConnection object
+				MethodInfo [] conMethodInfo = Connection.GetType ().GetMethods ();
+		
+				for (int m = 0; m < conMethodInfo.Length; m++) {
+					if (conMethodInfo[m].Name.Equals ("GetSchema")) {
+						ParameterInfo[] parms = conMethodInfo[m].GetParameters ();
+         
+						if (parms.Length == 2) {
+							if (parms[0].ParameterType.ToString ().Equals ("System.String") &&
+								parms[1].ParameterType.ToString ().Equals ("System.String[]")) {
+								schemaMethod = conMethodInfo [m];
+								m = conMethodInfo.Length;
+							}
+						}
+					}
+				}
+			}
+
+			object parm0 = (object) sCollectionName;
+			object parm1 = (object) sRestrictions;
+
+			object[] oParms = new object[2];
+			oParms[0] = parm0;
+			oParms[1] = parm1;
+
+			// invoke GetSchema method
+			return (DataTable) schemaMethod.Invoke (Connection, oParms);
+		}
 	}
 }
Index: Mono.Data.Sql/Providers/SybaseDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/SybaseDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/SybaseDbProvider.cs	(working copy)
@@ -5,7 +5,7 @@
 //   Christian Hergert	<chris at mosaix.net>
 //   Daniel Morgan <danielmorgan at verizon.net>
 //
-// Copyright (C) 2005 Mosaix Communications, Inc.
+// Copyright (C) 2005, 2006 Mosaix Communications, Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -33,7 +33,7 @@
 using System.Text;
 using System.Text.RegularExpressions;
 
-using Mono.Data.SybaseClient;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
@@ -43,8 +43,8 @@
 	[Serializable]
 	public class SybaseDbProvider : DbProviderBase
 	{
-		protected SybaseConnection connection = null;
-		protected SybaseDataAdapter adapter = new SybaseDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
 		
 		/// <summary>
@@ -52,21 +52,28 @@
 		/// </summary>
 		public SybaseDbProvider () : base ()
 		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
-		public override string ProviderName {
-			get {
-				return "Sybase ASE Database";
-			}
+
+		public SybaseDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
+
 		/// <summary>
 		/// Constructor with ADO.NET Sql connection.
 		/// </summary>
-		public SybaseDbProvider (SybaseConnection conn)
+		public SybaseDbProvider (IDbConnection conn) 
 		{
 			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
 		}
+
+		public override string ProviderName {
+			get {
+				return "Sybase ASE Database";
+			}
+		}
 		
 		/// <summary>
 		/// ADO.NET Connection
@@ -74,7 +81,7 @@
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new SybaseConnection();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -166,7 +173,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				SybaseCommand command = new SybaseCommand();
+				IDbCommand command = Connection.CreateCommand ();
 				command.Connection = connection;
 				command.CommandText = SQLText;
 
@@ -193,8 +200,7 @@
 			
 			ArrayList collection = new ArrayList ();
 			
-			SybaseCommand command = new SybaseCommand();
-			command.Connection = connection;
+			IDbCommand command = Connection.CreateCommand ();
 			command.CommandText =
 				"SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
 				" so.crdate as created_date, so.type as table_type " +
@@ -202,7 +208,7 @@
 				"WHERE type IN ('S','U') " +
 				"AND su.uid = so.uid " +
 				"ORDER BY 1, 2";
-			SybaseDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				TableSchema table = new TableSchema();
@@ -258,10 +264,10 @@
 				throw new InvalidOperationException ("Invalid connection");
 			
 			ArrayList collection = new ArrayList();
-			SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SybaseCommand command = con2.CreateCommand ();
+			IDbCommand command = con2.CreateCommand ();
 			
 			command.CommandText = 
 				"select su.name as owner, so.name as table_name, sc.name as column_name,  " +
@@ -278,7 +284,7 @@
 					"and sc.usertype = st.usertype " +
 					"order by sc.colid";
 
-			SybaseDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ColumnSchema column = new ColumnSchema();
@@ -320,10 +326,10 @@
 		private string GetSource (string objectName) 
 		{
 			string sql = String.Format ("EXEC [master].[dbo].[sp_helptext] '{0}', null", objectName);
-			SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SybaseCommand cmd = con2.CreateCommand ();
+			IDbCommand cmd = con2.CreateCommand ();
 			cmd.CommandText = sql;
 			IDataReader reader = cmd.ExecuteReader ();
 
@@ -351,7 +357,7 @@
 		{
 			ArrayList collection = new ArrayList();
 			
-			SybaseCommand command = new SybaseCommand();
+			IDbCommand command = Connection.CreateCommand ();
 			command.Connection = connection;
 			command.CommandText =
 				"SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
@@ -360,7 +366,7 @@
 				"WHERE type = 'V' " +
 				"AND su.uid = so.uid " +
 				"ORDER BY 1, 2";
-			SybaseDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 			
 			while (r.Read()) {
 				ViewSchema view = new ViewSchema();
@@ -401,15 +407,15 @@
 			
 			ArrayList collection = new ArrayList();
 			
-			SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
+			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 			if (con2.State == ConnectionState.Closed)
 				con2.Open();
-			SybaseCommand command = con2.CreateCommand ();
+			IDbCommand command = con2.CreateCommand ();
 			command.CommandText =
 				"SELECT * " +
 				" FROM " + view.Name +
 				" WHERE 1 = 0";
-			SybaseDataReader r = command.ExecuteReader();
+			IDataReader r = command.ExecuteReader();
 
 			for (int i = 0; i < r.FieldCount; i++) {
 				ColumnSchema column = new ColumnSchema();
@@ -442,9 +448,9 @@
 			
 //			ArrayList collection = new ArrayList ();
 //			
-//			SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
+//			IDbConnection con2 = (IDbConnection) (((ICloneable) connection).Clone ());
 //			con2.Open();
-//			SybaseCommand command = con2.CreateCommand ();
+//			IDbCommand command = con2.CreateCommand ();
 
 			// TODO: get constraints
 			return new ConstraintSchema[0];
@@ -461,3 +467,4 @@
 		}
 	}
 }
+
Index: Mono.Data.Sql/Providers/OdbcDbProvider.cs
===================================================================
--- Mono.Data.Sql/Providers/OdbcDbProvider.cs	(revision 57083)
+++ Mono.Data.Sql/Providers/OdbcDbProvider.cs	(working copy)
@@ -6,7 +6,7 @@
 //   Daniel Morgan <danielmorgan at verizon.net>
 //
 // Copyright (C) 2005 Mosaix Communications, Inc.
-// Copyright (C) 2005 Daniel Morgan
+// Copyright (C) 2005, 2006 Daniel Morgan
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -34,7 +34,7 @@
 using System.Text;
 using System.Text.RegularExpressions;
 
-using System.Data.Odbc;
+using Mono.Data;
 
 namespace Mono.Data.Sql
 {
@@ -44,8 +44,8 @@
 	[Serializable]
 	public class OdbcDbProvider : DbProviderBase
 	{
-		protected OdbcConnection connection = null;
-		protected OdbcDataAdapter adapter = new OdbcDataAdapter();
+		protected IDbConnection connection = null;
+		protected IDbDataAdapter adapter;
 		protected bool isConnectionStringWrong = false;
 		
 		/// <summary>
@@ -53,21 +53,28 @@
 		/// </summary>
 		public OdbcDbProvider () : base ()
 		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
-		public override string ProviderName {
-			get {
-				return "Provider for ODBC Data Sources";
-			}
+
+		public OdbcDbProvider (Mono.Data.Provider provider) : base (provider) 
+		{
+			adapter = Provider.CreateDataAdapter ();
 		}
-		
+
 		/// <summary>
 		/// Constructor with ADO.NET ODBC connection.
 		/// </summary>
-		public OdbcDbProvider (OdbcConnection conn)
+		public OdbcDbProvider (IDbConnection conn) 
 		{
 			connection = conn;
+			adapter = Provider.CreateDataAdapter ();
 		}
+
+		public override string ProviderName {
+			get {
+				return "Provider for ODBC Data Sources";
+			}
+		}
 		
 		/// <summary>
 		/// ADO.NET Connection
@@ -75,7 +82,7 @@
 		public override IDbConnection Connection {
 			get {
 				if (connection == null)
-					connection = new OdbcConnection();
+					connection = Provider.CreateConnection ();
 				
 				return (IDbConnection) connection;
 			}
@@ -143,38 +150,7 @@
 		/// </summary>
 		public override bool SupportsSchemaType(Type type)
 		{
-			if (type == typeof(TableSchema))
-				return true;
-			else if (type == typeof(ViewSchema))
-				return true;
-			else if (type == typeof(ProcedureSchema))
-				return true;
-			else if (type == typeof(AggregateSchema))
-				return true;
-			else if (type == typeof(GroupSchema))
-				return true;
-			else if (type == typeof(UserSchema))
-				return true;
-			else if (type == typeof(LanguageSchema))
-				return true;
-			else if (type == typeof(OperatorSchema))
-				return true;
-			else if (type == typeof(RoleSchema))
-				return true;
-			else if (type == typeof(SequenceSchema))
-				return true;
-			else if (type == typeof(DataTypeSchema))
-				return true;
-			else if (type == typeof(TriggerSchema))
-				return true;
-			else if (type == typeof(ColumnSchema))
-				return true;
-			else if (type == typeof(ConstraintSchema))
-				return true;
-			else if (type == typeof(RuleSchema))
-				return true;
-			else
-				return false;
+			return false;
 		}
 		
 		/// <summary>
@@ -183,8 +159,7 @@
 		public override DataTable ExecuteSQL(string SQLText)
 		{
 			try {
-				OdbcCommand command = new OdbcCommand();
-				command.Connection = connection;
+				IDbCommand command = Connection.CreateCommand ();
 				command.CommandText = SQLText;
 
 				DataSet resultSet = new DataSet ();
Index: Mono.Data.Sql/Makefile.Win32
===================================================================
--- Mono.Data.Sql/Makefile.Win32	(revision 57190)
+++ Mono.Data.Sql/Makefile.Win32	(working copy)
@@ -31,7 +31,6 @@
 Schema/AggregateSchema.cs \
 Schema/TableSchema.cs \
 Schema/ProcedureSchema.cs \
-Providers/MySqlDbProvider.cs \
 Providers/DbProviderBase.cs \
 Providers/NpgsqlDbProvider.cs \
 Providers/SqliteDbProvider.cs \
@@ -43,21 +42,23 @@
 Providers/MetaDataProviderFactory.cs \
 AssemblyInfo.cs
 
-# Providers/FirebirdDbProvider.cs
-
+#Providers/MySqlDbProvider.cs \
+#Providers/FirebirdDbProvider.cs \
+ 
 #build_sources = $(addprefix $(srcdir)/, $(FILES))
 build_sources=$(FILES)
 
 REFS = \
 -r:System.Data \
--r:Mono.Data \
--r:Npgsql \
--r:ByteFX.Data \
--r:Mono.Data.SqliteClient \
--r:Mono.Data.SybaseClient \
--r:System.Data.OracleClient
+-r:Mono.Data
 
-# -r:FirebirdSql.Data.Firebird.dll
+#-r:Npgsql 
+#-r:ByteFX.Data 
+#-r:Mono.Data.SqliteClient 
+#-r:Mono.Data.SybaseClient 
+#-r:System.Data.OracleClient 
+#-r:FirebirdSql.Data.Firebird.dll
+
 # -r:$(top_srcdir)/contrib/FirebirdSql.Data.Firebird.dll
 
 ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoQuery


More information about the Monodevelop-list mailing list