Page 1 of 1

How to add new field to db with Plugin?

Posted: Mon Oct 11, 2010 1:24 pm
by wjstarck
Hello-

I need to add another field to one of my tables in 7.2

The following code adds the field just fine,

Code: Select all

command = "ALTER TABLE anestheticrecord ADD ChangeLog varchar(255)";
DataCore.NonQ(command);
but then attempts to do so everytime the plugin loads, so I get an error that the column already exists. Can you suggest a workaround?

Re: How to add new field to db with Plugin?

Posted: Mon Oct 11, 2010 1:43 pm
by wjstarck
Well, I've found that I can encapsulate it in a try-catch like so:

Code: Select all

try {
command = "ALTER TABLE anestheticrecord ADD ChangeLog varchar(255)";
DataCore.NonQ(command);
}
catch { }
I'll go with that unless you have a cleaner way...

Re: How to add new field to db with Plugin?

Posted: Mon Oct 11, 2010 3:22 pm
by alkhaef
Hmm... As far as I remember, the PluginExample had the outline for the "cleaner way" you're referring to...

Namely, by tracking the version of the current schema, you can alter the table only when you have to "upgrade" to a given version.

Best regards,

Re: How to add new field to db with Plugin?

Posted: Mon Oct 11, 2010 3:49 pm
by wjstarck
Thanks, Al.

I'll have a look....