Thursday, January 31, 2008

Array support in the works!

Hi all,

Jon Hanna is working to add Array support to Npgsql. He already sent a patch which I applied to my working copy and it is working very well!

Now it is possible to write code like that:

NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User id=npgsql_tests;password=npgsql_tests;");

conn.Open();


NpgsqlCommand d = new NpgsqlCommand();

Int32[] a = new Int32[2];

a[0] = 4;
a[1] = 2;

NpgsqlCommand command = new NpgsqlCommand("select :arrayParam", conn);

command.Parameters.Add(new NpgsqlParameter("arrayParam", a));
Console.WriteLine(command.ExecuteScalar());

conn.Close();

And get this logged on server:

LOG: statement: select array['4','2']::int4[]

Also, Npgsql is able to receive an array from server as the example above shows. Npgsql will print to console:

System.Int32[]

Which shows it received an int32 array as expected!

Excellent work, Jon!

Wednesday, January 30, 2008

Parameters explicit typing support commited in cvs

Hi all!

Today I commited a patch (here, here, and here) to allow parameters explicit typing on plain queries.

What this means? This means that all parameters are sent to backend carrying its explicit type as specified by DbType and/or NpgsqlDbType enums. This will allow better typing matching between client and server. See here for Jon Hanna discussion about it. This explict typing isn't completely new. It was already being applied to function calling. We just decided to apply it to plain queries too.

Now queries are sent this way:

select * from tablea where field_serial = '4'::int4

where they were being sent as:

select * from tablea where field_serial = 4

This modification may lead to problems, as said in discussion above (end of first post), but we hope this can be easily fixed. Please, send your comments about it.

Please, grab a cvs copy of it and give it a try. We soon will be doing a new beta release which will contain this code.

Thanks Jon Hanna, Agrinei and Josh Cooley for discussion about this feature.