Method: UnQLite::Database#initialize

Defined in:
ext/unqlite/unqlite_database.c

#initialize(rb_string) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ext/unqlite/unqlite_database.c', line 22

static VALUE initialize(VALUE self, VALUE rb_string)
{
  void *c_string;
  int rc;
  unqliteRubyPtr ctx;

  // Ensure the given argument is a ruby string
  Check_Type(rb_string, T_STRING);

  // Get class context
  Data_Get_Struct(self, unqliteRuby, ctx);

  // Transform Ruby string into C string
  c_string = calloc(RSTRING_LEN(rb_string), sizeof(char));
  memcpy(c_string, StringValuePtr(rb_string), RSTRING_LEN(rb_string));

  // Open database
  // TODO: Accept others open mode (read-only + mmap, etc. Check http://unqlite.org/c_api/unqlite_open.html)
  rc = unqlite_open(&ctx->pDb, c_string, UNQLITE_OPEN_CREATE);

  // Check if any exception should be raised
  CHECK(ctx->pDb, rc);

  return self;
}