Skip to content

Commit 4064bb2

Browse files
authored
Merge pull request suketa#852 from suketa/appender_append_int8_error
retrieve error message from duckdb in DuckDB::Appender#append_int8
2 parents e4a9266 + 4a9f7d8 commit 4064bb2

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
# Unreleased
55
- add `DuckDB::Appender#error_message`.
66
- fix error message when `DuckDB::Appender#flush`, `DuckDB::Appender#close`, `DuckDB::Appender#end_row`,
7-
`DuckDB::Appender#append_bool` failed.
7+
`DuckDB::Appender#append_bool`, `DuckDB::Appender#append_int8` failed.
88
- `DuckDB::Appender#begin_row` does nothing. Only returns self. `DuckDB::Appender#end_row` is only required.
99

1010
# 1.1.3.1 - 2024-11-27

ext/duckdb/appender.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static size_t memsize(const void *p);
88
static VALUE appender_initialize(VALUE klass, VALUE con, VALUE schema, VALUE table);
99
static VALUE appender_error_message(VALUE self);
1010
static VALUE appender__append_bool(VALUE self, VALUE val);
11-
static VALUE appender_append_int8(VALUE self, VALUE val);
11+
static VALUE appender__append_int8(VALUE self, VALUE val);
1212
static VALUE appender_append_int16(VALUE self, VALUE val);
1313
static VALUE appender_append_int32(VALUE self, VALUE val);
1414
static VALUE appender_append_int64(VALUE self, VALUE val);
@@ -127,32 +127,14 @@ static VALUE appender__append_bool(VALUE self, VALUE val) {
127127
return duckdb_state_to_bool_value(duckdb_append_bool(ctx->appender, (val == Qtrue)));
128128
}
129129

130-
/* call-seq:
131-
* appender.append_int8(val) -> self
132-
*
133-
* Appends an int8(TINYINT) value to the current row in the appender.
134-
*
135-
* require 'duckdb'
136-
* db = DuckDB::Database.open
137-
* con = db.connect
138-
* con.query('CREATE TABLE users (id INTEGER, age TINYINT)')
139-
* appender = con.appender('users')
140-
* appender
141-
* .append_int32(1)
142-
* .append_int8(20)
143-
* .end_row
144-
* .flush
145-
*/
146-
static VALUE appender_append_int8(VALUE self, VALUE val) {
130+
/* :nodoc: */
131+
static VALUE appender__append_int8(VALUE self, VALUE val) {
147132
rubyDuckDBAppender *ctx;
148133
int8_t i8val = (int8_t)NUM2INT(val);
149134

150135
TypedData_Get_Struct(self, rubyDuckDBAppender, &appender_data_type, ctx);
151136

152-
if (duckdb_append_int8(ctx->appender, i8val) == DuckDBError) {
153-
rb_raise(eDuckDBError, "failed to append int8");
154-
}
155-
return self;
137+
return duckdb_state_to_bool_value(duckdb_append_int8(ctx->appender, i8val));
156138
}
157139

158140
/* call-seq:
@@ -494,7 +476,6 @@ void rbduckdb_init_duckdb_appender(void) {
494476
rb_define_alloc_func(cDuckDBAppender, allocate);
495477
rb_define_method(cDuckDBAppender, "initialize", appender_initialize, 3);
496478
rb_define_method(cDuckDBAppender, "error_message", appender_error_message, 0);
497-
rb_define_method(cDuckDBAppender, "append_int8", appender_append_int8, 1);
498479
rb_define_method(cDuckDBAppender, "append_int16", appender_append_int16, 1);
499480
rb_define_method(cDuckDBAppender, "append_int32", appender_append_int32, 1);
500481
rb_define_method(cDuckDBAppender, "append_int64", appender_append_int64, 1);
@@ -517,6 +498,7 @@ void rbduckdb_init_duckdb_appender(void) {
517498
rb_define_private_method(cDuckDBAppender, "_flush", appender__flush, 0);
518499
rb_define_private_method(cDuckDBAppender, "_close", appender__close, 0);
519500
rb_define_private_method(cDuckDBAppender, "_append_bool", appender__append_bool, 1);
501+
rb_define_private_method(cDuckDBAppender, "_append_int8", appender__append_int8, 1);
520502
rb_define_private_method(cDuckDBAppender, "_append_date", appender__append_date, 3);
521503
rb_define_private_method(cDuckDBAppender, "_append_interval", appender__append_interval, 3);
522504
rb_define_private_method(cDuckDBAppender, "_append_time", appender__append_time, 4);

lib/duckdb/appender.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ def append_bool(value)
117117
raise_appender_error('failed to append_bool')
118118
end
119119

120+
# call-seq:
121+
# appender.append_int8(val) -> self
122+
#
123+
# Appends an int8(TINYINT) value to the current row in the appender.
124+
#
125+
# require 'duckdb'
126+
# db = DuckDB::Database.open
127+
# con = db.connect
128+
# con.query('CREATE TABLE users (id INTEGER, age TINYINT)')
129+
# appender = con.appender('users')
130+
# appender
131+
# .append_int32(1)
132+
# .append_int8(20)
133+
# .end_row
134+
# .flush
135+
#
136+
def append_int8(value)
137+
return self if _append_int8(value)
138+
139+
raise_appender_error('failed to append_int8')
140+
end
141+
120142
# appends huge int value.
121143
#
122144
# require 'duckdb'

0 commit comments

Comments
 (0)