FS::Record - Database record objects
use FS::Record; use FS::Record qw(dbh fields qsearch qsearchs dbdef);
$record = new FS::Record 'table', \%hash; $record = new FS::Record 'table', { 'column' => 'value', ... };
$record = qsearchs FS::Record 'table', \%hash; $record = qsearchs FS::Record 'table', { 'column' => 'value', ... }; @records = qsearch FS::Record 'table', \%hash; @records = qsearch FS::Record 'table', { 'column' => 'value', ... };
$table = $record->table; $dbdef_table = $record->dbdef_table;
$value = $record->get('column'); $value = $record->getfield('column'); $value = $record->column;
$record->set( 'column' => 'value' ); $record->setfield( 'column' => 'value' ); $record->column('value');
%hash = $record->hash;
$hashref = $record->hashref;
$error = $record->insert; #$error = $record->add; #depriciated
$error = $record->delete; #$error = $record->del; #depriciated
$error = $new_record->replace($old_record); #$error = $new_record->rep($old_record); #depriciated
$value = $record->unique('column');
$value = $record->ut_float('column'); $value = $record->ut_number('column'); $value = $record->ut_numbern('column'); $value = $record->ut_money('column'); $value = $record->ut_text('column'); $value = $record->ut_textn('column'); $value = $record->ut_alpha('column'); $value = $record->ut_alphan('column'); $value = $record->ut_phonen('column'); $value = $record->ut_anythingn('column');
$dbdef = reload_dbdef; $dbdef = reload_dbdef "/non/standard/filename"; $dbdef = dbdef;
$quoted_value = _quote($value,'table','field');
#depriciated $fields = hfields('table'); if ( $fields->{Field} ) { # etc.
@fields = fields 'table'; #as a subroutine @fields = $record->fields; #as a method call
(Mostly) object-oriented interface to database records. Records are currently implemented on top of DBI. FS::Record is intended as a base class for table-specific classes to inherit from, i.e. FS::cust_main.
Note that the object stores this hash reference, not a distinct copy of the hash it points to. You can ask the object for a copy with the hash method.
TABLE can only be omitted when a dervived class overrides the table method.
###oops, argh, FS::Record::new only lets us create database fields.
#Normal behaviour if SELECT is not specified is `*', as in
#SELECT * FROM table WHERE ...
. However, there is an experimental new
#feature where you can specify SELECT - remember, the objects returned,
#although blessed into the appropriate `FS::TABLE' package, will only have the
#fields you specify. This might have unwanted results if you then go calling
#regular FS::TABLE methods
#on it.
$record->column('value')
is a synonym for $record->set('column','value');
To make a distinct duplicate of an FS::Record object, you can do:
$new = new FS::Record ( $old->table, { $old->hash } );
Takes an optional two-letter ISO country code; without it or with unsupported countries, ut_phonen simply calls ut_alphan.
reload_dbdef([FILENAME])
It returns a hash-type list with the fields of this record's table set true.
$Id: Record.html,v 1.1 2001-07-30 07:36:03 ivan Exp $
This module should probably be renamed, since much of the functionality is of general use. It is not completely unlike Adapter::DBI (see below).
Exported qsearch and qsearchs should be depriciated in favor of method calls (against an FS::Record object like the old search and searchs that qsearch and qsearchs were on top of.)
The whole fields / hfields mess should be removed.
The various WHERE clauses should be subroutined.
table string should be depriciated in favor of FS::dbdef_table.
No doubt we could benefit from a Tied hash. Documenting how exists / defined true maps to the database (and WHERE clauses) would also help.
The ut_ methods should ask the dbdef for a default length.
ut_sqltype (like ut_varchar) should all be defined
A fallback check method should be provided which uses the dbdef.
The ut_money method assumes money has two decimal digits.
The Pg money kludge in the new method only strips `$'.
The ut_phonen method assumes US-style phone numbers.
The _quote function should probably use ut_float instead of a regex.
All the subroutines probably should be methods, here or elsewhere.
Probably should borrow/use some dbdef methods where appropriate (like sub fields)
As of 1.14, DBI fetchall_hashref( {} ) doesn't set fetchrow_hashref NAME_lc, or allow it to be set. Working around it is ugly any way around - DBI should be fixed. (only affects RDBMS which return uppercase column names)
the DBIx::DBSchema manpage, the FS::UID manpage, DBI
Adapter::DBI from Ch. 11 of Advanced Perl Programming by Sriram Srinivasan.