Skip to content

Commit

Permalink
Added a buffered method again
Browse files Browse the repository at this point in the history
  • Loading branch information
gja committed Jun 5, 2011
1 parent 05d3aa8 commit 8c6d67d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
8 changes: 2 additions & 6 deletions ext/downpour/buffered_result.c
@@ -1,4 +1,5 @@
#include "downpour.h"
#include "result.h"

#define SELF_TYPE drizzle_result_st
#define RUBY_CLASS DrizzleBufferedResult
Expand All @@ -9,15 +10,10 @@
return conversion(drizzle_result_##foo(self_ptr));\
}

static bool is_buffered(drizzle_result_st *self_ptr)
{
return self_ptr->options & (DRIZZLE_RESULT_BUFFER_ROW);
}

static void buffer_if_needed(drizzle_result_st *self_ptr)
{
// Only buffer once
if(is_buffered(self_ptr))
if(downpour_is_buffered(self_ptr))
return;

CHECK_OK(drizzle_result_buffer(self_ptr));
Expand Down
14 changes: 14 additions & 0 deletions ext/downpour/result.c
@@ -1,4 +1,5 @@
#include "downpour.h"
#include "result.h"

#define SELF_TYPE drizzle_result_st
#define RUBY_CLASS DrizzleResult
Expand All @@ -9,6 +10,18 @@
return conversion(drizzle_result_##foo(self_ptr));\
}

bool downpour_is_buffered(drizzle_result_st *self_ptr)
{
return self_ptr->options & (DRIZZLE_RESULT_BUFFER_ROW);
}

static VALUE is_buffered(VALUE self)
{
read_self_ptr();

return downpour_is_buffered(self_ptr) ? Qtrue : Qfalse;
}

static void buffer_column_if_needed(drizzle_result_st *self_ptr)
{
if(self_ptr->options & DRIZZLE_RESULT_BUFFER_COLUMN)
Expand Down Expand Up @@ -80,6 +93,7 @@ VALUE downpour_include_result_module(drizzle_result_st *self_ptr, VALUE result)
void init_drizzle_result()
{
DrizzleResult = rb_define_module_under(DownpourModule, "Result");
rb_define_method(DrizzleResult, "buffered?", is_buffered, 0);
define_attr(column_count);
define_attr(insert_id);
define_attr(error_code);
Expand Down
4 changes: 4 additions & 0 deletions spec/downpour/concurrent_spec.rb
Expand Up @@ -37,6 +37,10 @@
@status.run!.should be_nil
end

it "should have buffered the results" do
@status.run!.result.should be_buffered
end

it "should release pending queries" do
query = @status.run!
@status.pending_queries.should_not include(query)
Expand Down
4 changes: 3 additions & 1 deletion spec/downpour/select_spec.rb
Expand Up @@ -31,7 +31,9 @@
end

context "with buffering" do
#before(:each) { @results.buffer! }
it "should be buffered" do
@results.should be_buffered
end

it_should_behave_like "a read query"
end
Expand Down

0 comments on commit 8c6d67d

Please sign in to comment.