Fix sort title update and already broken sort titles.

From #6689.
It would just fatal as soon as it hit db_select(), wouldn't it? If you just run this naked in the browser, it won't have gone through any Drupal bootstrap.