public void PqsqlCopyToTest14() { const int len = 1; PqsqlTransaction tran = mConnection.BeginTransaction(); mCmd.Transaction = tran; mCmd.CommandText = "create temporary table foo (a int4, b text, c text); " + "insert into foo values (2, 'hallo pqsql 2', null);"; mCmd.CommandType = CommandType.Text; int affected = mCmd.ExecuteNonQuery(); Assert.AreEqual(len, affected); var copy = new PqsqlCopyTo(mConnection) { Table = "foo", CopyTimeout = 10, SuppressSchemaQuery = true, }; copy.Start(); var res = copy.FetchRow(); Assert.IsTrue(res); try { copy.ReadBoolean(); } catch (InvalidOperationException) {} // try again with correct reader var a0 = copy.ReadInt4(); Assert.AreEqual(2, a0); var b0 = copy.ReadString(); Assert.AreEqual("hallo pqsql 2", b0); var c0 = copy.IsNull(); Assert.IsTrue(c0); res = copy.FetchRow(); Assert.IsFalse(res); copy.Close(); tran.Rollback(); }
public void PqsqlCopyToTest2() { const int len = 1; PqsqlTransaction tran = mConnection.BeginTransaction(); mCmd.Transaction = tran; mCmd.CommandText = "create temporary table foo (a int4, b int4, c int4); " + "insert into foo values (null, 2, 3); "; mCmd.CommandType = CommandType.Text; int affected = mCmd.ExecuteNonQuery(); Assert.AreEqual(len, affected); var copy = new PqsqlCopyTo(mConnection) { Table = "foo", ColumnList = "c,a,b", CopyTimeout = 10, }; copy.Start(); var results = new int?[len]; while (copy.FetchRow()) { for (int i = 0; i < len; i++) { int?result; if (copy.IsNull()) { result = null; } else { result = copy.ReadInt4(); } if (i == 0) { // c Assert.IsTrue(result.HasValue); Assert.AreEqual(3, result.Value); } else if (i == 1) { // a Assert.IsFalse(result.HasValue); } else if (i == 2) { // b Assert.IsTrue(result.HasValue); Assert.AreEqual(2, result.Value); } } } copy.Close(); tran.Rollback(); }