Archive for November, 2006

Upgrading to MySQL 4.1 with Rails

November 29, 2006

In a Rails app, I’m using ActiveRecord::Extensions to get faster load times of a large set of records. This requires a new feature in MySQL 4.1, supporting the ‘ON DUPLICATE KEY UPDATE …’ statement. I previously had MySQL 4.0 installed (ubuntu breezy badger). Here’s what I did to update:

sudo apt-get install mysql-server-4.1 mysql-client-4.1

After that, tried to do some operation in rails, and it failed:

Mysql::Error: Lost connection to MySQL server during query: ....

That problem had a simple fix:

 sudo gem install mysql

The ruby mysql gem had to be rebuilt with the new mysql libs, then everything was peachy!


Cross-browser JavaScript

November 18, 2006

Working on a web application, dealing with some cross-browser JavaScript issues. My main development platform is Firefox + FireBug extension, and I had everything working there just great. It took a while to get it working on other browsers — recording lessons learned here.

Lesson 1: Firefox – Opera – IE

After getting things working in Firefox, I found the next best platform for testing is Opera. Opera’s JavaScript engine seems a bit stricter on some things that Firefox, so it generates errors on things that Firefox handles fine. While not nearly as nice has FireBug, Opera does have an Error Console feature that is pretty clear on both the location and the meaning of the errors.

Finally it comes to testing Internet Explorer — IE6 to be precise. The tools for JavaScript debugging in IE6 are awful, it is a painful experience. So do all your testing on other platforms first.

Lesson 2: The real issues

Once I figured out a good debugging strategy, it wasn’t too hard to fix my problems. It came down to a few syntactic constructs that I now know to avoid in the future:

  • Don’t use assignment in an if() statement
    • Okay in Firefox and Opera:
      if ( foo = something() ) { ... }
    • Alternative that works in IE6 as well:
      var foo = something(); if ( foo ) { ... }
  • In hash / object construct, don’t leave dangling ‘,’ after last pair
    • Okay in Firefox:
      { a: 1, b: 2, c: 3, }
    • Alternative for Opera and IE6:
      { a: 1, b: 2, c: 3 }