Method: SQLite3::Database#define_function_with_flags

Defined in:
ext/sqlite3/database.c

#define_function_with_flags(name, flags) {|args, ...| ... } ⇒ Object

Define a function named name with args using TextRep bitflags flags. The arity of the block will be used as the arity for the function defined.

Yields:

  • (args, ...)


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'ext/sqlite3/database.c', line 338

static VALUE define_function_with_flags(VALUE self, VALUE name, VALUE flags)
{
  sqlite3RubyPtr ctx;
  VALUE block;
  int status;

  Data_Get_Struct(self, sqlite3Ruby, ctx);
  REQUIRE_OPEN_DB(ctx);

  block = rb_block_proc();

  status = sqlite3_create_function(
    ctx->db,
    StringValuePtr(name),
    rb_proc_arity(block),
    NUM2INT(flags),
    (void *)block,
    rb_sqlite3_func,
    NULL,
    NULL
  );

  CHECK(ctx->db, status);

  rb_hash_aset(rb_iv_get(self, "@functions"), name, block);

  return self;
}