artifact_id;status_id;status_name;priority;submitter_id;submitter_name;assigned_to_id;assigned_to_name;open_date;close_date;last_modified_date;summary;details;"Category";"Group";"Resolution"
1003336;1;"Open";3;100;"Nobody";100;"Nobody";"2007-04-20 13:46";"";"2012-09-24 02:14";"Partial support for Interval/TimeSpan type";"Append partial suuport for interval data type.
Support for 'years' and 'months' missing.";"None";"None";"None"
1003337;1;"Open";3;105382;"Waldemar Bergstreiser";100;"Nobody";"2007-04-20 14:15";"";"2012-09-24 02:14";"Partial support for TimeSpan/Interval data type";"Partial support for TimeSpan/Interval data type. 
interval with 'year' and 'month' values are not supported.";"None";"None";"None"
1008537;1;"Open";3;106914;"Frank Chow";100;"Nobody";"2007-08-29 18:51";"";"2012-09-24 02:14";"New resource files - zh-CN";"New resource files for supporting Chinese (Simplified)

regards.

Fang (Frank) Chow
";"None";"None";"None"
1010192;1;"Open";3;107576;"Tao Wang";100;"Nobody";"2007-11-19 11:15";"";"2012-09-24 02:14";"Update for Simplified Chinese translation.";"NpgsqlClosedState.zh-CN.resx
NpgsqlCommandBuilder.zh-CN.resx
NpgsqlConnectedState.zh-CN.resx
NpgsqlConnectionString.zh-CN.resx
NpgsqlException.zh-CN.resx
NpgsqlReadyState.zh-CN.resx
NpgsqlState.zh-CN.resx
NpgsqlTypesHelper.zh-CN.resx
PGUtil.zh-CN.resx
";"None";"None";"None"
1010193;1;"Open";3;107576;"Tao Wang";100;"Nobody";"2007-11-21 10:22";"";"2012-09-24 02:14";"NpgsqlConnectionString caching support patch";"This patch is adding caching ability to NpgsqlConnectionString class. It will improve the NpgsqlConnectionString.ParseConnectionString() function for recent parsed connection strings.

Following functions are added to NpgsqlConnectionString class:

private static NpgsqlConnectionString LookupCached(string CS);
private static void CacheCS(string CS, NpgsqlConnectionString obj);

And a public property for setting cache size are added:

public static int CacheSize{get; set;}

And NpgsqlConnection.ChangeDatabase() also be modified to avoid broken ChangeDatabase() function.

A test case, ChangeDatabaseTestConnectionCache(), is added to test calling ChangeDatabase() will never affect other connections which sharing same NpgsqlConnectionString object.

This patch is based on Npgsql2.0beta1 src.

";"None";"None";"None"
1010200;1;"Open";3;107576;"Tao Wang";100;"Nobody";"2007-11-28 19:08";"";"2012-09-24 02:14";"Using Resource file in NUnit20 test suite.";"Some test cases fail just because they use hardcoded string for message, however, the message are in resource file with locale sense. To make the test case pass, I create a patch to use resource file. 

The patch will affect 3 files:

BaseClassTests.cs
CommandTests.cs
ConnectionTests.cs

And 2 more resource file added:

BaseClassTests.resx
BaseClassTests.zh-CN.resx";"None";"None";"None"
1010204;1;"Open";3;107576;"Tao Wang";100;"Nobody";"2007-11-30 08:06";"";"2012-09-24 02:14";"Centralize the Resource file and Generate Strong-type class by ResGen.";"Centralize the resources files can esay tranlation job. Generate strong-type class for the resource file can easy any resource string reference in code. This patch do the job.

The package contains following files:

Resources.cs
    contains class Npgsql.Resources, which is generated by ResGen. 

Resources.resx
    contains all strings of current every .resx file (English).
Resources.*.resx (* are [cs,de,es,fi,ja,zh-CN])
    locale resource file. generate by copy Resources.resx first, and replace existing translated string.

Resources.patch
    The patch for affected files, which are:

NpgsqlParameter.cs
NpgsqlTransaction.cs
NpgsqlCommand.cs
NpgsqlParameterCollection.cs
NpgsqlCommandBuilder.cs
NpgsqlEventLog.cs
NpgsqlState.cs
NpgsqlConnection.cs
NpgsqlClosedState.cs
NpgsqlException.cs
PGUtil.cs

One thing should be notice is that, since no need for ResourceManager anymore, the NpgsqlEventLog.LogMsg(), previous is:
internal static void LogMsg(ResourceManager resman, string ResourceString, LogLevel msglevel, params Object[] Parameters)
new one is:
internal static void LogMsg(string message, LogLevel msglevel, params Object[] Parameters)

And a file 'NpgsqlConnectionStringBuilder.cs', this file is seperate with the patch, the reason is this file is current not existing in CVS, so I cannot generate a patch against CVS Head. So please merge it manually if needed.

