473,889 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Picture with Postgres and Delphi

Hi !! Everybody
I am developing app using Delphi and I have a question:
I have to save pictures into my database. Each picture has 20 o 30k aprox.
What is the way more optimus?
That 's table will have 500000 records around. Somebody said the best way to
do that was encoder the picture to field bytea but I dont know about this.
Another way is save the path to the picture file but I dont like so much
because I need to write to disk by OS and have permission to write a
directory to OS.
What do u think??
Edwin Quijada

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 11 '05
48 11958
On Wednesday 10 September 2003 17:17, Derrick Betts wrote:
Is the size limit 8K for 'text' field types as well?
What is the size limit of bytea, I thought it was 8K?


Not for some time now - the TOAST system (Tom Lane's work IIRC) means you can
store large text fields in a table. By large I mean MB large, not 64k or
something. I think there's a section on TOAST in the manuals.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 11 '05 #31
Thanks that is extremely helpfull.

Guy

Jonathan Bartlett wrote:
What is the size limit of bytea, I thought it was 8K?
No limit that I've found. Some are several meg.
How do you dump your database when you have bytea, do you need to do a
binary dump?
Nope. pg_dump automagically escapes everything.
What are you using to insert the binary data?


Perl example:

my $COMPLETED_TEMP LATE_VARS_INSER T = <<EOF; insert into
completed_temp late_vars (completed_temp late, name, value, binvalue) VALUES
(?, ?, ?, ?)
EOF

$sth = $dbh->prepare($COMPL ETED_TEMPLATE_V ARS_INSERT);
$value = undef;
$binvalue = $field->{BINANS};
$value = $field->{ANS} unless $binvalue;
$sth->bind_param(1 , $self->getOID);
$sth->bind_param(2 , $name);
$sth->bind_param(3 , $value);
$sth->bind_param(4 , $binvalue, DBI::SQL_BINARY );
$sth->execute || die("DBERROR:${ DBI::errstr}:") ;

Note that I explicityl set DBI::SQL_BINARY .

Now, for php, you do the following:

$logodata = pg_escape_bytea ($tmpdata);
$tmpsql = "update advertisements set $column_name = '$logodata'::by tea where object_id = $advertisement_ oid";
$tmp = $db->query($tmpsql) ;

I never got it to work with parameterized queries, but this works fine for
me. To select it back out, you need to do:

$q = $db->query("selec t teaser_logo_gif _image from advertisements where
object_id = ?::int8", array($_GET['advertisement']));
$row = $q->fetchrow();
$data = pg_unescape_byt ea($row[0]);

NOTE that many versions of PHP include pg_escape_bytea but NOT
pg_unescape_by tea. Look in the docs to see which function appeared in
which version.

Jon

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #32
Darko Prenosil wrote:

There is no need for manually storing files on filesystem, because large
objects are doing that for You. I am storing whole binary files in
blobs(synonym for large objects from some other platforms), and I do not
remember that I had a single problem with that. Do not forget that libpq has
great support for large objects, and you can store large object without
actually storing them on server filesystem, so You do not need any file
permissions on "upload directory" or something like that.
The pictures are prepared for web. Storing in files is faster from
that side. That system is calling db every 30 mins...
If You are using Delphi, there is great project called "Zeos objects", and
if I remember correctly it has support for large objects.

Zeos are useing a lot of memory...

Regards,
Micha³ Zaborowski (TeXXaS)
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #33
Richard Huxton <de*@archonet.c om> writes:
On Wednesday 10 September 2003 17:17, Derrick Betts wrote:
What is the size limit of bytea, I thought it was 8K?
Not for some time now - the TOAST system (Tom Lane's work IIRC)


Not my work, Jan Wieck's. But yes, the 8K limit is ancient history.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #34
> What is the size limit of bytea, I thought it was 8K?

No limit
How do you dump your database when you have bytea, do you need to do a
binary dump?
Just dump it normally.
What are you using to insert the binary data?
Depends. For php, I use pg_escape_bytea , and just use it as an in-query
string value. For perl, I use bind_param with SQL_BINARY.

Jon

Thank you in advance.

Guy

Jonathan Bartlett wrote:
For the education of me and maybe others too, why was
that? i.e. what problems did you run into, that bytea avoids?


Compared to the filesystem, bytea provides data integrity.

Bytea gives you remote access, which you can cache if needed.

Bytea gives you the same permissions as anything else in Postgres, so you
don't have to worry about that separately.

Compared to BLOBs, bytea's are just simpler. You can select them with a
single statement, you don't have to worry about leaving unreferenced
BLOBs, and, after 4 billion inserts, byteas are still meaningful while
BLOBs might not be. (due to OID problems).

Jon

_____________ _______________ ______
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


--
Guy Fraser
Network Administrator
The Internet Centre
780-450-6787 , 1-888-450-6787

There is a fine line between genius and lunacy, fear not, walk the
line with pride. Not all things will end up as you wanted, but you
will certainly discover things the meek and timid will miss out on.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 11 '05 #35
Thanks that is extremely helpfull.

Guy

Jonathan Bartlett wrote:
What is the size limit of bytea, I thought it was 8K?
No limit that I've found. Some are several meg.
How do you dump your database when you have bytea, do you need to do a
binary dump?
Nope. pg_dump automagically escapes everything.
What are you using to insert the binary data?


Perl example:

my $COMPLETED_TEMP LATE_VARS_INSER T = <<EOF; insert into
completed_temp late_vars (completed_temp late, name, value, binvalue) VALUES
(?, ?, ?, ?)
EOF

$sth = $dbh->prepare($COMPL ETED_TEMPLATE_V ARS_INSERT);
$value = undef;
$binvalue = $field->{BINANS};
$value = $field->{ANS} unless $binvalue;
$sth->bind_param(1 , $self->getOID);
$sth->bind_param(2 , $name);
$sth->bind_param(3 , $value);
$sth->bind_param(4 , $binvalue, DBI::SQL_BINARY );
$sth->execute || die("DBERROR:${ DBI::errstr}:") ;

Note that I explicityl set DBI::SQL_BINARY .

Now, for php, you do the following:

$logodata = pg_escape_bytea ($tmpdata);
$tmpsql = "update advertisements set $column_name = '$logodata'::by tea where object_id = $advertisement_ oid";
$tmp = $db->query($tmpsql) ;

I never got it to work with parameterized queries, but this works fine for
me. To select it back out, you need to do:

$q = $db->query("selec t teaser_logo_gif _image from advertisements where
object_id = ?::int8", array($_GET['advertisement']));
$row = $q->fetchrow();
$data = pg_unescape_byt ea($row[0]);

NOTE that many versions of PHP include pg_escape_bytea but NOT
pg_unescape_by tea. Look in the docs to see which function appeared in
which version.

Jon

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #36
Richard Huxton <de*@archonet.c om> writes:
On Wednesday 10 September 2003 17:17, Derrick Betts wrote:
What is the size limit of bytea, I thought it was 8K?
Not for some time now - the TOAST system (Tom Lane's work IIRC)


Not my work, Jan Wieck's. But yes, the 8K limit is ancient history.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #37
On Wednesday 10 September 2003 21:36, Micha³ Zaborowski wrote:
Darko Prenosil wrote:
There is no need for manually storing files on filesystem, because large
objects are doing that for You. I am storing whole binary files in
blobs(synonym for large objects from some other platforms), and I do not
remember that I had a single problem with that. Do not forget that libpq
has great support for large objects, and you can store large object
without actually storing them on server filesystem, so You do not need
any file permissions on "upload directory" or something like that.


The pictures are prepared for web. Storing in files is faster from
that side. That system is calling db every 30 mins...
If You are using Delphi, there is great project called "Zeos objects",
and if I remember correctly it has support for large objects.


Zeos are useing a lot of memory...

Regards,
Micha³ Zaborowski (TeXXaS)

I do not remember that this was the problem whan I used it. I was also diging
through that code, because I was writing something similar to dataset for QT.
What actually "Zeos are useing a lot of memory..." means ? A lot of alocated
space for result ?

Regards !

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 11 '05 #38
> What is the size limit of bytea, I thought it was 8K?

No limit
How do you dump your database when you have bytea, do you need to do a
binary dump?
Just dump it normally.
What are you using to insert the binary data?
Depends. For php, I use pg_escape_bytea , and just use it as an in-query
string value. For perl, I use bind_param with SQL_BINARY.

Jon

Thank you in advance.

Guy

Jonathan Bartlett wrote:
For the education of me and maybe others too, why was
that? i.e. what problems did you run into, that bytea avoids?


Compared to the filesystem, bytea provides data integrity.

Bytea gives you remote access, which you can cache if needed.

Bytea gives you the same permissions as anything else in Postgres, so you
don't have to worry about that separately.

Compared to BLOBs, bytea's are just simpler. You can select them with a
single statement, you don't have to worry about leaving unreferenced
BLOBs, and, after 4 billion inserts, byteas are still meaningful while
BLOBs might not be. (due to OID problems).

Jon

_____________ _______________ ______
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


--
Guy Fraser
Network Administrator
The Internet Centre
780-450-6787 , 1-888-450-6787

There is a fine line between genius and lunacy, fear not, walk the
line with pride. Not all things will end up as you wanted, but you
will certainly discover things the meek and timid will miss out on.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 11 '05 #39
>> If You are using Delphi, there is great project called "Zeos
objects", and if I remember correctly it has support for large
objects.

Zeos are useing a lot of memory...


Another issue I had with Zeos was that when I looked into possibly using
those components (this was probably over a year ago now), and tried
connecting to a database which is configured for md5 password encryption,
I got some kind of error message about that (md5 password authentication)
not being supported. Perhaps it works differently now, but be forewarned
to look at that if you need that type of authentication for your
database.

~Berend Tober


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8712
by: warwick.poole | last post by:
I am interested in finding out about Enterprise scale Postgres installations and clustering, especially on Linux. Essentially I would like to know the possibility that Postgres can store the database data in a central location (ex: on a SAN fiber array) and have a cluster of machines sharing processor/RAM/IO bandwidth to do the application processing. Or perhaps there is another solution similar to what www.emicnetworks.com have...
18
5160
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
1
2456
by: eric_berlin | last post by:
I am writing a multithreaded application that has 6 threads each writing 5 frames per second video bitmaps to a different picture box. I have just found out that only the main UI thread is supposed to interact with Windows Fourms. What is the fastest way to have a non UI thread safely write a bit map to a picture box?
0
2709
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
2284
by: varathasiva | last post by:
Dear All, I have one Delphi 7 application software.In that software i am using backend for PostgreSQL 8.1 with linux server fedura version.I am using this software through internet.After getting more data in PostgreSQL database server will be slow.In delphi 7 i am using data access component Zeos Lib.I cann't fund where is the problem.Please advice where is the problem.Advance thanks to all. Kindly Regards Siva
0
9970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10794
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.