Skip to content

Conversation

@jimflood
Copy link

@jimflood jimflood commented Nov 5, 2015

Hello,
I was unable to return BLOB values from created functions using the gem. The change in this pull request allows returning of a BLOB value from a created function.

If the encoding on the string value is ASCII-8BIT, then the return value is a BLOB instead of TEXT. This is important if binary data contains null values, or is otherwise not valid UTF-8.

@jimflood
Copy link
Author

jimflood commented Dec 4, 2015

Here is a test I've added to show the problem:

def test_function_return_type_round_trip
  [10, 2.2, nil, "foo", Blob.new("foo\0bar")].each do |thing|
    @db.define_function("hello") { |thing| thing }
    assert_equal [thing], @db.execute("select hello(hello(?))", [thing]).first
  end
end

Before the fix:

  1. Failure:
    SQLite3::TestDatabase#test_function_return_type_round_trip [/home/jim/workspace/sqlite3-ruby/test/test_database.rb:273]:
    Expected: ["foo\u0000bar"]
    Actual: ["foo"]

tenderlove added a commit that referenced this pull request Feb 7, 2016
BLOB function result when ASCII-8BIT encoding
@tenderlove tenderlove merged commit 7dc8122 into sparklemotion:master Feb 7, 2016
@jimflood jimflood deleted the sqlite3_result_blob branch February 9, 2016 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants