Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Synchronizing constants/enums in database and code

by liz (Monsignor)
on Apr 11, 2004 at 11:35 UTC ( [id://344243]=note: print w/replies, xml ) Need Help??


in reply to Synchronizing constants/enums in database and code

I would go for 5:

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.

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 } }
That should ensure that your constants are up to date for each run, as opposed to each build/test cycle.

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
    The solution that you gave is one for case #4. Which is fine, as long as you don't have a lot of data to load at the start of the program. There is also the case where we're using other data structures from other languages (enums were mentioned). I'm no C wizard, but I don't know whether or not you can define an enum at run time.

    thor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://344243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-26 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found