<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Who is Chris Neale? &#187; sql</title>
	<atom:link href="http://who-is.chrs.nl/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://who-is.chrs.nl</link>
	<description>who-is.chrs.nl?</description>
	<lastBuildDate>Mon, 30 Aug 2010 16:20:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tweeting MythTV events in the new OAuth era</title>
		<link>http://who-is.chrs.nl/2010/08/30/tweeting-mythtv-events-in-the-new-oauth-era/</link>
		<comments>http://who-is.chrs.nl/2010/08/30/tweeting-mythtv-events-in-the-new-oauth-era/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 16:05:24 +0000</pubDate>
		<dc:creator>cdn</dc:creator>
				<category><![CDATA[MythTV]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[insanity]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[vanity]]></category>

		<guid isPermaLink="false">http://who-is.chrs.nl/?p=217</guid>
		<description><![CDATA[The mythtv wiki has a few scripts for tweeting MythTV stuff to twitter; although they all relied upon Basic Auth. until recently. Taking a leaf out of Twitter Tools&#8216; book it&#8217;s possible to convert the LWP::UserAgent-based code to do OAuth. &#8230; <a href="http://who-is.chrs.nl/2010/08/30/tweeting-mythtv-events-in-the-new-oauth-era/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mythtv.org/wiki/">The mythtv wiki</a> has <a href="http://cdn.cx/mythtweet">a few scripts for tweeting MythTV stuff</a> to twitter; although they all relied upon Basic Auth. until recently.</p>
<p>Taking a leaf out of <a href="http://alexking.org/projects/wordpress">Twitter Tools</a>&#8216; book it&#8217;s possible to convert the LWP::UserAgent-based code to do <a href="http://oauth.net/">OAuth</a>.</p>
<p>Before:</p>
<p><code>#!/usr/bin/perl<br />
use LWP::UserAgent;<br />
my $output = shift;<br />
my $browser = LWP::UserAgent->new;<br />
my $url = 'http://twitter.com/statuses/update.json';<br />
$browser->credentials('twitter.com:80', 'Twitter API', 'username', 'password');<br />
$response = $browser->get("http://twitter.com/account/verify_credentials.json");<br />
my $response = $browser->post($url, {status => $output});</code></p>
<p>First step is registering an App. at <a href="//dev.twitter.com/">dev.twitter.com</a>, so that you&#8217;ve got the necessary authentication keys to do <a href="http://dev.twitter.com/pages/oauth_single_token">OAuth directly with an access token</a>.</p>
<p>See also: http://wphelpcenter.com/plugins/twitter-tools/</p>
<p>Secondly, you&#8217;ll need a means of performing OAuth in perl, I chose <a href="http://search.cpan.org/~miyagawa/Net-Twitter-OAuth/lib/Net/Twitter/OAuth.pm">Net::Twitter:OAuth</a>, the <a href="http://search.cpan.org/~miyagawa/Net-Twitter-OAuth-0.02/lib/Net/Twitter/OAuth.pm">0.02 version page</a>&#8216;s example forming the basis for the simplest twitter.pl upgrade.</p>
<p>After:</p>
<p><code>#!/usr/bin/perl<br />
  use Net::Twitter::OAuth;<br />
  my $client = Net::Twitter::OAuth->new(<br />
      consumer_key    => "",<br />
      consumer_secret => "",<br />
  );<br />
  my $output = shift @ARGV;<br />
#  $client->oauth_token('', '');<br />
# DEPRECATED: use access_token and access_token_secret instead at ./oauth-mtv-tweet.pl line X<br />
  $client->access_token('');<br />
  $client->access_token_secret('');<br />
  my $res    = $client->update({ status => $output });<br />
</code></p>
<p>The more complex twitter.pl script can be upgraded in much the same way:</p>
<p>After:<br />
<code>#!/usr/bin/perl<br />
#use LWP::UserAgent;<br />
 use Net::Twitter::OAuth;<br />
  my $client = Net::Twitter::OAuth->new(<br />
      consumer_key    => "xxxxxxxxxxxxxxxxxx",<br />
      consumer_secret => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",<br />
  );<br />
  $client->access_token('xxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');<br />
  $client->access_token_secret("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");<br />
#<br />
use DBI;<br />
use DBD::mysql;<br />
use MythTV;<br />
#<br />
my $connect;<br />
my $debug = 0;<br />
my $title="";<br />
my $subtitle="";<br />
my $newsubtitle="";<br />
my $starttime="";<br />
my $chanid="";<br />
#<br />
##################################<br />
#                                #<br />
#    Main code starts here !!    #<br />
#                                #<br />
##################################<br />
#<br />
my $usage = "\nHow to use twitter.pl \n\ twitter.pl starttime=%STARTTIME% chanid=%CHANID% debug\n"<br />
        ."\n%CHANID% = channel ID associated with the recording\n"<br />
        ."%STARTTIME% = recording start time in either 'yyyy-mm-dd hh:mm:ss' or 'yyyymmddhhmmss' format\n"<br />
        ."debug = enable debugging information - outputs which commands would be run etc\n";<br />
#<br />
# get this script's ARGS<br />
#<br />
#<br />
my $num = @ARGV;<br />
#<br />
# if user hasn't passed enough arguments, die and print the usage info<br />
#<br />
if ($num le "1") {<br />
        die "$usage";<br />
}<br />
#<br />
#<br />
# Get all the arguments<br />
#<br />
#<br />
foreach (@ARGV){<br />
    if (/debug/) {<br />
        $debug = 1;<br />
    }<br />
    elsif (/starttime/) {<br />
        $starttime = (split(/=/))[1];<br />
    }<br />
    elsif (/chanid/) {<br />
        $chanid = (split(/=/))[1];<br />
    }<br />
}<br />
#<br />
# connect to backend<br />
my $myth = MythTV->new;<br />
# connect to database<br />
my $connect = $myth->{dbh};<br />
#<br />
my $query = "SELECT name FROM channel WHERE chanid=$chanid";<br />
my $query_handle = $connect->prepare($query);<br />
$query_handle->execute  or die "Unable to query channel table";<br />
#<br />
my ($channame) = $query_handle->fetchrow_array;<br />
#<br />
$query = "SELECT title, subtitle, endtime FROM recorded WHERE chanid=$chanid and starttime='$starttime'";<br />
$query_handle = $connect->prepare($query);<br />
$query_handle->execute  or die "Unable to query settings table";<br />
#<br />
$query_handle->bind_columns(undef, \$title, \$subtitle, \$endtime);<br />
$query_handle->fetch;<br />
#<br />
if ($subtitle)<br />
{<br />
$newsubtitle = " - ".$subtitle;<br />
}<br />
#<br />
my $output = "Finished recording $title $newsubtitle from $channame at $endtime";<br />
    print "Chanid $chanid \n";<br />
    print "Starttime $starttime \n";<br />
    print "$output \n";<br />
#<br />
unless ($debug)<br />
{<br />
#<br />
  my $res    = $client->update({ status => $output });<br />
#<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://who-is.chrs.nl/2010/08/30/tweeting-mythtv-events-in-the-new-oauth-era/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yes, this IS getting boring</title>
		<link>http://who-is.chrs.nl/2010/05/24/yes-this-is-getting-boring/</link>
		<comments>http://who-is.chrs.nl/2010/05/24/yes-this-is-getting-boring/#comments</comments>
		<pubDate>Mon, 24 May 2010 16:56:14 +0000</pubDate>
		<dc:creator>cdn</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[insanity]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://who-is.chrs.nl/?p=191</guid>
		<description><![CDATA[Upgraded most of the short linking I&#8217;ve been doing outside wordpress/la-petite-url to use yourls; except, of course, that a quick bit of sql didn&#8217;t translate everything. The MySQL insert into yourls_url select key1, target, timestamp(concat(year, '-', month, '-',day, ' 12:00:00')), &#8230; <a href="http://who-is.chrs.nl/2010/05/24/yes-this-is-getting-boring/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Upgraded most of the short linking I&#8217;ve <ins>been</ins> doing outside wordpress/la-petite-url to use yourls; except, of course, that a quick bit of sql didn&#8217;t translate everything.</p>
<p>The MySQL</p>
<p><code>insert into yourls_url select key1, target, timestamp(concat(year, '-', month, '-',day, ' 12:00:00')), '10.0.0.1', clicks from shorty_shorties;</code></p>
<p>The Problem<br />
One shorty link was hyphenated, not something yourls allows.</p>
<p>So, some .htaccess hackery required, again &#8230;</p>
<p><code>RewriteRule ^([0-9A-Za-z-]+)-([0-9A-Za-z-]+)?/?$ /yourls-go.php?id=$1$2 [L]</code></p>
]]></content:encoded>
			<wfw:commentRss>http://who-is.chrs.nl/2010/05/24/yes-this-is-getting-boring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Fix&#8221;ing WordPress database tables</title>
		<link>http://who-is.chrs.nl/2010/02/06/fixing-wordpress-database-tables/</link>
		<comments>http://who-is.chrs.nl/2010/02/06/fixing-wordpress-database-tables/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 15:41:47 +0000</pubDate>
		<dc:creator>cdn</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://who-is.chrs.nl/?p=169</guid>
		<description><![CDATA[After restoring tables from a WP mu backup (an incomplete one as it turned out) various issues presented themselves, not least an inability to submit posts (HTTP 500 not informative). A little searching revealed a likely cause (http://discuss.joyent.com/viewtopic.php?id=19116): missing auto_increment &#8230; <a href="http://who-is.chrs.nl/2010/02/06/fixing-wordpress-database-tables/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After restoring tables from a WP mu backup (an incomplete one as it turned out) various issues presented themselves, not least an inability to submit posts (HTTP 500 not informative).<br />
A little searching revealed a likely cause (<a href="http://discuss.joyent.com/viewtopic.php?id=19116">http://discuss.joyent.com/viewtopic.php?id=19116</a>): missing auto_increment on wp_{n}_posts; not only was auto_increment missing, indexes and keys were too. Later I found a hiccup in tagging, again wp_{n}_terms and related tables had missing metadata.</p>
<p>Fixes</p>
<p>Removing erroneous entries added by admin-ajax.php</p>
<p><code>delete from wp_{n}_posts where ID = 0 and post_modified = 'YYYY-MM-DD hh:mm:ss';</code></p>
<p>Add primary index before restoring auto_increment</p>
<p><code>alter table wp_{n}_posts add primary key (ID);<br />
alter table wp_{n}_posts change ID `ID` bigint(20) unsigned NOT NULL auto_increment;</code></p>
<p>Add remaining keys</p>
<p><code>alter table wp_{n}_posts add key post_name (post_name);<br />
alter table wp_{n}_posts add key type_status_date (post_type, post_status, post_date, ID);<br />
alter table wp_{n}_posts add key post_parent (post_parent);</code></p>
<p>Future backups</p>
<p><code>mysqldump --opt wordpress &gt; wordpress.sql</code></p>
<p>Just using &#8211;add-drop-table insufficent in some cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://who-is.chrs.nl/2010/02/06/fixing-wordpress-database-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
