On 6/8/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:
Hi all, this class that I have written lists the contents of a "log" table
when the $log->view method is invoked.  There is some hardcoded SQL in this
method and all I do is pass it a number which then looks up the relevant
records.  This really isn't a reusable class as far as I understand it
because it assumes that anyone else using it would have a log table with
various fields of a certain name defined.  How can I make this completely
reuseable, should it be documented saying that you need to create a log
table with various fields before using it or should I code it so that the
table name and fields have to be passed in and the script would then take
care of it?


Your thoughts and comments are as always - appreciated.


Cheers,

G :)


Interesting. Reusable by who? Is it part of a package you're going to
distribute? is there an included mypkg.sql file they have to run?

Typically, package installs come with a config file where a user can
specify tablename_prefix. so it would be pretty seamless if all they
had to do was edit mypkg.conf and change:
table_prefix = mypkg_

so then "log_table" would become "mypkg_log_table", while columns
would remain the same.
You could have your module simply read the config file inside the
implementation of $log->view();

The table structure(s) should stay the same, but give them a chance to
override the table names incase they collide with pre-existing tables.

I've found this to be the best way to ensure not dropping tables on
accident, especially if you load an sql file with "drop table foo if
foo exists". I almost did that at work the other day on a table with 1
character diff in the name (i was lucky, and added dp_ to all my table
namespaces).



--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to