Class AddressDB

Summary

The AddressDB class provides an addressbook-oriented interface to the address book database. In particular, all SQL commands are hidden within this class.

The addressbook database table must be created and properly configured before using this class! The following SQL commands can be used with PostgreSQL to build the database table:

 SET search_path = public, pg_catalog;

 CREATE FUNCTION plpgsql_call_handler () RETURNS language_handler
     AS '/usr/lib/pgsql/plpgsql.so', 'plpgsql_call_handler'
        LANGUAGE c;

 CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler;

 CREATE TABLE addressbook (
     name character varying(64),
     address text,
     email character varying(64),
     phone character varying(64),
     company character varying(64),
     misc text,
     category character varying(128)
     );

 CREATE FUNCTION insertabook () RETURNS "trigger"
     AS '
         DECLARE a_rec record;
         BEGIN
             SELECT * INTO a_rec FROM addressbook WHERE name=new.name;
             IF NOT FOUND THEN RETURN new;
             ELSE UPDATE addressbook SET address=new.address,email=new.email,
                                         phone=new.phone,
                                         company=new.company,misc=new.misc,
                                         category=new.category
                                     WHERE name=new.name;
                  RETURN null;
             END IF;
         END;'
     LANGUAGE plpgsql;

 CREATE TRIGGER trigger_insert
     BEFORE INSERT ON addressbook
     FOR EACH ROW
     EXECUTE PROCEDURE insertabook ();

Access to this database table must be made available through Unicon's ODBC support.

Superclasses:
Object

Package:
addressbook
File:
addressdb.icn
Methods:
isValid, loadView, performSearch, reload, remove, setCatCondition, setCondition, storeAddress

Methods inherited from Object:
Type, className, clone, equals, fieldNames, genMethods, getField, get_class, get_class_name, get_id, hasField, hasMethod, hash_code, instanceOf, invoke, is_instance, setField, to_string

Fields:
criteria, db, order, tablName

Source code.

Details
Constructor

AddressDB(user, passwd, dsn, tabl:"addressbook")

Parameters:
user
database user name
passwd
database password for user
dsn
ODBC dsn. Defaults to user
tabl
database table access. Defaults to "addressbook"

Attach to a database and attach to the addressbook table, if possible.

Methods:

isValid(s)

Parameter:
s
string to check
Returns:
s if valid
Fails:
if s is null or empty [except for whitespace]

Check a string to see if it can be used in an SQL WHERE clause (non-null, non-empty).


loadView(criteria, order:"name")

Parameters:
criteria
SQL query criteria (for WHERE clause)
order
sort results by this field. Default is "name"
Returns:
an AddressView of all addresses matching criteria

Produce an AddressView matching some criteria from the DB.


performSearch(addr)

Parameter:
addr
used as key for search. All addresses matching the the information in addr are returned.
Returns:
AddressView for matching addresses

Given a record that represents the search criteria, returns a view of all addresses matching that criteria


reload()

Returns:
reloaded AddressView

Reload based on the last view's criteria


remove(addr)

Parameter:
addr
address to remove
Returns:
result of attempting the removal of addr

Remove an address from the database


setCatCondition(wc, cats, terminator:"\n")

Parameters:
wc
existing WHERE clause
cats
set of categories to use in condition
terminator
terminate for a category, default is \n
Returns:
modified WHERE clause with new conditions added

Search conditions on categories have to take into account the special formatting of the category column in the database. This method does so.


setCondition(wc, id, test, value)

Parameters:
wc
existing WHERE clause
id
name of field to test
test
comparison operation, eg: "="
value
the field given by id is tested against this value
Returns:
modified WHERE clause with new condition added

Add a condition to the SQL WHERE clause, if the test value is valid.


storeAddress(addr)

Parameter:
addr
address to store

Store an Address into the DB.


Fields:
criteria

db

order

tablName


This page produced by UniDoc on 2021/04/15 @ 23:59:53.