         Zotero.BetterBibTeX.keymanager.get({itemID: id}, 'on-change')
 
   unless collections.length == 0 || Zotero.BetterBibTeX.pref.get('auto-export') == 'disabled'
-    collections = ('' + id for id in collections).join(',')
-    Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection_id in (#{collections})")
+    Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection_id in #{Zotero.BetterBibTeX.SQLSet(collections)}")
     Zotero.BetterBibTeX.auto.process('itemChanged')
 
   return

        item.save()

    unless collections.length == 0 || Zotero.BetterBibTeX.pref.get('auto-export') == 'disabled'
      collections = ('' + id for id in collections).join(',')
      Zotero.DB.query("update betterbibtex.autoexport set status = 'pending' where collection_id in (#{collections})")
      Zotero.BetterBibTeX.auto.process('collectionChanged')

    return
}

Zotero.BetterBibTeX.collectionChanged = notify: (event, type, ids, extraData) ->
  Zotero.DB.query("delete from betterbibtex.autoexport where collection_id in (#{('' + id for id in extraData).join(',')})") if event == 'delete' && extraData.length > 0
  return

Zotero.BetterBibTeX.itemChanged = notify: (event, type, ids, extraData) ->
  Zotero.BetterBibTeX.keymanager.reset()

    @flash('Citation key rescan', "Scanning 'extra' fields for fixed keys\nFor a large library, this might take a while")
    patched = []
    for row in Zotero.DB.query(@findKeysSQL) or []
      patched.push(row.itemID)
      @log('scan:', row)
      @keymanager.set(row, @keymanager.extract({extra: row.extra}).__citekey__)
    if patched.length > 0
      for row in Zotero.DB.query("select * from betterbibtex.keys where citeKeyFormat is null and itemID not in #{@SQLSet(patched)}")
        @keymanager.remove(row)
    @pref.set('scan-citekeys', false)

