I’m currently on my way to write a web application implementing the MVC and well reducing complex things. Yet I’ve been pondering for a few hours what to do for future database systems like Oracle, PostgreSQL, Firebird, etc.
Then again to implement these adapters in the logic is what gets me, should I just trigger-happy it with tons of SWITCHes? What can I do in this situation?
The typical answer to this is to use the ORM functionality in your framework. You can either treat your models as dataobjects or you could use some composition and let models have data objects. Either way, your data objects should be fairly abstract and mainly compile DB queries queries using methods – like the Zend framework does it with the Select object. This allows you to a) keep sql out of your objects and b) replace the objects that actually produce your sql.
So, if you data objects all inherit from the same base ORM class, this base class can be given a DB object that it sends queries to. If you swing it right, the ORM base class will be ignorant of the type of DB class: the data object compiles a select object and hands it over to the DB object that then interprets it in whichever way it finds best.
And the short answer: no, don’t use a bunch of switch statements 🙂