U:RDoc::AnyMethod[iI"create_aggregate:EFI"'SQLite3::Database#create_aggregate;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [ I"KCreates a new aggregate function for use in SQL statements. Aggregate ;TI"Jfunctions are functions that apply over every row in the result set, ;TI"Jinstead of over just a single row. (A very common aggregate function ;TI"Lis the "count" function, for determining the number of rows that match ;TI"a query.);To:RDoc::Markup::BlankLineo; ; [I"LThe new function will be added as +name+, with the given +arity+. (For ;TI"5variable arity functions, use -1 for the arity.);T@o; ; [ I"JThe +step+ parameter must be a proc object that accepts as its first ;TI"Cparameter a FunctionProxy instance (representing the function ;TI"Oinvocation), with any subsequent parameters (up to the function's arity). ;TI"MThe +step+ callback will be invoked once for each row of the result set.;T@o; ; [ I"JThe +finalize+ parameter must be a +proc+ object that accepts only a ;TI"Ksingle parameter, the FunctionProxy instance representing the current ;TI"Dfunction invocation. It should invoke FunctionProxy#result= to ;TI"&store the result of the function.;T@o; ; [I" Example:;T@o:RDoc::Markup::Verbatim; [I",db.create_aggregate( "lengths", 1 ) do ;TI" step do |func, value| ;TI" func[ :total ] ||= 0 ;TI"8 func[ :total ] += ( value ? value.length : 0 ) ;TI" end ;TI" ;TI" finalize do |func| ;TI"+ func.result = func[ :total ] || 0 ;TI" end ;TI" end ;TI" ;TI"Bputs db.get_first_value( "select lengths(name) from table" ) ;T: @format0o; ; [I"OSee also #create_aggregate_handler for a more object-oriented approach to ;TI"aggregate functions.;T: @fileI"lib/sqlite3/database.rb;T:0@omit_headings_from_table_of_contents_below000[I"V( name, arity, step=nil, finalize=nil, text_rep=Constants::TextRep::ANY, &block );T@8FI" Database;TcRDoc::NormalClass00