NAME

DbFramework::Catalog - Catalog class

SYNOPSIS

use DbFramework::Catalog;
my $c = new DbFramework::Catalog($dsn,$user,$password);
$c->set_primary_key($table);
$c->set_keys($table);
$c->set_foreign_keys($dm);

DESCRIPTION

DbFramework::Catalog is a class for manipulating the catalog database used by various DbFramework modules and scripts.

The Catalog

DbFramework retrieves as much metadata as possible using DBI. It aims to store the metadata not provided by DBI in a consistent manner across all DBI drivers by using a catalog database called dbframework_catalog. Each database you use with DbFramework requires corresponding key information added to the catalog. The dbframework_catalog database will be created for each driver you test when you build DbFramework. Entries in the catalog only need to be modified when the corresponding database schema changes.

The following (Mysql) SQL creates the catalog database schema.

	CREATE TABLE c_db (
  	  db_name varchar(50) DEFAULT '' NOT NULL,
  	  PRIMARY KEY (db_name)
	);

	CREATE TABLE c_key (
	  db_name varchar(50) DEFAULT '' NOT NULL,
	  table_name varchar(50) DEFAULT '' NOT NULL,
	  key_name varchar(50) DEFAULT '' NOT NULL,
	  key_type int(11) DEFAULT '0' NOT NULL,
	  key_columns varchar(255) DEFAULT '' NOT NULL,
	  PRIMARY KEY (db_name,table_name,key_name)
	);

	CREATE TABLE c_relationship (
	  db_name varchar(50) DEFAULT '' NOT NULL,
	  fk_table varchar(50) DEFAULT '' NOT NULL,
	  fk_key varchar(50) DEFAULT '' NOT NULL,
	  pk_table varchar(50) DEFAULT '' NOT NULL,
	  PRIMARY KEY (db_name,fk_table,fk_key,pk_table)
	);

	CREATE TABLE c_table (
	  table_name varchar(50) DEFAULT '' NOT NULL,
	  db_name varchar(50) DEFAULT '' NOT NULL,
	  labels varchar(127) DEFAULT '',
	  PRIMARY KEY (table_name,db_name)
	);

The example below shows the creation of a simple Mysql database and the corresponding catalog entries required by DbFramework.

	CREATE DATABASE foo;
        use foo;

	CREATE TABLE foo (
  	  foo integer not null,
	  bar varchar(50),
	  KEY var(bar),
  	  PRIMARY KEY (foo)
	);

	CREATE TABLE bar (
  	  bar integer not null,
	  # foreign key to table foo
	  foo integer not null,
  	  PRIMARY KEY (bar)
	);

	use dbframework_catalog;

	# catalog entry for database 'foo'
	INSERT INTO c_db VALUES('foo');

	# catalog entries for table 'foo'
	INSERT INTO c_table VALUES('foo','foo','bar');
	# primary key type = 0
	INSERT INTO c_key VALUES('foo','foo','primary',0,'foo');
	# index type = 2
	INSERT INTO c_key VALUES('foo','foo','bar_index',2,'bar');

	# catalog entries for table 'bar'
	INSERT INTO c_table VALUES('bar','foo',NULL);
	# primary key type = 0
	INSERT INTO c_key VALUES('foo','bar','primary',0,'bar');
	# foreign key type = 1
	INSERT INTO c_key VALUES('foo','bar','foreign_foo',2,'foo');
	# relationship between 'bar' and 'foo'
	INSERT INTO c_relationship VALUES('foo','bar','foreign_foo','foo');

SUPERCLASSES

DbFramework::Util

CLASS METHODS

new($dsn,$user,$password)

Create a new DbFramework::Catalog object. $dsn is the DBI data source name containing the catalog database (default is 'dbframework_catalog'). $user and $password are optional arguments specifying the username and password to use when connecting to the database.

OBJECT METHODS

set_primary_key($table)

Set the primary key for the DbFramework::Table object $table. The catalog column c_table.labels may contain a colon seperated list of column names to be used as 'labels' (see "new()" in DbFramework::Primary.)

set_keys($table)

Set the keys (indexes) for the DbFramework::Table object $table.

set_foreign_keys($dm)

Set the foreign keys for the DbFramework::DataModel object $dm.

AUTHOR

Paul Sharpe <paul@miraclefish.com>

COPYRIGHT

Copyright (c) 1999 Paul Sharpe. England. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.