<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - mysql tag</title>
  <link>http://bleaklow.com:80/tags/mysql/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 29 Feb 2012 20:50:00 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>Language wars are so boring</title>
    <link>http://bleaklow.com:80/2006/03/24/language_wars_are_so_boring.html</link>
    <description>
          &lt;p&gt;
I&#039;ve just read James Gosling&#039;s &lt;a href=&#034;http://blogs.sun.com/roller/page/jag?entry=scripting_flamewar&#034;&gt;post&lt;/a&gt; on how he got flamed for daring to say that scripting languages aren&#039;t a panacea.  Whereas the old language crusades used to be fought between the various &#034;compiled languages&#034; it seems the new jihad is between &#034;compiled&#034; and &#034;dynamic&#034; languages.  The arguments are much the same, and are just as tedious as they rely on religious fervour rather than pragmatism and common sense.
&lt;p&gt;
As James points out there&#039;s a huge continuum of both problem spaces and languages that can be used to address them, the trick is to pick the &lt;strong&gt;right&lt;/strong&gt; tool for the job at hand.  The point that most of the participants in language wars miss is that in most cases the choice of language should be secondary, the most important deciding factor should be what tools and libraries are available for the language and how closely they address the problem domain.  Syntax just isn&#039;t that important - I care far less about having to declare types for my variables than I do about having to write a thousands of lines of code that could more properly be replaced with a library function.  I also quite like having the dangerous and tedious bits of programming taken care of, such as memory management - an area where dynamic languages and garbage collecting languages such as Java have a clear edge over more traditional choices such as C - however in some circumstances C is still the right choice, when other factors (e.g. predictability or outright speed) are more important.
&lt;p&gt;
The day job for the last 18 months has been nearly 100% Perl and heavily regexp based as well as requiring access to MySQL, LDAP and a load of other network-based stuff.  At one point I rewrote some of the Perl regexp code in Java.  It was easy to do, thanks to Java&#039;s good regexp library.  Sure it was a bit more wordy, but it worked just fine.  That&#039;s the point - the power of both Perl an Java isn&#039;t really the core language, it&#039;s the ecosystem in which they exist - in Perl&#039;s case the unspoken hero is &lt;a href=&#034;http://cpan.org&#034;&gt;CPAN&lt;/a&gt;, in Java&#039;s case it&#039;s the extensive class library that it comes with, along with the vast range of freely available external class libraries.  Choosing a language based purely on whether it is &#034;static&#034; or &#034;dynamic&#034; makes about as much sense as choosing a car based on the paint colour - sure it&#039;s important, but it&#039;s not the &lt;strong&gt;most&lt;/strong&gt; important factor.
&lt;p&gt;</description>
      <category>Tech</category>
    <category>Java</category>
    <category>Perl</category>
    <comments>http://bleaklow.com:80/2006/03/24/language_wars_are_so_boring.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2006/03/24/language_wars_are_so_boring.html</guid>
    <pubDate>Fri, 24 Mar 2006 03:03:59 GMT</pubDate>
  </item>
  <item>
    <title>Making a perl filehandle into an object</title>
    <link>http://bleaklow.com:80/2004/12/22/making_a_perl_filehandle_into_an_object.html</link>
    <description>
          &lt;p&gt;
