ext/duckdb/appender.c in duckdb-0.3.1.0 vs ext/duckdb/appender.c in duckdb-0.3.2.0
- old
+ new
@@ -46,20 +46,18 @@
#endif
static VALUE appender_flush(VALUE self);
static VALUE appender_close(VALUE self);
-static void deallocate(void * ctx)
-{
+static void deallocate(void * ctx) {
rubyDuckDBAppender *p = (rubyDuckDBAppender *)ctx;
duckdb_appender_destroy(&(p->appender));
xfree(p);
}
-static VALUE allocate(VALUE klass)
-{
+static VALUE allocate(VALUE klass) {
rubyDuckDBAppender *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBAppender));
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
}
static VALUE appender_initialize(VALUE self, VALUE con, VALUE schema, VALUE table) {
@@ -288,20 +286,16 @@
}
return self;
}
#ifdef HAVE_DUCKDB_APPEND_DATE
-static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VALUE dayval) {
- duckdb_date_struct dt_struct;
+static VALUE appender__append_date(VALUE self, VALUE year, VALUE month, VALUE day) {
duckdb_date dt;
rubyDuckDBAppender *ctx;
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
- dt_struct.year = NUM2INT(yearval);
- dt_struct.month = NUM2INT(monthval);
- dt_struct.day = NUM2INT(dayval);
- dt = duckdb_to_date(dt_struct);
+ dt = to_duckdb_date_from_value(year, month, day);
if (duckdb_append_date(ctx->appender, dt) == DuckDBError) {
rb_raise(eDuckDBError, "failed to append date");
}
return self;
@@ -312,59 +306,42 @@
static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros) {
duckdb_interval interval;
rubyDuckDBAppender *ctx;
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
- interval.months = NUM2INT(months);
- interval.days = NUM2INT(days);
- interval.micros = NUM2LL(micros);
+ to_duckdb_interval_from_value(&interval, months, days, micros);
if (duckdb_append_interval(ctx->appender, interval) == DuckDBError) {
rb_raise(eDuckDBError, "failed to append interval");
}
return self;
}
#endif
#ifdef HAVE_DUCKDB_APPEND_TIME
static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
- duckdb_time_struct time_st;
duckdb_time time;
rubyDuckDBAppender *ctx;
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
- time_st.hour = NUM2INT(hour);
- time_st.min = NUM2INT(min);
- time_st.sec = NUM2INT(sec);
- time_st.micros = NUM2INT(micros);
+ time = to_duckdb_time_from_value(hour, min, sec, micros);
- time = duckdb_to_time(time_st);
-
if (duckdb_append_time(ctx->appender, time) == DuckDBError) {
rb_raise(eDuckDBError, "failed to append time");
}
return self;
}
#endif
#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
- duckdb_timestamp_struct timestamp_st;
duckdb_timestamp timestamp;
rubyDuckDBAppender *ctx;
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
- timestamp_st.date.year = NUM2INT(year);
- timestamp_st.date.month = NUM2INT(month);
- timestamp_st.date.day = NUM2INT(day);
- timestamp_st.time.hour = NUM2INT(hour);
- timestamp_st.time.min = NUM2INT(min);
- timestamp_st.time.sec = NUM2INT(sec);
- timestamp_st.time.micros = NUM2INT(micros);
-
- timestamp = duckdb_to_timestamp(timestamp_st);
+ timestamp = to_duckdb_timestamp_from_value(year, month, day, hour, min, sec, micros);
if (duckdb_append_timestamp(ctx->appender, timestamp) == DuckDBError) {
rb_raise(eDuckDBError, "failed to append timestamp");
}
return self;