After apply the patch, all existing *.resx in Npgsql,NpgsqlType are not necessary, can be removed.";"None";"None";"None"
1010229;1;"Open";3;107937;"Michael Parshin";100;"Nobody";"2008-01-09 08:26";"";"2012-09-24 02:14";"Changes in LargeObject";"This pathch will add truncate function to the LargeObject that is supported in PostgreSQL V 8.3 or prev with paches. 

In addition attached LargeObject.cs has changes all usages of Array.Copy to Buffer.BlockCopy

Seek function is now returns Int32 that is new position after the operation

Unfortunatly, I can attach only one file in this form, so another related change in LargeObjectManager.cs I am posting here. It has updated constructor wich selects fid for lo_truncate.

       /*
         * Constructs the LargeObject API.
         *
         * <p><b>Important Notice</b>
         * <br>This method should only be called by org.postgresql.Connection
         *
         * <p>There should only be one LargeObjectManager per Connection. The
         * org.postgresql.Connection class keeps track of the various extension API's
         * and it's advised you use those to gain access, and not going direct.
         */
        public LargeObjectManager(NpgsqlConnection conn)
        {
            // We need Fastpath to do anything
            // Now get the function oid's for the api
            //
            // This is an example of Fastpath.addFunctions();
            //
            String sql;
            if (conn.PostgreSqlVersion > new ServerVersion(7, 3, 0))
            {

                sql = ""SELECT p.proname,p.oid ""+
                      "" FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n ""+
                      "" WHERE p.pronamespace=n.oid AND n.nspname='pg_catalog' AND ("";
            }
            else
            {
                sql = ""SELECT proname,oid FROM pg_proc WHERE "";
            }
            sql += "" proname = 'lo_open'"" +
                   "" or proname = 'lo_close'"" +
                   "" or proname = 'lo_creat'"" +
                   "" or proname = 'lo_unlink'"" +
                   "" or proname = 'lo_lseek'"" +
                   "" or proname = 'lo_tell'"" +
                   "" or proname = 'lo_truncate'"" +
                   "" or proname = 'loread'"" +
                   "" or proname = 'lowrite'"";

            if (conn.PostgreSqlVersion > new ServerVersion(7, 3, 0))
            {
                sql += "")"";
            }

            IDbCommand cmd = new NpgsqlCommand(sql);
            cmd.Connection = conn;

            this.fp = new Fastpath(conn,conn.Connector.Stream);

            IDataReader res = cmd.ExecuteReader(CommandBehavior.CloseConnection);


            if (res == null)
                throw new NpgsqlException(""postgresql.lo.init"");


            fp.AddFunctions(res);
        }";"None";"None";"None"
1010274;1;"Open";3;107696;"Jon Hanna";100;"Nobody";"2008-02-10 17:16";"";"2012-09-24 02:14";"Experimental Patch of Doom!";"Okay, nobody try this on production code, there's still a lot of checking for me to do on things.

Still this should add:

CommandBehavior.SequentialAccess support.

As-needed loading of DataReader objects.

Correction of connections left in a corrupt state by earlier errors (particularly with regard to the Thread.Abort() issue reported by AS).

Testing notes:

1. The connection-correct currently only works of Protocol Version 3, trying this with Protocol Version 2 is likely to be a mess, even when there aren't any errors to correct for.

2. The change in DataReader access should hopefully improve performance for very large resultsets. Performance measurements should measure both the time to first successful Read() as well as the time to complete a full operation, since this is where the biggest gain should hopefully have been made, and it can be very important in some applications.

3. In the case reported by AS as well as there being issues with subsequent queries by the client in question, there were also orphaned postgres.exe processes. Therefore attempts to find errors it doesn't handle should look for such orphaned instances, as well as for correct recovery as seen on the client.";"None";"None";"None"
1010400;1;"Open";3;109168;"Cody Konior";100;"Nobody";"2008-05-27 02:36";"";"2012-09-24 02:14";"Proper NpgsqlException on connection errors";"The NpgsqlException class has some interesting properties like Code and Severity to help a client determine what it should do with the exception, but these aren’t set by the Open() subroutine.  I propose a small change to set these properties to the sqlclient_unable_to_establish_sqlconnection error defined at <http://postgresql.com.cn/docs/8.3/static/errcodes-appendix.html> when the open fails.  Or if you just like the idea you can implement it in some cleaner fashion.

NpgsqlClosedState.cs:
Line 29: 
 Using System.Collections.Generic;
Line 191, change the catch to:
 // Fake sqlclient_unable_to_establish_sqlconnection to give clients an opportunity
 // to do some automatic error handling.
 List<NpgsqlError> errors = new List<NpgsqlError>();
 errors.Add(new NpgsqlError(e.message, “FATAL”, “08001”));
 throw new NpgsqlException(errors);

NpgsqlError.cs
Line 278:
 // An optional constructor used to fake an error message.
 Internal NpgsqlError(String errorMessage, String severity, String code) 
 {
 _message = errorMessage;
 _severity = severity;
 _code = code;
 }

