Hi monks

I want to store some binary data in sql database (actually postgresql) produced by Storable::nfreeze(). How can I do it?

Test table have following structure

Attribute | Type | Modifier -----------+------------------------+---------- pkey | character varying(255) | not null pvalue | bytea | Index: demo_pkey

Following test code fails with error 'Unterminated quoted string at ...' for line with execute call.

#!/usr/bin/perl -w use strict; use Storable qw(nfreeze thaw); use DBI; use DBD::Pg; # database settings my $db_name = 'unicode'; my $db_host = 'localhost'; my $db_user = 'elric'; my $db_pass = 'test01'; my $dbh = DBI->connect("dbi:Pg:dbname=$db_name;host=$db_host;", "$db_user", "$db_pass"); my $test = { 'ahoj svete...', [ 1, 23, 'ttt' ], }; my $sth = $dbh->prepare("insert into demo values (?, ?)"); $sth->execute('test', nfreeze($test)); $dbh->disconnect(); exit 0;

I need to have similar functionality like MLDBM module, but for sql database. The modules Tie::RDBM, Tie::MLDBM looks buggy for me.

How can I solve this. What I'm doing wrong? or is there already preset other module for doing this?


In reply to postgresql: store binary data? by ph0enix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.