X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=758e0f96c42e1266200b33506fc26996e27275ea;hp=9a99aebe725f1d63d401015435dcb6aae6c342e1;hb=b1d445f94514a29e5d4753839798b0291d89aee3;hpb=b63800b2aaca886ae42c0f61f83ae2e2f0b4c44f diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 9a99aebe7..758e0f96c 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -2,18 +2,26 @@ package FS::Record; use strict; use vars qw( $AUTOLOAD @ISA @EXPORT_OK $DEBUG - $me %virtual_fields_cache $nowarn_identical ); + $conf $conf_encryption $me + %virtual_fields_cache + $nowarn_identical $nowarn_classload + $no_update_diff $no_check_foreign + ); use Exporter; use Carp qw(carp cluck croak confess); +use Scalar::Util qw( blessed ); use File::CounterFile; use Locale::Country; +use Text::CSV_XS; +use File::Slurp qw( slurp ); use DBI qw(:sql_types); -use DBIx::DBSchema 0.25; +use DBIx::DBSchema 0.38; use FS::UID qw(dbh getotaker datasrc driver_name); +use FS::CurrentUser; use FS::Schema qw(dbdef); use FS::SearchCache; use FS::Msgcat qw(gettext); -use FS::Conf; +#use FS::Conf; #dependency loop bs, in install_callback below instead use FS::part_virtual_field; @@ -22,20 +30,36 @@ use Tie::IxHash; @ISA = qw(Exporter); #export dbdef for now... everything else expects to find it here -@EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch); +@EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch + str2time_sql str2time_sql_closing regexp_sql not_regexp_sql ); $DEBUG = 0; $me = '[FS::Record]'; $nowarn_identical = 0; +$nowarn_classload = 0; +$no_update_diff = 0; +$no_check_foreign = 0; my $rsa_module; my $rsa_loaded; my $rsa_encrypt; my $rsa_decrypt; +$conf = ''; +$conf_encryption = ''; FS::UID->install_callback( sub { - $File::CounterFile::DEFAULT_DIR = "/usr/local/etc/freeside/counters.". datasrc; + eval "use FS::Conf;"; + die $@ if $@; + $conf = FS::Conf->new; + $conf_encryption = $conf->exists('encryption'); + $File::CounterFile::DEFAULT_DIR = $conf->base_dir . "/counters.". datasrc; + if ( driver_name eq 'Pg' ) { + eval "use DBD::Pg ':pg_types'"; + die $@ if $@; + } else { + eval "sub PG_BYTEA { die 'guru meditation #9: calling PG_BYTEA when not running Pg?'; }"; + } } ); =head1 NAME @@ -80,8 +104,11 @@ FS::Record - Database record objects $value = $record->unique('column'); $error = $record->ut_float('column'); + $error = $record->ut_floatn('column'); $error = $record->ut_number('column'); $error = $record->ut_numbern('column'); + $error = $record->ut_snumber('column'); + $error = $record->ut_snumbern('column'); $error = $record->ut_money('column'); $error = $record->ut_text('column'); $error = $record->ut_textn('column'); @@ -132,7 +159,8 @@ sub new { unless ( defined ( $self->table ) ) { $self->{'Table'} = shift; - carp "warning: FS::Record::new called with table name ". $self->{'Table'}; + carp "warning: FS::Record::new called with table name ". $self->{'Table'} + unless $nowarn_classload; } $self->{'Hash'} = shift; @@ -192,27 +220,33 @@ objects. The preferred usage is to pass a hash reference of named parameters: - my @records = qsearch( { - 'table' => 'table_name', - 'hashref' => { 'field' => 'value' - 'field' => { 'op' => '<', - 'value' => '420', - }, - }, - - #these are optional... - 'select' => '*', - 'extra_sql' => 'AND field ', - #'cache_obj' => '', #optional - 'addl_from' => 'LEFT JOIN othtable USING ( field )', - } - ); + @records = qsearch( { + 'table' => 'table_name', + 'hashref' => { 'field' => 'value' + 'field' => { 'op' => '<', + 'value' => '420', + }, + }, + + #these are optional... + 'select' => '*', + 'extra_sql' => 'AND field = ? AND intfield = ?', + 'extra_param' => [ 'value', [ 5, 'int' ] ], + 'order_by' => 'ORDER BY something', + #'cache_obj' => '', #optional + 'addl_from' => 'LEFT JOIN othtable USING ( field )', + 'debug' => 1, + } + ); Much code still uses old-style positional parameters, this is also probably fine in the common case where there are only two parameters: my @records = qsearch( 'table', { 'field' => 'value' } ); +Also possible is an experimental LISTREF of PARAMS_HASHREFs for a UNION of +the individual PARAMS_HASHREF queries + ###oops, argh, FS::Record::new only lets us create database fields. #Normal behaviour if SELECT is not specified is `*', as in #C