Tuesday, April 22, 2008

Holiday week

It's Passover week, and my company has decided to close down, forcing everyone to take four days holiday. Some people are only too delighted to do so (one man was telling me how he is taking his entire family to Eilat for the holiday, which makes life much easier on his wife), whereas I tend to find little to do during such weeks.

I have been buying via e-bay dvds of the excellent British series "Cold Feet" for very low prices, and so this week has been an opportunity to watch them. I have the entire series on videotape, but I don't think that I've ever watched all of them in continuity (although I did see all the episodes twice on tv). There is a limit to how much emotion one can take in a day.

Regarding the computer, I haven't been doing much programming at home in the past few weeks as my psychologist friend has been on holiday. I thought that I would get back into the swing of things yesterday by programming a quick demo of something that we've been talking about but has been left aside as there have been more important things to do.

Then popped into my head the idea of writing a command line interface (CLI) for the databases. I use Borland's "Desktop database" program, but this is concerned primarily with describing a database (ie defining the tables in the database and defining the fields within each table) and
the possibilities of editing the data are very limited. I wrote a program which allows me to do three different kinds of operation:
  • meta-queries (list of tables in database, structure of table)
  • 'select' queries, which can be simple ones about one table, or complex joins
  • updates and deletions
Basically the program consists of a text parser and an sql engine; if the first word in the text stream is one of those connected with a meta-query, then the program executes this command. Otherwise all the text is passed to a 'query' component which is then executed and the results displayed.

The whole thing took about two hours to write and works well enough for what I need. The parser could do with improving, which is hardly surprising as it was written ad hoc without any prior thought, but it's ok. As it's only for my use, I'm not going to bamboozle it with improper commands.

Anyway, the reason for this program is that the demo which I wrote requires that values within a field in one of the tables be changed. Instead of doing this manually via Desktop Database, or writing a program which executes the 'update' queries, I thought that this CLI approach would be better as it is of course re-usable.

No comments: