X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=4efaeffdc121c50090b0054a8117f9727de8cbe2;hb=a014f2e125028a5a80c0587f36df5e865b70b47f;hp=ba03091523015fc30581c60ac16cb20d435cd154;hpb=633c48448d9468690b7ad77eb6ff7c660a286658;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index ba0309152..4efaeffdc 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. @@ -677,6 +688,24 @@ sub modified { $self->{'modified'}; } +=item select_for_update + +Selects this record with the SQL "FOR UPDATE" command. This can be useful as +a mutex. + +=cut + +sub select_for_update { + my $self = shift; + my $primary_key = $self->primary_key; + qsearchs( { + 'select' => '*', + 'table' => $self->table, + 'hashref' => { $primary_key => $self->$primary_key() }, + 'extra_sql' => 'FOR UPDATE', + } ); +} + =item insert Inserts this record to the database. If there is an error, returns the error, @@ -688,6 +717,8 @@ sub insert { my $self = shift; my $saved = {}; + warn "$self -> insert" if $DEBUG; + my $error = $self->check; return $error if $error; @@ -784,8 +815,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; }; @@ -1297,16 +1327,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