class DBIAccessor

Synopsis

See the sample program.

Description

DBIAccessor is a glue class between the DBBackedClass object space and the database itself. While rarely used directly, it provides the engine for DBBackedClasses to reconstitute instances from data in the database, create new database records from new instances, and delete existing instances from the database.

Class Methods

DBIAccessor.new(dbh, query_strings)

Constructs a new DBIAccessor instance, talking to the database attached to the DBI database handle dbh with the query strings being a hash of tags to parameterized SQL query strings. This allows DBIAccessor to be database independent, in the true spirit of DBI. Want to backend with a different DB? Just drop in a new set of query strings and pass a database handle to that new database.

Instance Methods

You will probably never use any of these directly. Rather they get called by instances of DBBackedClass.

DBIAccessor#selexec2(stmt, *params)

Execute the statement stmt with the parameters params (an arbitrary number of parameters to the method). Results are return as an array of rows. Each row is a hash of keys (field names) to values.

DBIAccessor#selexec(query, *params)

This is similar to DBIAccessor#selexec2 only query is the shorthand tag for one of the queries in the query string hash. The appropriate query is looked up and then it and the parameters are passed to selexec2.

DBIAccessor#listByType(klass, modifier=nil)

List all instances of type klass where klass is an instance of Class. Optionally modifier may be a non-null string modifying the query. An array of results is returned.

DBIAccessor#lookupByTypeAndID(klass, record_id)

Lookup a particular instance/record from the table klass by record ID where klass is an instance of Class. Return the result as an array of rows where each row is a hash of key (field name) => value.

DBIAccessor#lookupByAttributes(object)

Given an object object, we try to find all rows that look like it (by looking at the attributes that are actually defined for object). Return the results as an array of rows where each row is a hash of key (field name) => value.

DBIAccessor#lookupLastInsert(object)

Lookup the last record insert into the table which stores instances of the same class as object. Used internally by DBIAccessor.

DBIAccessor#insert(object)

Insert object into the table. Fails if an instance with the same record ID already exists.

DBIAccessor#update(object)

Update object in the database.

DBIAccessor#delete(object)

Delete object from the database.