Gossamer Forum
Quote Reply
Add Column
Is there a way just to add columns to a table using the creator subclass?

I don't seem to be able to do it without dropping the table and losing the data, ie...

my $existing_cols = $DB->table('Links')->cols;

my $new_table = $DB->creator('Links');

$new_table->cols( %$existing_cols, %$new_cols );

$new_table->create("force") or return Plugins::MyPlugin->error("Bla...");

Last edited by:

RedRum: Feb 24, 2002, 8:48 AM
Quote Reply
Re: [RedRum] Add Column In reply to
Mmmm I love Links SQL :)

Code:
my $table = $DB->editor('Links');

$table->add_col ('Price',
{
size => 11,
type => 'INT',
view_size => 20,
nice_name => "Price",
regex => '^[\d\.]+$'
}
);

Last edited by:

RedRum: Feb 24, 2002, 8:59 AM
Quote Reply
Re: [RedRum] Add Column In reply to
Ugh...

Im using the following (snippet)...

Code:
my $creator = $DB->creator('MyTable');

$creator->cols (
UserID => {
pos => 1,
type => 'INT',
not_null => 1
},
);

$creator->create("force") or return Plugins::MyPlugin->error("Unable to create: $GT::SQL::error");

.....and....

Code:
my $editor = $DB->editor('Links');

$editor->add_col ('Price',
{
size => 11,
type => 'INT',
view_size => 20,
nice_name => "Price",
regex => '^[\d\.]+$'
}
) or return Plugins::MyPlugin->error("Couldn't create Price col: $GT::SQL::error");

......so why does $editor->add_col keep trying to create the Price column in the "MyTable" table instead of Links?

Last edited by:

RedRum: Feb 24, 2002, 9:17 AM
Quote Reply
Re: [RedRum] Add Column In reply to
printing $editor->{table} prints Links (which is right) Pirate

I tried adding:

$editor->drop_col('Price') or return Plugins::MyPlugin->error("Could not drop Price column: $GT::SQL::error");

....and I got:

Could not drop Price column: Failed to execute query: 'ALTER TABLE lsql_Links DROP Price' Reason: Can't DROP 'Price'.

This is weird.

Last edited by:

RedRum: Feb 24, 2002, 9:26 AM
Quote Reply
Re: [RedRum] Add Column In reply to
Fixed. It was a def problem. I had repaired/resysnc'd but that hadn't fixed it for some reason - had to do it manually.
Quote Reply
Re: [RedRum] Add Column In reply to
Did this fix the problem with $editor adding a column to the wrong table? Seems very strange.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Add Column In reply to
Yes, not sure what happened - probably a freak error.

The price column was still in the def....after removing it, everything worked.