[Dbix-class] Getting numeric columns as numeric values

Augustus Saunders asaunders at solfo.com
Wed Feb 25 21:15:12 GMT 2015


For reasons unknown to us, DBIx is stringifying numeric values somewhere along the way. In order to ensure they come out numeric, we made this small patch:

--- a/lib/perl5/DBIx/Class/Row.pm
+++ b/lib/perl5/DBIx/Class/Row.pm
@@ -661,10 +661,15 @@ To retrieve all loaded column values as a hash, use L</get_columns>.
 sub get_column {
   my ($self, $column) = @_;
   $self->throw_exception( "Can't fetch data as class method" ) unless ref $self;
-  return $self->{_column_data}{$column} if exists $self->{_column_data}{$column};
+  if (exists $self->{_column_data}{$column}) {
+    return 0 + $self->{_column_data}{$column} if $self->_is_column_numeric($column);
+    return $self->{_column_data}{$column};
+  }
   if (exists $self->{_inflated_column}{$column}) {
-    return $self->store_column($column,
+    my $ret = $self->store_column($column,
       $self->_deflated_column($column, $self->{_inflated_column}{$column}));
+    return 0 + $ret if $self->_is_column_numeric($column);
+    return $ret;
   }
   $self->throw_exception( "No such column '${column}'" ) unless $self->has_column($column);
   return undef;

If there's a better way to do this, or some way to prevent DBIx from stringifying the values in the first place, that would be nice to know too. Thanks-

Augustus


More information about the DBIx-Class mailing list