コード例 #1
0
ファイル: time.c プロジェクト: cafedomancer/groonga
grn_bool
grn_time_to_tm(grn_ctx *ctx, int64_t time, struct tm *tm)
{
  int64_t sec;
  int32_t usec;

  GRN_TIME_UNPACK(time, sec, usec);
  return grn_time_t_to_tm(ctx, sec, tm);
}
コード例 #2
0
ファイル: test-cast-basic.c プロジェクト: zunda/groonga
void
test_uint64_to_time(void)
{
  long long int sec, usec;

  grn_obj_reinit(&context, &dest, GRN_DB_TIME, 0);
  cast_uint64(1259009530);
  GRN_TIME_UNPACK(GRN_TIME_VALUE(&dest), sec, usec);
  cut_assert_equal_int(1259009530, sec);
  cut_assert_equal_int(0, usec);
}
コード例 #3
0
ファイル: test-cast-basic.c プロジェクト: zunda/groonga
void
test_text_to_time(void)
{
  long long int sec, usec;

  grn_obj_reinit(&context, &dest, GRN_DB_TIME, 0);
  cast_text("2009/11/24 05:52:10.02929");
  GRN_TIME_UNPACK(GRN_TIME_VALUE(&dest), sec, usec);
  cut_assert_equal_int(1259009530, sec);
  cut_assert_equal_int(29290, usec);
}
コード例 #4
0
ファイル: rb-grn-utils.c プロジェクト: ryoqun/rroonga
static VALUE
rb_grn_bulk_to_ruby_object_by_range_id (grn_ctx *context, grn_obj *bulk,
					grn_id range_id,
					VALUE related_object, VALUE *rb_value)
{
    grn_bool success = GRN_TRUE;

    switch (range_id) {
      case GRN_DB_VOID:
	*rb_value = rb_str_new(GRN_TEXT_VALUE(bulk), GRN_TEXT_LEN(bulk));
	break;
      case GRN_DB_BOOL:
	*rb_value = GRN_BOOL_VALUE(bulk) ? Qtrue : Qfalse;
	break;
      case GRN_DB_INT32:
	*rb_value = INT2NUM(GRN_INT32_VALUE(bulk));
	break;
      case GRN_DB_UINT32:
	*rb_value = UINT2NUM(GRN_UINT32_VALUE(bulk));
	break;
      case GRN_DB_INT64:
	*rb_value = LL2NUM(GRN_INT64_VALUE(bulk));
	break;
      case GRN_DB_UINT64:
	*rb_value = ULL2NUM(GRN_UINT64_VALUE(bulk));
	break;
      case GRN_DB_FLOAT:
	*rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
	break;
      case GRN_DB_TIME:
	{
	    int64_t time_value, sec, usec;

	    time_value = GRN_TIME_VALUE(bulk);
	    GRN_TIME_UNPACK(time_value, sec, usec);
	    *rb_value = rb_funcall(rb_cTime, rb_intern("at"), 2,
				   LL2NUM(sec), LL2NUM(usec));
	}
	break;
      case GRN_DB_SHORT_TEXT:
      case GRN_DB_TEXT:
      case GRN_DB_LONG_TEXT:
	*rb_value = rb_grn_context_rb_string_new(context,
						 GRN_TEXT_VALUE(bulk),
						 GRN_TEXT_LEN(bulk));
	break;
      default:
	success = GRN_FALSE;
	break;
    }

    return success;
}
コード例 #5
0
ファイル: mrb_bulk.c プロジェクト: fenicks/groonga
mrb_value
grn_mrb_value_from_bulk(mrb_state *mrb, grn_obj *bulk)
{
  mrb_value mrb_value_;
  grn_ctx *ctx = (grn_ctx *)mrb->ud;

  switch (bulk->header.domain) {
  case GRN_DB_INT32 :
    {
      int32_t value;
      value = GRN_INT32_VALUE(bulk);
      mrb_value_ = mrb_fixnum_value(value);
    }
    break;
  case GRN_DB_UINT32 :
    {
      int64_t value;
      value = GRN_UINT32_VALUE(bulk);
      if (!FIXABLE(value)) {
        mrb_raisef(mrb, E_RANGE_ERROR,
                   "can't handle large number: <%S>: max: <%S>",
                   mrb_fixnum_value(value), /* TODO: This will cause overflow */
                   mrb_fixnum_value(MRB_INT_MAX));
      }
      mrb_value_ = mrb_fixnum_value(value);
    }
    break;
  case GRN_DB_TIME :
    {
      int64_t value;
      int32_t sec;
      int32_t usec;

      value = GRN_TIME_VALUE(bulk);
      GRN_TIME_UNPACK(value, sec, usec);
      mrb_value_ = mrb_funcall(mrb,
                               mrb_obj_value(ctx->impl->mrb.builtin.time_class),
                               "at",
                               2,
                               mrb_fixnum_value(sec),
                               mrb_fixnum_value(usec));
    }
    break;
  case GRN_DB_SHORT_TEXT :
  case GRN_DB_TEXT :
  case GRN_DB_LONG_TEXT :
    mrb_value_ = mrb_str_new(mrb,
                             GRN_TEXT_VALUE(bulk),
                             GRN_TEXT_LEN(bulk));
    break;
  default :
    {
      grn_obj *domain;
      grn_bool is_record = GRN_FALSE;

      domain = grn_ctx_at(ctx, bulk->header.domain);
      if (domain) {
        switch (domain->header.type) {
        case GRN_TABLE_HASH_KEY :
        case GRN_TABLE_PAT_KEY :
        case GRN_TABLE_DAT_KEY :
        case GRN_TABLE_NO_KEY :
          is_record = GRN_TRUE;
          break;
        default :
          break;
        }
      }

      if (is_record) {
        mrb_value_ = mrb_fixnum_value(GRN_RECORD_VALUE(bulk));
        grn_obj_unlink(ctx, domain);
      } else {
#define MESSAGE_SIZE 4096
        char message[MESSAGE_SIZE];
        char domain_name[GRN_TABLE_MAX_KEY_SIZE];
        int domain_name_size;

        if (domain) {
          domain_name_size = grn_obj_name(ctx, domain,
                                          domain_name, GRN_TABLE_MAX_KEY_SIZE);
          grn_obj_unlink(ctx, domain);
        } else {
          grn_strcpy(domain_name, GRN_TABLE_MAX_KEY_SIZE, "unknown");
          domain_name_size = strlen(domain_name);
        }
        grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE,
                     "unsupported bulk value type: <%d>(%.*s)",
                     bulk->header.domain,
                     domain_name_size,
                     domain_name);
        mrb_raise(mrb, E_RANGE_ERROR, message);
      }
#undef MESSAGE_SIZE
    }
    break;
  }

  return mrb_value_;
}