dbTalk Databases Forums  

Read problem from Bytea column

comp.databases.postgresql comp.databases.postgresql


Discuss Read problem from Bytea column in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
orgilhp
 
Posts: n/a

Default Read problem from Bytea column - 01-21-2011 , 03:24 AM






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.

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();
}

Reply With Quote
  #2  
Old   
Jasen Betts
 
Posts: n/a

Default Re: Read problem from Bytea column - 01-23-2011 , 05:31 AM






On 2011-01-21, orgilhp <orgilhp (AT) gmail (DOT) com> wrote:
Quote:
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.

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?
possibly you need to do unescape_bytea() or equivalent to the returned bytea value

--
⚂⚃ 100% natural

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.