PDA

View Full Version : PostgreSQL Ado support


wimpleshapers
06-19-2007, 10:29 PM
Using the latest Npgsql Ado driver, I get an exception when performing a query. The error occurs when the function:

AdoTemplate.Execute<T>(ICommandCallback<T> action)

invokes

T result = action.DoInCommand((DbCommand)command);

The error says the cast to 'DbCommand' is illegal. This makes sense, since the Npgsql driver's implementation of the command object simply implements IDbCommand, and does not extend DbCommand. I was able to correct the problem by changing methods in QueryCallback<T> and ICommandCallback<T> accept IDbCommand instead.

Is this the corrrect action to take, or is the Npgsql library expected to implement DbCommand instead.

Thanks.

Bruno Baia
06-20-2007, 03:15 PM
Hi,

This is an known issue :
Spring.Data sometimes uses DbCommand instead of IDbCommand (http://opensource.atlassian.com/projects/spring/browse/SPRNET-552)


Bruno

Mark Pollack
06-20-2007, 04:31 PM
Hi,
Yea, we have to provide a signature that has just IDbCommand instead of DbCommand. I'd like to find a way to support both without having to duplicate lots of code, as it is much more convenient to use the parameter class obtained from DbCommand than IDbCommand...
Mark

Mark Pollack
06-27-2007, 10:22 PM
Hi,
I have added a new interface and delegate for those providers that do not inherit from the DbCommand base class. They are the interface
public interface IDbCommandCallback<T>
{
T DoInCommand(IDbCommand command);
}
and the delegate
public delegate T IDbCommandDelegate<T>(IDbCommand command);
A few internal classes were using the versions based on DbCommand and those were retro-fitted to use the new version. I still need to go back and clean things up a bit, buy you should be fine for now. It was wrong to assume all .NET 2.0 providers would inherit from the base class, not sure how I got that in my head. Anyway, try it out.

Cheers,
Mark