From: ivan Date: Mon, 7 Jul 2008 19:50:31 +0000 (+0000) Subject: add debugging of bind_param statements X-Git-Tag: root_of_webpay_support~507 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=87db725871fbc27ce2537b61bf0d42f5f3969250 add debugging of bind_param statements --- diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index b9fb2ae08..a27c4bcec 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -42,7 +42,7 @@ my $rsa_decrypt; FS::UID->install_callback( sub { eval "use FS::Conf;"; die $@ if $@; - $conf = new FS::Conf; + $conf = FS::Conf->new; $File::CounterFile::DEFAULT_DIR = $conf->base_dir . "/counters.". datasrc; } ); @@ -238,6 +238,8 @@ fine in the common case where there are only two parameters: =cut +my %TYPE = (); #for debugging + sub qsearch { my($stable, $record, $select, $extra_sql, $order_by, $cache, $addl_from ); my $debug = ''; @@ -298,20 +300,30 @@ sub qsearch { foreach my $field ( grep defined( $record->{$_} ) && $record->{$_} ne '', @real_fields ) { + my $value = $record->{$field}; $value = $value->{'value'} if ref($value); my $type = dbdef->table($table)->column($field)->type; + + my $TYPE = SQL_VARCHAR; if ( $type =~ /(int|(big)?serial)/i && $value =~ /^\d+(\.\d+)?$/ ) { - $sth->bind_param($bind++, $value, { TYPE => SQL_INTEGER } ); + $TYPE = SQL_INTEGER; } elsif ( ( $type =~ /(numeric)/i && $value =~ /^[+-]?\d+(\.\d+)?$/) || ( $type =~ /(real|float4)/i && $value =~ /[-+]?\d*\.?\d+([eE][-+]?\d+)?/ ) ) { - $sth->bind_param($bind++, $value, { TYPE => SQL_FLOAT } ); - } else { - $sth->bind_param($bind++, $value, { TYPE => SQL_VARCHAR } ); + $TYPE = SQL_FLOAT; } + + if ( $DEBUG > 2 ) { + %TYPE = map { &{"DBI::$_"} => $_ } @{ $DBI::EXPORT_TAGS{sql_types} } + unless keys %TYPE; + warn " bind_param $bind (for field $field), $value, TYPE $TYPE{$TYPE}\n"; + } + + $sth->bind_param($bind++, $value, { TYPE => $TYPE } ); + } # $sth->execute( map $record->{$_},