Developing software in the Real World

ADOdb Data Dictionary

CMS Made Simple (CMSMS) uses ADOdb for database abstraction. This is a good thing from my point of view as we use ADOdb at work so I don’t have any paradigm shifts to worry about. When writing my modules for CMSMS I discovered ADOdb’s data dictionary system. This allows you to create and edit tables in a cross-database manner. For instance:

This code creates a simple table for storing categories in any supported database. CMSMS uses it so that a module can create it’s own tables in Install() and then remove them again in Uninstall(). There is also a function Upgrade() which I’d never used before (having got my DB tables right first time!)

Whilst developing the Calendar module, I had a need to alter the database table structure that held an event. A feature request came in asking for “from” and “to” dates for each event rather than just a single date.”Aha!” thought I; a chance to play with some more data dictionary functions. (Actually, I wondered if I could just require users to dump their data as it’s only a 0.2 release, then I relented!)

Having decided to manipulate the table, I worked out that I needed to add a new timestamp field called event_date_end and rename my event_date field to event_date_start. I wandered over to the ADOdb Data Dictionary manual to find out what I could do. As with the main documentation, it’s very well written and easy to understand (with examples!). I quickly discovered RenameColumnSQL() and AddColumnSQL() were what I wanted.

Thus the Upgrade code is:

How easy is that?

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *