Gossamer Forum
Home : Products : Gossamer Links : Pre Sales :

Pugdog! Please help!

Quote Reply
Pugdog! Please help!
Hi Pugdog,
as you have written, itīs no problem for you to call two databases from your first links; so please, please tell me how.
Im still suck at

sub connect {
# ---------------------------------------------------------------
# Connects to the SQL server.
#
# IN : DBI connect string and table name (optional)
# OUT: 1 on success, undef on connect error.
#
defined $DBH and $_[0]->{db_driver} and return 1;

I cant find any "if then" to know, if the last connect goes to the same db as the actuall;
if i could get it somehow, everything is clear.

At the moment i could solve this only if the Database B is the last connect;
then i could write:

if passed db_name = first_db then return; else go on.

But this fails if i call A, B then again A, cause at the last the "if then" is true and the old connection is used.

Im sitting here now since 12 hours and cant fix it, so please drop me a note how you have done this.

Robert





Quote Reply
Re: Pugdog! Please help! In reply to
Ok, as I've said, I've done it differently than you, under different circumstances, but I am using one database to store the postcards, but the postcards records require accessing the Links:Links table, to store the records in the Postcards:Cards table.

I created two database objects, since MySQL can only work with one database at a time. You can force it to work with two by using two object references, and using fully qualified table names.

I've not quite fully grasped what you are trying to do, with two databases, Sun/Mon are my two "family" days, so I tend to be in fog.

You can open two different database handles by calling

my $db1 = (new Links::DBSQL '/path/to/links/def_1/Links.def');
my $db2 = (new Links::DBSQL '/path/to/links/def_2/Links.def');

Now, $db1 and $db2 will be handles to different databases inside the MySQL database.

One of the unclean things about this, is you've opened a handle, and given it a table, but you've _really_ only opened up a DataBase Handle, with the additional parameter of some table defaults.

What that means, is that you can access pretty much any table in the $db1 and $db2 using that handle, since the "SELECT" and other statements work on TABLES _IN_ A DATABASE.

So, using $db1 you'll work on database1 and using $db2 you'll work on database2.

You can _force_ the handles to open other databases (I _THINK_ by fully qualifying the database/tables such as database1.table1.field1 and datbase2.table1.field1) but, the handle is still for that one database, making an external call to the "other" database.

As I said, this is somewhat unclean, and I guess it would be akin to using "undocumented" features of a program.

This is why I've been waiting for next release so impatiently, since I am hoping with the new MySQLMan and other programs, that the calling conventions have been cleaned up.

One thing you might do is look around on the net for code for managing multiple SQL databases. There might be code fragments around in some of the archives for DBI and DBD that give examples of how to step through and manipulate multiple databases.

Early on I did a short piece of code that stepped through the database, and listed each of the databases, each of the tables in each database, and each of the fields in each table. So, I know you can connect to multiple databases, and use multiple tables across each database, but you _must_ keep track of what you are pointing to, and what your "current" database is if you don't use the fully qualified table names (database.tablename)

I know this probably didn't help much, but I'll think about it some morelater and see if anything else hits me.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/