Gossamer Forum
Home : Products : DBMan : Customization :

Relational: switch_to_db working & not working!!

Quote Reply
Relational: switch_to_db working & not working!!
Been racking my brain on this one and can't see the problem.

Working on two databases, I'm sucessfully using JPDeni's switch working on the first of my databases. With sub html_add specifying db=first and, in sub html_record_form, switching to the second database to check a value which all works fine.

But working on the second database, with sub html_add_second (which specifies db=second and calls on sub html_record_form_second) while the page displays fine and the debug info confirms I'm working on the second database, the switch (which seems to be defined correctly) gives me an empty field value for all fields I've tested.

Here, I've got:

&switch_to_first;
%rec3 = &get_record($rec{'UserID'});
&switch_to_second;

and db.cgi includes:

sub switch_to_first {
@db_cols = qw(UserID ApproveDisplay AbbreviatedName [etc -- all other field names listed]);
$db_file_name = $db_database_path . "/first.db";
$db_key_pos = 0;
}

sub switch_to_second {
@db_cols = qw(UserID RecordID [etc. all field names specified]);
$db_file_name = $db_database_path . "/second.db";
}



------------------
WYSIWYG

Regn # 1718-00-DB

[This message has been edited by WYSIWYG (edited February 13, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
If you only have two databases, then you need to only use two record hashes, not three.

Try changing the following line:

Code:
%rec3 = &get_record($rec{'UserID'});

to the following:

Code:
%rec2 = &get_record($rec{'UserID'});

Then use $rec2{'FieldName'} to print the field from the second database, and $rec{'FieldName'} to print from the first database.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Thanks, Eliot, for picking up on the error. Unfortunately, working on the second database, the switch is still not functioning to print the content of the "Markets" field from the first database using $rec2{'Markets'}. (This prints just fine using $rec{'Markets'} while working on the first database.)

------------------
WYSIWYG

Regn # 1718-00-DB
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
You need to reverse the switch to print the values from the FIRST database into the SECOND database.

Look at the codes that JPDENI wrote...reverse the switch calls in the sub html_record_second.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
In the first, I've got:

&switch_to_second;
%rec2 = &get_record($rec{'UserID'});
&switch_to_first;

and in the second I've got:

&switch_to_first;
%rec2 = &get_record($rec{'UserID'});
&switch_to_second;

After checking and re-checking back to JPDeni's guidance notes, I'm sure this is right. Yet it doesn't work in the second.

------------------
WYSIWYG

Regn # 1718-00-DB

[This message has been edited by WYSIWYG (edited February 13, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
And in the second routine, you are using $rec{'FieldName'} for fields in the second database and $rec2{'FieldName'} for fields in the first database, right?????????????????

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Sure am!

------------------
WYSIWYG

Regn # 1718-00-DB
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
The only thing I can add is to make sure that your fields are correctly defined on the @db_cols line... this could potentially allow you to access DB2 fields in DB1, but not visa-versa...

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Thanks for the pointer. I've checked this again (twice), but can't see an error. Please allow me post the @db_cols line (for the database that I can't access using the switch) and the db_def from the .cfg file:

@db_cols = qw(UserID ApproveDisplay Abbreviated_name Category DirectoryUserID DirectoryRecordID f6 f7 f8 f9 f10 Services ServicesSuggest Markets MarketsSuggest PlannedMarkets DateSubmitted LastModified OrganisationName YourName YourTitle YourEmail);

%db_def = (
UserID => [ 0, 'alpha', -1, 12, 0, '', ''],
ApproveDisplay => [ 1, 'alpha', -2, 70, 0, 'Y', ''],
Abbreviated_name => [ 2, 'alpha', 40, 25, 1, '', ''],
Category => [ 3, 'alpha', 40, 70, 1, '', ''],
DirectoryUserID => [ 4, 'alpha', 40, 25, 0, '', ''],
DirectoryRecordID => [ 5, 'alpha', 40, 25, 0, '', ''],
f6 => [ 6, 'alpha', 40, 75, 0, '', ''],
f7 => [ 7, 'alpha', 40, 75, 0, '', ''],
f8 => [ 8, 'alpha', 40, 75, 0, '', ''],
f9 => [ 9, 'alpha', 40, 75, 0, '', ''],
f10 => [10, 'alpha', 40, 75, 0, '', ''],
Services => [11, 'alpha', 40, 2000, 0, '', ''],
ServicesSuggest => [12, 'alpha', 40, 400, 0, '', ''],
Markets => [13, 'alpha', 40, 2000, 0, '', ''],
MarketsSuggest => [14, 'alpha', 40, 400, 0, '', ''],
PlannedMarkets => [15, 'alpha', 40, 600, 0, '', ''],
DateSubmitted => [16, 'alpha', -2, 50, 0, &get_date, ''],
LastModified => [17, 'alpha', -2, 50, 0, '', ''],
OrganisationName => [18, 'alpha', 40, 42, 0, '', ''],
YourName => [19, 'alpha', 40, 50, 0, '', ''],
YourTitle => [20, 'alpha', 40, 90, 0, '', ''],
YourEmail => [21, 'alpha', -1, 50, 0, '', '']
);

------------------
WYSIWYG

Regn # 1718-00-DB
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Looks fine to me... going to need to look at your cfg and html files to diagnose further. You might want to post URLs to text versions of these files... also, in your first post, you say you want to pull in relational fields on sub html_add... I take it you mean sub html_record (or sub html_record_long), right?

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)

[This message has been edited by oldmoney (edited February 14, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
s101.cfg wrong... point $db_key and $db_key_track to RecordID, not UserID...

In your html file, I saw that you refer to rec{'Markets'} and rec2{'Markets'}, which I assume is for testing. In practice, the ONLY fields that can have identical names between your DBs in UserID...

As I said to another user, you might want to look at JPDeni's example a little closer... she discuses the key field in depth.

------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)

[This message has been edited by oldmoney (edited February 15, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Thanks for picking up on the $db_key error. I'd used RecordID originally (the only reason for creating this field) and then switched to ensure only 1 record per user. In a previous thread, I'd asked if this is OK and got an affirmative!

And yes, using rec and rec2 on a single field name is just a test in case I'd got the switching confused.

Having corrected the db_key in s101.cfg, and working on the s101 database, my switch to the services database is still not working. I've been over JPDeni's example a dozen times and can't see where I've gone wrong.
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Thanks.

On your second point, I'm calling the "switch to other database" in html_record_form (and the switch the other way round in a variant of this sub-routine).

I really appreciate your offer to look at my adjusted scripts. Text versions of the scripts are at:

http://www.globalcustody.net/read/servicespl.txt
http://www.globalcustody.net/read/servicescfg.txt
http://www.globalcustody.net/read/s101cfg.txt
http://www.globalcustody.net/read/servicesdbcgi.txt

------------------
WYSIWYG

Regn # 1718-00-DB

[This message has been edited by WYSIWYG (edited February 15, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
... and now I think I've solved the problem without risking the database engine falling over!

I've removed the ($restricted=1) line from the sub modify_record in db.cgi (as well as sub get_record which is recommended by JPDeni's notes on the mod). With this change, I manage to make changes to the secondary database (not yet tried to change the first, but presume this will be fine) AND the switch is working in both directions.

Can I just ask if anyone thinks this change might cause another problem -- or is this something that should be done in every case?
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Have you tested this?

One potential problem I see is that users may be able to edit other user's records.

I would suggest thoroughly testing this code hack.

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums

Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
Again...test it...Create a bunch of dummy accounts and then go through the process of adding, modifying, deleting, etc. in each database.

See what happens.

Regards,


------------------
Eliot Lee....
* Check Resource Center
* Search Forums

Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
All seems fine on testing -- perhaps due to the fact that each user can enter only one record in each database. I've dropped the "Add" option from the menu and inserted the following at the top of sub html_home:

$in{$db_key} = $db_userid;
my ($status,@hits) = &query('view');
unless ($status eq 'ok') {
&html_add_form; return;
}

I am concerned that users being able to edit each others' records would prove very embarrassing once we go live on this in a month or two. Do you think my "one record per user" limit means all is well, or should I do something (perhaps to sub html_modify_form?) to avoid the risk entirely.

On the other hand, does the need for my code hack give any clues as to where there's a hiccup in the scripts I've tweaked?

[This message has been edited by WYSIWYG (edited February 20, 2000).]
Quote Reply
Re: Relational: switch_to_db working & not working!! In reply to
My testing worked fine -- the database switch is now fine in both directions.

Also, the previous "modify error -- can't find requested record" no longer appears when editing the secondary database. But if I try to edit the primary database, while the form is filled out fine and the correct database is showing in the debug info, I still get the same "modify error".

Anyone have a clue what's up? Could it be another issue arising because I've combined the "relational database" and "one record per user" mods?



------------------
WYSIWYG

Regn # 1718-00-DB