Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > MySQL RENAME TABLE error

Reply
Thread Tools

MySQL RENAME TABLE error

 
 
John
Guest
Posts: n/a
 
      10-17-2009
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)=@_;
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>";


 
Reply With Quote
 
 
 
 
smallpond
Guest
Posts: n/a
 
      10-17-2009
On Oct 17, 8:09*am, "John" <(E-Mail Removed)> wrote:
> 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)=@_;
> * * *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>";

> * * * $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?
 
Reply With Quote
 
 
 
 
smallpond
Guest
Posts: n/a
 
      10-17-2009
On Oct 17, 3:59*pm, smallpond <(E-Mail Removed)> wrote:
> On Oct 17, 8:09*am, "John" <(E-Mail Removed)> wrote:
>
> > 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 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)=@_;
> > * * *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:
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>";

>
> 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?


 
Reply With Quote
 
John
Guest
Posts: n/a
 
      10-19-2009

"smallpond" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Oct 17, 3:59 pm, smallpond <(E-Mail Removed)> wrote:
> On Oct 17, 8:09 am, "John" <(E-Mail Removed)> wrote:
>
> > 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)=@_;
> > 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:
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>";

>
> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql::Error Table doesn't exist Michael Furmaniuk Ruby 1 04-08-2009 05:40 PM
How rename table thru VS2008 Server Explorer? Cirene ASP .Net 3 05-12-2008 11:26 PM
using mysql client to read a file to create a table in a database in a mysql server julian Ruby 8 04-06-2006 10:29 AM
Table/table rows/table data tag question? Rio HTML 4 11-05-2004 08:11 AM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM



Advertisments