Header

ALEX::DB - A data store for the Integrated Library System ALEX.


NAME

ALEX::DB - A data store for the Integrated Library System ALEX.


SYNOPSIS

 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);


DESCRIPTION

ALEX::DB is the generic database-access object for the Integrated Library System ALEX.


METHODS

Database methods

new( [dbname [,name [,password [, ... ]]] )

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).

errstr()

Returns the last error string.

dbh()

Returns the database handle.

tables()

Returns an array holding table names.

data_sources()

Returns an array holding database names.

backend()

Returns the database connect string

connect( dbname [,name [,password [, ... ]]] )

Connect to a database

Parameters are passed verbatim to the constructor in the database implementation layer (e.g. ALEX::DB::PostgreSQL).

RECORD methods

record_get( $id [, $owner] )

  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.

record_add( $rec [, $owner] )

  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.

record_update( $id, $rec [, $owner] )

  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.

record_delete( $id [, $owner] )

  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.

record_step( $last_record_id [, $owner] )

 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

record_transfer( $id, $from_wf, $to_wf )


 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.

record_file_count( $filename )

 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.

record_file_import( $filename [, $owner [, $ref_current [, $aref_status, $max, $w]]] )

 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.

record_file_export( $filename, $owner [, @id_list] )

 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.

record_tables_create()

  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.

record_tables_drop()

  Toast the database tables - should only be invoked when... well, never
  in real life :-)
  Returns undef on error; check $obj->errstr for error message.

INDEXES

index_create( $new_index_name, $tag, $subfield, $type, $bIsWorkfile)

 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 )

indexes_get( $bIsWorkfile )

 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

index_stopwords_add( $s )

 Add a word to the 'stopword' table (ie - words that get ignored in
 keyword indexing).

index_browse( $limit, $index_name, $key, $pre [, $owner])

 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 )

index_search( $index_name, $key, [, $owner] )

 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....)

index_clear( $index_name [,$bIsWorkfile] )

 Removes all records from an index.


NOTES

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).


SEE ALSO

 ALEX::DB::PostgreSQL
 ALEX::DB::PostgreSQL::Records
 MARC::Record
 MARC::Descriptions
 Tk::MARC


AUTHOR

David A. Christensen, DChristensenSPAMLESS@westman.wave.ca


COPYRIGHT AND LICENSE

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.

Copyright (c) 2004, David A. Christensen