";"None";"None";"None"
1010423;1;"Open";3;109640;"Mathieu Cartoixa";100;"Nobody";"2008-07-01 18:36";"";"2012-09-24 02:14";"LargeObject inherits from Stream";"As discussed in the support request #1010225 (not sure this was the most appropriate place for this...), here is a patch that turns LargeObject into a proper Stream.

Notes :
 * the patch #1010229 was needed for this one and has been included (I hope I did not miss anything...).
 * the old interface (Tell, Size...) has been internalized.
 * this is largely untested.";"None";"None";"None"
1010434;1;"Open";3;101377;"Josh Cooley";100;"Nobody";"2008-07-18 12:44";"";"2012-09-24 02:14";"ThreadAbort hack patch";"Not for use in production.

This patch detects ThreadAbortException and closes the connection when aborted while communicating with the server.  This is for testing connection problems with aborted threads.";"None";"None";"None"
1010450;1;"Open";3;102254;"Christian Graefe";100;"Nobody";"2008-08-07 16:26";"";"2012-09-24 02:14";"Remove of unnecessary MD5 classes";"Hi,

Until digging through the code, i checked, if the MD5 classes are still needed for compatibility with mono.

Class documentation of mono:
http://www.go-mono.com/docs/monodoc.ashx?link=T%3aSystem.Security.Cryptography.MD5

In my point of view the following classes aren't necessary for Npgsql2:
MD5, MD5CryptoServiceProvider and HashAlgorithm

If I'm right, we could apply this patch and remove the unnecessary classes.



best regards
Christian Gräfe";"None";"None";"None"
1010539;1;"Open";3;103935;"Rikard Pavelic";100;"Nobody";"2008-12-24 23:12";"";"2012-09-24 02:14";"checking for function info";"I noticed that in CheckFunctionHasOutParameters() and CheckFunctionReturn(string) Npgsql creates command in which it incorrectly sets function name.

If I define function as com.CommandText = ""public.my_function(@id)""

Npgsql will fill function name as ""my_function(@id)"" instead of ""my_function"".

This lines should be added after calculating procedureName

int indx = procedureName.IndexOf('(');
if (indx > 1) procedureName = procedureName.Substring(0, indx).Trim();

Also, are this calls really necesarry? They don't seem to be and they cause three roundtrips.";"None";"None";"None"
1010595;1;"Open";3;103935;"Rikard Pavelic";100;"Nobody";"2009-04-13 20:48";"";"2012-09-24 02:14";"Array handling exception";"In ArrayHandling.cs
Function WriteItem(NpgsqlNativeTypeInfo TypeInfo, object item, StringBuilder sb)
should start with 
            if (item == null)
            {
                sb.Append(""NULL"");
                return true;
            }
            else 

or exception will be thrown if object like

List<int?> x=new List<int?>();
x.add(1);
x.add(null);

is sent as parameter.";"None";"None";"None"
1010683;1;"Open";3;110661;"Yann ROBIN";100;"Nobody";"2009-08-07 18:47";"";"2012-09-24 02:14";"Bug while parsing parameter";"Hi,

I found a bug in npgsql, it's a small one as it won't affect everyone but I think it should really be fixed.

This bug occurs when you send a querystring that use both parameter and raw sql, like :
INSERT INTO ""D"" (""Type"", ""Id"", ""d"" ) VALUES ('Test:D' ,  @EntityId ,  @d  ) 

In the GetClearCommandText there is a Split on "":"" and ""@"", that split the command here 'Test:D' and then try to replace :D with the parameter.

So i've created a patch that iterate over the parameters instead of splitting the querystring and replace the parameterName in the string (using a regexp) with the needed informations.

I don't think this is very efficient (and it removes the previons performance patch that was applied) but it works.";"None";"None";"None"
1010703;1;"Open";3;108596;"Bence Galat";100;"Nobody";"2009-09-11 11:16";"";"2012-09-24 02:14";"RSA private key load to use SSL client authentication";"It seems, private key can not be extracted from client certificate, so it throws 
a IOException says 'The authentication or decryption has failed.'

The class I have made (PrivateKeySetup)can load the privata key parameters from an unenrypted RSA pem key file and setups a RSA that can decrypt the stream.

Just add the PrivateKeySelectionCallback delegate to your connection instance 
and use the PrivateKeySetup.PrivateKeyLoad(filepath) method to setup an RSA instance. 

Bence Galat";"None";"None";"None"
1010715;1;"Open";3;108875;"Gildas ";100;"Nobody";"2009-10-08 23:07";"";"2012-09-24 02:14";"NpgsqlParameterCollection.Add and System.Data.DbType management";"Concerning bug [#1010714] using 'DbType.Binary' instead of 'NpgsqlTypes.NpgsqlDbType.Bytea' for updating bytea column fails, i hesitate between two solutions in order to correct the bug (i have reproduced it).

