Skip to Content.
Sympa Menu

freetds - Re: [freetds] 'Money' column types need an explicit convert

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Daniel Kasak <dkasak AT nusconsulting.com.au>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] 'Money' column types need an explicit convert
  • Date: Tue, 15 Aug 2006 11:51:51 +1000

James K. Lowden wrote:

> You said it's a "simple update" statement, indicating that somewhere
> you're pointing quotes around a numeric value or storing a number in a
> variable declared as char/varchar. Stop doing that and you'll be OK. ;-)
>
> If you're binding to a character host variable, similar restrictions
> apply.

OK. I should probably have posted some code as well. Sorry. I'm doing:

sub on_DisputeAmount_clicked {

my ( $self, $widget, $event ) = @_;

if ( $event->type ne '2button-press' ) {
return;
}

my $amount = dialogs::input_box->new( {
title => "Dispute Amount",
prompt => "Enter dispute
amount"
}
);

if ( $amount || $amount == 0 ) {

# Strip dollar signs and commas
$amount =~ s/[\$|\,]//g;

my @values = ( $amount, $self->{clientid} );

$self->{globals}->{common}->dbdo(
$self->{globals}->{ms_dbh},
"update Clients set DisputeAmount = ? where ID = ?",
\@values
);

}

$self->refresh_client_details;

}

The 'dbdo' function is a very light wrapper around:

$sth = $dbh->prepare( $sql );
$sth->execute( $sql, $values );

Being Perl, I suppose it mightn't be accurate to say that $amount is
numeric. It's a scalar anyway. It holds a number and nothing else by the
time it gets to the 'dbdo' function. At least I've always tested it with
numeric data. I'm not concerned if someone enters text where a number
should be - I raise a suitable warning in this case ( in 'dbdo' ).

Anyway, I suppose to support money fields properly, I should use
$dbh->column_info to sniff out money columns, and wrap all inserts /
updates on this field with a convert function? There's certainly no way
I can see that my current setup ( FreeTDS, DBD::ODBC ) will allow me to
use money columns otherwise.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak AT nusconsulting.com.au
website: http://www.nusconsulting.com.au




Archive powered by MHonArc 2.6.24.

Top of Page