Skip to content

Commit ebcfd62

Browse files
committed
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 <rmichael@edgeofthenet.org> * Franck Verrot <franck@verrot.fr>
1 parent 8d40981 commit ebcfd62

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/sqlite3/database.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ def step( *args )
395395

396396
def finalize
397397
super(@ctx)
398+
result = @ctx.result
399+
@ctx = FunctionProxy.new
400+
result
398401
end
399402
})
400403
proxy.ctx = FunctionProxy.new

test/test_integration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ def test_create_aggregate_without_block
499499

500500
value = @db.get_first_value( "select accumulate(a) from foo" )
501501
assert_equal 6, value
502+
503+
# calling #get_first_value twice don't add up to the latest result
504+
value = @db.get_first_value( "select accumulate(a) from foo" )
505+
assert_equal 6, value
502506
end
503507

504508
def test_create_aggregate_with_block

0 commit comments

Comments
 (0)