First of all the bug comes because the user (alemarko) uses this :
> cmd.Parameters.Add(""bytesData"", System.Data.DbType.Binary).Value = bytes;

instead of decomposing like :
> NpgsqlParameter param = new NpgsqlParameter("":bytesData"", DbType.Binary);
> param.Value = bytes;

So in this case the NpgsqlParameter constructor used is the NpgsqlParameter(String parameterName, object value) instead of this one NpgsqlParameter(String parameterName, DbType parameterType).

So the GetNativeTypeInfo will try to get the type of (DbType.Binary).GetType() That retuns DbType and not Binary and it's not known... :)

So three solutions are possible :
1 - User has to decompose your parameter additions  :)
2 - Add a new Add function in the NpgsqlParameterCollection that takes a DbType instead of an object NpgsqlParameter Add(string parameterName, DbType value), so the correct NpgsqlParameter constructor will be called
3 - Add a test in the NpgsqlParameter(String parameterName, object value) constructor to test if the value (object) is a DbType, if it does use TryGetNativeTypeInfo(DbType dbType, out NpgsqlNativeTypeInfo typeInfo) by casting value, instead of use TryGetNativeTypeInfo(Type type, out NpgsqlNativeTypeInfo typeInfo)

The two patchs, for the two methods (2 and 3) are in the attached zip file";"None";"None";"None"
1010777;1;"Open";3;130136;"Noah Misch";100;"Nobody";"2010-03-15 15:48";"";"2012-09-24 02:14";"String syntax for function call parameters";"This code:

  cmd = new NpgsqlCommand(""length"", conn);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add(new NpgsqlParameter());
  cmd.Parameters[0].NpgsqlDbType = NpgsqlDbType.Varchar;
  cmd.Parameters[0].Value = ""fo\\o"";

produces this SQL statement:

  select * from length(('fo\\o')::varchar)

The string has an extra backslash under standard_conforming_strings=on, while standard_conforming_strings=off && escape_string_warning=on produces a warning.  This patch reuses the logic from the non-function-call case to make the behavior consistent.  I include a new test case based on the one it follows.

Thanks,
nm
";"None";"None";"None"
1010779;1;"Open";3;130136;"Noah Misch";100;"Nobody";"2010-03-16 07:02";"";"2012-09-24 02:14";"Respect CommandTimeout in first function call w/ string parameter";"When a connection to a server with ""standard_conforming_strings = off"" first executes a command with a string parameter, we run ""SHOW escape_string_warning""
internally.  That internal command clobbers the user's CommandTimeout for the
execution of the main command.  The effective CommandTimeout was 20 until NpgsqlCommand.cs revision 1.46 (2010-02-16), and lately 0 (unlimited).  This
patch adds a CommandTimeout/SqlSent reset to NpgsqlCommand.GetCommandText, the
last NpgsqlCommand entry before we use the timeout value in ProcessBackendResponsesEnum.  I have removed similar, existing resets in
GetCommandText callees.  This is a bit of a hack; the right fix seemed to be to
push CommandTimeout through the call stack instead of through the mediator, but
that wasn't readily satisfying either.  Thoughts?  I've also added test cases.

Related discussion:
http://pgfoundry.org/forum/forum.php?thread_id=2514&forum_id=519

Thanks,
nm
";"None";"None";"None"
1010826;1;"Open";3;108359;"Matthew Gabeler-Lee";100;"Nobody";"2010-05-20 16:21";"";"2012-09-24 02:14";"Thread safety fix for PGUtil";"(see http://pgfoundry.org/forum/message.php?msg_id=1006084 )

PGUtil has a thread safety problem introduced in CVS revision 1.13 (Knuth: ""Premature optimization is the root of all evil"").  The optimization introduced in that revision effectively means that Npgsql can only be used by one thread at a time, even with separate connections.

Attached is a patch that makes the buffers thread local to keep most of the optimization and remove the thread safety issue.";"None";"None";"None"
1010978;1;"Open";3;218956;"Randon Spackman";100;"Nobody";"2011-01-24 20:12";"";"2012-09-24 02:14";"ClearAllPools leaking connections";"The behavior of NpgsqlConnection's ClearAllPools is slightly different that OracleConnection's and SQLConnection's.  SQLConnection's docs specify that connections in use at the time of ClearAllPools will be closed as soon as the connection is closed.  (See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.clearallpools.aspx)  Instead, any connections in use will have one of two behaviors:

1) If no new connection queue is established between the ClearAllPools call and the Connection.Close, the connection will be lost until garbage collection.

2) If a new connection queue is established between the calls, the connection is returned to that queue.

The following code will demonstrate the problems:

namespace DALTest
{
	class DALTestClass
	{
		static void Test1()
		{
			// Problem: A connection in use at the time of ClearAllPools is never released from Postgres (SELECT * FROM pg_stat_activity;)
			var Conn = new Npgsql.NpgsqlConnection(""Database=test;User Id=test;Password=test;Server=localhost;Port=5432"");
			Conn.Open();
			Npgsql.NpgsqlConnection.ClearAllPools();
			Conn.Dispose();
			Npgsql.NpgsqlConnection.ClearAllPools(); // Fails to remove existing connection; it is not in pool and is leaked
		}

		static void Test2()
		{
			// Problem: A connection in use at the time of ClearAllPools is re-added to the pool
			var Conn = new Npgsql.NpgsqlConnection(""Database=test;User Id=test;Password=test;Server=localhost;Port=5432"");
			Conn.Open();
			Npgsql.NpgsqlConnection.ClearAllPools();

			var Conn2 = new Npgsql.NpgsqlConnection(""Database=test;User Id=test;Password=test;Server=localhost;Port=5432"");
			Conn2.Open();
			Conn2.Dispose();

			Conn.Dispose(); // Adds connection back to pool
			Npgsql.NpgsqlConnection.ClearAllPools(); // Releases both connections
		}

		static int Main()
		{
			Test1();
			Test2();
			return 0;
		}
	}
}
";"None";"None";"None"
1011008;1;"Open";3;108875;"Gildas ";100;"Nobody";"2011-03-29 08:57";"";"2012-09-24 02:14";"Add PhysicalAddress (MAC Address) support to Npgsql";"Hi, here is the patch in order to add the MAC Address support to Npgsql

See http://pgfoundry.org/forum/forum.php?thread_id=10309&forum_id=518 for the first discussion about it.";"None";"None";"None"
1011011;1;"Open";3;100095;"Stanislaw Tristan";100;"Nobody";"2011-04-03 14:09";"";"2012-09-24 02:14";"citext support";"this patch provides citext datatype support";"None";"None";"None"
1011012;1;"Open";3;248390;"Hans Peter";100;"Nobody";"2011-04-04 16:28";"";"2012-09-24 02:14";"Australian Date and Time Formats";"Npgsql does not support the australian date and time format. The following small patch should resolve this issue.

The lines in question can be found in NpgsqlTypes.cs  (the code lines starting with ‘+’ must be added) 

@ line 52:
                                                                         
""HH:mm:ss.ffffff"", ""HH:mm:ss"", ""HH:mm:ss.ffffffzz"", ""HH:mm:sszz"", ""HH:mm:ss.fffff"", ""HH:mm:ss.ffff"", ""HH:mm:ss.fff"", ""HH:mm:ss.ff"",
""HH:mm:ss.f"", ""HH:mm:ss.fffffzz"", ""HH:mm:ss.ffffzz"", ""HH:mm:ss.fffzz"", ""HH:mm:ss.ffzz"", ""HH:mm:ss.fzz"",

+ ""HH:mm:ss.fffffzzz"", ""HH:mm:ss.ffffzzz"", ""HH:mm:ss.fffzzz"", ""HH:mm:ss.ffzzz"",
+ ""HH:mm:ss.fzzz"", ""HH:mm:sszzz""

@ line 61:
                                                                    
""yyyy-MM-dd HH:mm:ss.fffff"", ""yyyy-MM-dd HH:mm:ss.ffff"", ""yyyy-MM-dd HH:mm:ss.fff"", ""yyyy-MM-dd HH:mm:ss.ff"",
""yyyy-MM-dd HH:mm:ss.f"", ""yyyy-MM-dd HH:mm:ss.fffffzz"", ""yyyy-MM-dd HH:mm:ss.ffffzz"", ""yyyy-MM-dd HH:mm:ss.fffzz"",
""yyyy-MM-dd HH:mm:ss.ffzz"", ""yyyy-MM-dd HH:mm:ss.fzz"",

+ ""yyyy-MM-dd HH:mm:ss.fffffzzz"", ""yyyy-MM-dd HH:mm:ss.ffffzzz"", ""yyyy-MM-dd HH:mm:ss.fffzzz"",
+ ""yyyy-MM-dd HH:mm:ss.ffzzz"", ""yyyy-MM-dd HH:mm:ss.fzzz"", ""yyyy-MM-dd HH:mm:sszzz""
";"None";"None";"None"
1011013;1;"Open";3;248390;"Hans Peter";100;"Nobody";"2011-04-11 17:03";"";"2012-09-24 02:14";"Bug when NpgslTimeStamp '1001.01.01 00:00:00' is converted from UTC to local Time Zone";"for example when 

local time = UTC - 1

then

TimeStamp.Date.DaysSinceEra = -1

then (for example when trying to cast to DateTime via explicit operator)

-> runtime error.";"None";"None";"None"
1011019;1;"Open";3;230018;"Yaroslav Potapov";100;"Nobody";"2011-04-24 01:08";"";"2012-09-24 02:14";"Composite type support";"Composite type support 

Example:

CREATE TYPE ct AS 
(
    i smallint,
    t character varying,
    b bytea,
    p inet,
    d time with time zone
);

CREATE TABLE tt
(
    id integer NOT NULL,
    ""ctype"" ct,
    arrctype ct[],
    CONSTRAINT pki PRIMARY KEY (id)
)
WITH ( OIDS=FALSE);

