projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix DBI binding for negative integers, shoudl fix CCH update, RT#14243
[freeside.git]
/
FS
/
FS
/
Record.pm
diff --git
a/FS/FS/Record.pm
b/FS/FS/Record.pm
index
16520f4
..
ad26d60
100644
(file)
--- a/
FS/FS/Record.pm
+++ b/
FS/FS/Record.pm
@@
-265,7
+265,7
@@
sub _bind_type {
my $bind_type = { TYPE => SQL_VARCHAR };
my $bind_type = { TYPE => SQL_VARCHAR };
- if ( $type =~ /(big)?(int|serial)/i && $value =~ /^\d+(\.\d+)?$/ ) {
+ if ( $type =~ /(big)?(int|serial)/i && $value =~ /^
-?
\d+(\.\d+)?$/ ) {
$bind_type = { TYPE => SQL_INTEGER };
$bind_type = { TYPE => SQL_INTEGER };
@@
-1591,6
+1591,7
@@
sub process_batch_import {
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
+ postinsert_callback => $opt->{postinsert_callback},
);
if ( $opt->{'batch_namecol'} ) {
);
if ( $opt->{'batch_namecol'} ) {
@@
-1629,6
+1630,8
@@
Class method for batch imports. Available params:
=item fields - Alternate way to specify import, specifying import fields directly as a listref
=item fields - Alternate way to specify import, specifying import fields directly as a listref
+=item preinsert_callback
+
=item postinsert_callback
=item params
=item postinsert_callback
=item params
@@
-1663,7
+1666,14
@@
sub batch_import {
my( $type, $header, $sep_char, $fixedlength_format,
$xml_format, $row_callback, @fields );
my( $type, $header, $sep_char, $fixedlength_format,
$xml_format, $row_callback, @fields );
+
my $postinsert_callback = '';
my $postinsert_callback = '';
+ $postinsert_callback = $param->{'postinsert_callback'}
+ if $param->{'postinsert_callback'};
+ my $preinsert_callback = '';
+ $preinsert_callback = $param->{'preinsert_callback'}
+ if $param->{'preinsert_callback'};
+
if ( $param->{'format'} ) {
my $format = $param->{'format'};
if ( $param->{'format'} ) {
my $format = $param->{'format'};
@@
-1709,9
+1719,6
@@
sub batch_import {
$row_callback = '';
@fields = @{ $param->{'fields'} };
$row_callback = '';
@fields = @{ $param->{'fields'} };
- $postinsert_callback = $param->{'postinsert_callback'}
- if $param->{'postinsert_callback'}
-
} else {
die "neither format nor fields specified";
}
} else {
die "neither format nor fields specified";
}
@@
-1747,7
+1754,7
@@
sub batch_import {
eval "use Parse::FixedLength;";
die $@ if $@;
eval "use Parse::FixedLength;";
die $@ if $@;
- $parser =
new Parse::FixedLength $fixedlength_format
;
+ $parser =
Parse::FixedLength->new($fixedlength_format)
;
}
else {
}
else {
@@
-1843,15
+1850,20
@@
sub batch_import {
next if $line =~ /^\s*$/; #skip empty lines
$line = &{$row_callback}($line) if $row_callback;
next if $line =~ /^\s*$/; #skip empty lines
$line = &{$row_callback}($line) if $row_callback;
+
+ next if $line =~ /^\s*$/; #skip empty lines
$parser->parse($line) or do {
$dbh->rollback if $oldAutoCommit;
$parser->parse($line) or do {
$dbh->rollback if $oldAutoCommit;
- return "can't parse: ". $parser->error_input();
+ return "can't parse: ". $parser->error_input()
. " " . $parser->error_diag
;
};
@columns = $parser->fields();
} elsif ( $type eq 'fixedlength' ) {
};
@columns = $parser->fields();
} elsif ( $type eq 'fixedlength' ) {
+ last unless scalar(@buffer);
+ $line = shift(@buffer);
+
@columns = $parser->parse($line);
} elsif ( $type eq 'xls' ) {
@columns = $parser->parse($line);
} elsif ( $type eq 'xls' ) {
@@
-1911,6
+1923,16
@@
sub batch_import {
}
next if exists( $param->{skiprow} );
}
next if exists( $param->{skiprow} );
+ if ( $preinsert_callback ) {
+ my $error = &{$preinsert_callback}($record, $param);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "preinsert_callback error". ( $line ? " for $line" : '' ).
+ ": $error";
+ }
+ next if exists $param->{skiprow} && $param->{skiprow};
+ }
+
my $error = $record->insert;
if ( $error ) {
my $error = $record->insert;
if ( $error ) {
@@
-2589,6
+2611,20
@@
sub ut_enum {
return "Illegal (enum) field $field: ". $self->getfield($field);
}
return "Illegal (enum) field $field: ". $self->getfield($field);
}
+=item ut_enumn COLUMN CHOICES_ARRAYREF
+
+Like ut_enum, except the null value is also allowed.
+
+=cut
+
+sub ut_enumn {
+ my( $self, $field, $choices ) = @_;
+ $self->getfield($field)
+ ? $self->ut_enum($field, $choices)
+ : '';
+}
+
+
=item ut_foreign_key COLUMN FOREIGN_TABLE FOREIGN_COLUMN
Check/untaint a foreign column key. Call a regular ut_ method (like ut_number)
=item ut_foreign_key COLUMN FOREIGN_TABLE FOREIGN_COLUMN
Check/untaint a foreign column key. Call a regular ut_ method (like ut_number)