PostgreSQL Images with WinDev – Update 12/21/2012

If you want to store images in your postgreSQL database and display them directly in a WinDev image control, Then you need to configure your database to return the bytea format as ‘Escape’ instead of Hex. With V9 of PostgreSQL the default changed to Hex and apparently pcSoft has not caught up with the new default format. Here’s the command you need to execute on your database:

ALTER DATABASE databasename SET bytea_output TO 'escape';

Now, back to your regular schedule program….

Update:

A few have asked for the rest of the code to get an image back and forth between the database and WX. So here is a quick overview of the process, this example is if you have a form where you want the user to be able to select the image that gets stored. Once you have it in the database, just linking an image control to the variable and doing a filestoscreen will display it..

1. You must make the change to your database as outlined above.

2. In PostgreSQL the image filed is defined as a bytea:

CREATE TABLE developer
(
 devsysid serial NOT NULL,
 logo bytea,
 CONSTRAINT "Pk_Developer" PRIMARY KEY (devsysid)
)

3. In your Analysis it is defined as a Sound,image, binary field
2012-12-21_1653

4. Place an image control on your screen (ImgLogo is what I am calling it in this example) and link it to the bytea field (logo) in you analysis

2012-12-21_1652

5. So the user can lookup the image file, and store it in the database field, add a file lookup control to your screen with the code for it

IF fFileExist(LogoFile) THEN
 ImgLogo = LogoFile
END

Now the normal Hadd, Hmodify will update the database. And screentofile, filetoscreen will make the logo display in the image control

One thought on “PostgreSQL Images with WinDev – Update 12/21/2012

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s