[freeside-commits] branch master updated. a1c46091ebd0cc17bcbe19be266dc2efa9f2d92b

Mark Wells mark at 420.am
Fri Dec 12 16:02:03 PST 2014


The branch, master has been updated
       via  a1c46091ebd0cc17bcbe19be266dc2efa9f2d92b (commit)
      from  f48943ca9b3d280919d5e2d4cb6880ea8f095d7b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a1c46091ebd0cc17bcbe19be266dc2efa9f2d92b
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Dec 12 16:01:48 2014 -0800

    use the mysql equivalent of array_to_string, #32548

diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index a667f4e..9fa8296 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -32,7 +32,8 @@ our @encrypt_payby = qw( CARD DCRD CHEK DCHK );
 #export dbdef for now... everything else expects to find it here
 our @EXPORT_OK = qw(
   dbh fields hfields qsearch qsearchs dbdef jsearch
-  str2time_sql str2time_sql_closing regexp_sql not_regexp_sql concat_sql
+  str2time_sql str2time_sql_closing regexp_sql not_regexp_sql
+  concat_sql group_concat_sql
   midnight_sql
 );
 
@@ -3568,6 +3569,24 @@ sub concat_sql {
 
 }
 
+=item group_concat_sql COLUMN, DELIMITER
+
+Returns an SQL expression to concatenate an aggregate column, using 
+GROUP_CONCAT() for mysql and array_to_string() and array_agg() for Pg.
+
+=cut
+
+sub group_concat_sql {
+  my ($col, $delim) = @_;
+  $delim = dbh->quote($delim);
+  if ( driver_name() =~ /^mysql/i ) {
+    # DISTINCT(foo) is valid as $col
+    return "GROUP_CONCAT($col SEPARATOR $delim)";
+  } else {
+    return "array_to_string(array_agg($col), $delim)";
+  }
+}
+
 =item midnight_sql DATE
 
 Returns an SQL expression to convert DATE (a unix timestamp) to midnight 
diff --git a/FS/FS/Report/Tax.pm b/FS/FS/Report/Tax.pm
index 43337a6..76012fb 100644
--- a/FS/FS/Report/Tax.pm
+++ b/FS/FS/Report/Tax.pm
@@ -2,7 +2,7 @@ package FS::Report::Tax;
 
 use strict;
 use vars qw($DEBUG);
-use FS::Record qw(dbh qsearch qsearchs);
+use FS::Record qw(dbh qsearch qsearchs group_concat_sql);
 use Date::Format qw( time2str );
 
 use Data::Dumper;
@@ -113,7 +113,8 @@ sub report_internal {
       $select .= "NULL AS $_, ";
     }
   }
-  $select .= "array_to_string(array_agg(DISTINCT(cust_main_county.taxnum)), ',') AS taxnums, ";
+  $select .= group_concat_sql('DISTINCT(cust_main_county.taxnum)', ',') .
+             ' AS taxnums, ';
   $group =~ s/, $//;
 
   # SELECT/GROUP clauses for second-level (totals) queries
@@ -124,7 +125,8 @@ sub report_internal {
     $select_all = "SELECT $breakdown{pkgclass} AS pkgclass, ";
     $group_all = "GROUP BY $breakdown{pkgclass}";
   }
-  $select_all .= "array_to_string(array_agg(DISTINCT(cust_main_county.taxnum)), ',') AS taxnums, ";
+  $select_all .= group_concat_sql('DISTINCT(cust_main_county.taxnum)', ',') .
+                 ' AS taxnums, ';
 
   my $agentnum;
   if ( $opt{agentnum} and $opt{agentnum} =~ /^(\d+)$/ ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Record.pm     |   21 ++++++++++++++++++++-
 FS/FS/Report/Tax.pm |    8 +++++---
 2 files changed, 25 insertions(+), 4 deletions(-)




More information about the freeside-commits mailing list