How to add new field to db with Plugin?

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
wjstarck
Posts: 949
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

How to add new field to db with Plugin?

Post 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?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA
User avatar
wjstarck
Posts: 949
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

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

Post 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...
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA
alkhaef
Posts: 105
Joined: Fri Jul 02, 2010 10:37 am
Location: Los Angeles, CA

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

Post 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,
Al
Help! I've OD'ed on OD! :)
User avatar
wjstarck
Posts: 949
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

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

Post by wjstarck »

Thanks, Al.

I'll have a look....
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA
Post Reply