示例#1
0
 public static void FailCopyOutToStream()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     try
     {
         cout = new NpgsqlCopyOut( new NpgsqlCommand("COPY copy1 TO STDOUT", conn), conn, cs );
         cout.Start();
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             Console.Out.WriteLine("Copy to stream failed as requested.");
             return;
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cout.End(); // should silently discard rest of data
     }
     throw new Exception("Copy to stream did not fail as requested");
 }
示例#2
0
 public static void CopyOutToStream()
 {
     cs = new CountStream();
     // cs.WrapStream = new FileStream("test_copy.out", FileMode.Create, FileAccess.Write);
     cout = new NpgsqlCopyOut( new NpgsqlCommand("COPY copy1 TO STDOUT", conn), conn, cs );
     cout.Start();
     if(cout.IsActive)
     {
         throw new Exception("Copy to stream did not complete in single pass");
     }
     Console.Out.WriteLine("Lengths of text written to and read in single pass from database differ by " + (InLength-cs.BytesPassed));
     Console.Out.WriteLine("Sums of characters written to and read in single pass from database differ by " + (InSum-cs.CheckSum));
 }
示例#3
0
 public static void FailCopyOutByReading()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     cout = new NpgsqlCopyOut( "COPY copy1 TO STDOUT", conn );
     cout.Start();
     if(! cout.IsActive)
     {
         throw new Exception("Copy reading started inactive");
     }
     byte[] buf = new byte[9];
     int i;
     try
     {
         while( (i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0 )
         {
             cs.Write(buf, 0, i);
         }
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             Console.Out.WriteLine("Copy to reading failed as requested.");
             return;
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cout.End();
     }
     throw new Exception("Copy reading did not fail as requested");
 }
示例#4
0
 public static void CopyOutByReading()
 {
     cs = new CountStream();
     cout = new NpgsqlCopyOut( "COPY copy1 TO STDOUT", conn );
     cout.Start();
     if(! cout.IsActive)
     {
         throw new Exception("Copy reading started inactive");
     }
     byte[] buf = new byte[9];
     int i;
     while( (i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0 )
     {
         cs.Write(buf, 0, i);
     }
     cs.Close();
     cout.End();
     Console.Out.WriteLine("Lengths of text written to and read via stream from database differ by " + (InLength-cs.BytesPassed));
     Console.Out.WriteLine("Sums of characters written to and read via stream from database differ by " + (InSum-cs.CheckSum));
 }