If I understand you correctly, take a look at
tblSync. I wrote this to do table synchronization between heterogeneous databases. I have since added functionality to handle tables w/ no unique keys.
I believe that the following code is what you're after.
# Set up you db connections - my statment handler is $rsth.
# prepare and execute your query etc...
__SNIP___
my $fetch = \&fetch;
$counter = 0;
my @rmaporder = qw|col1 col2 col3|;
my %rdb;
for ( @rmaporder )
{
$counter++;
$rdb{$_} = undef;
$rsth->bind_col( $counter, \$rdb{$_} );
}
my $rkey = 'col1';
# Fetch the data and hold in these hashes
%RemoteDB = $fetch->($rsth, \%rdb, $rkey);
sub fetch
{
my $sth = shift;
my $dbhash = shift;
my $key = shift;
my %DB;
while ( $sth->fetchrow_hashref )
{
# Ensure that ALL data is properly quoted
# using the dbi->quote method
$DB{$dbhash->{$key}}{$_}
= $rdbh->quote($dbhash->{$_}) for keys %$dbhash
}
return %DB or errpt ( 'FATAL', 'Unable to return data from fetch',
+ 'NA', 'NA' );
}
__SNIP__
Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
--Ralph Waldo Emerson
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.