X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=6c0f5f819d354420ea1c1058e30b491ac9eaf906;hp=3c8e9bac60541fc1427b3b0e04ad357ef0944118;hb=cf16b23820da69e3c8d0156ae27e21c635bf1ec5;hpb=fd72d2af8120195f96826eb044e217dbfcaee1c7 diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 3c8e9bac6..6c0f5f819 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -7,6 +7,7 @@ use Exporter; use Carp qw(carp cluck croak confess); use File::CounterFile; use Locale::Country; +use DBI qw(:sql_types); use DBIx::DBSchema 0.19; use FS::UID qw(dbh checkruid getotaker datasrc driver_name); use FS::SearchCache; @@ -210,7 +211,7 @@ sub qsearch { $statement .= ' WHERE '. join(' AND ', map { if ( ! defined( $record->{$_} ) || $record->{$_} eq '' ) { if ( driver_name =~ /^Pg$/i ) { - "$_ IS NULL"; + qq-( $_ IS NULL OR $_ = '' )-; } else { qq-( $_ IS NULL OR $_ = "" )-; } @@ -225,9 +226,26 @@ sub qsearch { my $sth = $dbh->prepare($statement) or croak "$dbh->errstr doing $statement"; - $sth->execute( map $record->{$_}, + my $bind = 1; + + foreach my $field ( grep defined( $record->{$_} ) && $record->{$_} ne '', @fields - ) or croak "Error executing \"$statement\": ". $dbh->errstr; + ) { + if ( $record->{$field} =~ /^\d+(\.\d+)?$/ + && $dbdef->table($table)->column($field)->type =~ /(int)/i + ) { + $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_INTEGER } ); + } else { + $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_VARCHAR } ); + } + } + +# $sth->execute( map $record->{$_}, +# grep defined( $record->{$_} ) && $record->{$_} ne '', @fields +# ) or croak "Error executing \"$statement\": ". $sth->errstr; + + $sth->execute or croak "Error executing \"$statement\": ". $sth->errstr; + $dbh->commit or croak $dbh->errstr if $FS::UID::AutoCommit; if ( eval 'scalar(@FS::'. $table. '::ISA);' ) { @@ -257,13 +275,15 @@ sub qsearch { } -=item jsearch +=item jsearch TABLE, HASHREF, SELECT, EXTRA_SQL, PRIMARY_TABLE, PRIMARY_KEY Experimental JOINed search method. Using this method, you can execute a single SELECT spanning multiple tables, and cache the results for subsequent method calls. Interface will almost definately change in an incompatible fashion. +Arguments: + =cut sub jsearch { @@ -384,7 +404,7 @@ $record->column('value') is a synonym for $record->set('column','value'); sub AUTOLOAD { my $field = $AUTOLOAD; $field =~ s/.*://; - if ( scalar(@_) == 2 ) { + if ( defined($_[1]) ) { $_[0]->setfield($field, $_[1]); } else { $_[0]->getfield($field); @@ -804,7 +824,7 @@ sub ut_phonen { $phonen .= " x$4" if $4; $self->setfield($field,$phonen); } else { - warn "don't know how to check phone numbers for country $country"; + warn "warning: don't know how to check phone numbers for country $country"; return $self->ut_textn($field); } ''; @@ -1036,12 +1056,12 @@ sub hfields { \%hash; } -#sub _dump { -# my($self)=@_; -# join("\n", map { -# "$_: ". $self->getfield($_). "|" -# } (fields($self->table)) ); -#} +sub _dump { + my($self)=@_; + join("\n", map { + "$_: ". $self->getfield($_). "|" + } (fields($self->table)) ); +} sub DESTROY { return; }