Follow Me On Twitter Facebook LinkedIn Flickr
Surprisingly I'm rather liking the Amazon elastic compute cloud. Running my first VM instance with my new pet Linux distro ubuntu 10.04 ... 3 weeks ago
A software development and computer technology blog.

Archive for May, 2009

Twitter Weekly Updates for 2009-05-24

Powered by Twitter Tools.

Fleshing out the beast

I’m starting to put the AJAX game framework to the test, and applying it to some game rules. Although currently I’m starting from a higher level not covered by the rules at the moment, which is where individual game instances are created. Whoever is running a particular game instance can set the parameters of the game; starting conditions and victory conditions for instance. Then once the players have joined, the game can begin.

As this system is turn based I intend to allow a turn period to be set as part of the starting parameters. But also provide the option to have this as a maximum turn duration, and process turns as soon as all players have submitted their turn. Since turn processing will take a matter of seconds and the next turn will start once processing has completed, it would actually be possible for all players to be logged in at the same time and submit turn after turn.

Twitter Weekly Updates for 2009-05-17
  • Inspired to XMLHttpRequest like a madman… *gibber* #
  • Toasted ham and poached egg sandwich with herbs and spices and a juicy pear, yum-yum! #
  • Loving the breadmaker! At 30p a loaf and no preservatives or additives, it’s must-have kitchenware! #
  • Off to the garden centre because I am at *that* age now. #
  • A surprise visit to a farm! Fed the goats and donkeys. A cow mooed and Abi cried. #
  • Setting up my new work machine… Where do I insert the punched cards? #
  • Moving the cygwin installation to the new work machine, fingers crossed… #
  • No need to shoot first, and then take names. http://tinyurl.com/oehdln #

Powered by Twitter Tools.

Trigger Happy with MySQL

I have to say I am a rather big fan of db triggers, in an effort to bring some discipline to my databases. Since audit tables have become quite a habit of mine, this is probably my main use for triggers. Although MySQL has a little way to go yet before we have the kind of experience that SQL Server has brought to us in the past, but it’s getting there.

I was surprised to see how little documentation there is on the ‘BEFORE’ and ‘AFTER’ keywords. I was looking for something that would explain to me when I should use each of these, and wherever I found *something* on it, it wasn’t enough.

Through a little bit of testing however, I have found that using ‘AFTER’ delivers desirable results for Inserts, Updates and Deletes. Is it important? Well, considering that after performing the tasks of a ‘BEFORE’ trigger the actual Insert, Update or Delete might fail, but this doesn’t undo the effects of the trigger. Using ‘AFTER’ triggers ensures that the task has completed before we create the audit record.

An example of auditing triggers, for Insert, Update and Delete:


CREATE TRIGGER mytable_audit_trigger_insert
AFTER INSERT ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        NEW.id, NOW(), NEW.name
    );
END;


CREATE TRIGGER mytable_audit_trigger_update
AFTER UPDATE ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        NEW.id, NOW(), NEW.name
    );
END;


CREATE TRIGGER mytable_audit_trigger_delete
AFTER DELETE ON mytable
FOR EACH ROW BEGIN
    INSERT INTO mytable_audit (
        id, date, name
    )
    VALUES(
        OLD.id, NOW(), OLD.name
    );
END;

It would be nice to be able to query/edit triggers, but unfortunately you can only CREATE and DROP them, certainly within the MySQL Query Browser. I’ve not tried any 3rd party tools as I’m happy to keep .sql files, with the details of the CREATE TRIGGER statements so I know what’s in them.

Twitter Weekly Updates for 2009-05-10
  • downloading Amiga software, installing LFS, updating to Drupal 6.11, installing TweetDeck, setting up email accounts. #
  • Just became a wizard of the Lore of Metal \m/, then lost a foot! #

Powered by Twitter Tools.