Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Yet Another Half Perl Half mySQL Question

by Brovnik (Hermit)
on Jul 06, 2001 at 17:49 UTC ( #94462=note: print w/replies, xml ) Need Help??

in reply to Yet Another Half Perl Half mySQL Question

This is what I used for a module written recently.

Table Creation :

$sql = "CREATE TABLE depend (\ usedby VARCHAR(80) NOT NULL ,\ uses VARCHAR(80) NOT NULL \ )"; $dbh->do($sql);
Then INSERT rows. And later, to access :
$sql = "SELECT usedby FROM depend where uses=$name"; $aref = $dbh->selectall_arrayref($sql); my @uses = map {$_->[0]} @$aref; $sql = "SELECT uses FROM depend where usedby=$name"; $aref = $dbh->selectall_arrayref($sql); my @usedby = map {$_->[0]} @$aref;
Note that the table is created without unique IDs or primary keys since this is a many-to-many relationship. One of the columns could be an IP address in your case.

For the pedants, there is replication of the name in the columns, but the duplication is outweighed by the ease of access (see how easy in lines of code it is to retrieve a list of names) and reduction in complexity by not having a name-to-id mapping.

BTW, the previous iteration of the module used a single entry in another table and used join/split, which is quicker, but less elegant in DB terms.

If you need raw speed, use Perl to do the split, if you want it cleaner and more DBish, use a table as above.

Full module is Depend::Module

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://94462]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-04-22 18:55 GMT
Find Nodes?
    Voting Booth?