Sunday, November 13, 2011

LibreOffice

I was extremely skeptical when LibreOffice was launched as a reaction to Oracle's stewardship of the terrific open source OpenOffice office suite, but now I find myself using LibreOffice every day - there are no compatibility problems with OpenOffice formats, and I've actually now uninstalled OpenOffice.



Thumbs up - go get it!

Thursday, November 25, 2010

MySQL update syntax

I didn't realize you could update one table from another by including both names in the update clause like this:

UPDATE order_details o, products p
SET o.productname = p.productname
WHERE o.productid = p.productid;

Using aliases as in the above example also helps to avoid errors - specifically, Error Code: 1093 You can't specify target table '[your table]' for update in FROM clause when updating a table from itself:

UPDATE order_details a, order_details b
SET a.test = b.productname
WHERE a.orderdetailsid = b.orderdetailsid;

Guess it helps to read the fine manual. :-/

Tuesday, November 23, 2010

Preventing MySQL Error Code 1242 - temporarily disabling triggers

Have you ever gotten the dreaded Error Code: 1242 Subquery returns more than 1 row when trying to update or import rows in a MySQL table with triggers? Here's a workaround. First, wrap the active part of your trigger with the following if statement:

if @NOTRIG IS NULL then
[your code goes here]
end if

Then when before you run the update or import, set @NOTRIG = 1;

After your import you can set @NOTRIG to null, but the @NOTRIG variable only affects the current connection and won't prevent other applications connecting to the database from triggering the triggers.

UPDATE: this appears to work only fitfully - it worked fine on OS X but was flaky on a Windows server. I'm going to redo it using values in a table instead of user-defined variables.

UPDATE 2: testing if @NOTRIG is null works properly. Above code updated accordingly. 

Saturday, April 3, 2010

Virtualbox: Windows in a Window

Now that my main computer is a Mac, I have to have some way to support legacy Windows apps. Right now my choice is Virtualbox.



It's impressive - setup was nearly painless (about as painless as installing XP ever gets I suppose). It's fast too. You can assign as many cores as you want from your CPU.

A nice feature is auto-expansion of the disk image - if you set it to use ten gigs of disk space mximum, it will start out by using one actual gig on your real hard drive (whatever's required to install the OS) and increase as necessary. It runs on Windows, Mac, Linux and Solaris. The list of supported "guest" operating systems - OSes you can run inside it - is impressive:
  • Windows NT 4.0
  • Windows 2000 / XP / Server 2003 / Vista / Server 2008 / Windows 7 beta
  • DOS / Windows 3.x / 95 / 98 / ME
  • Linux 2.4
  • Linux 2.6
  • Solaris 10, OpenSolaris
  • FreeBSD
  • OpenBSD
  • OS/2 Warp 4.5
Originally owned by Sun and now Oracle, it's a free download.