Tidy up iterator SQL

  - drop explicit qualification of table name by 'main': it's the default
  - similarly drop use of sqlite3_snprintf to replace %Q with 'main'
  - layout SQL code in a consistent style
Merge branch 'master' into docco