diff options
author | Mark Wells <mark@freeside.biz> | 2014-12-12 16:01:48 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-12-12 16:01:48 -0800 |
commit | a1c46091ebd0cc17bcbe19be266dc2efa9f2d92b (patch) | |
tree | 00da82f60e9eeb1b960f071283e72427a5127a93 /FS/FS/Record.pm | |
parent | f48943ca9b3d280919d5e2d4cb6880ea8f095d7b (diff) |
use the mysql equivalent of array_to_string, #32548
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r-- | FS/FS/Record.pm | 21 |
1 files changed, 20 insertions, 1 deletions
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 |