« SubCategories 1.0 Release Candidate 3 | Main | CommentThreads is working! »

June 12, 2004

Getting Postgres and Movable Type to play well together

There is a bug in Movable Type: only single values (i.e scalar references) can be stored with MT::PluginData when used with a PostgreSQL database. Complex values (i.e. non-scalar references) can be stored with MySQL however, because MySQL allows binary data in its text columns (I would consider that incorrect behavior myself). PostgreSQL does not. So, to fix the problem, the binary data that the Storable perl module outputs needs to be converted to text before reaching the database. To do this, I made use of pack and unpack to trasform the data to and from hexadecimal before it gets to the database itself. I also needed to be sure to preserve any existing data already stored in the database.

The updated data method of MT::PluginData looks like this:

sub data {
    my $data = shift;
    $data->column('data', unpack ("H*", freeze(shift))) if @_;
    my $r;
    eval {
        $r = thaw($data->column('data'));
    };
    $r = thaw(pack ("H*", $data->column('data'))) if ($@);
    $r;
}

Posted by rayners at June 12, 2004 01:38 AM

Trackback Pings

TrackBack URL for this entry:
http://mt.rayners.org/mt-tb.cgi/307

Listed below are links to weblogs that reference Getting Postgres and Movable Type to play well together:

» MT and Blacklist from Strang's Blog
Is there anybody out there that has got Blacklist to run with MovableType 3.11? I run MT against PostgreSQL and I get some annoying error messages: Can't call method "param" on an undefined value at lib/Blacklist/App.pm line 583. Use of uninitialized v... [Read More]

Tracked on September 12, 2004 08:25 AM

» MT and Blacklist from Strang's Blog
Is there anybody out there that has got Blacklist to run with MovableType 3.11? I run MT against PostgreSQL and I get some annoying error messages: Can't call method "param" on an undefined value at lib/Blacklist/App.pm line 583. Use of uninitialized v... [Read More]

Tracked on September 12, 2004 08:27 AM

» MT 3.11, MTB 2.01 and PostgreSQL from Cliff's Weblog
There seems to be a bug in MT 3.11's MT::PluginData that breaks MT::Blacklist if you use PostgreSQL. MT's authors are using an (what I call) flaw in MySQL that makes MySQL let you store binary data in an text field.... [Read More]

Tracked on September 13, 2004 05:26 AM

» changing more MT source from daily babble
I've been having a problem with MT-Blacklist 2.x for a while now; it stopped saving my preferences. After loads of fruitless and frustrated (and frustrating) Google and code searches, I finally found an oblique reference to the same problem with... [Read More]

Tracked on December 17, 2004 02:25 PM

» Movable Type + PostgreSQL from Wesley Miaw - Blog
I've been searching for a reason Movable Type didn't seem to want to play nice with PostgreSQL. (I prefer PostgreSQL to MySQL for databases where things are going to be changing somewhat often. Some will argue PostgreSQL is a real... [Read More]

Tracked on January 29, 2005 04:19 PM

» Movable Type + PostgreSQL from Wesley Miaw - Blog
I've been searching for a reason Movable Type didn't seem to want to play nice with PostgreSQL. (I prefer PostgreSQL to MySQL for databases where things are going to be changing somewhat often. Some will argue PostgreSQL is a real... [Read More]

Tracked on January 29, 2005 04:32 PM

» MT::PluginData and postgresql from Daniel J. Luke's Weblog
I was wondering why the plugin I've modified to help prevent comment and trackback spam wasn't saving its cache properly.... [Read More]

Tracked on February 24, 2005 04:12 PM

Comments

Arg, I was so hopeful that this would fix the problem I was having with rebuilding my index since I had tried everything else!!

Storable binary image v35.65 more recent than I am (v2.4) at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/thaw.al) line 355, at /usr/www/users/puppydog/mt/lib/MT/PluginData.pm line 32

But hey, thanks for posting it!

Posted by: Sean at January 4, 2005 03:07 AM

One day, I'm going to buy you a very large beer for this, I swear it.

Posted by: Ben Hammersley at January 17, 2005 03:07 PM

I also owe you a large beer, a very large foamy beer with whipped cream on top or something. THANKS!

Posted by: sninky-chan at February 20, 2005 07:07 AM

Post a comment




Remember Me?

(you may use HTML tags for style)