in reply to Synchronizing constants/enums in database and code
5. Keep the official enumeration in the database; query the database to generate code that contains appropriate constants/enums. Have to make sure your code generation really occurs when the database changes. Could automate this as part of the build/test process.
But please note that you don't need to do this as part of the build/test process, but you can also do this at compile time in a BEGIN block.
That should ensure that your constants are up to date for each run, as opposed to each build/test cycle.BEGIN { use DBI; my $dbh = DBI->connect( dsn,user,password ); my $result = $dbh->some sort of query that generates name/value pa +irs; no strict 'refs'; # allow for using variables to make subs foreach (@$result) { *{$_->[0]} = eval "sub () { $_->[1] }"; # use constant on vari +ables } }
Liz
Update:
As thor pointed out, this could be construed as going with #4, but I was more thinking along the lines of SHOW COLUMNS FROM table LIKE 'columnname' and associated magic as can e.g. be found on the MySQL site.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Synchronizing constants/enums in database and code
by thor (Priest) on Apr 11, 2004 at 13:27 UTC |