B
Bigus
Has anyone had probs adding columns to a table using DBI and the ALTER TABLE
command?
I've been sending the command in a loop that processes some key/value pairs,
checks if the column already exists and if not attempts to create it:
foreach my $k(keys %keyvals){
my $result = $db->do("DESCRIBE list_headers '$k'");
logit("Failed to describe column $k ".$db->errstr,0) if $db->errstr ;
if($result != 1){
$db->do("ALTER TABLE list_headers ADD '$k' TEXT");
logit("Failed to add column $k ".$db->errstr,1) if $db->errstr ;
}
}
The error that's returned is:
DBD::mysql::db do failed: You have an error in your SQL syntax; check
the manual
that corresponds to your MySQL server version for the right syntax to
use near
''owner' TEXT' at line 1 at header.pl line 44.
That's where $k = "owner". If I remove the single quotes round $k in teh
ALTER TABLE line then the owner column is created fine, but of course it
then falls over when $k = "reply-to" because of the hyphen.
When I use PHPMyadmin to create the owner column it works fine and tells me
it's used the syntax:
ALTER TABLE `list_headers` ADD `owner` TEXT
I've tried using the prepare & execute method but it falls over with
exactly the same error.
This sounds like a MySQL problem to me but if that's the case why does
PHPMyadmin work? Anyone had this prob and got round it?
Bigus
command?
I've been sending the command in a loop that processes some key/value pairs,
checks if the column already exists and if not attempts to create it:
foreach my $k(keys %keyvals){
my $result = $db->do("DESCRIBE list_headers '$k'");
logit("Failed to describe column $k ".$db->errstr,0) if $db->errstr ;
if($result != 1){
$db->do("ALTER TABLE list_headers ADD '$k' TEXT");
logit("Failed to add column $k ".$db->errstr,1) if $db->errstr ;
}
}
The error that's returned is:
DBD::mysql::db do failed: You have an error in your SQL syntax; check
the manual
that corresponds to your MySQL server version for the right syntax to
use near
''owner' TEXT' at line 1 at header.pl line 44.
That's where $k = "owner". If I remove the single quotes round $k in teh
ALTER TABLE line then the owner column is created fine, but of course it
then falls over when $k = "reply-to" because of the hyphen.
When I use PHPMyadmin to create the owner column it works fine and tells me
it's used the syntax:
ALTER TABLE `list_headers` ADD `owner` TEXT
I've tried using the prepare & execute method but it falls over with
exactly the same error.
This sounds like a MySQL problem to me but if that's the case why does
PHPMyadmin work? Anyone had this prob and got round it?
Bigus