DAViCal Dollar Token Database Write Problem

During the testing of my public DAViCal server I noticed a very strange phenomenon. This phenomenon wasn't present in my localhost system which had passed all my testing. Any rate, when I attempted to PUT a calendar .ics file into the PostgreSQL database, the caldav_data table / caldav_data column was being mangled.

This was occurring for all of my calendar files, so at least the error was consistent. My calendar files SHOULD look like (snipped for brevity):

CALSCALE:GREGORIAN
METHOD:PUBLISH
PRODID:Data::ICal 0.15
VERSION:2.0
X-WR-CALNAME:Barrow
BEGIN:VEVENT
CATEGORIES:http://www.badzilla.co.uk\x5c;SPORT\x5c;FOOTBALL\x5c;Barrow

But, I was actually seeing this being written:
BEGIN$1
CALSCALE$2
METHOD$3
PRODID$4::ICal 0.15
VERSION$5.0
X-WR-CALNAME$6
BEGIN$7
CATEGORIES$8://www.badzilla.co.uk\;SPORT\;FOOTBALL\;Barrow

If you look closely you'll see that somehow the colon characters are being replaced by dollar-number tokens in the form $n. How strange is that?

After many, many hours of attempting to track down the bug by littering trace comments all over the code, I noted that as close to the actual db write as possible, when the execution is in AwlQuery.php, the code was still ok.

    if ( isset($c->expand_pdo_parameters) && $c->expand_pdo_parameters ) {
      if ( isset($this->bound_parameters) ) {
        error_log("AwlQuery. bound_parameters exist");
        $this->bound_querystring = $this->connection->ReplaceParameters($this-
>querystring,$this->bound_parameters);
        //printf(
"\n=============================================================== OQ\n%s\n",
$this->querystring);
error_log("Final query is {$this->bound_querystring}");    // TRACE HERE

This trace was giving the perfect output:
Final query is INSERT INTO caldav_data ( user_no, dav_name, dav_etag,
caldav_data, caldav_type, logged_user, created, modified, collection_id,
weak_etag )
            VALUES( 1001, '/Football/AFCWimbledon/Barrow.ics', '72d2aa993d0ba362aa9a39e61a47dc44', E'BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:PUBLISH
PRODID:Data::ICal 0.15
VERSION:2.0
X-WR-CALNAME:Barrow
BEGIN:VEVENT

So the error must be either in the AwlDBDialect.php code, the PDO code, or the PostgreSQL database itself. After posting a message on the DAViCal list I quickly got a response. Apparently, there is a version discrepancy between the awl package and PHP. PHP on hosted servers tends to be old and stable, whilst PHP on enthusiasts machines tends to be more recent. The code had been written for the latest versions and as consequence a dependency had been overlooked. I am running PHP 5.2.12 whilst my host is running 5.2.9.

The work around is to install the latest development version of AwlDBDialect.php which can be downloaded from http://repo.or.cz/w/awl.git. You will need to download the entire tarball, but I would caution against installing all the files. I merely copied over AwlDBDialect.php and everything was fine!