I&#039;m working on a project that uses both perl and MySQL, and I needed an easy way of piping stuff from perl into &lt;a href=&#034;http://dev.mysql.com/doc/mysql/en/mysqlimport.html&#034;&gt;mysqlimport&lt;/a&gt; so that I could do fast bulk uploads to the database.  MySQL is a bit odd in how it does this - it insists that the data has to come from a file who&#039;s filename prefix is the same as the table into which you are loading.  This precludes a vanilla perl &lt;a href=&#034;http://www.perldoc.com/perl5.8.4/pod/perlopentut.html#Pipe-Opens&#034;&gt;piped open&lt;/a&gt; and requires the use of a named pipe - the easiest way being to create a named pipe under &lt;span class=&#034;code&#034;&gt;/tmp&lt;/code&gt; of the form &lt;span class=&#034;code&#034;&gt;&amp;lt;table name&amp;gt;.&amp;lt;pid&amp;gt;&lt;/span&gt;.
&lt;p&gt;
I needed several loaders open simultaneously, so the obvious thing was to abstract the functionality into a class.  I still wanted to be able to use normal &lt;span class=&#034;code&#034;&gt;print&lt;/span&gt; statements to output the table rows to the loader, so I wanted the filehandle to simultaneously be an object as well.  Creating objects in perl is done with the &lt;span class=&#034;code&#034;&gt;bless&lt;/span&gt; operator, which requires a reference to bless - you can&#039;t bless a normal scalar value into an object.  Fortunately &lt;span class=&#034;code&#034;&gt;open()&lt;/span&gt; in later versions of perl actually gives you a reference to a filehandle:
&lt;/p&gt;&lt;p&gt;&lt;pre&gt;
$ perl -d -e 1

Loading DB routines from perl5db.pl version 1.25
Editor support available.

Enter h or `h h&#039; for help, or `man perldebug&#039; for more help.

