Beispiel #1
0
    static public 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));
    }
Beispiel #2
0
    static public 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");
    }
Beispiel #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");
 }
Beispiel #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));
 }