X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=fb83faa3fec411e1cd1a647e6a338ed35f6701ee;hb=e356f2ebb6564fe8d5333fc89bb4583ee3cd1fb1;hp=2e2612e35e225ea802dfab75a2d0da658176f735;hpb=7353f670ef61e617a9dfb6c258907eb70e0345f6;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 2e2612e35..fb83faa3f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -30,8 +30,10 @@ use Tie::IxHash; @ISA = qw(Exporter); #export dbdef for now... everything else expects to find it here -@EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch - str2time_sql str2time_sql_closing regexp_sql not_regexp_sql ); +@EXPORT_OK = qw( + dbh fields hfields qsearch qsearchs dbdef jsearch + str2time_sql str2time_sql_closing regexp_sql not_regexp_sql concat_sql +); $DEBUG = 0; $me = '[FS::Record]'; @@ -1591,6 +1593,7 @@ sub process_batch_import { params => { map { $_ => $param->{$_} } @pass_params }, #? default_csv => $opt->{default_csv}, + postinsert_callback => $opt->{postinsert_callback}, ); if ( $opt->{'batch_namecol'} ) { @@ -1664,6 +1667,8 @@ sub batch_import { my( $type, $header, $sep_char, $fixedlength_format, $xml_format, $row_callback, @fields ); my $postinsert_callback = ''; + $postinsert_callback = $param->{'postinsert_callback'} + if $param->{'postinsert_callback'}; if ( $param->{'format'} ) { my $format = $param->{'format'}; @@ -1709,9 +1714,6 @@ sub batch_import { $row_callback = ''; @fields = @{ $param->{'fields'} }; - $postinsert_callback = $param->{'postinsert_callback'} - if $param->{'postinsert_callback'} - } else { die "neither format nor fields specified"; } @@ -2909,7 +2911,8 @@ sub scalar_sql { my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute(@_) or die "Unexpected error executing statement $sql: ". $sth->errstr; - my $scalar = $sth->fetchrow_arrayref->[0]; + my $row = $sth->fetchrow_arrayref or return ''; + my $scalar = $row->[0]; defined($scalar) ? $scalar : ''; } @@ -3098,6 +3101,29 @@ sub not_regexp_sql { } +=item concat_sql [ DRIVER_NAME ] ITEMS_ARRAYREF + +Returns the items concatendated based on database type, using "CONCAT()" for +mysql and " || " for Pg and other databases. + +You can pass an optional driver name such as "Pg", "mysql" or +$dbh->{Driver}->{Name} to return a function for that database instead of +the current database. + +=cut + +sub concat_sql { + my $driver = ref($_[0]) ? driver_name : shift; + my $items = shift; + + if ( $driver =~ /^mysql/i ) { + 'CONCAT('. join(',', @$items). ')'; + } else { + join('||', @$items); + } + +} + =back =head1 BUGS