This article is more than 1 year old

The database abstraction framework strikes back

Part 2: C++ Generic Coding

The (potentially) finished framework starts here!

So, here's the code we've generated, complete with a makefile and a vc project file. If you're not convinced, then compile the associated code and run it against a database! If people are interested, this is an open source project (available on SourceForge.net here), as I've implied already; and if anyone wants to help with the transition from a prototype to a real tool then let me know.

The example implementations are in terms of the MySQL database, but they could equally well be implemented in terms of any other interface library, or a database independent interface library – the dependency on MySQL is hidden in the generated cpp files so the database dependency is localised. For the example project, we've submitted the generated code to cvs, but for a real project this would, of course, be questionable.

The link to the Dbi generated source files is here and to the library support code here.

There are some unanswered questions here because of space constraints, so if you find that any of the answers to those posed below would be interesting, please comment or email the author and let us know (comments are, usually, automatically published; emails to the author are only published with explicit permission). We'll probably make them part of future articles. Some possible issues are:

  • How do we ensure that there are no memory leaks given that all the objects are allocated on the heap?
  • Can we do this generically instead of polymorphically?
  • How can we expand this approach to many-to-many relationships?
  • How can we support late binding of objects associated by relationships?
  • How can we support the notion of a strong relationship so that one object exists if and only if another corresponding object exists?
  • How can we expand this approach so as to catch as many breaches of database constraints as possible at compile time? [A "proper" relational database will, of course, enforce such constraints automatically at every access; although some – many - implementations may not – Ed]

More about

TIP US OFF

Send us news


Other stories you might like