MySQL RENAME TABLE error


J

John

Hi

This is just a snip of a program I don't know if it's a Perl or MySQL
problem
Basically, there is a list of tables in the array 'all'.
Prioblem = the program will create backups of all except the first table.
I can re-arrange the tables in the array 'all', but the first one still does
not get a backup created.

Any ideas?
John




for (my $j=0; $j<$total; $j++) {
my $table=$all[$j] ;
create_MySQL ($table)
}

sub create_MySQL {
my ($table)[email protected]_;
my $backup='old_' . $table;

# backup existing table
my ($dbh,$sql,$sth);
$dbh=$library->MySQL_connection;
print "<hr>$table<hr>";
$sql="DROP TABLE IF EXISTS $backup"; $sth=$dbh->prepare($sql);
$sth->execute or die "Unable to execute query: $dbh->errstr<br>";
$sql="RENAME TABLE $table TO $backup"; $sth=$dbh->prepare($sql);
$sth->execute or die "Unable to execute query: $dbh->errstr<br>";
 
Ad

Advertisements

S

smallpond

Hi

This is just a snip of a program  I don't know if it's a Perl or MySQL
problem
Basically, there is a list of tables in the array 'all'.
Prioblem = the program will create backups of all except the first table.
I can re-arrange the tables in the array 'all', but the first one still does
not get a backup created.

Any ideas?
John

Somewhere above, you need to have:

use warnings;
use strict;

Otherwise everyone on this group will be mad at you.
for (my $j=0; $j<$total; $j++) {
    my $table=$all[$j] ;
    create_MySQL ($table)

}

Perl arrays know how big they are, so there is no need
for a separate variable $total.

This code is ok, but a more perlish way to write it would be:

foreach my $table (@all) {
create_MySQL($table);
}

 sub create_MySQL {
      my ($table)[email protected]_;
     my $backup='old_' . $table;

      # backup existing table
      my ($dbh,$sql,$sth);
      $dbh=$library->MySQL_connection;
     print "<hr>$table<hr>";

Add delimiters around the name so you know there aren't extra chars:
print said:
      $sql="DROP TABLE IF EXISTS $backup"; $sth=$dbh->prepare($sql);
      $sth->execute or die "Unable to execute query: $dbh->errstr<br>";
      $sql="RENAME TABLE $table TO $backup"; $sth=$dbh->prepare($sql);
     $sth->execute or die "Unable to execute query: $dbh->errstr<br>";

Certainly looks like the perl is ok. Questions:
1) Is the first table appearing in the html output?
2) If so, how do you know the backup is not being created?
 
S

smallpond

This is just a snip of a program  I don't know if it's a Perl or MySQL
problem
Basically, there is a list of tables in the array 'all'.
Prioblem = the program will create backups of all except the first table.
I can re-arrange the tables in the array 'all', but the first one stilldoes
not get a backup created.
Any ideas?
John

Somewhere above, you need to have:

use warnings;
use strict;

Otherwise everyone on this group will be mad at you.
for (my $j=0; $j<$total; $j++) {
    my $table=$all[$j] ;
    create_MySQL ($table)

Perl arrays know how big they are, so there is no need
for a separate variable $total.

This code is ok, but a more perlish way to write it would be:

foreach my $table (@all) {
  create_MySQL($table);

}
 sub create_MySQL {
      my ($table)[email protected]_;
     my $backup='old_' . $table;
      # backup existing table
      my ($dbh,$sql,$sth);
      $dbh=$library->MySQL_connection;
     print "<hr>$table<hr>";

Add delimiters around the name so you know there aren't extra chars:
      print "<hr>::$table::<hr>";
^^
not a good choice for delimiters. with more coffee i would say:
 
Ad

Advertisements

J

John

This is just a snip of a program I don't know if it's a Perl or MySQL
problem
Basically, there is a list of tables in the array 'all'.
Prioblem = the program will create backups of all except the first
table.
I can re-arrange the tables in the array 'all', but the first one still
does
not get a backup created.
Any ideas?
John

Somewhere above, you need to have:

use warnings;
use strict;

Otherwise everyone on this group will be mad at you.
for (my $j=0; $j<$total; $j++) {
my $table=$all[$j] ;
create_MySQL ($table)

Perl arrays know how big they are, so there is no need
for a separate variable $total.

This code is ok, but a more perlish way to write it would be:

foreach my $table (@all) {
create_MySQL($table);

}
sub create_MySQL {
my ($table)[email protected]_;
my $backup='old_' . $table;
# backup existing table
my ($dbh,$sql,$sth);
$dbh=$library->MySQL_connection;
print "<hr>$table<hr>";

Add delimiters around the name so you know there aren't extra chars:
print "<hr>::$table::<hr>";
^^
not a good choice for delimiters. with more coffee i would say:
Certainly looks like the perl is ok. Questions:
1) Is the first table appearing in the html output?
2) If so, how do you know the backup is not being created?

Hi

OK. Many thanks. I know there is no backup as I use PhpMyAdmin - a nice
GUI - to look at the tables.
So I now know it's a MySQL problem. I least I know where to look.

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top