Options

ExecutionBlock.GetFilestream()

General1General1 Posts: 17
edited April 7, 2006 2:55AM in SQL Toolkit Previous Versions
Hi there,

I just installed the latest version of the toolkit and upgraded our existing code.

To know what the toolkit actually produces, we would like to write the executed SQL to a file, just before it gets executed.

Which encoding is used for this file stream ?
How do you recommend writing this ideally to a file (it is around 5 MB for our structure changes) ?

Thanks for your views.

I currently use the following code, which gives me a couple of extra bytes (UTF8 markings) every 32K :-(
      FileStream readstream = block.GetFileStream();
      long position = readstream.Position;
      readstream.Position = 0;
      if (File.Exists(path))
        File.Delete(path);
      using (FileStream writestream = File.OpenWrite(path))
      {
        using (StreamWriter writer = new StreamWriter(writestream, Encoding.UTF8))
        {
          byte[] buffer = new byte[32768];
          int read;
          do
          {
            read = readstream.Read(buffer, 0, buffer.Length);
            string chunk = Encoding.UTF8.GetString(buffer, 0, read);
            writer.Write(chunk);
          } while (read == buffer.Length);
        }
      }
      readstream.Position = position;
Dirk

Comments

  • Options
    OK. I found it meanwhile.

    Use the following code:
          BlockSaver saver = new BlockSaver(path, EncodingType.UTF8, block);
          saver.SaveToFile();
    
    Dirk
Sign In or Register to comment.