简体   繁体   English

如何使用Class :: DBI将二进制数据插入BLOB列?

[英]How do you insert binary data into a BLOB column with Class::DBI?

I want to create a new object using Class::DBI. 我想使用Class :: DBI创建一个新对象。 One of the fields of this object is a BLOB type. 此对象的字段之一是BLOB类型。 I have a filehandle I want to use for this data, but apparently, just doing this doesn't work: 我有一个要用于此数据的文件句柄,但显然,仅这样做是行不通的:

my $item = My::Class::DBI::Class->insert({
        foo       => $bar,
        biz       => $baz,
        blob         => $my_filehandle
        });

Is there some trick I am missing? 我缺少一些技巧吗?

Thanks! 谢谢!

You have to read out the filehandle, and insert that. 您必须读出文件句柄,然后将其插入。

my $blob = do {local $/; <$my_filehandle>};
my $item = My::Class::DBI::Class->insert({
        foo       => $bar,
        biz       => $baz,
        blob         => $blob,
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Perl DBI / FreeTDS / SQL-Server:如何插入/更新 BLOB varbinary(max) 数据? - Perl DBI / FreeTDS / SQL-Server: How to insert/update BLOB varbinary(max) data? Perl DBI / MS ODBC 驱动程序 (LinuxL:RHEL) / SQL-Server:如何插入/更新 BLOB varbinary(max) 数据? - Perl DBI / MS ODBC Driver (LinuxL:RHEL) / SQL-Server: How to insert/update BLOB varbinary(max) data? 如何在带有DBI的Perl中列出Jet数据库的表名? - How do you list the table names of a Jet database in Perl with DBI? 如何在Class :: DBI中使用add_to? - How do I use add_to in Class::DBI? 如何在Perl的Class :: DBI中覆盖自动生成的访问器? - How do I override autogenerated accessors in Perl's Class::DBI? 如何使用Perl的DBI模块将哈希值插入数据库? - How do I insert values from a hash into a database using Perl's DBI module? 如何使用Perl的DBI模块将并行数组中的值插入数据库中? - How do I insert values from parallel arrays into a database using Perl's DBI module? 如何使用Perl DBI检索DB2 SQL sproc的返回值? - How do you retrieve the return value of a DB2 SQL sproc using Perl DBI? 如何在Perl中插入mongoDB float数据类型? - How do you insert into mongoDB float data type in Perl? 如何使用DBI解析FASTA文件并将序列提交到Perl中的SQLite db文件? - How do you parse FASTA file and submit sequence to SQLite db file in Perl using DBI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM