Problem saving binary data in postgresql
eleiva opened this issue · comments
Eduardo Leiva commented
Hi !
I have postgre to store my data and i had to change blob for bytea to store messages in spool_message table. So far so good.
But, I have encounter encoding issues with last change so i had done this in EmailSpool:
public static function pack($value)
{
// return gzcompress(serialize($value));
return pg_escape_bytea(serialize($value));
}
public static function unpack($value)
{
//return unserialize(gzuncompress($value));
return unserialize(pg_unescape_bytea($value));
}
As you may notice:
- I had to remove compress because encoding issues continues.
- Only work with postgre
- Is not binary anymore ( column now is type 'text')
This solution works but have you any thought to improve this?
This is my table, for others who are working with postgre too.
CREATE TABLE email_spool (
id integer NOT NULL,
transport character varying(32),
template character varying(32),
priority integer,
status character varying(32),
model_name character varying(255),
model_id character varying(255),
to_address character varying(255),
from_address character varying(255),
subject character varying(255),
message text,
sent integer,
created integer
);
CREATE SEQUENCE email_spool_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE ONLY email_spool ALTER COLUMN id SET DEFAULT nextval('email_spool_id_seq'::regclass);
ALTER TABLE ONLY email_spool
ADD CONSTRAINT email_spool_pkey PRIMARY KEY (id);
CREATE TABLE email_template (
id integer NOT NULL,
name character varying(255),
subject character varying(255),
heading character varying(255),
message text
);
CREATE SEQUENCE email_template_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE ONLY email_template
ADD CONSTRAINT email_template_pkey PRIMARY KEY (id);
ALTER TABLE ONLY email_template ALTER COLUMN id SET DEFAULT nextval('email_template_id_seq'::regclass);
CoRNeRNoTe commented
Wow, I was just talking to a @zainengineer yesterday about how nobody uses postgres. Haha!
I'll add your schema to the migrations and update the pack/unpack methods