Class AddressDB |
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.
Details |
Constructor |
AddressDB(user, passwd, dsn, tabl:"addressbook")
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: |
s | string to check |
s if valid |
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")
criteria | SQL query criteria (for WHERE clause) |
order | sort results by this field. Default is "name" |
an AddressView of all addresses matching
criteria |
Produce an AddressView matching some criteria from the DB.
addr | used as key for search. All addresses matching
the the information in addr are returned. |
AddressView for matching addresses |
Given a record that represents the search criteria, returns a view of all addresses matching that criteria
reloaded AddressView |
Reload based on the last view's criteria
addr | address to remove |
result of attempting the removal of addr |
Remove an address from the database
setCatCondition(wc, cats, terminator:"\n")
wc | existing WHERE clause |
cats | set of categories to use in condition |
terminator | terminate for a category, default is \n |
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)
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 |
modified WHERE clause with new condition added |
Add a condition to the SQL WHERE clause, if the test value is valid.
addr | address to store |
Store an Address into the DB.
Fields: |