bit varying columns

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bit varying columns

Bill Moseley
What's a good way to work with "bit varying" columns?  I want to toggle bits and set values.

__PACKAGE__->add_columns( my_bits => {  data_type => 'bit varying', } );

$foo->my_bits returns a string (e.g. "0000101010101" ).

I can do something like this to set a bit, but I assume there's a cleaner way:


my $new_bits = 2 | oct( '0b' . $foo->my_bits );
my $bit_str = sprintf '%b', $new_bits;

$foo->update( { my_bits => \"B'$bit_str'" } );


Seems like inflating to the integer (or Bit::Vector?) would be cleaner.

Suggestions?

--
Bill Moseley
[hidden email]

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: bit varying columns

Dagfinn Ilmari Mannsåker
Bill Moseley <[hidden email]> writes:

> What's a good way to work with "bit varying" columns?  I want to toggle
> bits and set values.
>
> __PACKAGE__->add_columns( my_bits => {  data_type => 'bit varying', } );
[…]
> Seems like inflating to the integer (or Bit::Vector?) would be cleaner.

Just write a DBIx::Class::InflateColumn::BitVector?

--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
 the consequences of."                              -- Skud's Meta-Law


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...