Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings Mangled through Custom Function #218

Closed
prologician opened this issue May 13, 2017 · 1 comment · Fixed by #488
Closed

Strings Mangled through Custom Function #218

prologician opened this issue May 13, 2017 · 1 comment · Fixed by #488
Labels

Comments

@prologician
Copy link

prologician commented May 13, 2017

I'm using ruby 2.1.7p400 (2015-08-18 revision 51632) [i386-mingw32], and have the gem sqlite3 (1.3.13 x86-mingw32) installed. As part of a larger Ruby script, I was doing some database manipulations. While my main development environment ran fine, an alternate environment was seeing issues when processing data fetched from one table and inserted into another. The following test exercises the issue:

#!/usr/bin/ruby
# encoding: UTF-8

require 'sqlite3'
require 'minitest/autorun'

class TestCreateFunction < MiniTest::Unit::TestCase
    def setup
        @db = SQLite3::Database.new('')
        @db.execute("CREATE TABLE
                       sourceTable(
                         sourceData TEXT);")
        @db.execute("INSERT INTO sourceTable
                     VALUES ('abcde');")

        @db.create_function("GetCopy", 1) {|func, value|
            func.result = value
        }
    end

    def test_passthrough_udf
        @db.transaction {|t|
            t.execute("CREATE TABLE
                         afterTable(
                           beforeData TEXT,
                           afterData TEXT);".squeeze(" "))

            t.execute("INSERT INTO afterTable
                       SELECT
                         sourceData,
                         GetCopy(sourceData)
                       FROM sourceTable;")
        }

        refute_nil(@db.get_first_value("SELECT 1
                                        FROM afterTable
                                        WHERE beforeData = afterData
                                        LIMIT 1;"))
    end
end

The above test fails when using the sqlite3 gem 1.3.13, but passes with version 1.3.11.

When using a nonempty database name and inspecting the values in afterTable, it appears that the output of GetCopy() generated a blob instead of preserving the properties of the original string.

@flavorjones
Copy link
Member

Thank you for the executable test! I git-bisected and found that 44860d4 from #169 caused this test to start failing.

Reading the PR, this seems like a sensible change to make -- ASCII-8BIT encoding essentially means "binary encoding" and so a BLOB is arguably the correct data type for a string with this encoding.

However, given you're manipulating ordinary text I'm wondering why that encoding is being used, and perhaps that's the deeper issue we should look into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants