public void PqsqlCopyToTest6() { const int len = 8; // the highest representable System.DateTime tick in postgres is 9 less than // System.DateTime.MaxValue.Ticks, because the resolution in postgres is to the millisecond whereas // System.DateTime's resolution is to 100 nanoseconds. This means the last 900 nanoseconds before the year // 10000 cannot be represented in postgres' timestamp. var postgresDateTimeMaxValueTicks = DateTime.MaxValue.Ticks - 9; PqsqlTransaction tran = mConnection.BeginTransaction(); mCmd.Transaction = tran; mCmd.CommandText = "create temporary table foo (a timestamp, b timestamptz); " + "insert into foo values (null, null); " + "insert into foo values ('0001-01-01 00:00:00.000000 UTC', '0001-01-01 00:00:00.000000 UTC'); " + "insert into foo values ('1970-01-01 00:00:00.000000 UTC', '1970-01-01 00:00:00.000000 UTC'); " + "insert into foo values ('9999-12-31 23:59:59.999999 UTC', '9999-12-31 23:59:59.999999 UTC'); " + "insert into foo values ('31 December, 1 BC 23:59:59.999999', '31 December, 1 BC 23:59:59.999999'); " + "insert into foo values ('10000-01-01 00:00:00.000000 UTC', '10000-01-01 00:00:00.000000 UTC'); " + "insert into foo values ('-infinity', '-infinity'); " + "insert into foo values ('infinity', 'infinity'); "; mCmd.CommandType = CommandType.Text; int affected = mCmd.ExecuteNonQuery(); Assert.AreEqual(len, affected); var copy = new PqsqlCopyTo(mConnection) { Table = "foo", ColumnList = "a,b", CopyTimeout = 10, }; copy.Start(); var res = copy.FetchRow(); Assert.IsTrue(res); var a0 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, a0); var b0 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, b0); res = copy.FetchRow(); Assert.IsTrue(res); var a1 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, a1); var b1 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, b1); res = copy.FetchRow(); Assert.IsTrue(res); var a2 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.UnixEpoch, a2); var b2 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.UnixEpoch, b2); res = copy.FetchRow(); Assert.IsTrue(res); var a3 = copy.ReadTimestamp(); Assert.AreEqual(new DateTime(postgresDateTimeMaxValueTicks), a3); var b3 = copy.ReadTimestamp(); Assert.AreEqual(new DateTime(postgresDateTimeMaxValueTicks), b3); res = copy.FetchRow(); Assert.IsTrue(res); try { // a4 '31 December, 1 BC 23:59:59.999999' copy.ReadTimestamp(); Assert.Fail(); } catch (ArgumentOutOfRangeException) {} try { // b4 '31 December, 1 BC 23:59:59.999999' copy.ReadTimestamp(); Assert.Fail(); } catch (ArgumentOutOfRangeException) {} res = copy.FetchRow(); Assert.IsTrue(res); try { // a5 '10000-01-01 00:00:00.000000 UTC' copy.ReadTimestamp(); Assert.Fail(); } catch (ArgumentOutOfRangeException) {} try { // b5 '10000-01-01 00:00:00.000000 UTC' copy.ReadTimestamp(); Assert.Fail(); } catch (ArgumentOutOfRangeException) {} res = copy.FetchRow(); Assert.IsTrue(res); // a6 '-infinity' var a6 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, a6); // b6 '-infinity' var b6 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MinValue, b6); res = copy.FetchRow(); Assert.IsTrue(res); // a7 'infinity' var a7 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MaxValue, a7); // b7 'infinity' var b7 = copy.ReadTimestamp(); Assert.AreEqual(DateTime.MaxValue, b7); res = copy.FetchRow(); Assert.IsFalse(res); copy.Close(); tran.Rollback(); }
public void PqsqlCopyToTest3() { const int len = 1; PqsqlTransaction tran = mConnection.BeginTransaction(); mCmd.Transaction = tran; mCmd.CommandText = "create temporary table foo (a int2, b int4, c int8, d boolean, e boolean, f float4, " + "g float8, h text, i timestamp, j time, k timetz, l timetz, m date, n interval); " + "insert into foo values (5, 1000001, 42949672950, true, false, 3.14, 3.14, 'hallo 1', " + "TIMESTAMP '1999-01-08 04:05:06', '04:05:06.789', '04:05:06-08:00', '04:05:06+08:00', " + "'1999-01-08', '3 4:05:06');"; mCmd.CommandType = CommandType.Text; int affected = mCmd.ExecuteNonQuery(); Assert.AreEqual(len, affected); var copy = new PqsqlCopyTo(mConnection) { Table = "foo", ColumnList = "a,b,c,d,e,f,g,h,i,j,k,l,m,n", CopyTimeout = 10, }; copy.Start(); while (copy.FetchRow()) { var a = copy.ReadInt2(); Assert.AreEqual(5, a); var b = copy.ReadInt4(); Assert.AreEqual(1000001, b); var c = copy.ReadInt8(); Assert.AreEqual(42949672950, c); var d = copy.ReadBoolean(); Assert.IsTrue(d); var e = copy.ReadBoolean(); Assert.IsFalse(e); var f = copy.ReadFloat4(); Assert.AreEqual(3.14, f, 0.00001); var g = copy.ReadFloat8(); Assert.AreEqual(3.14, g, 0.00001); var h = copy.ReadString(); Assert.AreEqual("hallo 1", h); var i = copy.ReadTimestamp(); Assert.AreEqual(new DateTime(1999, 1, 8, 4, 5, 6), i); var j = copy.ReadTime(); Assert.AreEqual(new DateTime(1970, 1, 1, 4, 5, 6, 789), j); var k = copy.ReadTimeTZ(); Assert.AreEqual(new DateTimeOffset(1970, 1, 1, 4, 5, 6, 0, new TimeSpan(-8, 0, 0)), k); var l = copy.ReadTimeTZ(); Assert.AreEqual(new DateTimeOffset(1970, 1, 1, 4, 5, 6, 0, new TimeSpan(8, 0, 0)), l); var m = copy.ReadDate(); Assert.AreEqual(new DateTime(1999, 1, 8), m); var n = copy.ReadInterval(); Assert.AreEqual(new TimeSpan(3, 4, 5, 6), n); } copy.Close(); tran.Rollback(); }