/** * call-seq: * create_function( db, name, args, proc ) -> nil * * Defines a new function that may be invoked from within an SQL * statement. The +args+ parameter specifies how many arguments the function * expects--use -1 to specify variable arity. The +proc+ parameter must be * a proc that expects +args+ + 1 parameters, with the first parameter * being an opaque handle to the function object itself: * * proc do |func, *args| * ... * end * * The function object is used when calling the #set_result and * #set_result_error methods. */ static VALUE static_api_create_function( VALUE module, VALUE db, VALUE name, VALUE n, VALUE proc ) { sqlite *handle; int result; GetDB( handle, db ); Check_Type( name, T_STRING ); Check_Type( n, T_FIXNUM ); if( !rb_obj_is_kind_of( proc, rb_cProc ) ) { rb_raise( rb_eArgError, "handler must be a proc" ); } result = sqlite_create_function( handle, StringValueCStr(name), FIX2INT(n), static_function_callback, (void*)proc ); if( result != SQLITE_OK ) { static_raise_db_error( result, "create function %s(%d)", StringValueCStr(name), FIX2INT(n) ); /* "raise" does not return */ } return Qnil; }