main::(-e:1):	1
  DB&amp;lt;1&amp;gt; my $a;

  DB&amp;lt;2&amp;gt; open($a, &#039;&amp;gt;&#039;, &#039;/dev/null&#039;);

  DB&amp;lt;3&amp;gt; x $a
0  GLOB(0x3a40e0)
   -&amp;gt; *main::$a
         FileHandle({*main::$a}) =&amp;gt; fileno(3)
  DB&amp;lt;4&amp;gt; bless($a, &#039;MyClass&#039;);

  DB&amp;lt;5&amp;gt; x $a
0  MyClass=GLOB(0x3a40e0)
   -&amp;gt; *main::$a
         FileHandle({*main::$a}) =&amp;gt; fileno(3)
  DB&amp;lt;6&amp;gt; 
&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;
Having blessed the filehandle into the appropriate class we can then invoke methods on it (e.g. &lt;span class=&#034;code&#034;&gt;$a-&gt;do_stuff()&lt;/span&gt;), as well as print to it directly (e.g. &lt;span class=&#034;code&#034;&gt;print($a &#034;hello\n&#034;);&lt;/span&gt;).  However, having an object without any associated properties isn&#039;t really much use - in my case I needed to be able to store the name of the named pipe I was using to communicate with mysqlimport so that I could remove it when the filehandle was closed.  It&#039;s possible to use the perl &lt;a href=&#034;http://www.perldoc.com/perl5.8.4/pod/perltie.html&#034;&gt;tie&lt;/a&gt; and &lt;a href=&#034;http://www.perldoc.com/perl5.8.4/lib/overload.html&#034;&gt;overloading&lt;/a&gt; mechanisms to do this, but as this is perl and &lt;a href=&#034;http://dictionary.reference.com/search?q=tmtowtdi&#034;&gt;tmtowtdi&lt;/a&gt; always applies, and there is in fact a simpler although less obvious way.
&lt;/p&gt;&lt;p&gt;
To follow this it&#039;s first necessary to understand a little about how perl actually stores values internally.  Variables come in different types, the common ones being scalars, hashes and arrays, repectively denoted by the leading $, % and @ characters on variables.  &lt;span class=&#034;code&#034;&gt;$a&lt;/span&gt;, &lt;span class=&#034;code&#034;&gt;%a&lt;/span&gt; and &lt;span class=&#034;code&#034;&gt;@a&lt;/span&gt; look like they are entirely different variables, but in fact they aren&#039;t - they are all slots in a single perl symbol table entry called &#034;a&#034;.  These symbol table entries are called typeglobs or globs for short and are accessible by using the &#034;*&#034; prefix on a variable, so &lt;span class=&#034;code&#034;&gt;*a&lt;/span&gt; refers to the typeglob where &lt;span class=&#034;code&#034;&gt;$a&lt;/span&gt;, &lt;span class=&#034;code&#034;&gt;%a&lt;/span&gt; and &lt;span class=&#034;code&#034;&gt;@a&lt;/span&gt; all live.
&lt;/p&gt;&lt;p&gt;
The &#034;a&#034; filehandle that we opened in the example above also has a hash slot, so if we want to store additional attributes on &#034;a&#034; we need some way of getting the associated hash slot in its typeglob.  This is actually very easy, although the syntax is a little abstruse:
&lt;/p&gt;&lt;p&gt;&lt;pre&gt;
my $fh;
open($fh, &#039;&gt;&#039;, $fifo);
my $self = \%{*$fh};
$self-&gt;{fifo} = $fifo;
bless($fh, $class);
&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;
Let&#039;s pick apart the line that assigns to &lt;span class=&#034;code&#034;&gt;$self&lt;/span&gt;.  &lt;span class=&#034;code&#034;&gt;$fh&lt;/span&gt; is actually a reference to a filehandle, so we dereference it with &lt;span class=&#034;code&#034;&gt;*$&lt;/span&gt; to the entire &#034;fh&#034; glob.  The &lt;span class=&#034;code&#034;&gt;%{...}&lt;/span&gt; says we want to access the hash slot of the &#034;fh&#034; glob, and the &lt;span class=&#034;code&#034;&gt;\&lt;/span&gt; gets us a reference to that, so &lt;span class=&#034;code&#034;&gt;$self&lt;/span&gt; ends up being a reference to the hash slot associated with &#034;fh&#034;.  Phew.  We can then assign to it as a normal hash reference.  When we subsequently call a method on the blessed &lt;span class=&#034;code&#034;&gt;$fh&lt;/span&gt; filehandle, we can use exactly the same chant to get back the hash reference and access the data that we put in it.  This trick is used by the standard perl IO::Socket class to squirrel away socket attributes, but it&#039;s often useful to be able to associate properties with a filehandle yourself so I think this particular technique deserves to be more widely known.  If you want further information on how all this stuff hangs together, you should check out the &lt;a href=&#034;http://www.perldoc.com/perl5.8.4/pod/perlref.html&#034;&gt;perlref&lt;/a&gt; manpage.
&lt;/p&gt;</description>
      <category>Tech</category>
    <category>Perl</category>
    <comments>http://bleaklow.com:80/2004/12/22/making_a_perl_filehandle_into_an_object.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2004/12/22/making_a_perl_filehandle_into_an_object.html</guid>
    <pubDate>Wed, 22 Dec 2004 09:25:38 GMT</pubDate>
  </item>
  <item>
    <title>MySQL - is there no end to my pain?</title>
    <link>http://bleaklow.com:80/2004/08/18/mysql_is_there_no_end_to_my_pain.html</link>
    <description>
          &lt;p&gt;
I&#039;ve been doing all my MySQL development on an Opteron box running Solaris 10, but the production machine is an Ultra 60, and therefore sparc architecture. Having got everything ready to roll out, I set to to build MySQL on the U60 - a simple job, or so I thought - only to have it blow up during the compile:
&lt;p&gt;
&lt;pre&gt;
&#034;history.c&#034;, line 617: warning: implicit function declaration: strunvis
&#034;history.c&#034;, line 655: warning: implicit function declaration: strvis
&#034;history.c&#034;, line 655: undefined symbol: VIS_WHITE
cc: acomp failed for history.c
&lt;/pre&gt;
&lt;p&gt;
It turns out that on sparc the macro HAVE_VIS_H was being defined in config.h, but it wasn&#039;t defined on x86, which was kinda odd. Time to go spelunking through configure to figure out what was going on. It turns out that configure was probing for the file vis.h, using the usual &#039;write and compile a test program&#039; method, which was succeeding. A &#039;find&#039; on the immediately obvious directory trees didn&#039;t help, so the -H compiler flag came to the rescue:
&lt;p&gt;
&lt;pre&gt;
$ printf &#039;#include &amp;lt;vis.h&amp;gt;\nint main(){}\n&#039; &gt; try.c
$ cc -H -c try.c
/ws/on-tools-uk/SUNWspro/SOS8/prod/include/cc/vis.h
	/ws/on-tools-uk/SUNWspro/SOS8/prod/include/cc/sys/vis_proto.h
		/usr/include/sys/isa_defs.h
	/ws/on-tools-uk/SUNWspro/SOS8/prod/include/cc/sys/vis_define.h
	/ws/on-tools-uk/SUNWspro/SOS8/prod/include/cc/sys/vis_types.h
	/ws/on-tools-uk/SUNWspro/SOS8/prod/include/cc/sys/vis_asi.h
$
&lt;/pre&gt;
&lt;p&gt;
Ah. sparc has some additional instructions called the VIS instructions which are analagous to the MMX
extensions on x86, and it was the header file for those that was being picked up, rather than the one
that history.c was expecting. This leads rather nicely to &lt;i&gt;Alan&#039;s First Rule of Configure Scripting&lt;/i&gt;:
&lt;p&gt;
&lt;strong&gt;Test for the symbol, not the header file.&lt;/strong&gt;
&lt;p&gt;
I&#039;ve had pain in this area before, early on in the development of Solaris 10 I had to fix perl&#039;s Configure. Perl&#039;s Configure is &lt;strong&gt;way&lt;/strong&gt; smarter than the GNU one in that it does actually probe the symbol table of the libraries it it interested in, which is much faster and also more accurate. However the perl Configure was
assuming that if it found &#039;_foo&#039;, plain &#039;foo&#039; also also existed. It even went as far as assuming that
if &#039;__foo&#039; existed then &#039;foo&#039; also existed, and that just isn&#039;t necessarily so. Fixing it proved to be an exercise in cross-platform development and remote debugging - at the same time as fixing it on Solaris I managed to break Configure on MPE/iX, and had to work with the maintainer for that platform to
get it going again. It never ceases to amaze me how many platforms perl actually compiles and runs on
- as I said, it&#039;s Configure is way smarter than the GNU one.
&lt;p&gt;
I can&#039;t really blame MySQL for this particular problem, as I guess they normally build with gcc.  In the past I&#039;ve spent considerable amounts of time making sure perl builds OK with our compiler, and I&#039;ve also obtained some free Forte compiler licenses for the other perl developers. Not that I have any say at all in the matter, the usual disclaimers apply etc, but unbundling just Forte cc, CC, dbx and dmake and offering them for free would be really helpful to both our customers &lt;strong&gt;and&lt;/strong&gt; us. Sure, we can still make money by charging for the full IDE, but I&#039;d love if we could make those bits free. Heck, even Microsoft have realised that &lt;a href=&#034;http://msdn.microsoft.com/visualc/vctoolkit2003/&#034;&gt;free compilers&lt;/a&gt; make good sense!
&lt;p&gt;
Anyway, back to my MySQL problem. I&#039;ve now got to try to figure out the command-line magic I need to stop it picking up the wrong header. I&#039;ve also logged a MySQL bug - the bug id is &lt;a href=&#034;http://bugs.mysql.com/5102&#034;&gt;5102&lt;/a&gt;.</description>
      <category>Solaris</category>
    <category>Tech</category>
    <category>Work</category>
    <comments>http://bleaklow.com:80/2004/08/18/mysql_is_there_no_end_to_my_pain.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2004/08/18/mysql_is_there_no_end_to_my_pain.html</guid>
    <pubDate>Wed, 18 Aug 2004 14:56:18 GMT</pubDate>
  </item>
  <item>
    <title>MySQL bites my ass... again.</title>
    <link>http://bleaklow.com:80/2004/08/11/mysql_bites_my_ass_again.html</link>
    <description>
          &lt;p&gt;
Having got all my data shovelled into MySQL, I foolishly decided that I&#039;d like some of it back.  I&#039;d carefully &lt;a href=&#034;http://en.wikipedia.org/wiki/Database_normalization&#034;&gt;normalised&lt;/a&gt; all my tables, so in order to retrieve it I needed to join across several tables plus I needed some subqueries in the select field list to do some lookups, so it ended up being a reasonably complex query - something along the lines of:
&lt;p&gt;
&lt;pre&gt;
select
    a1.col1, c1.col2
    (select b1.col2 from b b1 where b1.col1 = a1.col2),
    (select b2.col2 from b b2 where b2.col1 = a1.col3)
from
    a a1 join b b3 on a1.col1 = b3.col1
    join c c1 on a1.col4 = c1.col1
order by
    b3.col4
&lt;/pre&gt;
&lt;p&gt;
Which worked just fine - right up until the rows where the value in a1.col3 was NULL, when instead of the second subselect returning the value NULL it returned the value looked up in the subselect on the previous line of the query!!!!!  I&#039;ve tried to create a smaller reproducible test case without success, and I really don&#039;t have the time to chase it down.  Removing the third join on the b table makes the problem go away, but then I lose the required ordering - gah!
&lt;p&gt;
I can reformulate the query to remove the subselects by the crafty use of a left outer join, which will probably be more efficient anyway, but it &lt;strong&gt;should&lt;/strong&gt; work as is.  Bah.
&lt;p&gt;
&lt;a href=&#034;http://hates-software.com&#034;&gt;I hates software!&lt;/a&gt;</description>
      <category>Solaris</category>
    <category>Tech</category>
    <category>Work</category>
    <comments>http://bleaklow.com:80/2004/08/11/mysql_bites_my_ass_again.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2004/08/11/mysql_bites_my_ass_again.html</guid>
    <pubDate>Wed, 11 Aug 2004 13:30:00 GMT</pubDate>
  </item>
  <item>
    <title>Elbonian database technology, part II</title>
    <link>http://bleaklow.com:80/2004/07/26/elbonian_database_technology_part_ii.html</link>
    <description>
          &lt;p&gt;
cp kindly commented on my &lt;a href=&#034;http://blogs.sun.com/roller/page/alanbur/20040723#elbonian_database_technology&#034;&gt;last post&lt;/a&gt; regarding Open Source databases, and suggested two others I should go look at, &lt;a href=&#034;http://www.sapdb.org&#034;&gt;SapDB/MaxDB&lt;/a&gt; and &lt;a href=&#034;http://firebird.sourceforge.net/&#034;&gt;Firebird&lt;/a&gt;.  I looked at MaxDB, and it is a re-branded and enhanced version of SAP DB, &lt;a href=&#034;http://www.sap.com/&#034;&gt;SAP AG&#039;s&lt;/a&gt; open source database.  It has been taken over by &lt;a href=&#034;http://www.mysql.com&#034;&gt;MySQL AG&lt;/a&gt;, and it appears that it will eventually be merged into MySQL.  It therefore doesn&#039;t look like a particularly good choice, as it might not be around in the future.
&lt;p&gt;
I then went and looked at Firebird.  This started out as Borland&#039;s &lt;a href=&#034;http://community.borland.com/interbase/&#034;&gt;InterBase&lt;/a&gt; product, which they released as open source in 2000, then changed their minds and tried to close it back up.  The result was a fork - the original Borland code was taken and rewritten in C++ (no, I have no idea why) by the Firebird community (including the original Interbase author) that developed around the original Borland code release.  It&#039;s an interesting &lt;a href=&#034;http://firebird.sourceforge.net/index.php?op=history&amp;id=opensource&#034;&gt;story&lt;/a&gt; that anyone who is thinking about open sourcing a large piece of software (*cough*) should be aware of.  The documentation is a bit thin - the Firebird website relies heavily on the Borland docs, but it seems to be a mature product, so I&#039;m going to give it a whizz.</description>
      <category>Tech</category>
    <category>Work</category>
    <comments>http://bleaklow.com:80/2004/07/26/elbonian_database_technology_part_ii.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2004/07/26/elbonian_database_technology_part_ii.html</guid>
    <pubDate>Mon, 26 Jul 2004 06:20:47 GMT</pubDate>
  </item>
  </channel>
</rss>

