X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=201e7b23cdf3e8378fe6089a57a8b5789ebdd8bf;hb=1bfbab83c338f6a11ae26c4d197ad775c568ebde;hp=e02a2cff8029cbc44ae4aa279b7b21556035b1ab;hpb=457cf05ffc31212de613249c95a8ab05aed34f47;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index e02a2cff8..201e7b23c 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -15,7 +15,7 @@ use Locale::Country; use Text::CSV_XS; use File::Slurp qw( slurp ); use DBI qw(:sql_types); -use DBIx::DBSchema 0.33; +use DBIx::DBSchema 0.38; use FS::UID qw(dbh getotaker datasrc driver_name); use FS::CurrentUser; use FS::Schema qw(dbdef); @@ -962,12 +962,12 @@ sub insert { my $db_seq = 0; if ( $primary_key ) { my $col = $self->dbdef_table->column($primary_key); - + $db_seq = uc($col->type) =~ /^(BIG)?SERIAL\d?/ || ( driver_name eq 'Pg' && defined($col->default) - && $col->default =~ /^nextval\(/i + && $col->quoted_default =~ /^nextval\(/i ) || ( driver_name eq 'mysql' && defined($col->local) @@ -1032,7 +1032,7 @@ sub insert { #my $oid = $sth->{'pg_oid_status'}; #my $i_sql = "SELECT $primary_key FROM $table WHERE oid = ?"; - my $default = $self->dbdef_table->column($primary_key)->default; + my $default = $self->dbdef_table->column($primary_key)->quoted_default; unless ( $default =~ /^nextval\(\(?'"?([\w\.]+)"?'/i ) { dbh->rollback if $FS::UID::AutoCommit; return "can't parse $table.$primary_key default value". @@ -1767,6 +1767,8 @@ sub batch_import { last unless scalar(@buffer); $line = shift(@buffer); + next if $line =~ /^\s*$/; #skip empty lines + $parser->parse($line) or do { $dbh->rollback if $oldAutoCommit; return "can't parse: ". $parser->error_input(); @@ -2762,6 +2764,25 @@ sub h_date { $h ? $h->history_date : ''; } +=item scalar_sql SQL + +A class method with a propensity for becoming an instance method. This +method executes the sql statement represented by SQL and returns a scalar +representing the result. Don't ask for rows -- you get the first column +of the first row. Don't give me bogus SQL or I'll die on you. + +Returns an empty string in the event of no rows. + +=cut + +sub scalar_sql { + my($self, $sql ) = ( shift, shift ); + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute + or die "Unexpected error executing statement $sql: ". $sth->errstr; + $sth->fetchrow_arrayref->[0] || ''; +} + =back =head1 SUBROUTINES