Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by rafl (Friar)
on Aug 23, 2006 at 18:54 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found