Gossamer Forum
Quote Reply
Table creator ?
Alex,

A few things don't seem to be documented in the help. From the spider plugin:

Code:
# --------- Hosts Table ----------------
$self->debug( "Creating Hosts table" ) if ($self->{_debug});
my $c = $DB->creator($prefix.'Hosts');
$c->cols (
ID => { pos => 1, type => 'INT', not_null => 1, unsigned => 1, regex => '^\d+$' },
Hostname => { pos => 2, type => 'CHAR', size => 100, not_null => 1 },
Robot => { pos => 3, type => 'TEXT' },
Last_Hit_Tic => { pos => 4, type => 'INT', unsigned => 1 },
Hits_Interval => { pos => 5, type => 'INT', unsigned => 1 },
Banned => { pos => 6, type => 'ENUM', values => ['Yes', 'No'], not_null => 1, default => 'No' },
Descend_Only => { pos => 7, type => 'ENUM', values => ['Yes', 'No'], not_null => 1, default => 'No' },
Status => { pos => 8, type => 'INT', not_null => 1, unsigned => 1, regex => '^\d+$' },
Max_Depth => { pos => 9, type => 'INT', unsigned => 1 },
);
$c->pk('ID');
$c->ai('ID');
$opts->{hosts_subclass} and $c->subclass( $opts->{hosts_subclass} );
$c->index({
hstndx => [ 'Hostname' ]
});
if ($c->create($action,$opts->{action_opts})) { $err{'Hosts'} = 'OK' }
else {
$err{'Hosts'} = $GT::SQL::error;
$c->save_schema();
}


$c = $DB->creator($prefix.'Hosts');

Is it still necessary to use $prefix? Or does it get used automatically now?

What is the subclass function? Also, when would you want to use this form of the creator, rather than the form that was used in the search logger:

Code:


if (! $c2->create()) {
$GT::SQL::errcode ||= ''; #silence -w, ugh.
$GT::SQL::errcode eq 'TBLEXISTS' ? ($message = "Could not create table SearchLogDaily (table already exists)\n") :
($error = "Could not create table SearchLogDaily: $GT::SQL::error)");
$c2->set_defaults();
$c2->save_schema();
};


I'm trying to figure this out, but seem there is a lot of catching up to do :)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Table creator ? In reply to
Hi,

No, the prefix is not neccessary. It's used in the spider as it's double prefixed (i.e. your prefix is lsql_, well the spider will use lsql_Spider_Hosts). Not really something anyone else needs to worry about.

subclass tells GT::SQL to load a custom .pm module. So when you do:

my $table = $DB->table('Foo');

and Foo has subclass('Bar') defined on it, $table is now a Bar object and not a GT::SQL::Table object.

The reason for doing this is so you can customize functions. i.e. if you want to do something every time an insert happens, you can use subclass, and create your own insert function. Look at User.pm as an example of a subclass in Links SQL.

The last step is no longer neccessary any more.

Cheers,

Alex
--
Gossamer Threads Inc.