6 use FS::UID qw(adminsuidsetup dbh driver_name);
8 # Remove trailing whitespace from custom field option lists and values.
10 my $dbh = adminsuidsetup(shift) or die "Usage: rt-trim-whitespace username\n";
11 die "rt-trim-whitespace only works on Pg databases" if driver_name ne 'Pg';
14 customfieldvalues => 'name',
15 objectcustomfieldvalues => 'content',
19 my $table = shift @updates;
20 my $field = shift @updates;
22 "SELECT $field FROM $table WHERE $field != substring($field from ".
23 q!E'^(.*\\\\S)\\\\s*$'! . ')';
26 my $rows = $dbh->do($select);
27 print "$rows rows found.\n";
31 "UPDATE $table SET $field = substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')'.
32 " WHERE $field != substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')';
34 my $rows = $dbh->do($update);
35 print "$rows updated.\n";
38 $dbh->commit or die $dbh->errstr;