INSERT INTO tt (id, ctype, arrctype, ba, iarr, arr)
VALUES
 (1, '(11,text,bbb,127.0.0.1,00:19:18.748265+03)', '{""(11,text,bbb,,00:19:18.748265+03)"",""(11,text,bbb,127.0.0.1,00:19:18.748265+03)""}'),
 (2, '(11,text,bbb,127.0.0.1,00:19:18.748265+03)', '{""(11,text,bbb,,00:19:18.748265+03)"",""(11,text,bbb,127.0.0.1,00:19:18.748265+03)""}');


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NpgsqlTypes;
using System.Net;
using Npgsql;

namespace TestProject1
{
    [TestClass]
    public class CompositeTest
    {
        /// <summary>
        /// Composite test. 
        /// Metood first writes the data into a database, then reads and compares them.
        /// Shows compatibility with arrays.
        /// </summary>
        [TestMethod()]
        public void CompositeTest()
        {
            // Init composite description
            CompositeDescription description = new CompositeDescription(""ct"",
                new ColumnDescription(""i"", NpgsqlDbType.Smallint),
                new ColumnDescription(""t"", NpgsqlDbType.Varchar),
                new ColumnDescription(""b"", NpgsqlDbType.Bytea),
                new ColumnDescription(""p"", NpgsqlDbType.Inet),
                new ColumnDescription(""d"", NpgsqlDbType.TimeTZ));

            // First way to get composite
            Composite composite = new Composite(description);
            // set values
            composite[0] = 11;
            composite[1] = ""k02\\2jj\"",'jj"";
            composite[""b""] = new byte[] { 0, 11, 22, 33, 44, 55, 66, 77 }; // it the same that composite[2] =...
            composite[3] = IPAddress.Parse(""88.45.88.44"");
            composite[4] = DateTime.Now;

            // Gets array
            Composite[] cmpArr = new Composite[2];
            cmpArr[0] = composite;

            // Second way to get composite
            cmpArr[1] = new Composite(description, 11, ""some text"", new byte[1], null, DateTime.Now);

            NpgsqlCommand cmd = new NpgsqlCommand(""UPDATE tt SET ctype = @cty, arrctype = @ctyarr WHERE id = 2"");

            cmd.Parameters.AddWithValue(""@cty"", composite);
            cmd.Parameters.AddWithValue(""@ctyarr"", cmpArr);

            cmd.Connection = new NpgsqlConnection();
            cmd.Connection.Open();

            int i = cmd.ExecuteNonQuery();
            if (i < 1) Assert.Fail(""don't update"");

            cmd.CommandText = ""SELECT ctype, arrctype FROM tt WHERE id = 2"";
            cmd.CommandType = System.Data.CommandType.Text;
            using (NpgsqlDataReader rdr = cmd.ExecuteReader())
            {
                if (rdr.Read())
                {
                    //gets composite
                    Composite c = rdr.GetComposite(0);

                    //gets composite[]
                    object obj = rdr.GetValue(1);
                    //gets first element 
                    Composite cmp1 = (Composite)((object[])obj)[0];

                    // send and recived data must be equaled
                    Assert.IsTrue(
                        (string)composite[""t""] == (string)c[""t""] &&
                        (string)composite[""t""] == (string)cmp1[""t""]);
                }
            }
        }
    }
}";"None";"None";"None"
1011157;1;"Open";3;439502;"Mirko Geffken";100;"Nobody";"2012-02-02 05:36";"";"2012-09-24 02:14";"Fix (I think) for incorrect handling of timestamptz to DateTimeOffset mapping in Entity Framework Code First";"Method GetStoreType in NpgsqlProviderManifest currently handles both DateTime and DateTimeOffset types and attempts to map timestamp to DateTime and timestamptz to DateTimeOffset. The implementation for DateTime is correct, but for DateTimeOffset that is not the case in my opinion. The framework has both a CreateDateTimeTypeUsage as well as a CreateDateTimeOffsetTypeUsage function on the TypeUsage class and the incorrect one is called for DateTimeOffset.

Please find as attached file a new copy of NpgsqlProviderManifest.cs with the call corrected (based on currently latest source of 2.0.11.92).

Please note that I did not do a lot of testing on this change. It seems to resolve my immediate issue, but I cannot guarantee that it doesn't cause others. 

Please note that without this change mappings such as this example:
[Table(""Vendor"", Schema = ""Foo"")]
public class Vendor
{
	[Key]
	public int ID { get; set; }
	public string Name { get; set; }
	[Column(""JoinedOn"")]
	public DateTimeOffset JoinedOn { get; set; }
}

failed with something like this:
The PrimitiveType is not a DateTime type.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: The PrimitiveType is not a DateTime type.

Source Error: 


Line 230:                    else
Line 231:                    {
Line 232:                        return TypeUsage.CreateDateTimeTypeUsage(StoreTypeNameToStorePrimitiveType[""timestamptz""], null);
Line 233:                    }
Line 234:                case PrimitiveTypeKind.Time:

Source File: C:\Users\Mirko\Downloads\Npgsql2.0.11.92.src\Npgsql2.0.11.92.src\src\Npgsql\NpgsqlProviderManifest.cs    Line: 232 

Stack Trace: 


[ArgumentException: The PrimitiveType is not a DateTime type.]
   System.Data.Metadata.Edm.TypeUsage.CreateDateTimeTypeUsage(PrimitiveType primitiveType, Nullable`1 precision) +7071757
   Npgsql.NpgsqlProviderManifest.GetStoreType(TypeUsage edmType) in C:\Users\Mirko\Downloads\Npgsql2.0.11.92.src\Npgsql2.0.11.92.src\src\Npgsql\NpgsqlProviderManifest.cs:232
   System.Data.Entity.ModelConfiguration.Edm.Services.StructuralTypeMappingGenerator.MapTableColumn(EdmProperty property, DbTableColumnMetadata tableColumnMetadata, Boolean isInstancePropertyOnDerivedType, Boolean isKeyProperty) +62
   System.Data.Entity.ModelConfiguration.Edm.Services.PropertyMappingGenerator.Generate(EdmEntityType entityType, IEnumerable`1 properties, DbEntitySetMapping entitySetMapping, DbEntityTypeMappingFragment entityTypeMappingFragment, IList`1 propertyPath, Boolean createNewColumn) +1282
   System.Data.Entity.ModelConfiguration.Edm.Services.EntityTypeMappingGenerator.Generate(EdmEntityType entityType, DbDatabaseMapping databaseMapping) +493
   System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateEntityTypes(EdmModel model, DbDatabaseMapping databaseMapping) +117
   System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel model) +30
   System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +189
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +164
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +111
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +416
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
   System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
   System.Linq.Queryable.First(IQueryable`1 source) +50
   PostgreSQLTest.Controllers.HomeController.Index() in C:\Users\Mirko\Documents\Projects\uurge\trunk\code\postgresqltest\code\PostgreSQLTest\Controllers\HomeController.cs:12
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +326
   System.Web.Mvc.Controller.ExecuteCore() +109
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +13
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +10303829
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +178
";"None";"None";"None"
1011166;1;"Open";3;108359;"Matthew Gabeler-Lee";100;"Nobody";"2012-02-23 00:28";"";"2012-09-24 02:14";"Missing null check in NpgsqlDataReader";"I ran into a NullReferenceException in Npgsql and tracked it down to a missing null check in NpgsqlDataReader.  Tiny patch fixing this is attached.";"None";"None";"None"
1011175;1;"Open";3;451232;"Roman Starkov";100;"Nobody";"2012-03-21 14:44";"";"2012-09-24 02:14";"Files with \r\r\n line endings";"The current release (93) has two files with broken line endings: src/Npgsql/Cache.cs and src/NpgsqlTypes/DateDatatypes.cs";"None";"None";"None"
1011176;1;"Open";3;451232;"Roman Starkov";100;"Nobody";"2012-03-21 14:48";"";"2012-09-24 02:14";"Null reference exception fix in VisitedExpression.GetProjectedColumns";"Diff available here: https://bitbucket.org/Aldaray/npgsql-tweaks/changeset/3c1c92cbb0fe";"None";"None";"None"
1011177;1;"Open";3;451232;"Roman Starkov";100;"Nobody";"2012-03-21 14:53";"";"2012-09-24 02:14";"Fixed a number of warnings";"Most of these are warnings about the XML documentation. Some are about unused declarations.";"None";"None";"None"
1011188;1;"Open";3;451232;"Roman Starkov";100;"Nobody";"2012-04-25 15:39";"";"2012-09-24 02:14";"Fix for incorrect use of TimeSpan parameters in named arguments";"Postgres allows expressions like this:

