lib/redlander/query/results.rb in redlander-0.5.0 vs lib/redlander/query/results.rb in redlander-0.5.1

- old
+ new

@@ -17,36 +17,38 @@ end def process(model) @rdf_results = Redland.librdf_model_query_execute(model.rdf_model, @rdf_query) - if @rdf_results.null? - return nil - else + begin case when bindings? if block_given? + return nil if @rdf_results.null? each { yield process_bindings } else + return [] if @rdf_results.null? map { process_bindings } end when boolean? + return nil if @rdf_results.null? process_boolean when graph? + return nil if @rdf_results.null? if block_given? process_graph { |statement| yield statement } else process_graph end when syntax? process_syntax else raise RedlandError, "Cannot determine the type of query results" end + ensure + Redland.librdf_free_query_results(@rdf_results) end - ensure - Redland.librdf_free_query_results(@rdf_results) end def each if block_given? while Redland.librdf_query_results_finished(@rdf_results).zero? @@ -80,10 +82,13 @@ {}.tap do |bindings| n = Redland.librdf_query_results_get_bindings_count(@rdf_results) while n > 0 name = Redland.librdf_query_results_get_binding_name(@rdf_results, n-1) value = Redland.librdf_query_results_get_binding_value(@rdf_results, n-1) - bindings[name] = Node.new(value) unless value.null? + unless value.null? + bindings[name] = Node.new(value) + Redland.librdf_free_node(value) + end n -= 1 end end end