Google Analytics

Google Analytics

Just received a Google Analytics invitation code. Analytics now replaces AWstats on The Weblog of Titus Barik as the primary web statistics package. In my opinion, Google thus far has had a mixed bag of product rollouts, so I’m curious to see what Analytics will bring to the table.

There’s also a Google Analytics WordPress Plugin by Matt Labrum, though it isn’t particularly sophisticated. To be fair, it probably doesn’t need to be.

Building Links with Amazon Associates

The Amazon Associates Central “build links” feature is cumbersome to use. Fortunately, Amazon supports a simpler and cleaner link format, though it is not well advertised on the Amazon homepage. To use, create a URL like the following:

http://www.amazon.com/exec/obidos/ASIN/number/id

where number is the ISBN or ASIN identifier, and id is your user affiliate ID. Thus, a link for the book The C Programming Language would transform into:

http://www.amazon.com/exec/obidos/ASIN/0131103628/barik-20

You can use Eli’s Amazon Link Generator to quickly generate URLs of this form, along with image information. If you’re of the programming sort, take a look at the Services_Amazon package for PHP.

RecordCount Always Returns -1

RecordCount is not supported with the default forward-only cursor. The use of RecordCount requires either the use of static or keyset server-side cursors. By default, all records are opened server-side, with adOpenForwardOnly. The easiest way to change this is to explicitly create a RecordSet object:

rs.Open strSQL, objConn, adOpenStatic, adLockReadOnly

Here, we use adOpenStatic and adLockReadOnly. However, for larger data sets, there are superior alternatives to RecordCount; these are presented at the adOpenStatic.com web site. This limitation is also documented on MSDN, though information on ADO RecordCount is harder to find there.

This App Can Break

Considering that Microsoft can’t even program Notepad without bugs, it’s no surprise that the rest of the Microsoft product line is as buggy as it is:

  1. Open up Notepad (not Wordpad, not Word or any other word processor)
  2. Type in this sentence exactly (without quotes): “this app can break”
  3. Save the file to your hard drive.
  4. Close Notepad
  5. Open the saved file by double clicking it.

Found on WinCustomize. It looks to be a UTF-16 bug of some sort, and there’s more information on it at Aftermarket Pipes.

32-bit ODBC Driver on Windows x64

If you have installed a 32-bit ODBC driver on Microsoft Windows x64, such as psqlODBC, you will find that 32-bit ODBC drivers do not appear in the ODBC Data Source Administrator. To resolve this issue, use

%SYSTEMROOT%\SysWOW64\odbcad32.exe

instead of the default program in system32. This will show all installed 32-bit ODBC drivers. At this point you can use your DSN as you would with any other system.

SQL to Swap Positions of Two Items in a Table

Given a single table, swapping two columns within that table is quite easy:

UPDATE table
SET a = b, b = a;

If instead, we want to swap one field between two rows, for example, the priority of two rows in a prioritized list implemented in the database, the query requires some algebraic tricks:

UPDATE table SET 
priority = A + ABS(priority - B)
WHERE priority in (A , B);

where A and B are integer constants such that A < B. This is an interesting interview problem, primarily because the first instinct is to use a CASE WHEN statement. This problem also arises commonly in many database applications, such as shopping carts and queues.