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

After browsing through the DBIx::Class source code, it seems to me that DBIx::Class is less flexible that I hoped it to be... maybe it is not possible / very difficult to do what I originally intended.

Concretely, DBIx::Class::Storage::DBI handles insert/update statements, using
sub _execute { ... my ($sql, @bind) = $self->sql_maker->$op($ident, @args); ... my $sth = $self->sth($sql,$op); ... $rv = $sth->execute(@bind) ... }
In particular, this means that because the bind parameters are passed to execute as array, no bind attributes can be specified! In this case, according to the documentation of DBI:
It would be possible to define the data type prior to executing the statement, because according to the documentation of DBI::bind_param(..., \%attr), the whole \%attr parameter is 'sticky' in the sense that a driver only needs to consider the \%attr parameter for the first call, for a given $sth and parameter.
However, even when using bind_param, this would still would still require changes to DBIx::Class in some form.

Replies are listed 'Best First'.
Re^2: Updating/inserting Binary data using DBIx::Class
by siracusa (Friar) on Aug 22, 2006 at 14:47 UTC

    Yes, this is a common issue with binary column data and DBI. I recently added support for explicit bind_param() calls to Rose::DB::Object in order to support Postgres's BYTEA column type. (Unfortunately, Rose::DB::Object does not currently support DB2.)

    Calling bind_param() explicitly incurs a small performance hit, since it must be called on every value in a given query, even if it's only strictly needed on just one. Although the DBI docs say that calling execute() with arguments calls bind_param() on every value anyway, my testing has shown that there is a difference between allowing DBI to do it and doing it manually.

    The compromise I came up with in Rose::DB::Object is to explicitly call bind_param() only if one or more columns in a particular table requires it. This eliminates the performance hit for the common case of tables without any binary columns.

      It is very interesting that you identify this as a common issue with binary column data! That, after a rigorous analysis, you were able to come up with an elegant compromise, raises my hopes that an implementation in DBIx::Class is not too far away :)