I've put the initial version of the ProviderFactory objects into CVS. This will give us a foundation for abstract data provider access within Mono. It can also be used in the MS.NET framework.

The code is in CVS under /mcs/class/Mono.Data. I've included build files, but haven't tied it into the main build process.


Here's a basic overview of the object model:

* ProviderFactory: used to create new Connections, DataAdapters, or Commands. All objects are returned using the provider interfaces such as IDbCommand.
* DataTools: static methods for doing common tasks like filling a DataSet with the contents of a select statement.
* ProviderCollection: list of providers configured in the system. Initially loaded from app.config, but can be modified at run-time.
* Provider: represents a given provider and holds information needed to create the types.
* ProviderSectionHandler: works behind the scenes to load the list of providers from the app.config into a ProviderCollection.

See /mcs/class/Mono.Data/app.config for sample configuration file.


Alrighty...now for some examples:

1) Using app.config to store your connection string:
<appSettings>
<add key="PubsConnStr" value="factory=System.Data.SqlClient; server=speedy;database=pubs;uid=sa;pwd=" />
</appSettings>

IDbConnection conn=ProviderFactory.CreateConnectionFromConfig("PubsConnStr");

The factory attribute specifies which provider to use. The factory attribute is parsed out, the object is created, and then the rest of the connection string is passed into the provider. The providers are defined in the app.config (or machine.config).


2) Creating a DataAdapter and filling a DataSet.

// Create Connection
IDbConnection conn =
ProviderFactory.CreateConnectionFromConfig("PubsConnStr");

// Select command
IDbCommand cmd=conn.CreateCommand();
cmd.Text="select * from author";

// Data Adapter
DataSet ds=new DataSet();
IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(cmd);
adapter.Fill(ds, "Table1");


3) Creating a DataAdapter and filling a DataSet. The super lazy method for people like me. :-)

// Create Connection
IDbConnection conn =
ProviderFactory.CreateConnectionFromConfig("TdsPubsConnStr");

// Data Adapter
DataSet ds=DataTools.FillDataSet(conn, "select * from author");


Well thats it for now. I'll be adding a number of common tasks into the DataTools class, so send me your favorite data routines.

I'd guess I should get some sleep...too bad I can't sleep and code at the same time...hmmm...

Later,
Brian




_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus


_______________________________________________
Mono-list maillist - [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to