def all(options = { }, &iterator)
      query(options) do |q|
        mode = results_mode(options)
        if not iterator.nil? and not read_only?
          results  = self
          callback = lambda { |key_pointer, key_size, doc_map, _|
            if mode != :docs
              key = cast_key_out(key_pointer.get_bytes(0, key_size))
            end
            if mode != :keys
              map = HashMap.new(doc_map)
              doc = map.to_hash { |string| cast_to_encoded_string(string) }
            end
            flags = case mode
                    when :keys then iterator[key]
                    when :docs then iterator[doc]
                    when :aoh  then iterator[doc.merge!(:primary_key => key)]
                    else            iterator[[key, doc]]
                    end
            Array(flags).inject(0) { |returned_flags, flag|
              returned_flags | case flag.to_s
                               when "update"
                                 if mode != :keys
                                   map.replace(doc) { |key_or_value|
                                     cast_to_bytes_and_length(key_or_value)
                                   }
                                 end
                                 lib::FLAGS[:TDBQPPUT]
                               when "delete" then lib::FLAGS[:TDBQPOUT]
                               when "break"  then lib::FLAGS[:TDBQPSTOP]
                               else               0
                               end
            }
          }
          unless lib.qryproc(q.pointer, callback, nil)
            error_code    = lib.ecode(@db)
            error_message = lib.errmsg(error_code)
            fail Error::QueryError,
                 "#{error_message} (error code #{error_code})"
          end
          results
        else
          query_results(lib.qrysearch(q.pointer), mode, &iterator)
        end
      end
    end
def all(options = { }, &iterator)
      query(options) do |q|
        mode = results_mode(options)
        if not iterator.nil? and not read_only?
          results  = self
          callback = lambda { |key_pointer, key_size, doc_map, _|
            if mode != :docs
              key = cast_key_out(key_pointer.get_bytes(0, key_size))
            end
            if mode != :keys
              map = HashMap.new(doc_map)
              doc = map.to_hash { |string| cast_to_encoded_string(string) }
            end
            flags = case mode
                    when :keys then iterator[key]
                    when :docs then iterator[doc]
                    when :aoh  then iterator[doc.merge!(:primary_key => key)]
                    else            iterator[[key, doc]]
                    end
            Array(flags).inject(0) { |returned_flags, flag|
              returned_flags | case flag.to_s
                               when "update"
                                 if mode != :keys
                                   map.replace(doc) { |key_or_value|
                                     cast_to_bytes_and_length(key_or_value)
                                   }
                                 end
                                 lib::FLAGS[:TDBQPPUT]
                               when "delete" then lib::FLAGS[:TDBQPOUT]
                               when "break"  then lib::FLAGS[:TDBQPSTOP]
                               else               0
                               end
            }
          }
          unless lib.qryproc(q.pointer, callback, nil)
            error_code    = lib.ecode(@db)
            error_message = lib.errmsg(error_code)
            fail Error::QueryError,
                 "#{error_message} (error code #{error_code})"
          end
          results
        else
          query_results(lib.qrysearch(q.pointer), mode, &iterator)
        end
      end
    end
Queries