X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=f6812592f5a90fae144e0d40cf24e0e15b253142;hb=ff40e4713971790ef6e334bfb34c3657b7d23d80;hp=c25b9beb09f87b498d998b3fbcaa1f17fc2cd0e2;hpb=4a54e68baa0fe7c4171d57c3eb0e1579aa21ae77;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index c25b9beb0..f6812592f 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -563,6 +563,17 @@ sub dbdef_table { dbdef->table($table); } +=item primary_key + +Returns the primary key for the table. + +=cut + +sub primary_key { + my $self = shift; + my $pkey = $self->dbdef_table->primary_key; +} + =item get, getfield COLUMN Returns the value of the column/field/key COLUMN. @@ -688,6 +699,8 @@ sub insert { my $self = shift; my $saved = {}; + warn "$self -> insert" if $DEBUG; + my $error = $self->check; return $error if $error; @@ -784,8 +797,7 @@ sub insert { dbh->rollback if $FS::UID::AutoCommit; return dbh->errstr; }; - #$i_sth->execute($oid) or do { - $i_sth->execute() or do { + $i_sth->execute() or do { #$i_sth->execute($oid) dbh->rollback if $FS::UID::AutoCommit; return $i_sth->errstr; }; @@ -974,21 +986,9 @@ returns the error, otherwise returns false. =cut sub replace { - my $new = shift; - my $old = shift; - - if (!defined($old)) { - warn "[debug]$me replace called with no arguments; autoloading old record\n" - if $DEBUG; - my $primary_key = $new->dbdef_table->primary_key; - if ( $primary_key ) { - $old = qsearchs($new->table, { $primary_key => $new->$primary_key() } ) - or croak "can't find ". $new->table. ".$primary_key ". - $new->$primary_key(); - } else { - croak $new->table. " has no primary key; pass old record as argument"; - } - } + my ($new, $old) = (shift, shift); + + $old = $new->replace_old unless defined($old); warn "[debug]$me $new ->replace $old\n" if $DEBUG; @@ -1158,6 +1158,22 @@ sub replace { } +sub replace_old { + my( $self ) = shift; + warn "[$me] replace called with no arguments; autoloading old record\n" + if $DEBUG; + + my $primary_key = $self->dbdef_table->primary_key; + if ( $primary_key ) { + $self->by_key( $self->$primary_key() ) #this is what's returned + or croak "can't find ". $self->table. ".$primary_key ". + $self->$primary_key(); + } else { + croak $self->table. " has no primary key; pass old record as argument"; + } + +} + =item rep Depriciated (use replace instead). @@ -1293,16 +1309,15 @@ null. If there is an error, returns the error, otherwise returns false. =cut +#false laziness w/ut_ipn sub ut_floatn { - my($self,$field)=@_ ; - ($self->getfield($field) =~ /^(\d*)$/ || - $self->getfield($field) =~ /^(-?\d+\.\d+)$/ || - $self->getfield($field) =~ /^(-?\d+)$/ || - $self->getfield($field) =~ /^(-?\d+\.\d+e\d+)$/ || - $self->getfield($field) =~ /^(-?\d+e\d+)$/) - or return "Illegal or empty (float) $field: ". $self->getfield($field); - $self->setfield($field,$1); - ''; + my( $self, $field ) = @_; + if ( $self->getfield($field) =~ /^()$/ ) { + $self->setfield($field,''); + ''; + } else { + $self->ut_float($field); + } } =item ut_snumber COLUMN