Skip to content

Clash between independent registered functions #331

@aplavin

Description

@aplavin

Registering different UDF functions in different databases but with the same name doesn't work and silently gives a wrong result:

using SQLite
using DBInterface: execute

db_a = SQLite.DB(":memory:")
db_b = SQLite.DB(":memory:")
SQLite.register(db_a, x -> 2x, name="myfunc")
SQLite.register(db_b, x -> 10x, name="myfunc")
@show first(execute(db_a, """select myfunc(1) as x"""))  # shows 10 (should be 2)
@show first(execute(db_b, """select myfunc(1) as x"""))  # shows 10 (as it should)

As I understand, it's due to this line:

function $(nm)(

Definitions with the function keyword are global in Julia, and SQLite.jl defines function myfunc(x) in both cases above. Can this be an anonymous function instead? I think it would fix the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions