Keeping an enum and a table in sync
- by MPelletier
I'm making a program that will post data to a database, and I've run into a pattern that I'm sure is familiar: A short table of most-likely (very strongly likely) fixed values that serve as an enum. So suppose the following table called Status:
Status
Id Description
--------------
0 Unprocessed
1 Pending
2 Processed
3 Error
In my program I need to determine a status Id for another table, or possibly update a record with a new status Id.
I could hardcode the status Id's in an enum and hope no one ever changes the database. Or I could pre-fetch the values based on the description (thus hardcoding that instead).
What would be the correct approach to keep these two, enum and table, synced?