<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Timm Murray</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/timm_murray/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/timm_murray/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/timm_murray//1522</id>
    <updated>2013-05-09T17:37:37Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Announcing: UAV::Pilot v0.1</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/timm_murray/2013/05/announcing-uavpilot-v01.html" />
    <id>tag:blogs.perl.org,2013:/users/timm_murray//1522.4660</id>

    <published>2013-05-09T17:25:04Z</published>
    <updated>2013-05-09T17:37:37Z</updated>

    <summary>UAV::Pilot is a Perl library for controlling UAVs. It currently works with the Parrot AR.Drone, with plans to expand to others in the future. Demo video The current library supports basic commands, such as takeoff, pitch, roll, yaw, vert speed,...</summary>
    <author>
        <name>Timm Murray</name>
        
    </author>
    
    <category term="ardrone" label="ardrone" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="arparrot" label="arparrot" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="uav" label="uav" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/timm_murray/">
        <![CDATA[<p>UAV::Pilot is a Perl library for controlling UAVs.  It currently works with the Parrot AR.Drone, with plans to expand to others in the future.</p>

<p><a href="http://www.youtube.com/watch?v=a8hRsIWPd6Q">Demo video</a></p>

<p>The current library supports basic commands, such as takeoff, pitch, roll, yaw, vert speed, and land.  All the preprogrammed flight animations are also in place.Navigation data and video are not yet supported–see the ROADMAP file for future plans.</p>

<p>Github repository: <a href="https://github.com/frezik/UAV-Pilot">https://github.com/frezik/UAV-Pilot</a></p>

<p>Should be up on CPAN shortly.</p>]]>
        
    </content>
</entry>

<entry>
    <title>SQLite and Writes</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/timm_murray/2013/02/sqlite-and-writes.html" />
    <id>tag:blogs.perl.org,2013:/users/timm_murray//1522.4315</id>

    <published>2013-02-11T19:45:28Z</published>
    <updated>2013-02-11T20:24:48Z</updated>

    <summary>Most DBI tutorials will show you how to use prepare()/execute(). Something like this: my $sth = $dbh-&gt;prepare( &apos;INSERT INTO table (foo, bar) VALUES (?, ?)&apos; ) or die ...; $sth-&gt;execute( 1, 2 ) or die ...; $sth-&gt;finish; Most of us...</summary>
    <author>
        <name>Timm Murray</name>
        
    </author>
    
    <category term="dbi" label="dbi" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="mysql" label="mysql" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="sqlite" label="sqlite" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/timm_murray/">
        <![CDATA[<p>Most DBI tutorials will show you how to use <code>prepare()</code>/<code>execute()</code>. Something like this:</p>

<pre>
my $sth = $dbh->prepare( 'INSERT INTO table (foo, bar) VALUES (?, ?)' ) or die ...;
$sth->execute( 1, 2 ) or die ...;
$sth->finish;
</pre>

<p>Most of us write DBI this way when we don't use DBIx::Class or some other abstraction layer (or we use <code>$dbh->do()</code>, but it won't end up changing my point). For most databases, the above is fine.</p>

<p>On SQLite, you can lose data that otherwise would have gone in fine.</p>]]>
        <![CDATA[<p>The trouble is with the way SQLite handles concurrent writes. A typical RDBMS is a sophisticated beast with finely-tuned concurrency model built off decades of experience with writing data to spinning platters. SQLite, however, is a little too simple-stupid for that. Some might say that its simplicity has a place, but at the very least, developers need to be aware of this problem.</p>

<p>SQLite databases exist in a single file, which is widely considered a feature. When SQLite goes to write to a table, it grabs an exclusive lock on the <em>entire file</em>. Other threads/processes trying to write will wait a given amount of time to acquire a lock (which you can see with <code>$dbh->sqlite_busy_timeout()</code>). After that, it will error out with "database is locked".</p>

<p>(Note that since it uses <code>fcntl()</code> to lock the file, things can go very badly if used on NFS.)</p>

<p>If we consider the DBI code at the beginning, we see that the error handling is fine for most databases. Most errors coming back from <code>prepare()</code>, <code>execute()</code>, or <code>do()</code> are unrecoverable. They're almost invariably about SQL syntax errors or the wrong number of placeholders. Unless you're writing some very dynamic SQL, you'll probably catch these errors during development.</p>

<p>For SQLite, the <code>execute()</code> or <code>do()</code> can fail due to locking contention. If you wrote the code above, you could lose otherwise valid data. If we want to make sure the data is written and don't care how long it takes, then you need to set <code>$dbh->sqlite_busy_timeout( 0 )</code> to turn off the busy timeout. If you do care how long it takes, then don't use SQLite.</p>

<p>If somebody ran into this problem, then on one hand you could say that they should have <a href="http://www.sqlite.org/lockingv3.html">read the manual</a>. On the other hand, SQLite is such an obvious candidate for a quick-and-dirty database that I can't say I blame developers for using it that way. Everything should Just Work with a minimum of fuss.</p>

<p>SQLite arguably has a place as an integrated database, but I think its usable niche is smaller than generally assumed. I'm not much of a MySQL fan, either, but for a quick mockup database, MySQL isn't much harder to deploy and avoids these sorts of problems.</p>]]>
    </content>
</entry>

</feed>
