From ebcfd62af01fad46e6f0ceb99f5572b9fc57b9d1 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Fri, 12 Jun 2015 22:06:17 +0200 Subject: [PATCH] Align #create_aggregate with #create_aggregate_handler Two issues are covered by this commit: * We make use of the value of `result` to define the value of the aggreator. Before that, `finalize` was used and this was not respecting the documentation; * Each call to `finalize` now resets the aggregator. In the future, there could be some kind of callback/DSL to make it configurable. Commit by: * Richard K. Michael * Franck Verrot --- lib/sqlite3/database.rb | 3 +++ test/test_integration.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/sqlite3/database.rb b/lib/sqlite3/database.rb index 01519882..29c7341e 100644 --- a/lib/sqlite3/database.rb +++ b/lib/sqlite3/database.rb @@ -395,6 +395,9 @@ def step( *args ) def finalize super(@ctx) + result = @ctx.result + @ctx = FunctionProxy.new + result end }) proxy.ctx = FunctionProxy.new diff --git a/test/test_integration.rb b/test/test_integration.rb index 5f707aff..9bd3c3a8 100644 --- a/test/test_integration.rb +++ b/test/test_integration.rb @@ -499,6 +499,10 @@ def test_create_aggregate_without_block value = @db.get_first_value( "select accumulate(a) from foo" ) assert_equal 6, value + + # calling #get_first_value twice don't add up to the latest result + value = @db.get_first_value( "select accumulate(a) from foo" ) + assert_equal 6, value end def test_create_aggregate_with_block