     observerService.removeObserver(@, 'quit-application-requested')
     return
 
+Zotero.BetterBibTeX.SQLColumns = (table) ->
+  statement = Zotero.DB.getStatement("pragma betterbibtex.table_info(#{table})", null, true)
+
+  # Get name column
+  for i in [0...statement.columnCount]
+    name = i if statement.getColumnName(i).toLowerCase() == 'name'
+
+  columns = null
+  while statement.executeStep()
+    columns ?= {}
+    columns[Zotero.DB._getTypedValue(statement, name)] = true
+  statement.finalize()
+
+  @log('schema', table, columns)
+
+  return columns
+
 Zotero.BetterBibTeX.init = ->
   return if @initialized
   @initialized = true


require('Formatter.js')

Zotero.BetterBibTeX = {}

Zotero.BetterBibTeX.inspect = (o) ->
  clone = Object.create(null)

          collection.addItem(id)
        else
          Zotero.BetterBibTeX.log("::: citekey #{citekey} missing")
          missing.push(citekey)

      if missing.length == 0
        Zotero.BetterBibTeX.log("::: all citekeys found")
      else
        report = new Zotero.BetterBibTeX.HTMLNode('http://www.w3.org/1999/xhtml', 'html')
        report.div(->
          @p(-> @b('BibTeX AUX scan'))
          @p('Missing references:')
          @ul(->
            for citekey in missing
              @li(citekey)
            return
          )
          return
        )
        item = new Zotero.Item('note')
        item.libraryID = collection.libraryID
        item.setNote(report.serialize())
        item.save()
        collection.addItem(item.id)

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