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!
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!
Comments
One thing worth adding is that since .NET2.0 has several different types of typed collection as well as arrays these can be used too:
Anything that implements IEnumerable<T> where T is a type already supported by npgsql will be treated the same as T[], anything that implements IEnumerable<U> where U implements IEnumerable<T> will be treated the same as T[,] (but cause an error if it's a "jagged" array, as postgres doesn't support them) and so on.
So, List<int> will be treated as a Postgres int4[], ICollection<List<string>> as a two-dimensional text[] and so on.
However, we look for direct support first, so string is still treated as string rather than as IEnumerable<char>, unless you explicitly ask for that.
Michael Parshin did a good job at catching a couple of edge cases in my previous attempt here.