Обсуждение: Bytea error in PostgreSQL 9.0

Поиск
Список
Период
Сортировка

Bytea error in PostgreSQL 9.0

От
tuanhoanganh
Дата:
I have program work with bytea, this field store image. Program work well in postgresql 8.3.9 but error in postgresql 9.0
Here is code to write image to database

FileStream srcStream = new FileStream(file_name, FileMode.Open, FileAccess.Read);
byte[] arrImage = new byte[srcStream.Length];
int read = srcStream.Read(arrImage, 0, arrImage.Length);

string sql = "INSERT INTO hrnvpict(ma_nv,pict) VALUES(@ma_nhan_vien ,@arrImage)";
Npgsql.NpgsqlConnection c = Public.cn;
Npgsql.NpgsqlCommand comm = new NpgsqlCommand(sql, c);
comm.Parameters.Add(new NpgsqlParameter("@arrImage", DbType.Binary)).Value = arrImage;
comm.Parameters.Add(new NpgsqlParameter("@ma_nhan_
vien", DbType.String, 40)).Value = _ma_nv;
comm.ExecuteNonQuery();

And Here is code to read image from database

string cmd = "select pict from hrnvpict where trim(ma_nv)= '" + _ma_nv + "'";
Npgsql.NpgsqlConnection c = Public.cn;
Npgsql.NpgsqlCommand comm = new NpgsqlCommand(cmd, c);
Byte[] result = (Byte[])comm.ExecuteScalar();
MemoryStream pic = new MemoryStream(result);
pictureBox1.Image = Image.FromStream(pic);  //<- 9.0 error here "parameter is not valid"

My postgresql 8.3 install is made by msi download from www.postgresql.org. Postgresql 9 install is made by EnterpriseDB, it has LC_COLLATE = 'English_United States.1252' and LC_CTYPE = 'English_United States.1252' (In 8.3 I cannot found this)

How to fix this. Please help me. Sorry for my English.

Tuan Hoang Anh

Re: Bytea error in PostgreSQL 9.0

От
"Mark Felder"
Дата:
On Mon, 13 Dec 2010 23:06:32 -0600, tuanhoanganh <hatuan05@gmail.com>
wrote:

> I have program work with bytea, this field store image. Program work
> well in
> postgresql 8.3.9 but error in postgresql 9.0

I don't know if this is your problem, but bytea changed in Postgres 9.0.
Could you try enabling "set bytea_output = escape"?



Regards,


Mark

Re: Bytea error in PostgreSQL 9.0

От
tuanhoanganh
Дата:
Thanks for your help.
Is there any .Net or VB tutorial new 9.0 bytea?

Tuan Hoang Anh

On Tue, Dec 14, 2010 at 1:27 PM, Mark Felder <feld@feld.me> wrote:
On Mon, 13 Dec 2010 23:06:32 -0600, tuanhoanganh <hatuan05@gmail.com> wrote:

I have program work with bytea, this field store image. Program work well in
postgresql 8.3.9 but error in postgresql 9.0

I don't know if this is your problem, but bytea changed in Postgres 9.0. Could you try enabling "set bytea_output = escape"?



Regards,


Mark

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Bytea error in PostgreSQL 9.0

От
Ivan Voras
Дата:
On 14/12/2010 14:51, tuanhoanganh wrote:
> Thanks for your help.
> Is there any .Net or VB tutorial new 9.0 bytea?

You do not need to change your code if you add

bytea_output = 'escape'                 # hex, escape

into postgresql.conf.


Re: Bytea error in PostgreSQL 9.0

От
tuanhoanganh
Дата:
Thanks for your answer. But I don't want to change db config or ALTER DATABASE data SET bytea_output='escape';
I can change my app. So is there document introduce how to work with postgresql 9 bytea ( I don't want to user lo_create, lo_import. lo_export)

Tuan Hoang Anh

On Tue, Dec 14, 2010 at 8:55 PM, Ivan Voras <ivoras@freebsd.org> wrote:
On 14/12/2010 14:51, tuanhoanganh wrote:
Thanks for your help.
Is there any .Net or VB tutorial new 9.0 bytea?

You do not need to change your code if you add

bytea_output = 'escape'                 # hex, escape

into postgresql.conf.




--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Bytea error in PostgreSQL 9.0

От
Tom Lane
Дата:
tuanhoanganh <hatuan05@gmail.com> writes:
> Thanks for your answer. But I don't want to change db config or ALTER
> DATABASE data SET bytea_output='escape';
> I can change my app. So is there document introduce how to work with
> postgresql 9 bytea ( I don't want to user lo_create, lo_import. lo_export)

http://www.postgresql.org/docs/9.0/static/datatype-binary.html

See 8.4.1 versus 8.4.2 in particular.

            regards, tom lane

Re: Bytea error in PostgreSQL 9.0

От
"Francisco Figueiredo Jr."
Дата:
Latest Npgsql version 2.0.11 already has a fix to handle new bytea
representation.

Can you try with this version and see if it works ok?

I hope it helps.

On Tue, Dec 14, 2010 at 14:22, tuanhoanganh <hatuan05@gmail.com> wrote:
> Thanks for your answer. But I don't want to change db config or ALTER
> DATABASE data SET bytea_output='escape';
> I can change my app. So is there document introduce how to work with
> postgresql 9 bytea ( I don't want to user lo_create, lo_import. lo_export)
>
> Tuan Hoang Anh
>
> On Tue, Dec 14, 2010 at 8:55 PM, Ivan Voras <ivoras@freebsd.org> wrote:
>>
>> On 14/12/2010 14:51, tuanhoanganh wrote:
>>>
>>> Thanks for your help.
>>> Is there any .Net or VB tutorial new 9.0 bytea?
>>
>> You do not need to change your code if you add
>>
>> bytea_output = 'escape'                 # hex, escape
>>
>> into postgresql.conf.
>>
>>
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>
>



--
Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://www.npgsql.org
http://fxjr.blogspot.com
http://twitter.com/franciscojunior

Re: Bytea error in PostgreSQL 9.0

От
Vick Khera
Дата:
On Tue, Dec 14, 2010 at 11:22 AM, tuanhoanganh <hatuan05@gmail.com> wrote:
> Thanks for your answer. But I don't want to change db config or ALTER
> DATABASE data SET bytea_output='escape';
> I can change my app. So is there document introduce how to work with
> postgresql 9 bytea

Your .Net or whatever library you're using will need to learn how to
interpret the new encoding, and do the necessary work to make the data
represented to you what you expect.

I use perl DBD::Pg interface, and the current released version does
not know how to do it, so I had to write my own layer of code into my
ORM that detects and decodes the new bytea format before passing it
back to my app.  The postgres manual has many details that will help
you do something like this.