Re: Read problem from Bytea column

From: "Francisco Figueiredo Jr(dot)" <francisco(at)npgsql(dot)org>
To: orgilhp <orgilhp(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Read problem from Bytea column
Date: 2011-01-22 11:06:35
Message-ID: AANLkTiknjBk+2JUGEKYmg3sVuE+mTrTMu432tk4YM0mZ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Francisco Figueiredo Jr

Sent from my Android phone.

Em 21/01/2011 13:50, "orgilhp" <orgilhp(at)gmail(dot)com> escreveu:
>
> Hello,

Hello!

> I have postgresql 8.3.9 database. Now I am working on reading file
> from bytea data and save to filesystem.
> I am using Npgsql.dll on c#.net.
>

Which version of Npgsql are you using?

Your code is ok and should be working. More info can be get from "Working
with binary data and bytea datatype" section of npgsql user manual.

Did you try another npgsql version? If it works in another version, please,
fill a bug report so we can fix it.

Thanks in advance!

> First I have using OpenERP to upload a file to postgres database in
> bytea column. The original file size is 104,960 bytes and .doc
> extension.
> Then I read the bytea data and save it to file system, its size
> becomes 141,790 bytes. This file cannot be opened however its
> extension is .doc.
>
> What is going on?
>
> My c# code is below:
>
> NpgsqlCommand cmd = new NpgsqlCommand("SELECT bytea_col
> FROM TableTest LIMIT 1", Conn);
> using (FileStream stream = new FileStream("c:\test.doc",
> FileMode.Create))
> {
> byte[] rawbytes = (byte[])cmd.ExecuteScalar();
> stream.Write(rawbytes, 0, rawbytes.Length);
> stream.Close();
> }
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Harald Armin Massa 2011-01-22 15:15:16 Re: Using copy for WAL archiving on Windows
Previous Message Andrus Moor 2011-01-22 09:00:12 Re: Server stops responding in every week