I have started to move the site over to WordPress, starting with the blog entries and during the conversion process I remembered to re-learn a little bit about SQL.
I studied relational databases at University but the days when I can knock up a left join insert with multiple renames, without thinking have passed me by.
I do find that in my old age I rely on query builders to help me generate some of the more complicated queries that I use during testing.
I hand crafted php files with automatically generated text data files to build my previous blog. With all of the blog data entry done in Compendium-TA using a VBA script to generate the files and the rss file, and generate an ftp script to upload it all to CompendiumDev.co.uk.
But I thought I’d get with the times and start to use a ‘proper’ blogging tool. So a quick hack to the VBA script and I generated an RSS file with all the posts in it. I imported the RSS file into WordPress. But because I have in the past written less than XHTML compliant posts, most of the posts generated had CDATA wrapped around them to generate a valid xml RSS file.
I started amending the posts in WordPress manually to remove the CDATA tags and after 5 edits thought “wait a minute why am I not automating this!”.
So a quick flick through the mysql manual and I identified the LEFT and SUBSTRING operators and voila…I could extract the contents of the CDATA information.
UPDATE 'posts'
SET post_content=left('post_content',length('post_content')-3)
WHERE substring('post_content',1,9)='<

