+
+ if ( $self->option('query_style') eq 'detailed' ) {
+
+ while (my $row = $sth->fetchrow_hashref) {
+ if (exists $row->{amount}) {
+ if ( $row->{amount} eq '' ) {
+ # treat as zero
+ } elsif ( $row->{amount} =~ /^\d+(?:\.\d+)?$/ ) {
+ $price += $row->{amount};
+ } else {
+ die "sql_external query returned non-numeric amount: $row->{amount}";
+ }
+ }
+ if (defined $row->{quantity}) {
+ if ( $row->{quantity} eq '' ) {
+ # treat as zero
+ } elsif ( $row->{quantity} =~ /^\d+$/ ) {
+ $quantity += $row->{quantity};
+ } else {
+ die "sql_external query returned non-integer quantity: $row->{quantity}";
+ }
+ }
+
+ my $detail = FS::cust_bill_pkg_detail->new;
+ foreach my $field (@detail_cols) {
+ if (exists $row->{$field}) {
+ $detail->set($field, $row->{$field});
+ }
+ }
+ if (!$detail->get('detail')) {
+ die "sql_external query did not return detail description";
+ # or make something up?
+ # or just don't insert the detail?
+ }
+
+ push @$details, $detail;
+ } # while $row
+
+ } else {
+
+ # simple style: returns only a single value, which is the price
+ $price += $sth->fetchrow_arrayref->[0];
+
+ }