Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/sqlite3/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ sqlite3val2rb(sqlite3_value *val)
rb_val = rb_float_new(sqlite3_value_double(val));
break;
case SQLITE_TEXT: {
rb_val = rb_utf8_str_new_cstr((const char *)sqlite3_value_text(val));
const char *text = (const char *)sqlite3_value_text(val);
int len = sqlite3_value_bytes(val);
rb_val = rb_utf8_str_new(text, len);
rb_obj_freeze(rb_val);
break;
}
Expand Down
13 changes: 13 additions & 0 deletions test/test_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,19 @@ def test_call_func_blob
assert_equal [blob, blob.length, 21], called_with
end

def test_call_func_text_with_embedded_nul
called_with = nil
@db.define_function("hello") do |a|
called_with = a
nil
end
@db.execute("create table texts ( text_value text )")
@db.execute("insert into texts ( text_value ) values ( ? )", ["abc\0def"])
@db.execute("select hello(text_value) from texts")
assert_equal "abc\0def", called_with
assert_equal 7, called_with.bytesize
end

def test_function_return
@db.define_function("hello") { |a| 10 }
assert_equal [10], @db.execute("select hello('world')").first
Expand Down
Loading