Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

How to use existing routines

Quote Reply
How to use existing routines
Alex,

I'm really trying to grasp how things are done in the program, but so much of this is new (including SQL) that I'm failing on several points.

One is how to use DBSQL.pm . It would be better for any modifications to use that interface, since they would survive upgrades better, and cause less conflicts (hopefully).

Could you explain the order of using your DBSQL.pm to handle calls to the database?
For example: When would I need to create a new object, vs using one that had been created? Can I create a new object in a subroutine, rather than using an existing one?) When is connect() called vs 'new' and what is the advantage of passing it parameters since most calls seem to be without them?

If I wanted to create a subroutine in one of the callable programs (add.cgi, search.cgi, etc) to do something extra, what would the order of operations be to connect to the database, prepare a query, execute it, and handle the results?

I had hoped by now there'd be some discussion here on how to start to modify it, but the silence is deafening.
Quote Reply
Re: How to use existing routines In reply to
I started something at:

www.gossamer-threads.com/scripts/resources/Detailed/552.html

To give you an overview about how to use the module. As for the specifics:

Quote:
When would I need to create a new object, vs using one that had been created?

Creating an object carries a small bit of overhead in loading the .def file, but all the objects share the same database connection. It's really a tough call. If it's not something that's being done in a loop, it will be clearer if you create a new object for whichever table you are working on.

Quote:
Can I create a new object in a subroutine, rather than using an existing one?)

Yes, definately! You only carry the overhead of loading a new .def file.

Quote:
When is connect() called vs 'new'

Connect is only called when the first object needs to access the database. So just by creating an object, you won't connect to the database. You only connect when you access data.

Disconnect is called when the script ends.

Quote:
If I wanted to create a subroutine in one of the callable programs (add.cgi, search.cgi, etc) to do something extra, what would the order of operations be to connect to the database, prepare a query, execute it, and handle the results?

You would:

1. Create an object:

my $db = new Links: BSQL '/path/to/file.def';

2. Prepare a query:

my $sth = $db->prepare($query);

3. Execute it:

$sth->execute();

$sth is a normal DBI statement handle. Connection/Disconnection are handled behind the scenes by the module.

Alternatively you can use the built in add/remove/modify/search functions described in the URL above.

I hope this helps, and if you have any questions (or anyone else does) please don't hesitate to ask.

Cheers,

Alex



[This message has been edited by Alex (edited August 17, 1999).]
Quote Reply
Re: How to use existing routines In reply to
Many thanks!

I've been working through this, and it's starting to make a little sense.

Default variables make it hard to follow sometimes.

With most programming languages, you have to actually code what you're doing. With Perl you can do all sorts of stuff without ever explicitly saying anything.