use strict;
use vars qw( $AUTOLOAD @ISA @EXPORT_OK $DEBUG
$conf $me
- %virtual_fields_cache $nowarn_identical $no_update_diff );
+ %virtual_fields_cache
+ $nowarn_identical $no_update_diff $no_check_foreign
+ );
use Exporter;
use Carp qw(carp cluck croak confess);
+use Scalar::Util qw( blessed );
use File::CounterFile;
use Locale::Country;
use DBI qw(:sql_types);
$nowarn_identical = 0;
$no_update_diff = 0;
+$no_check_foreign = 0;
my $rsa_module;
my $rsa_loaded;
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;
} );
=cut
+my %TYPE = (); #for debugging
+
sub qsearch {
my($stable, $record, $select, $extra_sql, $order_by, $cache, $addl_from );
my $debug = '';
foreach my $field (
grep defined( $record->{$_} ) && $record->{$_} ne '', @real_fields
) {
- if ( $record->{$field} =~ /^\d+(\.\d+)?$/
- && dbdef->table($table)->column($field)->type =~ /(int|(big)?serial)/i
- ) {
- $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_INTEGER } );
- }elsif ( $record->{$field} =~ /^[+-]?\d+(\.\d+)?$/
- && dbdef->table($table)->column($field)->type =~ /(numeric)/i
- ) {
- $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_FLOAT } );
- }elsif ( $record->{$field} =~ /[-+]?\d*\.?\d+([eE][-+]?\d+)?/
- && dbdef->table($table)->column($field)->type =~ /(float4)/i
- ) {
- $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_FLOAT } );
- } else {
- $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_VARCHAR } );
+
+ 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+)?$/ ) {
+ $TYPE = SQL_INTEGER;
+
+ #DBD::Pg 1.49: Cannot bind ... unknown sql_type 6
+ #} elsif ( ( $type =~ /(numeric)/i && $value =~ /^[+-]?\d+(\.\d+)?$/)
+ # || ( $type =~ /(real|float4)/i
+ # && $value =~ /[-+]?\d*\.?\d+([eE][-+]?\d+)?/
+ # )
+ # ) {
+ # $TYPE = SQL_FLOAT;
}
+
+ if ( $DEBUG > 2 ) {
+ no strict 'refs';
+ %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->{$_},
$field =~ s/.*://;
if ( defined($value) ) {
confess "errant AUTOLOAD $field for $self (arg $value)"
- unless ref($self) && $self->can('setfield');
+ unless blessed($self) && $self->can('setfield');
$self->setfield($field,$value);
} else {
confess "errant AUTOLOAD $field for $self (no args)"
- unless ref($self) && $self->can('getfield');
+ unless blessed($self) && $self->can('getfield');
$self->getfield($field);
}
}
sub ut_foreign_key {
my( $self, $field, $table, $foreign ) = @_;
+ return '' if $no_check_foreign;
qsearchs($table, { $foreign => $self->getfield($field) })
or return "Can't find ". $self->table. ".$field ". $self->getfield($field).
" in $table.$foreign";