Skip to content

Strings Mangled through Custom Function #218

@prologician

Description

@prologician

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions