Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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


Comment on Re: Updating/inserting Binary data using DBIx::Class
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://569169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-10-21 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (98 votes), past polls