Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Updating/inserting Binary data using DBIx::Class

by rafl (Friar)
on Aug 23, 2006 at 18:54 UTC ( #569169=note: print w/replies, xml ) Need Help??

in reply to Updating/inserting Binary data using DBIx::Class

I know this solution is quite hacky, but I don't really have another idea right now. Try to add the following accessor to your resultsource class

sub col_name { my $self = shift; if (@_) { my $data = shift; my $sth = $self->result_source->schema->storage->dbh->prepare( +"update table set col_name = ? where primary_key = ?"); $sth->bind_param(1, $data, {TYPE => DBI::SQL_BINARY}); $sth->bind_param(2, $self->primary_key); $sth->execute; } my $sth = $self->result_source->schema->storage->dbh->prepare("sel +ect col_name from table where primary_key = ?"); $sth->execute( $self->primary_key ); my $result = $sth->fetchrow_hashref; return $result->{col_name}; }

I know that this piece of code somehow undermines the principles of DBIx::Class because the resultsource already knows what the table name is and how the primary_key is called. You may be able to change the hard-coded SQL queries to something smarter or you will probably also be able to use SQL::Abstract, which DBIx::Class uses internal as well, to build that query, but I didn't bother with that.

Also note that the code is completely untested.

Cheers, Flo

Replies are listed 'Best First'.
Re^2: Updating/inserting Binary data using DBIx::Class
by hrr (Monk) on Aug 25, 2006 at 00:50 UTC
    Great, thank you very much for this hack! I will try it out and report about its results here.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://569169]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2018-02-22 13:38 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (293 votes). Check out past polls.