ALEX::DB - A data store for the Integrated Library System ALEX.
- NAME
- SYNOPSIS
- DESCRIPTION
- METHODS
- Database methods
- RECORD methods
- record_get( $id [, $owner] )
- record_add( $rec [, $owner] )
- record_update( $id, $rec [, $owner] )
- record_delete( $id [, $owner] )
- record_step( $last_record_id [, $owner] )
- record_transfer( $id, $from_wf, $to_wf )
- record_file_count( $filename )
- record_file_import( $filename [, $owner [, $ref_current [, $aref_status, $max, $w]]] )
- record_file_export( $filename, $owner [, @id_list] )
record_tables_create()
record_tables_drop()
- INDEXES
- index_create( $new_index_name, $tag, $subfield, $type, $bIsWorkfile)
- indexes_get( $bIsWorkfile )
- index_stopwords_add( $s )
- index_browse( $limit, $index_name, $key, $pre [, $owner])
- index_search( $index_name, $key, [, $owner] )
- index_clear( $index_name [,$bIsWorkfile] )
- NOTES
- SEE ALSO
- AUTHOR
- COPYRIGHT AND LICENSE
ALEX::DB - A data store for the Integrated Library System ALEX.
use ALEX::DB;
# Connect to the database
my $db = new ALEX::DB("alex") or die $db->errstr;
my $marc;
:
<somehow get a MARC::Record into $marc>
:
# Add a record
my $id = $db->record_add($marc);
# Get it back
my $new_marc = $db->record_get($id);
:
<do funky MARC::Record manipulations>
:
# Update the record
$db->record_update($id, $new_marc) or die $db->errstr;
# Delete a record
$db->record_delete($id) or die $db->errstr;
# Count the records in a file
my $cnt = $db->record_file_count($filename);
# Import a file of records into workfile 3
my $current; # a continuously updated counter
my $cnt = $db->record_file_import($filename, 3, \$current);
ALEX::DB is the generic database-access object for the Integrated
Library System ALEX.
Creates a new database access object, and connects to the database
if given the connection information.
Parameters are passed verbatim to the constructor in the database
implementation layer (e.g. ALEX::DB::PostgreSQL).
Returns the last error string.
Returns the database handle.
Returns an array holding table names.
Returns an array holding database names.
Returns the database connect string
Connect to a database
Parameters are passed verbatim to the constructor in the database
implementation layer (e.g. ALEX::DB::PostgreSQL).
Retrieves a record from the database.
id : id of the record to retrieve
owner: a user id [optional].
If $owner exists, the record is retrieved from that user's workfile rather
than the live database.
Returns undef on error; check $obj->errstr for error message.
Adds a record to the database.
rec : MARC::Record
owner: a user id [optional].
If $owner exists, the record is added to that user's workfile rather
than the live database.
Returns undef on error; check $obj->errstr for error message.
Update a record.
id : id of the record to update
rec : MARC::Record
owner: a user id [optional].
If $owner exists, the record is updated in that user's workfile rather
than the live database.
Returns undef on error; check $obj->errstr for error message.
Deletes a record from the database.
id : id of MARC record to delete.
owner: a user id [optional].
If $owner exists, the record is deleted from that user's workfile rather
than the live database.
Returns undef on error; check $obj->errstr for error message.
Step through the database one record at a time.
last_record_id: the id of the previous record accessed.
owner : 0 - main database
1+ - user id of workfile owner
-1 - all workfiles
Transfer a record between workfiles (or workfile and main)
id : id of the record to update
from_wf: owner id of the workfile to move from (or 0 for main)
to_wf : owner id of the workfile to move to (or 0 for main)
Returns id of the record in the new workfile (or main)
Returns undef on error; check $obj->errstr for error message.
Count the records in a MARC file.
filename : fully-qualified name of file to import.
Returns the count of records in the file.
Returns undef on error; check $obj->errstr for error message.
Import a file of records.
filename : fully-qualified name of file to import.
owner : a user id [optional].
ref_current: reference to an int to hold current count while processing,
suitable for use in a progress bar, etc. [optional].
aref_status: reference to an array to hold title-in-progress [optional]
max : maximum number of elements to have in the aref_status array
w : Tk window (ie - for progressbar, we need to $w->update())
If $owner exists, the record is added to that user's workfile rather
than the live database.
Returns the count of records imported.
Returns undef on error; check $obj->errstr for error message.
Export records to a file.
filename: fully-qualified name of file to import.
owner : a user id (or 0 for main).
id_list : a list of id number to export (or undef for all).
If $owner is non-zero, the records are exported from that user's
workfile rather than the main database.
Returns the count of records exported.
Returns undef on error; check $obj->errstr for error message.
Create the database tables - should only be invoked when creating a
new, empty backend database!
Returns undef on error; check $obj->errstr for error message.
Toast the database tables - should only be invoked when... well, never
in real life :-)
Returns undef on error; check $obj->errstr for error message.
Create a new (empty) index.
new_index_name: what to call it
tag : which MARC tag to index (eg: 245 for Title),
can use '6..' to mean all 600 fields.
subfield : within that tag, which subfield to index.
type : (b)rowse or (k)eyword
bIsWorkfile : 0 - live database index
non-zero - workfile index
For example, to create an index called "title_keyword", indexing tag 245
subfield 'a', as a keyword index, on the main database:
$db->index_create( "title_keyword", "245", "a", "k", 0 )
Returns a reference to an array containing the indexes. Each array
element is a hash containing 'tag', 'subfield', 'index_name', and
'index_type' (where 'index_type' is either 'b' (browse) or 'k' (keyword).
bIsWorkfile: 0 - get main index list
not-zero - get workfile index list
Add a word to the 'stopword' table (ie - words that get ignored in
keyword indexing).
Return a list of records in index order.
limit : number of records to return
index_name: name of the index we're browsing
key : value to browse on
pre : number of records *before* the key to start at
owner : 0 - live database
non-zero - workfile for that particular user id
For example, to return a browse list of twenty titles (5 before and
14 after) around the title, "The Case for Mars", from the live database:
$db->index_browse( 20, "title", "The Case for Mars", 5, 0 )
Return a list of records matching a search term.
index_name: the index to search
key: the value to search for
owner: 0 - main database
non-zero - indicates which workfile to search (user id)
Returns a maximum of 100 matching records (completely arbitrary number....)
Removes all records from an index.
Please read the README... many test cases will be skipped
if you don't set up a testing database!
Take a look in the pl/ directory for some sample code (including
'edit.pl', which uses Tk::MARC to build a database-backed
MARC editor, and 'search.pl', which is a simple cataloguing
module).
ALEX::DB::PostgreSQL
ALEX::DB::PostgreSQL::Records
MARC::Record
MARC::Descriptions
Tk::MARC
David A. Christensen, DChristensenSPAMLESS@westman.wave.ca
Copyright 2004 by David A. Christensen
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
|