[Mono-list] Which postgres client library?

Stuart Ballard stuart.ballard@corp.fast.net
Thu, 08 May 2003 13:16:42 -0400

yoros@wanadoo.es wrote:
> The best docs you have are the ChangeLog files and the source code of
> each provider. I've never used query parameters. I don't know how can I=

> use them (I never liked it), =BFcan you send an example, please?
> I think that the CVS of Npgsql is Mono sice a few months.

Off the top of my head:

string sql =3D "select * from table where name =3D :name";
string testValue =3D "TestValue";
NpgsqlConnection conn =3D new NpgsqlConnection(connStr);
NpgsqlCommand cmd =3D new NpgsqlCommand(sql, conn);
NpgsqlParameter param =3D new NpgsqlParameter();
param.ParameterName =3D "name";
param.DbType =3D DbType.String;
param.Size =3D testValue.Length;
param.Value =3D testValue;
NpgsqlDataReader dr =3D cmd.ExecuteReader();

You can reduce your lines-of-code count by passing the name, type and=20
size to the constructor of NpgsqlParameter but I forget what the exact=20
order of arguments is. Or you can do what I do, which is write a=20
function to create a parameter with a particular name, type, size and=20
value so it all happens in one line.

The benefit of this is supposedly that it's type-safe and you don't need =

to worry about quoting your parameter values, and the DB provider can=20
optimise it by only sending the query once and sending different sets of =

parameters for the query. It looks like the Npgsql provider isn't=20
implementing it correctly, though.

Does anyone know if there are any plans to update Mono's Npgsql to their =

latest CVS?


Stuart Ballard, Senior Web Developer
FASTNET - Web Solutions
(215) 283-2300, ext. 126