I'm working on a replication between heterogenous data sources program. I
seem to be so close, all transactions are well tracked, and everything seems
to be good in that respect, but in querying the recorded transactions from
the publisher, and putting those values into the subscriber I am running
into a problem with the columns getting out of order. Am I using the wrong
type of data structure here? Someone give me some feedback:
<aside> I am writing this from home, I work on this project at work. the
code I am giving here is hend typed into the e-mail, so I'm not going back
to use strict or -w, and I might miss a semicolon, but the part I am having
trouble with is between binding and execute, and the concept I am using to
get it there.</aside>
#after tracking database has been queried for transactions,
# and tables with replicatable transactions are identified, and
# table structure has been determined by queries to system catalogues.
$select = qq{SELECT
$columnlist
FROM $table
WHERE $where};
my $values = ",?"x scalar(@columns);
$values =~ s/,//;
my $insert = qq{INSERT INTO $repldb.$dbo.$table
($columnlist)
VALUES
($values)};
$subscrh = $subscriber->prepare($insert) || die qq(Can't
prepare\n$insert\n$subscriber::errstr\n};
$selecth = $publisher->prepare($select) || die qq{Can't
prepare\n$select\n$publisher::errstr\n};
$selecth->execute() || die qq{Can't execute\n$select\n$publisher::errstr\n};
my ($row, @valarray);
$selecth->bind_columns(undef,(\@valarray[0 .. scalar(@columns)-1]));
while ($row = $selecth->fetchrow_arrayref) {
$subscrh->execute(@valarray[0 .. scalar(@columns)-1])) || die qq{Can't
execute\n$insert\n$subscrh::errstr};
}
########################
I thought I was binding an ordered array, but it errors out usually giving a
type mismatch or truncation error. When I print this out, I find that
print @valarray[0..scalar(@columns)-1];
doesn't usually print the values in the order I expected them to be in the
array, so I can only assume that varchar values are trying to be inserted
into datetime columns etc.
What am I misunderstanding? How would I keep them in the same order between
binding and inserting?
Thanks in advance,
Steve Howard
Sr. DBA DTO.