From: | MarkB <avocet77(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | How to store and load images in PostgreSQL db? |
Date: | 2011-05-25 09:47:06 |
Message-ID: | 1306316826126-4424778.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello,
I recently started using PostgresDAC 9.0 and had no trouble getting things
to work until I started to try to find out if it is possible to store (and
load) images in the Postgresql db from Delphi 7. I read about it and in my
opinion it is the best option to use a Bytea field.
Now I am struggling to find out how to save and load data to this field from
Delphi.
My test code is fairly simple:
PSQLTable1.Insert;
BlobField := TBlobField(PSQLTable1.FieldByName('Picture_Bytea'));
BlobField.LoadFromFile('picture.bmp');
PSQLTable1.Post;
(PSQLTable1 is on the form.)
This works fine until the Post procedure is called. A db error near "\"
appears.
Instead of using a table I would rather use a Query, but I can't get to work
that at all.
Query := TPSQLQuery.Create(nil);
Query.DataBase := Db;
BlobField := TBlobField.Create(nil);
try
BlobField.LoadFromFile('picture.bmp');
Query.SQL.Text := Format ('insert into "tblImage" ("Picture_Bytea")
values (%s)', [QuotedStr(BlobField.Value)]);
Query.Open;
finally
Query.Free;
BlobField.Free;
end;
Apparantly it is not allowed to create a TBlobField this way and I don't
think it's a good idea to format a bytea-field as a string (%s) either.
Sorry for my newbie question. I hope someone will be able to point me in the
right direction to get this working as I have been searching all over the
internet, but have not been able to find a solution. Even finding a correct
forum to post this question is difficult as there does not seem to be a
PostgreSQL forum for Delphi users.
Thanks in advance!
--
View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-store-and-load-images-in-PostgreSQL-db-tp4424778p4424778.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | Rafael Martinez | 2011-05-25 11:30:35 | No control over max.num. WAL files |
Previous Message | Vitalii Tymchyshyn | 2011-05-25 08:51:57 | Re: [PERFORMANCE] expanding to SAN: which portion best to move |