Does anyone know if PostgreSQL is capable of storing binary
data? I'm using DBI/DBD::ODBC and I need to save JPEG/GIF/PNG images in a table.
Here is what I tried:
use DBI;
my ($dbh, $data) = (undef, '');
$data .= chr(int rand 256) for 1..400;
eval{
$dbh = DBI->connect('DBI:ODBC:testdb', '', '')
or die $DBI::errstr;
my $sth = $dbh->prepare('insert into btest(id, data) values (?,?);')
+or die $dbh->errstr();
$sth->execute(1, $data) or die $dbh->errstr();
$dbh->disconnect();
};
print "Error : $@" if length $@;
Table BTEST is defined as follows
testdb=# \d btest
Table "btest"
Attribute | Type | Modifier
-----------+---------+----------
id | integer | not null
data | text |
Index: btest_id_key
When I run the above code I get the following error:
DBD::ODBC::st execute failed: Error while executing the query;
ERROR: Unterminated quoted string (SQL-S1000)
ERROR: Unterminated quoted string (SQL-S1000)(DBD: st_execute/SQLExec
+ute err=-1
) at C:\Perl\dev\rdm\btest.pl line 12.
I tried doing two things
1) $data =~ s/'/''/g;
2) $data =~ s/(\W)/\\$1/g;
Neither one works.
Any input is appreciated.
Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.