dictyBase / Modware-Loader

Various data munging and loading scripts for genome database
2 stars 1 forks source link

Saving plasmid map jpegs in database #88

Closed ypandit closed 11 years ago

ypandit commented 11 years ago

View from #89

screen shot 2013-09-13 at 3 28 59 pm

ypandit commented 11 years ago
use DBD::Pg qw(:pg_types);
open( IMAGE, $filepath );
binmode(IMAGE);
my $buf;
my $data;
while ( read( IMAGE, $buf, 10000 ) ) { $data .= $buf; }
close(IMAGE);

$self->schema->storage->dbh_do(
    sub {
        my ( $storage, $dbh ) = @_;
        my $sth
            = $dbh->prepare(
            "INSERT INTO stockprop (stock_id, type_id, value) VALUES ( ?,?,? ) "
            ) or die "PREPARE FAILED";

        $sth->bind_param( 3, undef, { pg_type => PG_BYTEA } );
        $sth->execute(
            $stock_rs->stock_id,
            $self->find_or_create_cvterm(
                'plasmid map', 'dicty_stockcenter'
            ),
            $data
        ) or die "EXECUTE FAILED";
        $sth->finish;
    }
);

Ref: 7a7a4e3 #L145