Here's (kind of) what I would do. Everything I do is explained in more detail in the DBI docs. Definitely read the section on placeholders. Not only does it handle quoting for you, it makes this easier by predefining an array with your column names.
I'm guessing the column names in the 1st DB are the same as the second DB.
## UNTESTED
## Setup the column names - This way when you need to change it, you o
+nly change in one place
## The column names will also stay in order
my @col_names = qw/reg pat ped adnasec impexp cveped adnaent cr
+upimp rfcimp curpaa/;
my $col_names_string = join(',',@col_names);
my $dbhX1 = DBI->connect('dbi:XBase(RaiseError=1):');
my $select1 = $dbhX1->prepare("SELECT $col_names_string FROM r501");
$select1->execute();
## Now we create the string with placholders.
my $placeholders = join(',',map { '?' } @col_names );
my $sql = "INSERT INTO r501 ( $col_names_string ) VALUES ( $placehold
+ers )";
## We are going to call this quite a bit so lets prepare it out side o
+f the loop
my $sth = $mysql_dbh1->prepare( $sql );
while ( my @row = $select1->fetchrow_array() ){
## Stick the result in the other database
$sth->execute(@row);
}
grep
One dead unjugged rabbit fish later...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|