Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: GT::SQL::Sets -- Need Some Help

Quote Reply
Re: GT::SQL::Sets -- Need Some Help In reply to
Hi Shetland,

Hopefully this will help, the start of the documentation for GT::Sets.

----------------

Sets.pm

This module allows you to manipulate blocks of records in a database using set operation.

To initialize, you will need to create one GT::SQL::Table object.

Say:

my $entries = $DB->table('user_record_list');

Then:

my $first_set = GT::Sets->new({ db => $entries });

Will create a new Sets object for use.

Two of the simplest functions, copy and remove:

sub cp : copies entries into your table

This function can take different types of parameters. hashref, arrayref, STH, and even a "select" query. You may pass as many arguments as you would like as the method iterates through the parameter list.

1. Hashref

Expected here is a container with all the columns mapped to values. Insert will be called and the record will be added to the table.

2. Arrayref (of hashrefs)

A collection of Hashrefs that will be added to the table.

3. STH

An active sth which will be iterated, where each record retrieved will be entered into the table. Column names must match, though if there are more columns then required, they will be ignored.

4. Query

If a string starting with "select ..." is passed in, it will be appended to a "insert into my_table select ...". You must ensure that the appropropriate SQL syntax is adhered.

sub rm : deletes entries from your table

Like cp, this method can take many different types of arguments: hashref, arrayref, sth.

1. Hashref

Just passes the hash reference to $table->delete()

2. Arrayref (of hashrefs)

Each element will be passed to $table->delete()

3. STH

An active sth which will be iterated, where each record will be passed into $table->delete()

There are also 5 other methods which are a bit more complex and allow even more operations.

sub disjoin

This will take two GT::Sets objects, a and b, and based on the column to compare upon, will remove all matches to b from a and store the result in the local object.

This does require three identically structured tables to exist.., (maybe I should put add a clone table function to GT::SQL). All of the tables must be registered in a GT::Sets object.

Say we have three tables, A, B, and C. C will be an empty table. They each only have one integer column named SIN. How about putting some stuff into A and B like so...

A: 1, 2, 3, 4, 8
B: 1, 5, 8, 9

And C is empty so...,

C:

We have three GT::Sets objects. $a, $b, and $c. If we do the following:

$c->disjoin( 'SIN', $a, $b );

this will disjoin $b from $a and put the results into $c. When this function is completed, $c will contain.

C: 2, 3, 4

If there were records already found in C, the new records will simply be added to the list.

sub subtract
sub intersect
sub union
sub aggregate




Subject Author Views Date
Thread GT::SQL::Sets -- Need Some Help shetland 3941 Jun 10, 2001, 5:27 AM
Thread Re: GT::SQL::Sets -- Need Some Help
Alex 3860 Jun 11, 2001, 3:16 PM
Thread Re: GT::SQL::Sets -- Need Some Help
shetland 3844 Jun 11, 2001, 4:57 PM
Thread Re: GT::SQL::Sets -- Need Some Help
shetland 3828 Jun 12, 2001, 10:42 AM
Post Re: GT::SQL::Sets -- Need Some Help
kitsune 3779 Jun 18, 2001, 3:56 PM