  now() + E'15 days'

but not like this:

  now() - E'15 days'

The latter results in the error ""invalid input syntax for type timestamp with time zone"".

The correct syntax is to either include the ""INTERVAL"" keyword before the string, or use the cast syntax:

  now() - E'15 days'::interval

Since the parameter class already has support for inserting a cast, this patch makes use of that.

String objects are excluded from this logic for compatibility reasons: the current Npgsql allows one to use strings in place of, say, BIGINT parameters. An explicit cast to TEXT would break queries that rely on that.";"None";"None";"None"
1011231;1;"Open";3;474693;"Chris Webb";100;"Nobody";"2012-09-18 04:35";"";"2012-09-24 02:14";"Added using statements to NpgsqlConnector and NpgsqlTransaction classes.";"Some npgsqlcommand objects were being created in these files without being disposed.  Added the using statements to these files as required.

Files attached.";"None";"None";"None"
1011241;1;"Open";3;475664;"chen huajun";100;"Nobody";"2012-10-08 11:56";"";"2012-10-23 13:13";"Release connection into pool with ""Discard All""";"Now, Npgsql execute the following SQL statments to reset the status of a NpgsqlConnecor when put it into ConnectorPool.
-unlisten *
-deallocate $planName

But only execute the two SQL statments is not enough to clear the status of a connection. The ""Discard All"" which support from PostgreSQL 8.3 is better.

http://www.postgresql.org/docs/8.3/static/sql-discard.html";"None";"None";"None"
1011288;1;"Open";3;485307;"Richard Meyer";100;"Nobody";"2012-12-05 06:09";"";"2012-12-05 06:09";"Patch for bug #1011287";"In working on a custom data access layer with a colleague, we discovered an issue where the column ordinal values are
incremented by 1 when going from the DataReader to the DataTable objects.

Lines 515 and 607 of Ngpgsql.NpgsqlDataReader are the culprits in version 2.0.12.

Per the MSDN specifications, ColumnOrdinal is a zero-based index:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getschematable.aspx

Attached is a patched version of NgpgsqlDataReader.cs that removes the + 1.";"None";"None";"None"
1011305;1;"Open";3;3055;"Francisco Figueiredo jr. ";100;"Nobody";"2013-02-14 11:34";"";"2013-02-14 11:34";"Scope without prepared transactions";"
Transcript of bug report and patch on github: https://github.com/franciscojunior/Npgsql2/pull/8

Hey Francisco and Josh, sorry for disappearing, had some busy times at work.

Here's an attempt at a patch which would remove the dependency on prepared transactions when a connection is closed within a TransactionScope. I added a unit test which reproduced the problem on stock Postgres installations: SystemTransactionTests.SimpleTransactionScopeWithImplicitEnlist.

My general approach was to check whether a local (non-prepared) transaction is still active in the NpgsqlPromotableSinglePhaseNotification when Close() is called. If so, we enter the ""postponingClose"" state instead of actually closing. Then, when the local transaction is terminated (because of a commit, rollback or promote) the connection is notified and does the real close. There are a few more tweaks (Dispose and reopen after close) but it should be pretty straightforward.

Note that this takes care of the pattern:
using (var conn1 = new NpgsqlConnection(...) {
conn1.Open(); conn1.Close();
conn1.Open(); conn1.Close();
}

But does not take care of the pattern:
using (var conn1 = new NpgsqlConnection(connString1) { ... }
using (var conn2 = new NpgsqlConnection(connString1) { ... }
As Josh suggested, since I think that would require handling stuff at the pool. Maybe a second commit?

Anyway, let me know what you think...

Note that there are also two tiny build cleanup commits before the real one...
";"None";"None";"None"
1011311;1;"Open";3;491376;"Evan Martin";100;"Nobody";"2013-02-21 14:48";"";"2013-02-21 14:48";"Patch for bug #1011310: Command timeouts after the first are not handled";"This patch removes NpgsqlConnector.CancelRequestCalled, added for bug #1010986, and replaces it with a parameter to the ProcessBackendResponsesEnum() method. This way there is no limit to the number of timeouts a single Connection instance can handle, but the original problem in #1010986 (Endless recursion on hanging connection in ProcessBackendResponsesEnum) should still be solved as well.";"None";"None";"Accepted"
1011315;1;"Open";3;225559;"Damian W";100;"Nobody";"2013-03-06 23:39";"";"2013-03-06 23:39";"Retrieving ID with RETURNING instead of querying the sequence";"Hi,

right now when using INSERT to put a new record into the database you do the following:

INSERT INTO ""schema"".""table"" (...) VALUES (...);SELECT currval(pg_get_serial_sequence('""schema"".""table""', 'id')) AS ""id"";

That is totally slow and not recommend by PostgreSQL.

The prefereable way is:

INSERT INTO ""schema"".""table"" (...) VALUES (...) RETURNING id AS ""id"";

This also helps when the ID column uses some kind of computed values instead of a sequence. Currently using something else then a sequence is not possible.

Please add support for RETURNING statement, thank you!
";"None";"None";"None"
1011316;1;"Open";3;492008;"Tasos Mamaloukos";100;"Nobody";"2013-03-07 11:14";"";"2013-03-07 11:14";"ConnectionTimeout fix, bypass the 2147 seconds limit of Socket.Poll method";"Fix on issue:

- [#1011136] CommandTimeout has a surprising maximum value, and overflows

Also another issue that may be affected by this fix:

- [#1011302] Setting CommandTimeout too high gets silently ignored";"None";"None";"Accepted"
1011325;1;"Open";3;3055;"Francisco Figueiredo jr. ";100;"Nobody";"2013-03-31 16:31";"";"2013-03-31 16:31";"Escaped strings don't work with EF";"When using Npgsql with EF, strings with escape sequences like '\t\r' don't work because they are sent without the proper escape syntax: E'\t\r'. This gives problems like this one: 
http://pgfoundry.org/forum/forum.php?thread_id=15533&forum_id=518&group_id=1000140";"None";"None";"None"