X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=e4bc6c562bc4d211a8b7bef05f031f1cefc8e545;hb=5697bba078d6f9e263775bc2d887cc1ce3ff873d;hp=6773487285180f50ddd105238ff47cbe6583927d;hpb=8cbe016ac2c28cd209c48f053f361573368e7988;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 677348728..e4bc6c562 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -577,6 +577,8 @@ sub get_real_fields { qq-( $column $op "" )-; } } + } elsif ( $op eq '!=' ) { + qq-( $column IS NULL OR $column != ? )-; #if this needs to be re-enabled, it needs to use a custom op like #"APPROX=" or something (better name?, not '=', to avoid affecting other # searches @@ -2800,6 +2802,22 @@ sub scalar_sql { defined($scalar) ? $scalar : ''; } +=item count [ WHERE ] + +Convenience method for the common case of "SELECT COUNT(*) FROM table", +with optional WHERE. Must be called as method on a class with an +associated table. + +=cut + +sub count { + my($self, $where) = (shift, shift); + my $table = $self->table or die 'count called on object of class '.ref($self); + my $sql = "SELECT COUNT(*) FROM $table"; + $sql .= " WHERE $where" if $where; + $self->scalar_sql($sql); +} + =back =head1 SUBROUTINES