[Dbix-class] Setting additional attributes in bind_param

Matt S Trout dbix-class at trout.me.uk
Wed Nov 15 12:58:59 GMT 2006


John Napiorkowski wrote:
> Hi,
> 
> I'm trying to pass some additional 'hinting'
> information to the sql statement throught the dbi
> bind_param method.  In 'straight' dbi procedural code
> I might write something like:
> 
> my $update_sql	= q[
> 
>   update videos.content
>   set content=?
>   where catalog_id=? encoding_id=? format_id=?
> ];
> 	
> my $sth   = $dbh->prepare($update_sql);
> 
> $sth->bind_param(1,$file, {pg_type =>
> DBD::Pg::PG_BYTEA });
> $sth->bind_param(2,$self->catalog_id());
> $sth->bind_param(3,$self->encoding_id());
> $sth->bind_param(4,$self->format_id());
> 
> $sth->execute();
> 
> Now I can see we are using SQL::Abstract to create the
> SQL and bind lists which we pass straight to execute
> in 
> DBIx::Class::Storage::DBI.pm in the _execute method. 
> So we'd need to change this someway if we want to do
> binds with attributes and hinting.
> 
> In the docs for SQL::Abstract, it says we can do this
> by passing a 'bindtype='columns' when we instantiate
> the object.  The main drawback is that we need to loop
> through the parameter bindings instead of just passing
> it all to dbi excute, but in this case that sort of
> flexibility is something I want.
> 
> In DBIx::Class::Storage::DBI.pm I find a couple of
> methods that might help.  It looks like I can pass
> some SQL::Abstract options to the connection method,
> but right now these are limited to qw/limit_dialect
> quote_char name_sep/.
> 
> I don't think it would be too hard to patch
> DBIx::Class::Storage::DBI.pm so that you could pass
> some hints to the bind_param method.  I think the
> biggest choice would be to figure out how to set
> and/or store the hinting info.  I'd be inclined to
> have it in the column metadata, under a key called,
> "bind_attributes" or something like that but I'm not
> sure if that will interfere with some other future
> plans for extension.
> 
> Otherwise it looks to me like it would just be 10 or
> so lines of code in one class to make it work.

Should really be in _execute, not in the SQLA stuff, I think. bind_info in 
column_info seems like it'd be consistent with everything else, make sure you 
leave room to support the extra-interesting stuff like filehandle access to 
BLOBS that some DBs provide.

Patches (with tests) against -current welcome :)


-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list