Hello, I'm in a situation where I have several database tables with identical structure (please don't ask me why), the application at runtime decides from which table to query. I'm using Class::DBI to map to the same perl classes. In my application code, I simply call the table() method
before querying. This seems to be fine, except that if I query two tables with the same id, I got the same result. Is that a bug? or I'm doing something wrong?
Let me be more specific, say I have two tables Foo and Bar, each has the same columns: id, name. I have a standard perl object mapping to the table:
package FooBar;
use strict;
use base 'Class::DBI';
FooBar->set_db('Main','dburl','user','password');
FooBar->table('Foo'); # Foo is the default table
FooBar->columns(Primary=> qw/id/ );
FooBar->columns(Other=> qw/name/ );
package main;
my $foo = FooBar->retrieve(1);
print $foo->name(), "\n";
FooBar->table('Bar'); #switch table
my $bar1 = FooBar->retrieve(1); # this give the same as $foo, it shoul
+dn't.
my $bar2 = FooBar->retrieve(2); # this is different
and if I skip the first query, then $bar1 and $bar2 are correct.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.